rotory Encoder

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all

I am looking for some code to run an rotory Encoder.
I am useing BascomAVR and an 2313

thanks Ulf

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This Interrupt function is called about every 10 ms and checks if somebody turned the knob.

Be careful, not all rotary encoders use the gray code.

SIGNAL(SIG_OVERFLOW0) /* signal handler for tcnt0 overflow interrupt */
{
u08 temp;
static u08 knoppen=0;

temp=0;
if((knoppen & 0x03)==0x03){ /* Decode encoder if old value = ...11b */
knoppen=inp(PINB); /* estand inlezen */
if((knoppen & 0x03)==0x00)
temp=0x02; /* turned right */
else if((knoppen & 0x03)==2)
temp= 0x01; /* turned left */
}
knoppen=inp(PINB);
/* do something with the other buttons */
}

if the encoder is rotating very fast (on a motor) something like this could work better for you:

1. Connect one pin of the encoder to a external interrupt pin.
2. Connect the other pin to 'PinX'
3. Write a interrupt function which checks 'PinX' when the interrupt pin goes high
- If PinX is low: Encoder turned left
- If PinX is high: encoder turned right

Paul.

admin's test signature