DSPRelated.com
Forums
Online · Live + on demand
February 9-11, 2027
Price goes up Jan 1: register now to lock in today's rate
Register Now →

Quadrature encoder question

Started by Unknown ●April 6, 2008
Jamie wrote:
> Jerry Avins wrote: > >> 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. >>>> &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295; >>> >>> >>> 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 > 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.
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. Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
Scott Seidman wrote:
> kronecker@yahoo.co.uk wrote in news:076db4f6-3c70-4926-bbe8- > 0fed798cbefb@n1g2000prb.googlegroups.com: > >> 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.
The simplest circuit I know -- my patent has expired -- is an up/down counter and two XOR gates. Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
Jerry Avins wrote:
(snip)

> The simplest circuit I know -- my patent has expired -- > is an up/down counter and two XOR gates.
That only gets half the transitions, though, doesn't it? Last time I looked there is a design that uses a clock signal faster than the fastest transition (but slower than the counter) that can get all transitions. -- glen
glen herrmannsfeldt wrote:
> Jerry Avins wrote: > (snip) > >> The simplest circuit I know -- my patent has expired -- is an up/down >> counter and two XOR gates. > > That only gets half the transitions, though, doesn't it? > > Last time I looked there is a design that uses a clock > signal faster than the fastest transition (but slower than > the counter) that can get all transitions.
The output of the XOR xonnected to the direction input is the real LSB if you want all the transitions. With it, you get 200 counts with a 50-line wheel. Without it, you get 100. Many circuits would give you only 50. (When the raw photocell output is available, an extra pair of comparators can get you 400 counts.) Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
On Apr 8, 4:20&#65533;am, Jerry Avins <j...@ieee.org> wrote:
> Jamie wrote: > > Jerry Avins wrote: > > >> kronec...@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. > >>>> &#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533; > > >>> 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 > > 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. > > &#65533; &#65533;I don't have ASCII text options here to post something so I'll wing it. > > &#65533; Assume 2 D-FF's, 1FF and 2FF > > &#65533;On each FF, the Data input and CLR function pin are tied together. > > > &#65533; (A) encoder signal is connected to the Clk(clock) of 1FF as well to > > the Data/CLR pin function of 2FF. > > > &#65533; (B) encoder signal is connected to the CLK(clock) of 2FF as well to > > the Data/CLR pin function of 1FF. > > > &#65533; The Q output of each D-ff forms the Pulse. > > &#65533; &#65533; Q of 1FF will Pulse going CW. > > &#65533; &#65533; Q of 2FF will Pulse going CCW. > > > These Pulses can be used to inc/dec a counter somewhere to indicate > > position. > > > &#65533; 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. > > 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.
> > Jerry > -- > Engineering is the art of making what you want from things you can get. > &#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;- Hide quoted text - > > - Show quoted text -
Jerry Avins wrote:

(snip)

> The output of the XOR xonnected to the direction input is the real LSB > if you want all the transitions. With it, you get 200 counts with a > 50-line wheel. Without it, you get 100. Many circuits would give you > only 50. (When the raw photocell output is available, an extra pair of > comparators can get you 400 counts.)
Being too used to synchronous logic I didn't think about that one. The last one I worked on, in verilog below, takes the two phase inputs and clocks them into a register with a fast clock, and into another register after that. If there are an odd number of ones in the two registers, a transition occurred. An exclusive or between one bit of the first register and the other bit of the second gives the direction. The enable and direction signals go into a synchronous counter with the same clock. As long as the clock is faster than the time between real transitions it should get them all. I think one should zero the counter on the first pulse of the third signal line and not on any later pulse, but I was never sure about that. I didn't invent this one, I got it off the web and wrote the verilog for it. linem1 is the number of lines on the encoder wheel. Not being good at ASCII logic, here is the verilog. module quadrature(clk, reset, in, out, linem1); input clk, reset; input [1:0] in; output [17:0] out; input [15:0] linem1; reg [17:0] out; // shift register with extra stage for metastability reg [1:0] in0, in1, in2; wire enable, up; always @(posedge clk) begin in2 <= in1; in1 <= in0; in0 <= in; end // compare in1 and in2 to determine the new count // enable is an odd number of ones assign enable=^in1 ^ ^in2; assign up=in1[0]^in2[1]; // enabled modulo 4*linem1+4 up/down counter with asynchronous reset always @(posedge clk or posedge reset) begin if(reset) out <= 0; else if(enable) begin if(up) if(out< {linem1,2'h3}) out <= out+1; else out <=0; else if(out==0) out <= {linem1,2'h3}; else out <= out-1; end end endmodule -- glen
cbarn24050@aol.com wrote:
> On Apr 8, 4:20&#65533;am, Jerry Avins <j...@ieee.org> wrote:
...
>> 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.
Way back when, I was aware of one company that went bankrupt because they couldn't solve the problem at MHz fringe rates. The state-machine solution took a 3x5" circuit board and cost $175. The parts cost for my 35MHz version was about $6.00. I don't think that the schematic posted earlier in this thread or the verbal descriptions meet your standard. Jerry -- Engineering is the art of making what you want from things you can get. &macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;

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?
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, -- Walter Banks Byte Craft Limited Tel. (519) 888-6911 http://www.bytecraft.com