Skip to main content
infoinfo987
Associate
May 11, 2011
Question

Simply count pulses on TIM1?

  • May 11, 2011
  • 4 replies
  • 867 views
Posted on May 12, 2011 at 01:02

Simply count pulses on TIM1?

    This topic has been closed for replies.

    4 replies

    raptorhal2
    Lead
    May 17, 2011
    Posted on May 17, 2011 at 14:34

    It's simpler than you think. Just increment a variable in the TIM1 IRQ Handler for each CH1 interrupt.

    RM0008 the All Densities Reference Manual Section 8 has a complete description of how to configure pins. Table 19 defines the configuration needed for TIM1 pins.

    Cheers, Hal

    lowpowermcu
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 14:34

    Refere to ''External clock source mode 1'' in the reference manual.

    In this mode, the timer counter is incremented each time a valid edge is deteced on external pin.

    Thanks to let me know if you get out.

    MCU Lüfter

    infoinfo987
    Associate
    May 17, 2011
    Posted on May 17, 2011 at 14:34

    I failed to mention that I need to count pulses at rates up to 1 MHz.  That's way faster then an interrupt can handle.  My application is this:

    Every one second, record the pulse count and then reset it.  Pulse count can range from 0 to 1e6 pulses per second.

    Any additional help?

    JJS

    Tesla DeLorean
    Guru
    May 17, 2011
    Posted on May 17, 2011 at 14:34

    Consider also that the counter is only 16-bit, so you'll need to increase your sample rate, or cascade the counter.

    If the 1PPS has any precision to it, I'd be tempted to use a free running 32-bit counter off the 1 MHz, and latch it to a buffer every second, so as not to accumulate error.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..