HAL LPTIM How to Use ¶
- group LPTIM_How_To_Use
-
The LPTIM HAL driver can be used as follows ¶
(Non optional call) Call HAL_LPTIM_Init(), to initialize the LPTIM driver by establishing a link with ¶
the LPTIM physical instance.
(Non optional call) Call HAL_LPTIM_SetConfig(), to Configure the timebase unit : ¶
-
Select the clock source hal_lptim_clk_src_t :
-
:
LPTIM is clocked by internal clock source The counter is incremented following each internal clock pulse
-
HAL_LPTIM_CLK_EXTERNAL_SYNCHRONOUS
:
The LPTIM counter clock signal is generated from the external input 1 signal.
The LPTIM external Input1 is sampled with the internal clock provided to the LPTIM.
LPTIM Input 1 can be configured with
HAL_LPTIM_SetConfigInput1() . -
HAL_LPTIM_CLK_EXTERNAL_ASYNCHRONOUS
:
The LPTIM counter clock signal is generated from the external input1 signal.
The LPTIM external input 1 can be configured by calling HAL_LPTIM_SetConfigInput1() . -
HAL_LPTIM_CLK_ENCODER_SUBMODE_1 to HAL_LPTIM_CLK_ENCODER_SUBMODE_3
:
The LPTIM counter clock signal is generated from the two external input signals, input1 and input2.
-
-
Select the prescaler division factor hal_lptim_clk_src_presc_t
-
Set period value : number between 0 to 65535 (0x0000 to 0xFFFF)
-
set repetition counter value: number between 0 to 255 (0x00 to 0xFF)
-
Select the functioning mode with hal_lptim_mode_t :
-
HAL_LPTIM_ONE_SHOT : When the LPTIM counter is stopped a trigger event starts it. The counter is stopped on update event.
-
HAL_LPTIM_SET_ONCE : A first trigger event starts the LPTIM counter for a single one-shot cycle
-
HAL_LPTIM_CONTINUOUS : The LPTIM counter starts from trigger event and never stops until the timer is disabled.
-
HAL_LPTIM_TIMEOUT : The detection of an active edge on one selected trigger input can be used to reset the LPTIM counter.
-
If needed, HAL_LPTIM_DeInit() can be called to reset the driver. ¶
When an external clock is used, configure the LPTIM input1 by calling the HAL_LPTIM_SetConfigInput1() ¶
-
Select the input1 source with hal_lptim_input1_src_t
-
Select the input1 polarity with hal_lptim_input1_polarity_t
-
Select the input1 filter with hal_lptim_filter_t
select your usage : ¶
- To use LPTIM instance as a simple counter: ¶
-
Configure LPTIM time base unit. The functioning mode must be set to HAL_LPTIM_CONTINUOUS when calling HAL_LPTIM_SetConfig() .
-
Start the LPTIM counter, two execution mode are available:
-
Polling : HAL_LPTIM_Start()
-
Interrupt : HAL_LPTIM_Start_IT() , in this case, the update interrupt is enabled
-
-
Stop the LPTIM counter, call HAL_LPTIM_Stop() and HAL_LPTIM_Stop_IT() , as per selected execution mode.
- To generate a PWM signal: ¶
-
Configure LPTIM time base unit. The functioning mode must be set to HAL_LPTIM_CONTINUOUS when calling HAL_LPTIM_SetConfig() .
-
Configure the output channel(s) by calling HAL_LPTIM_OC_SetConfigChannel() .
-
To start PWM signal generation, first start the output channel, then the LPTIM time base unit by calling HAL_LPTIM_Start() . Three execution mode are available:
-
Polling : HAL_LPTIM_OC_StartChannel()
-
Interrupt : HAL_LPTIM_OC_StartChannel_IT() , in this case, the compare match interrupt is enabled
-
-
Stop the PWM signal generation, call HAL_LPTIM_OC_StopChannel() or HAL_LPTIM_OC_StopChannel_IT() as per selected execution mode.
- To generate a One pulse signal: ¶
-
Configure LPTIM time base unit. The functioning mode must be set to HAL_LPTIM_ONE_SHOT when calling HAL_LPTIM_SetConfig() .
-
Configure the output channel(s) by calling HAL_LPTIM_OC_SetConfigChannel() .
-
If the pulse generation is triggered when an active edge is detected on the external trigger input, configure the external trigger input by calling the HAL_LPTIM_SetConfigExtTrigInput() .
-
To start pulse generation, first start the output channel(s), then the LPTIM time base unit by calling HAL_LPTIM_Start() . Three execution mode are available:
-
Polling : HAL_LPTIM_OC_StartChannel()
-
Interrupt : HAL_LPTIM_OC_StartChannel_IT() , in this case, the compare match interrupt is enabled
-
-
Stop signal generation, call HAL_LPTIM_OC_StopChannel() or HAL_LPTIM_OC_StopChannel_IT() as per selected execution mode.
- To generate a set once signal: ¶
-
Configure LPTIM time base unit. The functioning mode must be set to HAL_LPTIM_SET_ONCE when calling HAL_LPTIM_SetConfig() .
-
If the signal generation is triggered when an active edge is detected on the external trigger input, configure the external trigger input by calling the HAL_LPTIM_SetConfigExtTrigInput() .
-
The output channel(s) must be configured by calling HAL_LPTIM_OC_SetConfigChannel()
-
To start signal generation, first start the channel(s), then the LPTIM time base unit by calling HAL_LPTIM_Start() . Two execution mode are available:
-
Polling : HAL_LPTIM_OC_StartChannel()
-
Interrupt : HAL_LPTIM_OC_StartChannel_IT() , in this case, the compare match interrupt is enabled
-
-
Stop signal generation, call HAL_LPTIM_OC_StopChannel() or HAL_LPTIM_OC_StopChannel_IT() , as per selected execution mode.
- To capture an input signal: ¶
-
Configure LPTIM time base unit. The functioning mode must be set to HAL_LPTIM_CONTINUOUS when calling HAL_LPTIM_SetConfig() .
-
The input channel(s) must be configured by calling HAL_LPTIM_IC_SetConfigChannel()
-
To start a capture, first start the input channel, then the LPTIM time base unit ( HAL_LPTIM_Start() ) Three execution mode are available:
-
Polling : HAL_LPTIM_IC_StartChannel()
-
Interrupt : HAL_LPTIM_IC_StartChannel_IT() , in this case, the capture interrupt is enabled
-
DMA : HAL_LPTIM_IC_StartChannel_DMA() , in this case, the capture DMA request is enabled
-
-
Stop input signal capture, call HAL_LPTIM_IC_StopChannel() or HAL_LPTIM_IC_StopChannel_IT() or HAL_LPTIM_IC_StopChannel_DMA() , as per selected execution mode.
- To use the LPTIM timeout feature: ¶
-
Configure LPTIM time base unit. The functioning mode must be set to HAL_LPTIM_TIMEOUT when calling HAL_LPTIM_SetConfig() .
-
Configure the external trigger input by calling the HAL_LPTIM_SetConfigExtTrigInput() .
-
Configure the timeout value by calling HAL_LPTIM_OC_SetPulse() Two execution mode are available:
-
Polling : HAL_LPTIM_Start()
-
Interrupt : HAL_LPTIM_Start_IT() , in this case, the update event is enabled
-
-
To stop pulse generation, HAL_LPTIM_Stop and HAL_LPTIM_Stop_IT() , as per selected execution mode.
- To use the LPTIM encoder interface: ¶
-
Configure LPTIM time base unit. The functioning mode must be set to HAL_LPTIM_CONTINUOUS and encoder mode must be selected as LPTIM clock source when calling HAL_LPTIM_SetConfig() .
-
The encoder interface (LPTIM input 1 and input 2) must be configured by calling HAL_LPTIM_SetConfigEncoder. Two execution mode are available:
-
Polling : HAL_LPTIM_Start()
-
Interrupt : HAL_LPTIM_Start_IT() , in this case, the update event is enabled
-
-
To stop encoder interface, call HAL_LPTIM_Stop() and HAL_LPTIM_Stop_IT() , as per selected execution mode.
Callbacks definition in Interrupt or DMA mode ¶
-
When the compilation define USE_HAL_LPTIM_REGISTER_CALLBACKS is set to 1, the user can configure dynamically the driver callbacks, via its own method:
Callback name
Default callback
Register callback
ErrorCallback
HAL_LPTIM_ErrorCallback
HAL_LPTIM_RegisterErrorCallback
StopCallback
HAL_LPTIM_StopCallback
HAL_LPTIM_RegisterStopCallback
InputCaptureStopCallback
HAL_LPTIM_InputCaptureStopCallback
HAL_LPTIM_RegisterChannelStopCallback
UpdateCallback
HAL_LPTIM_UpdateCallback
HAL_LPTIM_RegisterUpdateCallback
UpdateHalfCpltCallback
HAL_LPTIM_UpdateHalfCpltCallback
HAL_LPTIM_RegisterUpdateHalfCpltCallback
RepUpdateCallback
HAL_LPTIM_RepUpdateCallback
HAL_LPTIM_RegisterRepUpdateCallback
TriggerCallback
HAL_LPTIM_TriggerCallback
HAL_LPTIM_RegisterTriggerCallback
InputCaptureCallback
HAL_LPTIM_InputCaptureCallback
HAL_LPTIM_RegisterInputCaptureCallback
InputCaptureHalfCpltCallback
HAL_LPTIM_InputCaptureHalfCpltCallback
HAL_LPTIM_RegisterInputCaptureHalfCpltCallback
InputOverCaptureCallback
HAL_LPTIM_InputOverCaptureCallback
HAL_LPTIM_RegisterOverCaptureCallback
CompareMatchCallback
HAL_LPTIM_CompareMatchCallback
HAL_LPTIM_RegisterCompareMatchCallback
CompareUpdateCallback
HAL_LPTIM_CompareUpdateCallback
HAL_LPTIM_RegisterCompareUpdateCallback
AutoReloadMatchCallback
HAL_LPTIM_AutoReloadMatchCallback
HAL_LPTIM_RegisterAutoReloadMatchCallback
AutoReloadUpdateCallback
HAL_LPTIM_AutoReloadUpdateCallback
HAL_LPTIM_RegisterAutoReloadUpdateCallback
DirectionDownCallback
HAL_LPTIM_DirectionDownCallback
HAL_LPTIM_RegisterDirectionDownCallback
DirectionUpCallback
HAL_LPTIM_DirectionUpCallback
HAL_LPTIM_RegisterDirectionUpCallback
If one needs to unregister a callback, register the default callback via the registration function.
By default, after the HAL_LPTIM_Init() and when the state is HAL_LPTIM_STATE_INIT , all callbacks are set to the corresponding default weak functions.
Callbacks can be registered in handle global_state HAL_LPTIM_STATE_INIT and HAL_LPTIM_STATE_IDLE .
When the compilation define USE_HAL_LPTIM_REGISTER_CALLBACKS is set to 0 or not defined, the callback registration feature is not available and weak callbacks are used, represented by the default value in the table above.
Note
If needed, some configurations parameters can be changed on the fly (e.g: Period HAL_LPTIM_SetPeriod() ).
Note
If needed, some configurations parameters can be changed on the fly (e.g: PWM duty cycle HAL_LPTIM_OC_SetChannelPulse() ).
Note
In case of software start (external trigger not configured), call HAL_LPTIM_Start()
to starts the LPTIM counter for one-shot counting.
In one pulse mode the output waveform is similar to the one of the PWM mode for the first pulse, then the output is permanently reset.
Note
if needed, some configurations parameters can be changed on the fly (e.g: PWM duty cycle HAL_LPTIM_OC_SetChannelPulse() ).
Note
if needed, some configurations parameters can be changed on the fly (e.g: PWM duty cycle HAL_LPTIM_OC_SetChannelPulse() ).
Note
if needed, some configurations parameters can be changed on the fly (e.g: Period HAL_LPTIM_SetPeriod() ).
-