![]() |
Zap'Em Blast'Em Robots
robots that play laser tag!
|
High-level routines for initializing and reading a rotary encoder. More...
#include "encoder_driver.h"#include <stdio.h>#include <stdlib.h>#include <stdint.h>#include "stm32f4xx_hal.h"Macros | |
| #define | STALL_THRESHOLD 5 |
| #define | STALL_COUNT 20 |
| #define | STALL_DELAY_MS 10 |
Functions | |
| void | setup_encoder (encoder_t *p_enc) |
| Initialize encoder state. | |
| void | read_encoder (encoder_t *p_enc) |
| Read and accumulate encoder ticks since last call. | |
| void | wait_for_stall (encoder_t *p_enc) |
| Waits until the encoder motion stalls (no significant ticks change). | |
High-level routines for initializing and reading a rotary encoder.
Created on: Jun 7, 2025 Author: Andrew Carr and Kai De La Cruz
| void read_encoder | ( | encoder_t * | p_enc | ) |
Read and accumulate encoder ticks since last call.
Reads encoder ticks and applies wrap-around correction.
| p_enc | Pointer to an encoder_t instance. |
Computes the difference between the current timer count and the zero reference, applies wrap-around correction based on the encoder’s auto-reload value (p_enc->ar), and updates:
Wrap-around logic: If the delta exceeds half the auto-reload range, it is adjusted by ±(ar+1) to account for rollover.
| void setup_encoder | ( | encoder_t * | p_enc | ) |
Initialize encoder state.
Initializes the encoder by setting its zero reference.
| p_enc | Pointer to an encoder_t instance. |
Captures the current hardware timer counter as the zero reference, and clears both the cumulative tick count and the last-read snapshot.