AnsweredAssumed Answered

STM32F4 - Using timers with DMA to count pulses.

Question asked by John Hite on Mar 23, 2017
Latest reply on Mar 25, 2017 by Clive One

STM32F437 processor

I have no experience using the stm32 timers with DMA so I wish to solicit suggestions before banging my head against the wall.


I have set up a counter using an ISR to count pulses (RPM) and it works quite well for low speed and extremely low speeds. If the speed is real slow the timer overflows and triggers an interrupt. I just count the overflows until I get a real trigger event and shift the overflow count << 16 and add the new count. While this method works good at low speed it become a processor hog at higher speeds since there is an interrupt for each pulse, plus since I am using an OS (Micrium III) the isr is twice removed, so to speak. A system with one magnet or tit per revolution is fine up to a few thousand RPM. But some systems I will encounter will count flywheel teeth (perhaps 460 per revolution).  Or it might be a 60000RPM turbo with 6 pulses per revolution.


I am not experienced with using a timer and DMA together but I could see how it might allow me to collect a group of samples without an ISR. I have found some examples of using timers with dma but they are for pwm and transfer from memory from peripheral and don't seem too use DMA interrupts.


Another scheme would be to count pulses within a time window. If I determine how to setup and gate it. I may be able to use some timers together but not in cascade as RPM1 is fed to TIM3 ch2 and TIM4 ch1 while  RPM2 is fed to TIM1 ch 1 and TIM9 - ch 1.


So while I am figuring out how to use timers and DMA together I thought I would ask for articles or examples where you have measured pulses at rates up to 36000 pulses per second. I will have a look up table for normal operating speed and pulses per revolution (could actually be 0.5 if timing off the camshaft) so that will at least help with the prescaler setup.