cancel
Showing results for 
Search instead for 
Did you mean: 

choosing pwm channel stm32f407 discovery board

mohamad_armoon
Associate III
Posted on August 23, 2014 at 11:29

0690X00000605QPQAY.png

0690X00000605NLQAY.png

hi everybody

i want to have 8 channel pwm input and 8 channel pwm output in stm32f407vgt6

here is the table of timers in this micro . i also want to have a time scheduling .from your perspective which combination of these times is suitable for 8channel input and which one for 8 channel pwm output and  which one is  good for time scheduling ?

10 REPLIES 10
Posted on August 23, 2014 at 11:58

Doing the due diligence here would seem to take more time than I'm willing to expend, so I'll make some suggestions that might save you some time.

The manual for the board describes the available pins, this is going to limit your options. To do PWM Input mode you are going to need to find EIGHT timers, providing CH1 or CH2 pins. This is likely to be an impossibly high hurdle. Your post provides insufficient detail about the nature/speed of your signalling, so I'll assume it's something slow and mundane like a 50 Hz Servo, and the signals are all very similar in specification so can share a timer. I would suggest using the 32-bit timers to time stamp signal edges using Input Capture mode, where possible.  And use which ever 16-bit timer pins you have available to generate the PWM Output.

Use SysTick for continuous time base requirements, set it to 1 KHz, or whatever the granularity of the requirement is, have it dispatch tasks, decimate, or count off other time related events/signals.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mohamad_armoon
Associate III
Posted on August 23, 2014 at 12:50

thanks clive.

that's right i want to handle 8 50hz servos separately . but why i should use 8 timers for 8 channel input pwm. i mean for example timer2 has 4 channel i can not use each channel for each input ?? 

Posted on August 23, 2014 at 13:03

but why i should use 8 timers for 8 channel input pwm. i mean for example timer2 has 4 channel i can not use each channel for each input ??

Not it PWM Input mode you can't, it uses a pair of channels, and resets the timer. Review manual and examples thereof, and then explain to me how this is going to work. For a one-to-one channel to signal ratio you'd have to be using Input Capture mode.

Are all the servo input guaranteed to be synchronous with each other? Perhaps you can use CH3 and CH4 to latch secondary channels?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mohamad_armoon
Associate III
Posted on August 24, 2014 at 02:30

ok , but you wrote one simple example in this thread for stm32f10 and you mentioned that it is for 4 channel pwm input , but in that example you used 4 channels of one time (i assume timer 2)

what do yo mean by : Are all the servo input guaranteed to be synchronouswhat synchronous means here ?? i also wrote a code using both channel 1 and 2 in timer 2 for input capture but it didn't work.

void
TIM2_1_Configuration(
void
)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* TIM2 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
/* GPIO clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
/* Configure GPIO input for timer */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Connect TIM2 pins to AF */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_TIM2);
/* Enable the TIM2 global Interrupt */
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_Init(&NVIC_InitStructure);
TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t) (((SystemCoreClock / 1000000) / 2) - 1); 
TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
/* Configure PWM Input Capture */
TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM_ICInitStructure.TIM_ICFilter = 0x0;
TIM_PWMIConfig(TIM2, &TIM_ICInitStructure);
/* Select the TIM2 Input Trigger: TI1FP1 */
TIM_SelectInputTrigger(TIM2, TIM_TS_TI1FP1);
/* Select the slave Mode: Reset Mode */
TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Reset);
TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable);
/* TIM Interrupts enable */
TIM_ITConfig(TIM2, TIM_IT_CC1, ENABLE);
/* TIM2 enable counter */
TIM_Cmd(TIM2, ENABLE);
}
void
TIM2_2_Configuration(
void
)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* TIM2 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
/* GPIO clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
/* Configure GPIO input for timer */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; 
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource3, GPIO_AF_TIM2);
/* Enable the TIM2 global Interrupt */
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_Init(&NVIC_InitStructure);

TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t) (((SystemCoreClock / 1000000) / 2) - 1); 
TIM_TimeBaseStructure.TIM_Period = 0xFFFF; 
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
/* Configure PWM Input Capture */
TIM_ICInitStructure.TIM_Channel = TIM_Channel_2; 
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM_ICInitStructure.TIM_ICFilter = 0x0;
TIM_PWMIConfig(TIM2, &TIM_ICInitStructure);
/* Select the TIM2 Input Trigger: TI1FP1 */
TIM_SelectInputTrigger(TIM2, TIM_TS_TI1FP1);
/* Select the slave Mode: Reset Mode */
TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Reset);
TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable);
/* TIM Interrupts enable */
TIM_ITConfig(TIM2, TIM_IT_CC2, ENABLE);
/* TIM2 enable counter */
TIM_Cmd(TIM2, ENABLE);
}

Posted on August 24, 2014 at 02:44

what synchronous means here ??

The rising edge of all PWM signals are coherent.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mohamad_armoon
Associate III
Posted on August 25, 2014 at 15:31

hi clive , 

pwm 

uses a pair of channels

 

is this because of 2 ICx signals that are mapped on the same TIx input ??

one to capture the pulse width and another to capture paeriod ??

in this situation it's very expensive (from hardware side),to get 8 channel pwm with 8 timers .

is there another way to handle this ??(not to use input capture_pwm input) in open source projects i saw that an AVR micro controller handle more that 2 or 3 pwm input that is connected to INT pins in that micro.

mohamad_armoon
Associate III
Posted on August 25, 2014 at 15:33

hi clive , 

pwm 

uses a pair of channels

 

is this because of 2 ICx signals that are mapped on the same TIx input ??

one to capture the pulse width and another to capture paeriod ??

in this situation it's very expensive (from hardware side),to get 8 channel pwm with 8 timers .

is there another way to handle this ??(not to use input capture_pwm input) in open source projects i saw that an AVR micro controller handle more that 2 or 3 pwm input that is connected to INT pins in that micro.

Posted on August 25, 2014 at 15:55

As I said the channels are paired, they deliver period/duty, and reset the counter to do so.

I've also said several times you need to use Input Capture mode to time stamp the edges if you want to use multiple channels of a timer. You then need to manage the measurements via interrupts.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mohamad_armoon
Associate III
Posted on August 25, 2014 at 17:50

well, i should use input capture instead of pwm input mode.

but i never use input capture to measure pulse width, i used it for external pulse counting .

if i'm right it detect the edge of each rising. so how can i use it to find pulse width ??