Forums

Quad encoder problems

Started by smitty505000 September 9, 2006
Hey all,

I am trying to get a couple of quad encoders to work in Picbasic
pro. I know the basics of how they work and simple programing
abilities. Here is what I have:

Qty 2 quad encoders with 36 slots each
Pic 16F628-20p
parallel lcd

I want to be able to return a value of 1-36 from each encoder so I
know the exact position of each.

The code I wrote is very simple using if then statements and reading
the ports to see if it is high or low. It kinda works but only if
the encoder is turned extremly slow and even then I get glitching.

>From the information I have been able to find, it looks as if I need
to do it in assembly but like I said before, I only know simple
Basic programing.

Can anyone help??

Thanks,
Smitty
> Hey all,
>
> I am trying to get a couple of quad encoders to work in Picbasic
> pro. I know the basics of how they work and simple programing
> abilities. Here is what I have:
>
> Qty 2 quad encoders with 36 slots each
> Pic 16F628-20p
> parallel lcd
>
> I want to be able to return a value of 1-36 from each encoder so I
> know the exact position of each.
>
> The code I wrote is very simple using if then statements and reading
> the ports to see if it is high or low. It kinda works but only if
> the encoder is turned extremly slow and even then I get glitching.
>
>>From the information I have been able to find, it looks as if I need
> to do it in assembly but like I said before, I only know simple
> Basic programing.
>
> Can anyone help??
>
> Thanks,
> Smitty
>

A quad encoder SEEMS simple enough. Watch for an edge on one phase
indicating rotation, look at the other phase (high or low) to determine
direction. The problem is contact bounce. I finally ended up using a state
machine that ignores invalid edges. You should be able to do something
similar in Basic. Generally, quadrature encoder decoding is done in an
interrupt routine, but, if the processor is not doing much else, it could
be polled. I did this in an 8 pin pic that converts quadrature rotation to
up/down pulses to drive another piece of equipment.

Some code (pretty much all assembly, but should give you the idea) is
posted at http://www.piclist.org/techref/microchip/qenc.htm

Harold
--
FCC Rules Updated Daily at http://www.hallikainen.com - Advertising
opportunities available!