![]() |
Can Opener - ME 507
|
Class which operates an STM32 timer in quadrature encoder mode. More...
#include <encoder_counter.h>
Public Member Functions | |
| STM32Encoder (TIM_TypeDef *timer, uint8_t pin1, uint8_t pin2) | |
| Set up an STM32 timer to read a quadrature encoder. More... | |
| uint32_t | getCount (void) |
| Return the current position count from the timer. More... | |
| void | zero (void) |
| Set the counter reading to zero. | |
| void | pause (void) |
| Pause the counter so it won't update its count until resumed. | |
| void | resume (void) |
| Resume the counter so it will update its count when the encoder is moved. | |
Protected Attributes | |
| HardwareTimer * | p_timer |
| Pointer to the timer/counter to be used. | |
Class which operates an STM32 timer in quadrature encoder mode.
This class sets up a timer/counter which is capable of reading quadrature signals from an incremental encoder and provides a method for retrieving a count which corresponds to the encoder's position. The position will overflow, and this class doesn't deal with that – the user must periodically read the position and use it to update a position count with a large enough bit width that the full position reading does not overflow.
So far this class has been tested with the following timers and pins on an STM32L476RG:
TIM2 using pins PA0 and PA1 TIM3 using pins PB4 and PB5 TIM3 using pins PA6 and PA7 TIM4 using pins PB6 and PB7 TIM8 using pins PC6 and PC7 | STM32Encoder::STM32Encoder | ( | TIM_TypeDef * | timer, |
| uint8_t | pin1, | ||
| uint8_t | pin2 | ||
| ) |
Set up an STM32 timer to read a quadrature encoder.
This class prepares an STM32 timer in quadrature encoder reading mode, counting on each transition of either channel. It only works on timers whose hardware is quadrature compatible; check the data sheet to see which are. Each compatible timer must have the encoder connected to its channel 1 and 2 inputs; these inputs can only be connected to specific pins. For most timers there are two sets of pins from which we can choose. The alternate function tables in the STM32xxx data sheet shows which pins may be used with each timer.
This class has been tested on an STM32L476RG and may or may not work on other STM32 processors; see the TODO in the constructor.
Example:
| timer | A pointer to a TIM_TypeDef object, such as TIM3, which designates the timer to be used |
| pin1 | The pin to be configured for use with timer channel 1 |
| pin2 | The pin to be configured for use with timer channel 2 |
|
inline |
Return the current position count from the timer.