Decent rotary encoders - Page 1
Forum section: electronics / projects

author: Rachie5272
author_rank: Regular Contributor
timestamp: May 27, 2016, 06:41:14 am
content: Can anyone help me pick out a quadrature rotary encoder? There are so many with near identical specs, and I have no idea which are the good ones. I'm making a human interface controller, and I need rotary knobs much like the ones used on audio mixers. I got some Bournes encoders once, and they weren't quite nice enough.I'm flexible on most of the specifications, but I want nice feeling detents, and a push button. I know this is asking for the impossible triangle, but can anyone recommend a decent quality encoder which isn't too expensive, and is available from Digikey or Mouser?

author: ZeroStatic
author_rank: Contributor
timestamp: May 27, 2016, 07:42:28 am
content: Rachie5272: Check out the Panasonic ones, I have used these and Bourns with great success.The specs are shaft type and length, detents, position resolution, size, what are you after?

author: Richard Head
author_rank: Frequent Contributor
timestamp: May 27, 2016, 09:58:53 am
content: I'm using the Bourns PEC-11 "Pro-audio" type for a product and can give the following feedback:1. It's really low cost, even from RS. Sometimes under 1$US for certain versions.2. It has an optional push button switch which is great.3. It has up to 24 detents per rotation, which is quite a fine resolution for my application.The issues I've had with it are:1. The push button has had some reliability problems that was discovered during the testing phase following manufacture. This was about 1-2% of units.2. There is often a problem with jumping between one click and the next, even though I have optimised the cap/resistor (10nF and 10k) values. It could also be software related but I don't think so. I used a scope to watch the transitions and adjusted the noise capacitor value till the waveform was clean without excessive delay.Dick

author: Pjotr
author_rank: Frequent Contributor
timestamp: May 27, 2016, 10:01:51 am
content: Quality of those encoders depends much on their price. If you want decent and reliable ones, avoid the el-cheapo mechanical contact ones and look for optical ones: Grayhill, Bourns. The good mechanical contact ones are also not low cost.

author: wraper
author_rank: Unknown
timestamp: May 27, 2016, 10:08:57 am
content: Quote from: Richard Head on May 27, 2016, 09:58:53 amIf your software was smart enough, any capacitors won't be needed at all. Flaky implemented debouncing is so common that it is just ridiculous.QuoteAgain with good debouncing, I guess, there won't be any problems at all.

author: Pjotr
author_rank: Frequent Contributor
timestamp: May 27, 2016, 10:39:07 am
content: Quote from: wraper on May 27, 2016, 10:08:57 amDespite that, you need to build in digital hysteresis to avoid jitter at the edge of the contacts for encoders without detents. I usually use a state machine for that. Optical ones are much less prone to edge jitter. Not cheap but still affordable are Bourns Pro Audio EM14 series, available from Mouserl, Farnell etc.

author: MarkF
author_rank: Super Contributor
timestamp: May 27, 2016, 02:59:51 pm
content: Quote from: Richard Head on May 27, 2016, 09:58:53 amJust a quick aside here. I'm using the PEC11 encoders also. What are your typical/average RC values? I'm currently using 10nF and 33k values which works most of the time but is a bit aggressive. Also from a software standpoint, I'm currently sampling at 250 Hz. How often do you sample the encoder pins? When turning the knob fast, the shortest wide I'm seeing is about 5 ms. Therefore, the minimum sample rate would be 200 Hz. Thanks.

author: Fungus
author_rank: Super Contributor
timestamp: May 27, 2016, 06:54:39 pm
content: Quote from: wraper on May 27, 2016, 10:08:57 amYep.Quote from: wraper on May 27, 2016, 10:08:57 amSad, but true.eg. Most Arduino libraries try to do it with interrupts.This is totally moronic, but necessary. The average Arduino programmer can't write a program that has a fixed update rate to save their life. Their code is just a big bunch of delay() functions and calls to things like the ultrasonic sensor library that can take 50ms to take a reading and return.What's the writer of a rotary encoder library supposed to do...? Most of them just shrug, attach the encoder to pins 2+3 (the Arduino interrupt pins) and tell people to put capacitors on the inputs.

author: rstofer
author_rank: Super Contributor
timestamp: May 27, 2016, 07:47:14 pm
content: On an AVR, I avoided RC networks and sampling by simply bringing the A-B signals in on separate edge triggered interrupts. I wrote a little state machine to track the possible transitions. You do, of course, have to change which edge you are looking for at every interrupt. If you just processed a rising-edge interrupt on a signal, the next interrupt should be on a falling edge. When you have seen all 4 interrupts in a given direction, do something.

author: Pjotr
author_rank: Frequent Contributor
timestamp: May 27, 2016, 08:01:03 pm
content: Using edge triggered inputs for noisy signals is a sure way to create problems. One of the first lessons basic digital techniques. Use sampling for that kind of signals.

author: rstofer
author_rank: Super Contributor
timestamp: May 27, 2016, 08:14:11 pm
content: The switch uses Gray encoding for the very reason that glitches won't cause a false count. Why bother with quadrature if you plan to hang a massive capacitor on each signal line? Just pick either the A or B signals and call it good.

author: Fungus
author_rank: Super Contributor
timestamp: May 27, 2016, 08:20:37 pm
content: Quote from: rstofer on May 27, 2016, 08:14:11 pmIn theory only one signal can be unstable at any given time.In practice? It works. I've not seen any problems even on the cheapest eBay rotary encoders. It's all down to the software.It's not difficult to do: Sample them at 1ms intervals and make sure a signal stays the same for two consecutive samples before you say it's "valid". Job done.(Same thing for push buttons, etc.)

author: iampoor
author_rank: Frequent Contributor
timestamp: May 27, 2016, 09:22:43 pm
content: Quote from: Richard Head on May 27, 2016, 09:58:53 amWhat issues did you have with the pushbutton?I am looking to standardize my products encoders and was looking at the PEC11 series.Also...instead of just an RC debounce, have you tried using a 74AHCT based circuit?Figure 3 on Page 15 seems to work pretty well (In My experience). Havent tried it on rotary encoders. Maybe its overkill?http://www.eng.utah.edu/~cs5780/debouncing.pdf

