Incremental Rotary Encoder interface help

Thread Starter

NVergunst

Joined Feb 13, 2007
7
Hello everybody. I have been toying with the idea of using a rotary encoder in one of my projects. I can only sample at about 35mS, so my thought was to use a frequency to voltage converter with an incremental rotary encoder. So the more turns/rotations of the knob, the more pulses, the bigger the voltage correct?

I am not really sure if I am on the right track or not.

From what I understand, there is a very very short time between the 2 output pulses on these encoders that tells the direction. So I would need some sort of simple circuit to capture the first one that pulsed, so that would tell direction. And then perhaps I could somehow add 2.5 volts to the voltage output of the frequency converter if clockwise.

So 0v would mean no frequency, so not moving, from 0-2.5v it means that the greater the voltage the faster it is turning in the counterclockwise direction. If 2.5 - 5, the greater the voltage, the faster it is turning in the clockwise direction.

I am not set on any of these ideas, this is just what I am imagining at the moment.

Does anyone have any insight on simple circuits, or (am I asking too much here :p) an IC?

If anyone has a better solution for getting an infinately spinning knob to output a voltage depending on what direction/speed it is going, I am all ears.

Thankyou in advance.
 

hgmjr

Joined Jan 28, 2005
9,027
....From what I understand, there is a very very short time between the 2 output pulses on these encoders that tells the direction. So I would need some sort of simple circuit to capture the first one that pulsed, so that would tell direction. And then perhaps I could somehow add 2.5 volts to thevoltage output of the frequency converter if clockwise.
The recommended research by GonzoEngineer is a good idea. That will give you the background information that you need.

As for direction sensing, first you will need to make sure that the shaft encoder you choose has phase-quadrature outputs. With phase quadrature outputs, one approach to determining rotational direction is to feed the two phase-quadrature signals into a D-type flip-flop. One of the encoder output signal lines connects to the data input of the F/F while the other input connects to the clock input of the F/F. The "Q" output of the F/F will indicate the present direction of rotation. If you need the opposite signal polarity for the next stage of the circuit you have the NOT "Q" output available.

hgmjr
 

spar59

Joined Aug 4, 2007
64
You may want to use a commercially available encoder - I spotted one on Ebay that had a built in pushbutton action (for selection) as well for about £3 ($6) including postage.

However I needed one in a hurry for a PIC project and cannibalised a 1 pole 12 way rotary switch - removed the end stop so it could rotate continuously, wired together every 3rd output, fed the resulting 3 connections to the PIC (weak pull-ups configured on) with the common connection to ground. A bit of software to scan the inputs and hey presto a rotary encoder for around 30p (60c).

Steve.
 

Thread Starter

NVergunst

Joined Feb 13, 2007
7
You may want to use a commercially available encoder - I spotted one on Ebay that had a built in pushbutton action (for selection) as well for about £3 ($6) including postage.

However I needed one in a hurry for a PIC project and cannibalised a 1 pole 12 way rotary switch - removed the end stop so it could rotate continuously, wired together every 3rd output, fed the resulting 3 connections to the PIC (weak pull-ups configured on) with the common connection to ground. A bit of software to scan the inputs and hey presto a rotary encoder for around 30p (60c).

Steve.
Do you have a link for the ebay auction? Sounds nifty, and pretty much what I want. I am going for the look of an audio volume control such as you would find on a car stereo.
 

spar59

Joined Aug 4, 2007
64
Yes it is item number 270130801383 or search for:-

Rotary Encoder push button switch Ideal for Data Entry

It is for sale by pic-projects whom I don't have any affiliation with, but I have bought from him before with no problems.

Steve.
 

Thread Starter

NVergunst

Joined Feb 13, 2007
7
Yes it is item number 270130801383 or search for:-

Rotary Encoder push button switch Ideal for Data Entry

It is for sale by pic-projects whom I don't have any affiliation with, but I have bought from him before with no problems.

Steve.
That is just the encoder though... I can get those really cheap as well ($3-$4), I thought it may have had circuitry with it. Oh well.



Well anyways, I have been doing a little googling, and I have looked at this chip: http://www.avagotech.com/products/product-detail.jsp?navId=C1,C4935,C5005,C5015,P94649

So from what I can tell, it has a 16bit counter on it. I would rather it be a bigger chip and have access to all 16bits at once, but perhaps I could just use the lower 8 and update it fast enough. So it would take that counter output, and convert it to an analogue voltage with an r2r network with the up/down bit being the high bit so that would cause the big change I described in the first post. Only problem would be clearing it on queue.

Hmmm. This is proving to be more trouble than I first thought. :eek:
 

spar59

Joined Aug 4, 2007
64
The chip you refer to looks interesting but if your project includes a microcontroller why not read the device directly - you only need 2 inputs - the encoder I pointed to is not a quadrature encoder but a gray code one - the 2 output lines change state in sequence 00 01 11 10 - only one bit changes at a time thus preventing position errors at the switching points.

To read such a unit should be fairly easy bearing in mind that a PIC mcu can do up to 5,000,000 instructions per second and double this for the latest 40MHz clock units.

If time on the main mcu is really critical an 8pin PIC could be dedicated to this using internal clock, 2 pins for supply & 2 pins for encoder input this leaves up to 4 pins for data output - you could use one pin as a 'transmit now' input and another for serial data output.

Steve.
 

Thread Starter

NVergunst

Joined Feb 13, 2007
7
The chip you refer to looks interesting but if your project includes a microcontroller why not read the device directly - you only need 2 inputs - the encoder I pointed to is not a quadrature encoder but a gray code one - the 2 output lines change state in sequence 00 01 11 10 - only one bit changes at a time thus preventing position errors at the switching points.

To read such a unit should be fairly easy bearing in mind that a PIC mcu can do up to 5,000,000 instructions per second and double this for the latest 40MHz clock units.

If time on the main mcu is really critical an 8pin PIC could be dedicated to this using internal clock, 2 pins for supply & 2 pins for encoder input this leaves up to 4 pins for data output - you could use one pin as a 'transmit now' input and another for serial data output.

Steve.
The project does have a PIC in it, but the way that I am using it, it sort of needs to just be a general analogue output.

I could use a second PIC I guess but would rather not.
 

Thread Starter

NVergunst

Joined Feb 13, 2007
7
Ok, so I think this is the route I will be going...

Thanks for all the help so far! I wouldn't have thought to use a D-F/F to determine direction, but once I thought about it, it is perfect for the apllication since there is that overlap time! Thank you very much for that tidbit. Also thankyou very much for supplying me with the correct search keywords. I wasnt getting too much relevant data because I didnt know what I was really looking for.

Anyways, this is what I have come up with:



If you look on the left side where it says Keys... Keys 1 and 2, are the outputs from the rotary encoder. The program I was using didnt have an encoder so I did it all by hand for that hence the keys. Key 3, is actually going to be controlled by the same project that the analogue will be going into.

So the #1 and #2 in the circles will make the 13bits that will go into a resistor network. #1 will be the highest bit making that 2.5v switch I mentioned first a possibility. Then the greater the voltage, the more pulses have been counted meaning the knob has been turned more.

Then when the project polls the analogue value, it will also pulse Key 3, to reset the counter.

I think this should work. Does anybody have any insight on this? Obviously it will have a little jitter to it, but since it should be updated every 30-50mS the jitter shouldnt really be noticeable. Also the 12bit counter right now is 3 4bit synchronous, but if I can find a well priced 12bit synchronous or 2 6bit or something I will go that way. It shouldnt really matter. Power consumption isnt an issue so more chips is no problem.

Comments, Opinions, Suggestions, Improvements?
 
Top