Rotary Encoder - Illuminated (RGB) (COM-15141)

This is a placeholder topic for “Rotary Encoder - Illuminated (RGB)” comments.



Rotary encoders can be used similarly to potentiometers. The difference being that an encoder has full rotation without limits (It just goes round and round). They … read more

Read more

2 Likes

Trying one of these for a radio project - 3 rotary encoder pins only

Couldnt get it to work with the software discussed (there seem to be a lot of solutions around!)



If I ground the common terminal and pullup the encoder A and B terminals and watch the output on a CRO, I get a brief transition Hi=>Lo with each detent of the encoder of about 30msec for the A pin. Both pins are otherwise HIGH all the time. The B pin goes low immediately for CCW rotation. For CW rotation the Hi=> Lo transition of the B pin is delayed by about 10-15msec

So I can detect rotation with an interrupt on the A pin and then determine direction depending on the state of the B pin. This does not appear to be just a switch/hardware arrangement - is there some internal electronics such as a monostable? If so how are they powered?

No Gray codes here as far as I can see. The datasheet does not enlighten me.



Anyone gt any ideas?

Thanks


4 Likes

Hi Oliver,

Would it be possible to send through a photo of how you have it setup? Its odd that the encoder springs back to a state between events.

Your scope should be looking a bit like this:


From the diagram in the datasheet it doesnt look like there is anything other than the mechanical connections.
Do you have another you could drop in to test alongside this one?

3 Likes

More experiments
It looks like it is a mechanical switch when tested with a multimeter
The detents are between contacts - ie both lines pulled high when the encoder is at a “detent” position
In between detents there is a contact for both A and B pins
The B line is delayed on CW rotation and the same time for CCW rotation. So the “state machine” approach to taming the beast wont work (will it?).
Will have to use debounce delays - device will be unreliable at high rotation speed. But I guess it is not designed for that. With a normal hand rotation the A line is low for 20- 50 msec and the B line about half that.

3 Likes

S 2.1 shows the signal pattern. The phase difference in the two outputs means that only one output changes state at any point. That is the necessary condition for a gray code. The sequence in which the code counts tells you the direction in which the encoder is rotating - 11 01 00 10 11 for CW and 11 10 00 01 11 for CCW.

4 Likes

Will try another similar device - I have ordered 2
The lows are only momentary on this device
Would be usable though with a micro - plenty of time to service an interrupt routine
I will send some CRO screen captures also for CW and CCW rotation
Setup
Arduino Uno
From the encoder to micro
GND to GND
A to pin 2
B to Pin 3 (for the hardware interrupts)
Pin pulled high with Arduino pullup

CRO Tek MDO3014 capturing one encoder movement detent to detent

4 Likes

5 Likes

4 Likes

Hi Oliver,

From the looks of it the wiringor the encoder itself might be off/faulty, if you have a moment could you send a photo?
The common should be the middle pin and the two channels are the ones beside it according to the datasheet although that might be wrong.

3 Likes

Ahh
Maybe I have the wiring wrong
I found a pinout somewhere (cant see it on the datasheet which is a basic omission) which suggested the end terminal was ground
This is supported by a multimeter test - no connection between other two terminals

4 Likes

Hi Oliver
The spec sheet says 24 pulses per revolution but does not say how many indents could be 24 12 or 48.
I am currently using 10 encoders in a project connected to a Leo Bodnar board which claims to look after switch debounce. Seems to do this quite well. While I was experimenting debounce was a problem. If you scroll down that data sheet a bit you will find a circuit (Fig 4) that uses 4 X 10k resistors and 2 capacitors. That arrangement does work (for my encoders anyway. Bourns manufactured) quite well with only the very very occasional glitch. My encoders are 18 PPR and 18 detents.

There are a few Arduino sketches for decoding and they all seem to work albeit in different ways. One involves using interrupts and comparing binary numbers and will give 4 events per indent. To get the proper number simply divide by 4.
Cheers Bob

EDIT: Just looked again. The number of detents is 24 which means you will get 4 changes of state per detent.

I think you could be wrong. The ones I have and every other one I have looked at have the centre pin as common and the two outer pins are switch A and switch B. If you turn the shaft at a constant speed the switches will be closed for equal time and open for equal time with a 90º phase shift. The open and closed times in your attached pics seem quite strange. If you are using an outside pin for common that might explain this.

