2014-03-24 03:17 AM
Hi!
There is a problem with Timer4 Input Capture use. Initially everything was developed under the STM32L100R8T6 controler, but so happened that it was necessary to pass to STM32F103R8T6. This code perfectly works at STM32L100: RCC_APB1PeriphClockCmd (RCC_APB1Periph_TIM4, ENABLE); TIM_TimeBaseStructInit (& timer); timer.TIM_Prescaler = 72 - 1; timer.TIM_Period = 65535; TIM_TimeBaseInit (TIM4, & timer); TIM_ICInitTypeDef timICStruct; timICStruct.TIM_Channel = TIM_Channel_1; timICStruct.TIM_ICPolarity = TIM_ICPolarity_BothEdge; timICStruct.TIM_ICSelection = TIM_ICSelection_DirectTI; timICStruct.TIM_ICPrescaler = TIM_ICPSC_DIV1; timICStruct.TIM_ICFilter = 0x08; TIM_ICInit (TIM4, & timICStruct); TIM_ITConfig (TIM4, TIM_IT_CC1, ENABLE); TIM_Cmd(TIM4, ENABLE); On STM32F103 this code doesn't catch both Edges, works similarly with RisingEdge.Help to solve a problem, or describe how ''on the fly'' to change Edges.Thanks in advance.2014-03-25 10:10 AM
I think the problem is that in F1 series only advanced timer can catch both edges, in general timer it's only single polarity.
2014-03-25 10:48 AM
TIM_ICPolarity_BothEdge isn't defined in V3.3.0
In V3.5.0 it will assert if used on TIM1, TIM8, TIM2, TIM3, TIM4, TIM5 Configure CH1 for the rising edge, and CH2 for the falling edge indirect.2014-03-25 11:13 AM
RCC_APB1PeriphClockCmd (RCC_APB1Periph_TIM4, ENABLE);
TIM_TimeBaseStructInit (& timer); timer.TIM_Prescaler = 72 - 1; timer.TIM_Period = 65535; TIM_TimeBaseInit (TIM4, & timer); TIM_ICInitTypeDef timICStruct; timICStruct.TIM_Channel = TIM_Channel_1; timICStruct.TIM_ICPolarity = TIM_ICPolarity_RisingEdge; timICStruct.TIM_ICSelection = TIM_ICSelection_DirectTI; timICStruct.TIM_ICPrescaler = TIM_ICPSC_DIV1; timICStruct.TIM_ICFilter = 0; TIM_ICInit(TIM4, &timICStruct); timICStruct.TIM_Channel = TIM_Channel_2; timICStruct.TIM_ICPolarity = TIM_ICPolarity_FalingEdge; timICStruct.TIM_ICSelection = TIM_ICSelection_IndirectTI; // CH1 timICStruct.TIM_ICPrescaler = TIM_ICPSC_DIV1; timICStruct.TIM_ICFilter = 0; TIM_ICInit(TIM4, &timICStruct); TIM_ITConfig(TIM4, TIM_IT_CC1 | TIM_IT_CC2, ENABLE); TIM_Cmd(TIM4, ENABLE); void TIM4_IRQHandler(void) { uint16_t CurCapt; if (TIM_GetITStatus(TIM4, TIM_IT_CC1) != RESET) { TIM_ClearITPendingBit(TIM4, TIM_IT_CC1); curCapt = TIM_GetCapture1(TIM4); Capt = curCapt - oldCapt; oldCapt = curCapt; } if (TIM_GetITStatus(TIM4, TIM_IT_CC2) != RESET) { TIM_ClearITPendingBit(TIM4, TIM_IT_CC2); curCapt = TIM_GetCapture2(TIM4); Capt = curCapt - oldCapt; oldCapt = curCapt; } }2014-03-26 02:39 AM
Thank you Clive !
Your code works perfectly. Small inaccuracy, I have no TIM_ICPolarity_RisingEdge, TIM_ICPolarity_FalingEdge. They are called as TIM_ICPolarity_Rising, TIM_ICPolarity_Falling.Thanks once again!