Re: Atmel Avr, n-coder`s ticks counting

Hi Trix, in order to decode a quadrature encoder, you can put the A channel on the interrupt line, when you you get an interrupt on asy the negative edge you can read the B input to see what the direction of the encoder was. Schematically: St 012345 A 011001 B 110011 When you go from state 2 to 3, A causes the interrupt, and B is 0, that's one direction. When on the other end you go the other way, say from state 1 to 0, A causes the interrupt, and B is 1.

Cheers, Rik Assen. rik AT embeddedsystemconsult DOT nl (change AT to @ and DOT to .)

Reply to
Rikko
Loading thread data ...

Hello.

> >I would like to count n-coder`s ticks (channel A and B) >by use of AVR processor. >I think about that such variable is incrementing >while rotation of n-coder`s shaft in the right, and variable is >decrementing while rotation in the left. >I think that counters implemented in AVR can count >in one direction only.

As far as I know, when the counters are in "counting" mode, they will only count up. In PWM mode they do count in both directions but only in response to reaching an upper or lower count limit.

[snip...snip...]
The code shown above works well and I can achieve >frequency of counting which suits me. >I would like to get to know if there is better solution of >my problem (counting n-coder`s ticks in both directions) ?

Only recommendation is to ensure that you have taken precautions regarding the case where the encoder stops right over an edge and fires off constant interrupts. Possibly a hysteresis setup (which may be already built into the encoder) or, instead of firing an interrupt on an encoder event, run a tight timing loop and read the A-B conditions as inputs to a state machine.

--
Rich Webb   Norfolk, VA
Reply to
Rich Webb

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.