PDA

View Full Version : Rotary encoder help (not 'counting steps)



Elnino
- 23rd October 2009, 10:28
Hi all, I'm after a little input as to how i can achieve some speed tracking of 2 axes moving with rotary encoders. Think of these 2 encoders mounted on a movable x,y table. I want to be able to track the speed of the table - direction is ok too but is not needed.

The table is only moving slow, maybe a max of about 3cm/s. the encoders i have are >1000 pulse/rev but precision is not too important, the table is moved by hand and the speed will be converted to an eight bit value. The actual values i get are not really important. i.e i don't need to know the real world speed just a number that represents that speed.

My 'theory' was to only use an a or a b output on the encoders and use a simple pulsin function on each but i'm not sure this will do what i want - i think pulsin is more designed for much higher frequencies (but i have never used it). Also, i am not sure if this will work reading 2 sensors.
I guess i could do fixed time sampling and count pulses in that time too but i don't really know how to do that. interrupts i spose but once again, i've never dealt with interrupts.

I'm not expecting someone to do this for me, i'm looking for ideas for method of attack. If anyone has a theory on how i can do this, i'd love to hear it.

Thanks

aratti
- 23rd October 2009, 11:06
You could use "INTERRUPT ON CHANGE" which uses portB.4 to portB.7. You could connect Chan A of X axes to portB.4 and chan B of same axes to portB.5 while axes Y will use portB.6 and portB.7 in the same way.

In the interrupt routine you will increment a variable for X axes and one for Y axes. using the timer0 or timer1 overflow you will read the variable and extract the speed, once you have done that you will zero both variable for the next reading.

Since you will count both channels you will be able to detect also the direction setting a direction flag in function of the channel sequence.

As far as interrupt on change, is concerned you could take advantages from Darrel Taylor instant interrupt routine, simple to use and very relaible indeed.

Al.

Elnino
- 23rd October 2009, 11:46
Excellent, Thanks Al! that's exactly the headstart i needed. Time to get coding... (and checking out how these interrupts work...)

Darrel Taylor
- 24th October 2009, 01:26
SteveB might have something for you that goes along with arrati's suggestion ...

http://www.picbasic.co.uk/forum/showthread.php?p=25396#post25396
<br>

Elnino
- 26th October 2009, 22:03
Thanks DT, that's pretty darn close to what i need.