cancel
Showing results for 
Search instead for 
Did you mean: 

Reset timer in Input Capture

l239955_stm1
Associate II
Posted on November 04, 2015 at 15:16

Hi all,

I´m using timer in Input Capture mode to measure interval between pulses. Actual solution

actualTime = TIM3->CCR1;

if(actualTime > lastTime) delay = actualTime - lastTime;

else delay = 0xffff - lastTime + actualTime;

Is possible to set timer to clear counter after new input pulse?

5 REPLIES 5
Posted on November 04, 2015 at 17:28

Read the PWM input mode sub-chapter of the Timer chapter. You don't need to set capture on the second channel.

JW

Posted on November 04, 2015 at 18:19

As Jan suggests PWM Input does that. You can use input prescale to have it reset every 1, 2, 4 or 8 cycles, as I recall.

BTW your math is broken.

delay = actualTime - lastTime; // Just this works for ALL uint16_t values!!

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mckenney
Senior
Posted on November 04, 2015 at 18:26

>Is possible to set timer to clear counter after new input pulse?

Don't. If you do your numbers will always be off by something.

uint16_t new, prev, diff;

new = TIM3->CCR1;

diff = new - prev;

prev = new;

The magic of 16-bit arithmetic does the rest.

l239955_stm1
Associate II
Posted on November 05, 2015 at 13:39

Thanks a lot, PWM IC is OK.

-> mckenney.bruce, this solution is not suitable, I´m using Update interrupt to dedicate stopping of the communication.