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.
At the moment i am useing such code:

long int licz = 0;

SIGNAL (SIG_INTERRUPT0) { if (!(inb(PIND) & 8)) licz++; }

SIGNAL (SIG_INTERRUPT1) { if (!(inb(PIND) & 4)) licz--; }

int main(void) { outp(0, DDRD);

outp((1<<INT0)|(1<<INT1), GIMSK); outp((1<<ISC01)|(1<<ISC00) | (1<<ISC11)|(1<<ISC10), MCUCR); sei();

for (;;) ;

return 0; }

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) ? Maybe hardware counters implemented in AVR are able to count in both directions...

Thank you for advices and help Trix.

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

long int licz = 0;

SIGNAL (SIG_INTERRUPT0) { if (!(inb(PIND) & 8)) licz++; }

SIGNAL (SIG_INTERRUPT1) { if (!(inb(PIND) & 4)) licz--; }

int main(void) { outp(0, DDRD);

outp((1<<INT0)|(1<<INT1), GIMSK); outp((1<<ISC01)|(1<<ISC00) | (1<<ISC11)|(1<<ISC10), MCUCR); sei();

for (;;) ;

return 0; }

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) ? Maybe hardware counters implemented in AVR are able to count in both directions...

Thank you for advices and help Trix.