Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/29/01 15:25
Read: times


 
#14599 - RE: optical encoder
Hi all,
maybe this thread needs no more comments, but I think this can help somebody that has doubts about what method to use -polling or interrupts- reading encoders.

I have been working for many years with ALPS encoders. They are cheap (about $2.5), give typical 2 bit Gray code and 24 detent points, so the angular resolution is 360/24= 15 degrees: the possible STABLE positions are: 0-15-30-45-60-75-90 and so on, in a stable position both A and B enconder outputs are set to logic 1, hence if the user turns the axis from a detent position to the next detent position there is no posibility of missing codes even when you turn forth and back. The problem arises when the user stops turning before reach the next detent position, eg. 10 degrees, then an interrupt has been generated but no one will be generated until you reach the next detent position and turn from it, so practically speaking you have not loose pulses, given that you have not completed a full cycle. Well this is not strictly true: suposse you turn from 0 to 10 degrees: an interrupt has been generated and check B that is logic 1, then your program assumes that you have turn the axis from 0 to 15 degrees, if you continue turning from 15 to 30 there is no problem at all, but if you reverse direction from 10 to 0, the new position is 0 degrees but no interrupt has been generated because of rising edge on interrupt pin, so your program thinks you are in 15 when it really is in 0 degree.

One solution to this problem is polling A and B, as Peter and Erik have explained.

Other solution is to use a PIC, they have a change state external interrupt, this means: an interrupt can be generated both in rising and falling edges on INT pin. Yeah, I know this is a 8052 forum so I have to give solutions and not only complain about some weak points in 8052 architecture.
Some time ago I posted a message about emulating PIC external interrupts with 8052 and Peter post a very good idea on how to do it: using external interrupt pin and a counter. The disavantage of his solution is that you need a spare timer. But it really works fine. I named his idea as the SOFTWARE SOLUTION.

Ok, now my HARDWARE SOLUTION: you need a XOR gate, apply channel A to one input and the same channel A to the other XOR input through a RC filter. This RC works as a delay line, so every time A changes its state a pulse is generated in XOR output then join this output to 8051 EXT interrupt pin. You may wonder, but what now? How the missing pulse problem is solved? The solution follows:

When an interrupt is triggered you have to test both A and B channels and depending on the value you get, you can determine if you have turned the axis CW or CCW:

A=0 and B=0 turned Clockwise
A=1 and B=1 turned Clockwise
A=0 and B=1 turned CounterClockwise
A=1 and B=0 turned CounterClocwise

Easy, doesn´t it?
Maybe it is a bit difficult to understand these A and B values, but if you draw a circle with some diametral lines, the sectors you get represents alternatively a lever and lack of lever that opens and closes two switches -A and B- that placed in the proper place will yield the numbers showed previously.
It sounds complicated but it is easier than it looks. Take into account that English is not my native language and I am not able to express myself as I would like, so If someone needs more info about this I can make a draw and upload it to somewhere.

I prefer to use interrupt method instead of polling and hope this will be useful to those who need interrupt driven Encoder reading, but I think the Alfredo´s solution is adequate for human interface and I have been using it for years.

By the way, Alfredo do you work with Ferni or Antonio Manzanedo? Is your workplace at Cuvi or in Torrecedeira?

Best Regards.

Fran Dominguez.

List of 16 messages in thread
TopicAuthorDate
optical encoder            01/01/70 00:00      
RE: optical encoder            01/01/70 00:00      
RE: optical encoder            01/01/70 00:00      
RE: optical encoder, Alfredo            01/01/70 00:00      
RE: optical encoder, Alfredo            01/01/70 00:00      
RE: optical encoder            01/01/70 00:00      
RE: optical encoder, Bruce            01/01/70 00:00      
RE: optical encoder problems            01/01/70 00:00      
RE: optical encoder            01/01/70 00:00      
RE: optical encoder            01/01/70 00:00      
RE: optical encoder, Roger            01/01/70 00:00      
RE: optical encoder, Andy            01/01/70 00:00      
RE: optical encoder            01/01/70 00:00      
RE: optical encoder            01/01/70 00:00      
RE: optical encoder, Fran            01/01/70 00:00      
RE: optical encoder            01/01/70 00:00      

Back to Subject List