cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to count pulses with a frequency higher than the MCU-clock without prescaler? (STM32L0)

ToStei
Associate II

Dear all,

I am quite new to the STM32-verse but need to work on a project using an STM32L0 (if possible the L081KZ) to count pulses. The pulses are generated by a clock (~2Mhz) and a gate / AND with an other signal. So there are some pulses with 2Mhz and then a long time nothing and again some pulses… I need to count how many of these short pulses there are per time interval. Because of power constrains I would like to use 1Mhz or less as clock and later implement the sleep-mode.

Therefore I wanted to use two timers:

- the LPTIM with an external oscillator to generate the time interval (and later to wake up the MCU)

- a TIM to count the pulses

(or vice versa)

I tried a bit and found that I cant count pulses with a frequency higher than ~0.5 of the system clock. In the AN47776 “generalpurpose-timer-cookbook�? I found something regarding this and on page 21 a disconcerting part that I must use a prescaler with the ETR (mode 2) input to count frequencies higher than the clock…

This is not feasible since I need to measure low counts 0.1Hz to 2MHz and cant wait so long until I have enough pulses measured due to the prescaler.

So… is there any way to use a timer as a simple counter where I can read out the register? Disable this synchronization stage which implements these clock constrains, or some other way?

Thanks for your help and best wishes

Tobias

1 ACCEPTED SOLUTION

Accepted Solutions

TIMx inputs are synchronized to their internal clock, which is derived from AHB/APB clocks.

OTOH, LPTIM is asynchronous, so you may want to use that for counting, in external clock mode, and use some other means to wake up the mcu (RTC perhaps?)

JW

View solution in original post

3 REPLIES 3

TIMx inputs are synchronized to their internal clock, which is derived from AHB/APB clocks.

OTOH, LPTIM is asynchronous, so you may want to use that for counting, in external clock mode, and use some other means to wake up the mcu (RTC perhaps?)

JW

Uwe Bonnes
Principal III

In the datasheet for normal timers, you can that external input for normal timers is Timer Clock/2. LPTIM can count external pulses, but no datasheet I looked so long specifies anything around LPTIM in the electrical characteristics. I will post a question around that. Think about an external counter like SN74LV8154. For readout you will need 12 pins. Or put a port extender in between, than you need only 2 pins with I2c.

ToStei
Associate II

Dear @Community member​ ,

thank you very much for your fast answer! Using the LPTIM seems to be a good idea... if i could get it working at all with an external signal (see community.st.com/s/question/0D53W00001F0BNPSA3/) - with an internal clock source i had no problem.

Utilizing the RTC to wake the MCU up might be a good idea too... if i solve the counting issue ill look into it, or perhaps i can use the watchdog.

Thanks again for your answer.

Dear @Uwe Bonnes​ ,

of cause also a big thanks to you for your answer! Using an additional IC might be possible but brings other concerns... so this would be a last resort in my case. Never the less thanks for your idea!

Best wishes

Tobias