2025-02-11 06:15 AM - last edited on 2025-02-11 06:29 AM by Andrew Neil
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
2025-02-11 06:37 AM
You can find descriptions of the Init Structure in the HAL User Manual - UM2911:
The same information also appears in the comments in the source files - use the IDE's 'Go To Definition' feature...