How to use the Rotary Encoder to control the cs3310 ?

Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.
AX tech editor
Joined 2002
Paid Member
You only need two input lines. Here's a bit of documentation from a project I did once:

;--------System design notes-------------------------------------
;
; The encoders output a 2-bit value:
; the A-bit signals rotation,
; the B-bit signals the direction of rotation.
; encoder movement is detected by polling and debouncing in the b-port.
;
;CW channel A ___ ___ ___ [channel A leads channel B]
; ___| |___| |___|
;
; channel B ___ ___ ___
; |___| |___| |___|
;
;
;
; CCW: channel A ___ ___ ___ [channel A trails channel B]
; ___| |___| |___|
;
; channel B ___ ___ ___
; __| |___| |___|
;
; A-bit B-bit Direction
; 0>1 0 CW
; 1 CCW
; 1>0 0 CCW
; 1 CW

You poll the A-bit (or hang it on an interrupt line) and then check the B-bit for direction of rotation. Ther's probably a ton of other ways to do this, this happened to work for me.

Edit: I realize the formatting is screwed up, if needed I can email it to you.

Jan Didden
 
AX tech editor
Joined 2002
Paid Member
You have to debounce the bits. At the moment the switches close/open they bang around some time, depending on the quality of the encoder, but they all do it. So once you detect bit change, you wait a couple of milliseconds (I forgot exactly how many, it's trial and error and depends as I said on the type/brand of encoder), then after the delay you check the bit values and do your processing.

Edit: I think I used 6 msec debounce. Can't take too long, else you miss some pulses if someone turns it real fast...

Jan Didden
 
AX tech editor
Joined 2002
Paid Member
cac liu said:
I think I start to understand what you have just say.

I get to try again !

Could you send me your program to me to be referance?

Thank you very much !!!


I'm sorry but there is no 'program' to speak of...
It depends on the microcontroller you use, in 'meta-speak', you can do (with polling):

- see if the A bit is different from last time you looked;
- if yes, wait the debounce period;
- test the A-bit status (one or zero);
- test the B-bit status;
-depending on one of the four combinations, go to a routine to do whatever you want to do as action to the encoder movement.

I did this in a PIC and it is just a bunch of bittest and goto statements, but embedded in the program so I can't really send it to you.

But if you understand the process it should be a no-brainer.

Jan Didden
 
Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.