author: Fungus
author_rank: Super Contributor
timestamp: May 28, 2016, 10:48:26 am
content: Quote from: iampoor on May 27, 2016, 09:22:43 pmDid it just:a) Bounce more than you expected, orb) Fail to make contact?(b) sounds unlikely.(a) Is somethingallswitches do. You have to plan for it.External capacitors are generally a waste of time. The only time I'd use them is if the switch was feeding directly into a hardware counter which will increment on every single contact.If there's software in the middle then remove the capacitors and improve the software.(And if it's feeding directly into a hardware counter then cut the connection and put a tiny microcontroller in the middle)

author: Rachie5272
author_rank: Regular Contributor
timestamp: May 28, 2016, 08:26:32 pm
content: As much as I would love optical encoders, I can't find anything less than $25 each. How aboutthese Panasonic encoders? They're only $2.50 each. Any thoughts on the quality?As for debouncing, my plan is to connect the encoder pins directly to interrupt pins on a ATMega32u4, and use an Arduino interrupt library.

author: MT
author_rank: Super Contributor
timestamp: May 29, 2016, 02:15:00 am
content: Would also suggest Bourns PEC-11 "Pro-audio" we have used these in some stuff and they are alright.

author: linux-works
author_rank: Super Contributor
timestamp: May 29, 2016, 04:46:18 am
content: here's what works for me, on the arduino (using pins 2,3 - it must be those since there is a 'PIND' bit of magic going on):Code:// from http://www.circuitsathome.com/mcu/rotary-encoder-interrupt-service-routine-for-avr-micros#define ENC_PORT PINDvolatile int8_t pulse_dir; // -1, 0, +1 (for rotary encoders)volatile int8_t pulses; // we want to see 2 pulses in a row before we declare an inc/dec eventconst int8_t enc_states[] = { 0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0 };volatile uint8_t old_AB; //lookup table indexvolatile uint8_t new_AB;voidhandle_rotary_encoder_valueChanges (void){/** run the state machine for the volume control*/new_AB = (ENC_PORT >> 2); // Shift the bits two positions to the rightold_AB <<= 2; // remember previous state (2 bits, now pushed to the left)old_AB |= ( new_AB & 0x03); // add current state (2 new bits, ORed with the previous bits that were left-shifted)pulse_dir = enc_states[ (old_AB & 0x0F) ]; // using the combo of old,new bits, do a lookup to find the new statepulses += pulse_dir; // this shows us which direction to move the 'absolute value' to//// 'do something' with 'pulses', here//}I don't actually use interrupts, I just service this routine frequently enough in my main loop() and detect if old value is not equal to new value.it works great, it uses all 4 states and with most encoders, you can't over-run it.

author: rs20
author_rank: Super Contributor
timestamp: May 29, 2016, 05:10:48 am
content: +1Interrupts, RC circuits, external HC logic are all ineffective and/or needlessly expensive solutions. 500 Hz - 1kHz polling, as shown by linux-works above, is by far the easiest and best solution. Boggles my mind that people even try interrupts and RC circuits.

author: Rasz
author_rank: Super Contributor
timestamp: May 29, 2016, 05:26:58 am
content: Quote from: wraper on May 27, 2016, 10:08:57 amwoohooo hardware/software debouncing fight!http://www.ganssle.com/debouncing.htmhttp://www.ganssle.com/debouncing-pt2.htmcurrent microcontrollers have 70MHz for a reason, use it instead of spending $20 per encoder.

author: Fungus
author_rank: Super Contributor
timestamp: May 29, 2016, 07:43:06 am
content: Quote from: linux-works on May 29, 2016, 04:46:18 am(Not too fast, not too slow...)That's the entire trick, right there.

author: Pjotr
author_rank: Frequent Contributor
timestamp: May 29, 2016, 10:24:35 am
content: Apart from price, the basic difference between optical and mechanical encoders is speed and life time. Mechanical ones do not differ from mechanical switches and need de-bouncing of something of 10mS before feeding the channels to a state machine or whatever. The basic trick is: Sample the inputs at 1 kHz and feed the switch/channel signal to a 8-bit shifter. If the 8 bits of the shifter are not equal do nothing. If all bits are "1" set the signal bit to be used further to "1" and if all bits are "0" set the signal bit to "0".

author: Pjotr
author_rank: Frequent Contributor
timestamp: May 29, 2016, 10:47:23 am
content: Quote from: rs20 on May 29, 2016, 10:39:45 amPick what suits best

author: wraper
author_rank: Unknown
timestamp: May 29, 2016, 10:49:09 am
content: Quote from: Pjotr on May 29, 2016, 10:24:35 amFlawed trick. Waiting when it will stop bouncing completely, often will cause a missed reading (the most I hate in my home appliances when turning a rotary knob fast), or waiting for it slows down the response. I usually use counter where on adds 1 on each reading, off - substracts, and flips the output only when reaches 0 or max. If the signal is unstable, output will be delayed depending on the amount of instability, because the counter counts both ways. By this I don't care if the signal never really settles, because what I care the most is if button is pressed/encoder is turned and not completely stable signal from them. All I care is there is more "on" than "off" or vice versa.

author: Pjotr
author_rank: Frequent Contributor
timestamp: May 29, 2016, 10:56:29 am
content: Quote from: wraper on May 29, 2016, 10:49:09 amThat does basically the same but is more complex. The net result of 8-shifter is the same as a saturating 3-bit up/down counter: The signal must be stable for 8 samples to be reliable.

author: wraper
author_rank: Unknown
timestamp: May 29, 2016, 11:03:33 am
content: Quote from: Pjotr on May 29, 2016, 10:56:29 amNot the same at all, because if there is only one opposite reading in the shifter, it willneverdetect the transition.

author: rs20
author_rank: Super Contributor
timestamp: May 29, 2016, 11:10:02 am
content: Quote from: wraper on May 29, 2016, 11:03:33 amIndeed, but we seem to be talking about the case of a simple button? It's certainly anawfulidea to do this sort of debouncing on the two rotary encoder channels.It's much better to do the polling/state machine directly on the rotary encoder lines with no debouncing, and then do a sort of "debouncing" on the rotation output from the state machine. That way, you can make the user interface immune to little false turns while not compromising at all on its ability to handle fast rotation.With some rotary encoders, that "debouncing" could actually be as simple as dividing the decoded position by two, as illustrated by this picture I made for a totally different thread:EDIT: Fixed broken image link.

author: Fungus
author_rank: Super Contributor
timestamp: May 29, 2016, 11:16:29 am
content: Quote from: rs20 on May 29, 2016, 11:10:02 amAre you sure that's real?NOBODYwoulddesignan encoder with switching positions right on the detents. You need a complete cycle of pulses in-between each detent, it's necessary for the thing to work.That encoder (if real) is either broken or a messed-up prototype/reject.

author: wraper
author_rank: Unknown
timestamp: May 29, 2016, 11:22:42 am
content: Quote from: rs20 on May 29, 2016, 11:10:02 amWith such "simple" debouching you will have false output if both A and B bounce at the same time, they are moving mechanical contacts after all.

author: rs20
author_rank: Super Contributor
timestamp: May 29, 2016, 11:41:21 am
content: Quote from: Fungus on May 29, 2016, 11:16:29 amI absolutely agree that it sounds like a questionable design for a rotary encoder.However,Ididmake this image in response to some thread in this forum somewhere. I can't remember why, but I can only assume someone came across a real encoder like this. I'll try to find the original post and report back if I do.I must point out, though, that "you need a complete cycle of pulses in-between each detent, it's necessary for the thing to work" is not a true statement. You can see from the picture I posted, it can be made to work just fine?EDIT: See page 275 ofhttp://www.alps.com/prod/info/E/PDF/Switch/Encoder/EC11/EC11.PDF. There's a rotary encoder with the detents right on the transitions of B. Andthe forum thread where this was mentioned.But most importantly, none of this changes my overarching point that doing debouncing before the state machine is generally the wrong approach.Quote from: wraper on May 29, 2016, 11:22:42 amA. The divide-by-2 thing is just a simplistic example that happens to actually work in real life, much better than debouncing before the state machine. Didn't claim it was perfect.B. If you're turning the rotary encoder so rapidly that the bouncing of A is overlapping into the bouncing of B, how isanykind of debouncing going to be able to distinguish bouncing from the rotation itself? I claim that you're criticizing the behaviour of my design in a contrived scenario in whichanysoftware will produce erroneous output. In any case, I'd wait to see issues in practice with post-state-machine debouncing before deliberately destroying the ability of my solution to handle rapid rotation.

author: Fungus
author_rank: Super Contributor
timestamp: May 29, 2016, 11:47:05 am
content: Quote from: rs20 on May 29, 2016, 11:41:21 amI think it is.Quote from: rs20 on May 29, 2016, 11:41:21 amNope. Moving the knob from one detent to another isn't guaranteed to produce all the necessary state changes. Every single click has a small randomness factor in it.

author: rs20
author_rank: Super Contributor
timestamp: May 29, 2016, 11:53:41 am
content: A rotary encoder is shown on page 275 ofhttp://www.alps.com/prod/info/E/PDF/Switch/Encoder/EC11/EC11.PDFwhich has a detent sitting on every transition of the B signal.Quote from: Fungus on May 29, 2016, 11:47:05 amReferring to the example in the datasheet I linked:If you see a falling edge on A while B is high, or a rising edge on A while B is low, that's a clockwise rotation.If you see a falling edge on A while B is low, or a rising edge on A while B is high, that's an anticlockwise rotation.Disregard edges on B entirely (except of course, in keep state of what value B is for the value above).There it is, all the state changes required to completely unambiguously decode the position of the detent-every-2-positions encoder? What am I missing?

author: Pjotr
author_rank: Frequent Contributor
timestamp: May 29, 2016, 11:54:15 am
content: Quote from: rs20 on May 29, 2016, 11:41:21 amThat is not a fact but an opinion. Of coarse you can use the decoding state machine to catch up for erratic readings during bouncing. Simply provide states for it. A state machine is nothing more than a controlled (gray code) counter. But as usual, there are numerous ways to get the job done.

author: rs20
author_rank: Super Contributor
timestamp: May 29, 2016, 12:04:52 pm
content: Quote from: Pjotr on May 29, 2016, 11:54:15 amFair enough, point taken, I stated my point too forcefully. However, I would encourage anyone reading this to carefully study and understand the source of issues in their system and apply whatever fix makes the most sense for the signals they are getting.Debouncing after the state machine, as I propose, is more susceptible to interesting events like EMI events happening at the same time as encoder edges, and extremely late bounces from an a transition A happening coincident to an transtion on B.Meanwhile debouncing before the state machine severely hinders the ability of the decoder to hadle rapid rotation.How about we meet in the middle and agree that often, perhaps a mixed approach is appropriate -- for example, perhaps some very lightweight debouncing on the decoder inputs (think shifting bitfield of size 2, so that single-sample events are rejected), and then be perfectly happy that the decoder will still see some spurious inputs that will be handled afterwards. This gives reasonable immunity to EMI and late bounce events, while having a minimal impact on max rotation speed.

author: Fungus
author_rank: Super Contributor
timestamp: May 29, 2016, 12:05:02 pm
content: Quote from: rs20 on May 29, 2016, 11:53:41 amAh, I get it:Your encoder is detent-every-2-positions. Each detent gives a transition on A, B just tells you the direction the knob is turning (B is odd/even on every detent as you turn the knob).That will work, yes. Youonlyread B when you see a transition on A.

author: Robaroni
author_rank: Frequent Contributor
timestamp: May 29, 2016, 12:59:14 pm
content: I do a lot of encoders. I write my AVR progams mostly in assembly and I could add debounce but I find that the best solution is to build a mechanical debounce circuit, I've included one here that works well. On really scratchy encoders I use 100 nF caps but most times you can get away with 10 nF caps, especially on faster circuits.The first thing you have to decide with encoders is how often you utilize them in a circuit. If you just need an encoder to correct a RTC every few months then the ones from China will do the job cheaply. If you're using the encoder to as gain control on an audio device then you need a more robust one. For these I use the optical encoders like the Bourns 652-EM14AOL (Mouser). Of course you don't need the damping circuit just run the optical encoders directly.For super robustness I make my own encoders using ASM chips and Neodymium magnets (NdFeB) with ball bearing run shafts.If anyone wants the AVR assembly code let me know and I'll post it.Rob

author: Pjotr
author_rank: Frequent Contributor
timestamp: May 29, 2016, 01:28:06 pm
content: Quote from: Fungus on May 29, 2016, 12:05:02 pmGood point. First realise what's needed before providing a solutionIn this particular case no de-bouncing needed at all. But some 32 detent encoders use al four phases as separate positions.I do also a lot AVR assembly coding and the shift register de-bouncing is very easy/efficient to implement then and robust.

author: Robaroni
author_rank: Frequent Contributor
timestamp: May 29, 2016, 02:55:29 pm
content: If you use a full, any change of "A" or "B" with a detent encoder you will change when the encoder is half way between detents:Code:;int takes you hereEncoder:;* port pins must be moved to bits 0&1 position*in temp,PinB ;get pin changesandi temp,3 ;isolate pin 0 and 1;lsr and swap if necessary to move port pins used to bit 0 and 1 positionswap r20 ;swap old pin valuesor r20,temp ;orcpi r20,2 ;check if value = decrementbreq decrementcpi r20,35breq decrementcpi r20,49breq decrementcpi r20,16breq Decrementrjmp Increment ;not decrementIncrement:mov r20,temp; increment somethingretiDecrement:mov r20,temp;decrement somethingretiThis code monitorsbothencoder pins to the uC and increments or decrements on the change. I use this to design Digital Readouts for lathes and milling machines.The below code only interrupts on one uC pin, so it keeps changes aligned with detents. (A 16 position encoder operates 16 times per 360 degrees.) It's very simple, it monitors one encoder pin, if the pin is low it returns and does nothing, if the pin is high it checks the other encoder pin and increments or decrements as to the state of that pin.; for detent encoder use this to stop changes between detents;**ONLY use PCINT for one port, in this case use:; ldi temp,(1<<PCINT8)Encoder:sbis PinB,0reti ;A not high = returnsbis PinB,1rjmp Clock_Incr ;incrjmp Clock_DecrementretiRob

author: linux-works
author_rank: Super Contributor
timestamp: May 29, 2016, 02:58:33 pm
content: just bought a few of these, recently:http://www.ebay.com/itm/381383099441opto encoders, very high res, no bouncing, uses regular code that other encoders use. my c code worked perfectly as-is with these.they are larger and more expensive than the cheap 5cent encoders from china, but when I needed a GOOD volume control knob, I went with this. I can simulate a pot with this much resolution and have 1 turn lock to lock (no locks, continuous spin) to cover the full 127db range my preamp has.I hate the cheap encoders. I finally found one that is not expensive and still 100x better than the penny encoders.

author: Robaroni
author_rank: Frequent Contributor
timestamp: May 29, 2016, 03:11:16 pm
content: I see that's 24V. How many quad changes per revolution?If I use a 256 position digital pot I like to have two full turns for the total gain, especially since I use an LED display to give me the position (not the db level).Rob

author: BravoV
author_rank: Super Contributor
timestamp: May 29, 2016, 04:20:22 pm
content: All this time I'm spoiled and prolly lazy, as the arm mcu I'm using TI arm4f, has a dedicated peripheral that handle this rotary encoder by hardware. Btw, I'm a noob in mcu programming and just hobbyist level.Just wondering how you guys implemented "velocity" feature ?Really curious and eager to learn.

author: linux-works
author_rank: Super Contributor
timestamp: May 29, 2016, 05:04:17 pm
content: I hate velocity or acceleration. it drives me nuts. my 'curve' is not your curve and it causes over-run and back-off. its sloppy.I like steady auto-repeat on things. that goes for knobs, too. when I turn the knob, I want that action to be the same no matter what the computer thinks I want.there are other ways to get faster movement, but accel on knobs and arrow keys really is not the most usable way there is. its the most -obvious-, so it gets implemented (poorly) but its just not the best since users will over-run (go too far) and that loses any speed gains you think you have in this UI style.my style is a coarse and a fine set of adjustments. each with constant auto repeat. no sloppy over-runs by users that way, and the motion is predictable to the person, so it follows his command. its how UI's should really be, imho.

author: linux-works
author_rank: Super Contributor
timestamp: May 29, 2016, 05:09:42 pm
content: on the state machine that I posted, it gets all 4 changes for each event. I have to take the raw pulse count and divide it by an experimental number, and I found that 16 is the min I can live with, and 64 starts to make me turn the knob too many times. right now I'm at 16 or 24 modulo events, so every 24 real changes, I send one event to my app code. that slows things down, while still giving me a full twist to cover enough of the useful audio range that a vol control needs to cover.too bad these things don't allow for a push action. with those RE's, you could change resolution (as the app sees it) and have a coarse and fine step-size; push to toggle which mode you are in, and show it with some color led or other indication.the RE I have is 600 ticks/rev and I find that way too much. I ordered a 360 and I'll see how that goes. the less changes to the controller (arduino, for me) the better. I have to find the right balance on user feel vs cpu load. the whole thing is all about the user and it has to feel right, before anything else (that's how I approach UIs on devices).Quote from: Robaroni on May 29, 2016, 03:11:16 pm

author: linux-works
author_rank: Super Contributor
timestamp: May 29, 2016, 05:11:31 pm
content: pic I just took of my encoder installed in my diy audio chassis:I removed the old cheap style RE and threw this one in its place. it just barely fits since it was not designed for it. I'll have to redo the front panel now and give it more room and a better proper mount.I also need a knob, about that size, but with NO marking on it. all I can find is knobs with markings. drives me nuts

author: Pjotr
author_rank: Frequent Contributor
timestamp: May 29, 2016, 05:43:01 pm
content: Quote from: linux-works on May 29, 2016, 05:09:42 pmFor audio you can adapt the resolution to the level of attenuation: In the range of 0 to -20 dB you need more resolution than in the range below -40 dB. I did so with a look up table according to an audio taper curve from a Penny & Giles studio fader. Smoothed that curve with Excel and some curve fitting. Works pretty good with a natural feeling.In fact you don't need a rotary encoder for that. A good quality linear potentiometer and the build-in ADC of the MCU works as well.

author: linux-works
author_rank: Super Contributor
timestamp: May 29, 2016, 05:49:09 pm
content: on my design (LCDuino) I support motor pots just fine. for those that like it, its there for them.I personally don't like varied ranges. again, your curve or breakover point may not be what I feel is right and its that way with every user. it sounds good on paper, but I find it annoying in practice. speed sensitive knobs are the worst, but the whole concept just feels unnatural to me.when I turn a screwdriver, it always turns the same, no matter how hard or weakly I turn. its predictable. it does not have an 'automatic transmission' (lol) which is sort of what you are referring to.continuing that analogy, I guess I like the manual transmission and some others like automaticwhen you have enough steps, you don't need to play those multi-tier range tricks.also, one more secret; you can create a window (since this control is simply a UI device and no audio, in our cases, goes thru it). with a pot or rotary, you can define a min-val and max-val and then scale the useful range between that. for audio, I often set my min-vol to -70 or -80db and my max-vol to -10 (so that I don't blast my system by mistake). when I do that, a motor pot (cheap alps or bourns) works great even with arduino 10bit a/d. no jitter, no oscillation, minimal hyster needed to keep the set-value from moving due to noise. but if you go a whole 127db range (my atten moves at half-db steps) - then 255 steps on a 10bit a/d pot is too jittery and even walking on the floor can cause it to jump. by using the window trick, you solve many problems at once AND you set a safe mute level as well as a safe max-vol level.when I show people that window trick on my motor pot preamp, they all love it. and the UI lets you remap the min and max on the fly, as needed.

author: linux-works
author_rank: Super Contributor
timestamp: May 29, 2016, 05:50:20 pm
content: a useful link on that industrial RE:http://wemakethings.net/2014/05/26/rotary-encoder-teardown/not my blog, fwiw. but a useful link since there are few docs on those cheap china encoders.

author: HowardNamath
author_rank: Newbie
timestamp: May 29, 2016, 06:09:30 pm
content: Quote from: linux-works on May 29, 2016, 05:11:31 pmIt's not cheap, but is this maybe an option?http://www.digikey.com/product-detail/en/te-connectivity-alcoswitch-switches/KN1251B1-4/KN1251B1-4-ND/1201555

author: Pjotr
author_rank: Frequent Contributor
timestamp: May 29, 2016, 06:13:05 pm
content: Quote from: linux-works on May 29, 2016, 05:49:09 pmYou can't generalise that. Why do you think audio tapers are not linear in dB's? Those tapers evolved from a more than 60 years user experience.

author: linux-works
author_rank: Super Contributor
timestamp: May 29, 2016, 06:15:02 pm
content: and the 'audio tapers' vary like the wind. alps, themselves, have at least 3 or 4 that I know of. other brands have their own curves.some people think the curve idea is great. but its not for everyone and if you break free from that thinking and try alternatives, you may find that the 'old thinking' is actually quite stale.

author: linux-works
author_rank: Super Contributor
timestamp: May 29, 2016, 06:16:50 pm
content: Quote from: HowardNamath on May 29, 2016, 06:09:30 pmnot bad! I may give it a try.long term, I need to make friends with a cnc (or with a friend who's friends with a cnc)that way you can custom mill your own and have any size and feel to it you want. I'm not ready to pick up cnc skills, but someday...thanks for the link!

author: Pjotr
author_rank: Frequent Contributor
timestamp: May 29, 2016, 06:32:33 pm
content: Quote from: linux-works on May 29, 2016, 06:15:02 pmYes, and "new thinking" has to prove itself first. And yes, special people that can't do without their own customisation will continue to come alongI agree that dynamic adaptation feels unnatural. But static curve adaptation doesn't necessarily do so.

author: linux-works
author_rank: Super Contributor
timestamp: May 29, 2016, 06:48:07 pm
content: give it a try and you may be surprised.I've been using this style of attenuator (vol control) for about 7 yrs now. of the 500+ people that have downloaded my code and built my attenatuor project, not one has asked for a software patch to create different speeds based on where you are in the range. once they give the current setup a try, they are happy.maybe 7 years is not a long time, but I do eat my own dogfood (lol, that's the expression that's currently trendy; and its not literal, of course) and if it was not as usable as I say, I would have abandoned it for something else. all my diy audio systems are now like this, they have big-steps and small-steps (both settable by user) and having that dual speed constant repeat rate proves extremely usable, accurate and it does not 'fight' you.give it a try. you seriously may be surprised if you go into it with an open mind.

author: Robaroni
author_rank: Frequent Contributor
timestamp: May 29, 2016, 11:23:48 pm
content: What I find is that for most of my music I sit around a specific level. 255 steps is too much for me and too touchy on the control for one revolution.I think pots running db's are over rated. A linear pot will give you most of what you need and you can contour the algorithm to do what you specifically like. I divide encoders down often, a 255 works well in 64 or 128 detents and I do program for my sweet spot so that I have more control at my favorite levels.Let's face it, audio taper doesn't ever effect sound and if I really wanted an audio taper I could work it out in software.I've got EM14's running for years now with no problems, why fix it if it isn't broken? Encoders may look fancy but, again, they don't change the sound one bit.I personally don't like accelerators but this is also easy algorithm stuff if you do. I hate buttons! I design clocks of all kinds (I take care of the three story 100 year old clock in my village square, now that's a clock!). I always use encoders to change time the way real clocks work. My friends that get my clocks agree and so do my friends who get my audio designs.I like playing with audio but audio has so much hype that it borders on human stupidity. There's this guy Maplethorpe or something like that who thinks if the wires touch the floor it changes the sound, so he sells these 'T' poles to hang the wires from, and, of course, they're not cheap!. So I asked what the science behind it was. He said,"My ears." No kidding, you can't make this stuff up! I don't spend a lot of time on DIY Audio forums. rant over.....Rob

author: rs20
author_rank: Super Contributor
timestamp: May 29, 2016, 11:30:07 pm
content: Quote from: Robaroni on May 29, 2016, 11:23:48 pmI'd say whether accelerators are a good idea depends massively on the use-case. Accelerator on a volume knob? Crazy (in my opinion)! Accelerator for time-adjustment on an oven? Virtually essential!

author: Robaroni
author_rank: Frequent Contributor
timestamp: May 29, 2016, 11:33:45 pm
content: Quote from: linux-works on May 29, 2016, 06:48:07 pmIt's a pot, all it does is change the level. How many times do I change the level? What? Am I Herbert Von Karajan? All I want is to have it work without failing for 20 years if that.Rob

author: Robaroni
author_rank: Frequent Contributor
timestamp: May 29, 2016, 11:36:05 pm
content: Quote from: rs20 on May 29, 2016, 11:30:07 pmSure, no one said they didn't have their place but how many ovens are people adjusting? For me? None of the above....Rob

author: rs20
author_rank: Super Contributor
timestamp: May 30, 2016, 12:00:31 am
content: I'm setting 1h 40m for my slow-cooked pork curry all the time!! To be fair, though, I didn't design the rotary encoder software for the oven. I am, however, very pleased with the person who did.

author: Rachie5272
author_rank: Regular Contributor
timestamp: May 30, 2016, 04:54:08 am
content: Quote from: rs20 on May 29, 2016, 11:30:07 pmI've never used a decently designed accelerator on a clock or timer. They either tick along slower than rapidly pressing the button, or accelerate when you're least expecting it, causing overshoot. It would be so much simpler to install a ten minute button, but that costs an extra penny.

author: linux-works
author_rank: Super Contributor
timestamp: May 30, 2016, 05:31:52 am
content: Quote from: Robaroni on May 29, 2016, 11:33:45 pmyes, it changes the level, but for many of us, finding the exact sweet spot of volume is important (which is why my vol controls usually go down to half db steps). if its too loud, it clips (my hearing, that is) and too low, I don't get the feel of the full dynamics. as song volume changes from song to song or album to album, yes, I'm always on the vol control (the remote). and if there is applause at the beginning or end, I'll usually want to lower that quickly. accel does not do it fast enough but moving directly in big-steps (4db) with auto repeat lets me ZOOM up or down so fast, and so controlled.for the sweet spot, I'll move in coarse big steps, then tweak with 1 or .5db small-steps. again, no overshooting and it feels completely under YOUR control, not the cpu's.this has been a bit of an obsession with me and I've tried many different approaches and even various atten engines. I do consider myself somewhat of an expert after all this time and research I've put into it. once I settled on a strategy, I've been happily using it for all these years, now, and it still follows my commands precisely and efficiently.do most people care this much about their preamps and UI widgets? usually not. but I'm targeting the enthusiast and, well, yes - the control-freak, tooas for the pot, the pot will wear out in a few years. an opto rotary won't. no need to reread and average and smooth like you do on a carbon pot. no debouncing, either.

author: Robaroni
author_rank: Frequent Contributor
timestamp: May 30, 2016, 11:09:32 am
content: Yes, I know all that, I use optical encoders on my audio designs because I want them to work over the years as well as the day they went into service but let's accept our eccentricities. If you build these pots because you enjoy doing it that's fine but if you think you're hearing is that acute than I'll bet you're wrong. Take distortion, we really can't hear distortion below about 1% but 'audiophiles' fight over .05% distortion. You can't hear it - Period! Anyone who says they can has to be able to do it under a DBT (double blind test), an no one has yet. If two amplifiers subjected to an A/B subtractive test yield a null than you can't hear it. Period!People discerning the difference between two capacitors that I can't measure the difference between with sophisticated equipment. Right! I want to see them do it in a DBT.Audio 'experts' from a well known magazine were subjected to audio cables they were told were made of chicken wire complained about how scratchy they sounded, After the DBT they found out the cables were hi price audio products.Sam Tellig thinks he can hear the difference in the type of battery used in the light speed pot. What?? It varies an LED and is not even in the audio chain! It's scientifically impossible.I love clocks, I build clocks, both mechanical and electronic that are more accurate than I'll ever need but I accept it's me and that I'm doing it for fun. Go get your ears tested, that cochlea can only move so fast and as we get older it gets slower and slower. Art Dudley raves about sounds above his hearing range. I said, "Art, how about publishing a bode plot of your hearing spectrum.". "well, it's not what it once was." Is the best I got out of him.You've been doing it 7 years? I built my first stereo amp when I was 13, I'm 71 now and I have more audio designs published than I can count. Audio is 95% hype and 5% science. back in the 60's if it wasn't push/pull it was crap, today if it's not single ended it's crap.Look, have fun, enjoy life, enjoy building audio equipment with specially designed pots but don't think you've discovered the Holy Grail of pots. It's a pot!Rob

author: madires
author_rank: Super Contributor
timestamp: May 30, 2016, 12:00:52 pm
content: I like ALPS' rotary encoders. You can get them with or without push button, with or without detents, and different shaft types. Nearly no trouble with A/B changes at the detents. For demanding usage there are types with 1M cycles. The standard ones got about 15k or 30k cycles.My experience with reading rotary encoders is that polling works best (5ms-ish), and if you check for a proper Grey code sequence you have less problems with dodgy encoders or missed steps. Simply skip any invalid code sequences and wait for the next proper one. Based on the number of polling intervals between two steps in the same direction you can determine the velocity. A velocity aware UI is great for setting or adjusting something with a large range of values, like a frequency for example. 2 or 3 levels of acceleration work fine. But you should test different deltas for the acceleration levels to find the sweet spot for your application.

author: linux-works
author_rank: Super Contributor
timestamp: May 30, 2016, 01:39:09 pm
content: Quote from: Robaroni on May 30, 2016, 11:09:32 am(long tirade trimmed)wow, you went off on a tangent, there, dude.you don't quite understand what I'm saying. I'll just leave it at that.

author: Robaroni
author_rank: Frequent Contributor
timestamp: May 30, 2016, 02:29:31 pm
content: Not out to get you but when people start telling me they're an "expert" in the same breath they're talking about audio the flags go up, especially when they talk about the minute details of audio taper pots and half db increments.The voltage gain from 1 db to 1.5 db is about .067, that's what you're saying your ears are capable of differentiating.3 db doubles power but it takes about 10 db before we think the power actually doubled."A change by 1 dB is about the smallest change a human being can detect."http://physics.bu.edu/~duffy/py105/Sound.htmlSo, enjoy your hobby but unless you're conducting the New York Philharmonic you hear just about the same as the rest of us.Again, I'm not picking on you but let's put audio in perspective, it's not magic, it's science. This is how audio got to be voodoo with people spending thousands of dollars on silver audio cable.Sorry for my over rant, back to encoders.Rob

author: linux-works
author_rank: Super Contributor
timestamp: May 30, 2016, 05:59:47 pm
content: just to clarify, I'm over 50 (so, no spring chicken, either) and I've been doing audio projects for most of my life. the 6 years or so that I mentioned is how long I've been on THIS project; and not continuously, either, as most of the work happened that many years ago but its been under constant review and refinement since then.feel free to go check out my relay attenuator and if you have constructive comments, I'm all for hearing them:http://www.amb.org/audio/delta1/I designed the delta1, delta2 and LCDuino controller. the controller supports the relay atten (127.5db in half db steps) and also the TI pga23xx chip as well as the cirrus cs3318 8ch solid state atten. more 'engines' are planned as well, so that builders can decide the kind of atten engine they want (some are great for stereo, some don't scale well to multichannel, some are good for MC, etc).for control, the user can choose rotary encoders, analog pots, motor pots and there is IR and xbee/rf remote control as well.display is via standard hitachi 2x16 lcd display, but there are software patches for LED alpha displays as well as OLED graphic displays.the software took me quite a while to write and debug and its all open source, so nothing is hidden or obscurred. and this is not some audiophoolery; I (and my partner in business) do not believe in that and we only create things that have actual engineering principles behind them. I don't believe in 'power cords' and stupid crap like that, so don't think I'm any kind of golden ears type. my hearing is normal, not stellar and I try to design and build things that offer good value, have proper design behind them and give the best UI experience I can possibly create.at any rate, lets get back to the RE topic since we veered off a bit

author: linux-works
author_rank: Super Contributor
timestamp: May 30, 2016, 06:09:06 pm
content: Quote from: Robaroni on May 30, 2016, 02:29:31 pmjust have to address this. this is 1000% wrong.again, I'll refer to my own experience, just normal average hearing for a guy who is a bit older than middle age, and if I set the atten to move in half db steps, its pretty clear that you can tell that a step occurred..1db is very tiny; I once built a 1/10db relay atten (32db range for subwoofer trimming) and .1 db was insanely small, but I wanted to break the range down lower than half db and going with .1 made the most sense from a UI point of view.I could send you a vol control that has calibrated half db steps and I'm quite sure you'll notice every single step as long as its above a certain threshold. once things are down in the weeds, say 80db or so, I can't tell 80db from 80.5db. but at 20db down, yes, most certainly, 20 vs 20.5db is audible and since I'm sensitive to certain midrange freqs, if some singer is hitting one of those, I'll back it off a bit at a time and sometimes it just takes that half db step to 'cure' that problem for that instance.anyone is welcome to try this. as long as the sound is not so low that its near noise level, anyone can hear half db steps if they are sequenced like a normal volume control. now, if you structure your test so that you randomly jump around (which is not real world) and you jump from 20db to some other value, say 10, then over to 20.5 and ask if the 20 == 20.5, that would be hard since time passed. but AS YOU STEP from 20 to 20.5, yes, its quite audible and you may want to click up or down to find the exact spot that 'feels' right to you. having 1db steps is not bad, but half db is the right number for getting TO the spot that sits just right with your hearing.

author: Pjotr
author_rank: Frequent Contributor
timestamp: May 30, 2016, 07:32:17 pm
content: Quote from: Robaroni on May 30, 2016, 02:29:31 pmIndeed. And from a practical point, the useful range for a volume control for domestic listening is somewhere between -40 dB and -10 dB and 1 dB steps are fine enough. I made my relay attenuator with 0.5 dB steps just to make the jumps between steps inaudible. But it isn't strictly necessary. I control it with a good quality plastic film linear pot: -20 dB at "12 o'clock" as usual and - 40 dB at "8 o'clock". Below -70 dB it mutes. Satisfies my wife as wellAlthough I bended the curve this way, the resolution is still 0.5 dB from -70 dB to 0 dB. I can't help it, de ADC in my AVR mcu is 10 bits resolution, so why not?

author: Robaroni
author_rank: Frequent Contributor
timestamp: May 30, 2016, 08:52:16 pm
content: Quote from: linux-works on May 30, 2016, 05:59:47 pmI played with relay pots. (See AudioXpress Sept 2011 and Aug. 2012). In the end I abandoned the projects. Look at the signal path on your pot. The last design I did for Ax a few month ago has a signal path that's significantly shorter than just your pot. You want the shortest path possible.Problems:Long signal path, A digital pot like the DS1882 can sit right on the PCB next to the input.excessive noisemechanical contacts and switching noiseoverly complex, more components lower MTBF.too large, TSSOP 16 or 20 case with only an SPI or an I2C interface leaves the uC off the signal board with any digital interfacing.Now I use AD and Maximum pots with much better results, try them.You can hear the difference? Sure maybe if you're listening to the music and it's low but go out of the room and have someone change it and then see if you can discern half a db difference. I'll bet you can't.Rob

author: linux-works
author_rank: Super Contributor
timestamp: May 30, 2016, 09:14:04 pm
content: rob, my relay atten has passed 1mhz thru it just fine (as a test). and also as a test, since it had 127db of range, I needed to send 60v thru it just so my microvolt meter would register something above noise floor. the point is that the path is fine, its clean, its more than more than good enough for audio and if you follow it with a low noise buffer (it MUST have a follower) then its better than any solid state atten. I've done the testing.personally, I prefer the solid state attens like the PGA and cs3318. they are wonderful and for me, they are good enough. but if you care about which design performs better, its hand-down the relay r2r style atten. the relay contacts are absolutely not an issue, it would be absurd to even think to blame the relay contacts as long as you use good signal relays (which we do).and again, I already commented on the half db issue; and I ack'd that if you are not listening to a climb or descent (which is the ONLY way I use vol controls, they never jump randomly, lol) then you hear each step and you decide when you want to stop. I don't mind 1db but I do understand and see the value in half. all the solid state engines support half, too; why would that be if '1db is all you need'. the cirrus cs3318 goes down to 1/4 db, which I think it a little too much, but if it really was 1db as the 'understood' value for change, I don't think the vendors would spend their time making half db atten chips.

author: Robaroni
author_rank: Frequent Contributor
timestamp: May 30, 2016, 09:43:06 pm
content: Mine passed 1Mhz too but you still can't give me a relay pot, been there, did that, bought the shirt. Bottom line, can you hear the difference in a DBT?The PGA's introduce opamps into the circuit, take a look at what happens to the signal once you pass 0 db, if I remember it starts to go down hill.Manufacturer's sell 1/2 and 1/4 db pots for the same reason they sell wire that can run an industrial complex, people are gullible enough to buy it! Sorry, audio is the King's New Clothes, one guy says it and then someone else with just as little background parrots it. Now no one buys capacitor 'x' because it sucks. Hey, these guys are selling speakers that cost as much as a new house, what do you think they are going to tell you, go wash your face so you look better than I do!Nice chatting but we really should get back to encoders. (Sorry OP)Rob

author: Rasz
author_rank: Super Contributor
timestamp: May 31, 2016, 02:43:52 am
content: Quote from: linux-works on May 29, 2016, 05:11:31 pmLinux I found perfect knob for you, sadly it has been discontinued and 'Reference Audio Mods' went out of businesshttp://www.poormojo.org/pmjadaily/archives/009864.phpplease no pseudoaudiomumbojumbo in encoder theread

author: Robaroni
author_rank: Frequent Contributor
timestamp: May 31, 2016, 12:15:15 pm
content: If you are really going to make nice designs and nice knobs for any project you really need a small metal lathe. I make my knobs out of different materials from plastics to Stainless Steel. You can make that $485 dollar knob for about 50 cents in any wood you want.The trouble with wood is that it doesn't age that well in applications where it is constantly handled. Finishes wear off and, depending on the grain pattern, cracks can form. You can use woods like ebony or coco bola but metal works best. My favorite material is 303 SS, brass looks nice but you have to clear coat it and that wear off in time. SS looks the same year after year. 303 SS machines and polishes well (although I like a satin machined finish), requires no coating and lasts forever.Rob

author: mark03
author_rank: Frequent Contributor
timestamp: May 31, 2016, 03:31:02 pm
content: Back to the original topic (sort of):Does anyone know why optical encoders disappear below 5V? And why they consume so much power? All the ones I've come across seem wholly unsuited for portable or battery-powered projects, and I've always wondered why. All the demand is concentrated in the hi-fi market I guess?

author: Pjotr
author_rank: Frequent Contributor
timestamp: May 31, 2016, 04:00:58 pm
content: I was wondering that too. Modern leds can do with a fraction of a mA. You have the option to switch it on only when needed. But this only works for manual settings and you are in a setting mode/menu. Other options are magnetic encoders that work with a simple rotating magnet. They come in various flavours: With a simple sine/cos output or as absolute encoders with a SPI/I2C output. Have seen affordable ones with 14 bit resolution.

author: fcb
author_rank: Super Contributor
timestamp: May 31, 2016, 04:46:59 pm
content: Quote from: mark03 on May 31, 2016, 03:31:02 pmThey tend to have the LED dropper resistors built in, and most their market has historically been 5V - so they've done the calculations for 5V. Same goes for the signal processing on the optical receiver - history.I've used loads of AMS 5045 type magnetic encoder IC's in professional products, cheaper than an optical encoder in many applications.

author: Robaroni
author_rank: Frequent Contributor
timestamp: May 31, 2016, 08:23:14 pm
content: I use the AMS magnetic encoders also. The trouble with them is they draw 16ma. and require diametrically polarized magnets.I think they are mostly used in industry for radial angle applications.Rob

author: Robaroni
author_rank: Frequent Contributor
timestamp: May 31, 2016, 08:27:49 pm
content: There are guys on the net building their own, it's not that hard if you have a decent printer and some transparency film, I'll bet if you enclosed it you could get the LED current down under a ma. You could do hall sensors, the trouble is you can't get the detents in a small package.Rob

author: Rasz
author_rank: Super Contributor
timestamp: June 01, 2016, 10:38:34 am
content: Quote from: Robaroni on May 31, 2016, 08:27:49 pmor old mouse (ball or modern one with optical encoded scroll wheel)