Incremental Encoder Reader Circuit With Error Detection and Correction Using Microcontroller
Incremental Encoder Reader Circuit With Error Detection and Correction Using Microcontroller
00
10 01
The direction of the current state transition is determined
on the basis of two previous transitions. If the transition is
an FPT and an error has occurred, then the present state is
given by An = Bn − 1 and Bn − 1 = An − 1 ⊕ 1 and , if the
11 transition is an RPT, then the present state is given by
An = Bn − 1 ⊕ 1 and Bn = An − 1 . Thus, any error in the
signals A and B can be readily corrected. However, the
noise interference may be such that it gives rise to a valid
Fig. 2 State transition diagram of a biphase incremental encoder.
transition. The algorithm can be used to give the correct
Dashed lines indicate erroneous transition. number of transitions even in such a case. An error will
occur if due to the noise, a ‘1’ appears as a ‘0’ and vice
The above state diagram has been formed taking the value versa. If a spike occurs in any channel, it can be
of channel A as the msb ( most significant bit ) and the considered as an FPT and an RPT in succession. The
value of channel B as the lsb ( least significant bit ). The program uses a counter to store the number of transitions.
state transition from 00→01→11 →10 is denoted by FPT( The counter is incremented by 1 for every forward
forward pulse train )[2] and the state transition from transition and decremented by 1 for every reverse
00→10→11→01 is denoted by RPT ( reverse pulse train ). transition. Thus, there will be no change in the value of
The erroneous state transitions are shown by dotted lines. the counter due to the spike. If the spike triggers an
From the state diagram it can be seen that for no state erroneous transition, then the program will automatically
change, An ⊕ An −1 = 0 and Bn ⊕ Bn −1 = 0 where An correct the error and generate the correct state. This has
been explained with simulation diagrams in the next
and Bn denote the nth states of A and B. For an FPT, section.
An ⊕ Bn − 1 = 0 and, Bn ⊕ An − 1 = 1 and , for an RPT ,
An ⊕ Bn −1 = 1 and Bn ⊕ An −1 = 0 , provided a valid
transition has occurred. The program detects all the four
edges (Fig. 1) in a single cycle. So any missing edge must
be due to an erroneous transition. From the state
diagram(Fig. 2), it is seen that if any erroneous transition
occurs, then An ⊕ An − 1 = 1 and Bn ⊕ Bn −1 = 1 . This
algorithm forms the basis of decoding the positional and
directional information from the output signals of the III. IMPLEMENTATION
biphase encoder. However, there may be errors due to
excessive noise. There are two ways to handle this error: We have used Intel 8031 Microcontroller[3,4] to
(i) the program increments an error counter at every implement the reader circuit. We have also used UMPS
instance of an error and if the error counter exceeds a given demo version 1.75C to simulate the encoder reader circuit.
limit, it sends a proper signal to the main system , (ii) We have used DS80C320 microcontroller to simulate the
otherwise, the program automatically corrects the error. reader circuit. In both the hardware implementation as well
The error handling mechanism is explained in the next as the simulator implementation, channel A was connected
section. to port pin P1.1 and channel B was connected to port pin
P1.0. The interface output was seen at port pin P1.2. The
output shows a transition for every edge detected. The
number of valid transitions are stored in the register R0. Its
value is shown in the snapshots of the two simulation
B. Error Handling algorithm diagrams(Fig. 3 and Fig. 4) given below. In Fig. 3
below, we had taken two error free inputs as signals A and
The error handling algorithm follows readily from the B. We had simulated 8 cycles of signals A and B and the
previous algorithm. The error correction is done by first value of position counter stored in register R0 correctly
gives the number of transitions as 32. In Fig. 4 , we had
Proceedings of IETE 37th MTS:ICTIRD-2006, Kolkata, India P31-3
IV. CONCLUSION
V. REFERENCES