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

846 B

title summary chapter order tags estimated_minutes
Counting Direction and Steps Decode edges from the A and B channels to recover step count and direction. Reading Encoder Signals 2
decoding
interrupts
firmware
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.