cancel
Showing results for 
Search instead for 
Did you mean: 

Counting The impulses sent via timers...

magas09
Associate II
Posted on May 23, 2015 at 17:59

Hi!

I am working now on the project (STM32F429i board) where I need to profile the velocity of servo motor (i.e. trapezoidal velocity)... So I need to control the number of pulses I've sent via PWM channel, to control position of servo motor... Would You suggest me a few method which I can use to do that...? And which is the best...?

Now I am using 2 timers linked by wire: one in PWM Out Mode and the other in Input Capture Mode with External CLK on this pin.

This method has ''quite good results'' I dont know if it is the best or only method to implement...

Thanks for any advice,

Marcin

#timer-modes #stm32f429
5 REPLIES 5
Posted on May 24, 2015 at 03:27

Well the advanced timers (TIM1 and TIM8) have an 8-bit repetition count.

Other than that I'd probably either use another TIM in external count mode, or simply count Update interrupts from something that's low bandwidth like 50 Hz

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
magas09
Associate II
Posted on May 24, 2015 at 10:36

Hi!

Yes I thought about configuring counting timer in external clock mode 1. But the interrupt (to turn of PWM timer) is generated only when counter is overflowed (update interrupt)...

In my project I need to send different size and frequency packages of pulses and turn off PWM timer when enough pulses were sent. So to do that in external clk mode 1, I would have to reconfigure counting timer ARR register periodically, before/while generation of each package... Is it a good programistic idea? And if is it possible to work properly...? 

(I work with frequencies from 1Hz to 200kHz)

Posted on May 25, 2015 at 00:04

It can interrupt on things other than Update (Rollover), you can use the CCRx register to interrupt when it hits specific set points, and you can advance those setting to counts in the future. ie TIM2->CCR2 += 1000;

For complex patterns to a single register within the timer there is also DMA, you can have the DMA interrupt half way through or at the end of a pattern.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
magas09
Associate II
Posted on May 25, 2015 at 12:36

So when the value of counter reach to the CCRx register value the TIMx_IRQHandler() is called...? Or some other interrupt function...?

Posted on May 25, 2015 at 16:28

So when the value of counter reach to the CCRx register value the TIMx_IRQHandler() is called...? Or some other interrupt function...?

Yes for most timers there's just one interrupt handler and all interrupts go there, and you qualify the source in your handling code. Review the startup_stm32fxx.s file to see all the interrupt vectors, and confirm those available for a specific TIMx
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..