STM32F103R8T6 Timer4 Input Capture problem
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-03-24 3:17 AM
Posted on March 24, 2014 at 11:17
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.
This discussion is locked. Please start a new topic to ask your question.
13 REPLIES 13
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-03-25 10:10 AM
Posted on March 25, 2014 at 18:10
I think the problem is that in F1 series only advanced timer can catch both edges, in general timer it's only single polarity.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-03-25 10:48 AM
Posted on March 25, 2014 at 18:48
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.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Up vote any posts that you find helpful, it shows what's working..
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-03-25 11:13 AM
Posted on March 25, 2014 at 19:13
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; } }
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Up vote any posts that you find helpful, it shows what's working..
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-03-26 2:39 AM
Posted on March 26, 2014 at 10:39
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!
- « Previous
-
- 1
- 2
- Next »