cancel
Showing results for 
Search instead for 
Did you mean: 

Count PWM pulses

Posted on February 08, 2016 at 10:30

Hello there,

I am using STM32F4. I was wondering either it is possible to count the PWM rising or falling edges that the mcu generates. I know that I could connect the PWM output to anothers timer input trigger pin and do it this way. But I am using 8 PWM output channel so I would additionaly need 8 input capture channels (dunno how many timers is needed for that yet, hope less than 8). I could also generate an interrupt for each pwm channel to increment a variable in the interrupt routine but that would be really heave for the MCU if I had 8 pwm channels running 10kHz each.

Is it possible maybe, to somehow hook up timers internally to get this functionality I am looking for? Or using DMA maybe? I cannot think of anything better than external pin connection. I would apreciate all help!
12 REPLIES 12
Posted on February 08, 2016 at 17:38

What I meant is that for 8 PWM outputs, I would need 8 separate additional timers to measure each PWM channel overflows. Or did you have something better in mind :P?

Also sorry for the blank posts, this forum doesnt quite work on my mobile phone.
re.wolff9
Senior
Posted on February 08, 2016 at 22:24

What clive is STILL trying to say is that if you have timers 1-8 running with periods p1,p2,p3,...p8, you can use a nineth timer to count ''time''. Use a 32-bit timer for that. Callit timer T9. 

Now when you want to know the number of counts for the other timers measure T9 at the begining and at the end. Calculate the difference, call it ''d''. Next, for each of the other timers the number of PWM periods is d/tx (d/t1 for the first timer, d/t2 for the second and so on.). 

Posted on February 08, 2016 at 22:30

Yes, I gues thats doable... Thank you for the explanation, now I understand. Sorry it took so long.