Author Topic: Consumer grade optical rotary encoder  (Read 14524 times)

0 Members and 1 Guest are viewing this topic.

Offline npelovTopic starter

  • Frequent Contributor
  • **
  • Posts: 332
  • Country: bg
    • Microlab.info
Consumer grade optical rotary encoder
« on: September 04, 2016, 07:24:06 am »
Long time ago the PC mice were made with optical rotary encoders and they were cheap. Even the cheapest ones worked well (at least the rotary encoder part). Now everyone switched to mechanical rotary encoders. They are nasty to debounce - if you do it too much, you loose speed. If you don't - you loose/gain additional pulses. There are probably good onces which are expensive, but they'll still wear out and I heard of very expensive ones that failed.
I need a cheep rotary encoder like this one, but optical. Well it doesn't have to be $1-2. $5 is still a good price for optical one (that's the price of a cheap mouse). It doesn't have to be high precision like the ones used in industrial CNC machines. I need it for knob, not for location.
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5509
  • Country: gb
Re: Consumer grade optical rotary encoder
« Reply #1 on: September 04, 2016, 08:15:53 am »
I looked into this about three or so years ago, and didn't have any luck, at least not for a volume product.

In the end, as well as trying some expensive (tens of dollars) units, I sourced some via aliexpress or similar for about $3 a pop. When they arrived they turned out to be ex-equipment: they worked, but were spec'd at 5v, that may not be a problem for you, but my device was battery powered and didn't have a 5v power domain, although they did work at 3.3v, just. They are also reasonably bulky.

I am fairly sure that almost all consumer grade rotary encoders use mechanical contacts.

One further thing I was looking for was heavy, reasonably large sized knobs that look like they're not form the 50s. Like cheap optical rotary encoders, nice looking large shiny knobs are hard to find (ooh er missus*).

* Widely used response to a double entendre in the UK.
 

Offline electr_peter

  • Supporter
  • ****
  • Posts: 1615
  • Country: lt
Re: Consumer grade optical rotary encoder
« Reply #2 on: September 04, 2016, 12:43:21 pm »
I have just recently tested some cheap mechanical encoders and optical ones (CNC type with 100 steps). Short conclusion - just use anything optical if you can, cheap mechanical ones are horrible.

Mechanical encoders bounced like there is no tomorrow - whatever low pass filter (analog or digital) you implement, you are guaranteed to miss some pulses (especially at higher momentary turn speed). Turn knob faster and you don't even know whether waveforms could possibly come from an encoder. It is barely good enough for simple UI.
On the other hand, optical encoder provided very clean waveforms with no glitches and bounces - very easy to decode at any speed. I would strongly recommend using these if you fear about missing pulses or going in reverse direction (when knob is turned faster).

I used no name optical encoders (named "CNC 100 pulse encoder", ~50mm diameter), these go for $10-15 and use ~80mA at 5V DC. I can't suggest something cheaper and smaller, you have to look around. By the way, I can sell one these for lower price if you are interested in a knob only.
 

Offline ZeTeX

  • Frequent Contributor
  • **
  • !
  • Posts: 610
  • Country: il
  • When in doubt, add more flux.
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5509
  • Country: gb
Re: Consumer grade optical rotary encoder
« Reply #4 on: September 06, 2016, 09:41:00 pm »
http://www.ebay.com/itm/Rotary-Encoder-400P-R-6mm-Incremental-Optical-Shaft-Working-Measurement-5-24V-/171640123948?hash=item27f68c722c:g:90sAAOSwHmhV8Te8

That looks exactly like the ones I boughht a few years ago. The ones I had had varyng cable lengths, leading me to believe they are either ex-equipment or new old stock configured for a particular job.
 

Offline wraper

  • Supporter
  • ****
  • Posts: 19396
  • Country: lv
Re: Consumer grade optical rotary encoder
« Reply #5 on: September 06, 2016, 10:08:45 pm »
Mechanical encoders bounced like there is no tomorrow - whatever low pass filter (analog or digital) you implement, you are guaranteed to miss some pulses (especially at higher momentary turn speed). Turn knob faster and you don't even know whether waveforms could possibly come from an encoder. It is barely good enough for simple UI.
Low pass filter is not very useful for this purpose. You used a wrong tool to solve the problem.
 

Offline electr_peter

  • Supporter
  • ****
  • Posts: 1615
  • Country: lt
Re: Consumer grade optical rotary encoder
« Reply #6 on: September 07, 2016, 05:12:52 pm »
Low pass filter is not very useful for this purpose. You used a wrong tool to solve the problem.
Care to elaborate? I thought all improvements to mechanical encoder performance had came from low pass filter in analog or digital domain.

