electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links  |  Store
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » Arduino
Using rotary encoder switches with Arduino
Post new topic   Reply to topic
Page 1 of 1 [5 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
v-un-v
Janitor
Janitor


Joined: May 16, 2005
Posts: 8932
Location: Birmingham, England, UK
Audio files: 11
G2 patch files: 1

PostPosted: Sun Jul 08, 2012 4:07 am    Post subject: Using rotary encoder switches with Arduino Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Send e-mail
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 20626
Location: The Netherlands, Enschede
Audio files: 150
G2 patch files: 318

PostPosted: Sun Jul 08, 2012 5:54 am    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Visit poster's website
v-un-v
Janitor
Janitor


Joined: May 16, 2005
Posts: 8932
Location: Birmingham, England, UK
Audio files: 11
G2 patch files: 1

PostPosted: Sun Jul 08, 2012 11:33 am    Post subject: Reply with quote  Mark this post and the followings unread

Thanks Jan. Smile

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
View user's profile Send private message Send e-mail
Blue Hell
Site Admin


Joined: Apr 03, 2004
Posts: 20626
Location: The Netherlands, Enschede
Audio files: 150
G2 patch files: 318

PostPosted: Sun Jul 08, 2012 12:01 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Visit poster's website
MusicMan11712



Joined: Aug 08, 2009
Posts: 734
Location: Upstate New York USA
Audio files: 148

PostPosted: Mon Jul 16, 2012 10:49 am    Post subject: Reply with quote  Mark this post and the followings unread

Is something like this useful? http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1292081426
Steve
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic
Page 1 of 1 [5 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » Arduino
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
e-m mkii

Please support our site. If you click through and buy from
our affiliate partners, we earn a small commission.


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use