Skip to content

Incremental/quadrature encoder pulse timing for speed calculation using STM32 and HAL.

License

Notifications You must be signed in to change notification settings

ufnalski/incremental_encoder_pulse_timing_l432kc

Repository files navigation

Incremental/quadrature encoder pulse timing for speed calculation (STM32L432KC)

An STM32 HAL example of speed calculation using pulse timing.

Incremental encoder lab set

A timer in the encoder mode:

TIM Encoder Mode

A timer in the input capture mode:

TIM Encoder 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.

TIM Encoder 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.

Speed calculation: pulse timing vs. pulse counting

Missing files?

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.

Exemplary hardware

Libraries

Call for action

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!

Releases

No releases published

Packages

No packages published