My problem with mechanical encoders that bounce is that they can skip pulses or go in reverse - and there is little you can do about it (at least without very high sample rate or specialised IC). This issue is especially anoying when quick turn (meaning that you do not take care to turn it slowly and consistently) of knob creates strange results in UI.

Optical encoders at least guarantee (up to a point, of course) that it will not skip pulses or go in reverse.
« Last Edit: September 07, 2016, 08:19:56 pm by electr_peter »
 

Offline tesla500

  • Regular Contributor
  • *
  • Posts: 151
Re: Consumer grade optical rotary encoder
« Reply #7 on: September 07, 2016, 06:07:06 pm »
Use a sin/cos hall sensor like MLX90316, and mount a magnet to the end of your knob shaft. You should be able to get resolution equivalent to a many hundred line encoder, and there are no contacts, rubbing parts, or optical paths to get blocked up with dirt.
 

Offline mark03

  • Frequent Contributor
  • **
  • Posts: 777
  • Country: us
Re: Consumer grade optical rotary encoder
« Reply #8 on: September 07, 2016, 11:37:06 pm »
Use a sin/cos hall sensor like MLX90316, and mount a magnet to the end of your knob shaft. You should be able to get resolution equivalent to a many hundred line encoder, and there are no contacts, rubbing parts, or optical paths to get blocked up with dirt.

A bit pricey, but at least there are some (from ams) that operate at a convenient voltage instead of 5V.  Power consumption is high while actually reading, but it looks like you can get < 100 uA for a reasonable cadence of ~ 10 Hz.  And you get absolute position for free.

Where do you find knob/shaft combos with bearings and a suitable "feel" to mount the magnet onto?
 

Offline wraper

  • Supporter
  • ****
  • Posts: 19396
  • Country: lv
Re: Consumer grade optical rotary encoder
« Reply #9 on: September 08, 2016, 12:43:40 am »
Low pass filter is not very useful for this purpose. You used a wrong tool to solve the problem.
Care to elaborate? I thought all improvements to mechanical encoder performance had came from low pass filter in analog or digital domain.
This debounce algoritm works great for any bouncing contacts http://auto.teipir.gr/sites/default/files/debounce_kuhn2005_1.pdf
But the most important for encoder, proper state machine which accepts only valid state changes should be used.
http://www.buxtronix.net/2011/10/rotary-encoders-done-properly.html
 

Offline linux-works

  • Super Contributor
  • ***
  • Posts: 2073
  • Country: us
    • netstuff
Re: Consumer grade optical rotary encoder
« Reply #10 on: September 08, 2016, 12:50:32 am »
https://www.amazon.com/gp/product/B00Y9KDDCY


a project I used that in (it works great):

 
The following users thanked this post: thm_w, jonovid

Offline electr_peter

  • Supporter
  • ****
  • Posts: 1615
  • Country: lt
Re: Consumer grade optical rotary encoder
« Reply #11 on: September 08, 2016, 05:42:15 pm »
Low pass filter is not very useful for this purpose. You used a wrong tool to solve the problem.
Care to elaborate? I thought all improvements to mechanical encoder performance had came from low pass filter in analog or digital domain.
This debounce algoritm works great for any bouncing contacts http://auto.teipir.gr/sites/default/files/debounce_kuhn2005_1.pdf
But the most important for encoder, proper state machine which accepts only valid state changes should be used.
http://www.buxtronix.net/2011/10/rotary-encoders-done-properly.html
Thanks, I will look into this a bit more more and compare with my current algorithm implementation.
Still, I do not expect to completely eliminate missed steps or wrong direction with mechanical encoder.
 

Offline darko31

  • Regular Contributor
  • *
  • Posts: 103
  • Country: cs
Re: Consumer grade optical rotary encoder
« Reply #12 on: September 08, 2016, 06:57:14 pm »
What's your price limit on a single encoder? There are bunch of cheap-ish chinese industrial encoders available for a reasonable price, as shown in previous posts, although nowhere near as cheap as mechanical, and they are rather bulky.
« Last Edit: September 08, 2016, 06:59:18 pm by darko31 »
 

Offline npelovTopic starter

  • Frequent Contributor
  • **
  • Posts: 332
  • Country: bg
    • Microlab.info
Re: Consumer grade optical rotary encoder
« Reply #13 on: November 01, 2016, 04:31:53 pm »
Well, I forgot to get back to this thread. I've read everything and I found out optical encoders for UI control are no longer a thing. Industrial incremental encoders have too much steps - like 400 per rotation. Also I don't know if they have well defined stops to avoid a stop between the steps (which can cause backward jumps). What I need is 24 step encoder.

