Re: Atmel Avr, encoder's ticks counting (was: Atmel Avr, n-coder`s ticks counting)

Aug 23, 2003 0 Replies


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

The word "n-coder" is confusing me a bit, because "n" usually represents a natural number. It is also preventing search engines from finding your post. So please say "encoder". IMO "n-coder" is neither cooler nor shorter than "encoder".


decrementing while rotation in the left.

What kind of encoder are you using? I assume it is a quadrature, but am not sure.


The outputs of a quadrature decoder look like this, when turned in one direction (use a font with constant width to view)


__ __ __ A __ __ __



__ __ __ B _ __ __ _



Search the web for "quadrature decoder avr"


I think that counters implemented in AVR can count
> in one direction only.

You are right here ;-)


At the moment i am useing such code:

It is generally a good idea to mention what compiler and microcontroller you are using.


if (!(inb(PIND) & 8))

Recent versions of gcc don't need the "inb" function, just write if (!(PIND & 8)) or even better if (!PIND.3)


outp(0, DDRD);

Same as above for "outp". Better write DDRD = 0;



Can't say more about the code, until I know more about your decoder.



/Jan-Hinnerk



Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required