Quadrature encoder "decoding" - simple problem?

that

Very true on the rocking.

One of the complicating factors is that the bounce time can be several milliseconds, so if the knob is being turned rapidly at 4 edges per detent, and maybe 20 or 25 detents, and has a phasing spec that is very loose (due to mechanical tolerances on the stamped parts and alignment) you can get the bounce of one transition overlapping the next transition if a small knob is turned smartly.

A sophisticated algorithm might measure the time since the last count and if it is small, interpret sudden reversals of direction or "illegal" state changes as a further step in the same direction.. that could increase the maximum rate of rotation that the counter would reliably follow. Usually I just do a NOP and let the impatient user of the instrument twist the knob a bit more.

Reply to
Spehro Pefhany
Loading thread data ...

When I thought about this, it just seemed to beg for a '121 single shot. You want the following, I think, if I read your desires correctly:

A B What it does

---------------------------- _ _| 0 Increment

_ _| 1 Decrement

_ |_ 0 Decrement

_ |_ 1 Increment

A 74121 has two A inputs (not schmidt triggered directly) that respond to a falling edge and one B input (schmidt triggered) which responds to a rising edge. I think you said the A transition was probably safe to use, so it could feed both A and B inputs and produce a nice pulse of specifed length from both edges. You'd just need to route that pulse to either a down-count or up-count line.

Once A transitions, the knob is still moving towards that detent where it rests on a still-stable A value. Combining this after-trigger A value with the B value (still stable for a short period before the detent is reached) should allow you to direct the pulse to the right output... if the 121 pulse is short enough that the detent isn't yet reached. Since the system is mechanical and has a max rate of turn for it, I think you could achieve that requirement without problem. Once the 121 pulse dies, the routing logic will not permit runts from A or B through because the 121 output will be inactive and mask out their behaviors at other times.

A 1-2ms output pulse from the 121 seems nice to me. The timing from a detent position to the next A transition is, at its shortest, 12.5ms (taking into acount the +/- 3 degrees spec.) Chattering of B around the detent is itself 5ms, which I take to be +/- 2.5ms. So if the shortest time from A-edge to detent is 12.5ms and the earliest after that which a B-edge might occur is -2.5ms, you have a 10ms window there, from A-edge to worrying about B. So B should be stable for no worse than 10ms after the A-edge. The 1-2ms clock pulse should be able to work with stable A and B values on the combinatorial section, I think, just following the A-edge that triggered the 121.

I haven't thought more specifically than that. No time, right now. But that's what crossed my mind. There are lots of examples which use 4X overclocking and chains of D-flops around. But they aren't dealing with your exact situation.

Jon

Reply to
Jon Kirwan

I think I've done this part. With two inputs A and B (guaranteed in quad.) then I picture the inputs as forming a box, with the 'signal' going around one way or the other. ^A |

1+---+| | | | | | | 0+---+----> 0 1 B

You then count up for (say) clockwise.

^A |

1+->-+| | | ^ V | | 0+- 0 1 B

You then have to put that into logic, four condition lead to an increase. rising A edge and B low rising B edge and A high falling A edge and B high falling B edge and A low

Not sure what the clk pulses are?

George H.

Reply to
George Herold

Well, I guess I just spelled that out.

George H.

Reply to
George Herold

Cool, I think he might need two of the 121's, and some or's.

George H.

Reply to
George Herold

Yeah, that's actually what I first drew out because I knew it would be robust and work right. The fact that no two 121's will produce the exact same pulse width isn't really important in this application, either. So it is just fine. But then I wanted to imagine if only a one could be used. And I'm not yet convinced it can't.

Jon

Reply to
Jon Kirwan

Yup, that's the requirement as long as the coincidence of B transition and detent doesn't trip it up with unwanted output transitions.

?? There are two ways of approaching UP/DOWN counting - devices with separate Clk_Up and Clk_Dn inputs, or ones with an Up/Dn input and a Clk input. In the context of what I am seeking to do, either form of decoder output can be accommodated.

Reply to
who where

In every case I have had quadrature inputs, it needed to be a state machine. YMMV. Then again, it had to act on "illegal" transitions and there was already a micro...

--
Les Cargill
Reply to
Les Cargill

The spec sheet for the Panasonic encoder says A-COM is stable at the detent s which mark the B-transitions. So what is the problem with debouncing A fo r the maximum specified chatter time of 5 msec and sampling B-state??? All the A-transitions occur well away from the detents. The logic itself is sim ple: If the polarity of the A-transition is opposite the B-state then it is CW and if the polarity of the A-transition is same as B-state then it is CCW.

This is just a simple logic gate circuit shown below:

Reply to
bloggs.fredbloggs.fred

which mark the B-transitions. So what is the problem with debouncing A for the maximum specified chatter time of 5 msec and sampling B-state??? All the A-transitions occur well away from the detents. The logic itself is simple:

Yes, I agree that the logic is simple. What I'm trying to find is the equally simple way to implement it with a minimum of hardware yet retain the "idiotproofness".

I'm still looking down there ...

Reply to
who where

