Skip to main content
IVent.1
Senior
February 11, 2025
Question

LPTIM behaviour

  • February 11, 2025
  • 1 reply
  • 365 views

Hallo, I'd like to use LPTIM to count the number of digital impulse of a signal.

So, the signal is connected to (in this case) LPTIM2_IN1.

The init function (MX_LPTIM2_Init) is as this:

 

hlptim2.Instance = LPTIM2;
hlptim2.Init.Clock.Source = LPTIM_CLOCKSOURCE_ULPTIM;
hlptim2.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV1;
hlptim2.Init.UltraLowPowerClock.Polarity = LPTIM_CLOCKPOLARITY_FALLING;
hlptim2.Init.UltraLowPowerClock.SampleTime = LPTIM_CLOCKSAMPLETIME_DIRECTTRANSITION;
hlptim2.Init.Trigger.Source = LPTIM_TRIGSOURCE_SOFTWARE;
hlptim2.Init.Period = 65535;
hlptim2.Init.UpdateMode = LPTIM_UPDATE_IMMEDIATE;
hlptim2.Init.CounterSource = LPTIM_COUNTERSOURCE_EXTERNAL;
hlptim2.Init.Input1Source = LPTIM_INPUT1SOURCE_GPIO;
hlptim2.Init.Input2Source = LPTIM_INPUT2SOURCE_GPIO;
hlptim2.Init.RepetitionCounter = 0;

 

Does this mean that I will have an interrupt every time my signal passes

from high to low state, so incrementing a variable every interrupt, I will have the total

number of impulses? Instead, using LPTIM_CLOCKPOLARITY_RISING means that the interrupt will be

generated when the input signal passes from low to high state? And what is the effect of

this 

 

hlptim2.Init.UltraLowPowerClock.SampleTime

 

and this 

 

hlptim2.Init.UpdateMode

 

Thank you.


Code formatting applied - please see How to insert source code for future reference

This topic has been closed for replies.

1 reply

Andrew Neil
Super User
February 11, 2025

You can find descriptions of the Init Structure in the HAL User Manual - UM2911:

AndrewNeil_0-1739284589390.png

https://www.st.com/resource/en/user_manual/um2911-description-of-stm32u5-hal-and-lowlayer-driver-stmicroelectronics.pdf#page=765

The same information also appears in the comments in the source files - use the IDE's 'Go To Definition' feature...

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.