2015-11-04 06:16 AM
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?2015-11-04 08:28 AM
Read the PWM input mode sub-chapter of the Timer chapter. You don't need to set capture on the second channel.
JW2015-11-04 09:19 AM
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!!2015-11-04 09:26 AM
>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.2015-11-04 02:29 PM
> You can use input prescale to have it reset every 1, 2, 4 or 8 cycles, as I recall.
I am about this one... JW2015-11-05 04:39 AM
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.