Maker Pro
Maker Pro

Quadrature encoder question

I have an encoder for a servo that gives out two quadrature sets of
pulses and a clock. How do I use this to detect position? Do I need
the clock or do I just read both outputs and watch one edge wrt the
other? I thought maybe an exclusive OR may tell me direction?

K.
 
J

Jamie

Jan 1, 1970
0
I have an encoder for a servo that gives out two quadrature sets of
pulses and a clock. How do I use this to detect position? Do I need
the clock or do I just read both outputs and watch one edge wrt the
other? I thought maybe an exclusive OR may tell me direction?

K.
A, B outputs leads or lags depending on what direction your moving.

For example.
lets say the rotor is turning CW, A output comes on before B output
does, and if it was CCW, B output comes on before A output.

You can use a dual Data RS flip flop to gate the pulses where
only one output will pulse depending on the direction or, you
can do it in software via a micro.


http://webpages.charter.net/jamie_5"
 
M

MooseFET

Jan 1, 1970
0
---

Assuming that your encoder output looks like this: (View in Courier)

______ ______
CHA ______| |______|

__ ______ ___
CHB |______| |______|

__
CHI_________________| |_______

Then your decoder could look like this:

+--------+
CHI>---------------|> QD|
| QC|
+-----+ | _ QB|
CHA>-----|D Q|---|U/D QA|
| _| +--------+
CHB>-----|> Q| UP/DOWN
+-----+ COUNTER
DFLOP

Where the dflop could be part of an XX74 or a 4013 and the counter
could be something like an XX190 or 191.

Rotation of the encoder shaft in one direction will cause the dflop's
output to be high, while in the other direction it will cause it to be
low. This will cause the counter to either count up or down, and the
index pulse from your encoder will cause the count to increment or
decrement once per revolution of the encoder shaft.

I think that you want to bring the other section of the DFLOP into the
circuit. CHI sets it. CHA clears it and its Q clocks the counter.
This way bobbling of the CHI edge won't cause multiple counts and
reversing back past the CHI pulse won't count the wrong way on the
first time by. This would also mean changing to a CD4013 flip-flop to
get the right polarity set and clear.

I have, in the past, decoded just the CHA and CHB to get 4 counts per
cycle. I was using a counter with an up-clock and a down-clock. The
decoder was logic in a 22V10. Basically it was like this:


CHA_DELAYED = CHA;

CHA_RISE = CHA & !CHA_DELAYED;
CHA_FALL = !CHA & CHA_DELAYED;

CHB_DELAYED = CHB;

CHB_RISE = CHB & !CHB_DELAYED;
CHB_FALL = !CHB & CHB_DELAYED;

UP_CLOCK = CHA_RISE & !CHB
# CHB_RISE & CHA
# CHA_FALL & CHB
# CHB_FALL & !CHA;

DOWN_CLOCK = CHA_FALL & !CHB
# CHB_FALL & CHA
# CHA_RISE & CHB
# CHB_RISE & !CHA;
 
I have an encoder for a servo that gives out two quadrature sets of
pulses and a clock. How do I use this to detect position? Do I need
the clock or do I just read both outputs and watch one edge wrt the
other? I thought maybe an exclusive OR may tell me direction?

K.

It sounds like a standard encoder, the "clock" is not a clock but a
zero marker, 1 pulse per rev, you use that to reset the counter for
absolute position. You need a 2 phase counter, they are common in
microcontrollers made for the motor control market. You could also use
a state machine in a pld to produce clock, up/down pulses or some
gating and one shot monostables for a conventional counter.
 
J

Jamie

Jan 1, 1970
0
Jerry said:
Good. There must be chips that do this, but It is easily done with
hardware or with interrupt-driven software. Do you want a display, an
updated variable in a computer, or both? Whatever you do, there can be
mis-counts unless the shaft locations are exactly the same when counting
up and counting down. The up- and down-count angles differ In
excessively simple implementations, and that leads to trouble.
"Solutions should be as simple as possible, but not simpler."

Jerry
Email me, I'll give you a PDF file that shows the use of 2 D-Ff with
a clear Function that can generate the up/down pulse just from the
A and B outputs only.
I don't have ASCII text options here to post something so I'll wing it.
Assume 2 D-FF's, 1FF and 2FF
On each FF, the Data input and CLR function pin are tied together.


(A) encoder signal is connected to the Clk(clock) of 1FF as well to
the Data/CLR pin function of 2FF.

(B) encoder signal is connected to the CLK(clock) of 2FF as well to
the Data/CLR pin function of 1FF.

The Q output of each D-ff forms the Pulse.
Q of 1FF will Pulse going CW.
Q of 2FF will Pulse going CCW.

These Pulses can be used to inc/dec a counter somewhere to indicate
position.

We use this circuit via a A/B encoder to determine the direction
and speed with a large accumulator system to govern forward speed
and direction of detection. The decoded signal then gets past into a
simple F/V converter to generate an analog signal proportional to the
speed of movement only on the forward direction for a drive using analog
biasing.

Happy benching.
http://webpages.charter.net/jamie_5"
 
S

Scott Seidman

Jan 1, 1970
0
[email protected] wrote in [email protected]:
I have an encoder for a servo that gives out two quadrature sets of
pulses and a clock. How do I use this to detect position? Do I need
the clock or do I just read both outputs and watch one edge wrt the
other? I thought maybe an exclusive OR may tell me direction?

K.

Theres a great circuit for quad decoding in Horowitz and Hill, The Art of
Electronics. I believe it uses two D flip flops and a bidirectional
counter.
 
S

Scott Seidman

Jan 1, 1970
0
[email protected] (Dave Platt) wrote in
Theres a great circuit for quad decoding in Horowitz and Hill, The Art
of Electronics. I believe it uses two D flip flops and a
bidirectional counter.

Depending on the speed required, one can also use a small
microcontroller. A simple lookup-table design (previous two
quadrature bits, current two quadrature bits) yields a +1/0/-1 counter
increment.
[/QUOTE]

My experience with quad encoders and ucontrollers is that if you're in for
a penny, you're in for a pound, and it really helps to use a unit designed
around quad encoders, like the Pic 18F4331. Otherwise, if your encoder is
going real fast, even a very basic interrupt driven lookup can fall behind.
The extra cost is negligible, and many features that help you tweak out
your system are at your fingertips.
 
Jamie,

Thanks for the offer. The email address in this post (and all my posts)
is valid and I'd like to see your circuit. (I have several patents for
encoder circuits, so I'm not a newbie in the field.) If one of the
inputs to your counter circuit is held steady and the other excited with
a steady square wave, what will the counter do? The combination of
inputs I described is possible in service in the presence of vibration.

If it is of interest to anyone, I'll work up and post a description of a
vibration-proof counter. any algorithm that counts down and up at the
same phase transition works.

I think thats pretty much a standard, not much use otherwise.
 
W

Walter Banks

Jan 1, 1970
0
I have an encoder for a servo that gives out two quadrature sets of
pulses and a clock. How do I use this to detect position? Do I need
the clock or do I just read both outputs and watch one edge wrt the
other? I thought maybe an exclusive OR may tell me direction?

Most of the quad decoders we implement, we over sample the inputs
(generally less than twice expected maximum speed) and use the current
and previous samples to determine motion and direction. This approach
is quite noise immune because edge effects are self correcting. This
approach takes very little processing time and a limited number of
external components.

In small micros used in the mice we sampled both axis at the same
time and used a 16 way jump to routines that updated both x and y axis.

Regards,
 
Top