The hall effect sensor seems like a nice idea to play with. There could be a problem if you need more than one knob close together. Also mounting can be a problem. the magnet has to be in the center of the axis for best results. An existing mechanical encoder can be used for the stops. May be if 2 magnets are mounted at 180 deg. from each other, one N facing down, one S facing down and the sensor is in the middle behind the mechanical encoder (maybe on the back of the PCB).
Here is a cheaper chip that could (probably) used for the same purpose:
http://www.digikey.com/product-detail/en/infineon-technologies/TLV493DA1B6HTSA2/TLV493DA1B6HTSA2TR-ND/5887140
 

Offline retrolefty

  • Super Contributor
  • ***
  • Posts: 1648
  • Country: us
  • measurement changes behavior
Re: Consumer grade optical rotary encoder
« Reply #14 on: November 01, 2016, 05:51:36 pm »
Well, I forgot to get back to this thread. I've read everything and I found out optical encoders for UI control are no longer a thing. Industrial incremental encoders have too much steps - like 400 per rotation. Also I don't know if they have well defined stops to avoid a stop between the steps (which can cause backward jumps). What I need is 24 step encoder.

The hall effect sensor seems like a nice idea to play with. There could be a problem if you need more than one knob close together. Also mounting can be a problem. the magnet has to be in the center of the axis for best results. An existing mechanical encoder can be used for the stops. May be if 2 magnets are mounted at 180 deg. from each other, one N facing down, one S facing down and the sensor is in the middle behind the mechanical encoder (maybe on the back of the PCB).
Here is a cheaper chip that could (probably) used for the same purpose:
http://www.digikey.com/product-detail/en/infineon-technologies/TLV493DA1B6HTSA2/TLV493DA1B6HTSA2TR-ND/5887140

 One thing you might check into is using small (cheap) stepper motor as an magnetic encoder. It does require a little analog signal processing but has been done. Don't have a link handy but perhaps google can find something on this.

 

Offline Dave

  • Super Contributor
  • ***
  • Posts: 1364
  • Country: si
  • I like to measure things.
Re: Consumer grade optical rotary encoder
« Reply #15 on: November 01, 2016, 06:38:35 pm »
Thanks, I will look into this a bit more more and compare with my current algorithm implementation.
Still, I do not expect to completely eliminate missed steps or wrong direction with mechanical encoder.
I recently wrote a state machine for reading a mechanical encoder. I wrote it so that it only registers a valid step when the knob reaches the second detent. If any of the pin states is skipped during a cycle, the step is ignored and it waits for the knob to reach a detent before continuing. The polling of the pins is done at 1kHz, which seems to work very well.

It does occasionally skip steps if you flick the knob real quick, but it never registers steps in the wrong direction.
<fellbuendel> it's arduino, you're not supposed to know anything about what you're doing
<fellbuendel> if you knew, you wouldn't be using it
 

Offline Someone

  • Super Contributor
  • ***
  • Posts: 5972
  • Country: au
    • send complaints here
Re: Consumer grade optical rotary encoder
« Reply #16 on: November 01, 2016, 09:53:41 pm »
Well, I forgot to get back to this thread. I've read everything and I found out optical encoders for UI control are no longer a thing. Industrial incremental encoders have too much steps - like 400 per rotation. Also I don't know if they have well defined stops to avoid a stop between the steps (which can cause backward jumps). What I need is 24 step encoder.

The hall effect sensor seems like a nice idea to play with. There could be a problem if you need more than one knob close together. Also mounting can be a problem. the magnet has to be in the center of the axis for best results. An existing mechanical encoder can be used for the stops. May be if 2 magnets are mounted at 180 deg. from each other, one N facing down, one S facing down and the sensor is in the middle behind the mechanical encoder (maybe on the back of the PCB).
Here is a cheaper chip that could (probably) used for the same purpose:
http://www.digikey.com/product-detail/en/infineon-technologies/TLV493DA1B6HTSA2/TLV493DA1B6HTSA2TR-ND/5887140
Alps have their smaller/lower cost magnetic encoder EM11B16140A4, you should see reasonable pricing in volume when ordering directly.
 

Offline mubes

  • Regular Contributor
  • *
  • Posts: 238
  • Country: gb
  • Do Not Boil
Re: Consumer grade optical rotary encoder
« Reply #17 on: November 02, 2016, 03:22:47 pm »
Based on a brilliant little article from http://www.mkesc.co.uk/ise.pdf , call the _check function from a pin interrupt or on a regular basis;

Code: [Select]
const int32_t _moveTable[] = {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0};

volatile struct
{
uint32_t ab;
int32_t psn;
} _p;


void _check(void)

{
    _p.ab = (_p.ab << 2)
         | (Chip_GPIO_GetPinState(LPC_GPIO_PORT, GETGPIOPORT(ROT_A), GETGPIOPIN(ROT_A)) << 1 )
         | (Chip_GPIO_GetPinState(LPC_GPIO_PORT, GETGPIOPORT(ROT_B), GETGPIOPIN(ROT_B)));

    _p.psn += _moveTable[(_p.ab & 0xf)];
}
 

Offline Fungus

  • Super Contributor
  • ***
  • Posts: 18106
  • Country: 00
Re: Consumer grade optical rotary encoder
« Reply #18 on: November 02, 2016, 04:31:14 pm »
Based on a brilliant little article from http://www.mkesc.co.uk/ise.pdf , call the _check function from a pin interrupt or on a regular basis;

No, don't. Interrupts garantee that you'll pick up every last bit of switch noise and create lots of potential software bugs/race conditions.

or on a regular basis;
Much better idea. A 1ms polling function usually works perfectly.
 

Offline npelovTopic starter

  • Frequent Contributor
  • **
  • Posts: 332
  • Country: bg
    • Microlab.info
Re: Consumer grade optical rotary encoder
« Reply #19 on: November 02, 2016, 08:34:37 pm »
Alps have their smaller/lower cost magnetic encoder EM11B16140A4, you should see reasonable pricing in volume when ordering directly.
16.60 EUR is a bit on the high side (farnell). Ordering directly from the manufacturer might save from the product price, but what about shipping? I buy from farnell using local distributor and I think they add 5% or 10%. If I want to buy 2 to 3 encoders it'll still be cheaper to order locally through farnell.
 

Offline npelovTopic starter

  • Frequent Contributor
  • **
  • Posts: 332
  • Country: bg
    • Microlab.info
Re: Consumer grade optical rotary encoder
« Reply #20 on: November 02, 2016, 08:46:44 pm »
Guys, making a better filter (analog or digital) or any other approach of improving the readings of an mechanical encoder is a battle that you'll eventually loose. These things age and oxidise and do all kinds of horrible stuff. mechanical switches are not supposed to work at these frequencies. When I turn a pot I'm not careful how fast I turn it. A low pass filter won't hurt the performance of a pot noticeably. So I do use a pot when possible, but when you have too many values to change and too little space on the box you have no choice. So unless you use insanely expensive encoder with thick gold plating mechanical is not the way to go. They put more gold in a $5 multimeter range switch than in a $2 rotary encoder.
I remember beating the crap out of cheap old mouses and they still go. Sometimes the photodiodes get misaligned and I have to push them back in alignment. One would thing that technology will improve and they will make these encoders smaller - in form factor of today's mechanical encoders or maybe a bit bigger, but not.

Well I ordered a few sin-cos magnetic sensors and I'll see what I can achieve with them.
 

Offline LaserSteve

  • Super Contributor
  • ***
  • Posts: 1580
  • Country: us
Re: Consumer grade optical rotary encoder
« Reply #21 on: November 02, 2016, 09:00:09 pm »
If you need a lot of them, try US Digital, but again, you need to order many, many, many parts to get the price down.

http://www.usdigital.com/

Steve

"Programming is more than an important practical art. It is also a gigantic undertaking in the foundations of knowledge"

Adm. Grace Hopper
 

Offline LaserSteve

  • Super Contributor
  • ***
  • Posts: 1580
  • Country: us
Re: Consumer grade optical rotary encoder
« Reply #22 on: November 02, 2016, 09:01:53 pm »
"Programming is more than an important practical art. It is also a gigantic undertaking in the foundations of knowledge"

Adm. Grace Hopper
 

Offline mubes

  • Regular Contributor
  • *
  • Posts: 238
  • Country: gb
  • Do Not Boil
Re: Consumer grade optical rotary encoder
« Reply #23 on: November 03, 2016, 12:02:45 am »

No, don't. Interrupts garantee that you'll pick up every last bit of switch noise and create lots of potential software bugs/race conditions.

Much better idea. A 1ms polling function usually works perfectly.

Yup. As it happens I do use this function under interrupt but with an optical quad encoder and never have problems.  If you're intending using it with a mechanical encoder then deffo take precautions, although the state machine implied by the bitshift will protect you to a limited degree.

...not sure I agree about your bugs/races though, all depends how you use the output..the above is obviously very pared down, and polling is the devils spawn when you're trying to save power.

DAVE
 

Offline viperidae

  • Frequent Contributor
  • **
  • Posts: 308
  • Country: nz
Re: Consumer grade optical rotary encoder
« Reply #24 on: November 03, 2016, 05:49:56 am »
Why not use the encoder from a mouse, like you already said? The scroll wheel in a modern mouse is still an optical quadrature encoder.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf