Author Topic: Quadrature encoder decoder chip.  (Read 18245 times)

0 Members and 1 Guest are viewing this topic.

Offline firewalkerTopic starter

  • Super Contributor
  • ***
  • Posts: 2450
  • Country: gr
Quadrature encoder decoder chip.
« on: October 06, 2011, 07:43:28 am »
Is there any chip for decoding quadrature encoders?

E.g.



When encoder at rest: Out-1, Out-2 to LOW.
When encoder CW: Out-1 pulsing according to the speed of turning the encoder.
When encoder CCW: Out-2 pulsing according to the speed of turning the encoder.


I know it can be done with an mcu (I have already implement it). I was wondering for a specific ic for the job.
Become a realist, stay a dreamer.

 

Offline buxtronix

  • Contributor
  • Posts: 25
  • Country: 00
Re: Quadrature encoder decoder chip.
« Reply #1 on: October 06, 2011, 11:11:50 am »
The MAX7360 has a rotary decoder, but wont give the output you want (it is i2c).

You're probably better off implementing it in a small MCU, its easy to get it to run with
one chip and no external components. And probably cheaper. Unlikely that there is
anything that gives exactly what you want.
 

Offline FreeThinker

  • Frequent Contributor
  • **
  • Posts: 791
  • Country: england
  • Truth through Thought
Re: Quadrature encoder decoder chip.
« Reply #2 on: October 06, 2011, 02:11:24 pm »
Not sure I understand what you are after but the system you describe made in think 'mouse' as a first thought. A single axis of the mouse would give you what you need, or if you need two discrete channels then use both axis. Any good for you?
Machines were mice and Men were lions once upon a time, but now that it's the opposite it's twice upon a time.
MOONDOG
 

Offline Zad

  • Super Contributor
  • ***
  • Posts: 1013
  • Country: gb
    • Digital Wizardry, Analogue Alchemy, Software Sorcery
Re: Quadrature encoder decoder chip.
« Reply #3 on: October 06, 2011, 06:11:17 pm »
Should be a pretty simple state machine. If you can't find a custom chip for the job then a PIC10 or 12 should be easy to configure.

Offline firewalkerTopic starter

  • Super Contributor
  • ***
  • Posts: 2450
  • Country: gr
Re: Quadrature encoder decoder chip.
« Reply #4 on: October 06, 2011, 07:23:42 pm »
I have already made what I want with an AVR.

I was wondering if there was a chip just for the job that would be potentially cheaper.
Become a realist, stay a dreamer.

 

Offline deephaven

  • Frequent Contributor
  • **
  • Posts: 796
  • Country: gb
  • Civilization is just one big bootstrap
    • Deephaven Ltd
Re: Quadrature encoder decoder chip.
« Reply #5 on: October 06, 2011, 09:45:32 pm »
I have already made what I want with an AVR.

I was wondering if there was a chip just for the job that would be potentially cheaper.

You can get a PIC10F204T-I/OT for £0.38 from Farnell (1 off), I doubt if you'll find a dedicated chip cheaper than that.
 

Offline BravoV

  • Super Contributor
  • ***
  • Posts: 7547
  • Country: 00
  • +++ ATH1
Re: Quadrature encoder decoder chip.
« Reply #6 on: October 07, 2011, 06:22:28 am »
I have already made what I want with an AVR.

I was wondering if there was a chip just for the job that would be potentially cheaper.

I don't think it will be cheaper, thats why it doesn't exist and they don't make it, its too expensive to design and produce such chip and probably will not sell either, this from chip maker's perspective.

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19342
  • Country: gb
  • 0999
Re: Quadrature encoder decoder chip.
« Reply #7 on: October 07, 2011, 05:10:28 pm »
The cheapest PIC is just over half the price of the cheapest AVR in RS Components: ATTINY4-TSHR costs £0.64 and the PIC10F200 costs £0.34.

The MCU you've used is probably overkill, use a cheaper one.
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11534
  • Country: my
  • reassessing directives...
Re: Quadrature encoder decoder chip.
« Reply #8 on: October 08, 2011, 01:04:05 am »
The cheapest PIC is just over half the price of the cheapest AVR in RS Components: ATTINY4-TSHR costs £0.64 and the PIC10F200 costs £0.34.
The MCU you've used is probably overkill, use a cheaper one.
i dont think attiny is overkill. i've done this exactly encoder with pic10f206, my limitation is it only can encode reliably up to ~100rpm. if i have 4x processing speed, it will be able to do up to 400rpm. this type of state machine is about speed, if your system got high rpm.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline NiHaoMike

  • Super Contributor
  • ***
  • Posts: 8972
  • Country: us
  • "Don't turn it on - Take it apart!"
    • Facebook Page
Re: Quadrature encoder decoder chip.
« Reply #9 on: October 08, 2011, 02:15:14 am »
Have you tried the MSP430? Even the cheapest one can run at up to 16MHz with most instructions only using one cycle.
Cryptocurrency has taught me to love math and at the same time be baffled by it.

Cryptocurrency lesson 0: Altcoins and Bitcoin are not the same thing.
 

Offline firewalkerTopic starter

  • Super Contributor
  • ***
  • Posts: 2450
  • Country: gr
Re: Quadrature encoder decoder chip.
« Reply #10 on: October 08, 2011, 11:07:11 am »
Well, the Attiny2313 was the first chip I found in my drawers with two external interrupts pins (there will be two quadrature encoders, and four outputs two for every encoder).

Alexander.
« Last Edit: October 08, 2011, 11:14:08 am by firewalker »
Become a realist, stay a dreamer.

 

Offline NiHaoMike

  • Super Contributor
  • ***
  • Posts: 8972
  • Country: us
  • "Don't turn it on - Take it apart!"
    • Facebook Page
Re: Quadrature encoder decoder chip.
« Reply #11 on: October 08, 2011, 12:51:53 pm »
Since its only task is to decode a quadrature encoder, try using polling instead of interrupts. On most processors, interrupts have a significant latency.
Cryptocurrency has taught me to love math and at the same time be baffled by it.

Cryptocurrency lesson 0: Altcoins and Bitcoin are not the same thing.
 

Offline buxtronix

  • Contributor
  • Posts: 25
  • Country: 00
Re: Quadrature encoder decoder chip.
« Reply #12 on: October 08, 2011, 01:42:21 pm »
Indeed, if the only thing your MCU is doing is decoding this, then polling is the way to go. Interrupts only make sense if your MCU has to also do something else.

Any MCU should be able to decode these at thousands of RPMs, unless your routine is complex. I have a routine that has 3 lines of logic code (and immune to switch bounce). Thats a pretty tight loop.
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11534
  • Country: my
  • reassessing directives...
Re: Quadrature encoder decoder chip.
« Reply #13 on: October 08, 2011, 02:12:17 pm »
Interrupts only make sense if your MCU has to also do something else.
or you want low powered (sleep), or there's not much rotation going on, like non continuous or only once a while in a day.
« Last Edit: October 08, 2011, 02:15:25 pm by Mechatrommer »
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline Rufus

  • Super Contributor
  • ***
  • Posts: 2095
Re: Quadrature encoder decoder chip.
« Reply #14 on: October 08, 2011, 03:01:50 pm »
my limitation is it only can encode reliably up to ~100rpm. if i have 4x processing speed, it will be able to do up to 400rpm. this type of state machine is about speed, if your system got high rpm.

Stating encoder rpm without stating encoder lines is completely meaningless. My rough estimate is a polled loop in a PIC10F2xx should be able to track about 1.5 million lines/minute.
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11534
  • Country: my
  • reassessing directives...
Re: Quadrature encoder decoder chip.
« Reply #15 on: October 08, 2011, 07:05:30 pm »
Stating encoder rpm without stating encoder lines is completely meaningless. My rough estimate is a polled loop in a PIC10F2xx should be able to track about 1.5 million lines/minute.
the same with stating encoder lines without stating what it can do or cant. my encoder was to (as usual) encode the rotation (from my old mouse encoder), keep track of previous and current state (4 quadrature state right?) so to be able to decide whether CCW or CW, and then increment or decrement a 32bit value (counter) to be reported back to main mcu when asked through 2pin uart like comm. the idea was to make zero processing in the main mcu (full processing and report mech. in encoder), the main mcu will get a nice 32bit value from pic10f by request. its by polling, and the encoding must not be stopped even while uart reporting. it took me 5 versions to get it speced properly at 100rpm (slightly more). now ask me to do it in 3 opcodes? i surrender.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline buxtronix

  • Contributor
  • Posts: 25
  • Country: 00
Re: Quadrature encoder decoder chip.
« Reply #16 on: October 09, 2011, 07:30:28 am »

This is my encoder routine for AVR. 2 lines of C code logic (more if you want to make it verbose).

Just add a counter and serial routines.

Code: [Select]
/*
 * Rotary encoder handler.
 *
 * This assumes wiper is ground, and 2 outputs are on PB0 and PB1.
 *
 * More info: http://www.buxtronix.net/2011/10/rotary-encoders-done-properly.html
 */
const char ttable[6][4] = {
  {0x3 , 0x2, 0x1,  0x0}, {0x83, 0x0, 0x1,  0x0},
  {0x43, 0x2, 0x0,  0x0}, {0x3 , 0x5, 0x4,  0x0},
  {0x3 , 0x3, 0x4, 0x40}, {0x3 , 0x5, 0x3, 0x80}
};

volatile char state = 0;

void rotary_init() {
  DIRB = 0x0; // PortB is input
  PORTB = 0x3;  // Weak pullup on PB0/PB1.
}

/* Read input pins and process for events. Call this either from a
 * loop or an interrupt (eg pin change or timer).
 *
 * Returns 0 on no event, otherwise 0x80 or 0x40 depending on the direction.
 */
char rotary_process() {
  state = ttable[state & 0xf][PORTB & 0x3];
  return (state & 0xc0);
}
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11534
  • Country: my
  • reassessing directives...
Re: Quadrature encoder decoder chip.
« Reply #17 on: October 09, 2011, 01:12:43 pm »
nice code bux, using lookup table with some sort of fancy indexing to get current state. with code in C, it could more lines when translated to assembly, not that really important as long as it works. but how do you make sure it is bounce free as you said?
edit i just read your site where you explained state 1,2,3,4. if we are at state 2, the only acceptable next state is either 1 and 3. jump to state 4 will be ignored right? well, in my case its possible. so we are working on different system. on high speed system, if it happens state 2 jumps to state 4, i will count as two click (count) and rotation direction is based on previous rotation. based on momentum law.
« Last Edit: October 09, 2011, 01:22:19 pm by Mechatrommer »
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19342
  • Country: gb
  • 0999
Re: Quadrature encoder decoder chip.
« Reply #18 on: October 09, 2011, 02:14:15 pm »
What sort of encoder are you using? An optical encoder shouldn't bounce.
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11534
  • Country: my
  • reassessing directives...
Re: Quadrature encoder decoder chip.
« Reply #19 on: October 09, 2011, 02:33:30 pm »
me? yes optical encoder, i dont have to handle bounce, only "jump" state. for lookup table as bux's method, pic10f will not be able to do, it only has 24 registers, no eeprom. it was cranking up every bit of it. so attiny should be more comfortable for my earlier job. but if its only for rotary encoder for user interface, like knob, then pic10f should be just fine, no need lookup table no need fancy codes, just code all you like. ymmv.
edit: btw, the OP method of CW pin1 pulsing and CCW pin2 pulsing is more elegant way i think compared to serial comm like method (if speed is a concern), its just the main mcu needs a little bit of + - algebra.
« Last Edit: October 09, 2011, 02:41:25 pm by Mechatrommer »
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline baljemmett

  • Supporter
  • ****
  • Posts: 665
  • Country: gb
Re: Quadrature encoder decoder chip.
« Reply #20 on: October 09, 2011, 04:44:14 pm »
for lookup table as bux's method, pic10f will not be able to do, it only has 24 registers, no eeprom.

Huh?  By my reckoning even a naive assembler translation of the guts of the suggested code above would only require two registers (the state variable and a temporary), 25 words of program space for the lookup table, and approximately eight words of program space for the rotary_process routine.  There'd be plenty of space in a 256-word PIC10F device, even after accounting for initialisation code, a main loop to poll rotary_process and pulse outputs as required, and me potentially miscounting lines of code when doing a quick compilation in my head...
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11534
  • Country: my
  • reassessing directives...
Re: Quadrature encoder decoder chip.
« Reply #21 on: October 09, 2011, 06:26:37 pm »
for lookup table as bux's method, pic10f will not be able to do, it only has 24 registers, no eeprom.
only require two registers (the state variable and a temporary), 25 words of program space for the lookup table
i know about two registers. but how do you access program space?
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline buxtronix

  • Contributor
  • Posts: 25
  • Country: 00
Re: Quadrature encoder decoder chip.
« Reply #22 on: October 10, 2011, 12:09:06 am »
if we are at state 2, the only acceptable next state is either 1 and 3. jump to state 4 will be ignored right? well, in my case its possible. so we are working on different system. on high speed system, if it happens state 2 jumps to state 4, i will count as two click (count) and rotation direction is based on previous rotation. based on momentum law.

So two things...

1 - If state is jumping from 2 to 4 directly, then something isnt right. It's always bad news if a state from your encoder is going astray. You either have something skipping a contact...or the MCU is not fast enough.

2- If there is a reason that cannot be otherwise fixed, it's not hard at all to modify the state table such that from state 2 to state 4, it emits a CW/CCW code. The Arduino library linked from my blog has the state tables more verbose (properly worded #defines), and emitting a code on a jump from 2 to 4 is possible (including adding a 3rd bit to indicate a double jump). Let me know if you'd like me to show the changes necessary.

 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11534
  • Country: my
  • reassessing directives...
Re: Quadrature encoder decoder chip.
« Reply #23 on: October 10, 2011, 04:36:11 am »
or the MCU is not fast enough... Let me know if you'd like me to show the changes necessary.
yes the problem is if the mcu is not fast enough. its ok i'm not into it anymore maybe next time. at least you showed one way of doing it.

for lookup table as bux's method, pic10f will not be able to do, it only has 24 registers, no eeprom.
only require two registers (the state variable and a temporary), 25 words of program space for the lookup table
i know about two registers. but how do you access program space?
let me answer my own question. even though there's no instruction in pic10f to access the program space directly, but maybe its possible using the program space in form of returning function. by manipulating its address or PC register. i never tried but i think its possible. pseudo code maybe like this...

Code: [Select]

//lookup table in program space
progAddr:
retlw 0x03
retlw 0x02
....
retlw 0x80

// the application
main:

;// do something to get something

PC = progAddr + state * 4 + PORTB ;//change program address to point to the lookuptable (retlw table)
state = W ;// new state

as i said, i never tried and it needs more work rather than this simple pseudo. just maybe.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline Rufus

  • Super Contributor
  • ***
  • Posts: 2095
Re: Quadrature encoder decoder chip.
« Reply #24 on: October 10, 2011, 05:44:30 am »
This is my encoder routine for AVR. 2 lines of C code logic
Code: [Select]
....
 * Revision 1.1  1992/12/03
....
static Byte bdata encstate; // Encoder state
sbit eap = encstate^3;
sbit ebp = encstate^2;   
sbit eac = encstate^1;   
sbit ebc = encstate^0;
....
    // Absolute position change indexed by new encstate
    static char code absdelta[] = {0, 1, -1, 0, -1, 0, 0, 1, 1, 0, 0, -1, 0, -1, 1, 0};

        // Maintain absolute position from encoder inputs
        eap = eac;
        ebp = ebc;
        eac = ENCAI;
        ebc = ENCBI;

        abspos += absdelta[encstate];

One of mine in 8051 C.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf