| Author |
Message |
v-un-v
Janitor


Joined: May 16, 2005 Posts: 8902 Location: Birmingham, England, UK
Audio files: 11
G2 patch files: 1
|
Posted: Sun Jul 08, 2012 4:07 am Post subject:
Using rotary encoder switches with Arduino |
 |
|
Does anyone know how to use rotary encoders reliably with Arduino? _________________ ACHTUNG!
ALLES TURISTEN UND NONTEKNISCHEN LOOKENPEEPERS!
DAS KOMPUTERMASCHINE IST NICHT FÜR DER GEFINGERPOKEN UND MITTENGRABEN! ODERWISE IST EASY TO SCHNAPPEN DER SPRINGENWERK, BLOWENFUSEN UND POPPENCORKEN MIT SPITZENSPARKSEN.
IST NICHT FÜR GEWERKEN BEI DUMMKOPFEN. DER RUBBERNECKEN SIGHTSEEREN KEEPEN DAS COTTONPICKEN HÄNDER IN DAS POCKETS MUSS.
ZO RELAXEN UND WATSCHEN DER BLINKENLICHTEN. |
|
|
Back to top
|
|
 |
Blue Hell
Site Admin

Joined: Apr 03, 2004 Posts: 19598 Location: The Netherlands, Enschede
Audio files: 116
G2 patch files: 317
|
Posted: Sun Jul 08, 2012 5:54 am Post subject:
|
 |
|
This is what I used on a PIC ... not too efficient but it did the job
| Code: | code LpIntTMR3IF ( -- ) // Interrupt code
; [ --------------------------------------------------------------------- ]
; [ TMR3IF timer 3 overflow interrupt, must be cleared in software ]
; [ ]
; [ Interrupts every approx. every 100 us ]
; [ ]
; [ --------------------------------------------------------------------- ]
SetBSRDefault ; // Assure correct RAM bank
bcf pir2, TMR3IF ; // Clear the interrupt condition
; // reload the timer
movlw (( <@" tmr3_time">) >> 8) & 0xff
movwf tmr3h
movlw (( <@" tmr3_time">) >> 0) & 0xff
movwf tmr3l
call <@" _CollectRawInputs"> ; // Get physical inputs into wreg bits 0,1
; // Decode rotary, no debouncing used
movlw 0x03 ; // Isolate old state
andwf <@" RotaryState">
rlncf <@" RotaryState"> ; // shift it left over two bits
rlncf <@" RotaryState">
movf <@" InpStatus">, w ; // Or in new state
andlw 0x03 ; // as the low two bits
iorwf <@" RotaryState"> ; // to be kept for the next round
jr_f <@" RotaryState"> ; // Dispatch on old/new combination
bra t3_rot_done ; // 00 -> 00 nothing
bra t3_rot_up ; // 00 -> 01 up
bra t3_rot_dn ; // 00 -> 10 dn
bra t3_rot_done ; // 00 -> 11 nothing
bra t3_rot_dn ; // 01 -> 00 dn
bra t3_rot_done ; // 01 -> 01 nothing
bra t3_rot_done ; // 01 -> 10 nothing
bra t3_rot_up ; // 01 -> 11 up
bra t3_rot_up ; // 10 -> 00 up
bra t3_rot_done ; // 10 -> 01 nothing
bra t3_rot_done ; // 10 -> 10 nothing
bra t3_rot_dn ; // 10 -> 11 dn
bra t3_rot_done ; // 11 -> 00 nothing
bra t3_rot_dn ; // 11 -> 01 dn
bra t3_rot_up ; // 11 -> 10 up
bra t3_rot_done ; // 11 -> 11 nothing
t3_rot_up
incf16 <@" RotaryCount">
bra t3_rot_done
t3_rot_dn
decf16 <@" RotaryCount">
; // Fall through to rot_done
t3_rot_done
; // Rotary done, fall through
_Int_T3_Done
return ; // B/ ---->
endCode
|
_________________ Jan |
|
|
Back to top
|
|
 |
v-un-v
Janitor


Joined: May 16, 2005 Posts: 8902 Location: Birmingham, England, UK
Audio files: 11
G2 patch files: 1
|
Posted: Sun Jul 08, 2012 11:33 am Post subject:
|
 |
|
Thanks Jan.
How did you wire the encoders up to the PIC? _________________ ACHTUNG!
ALLES TURISTEN UND NONTEKNISCHEN LOOKENPEEPERS!
DAS KOMPUTERMASCHINE IST NICHT FÜR DER GEFINGERPOKEN UND MITTENGRABEN! ODERWISE IST EASY TO SCHNAPPEN DER SPRINGENWERK, BLOWENFUSEN UND POPPENCORKEN MIT SPITZENSPARKSEN.
IST NICHT FÜR GEWERKEN BEI DUMMKOPFEN. DER RUBBERNECKEN SIGHTSEEREN KEEPEN DAS COTTONPICKEN HÄNDER IN DAS POCKETS MUSS.
ZO RELAXEN UND WATSCHEN DER BLINKENLICHTEN. |
|
|
Back to top
|
|
 |
Blue Hell
Site Admin

Joined: Apr 03, 2004 Posts: 19598 Location: The Netherlands, Enschede
Audio files: 116
G2 patch files: 317
|
Posted: Sun Jul 08, 2012 12:01 pm Post subject:
|
 |
|
Pullup resistor from each input pin to Vcc, and each switch shorts it's input pin to ground when making contact. _________________ Jan |
|
|
Back to top
|
|
 |
MusicMan11712

Joined: Aug 08, 2009 Posts: 556 Location: Upstate New York USA
Audio files: 151
|
|
|
Back to top
|
|
 |
|