Making a pulse counter with LPTIM4
- May 11, 2023
- 1 reply
- 2711 views
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.
