AnsweredAssumed Answered

STM32 Pulse Counter

Question asked by Ferreira on Mar 28, 2012
Latest reply on Mar 30, 2012 by malund.erik

I wonder if someone could help me.

I want to count the number of pulses occured each "x" time.

I could use a timer configured to generate an interrupt each "x" time. And the interrupt handler of this timer should read the counter value, and reset the counter. But, if the processor is executing a non-preemptive task while an interrupt will occured, the processor will execute the non-preemptive task until the end, and the interrupt handler will wait until the non-preemptive task will be completly executed. But meanwhile, some pulses can occured and will be counted.

So, I would ask if I could avoid this situation with a timer in Input capture mode. Is it possible to configure a timer in Input capture mode, using as Active input an internal periodical timer, instead of an input pin channel, and using the input pin as counter clock, instead of internal clock?
I mean, I would like to have an internal timer that generates the capture event cyclically, meanwhile an external pin clocks the counter.
After each capture I would use the DMA to store the captured value to a global variable.

If it is possible, could someone tell me how I could make it working? (procedure, configuration, registers to modify)

I would also o ask if it is possible to cascade a timer in Input Capture mode. Because, the external signal has a 1Mhz max frequency. If I will generate capture events only each second, the capture counter will overflow before one second.

Thank you very much,

Best regards,

A. Paiva