cancel
Showing results for 
Search instead for 
Did you mean: 

Making a pulse counter with LPTIM4

Santiago_Deliotte
Associate II

I'm trying to use the LPTIM4 while in STOPMode2, in a stm32U575ZI-Q microcontroller, as a external pulse counter, and use this pulse value to refresh a LCD screen. For this question I'm only using the usart1 to tell me how many pulses were detected in an one second window when the microcontroller is in STOPMode2. I'm using the LSE clock for the LPTIM4 so I can count in this mode.

In the final project the pulses will come at different frequencies, so I'm using a waveform generator configured as a square form wave, with 3Vdc of amplitude, and a frecuence range of 1-500Hz.

The problem is that the amount of pulses read by the usart is always lower than the real amount of generated pulses. For example if I'm sending a 10 Hz square waveform, It has to read 10 pulses or similar (probably because of the low speed of the LSE, lower), but it always reads a lot less, like 0 or 1 pulses. The amount of read pulses increases with the frecuence, but not in a "propper way". With 100 Hz it reads 2 or 3 pulses every second, and so on.

I let the code below, and some code and configuration captures for fast checking.

1 REPLY 1
Sarra.S
ST Employee

Hello @Santiago_Deliotte​ 

Please refer to AN4013, pages 38 and 39 on how to use LPTIM as a pulse counter

For more details on using the timer in this mode, refer to the examples provided in the STM32Cube package in the Examples\LPTIM\LPTIM_PulseCounter subfolder.

Hope that helps!

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.