quadrature-encoder-course/lessons/01-reading-encoder-signals/02-counting-direction-and-steps/counting-direction-and-steps.md

34 lines
846 B
Markdown
Raw Permalink Normal View History

2026-04-07 19:47:37 -04:00
---
title: Counting Direction and Steps
summary: Decode edges from the A and B channels to recover step count and direction.
chapter: Reading Encoder Signals
order: 2
tags:
- decoding
- interrupts
- firmware
estimated_minutes: 10
---
# Counting Direction and Steps
Once you can read the A and B channels, the next job is decoding.
The most common approach is:
- trigger on an edge
- read both channels
- use a lookup table or state machine to update the count
If your decoder sees illegal state jumps, you are probably dropping edges or reading a noisy signal.
## Practical notes
- Start with low shaft speed.
- Add debounce or filtering only if the hardware needs it.
- Test forward and reverse explicitly.
## Checkpoint
Write firmware that increments a counter when the shaft turns forward and decrements when it turns backward.