4 Likes

Hi Liam

Where did you find that on this data sheet ???. I agree the common should be the middle.
Cheers Bob

4 Likes

Yes there seems to be a multitude of ways of handling it.
Some better than others
In my case I just want to know whether the encoder has been turned and the direction
I can sense this from the data
I could write a library to debounce the connections - the datasheet says 1-2msec but there may be noise from the sliding contacts also
Perhaps the way would be:
interrupt fro Pin A going low
Poll B
Next transition
If Lo to Hi CCW
If Hi to Lo => CW

Any inconsistent states could be ignored to improve noise immunity

But the device does not appear to work as specified - has the supplier changed it?
The datasheet could be improved - the lack of a pinout is a serious omission

I note Sparkfun do a board for these with I2C connectivity but the datasheet is the same
Seem to have lost the second device :frowning:
Will have to order some more or maybe a better quality encoder like a Bourns

3 Likes

Have tested with a multimeter - the only connections are between the end terminal and the other two and are between the detents - I can get a continuous short if I hold the shaft between detents

3 Likes

Hi Oliver
Try using the centre pin as common. I really think that is how it should be. You could look at Element 14, they stock literally hundreds of types and I think you will find pretty much all that have this sort of connection have the common on the centre pin. And yes, all the data sheets on this site I have had to look at are in English.
Cheers Bob

3 Likes

Hi Oliver

That would be the case too if the common is the centre pin and both switches are closed. You would have a connection all ways.
I think what I am saying if your connections are correct and you rotated the shaft in one continuous motion between detents you should not have got the waveforms you posted. You should have had one switch close then tho other 90º or half the closed duration after like as pictured in the data sheet.
Cheers Bob

3 Likes

Must be faulty - I have soldered to the pins - maybe the device did not tolerate this
I cannot get any connection between centre pin and one end, no matter how I rotate the shaft
The other end and centre gives me a short and also between the both ends, but only if I hold the shaft between detents
This would suggest that one end is the common
I am ignoring the 5 pins on the other side - these are the pushbutton switch and RGB LEDS
The mechanical drawing gives a pinout as you suggest with C in the centre
Oh well - will order a few more devices - maybe better quality

If I rotate the shaft continuously I get a series of pulses
enuff time spent on this…

3 Likes

Hi Oliver
This is the sort of thing I would expect to see.


Excuse the quality but pic taken with a camera. I know I can get screen shots via USB flash drive but it is a facility I don’t really use and no time to go looking up the book so took the easy way out.
Cheers Bob

5 Likes

Yes have a got another rotary encoder
Something wrong with that one
Screenshot


Seems to have fixed it
Thanks all

5 Likes

Mmm
Interesting discussion at Purchased my first Rotary Encoders. faulty or not? - #10 by system - General Electronics - Arduino Forum
Encoders were behaving like the one I have described above - ie at each detent both switches open circuit but making brief contact between detents - these appear to follow a Gray Code sequence between detents but are open circuit at “rest” - presumably to save pullup current
I have another encoder bought from Jaycar
In this case I have the opposite problem - with each detent both pins change state together!
I just want an encoder that will follow a Gray code sequence with each detent. (Grrr)

So all decoders are not created equal. We have quite a lot of variants which will be traps for young players :slight_smile:
(and no I am not a young player - have designed and built a lot of electronics over the years - thanks for all the help but I know what I am doing!)
Without fairly sophisticated test gear and knowledge a noob will not be able to work all this out
Variants
(1) Different Pinouts
(2) Transient make/break between detents
(3) Both pins changing state between detents - they do seem to follow a Gray code in between - a half step per detent (the JayCar decoder)
(4) Encoders generating pulses rather than a true “Gray Code” sequence as in the ones above
As I said above it appears you detect direction by the relative time of the B line transition vs the A
But this is not a Gray Code as both lines change together at the start or the end of the pulse. These are not “Quadrature Encoders”. So techniques to debounce them using state machines will not work. The datasheet with this device is clearly wrong - might I suggest that Core Electronics has a look at this?
All in all rather more complicated than I expected - a couple of days of hacking…

I still havent managed to find an encoder as described in all the sketches :slight_smile:

2 Likes