ents which mark the B-transitions. So what is the problem with debouncing A for the maximum specified chatter time of 5 msec and sampling B-state??? A ll the A-transitions occur well away from the detents. The logic itself is simple:

W

W.

In general terms this will do it: Please view in a fixed-width font such as Courier.

. . . . . _ . | | . - - . . A_TRANS>--------------. . | . | . ___ | . A_DB >--\\ \ | __ _ . || >---+--|----| \ | | . B >--//__/ | | | >-- CW - - . | +----|__/ . | | . | | . | | . | | . | | . | | __ _ . '--|----o| \ | | . | | >-- CCW - - . '-----|__/ . . . . A_DB = 5msec debounced encoder A output . . A_TRANS = transient High-going pulse on any transition +/- of A_DB . . B = encoder B output . . . . . SIMPLE A_TRANS TRIGGER CKT . _ . | | . ___ - - . A_DB >----+---------------------\\ \ . | || >-- A_TRANS . | __ __ .--//__/ . +--| \ .--| \ | . | | >-| | >--' . '--|__/ '--|__/ . . maybe more gate delays- use leftover gates . . total delay ----- DEBOUNCE -----> A_DB . . . .

Reply to
bloggs.fredbloggs.fred

like that

Main thing is it only updates whatever receives the INC output when contact 3 ( presumably A ) opens.

Reply to
bloggs.fredbloggs.fred

presumably A ) opens.

If you use a state machine (or some equivalent flags and jumps) you can make it work with any encoder regardless of where the detents are. That's a plus.

Best regards, Spehro Pefhany

--
"it's the network..."                          "The Journey is the reward" 
speff@interlog.com             Info for manufacturers: http://www.trexon.com 
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Reply to
Spehro Pefhany

( presumably A ) opens.

But isn't it important to detect all the transitions on that encoder output and not just one? Seems like he's thrown away half the resolution.

Reply to
bloggs.fredbloggs.fred

not just one? Seems like he's thrown away half the resolution.

Not really- there are four edges per detent on every mechanical knob enoder I've seen, and you only have to count up by one or down by one per detent*.

What you say is true for shaft encoders on motors etc., it would be throwing away half the resolution, but these guys have fixed stable posititions.

Best regards, Spehro Pefhany

--
"it's the network..."                          "The Journey is the reward" 
speff@interlog.com             Info for manufacturers: http://www.trexon.com 
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
Reply to
Spehro Pefhany

and not just one? Seems like he's thrown away half the resolution.

For info on the detents (ex olde Digikey cattledog):

formatting link

Reply to
who where

and not just one? Seems like he's thrown away half the resolution.

If he's using the -WTE encoder from

formatting link
, then that decoder misses the detents for A closed. It would work fine with the -VEM.

Reply to
bloggs.fredbloggs.fred

t

OK I guess that would work too. You get two pulses per turn versus, four with two 121's.

George H.

Reply to
George Herold

and not just one? Seems like he's thrown away half the resolution.

formatting link
, then that decoder misses the detents for A closed. It would work fine with the -VEM.

It is the -WTE ....

Reply to
who where

output and not just one? Seems like he's thrown away half the resolution.

formatting link
, then that decoder misses the detents for A closed. It would work fine with the -VEM.

If the encoder works the way they say it does then this should be pretty responsive. 74HC132 needed for pulse production and anti-race delay, not sure you even want to debounce B since it's unstable at detents anyway. It's three chips: Please view in a fixed-width font such as Courier.

. . VCC . +------+-----------------------+----------- . | | | . | | | . [10K] [10K] | . | | | . +------|-----------------------|----------> B . | | | . | | .---+ . | | 7.5ms debounce | | 555 . | | ---------- . | | | RST VCC | . | | | | ____ . | +-[68K]---+---+-|THR Q|-------> A_DB . | | | | | | . o o | '-|TRIG | . \ B \ A === | | . o o 0.1U | | GND | . | | | ---------- . | | | | . '------+---------+-----------+-------------- . GND . . . sample pulse generator . 74HC86:B . ____ ___ . A_DB >----+------------------------------\\ \ . | ___ HC132:A || >-> A_TRANS . -\\ \ __ .--//__/ . || >-[10K]----+--| \ | . VCC>---//__/ | | >o-' . +--|__/ 150us nom . 74HC86:A | . 0.1U === ________ . | __| |__ . GND . . . . delay 1.5us nom . . A_TRANS>----[10K]--+---. output clock steering . | | . 0.001U=== | . | | . GND | . ____ ___ | 74HC132:B . A_DB >--\\ \ | __ . || >---+----|----------| \ __ __ . B >--//__/ | | | >o-> CCW |________| . | +----------|__/ . 74HC86:C | | . | | 74HC132:C . | | __ 74HC132:D . '----|-----| \ __ . | | >o| \ __ __ . | VCC-|__/ | >o-> CW |________| . -----------|__/ . . . 74HC86:D . ___ . .--\\ \ . | || > . +--//__/ . | . GND . . . . . Both transitions of A are used to sense B, B is unstable at detents . . . Panasonic EVQ-WTE encoder . . .

Reply to
bloggs.fredbloggs.fred

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.