cancel
Showing results for 
Search instead for 
Did you mean: 

Simply count pulses on TIM1?

infoinfo987
Associate
Posted on May 12, 2011 at 01:02

Simply count pulses on TIM1?

4 REPLIES 4
raptorhal2
Lead
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

infoinfo987
Associate
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

lowpowermcu
Associate II
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

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
Up vote any posts that you find helpful, it shows what's working..