Using a rotary encoder - Page 1
Forum section: electronics / general

author: danjenkins
author_rank: Contributor
timestamp: February 08, 2017, 08:09:39 pm
content: Hi,The only 5 pin rotary encoders I have encountered used 3 for 'encoder' part and the other 2 pins were for a momentary push button in the shaft; I haven't seen one that names a 'CLK' signal etc. I'm trying to see activity in the serial monitor. The encoder in question is an Accu-Coder.http://www.clrwtr.com/PDF/Accu-Coder/Accu-Coder-260-Thru-Bore-Encoders.pdfThank you in advance for any help.

author: Benta
author_rank: Super Contributor
timestamp: February 08, 2017, 09:23:11 pm
content: No need for a clock signal, you have quadrature outputs.The tried-and-true way is to nominate one of the outputs as clock, using one of the edges as reference.For the device in your link, I'd suggest using the B positive edge as "clock". This will enable you to store A and index states as the encoder turns.

author: testian
author_rank: Regular Contributor
timestamp: February 16, 2017, 12:21:59 pm
content: Have you connected it directly to an serial port?The output is not a serial signal it is a quadrature output. You can use an Arduino to conenct the encoder and the sending the results via the serial interface.

author: Codebird
author_rank: Regular Contributor
timestamp: February 16, 2017, 12:40:56 pm
content: The output is in a form you can't do much with directly. You need to convert it for your application.If you just want speed, that's easy: Frequency of either A or B will give you that. And counting pulses will let you count how many times the shaft has been rotated. If you don't need to detect direction then you only need one output.If you want to know the direction too, then you need both. And a latch - either in discrete logic, or software in your microcontroller.

author: fki82
author_rank: Contributor
timestamp: February 19, 2017, 03:51:42 pm
content: have a look at this:https://tkkrlab.nl/wiki/Arduino_KY-040_Rotary_encoder_module

author: hfleming
author_rank: Regular Contributor
timestamp: February 21, 2017, 06:58:26 pm
content: Another web sit to help you along ishttp://henrysbench.capnfatz.com/henrys-bench/arduino-sensors-and-input/keyes-ky-040-arduino-rotary-encoder-user-manual/

author: FrankBuss
author_rank: Unknown
timestamp: February 21, 2017, 07:36:49 pm
content: Quote from: Benta on February 08, 2017, 09:23:11 pmYou keep telling this, but usually this is not a good idea. Better use a state machine, which can be implemented with a simple table and in a timer interrupt. See this posting for sample implementations:https://www.eevblog.com/forum/microcontrollers/quadrature-decoder-for-reference/But in this case the easy way with using one output as clock might work, because seems to be a high quality optical encoder, probably without contact bouncing and with a hysteresis.

author: Benta
author_rank: Super Contributor
timestamp: February 21, 2017, 08:29:49 pm
content: QuoteQuoteSo what's your problem?A HW solution works.

author: mr1979
author_rank: Contributor
timestamp: August 30, 2017, 09:09:24 pm
content: Quote from: Codebird on February 16, 2017, 12:40:56 pmCan I have a schematic example with discrete logic?Inviato dal mio PLK-L01 utilizzando Tapatalk

author: jesuscf
author_rank: Frequent Contributor
timestamp: August 30, 2017, 11:28:02 pm
content: Quote from: FrankBuss on February 21, 2017, 07:36:49 pmI totally agree with FrankBuss. Using a state machine (per encoder) with a timer interrupt (for all the state machines) you can read several encoders smoothly and with very little CPU overload. This is the real tried-and-true way of reading quadrature encoders.

author: rstofer
author_rank: Super Contributor
timestamp: September 01, 2017, 12:50:40 am
content: I have never used a timer, I always use the 4 edges and the interrupt on change feature of most micros. I just do a lookup for next state and what to do with the count. Even if I get contact bounce, I will just bobble back and forth between 2 states and the count will fluctuate by + or - 1.I usually want the resolution of all 4 edges and there are other approaches that use less edges but are probably easier to implement.