![]() |
Zap'Em Blast'Em Robots
robots that play laser tag!
|
Header file for encoder structure and read/setup functions. More...
#include <stdint.h>
#include "stm32f4xx_hal.h"
Go to the source code of this file.
Data Structures | |
struct | encoder_t |
Structure to hold encoder task configuration and state. More... |
Functions | |
void | setup_encoder (encoder_t *p_enc) |
Initializes the encoder by setting its zero reference. | |
void | read_encoder (encoder_t *p_enc) |
Reads encoder ticks and applies wrap-around correction. |
Header file for encoder structure and read/setup functions.
Created on: Jun 7, 2025
void read_encoder | ( | encoder_t * | p_enc | ) |
Reads encoder ticks and applies wrap-around correction.
Updates cumulative tick count and stores the latest tick snapshot.
p_enc | Pointer to encoder_t instance to read from. |
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 | ) |
Initializes the encoder by setting its zero reference.
p_enc | Pointer to encoder_t instance to initialize. |
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.