10.4.1 General Approach

Regardless of the encoding technology (optical, magnetic or even contact based), a program needs to know when a transition occurs.

Without any hardware peripherals to assist, a program can still rely on a timer ISR to sample an encoder input line. The logic to do this was already discussed when we discussed general purpose input. Debouncing is usually not needed nor desired.

Detecting edges (transitions) this way is general enough that it'll work on most platforms. However, it is also limited in terms of performance. An interrupt frequency of 5kHz is considered fairly high. Even at this frequency, a program can only detect 2500 transitions per second. The frequency is divided by 2 because it takes two samples to detect one transition.

With a fine optical encoder disk with 500 slots, one revolution yields up to 2000 transitions because there are 4 transitions per period with quadrature encoding. As a result, we can only correctly interpret transitions up to a speed of 1.25r/s, which isn't exactly fast.



Copyright © 2006-02-15 by Tak Auyeung