Skip to main content
l239955_stm1
Associate III
November 4, 2015
Question

Reset timer in Input Capture

  • November 4, 2015
  • 5 replies
  • 1033 views
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?

    This topic has been closed for replies.

    5 replies

    waclawek.jan
    Super User
    November 4, 2015
    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

    Tesla DeLorean
    Guru
    November 4, 2015
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    mckenney
    Associate
    November 4, 2015
    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 III
    November 5, 2015
    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.