Skip to main content
Santiago_Deliotte
Associate
May 11, 2023
Question

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.

This topic has been closed for replies.

1 reply

ST Employee
June 12, 2023

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!