RE: [bascom] AVR: Rotary Encoders
Andrew,
Try this. I used optical encoders, a delay can be inserted and the time
delay must be suited to the specs of your mechanical encoder. I did not use
external pull up and enable the uC pull up, which is about 100K. Channel A
is ahead of Channel B by 90 degrees if turned clockwise.
Used 2313 on this one, you can use other uC but connect ChA to INT0
Dim Count As Integer
Ddrd = &H00 'Port D as Input
Portd = &HFF 'Enable Pull Ups
Config Int0 = Rising
'Configure INT0 for Rising Edge of the encoder
ChA Signal
Ch_a Alias Pind.2 'Channel A
connected to INT0 pin
Ch_b Alias Pind.0 'Channel B can
be connected to any other pins
Enable Interrupts
Enable Int0 'enable the
interrupt
On Int0 Chkpins 'jump to Chkpins
on INT0
Start:
Print "Current Count Is " ; Count
Idle
Goto Start:
Chkpins:
'Waitms 10
'insert this delay for debounce if you use mechanical
encoder
If Ch_a = 1 Then
If Ch_b = 0 Then Count = Count + 1 Else Count = Count - 1
End If
Return
-----Original Message-----
From: owner-bascom@grote.net [mailto:owner-bascom@grote.net]On Behalf Of
Andrew & Rhonda
Sent: Friday, September 07, 2001 2:54 PM
To: bascom@grote.net
Subject: [bascom] AVR: Rotary Encoders
Before I re-invent the wheel, has anyone interfaced a 2 bit gray scale
rotary encoder
to and AVR???
I was thinking -
Common to GND
A & B to AVR input port
Are the internal pull-ups enough???
I dont need to determine velocity, just count up & down
any help appreciated.
Andrew