Last 2 bits of register encoder bits
00 00
01 01
10 11
11 10
cur prev state
00 00 resample
00 01 cw
00 10 ccw
00 11 error
01 00 ccw
...
Hi to all,
I have seen or gates used and even diodes to get the 2 bits of grey code to the single interrupt pin of the PIC, and seeing as this is the first time I have used an Encoder and I am certainly NOT a PIC genius I thought I would ask the experts, some of you no doubt have experience of these.
Is there a tried and trusted or should I say widely accepted method of doing this?
The encoder will be used to determine the position of a car seat moved by a motor. The Encoder is a standard type with 20 detents and will not be turning fast, I'm guessing about 10RPM and maybe a couple of complete rotations from limit to limit, depending on how I gear the linkage, giving me about 40 positions in all. Hopefully I will have 3 control switches for the positions, 2 giving me the separate positions and the third to let me set the position in memory.
..Al
hi Al,
You say a 2 bit Grey code and the encoder has 20 detents.???
How many wires are coming from the encoder.?
Hi Eric,
There are 5 pins altogether on the encoders, 2 of them are the switch (momentary on) and the other 3 are A, B and Common, below is the link to where I bought them.
thanks for the input so far guys.
Regards..........Al
hi Al,
UIGC something dosnt add up.?
Using a meter on ohms can you map out the code appearing on the two wires with respect to the Common for each detent of the rotation.?
Hi Eric,
Its difficult with the meter as the pulse is between detents, so I'll breadboard it with a couple of LEDs and map it out like that, I'm hoping that will be easier?
Al
Hi folks,
On each notch CW first a then b lights momentarily.
On each notch CCW first b then a lights momentarily.
This is exactly the same for each subsequent notch, is this right?
Regards Al
On each notch CW first a then b lights momentarily.
Is this momentary for 'a' and 'b'
On each notch CCW first b then a lights momentarily.
Is this momentary for 'b' and 'a'
;
; poll the Rotary Encoder A and B switches
;
ISR_Encoder
movf PORTB,W ; get switch data |B0
andlw b'00000011' ; mask encoder B and A switches |B0
xorwf ENCOLD,W ; same as last reading? |B0
bz ISR_Next ; yes, branch (no change), else |B0
xorwf ENCOLD,W ; restore encoder bits in W |B0
rrf ENCOLD,f ; prep for B-old ^ A-new |B0
xorwf ENCOLD,f ; ENCOLD bit 0 = direction |B0
rrf ENCOLD,f ; now Carry bit = direction |B0
movwf ENCOLD ; update ENCOLD (new BA bits) |B0
;
; encoder position has changed but we only act on a change
; that occurs when the encoder falls into one of the detent
; positions (we ignore the changes between detents)
;
xorlw b'00000011' ; detent position (BA = 11)? |B0
bnz ISR_Next ; no, branch, else |B0
;
; increment or decrement position variable based on direction
; in the Carry bit
hi,
Strange readings.
Note: the contacts are only rated at 1mA, how much current is the LED passing.?
Still wondering if something is iffy though, can't see how that is grey code can you?
Al
Still wondering if something is iffy though, can't see how that is grey code can you?
Al
# binary Grey
0 00 00
1 01 01
2 10 11
3 11 10
Hi Al,
Its most likely as Mike says, 4 bytes/indent.
Can you try the scope, you should clearly see a pattern.
Its important that you know before you write any code.
Hi Eric,
I tried my scope but I am baffled as to what I'm seeing! Between every notch I get a deviation to the top then one to the bottom, reversed if I turn the other way of course. On the detents there is nothing on either channel.
I cant make out a pattern other than up down up down etc.
If you think its strange and maybe I'm doing something wrong I will try to video the scope display if it will help?
Regards.........Al
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?