You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a driver for the encoder mode of STM32 MCU LPTIM timers.
5
+
6
+
:warning: not yet tested
7
+
8
+
The LPTIM timers are low power timers available on some STM32 MCUs. Some LPTIM timers have an encoder mode (typically LPTIM1 and LPTIM2). Using this encoder class has zero MCU overhead as the hardware handles all the encoder counting. There is also no need for interrupt handlers, interrupts are not used. However, you must be sure to call `encoder.update()` frequently (at least 2x per revolution) to correctly keep track of the full rotations.
9
+
10
+
In theory the LPTIM timers can keep counting when the MCU is in sleep mode, but in practice tracking the full rotations would be difficult to achieve.
11
+
12
+
## Compatibility
13
+
14
+
Unfortunately, Arduino framework (stm32duino) provides no support for low power timers, and there is no "PinMap" to identify which pins are LPTIM outputs.
15
+
16
+
If you want to use this driver, your MCU has to be part of the custom `PinMap_LPTIM.c` file used by this driver. Currently, we've added the following MCUs:
17
+
18
+
- STM32G431KB
19
+
- STM32G431CB
20
+
- STM32G473QE
21
+
- STM32G431VB
22
+
23
+
Adding MCUs is not hard if you look at the format [in the file](./PinMap_LPTIM.c), and pull requests for other MCUs would be gladly accepted.
24
+
25
+
## Usage
26
+
27
+
Like all our encoders, you must specify the PPR (pulses per revolution). This number should come from your encoder's datasheet. Note: internally, the encoder will use a 4x higher CPR (counts per revolution) than the PPR value you provide.
28
+
29
+
You may need to enable the LPTIM in stm32duino:
30
+
31
+
```
32
+
-DHAL_LPTIM_MODULE_ENABLED
33
+
```
34
+
35
+
Its easy to use:
36
+
37
+
```c++
38
+
STM32LowPowerEncoder encoder = STM32LowPowerEncoder(4096, PB5, PB7); // 4096 is the PPR
0 commit comments