Low-power timer (LPTIM)
From the two external input signals, Input1 and Input2, a clock signal is generated to clock
the LPTIM counter. The phase between those two signals determines the counting direction.
The Encoder mode is only available when the LPTIM is clocked by an internal clock source.
The signals frequency on both Input1 and Input2 inputs must not exceed the LPTIM internal
clock frequency divided by 4. This is mandatory in order to guarantee a proper operation of
the LPTIM.
Direction change is signalized by the two Down and Up flags in the LPTIMx_ISR register.
Also, an interrupt can be generated for both direction change events if enabled through the
LPTIMx_IER register.
To activate the Encoder mode the ENC bit has to be set to '1'. The LPTIM must first be
configured in Continuous mode.
When Encoder mode is active, the LPTIM counter is modified automatically following the
speed and the direction of the incremental encoder. Therefore, its content always
represents the encoder's position. The count direction, signaled by the Up and Down flags,
correspond to the rotation direction of the connected sensor.
According to the edge sensitivity configured using the CKPOL[1:0] bits, different counting
scenarios are possible. The following table summarizes the possible combinations,
assuming that Input1 and Input2 do not switch at the same time.
Active edge
Rising Edge
Falling Edge
Both Edges
The following figure shows a counting sequence for Encoder mode where both edges
sensitivity is configured.
Caution:
In this mode the LPTIM must be clocked by an internal clock source, so the CKSEL bit must
be maintained to its reset value which is equal to '0'. Also, the prescaler division ratio must
be equal to its reset value which is 1 (PRESC[2:0] bits must be '000').
1032/1693
Table 164. Encoder counting scenarios
Level on opposite
signal (Input1 for
Input2, Input2 for
Input1)
High
Low
High
Low
High
Low
DocID024597 Rev 3
Input1 signal
Rising
Falling
Down
No count
Up
No count
No count
Up
No count
Down
Down
Up
Up
Down
RM0351
Input2 signal
Rising
Falling
Up
No count
Down
No count
No count
Down
No count
Up
Up
Down
Down
Up
Need help?
Do you have a question about the STM32L4x6 and is the answer not in the manual?
Questions and answers