Showing results for 
Search instead for 
Did you mean: 

PWM Input Mode to capture [0% 100%] - Peripheral Alternate Functions

Posted on August 28, 2012 at 18:08


I have several questions concerning STM32 timer configured in PWM input. First, I need to capture 3 PWM signals.Each signal to measure needs two timer channels in order to capture Period and Duty cycle. On a single timer it is not possible to have channel 3 and 4 capturing external input signal. It implies I must have 3 timers to do my capture? Is it right? Then, during capture. How can I capture 0% and 100% duty cycle value? I thought about this solution : I only enableTIM_IT_Update interrupt. And my interrupt handler :

void TIM5_IRQHandler(void){
TIM_ClearITPendingBit(TIM5, TIM_IT_Update);
/* ]0%, 100%[ duty cycle */
if(TIM_GetFlagStatus(TIM5, TIM_IT_CC1) == SET && TIM_GetFlagStatus(TIM5, TIM_IT_CC2) == SET)
/* I can compute and save duty cycle and frequency */
else /* 0% or 100% duty cycle */
/* Counter overflow with no duty cycle and period capture
* ie signal has a 0% or 100% duty cycle value (prescaler
* configured according to signal frequency range) get
* signal state calling GPIO_ReadInputDataBit
TIM_ClearFlag(TIM5, TIM_IT_CC1);
TIM_ClearFlag(TIM5, TIM_IT_CC2);

What about this solution (in comparison to a solution based on a timeout using another timer channel)? And another question about alternate peripheral function. On PA0 I have following alternate functions (no remap) :WKUP/USART2_CTS(7)/ADC_IN0/TIM5_CH1/TIM2_CH1_ETR(7) I have TIM2 clock already enabled, and channel 3 and 4 enabled as output. If I want to use TIM5 on PA0 is it possible? what are limitations on mode? According to ST doc : ''If several peripherals share the same I/O pin, to avoid conflict between these alternate functions only one peripheral shouldbe enabled at a time through the peripheral clock enable bit (in the corresponding RCC peripheral clock enable register).'' If I refer to this rule I cannot use TIM5 on PA0 as TIM2 clock already enabled. But, * if TIM2 channel 1 is disabled andTIM5 channel 1 configuredas output * ifTIM2 channel 1 andTIM5 channel 1configured as input will I have some conflicts? And more generaly In other terms, if I have several peripheral Inputs sharing same input PIN will it cause conflicts? (In output case, with a PIN configured as output shared by several peripheral output, for sure this will leads to conflicts...) Thanks for your help Carlos. #pwm-input