[Dprglist] Encoder decoding, 2nd attempt
David Anderson
davida at smu.edu
Tue Feb 9 21:28:43 PST 2021
I realized my previous post doesn't make much sense without the
context. So here is maybe a better attempt at context.
This is derived from an email exchange with Murray and Dave Ackley. It
concerns decoding quadrature encoder signals.
Below is Murrays ASCII art waveform of two outputs of a quadrature
encoder, with my labels. Essentially two square waves 90 degrees out of
phase.
In the graph below high is logic 1, low is logic 0.
Forward ----> <---- Reverse
A rising fwd A falling fwd
A falling rev A rising rev
| |
V V
+---------+ +---------+ 1
| | | |
A | | | |
| | | |
+---------+ +---------+ +----- 0
+---------+ +---------+ 1
| | | |
B | | | |
| | | |
----+ +---------+ +---------+ 0
Forward is defined as moving left to right across the ASCII art graph. Reverse is moving right to left.
Channel A, rising edge.
Forward: A = 1 and B = 1
Reverse: A = 1 and B = 0
Channel B, rising edge.
Forward: A = 0 and B = 1
Reverse: A = 1 and B = 1
Channel A, falling edge.
Forward: A = 0 and B = 0
Reverse: A = 0 and B = 1
Channel B, falling edge.
Forward: A = 1 and B = 0
Reverse: A = 0 and B = 0
Dave pointed out that this can be reduced to two tests using a couple of
XORs. He added a column for the result of XOR'ing the two channels and
whether it increment or decrement the count.
The following differs from Dave's only in that encoder counts are
incremented in the forward direction and decremented in reverse.
Channel A, rising edge. XOR Action
Forward: A = 1 and B = 1 0 => increment \
Reverse: A = 1 and B = 0 1 => decrement \
\ Channel_A_Any_Change:
Channel A, falling edge. / If ( channel_A ^ channel_B) count--;
Forward: A = 0 and B = 0 0 => increment / else count++;
Reverse: A = 0 and B = 1 1 => decrement /
------------------------------------------------------
Channel B, rising edge.
Forward: A = 0 and B = 1 1 => increment \
Reverse: A = 1 and B = 1 0 => decrement \
\ Channel_B_Any_Change:
Channel B, falling edge. / If ( channel_A ^ channel_B) count++;
Forward: A = 1 and B = 0 1 => increment / else count--;
Reverse: A = 0 and B = 0 0 => decrement /
So when an interrupt happens on channel A, regardless of whether by
rising or falling edge, if (A XOR B) count--; else count++. Similarly
when an interrupt happens on channel B, regardless of edge, if (A XOR B)
count++; else count--;
thanks
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dprg.org/pipermail/dprglist-dprg.org/attachments/20210209/b60c2f3b/attachment.html>
More information about the DPRGlist
mailing list