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.
Quadrature encoder question
Started by ●April 6, 2008
Reply by ●April 6, 20082008-04-06
kronecker@yahoo.co.uk wrote:> 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.Google is your friend. http://en.wikipedia.org/wiki/Rotary_encoder
Reply by ●April 6, 20082008-04-06
kronecker@yahoo.co.uk wrote:> 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?Two sets of quadrature pulses? Four tracks? what do you do with them? Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●April 6, 20082008-04-06
On Apr 7, 12:35 pm, Jerry Avins <j...@ieee.org> wrote:> kronec...@yahoo.co.uk wrote: > > 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? > > Two sets of quadrature pulses? Four tracks? what do you do with them? > > Jerry > -- > Engineering is the art of making what you want from things you can get. > �����������������������������������������������������������������������Oops - two only of course not two sets. K.
Reply by ●April 6, 20082008-04-06
kronecker@yahoo.co.uk wrote:> 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"
Reply by ●April 7, 20082008-04-07
On Sun, 6 Apr 2008 14:25:23 -0700 (PDT), kronecker@yahoo.co.uk wrote:>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?--- 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. JF
Reply by ●April 7, 20082008-04-07
On Apr 7, 5:50 am, John Fields <jfie...@austininstruments.com> wrote:> On Sun, 6 Apr 2008 14:25:23 -0700 (PDT), kronec...@yahoo.co.uk wrote: > >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? > > --- > > 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;> > JF
Reply by ●April 7, 20082008-04-07
On Mon, 7 Apr 2008 06:34:09 -0700 (PDT), MooseFET <kensmith@rahul.net> wrote:>On Apr 7, 5:50 am, John Fields <jfie...@austininstruments.com> wrote: >> On Sun, 6 Apr 2008 14:25:23 -0700 (PDT), kronec...@yahoo.co.uk wrote: >> >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? >> >> --- >> >> 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;--- OK. :-) JF
Reply by ●April 7, 20082008-04-07
kronecker@yahoo.co.uk wrote:> On Apr 7, 12:35 pm, Jerry Avins <j...@ieee.org> wrote: >> kronec...@yahoo.co.uk wrote: >>> 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? >> Two sets of quadrature pulses? Four tracks? what do you do with them? >> >> Jerry >> -- >> Engineering is the art of making what you want from things you can get. >> ����������������������������������������������������������������������� > > Oops - two only of course not two sets.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 -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●April 7, 20082008-04-07
Jamie wrote:> kronecker@yahoo.co.uk wrote: > >> 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.Can you offer a schematic? What happens when the encoder shaft vibrates just a little, causing repeated transitions on one track and none on the other? Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������






