Author Topic: Using a rotary encoder  (Read 5474 times)

0 Members and 1 Guest are viewing this topic.

Offline danjenkinsTopic starter

  • Contributor
  • Posts: 18
Using a rotary encoder
« on: February 08, 2017, 08:09:39 pm »
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.pdf

Thank you in advance for any help.
 

Online Benta

  • Super Contributor
  • ***
  • Posts: 7195
  • Country: de
Re: Using a rotary encoder
« Reply #1 on: February 08, 2017, 09:23:11 pm »
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.

 

Offline testian

  • Regular Contributor
  • *
  • Posts: 55
Re: Using a rotary encoder
« Reply #2 on: February 16, 2017, 12:21:59 pm »
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.
 

Offline Codebird

  • Regular Contributor
  • *
  • Posts: 161
  • Country: gb
Re: Using a rotary encoder
« Reply #3 on: February 16, 2017, 12:40:56 pm »
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.
 

Offline fki82

  • Contributor
  • Posts: 34
  • Country: de
Re: Using a rotary encoder
« Reply #4 on: February 19, 2017, 03:51:42 pm »
 

Offline hfleming

  • Regular Contributor
  • *
  • Posts: 92
  • Country: no
 

Offline FrankBuss

  • Supporter
  • ****
  • Posts: 2425
  • Country: de
    • Frank Buss
Re: Using a rotary encoder
« Reply #6 on: February 21, 2017, 07:36:49 pm »
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.

You 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.
So Long, and Thanks for All the Fish
Electronics, hiking, retro-computing, electronic music etc.: https://www.youtube.com/c/FrankBussProgrammer
 
The following users thanked this post: jesuscf

Online Benta

  • Super Contributor
  • ***
  • Posts: 7195
  • Country: de
Re: Using a rotary encoder
« Reply #7 on: February 21, 2017, 08:29:49 pm »
Quote
You keep telling this, but usually this is not a good idea.

Quote
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.

So what's your problem?

A HW solution works.
 

Offline mr1979

  • Contributor
  • Posts: 14
Re: Using a rotary encoder
« Reply #8 on: August 30, 2017, 09:09:24 pm »
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.
Can I have a schematic example with discrete logic?

Inviato dal mio PLK-L01 utilizzando Tapatalk

 

Offline jesuscf

  • Frequent Contributor
  • **
  • Posts: 504
  • Country: ca
Re: Using a rotary encoder
« Reply #9 on: August 30, 2017, 11:28:02 pm »
The tried-and-true way is to nominate one of the outputs as clock, using one of the edges as reference.

You 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/

I 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.
Homer: Kids, there's three ways to do things; the right way, the wrong way and the Max Power way!
Bart: Isn't that the wrong way?
Homer: Yeah, but faster!
 

Online rstofer

  • Super Contributor
  • ***
  • Posts: 10091
  • Country: us
Re: Using a rotary encoder
« Reply #10 on: September 01, 2017, 12:50:40 am »
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.

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->