An STM32 HAL example of speed calculation using pulse timing.
A timer in the encoder mode:
A timer in the input capture mode:
Not any two timers would do the job. You have to choose timers that are connected in such a way that the pulse detection event from the timer in the encoder mode is able to trigger the timer that operates in the input capture mode.
Source: RM0394 Reference manual STM32L41xxx/42xxx/43xxx/44xxx/45xxx/46xxx advanced Arm-based 32-bit MCUs
Tip
If you want to go for very low speeds, you may need to monitor the overflow events for the timer in the input capture mode and count the number of them. Then you can use the number of overflows and the input captured value to get the time between two consecutive encoder pulses.
- Chapter 7. Enhanced Quadrature Encoder Pulse (eQEP) (Texas Instruments)
- How are encoders used for speed measurement? (Motion Control Tips)
- How to Estimate Encoder Velocity Without Making Stupid Mistakes: Part I (Embedded Related)
Don't worry 🙂 Just hit Alt-K to generate /Drivers/CMCIS/ and /Drivers/STM32L4xx_HAL_Driver/ based on the .ioc file. After a couple of seconds your project will be ready for building.
- DC motor with encoder (DFRobot)
- Rotary encoder module
- Tachometer GM8905 (Benetech)
- Tachometer AT-6 (CEM)
- Bidirectional 4-channel logic level shifter
- OLED display 1.3" (SH1106 or SSD1306)
- OLED: stm32-ssd1306 (MIT license)
Create your own home laboratory/workshop/garage! Get inspired by ControllersTech, DroneBot Workshop, Andreas Spiess, GreatScott!, ElectroBOOM, Phil's Lab, atomic14, That Project, Paul McWhorter, and many other professional hobbyists sharing their awesome projects and tutorials! Shout-out/kudos to all of them!
Warning
Control in power electronics and drives - try this at home ❗
190+ challenges to start from: Control Engineering for Hobbyists at the Warsaw University of Technology.
Stay tuned!