Counting the number of rotations...Help!

Thread Starter

indeedisuper

Joined Oct 14, 2015
21
Hello,

I was wondering if anyone has a good idea on how to count the number of rotations that an absolute rotary encoder went through.

http://www.usdigital.com/products/encoders/absolute/rotary/shaft/ma3

For example, if the encoder goes through a whole revolution clockwise, a rotation counter increments, and if it goes 1 revolution counter clockwise, the counter decrements.

I'm having a hard time figuring out a method to identify whether the encoder is going clockwise or counterclockwise, and if so if it has been a full rotation or not.

I'm thinking of setting up a marker, say if the last five readings were smaller than this marker then the encoder is moving clockwise. If the last five readings were bigger than the marker, than the encoder is going counterclockwise. But there are cases where this would not catch.

Any insight is appreciated.
 

shteii01

Joined Feb 19, 2010
4,644
I think the last time I worked with dual direction encoder, it had two outputs. One output for one direction, another output for the other direction.

Do you have encoder with just one output?
 

MaxHeadRoom

Joined Jul 18, 2013
28,686
An absolute encoder (as opposed to quadrature) usually either has serial output or 8bit 12 bit parallel.
The one shown appears to have analogue or PWM output and I have never used the one shown.
If the analogue out is used, then input into a Pic or other μp.
What is the method used to read it?
Max.
 

John P

Joined Oct 14, 2008
2,026
I'd never seen that component before. It's an interesting thing.

Since this is the Embedded Systems and Microcontrollers section, I assume you plan to use a processor. What I'd do is read the transducer output at some rate, frequent enough that you'd get several results during each turn of the shaft at maximum speed. Every time you get an input, subtract the previous reading (N) from the latest reading (N'). Do a 5-way test on the result, like this (assume the scale is 0-99):

(N' - N) = 0: No motion, do nothing
0 < (N' - N) < 50: Clockwise, don't change rotation count
(N' - N) >= 50: Counter-clockwise, decrement rotation count
0 > (N' - N) > -50: Counter-clockwise, don't change rotation count
(N' - N) <= -50: Clockwise, increment rotation count

The point is that the device gives you a number that (going "clockwise") increments slowly to the maximum and then jumps to zero. In the "counter-clockwise" direction, it decrements slowly from the maximum and then jumps back to the maximum. You compare each reading with the previous one, and if the difference is more than 49, you assume that there was that sudden jump from max to min or vice versa, and that's when you increment/decrement the turns count. Smaller changes don't indicate a sudden jump and just tell you the position within a turn.

If I haven't made it clear enough, sketch out a sawtooth waveform on a piece of paper and run your finger along it. You can count cycles by detecting the jumps from maximum to minimum, or the opposite.
 

Thread Starter

indeedisuper

Joined Oct 14, 2015
21
An absolute encoder (as opposed to quadrature) usually either has serial output or 8bit 12 bit parallel.
The one shown appears to have analogue or PWM output and I have never used the one shown.
If the analogue out is used, then input into a Pic or other μp.
What is the method used to read it?
Max.
Max is right. The encoder that I am using is the PWM version. I read it via a ISR that stores the rise/fall time whenever a pin change happens. I later convert the rise/fall time to pulse width and can figure out the appropriate rotation/distance from there.

The reason why I need to figure out how many rotations the encoder has gone through is because my MCU isn't fast enough to catch all the pin changes when the high or low pulse width is less than 2us which occurs right before/after a rotation through the 0 degree point. As of now my encoder reading's absolute accuracy is off so I need to adjust for the error during every rotation.
 

Thread Starter

indeedisuper

Joined Oct 14, 2015
21
I'd never seen that component before. It's an interesting thing.

Since this is the Embedded Systems and Microcontrollers section, I assume you plan to use a processor. What I'd do is read the transducer output at some rate, frequent enough that you'd get several results during each turn of the shaft at maximum speed. Every time you get an input, subtract the previous reading (N) from the latest reading (N'). Do a 5-way test on the result, like this (assume the scale is 0-99):

(N' - N) = 0: No motion, do nothing
0 < (N' - N) < 50: Clockwise, don't change rotation count
(N' - N) >= 50: Counter-clockwise, decrement rotation count
0 > (N' - N) > -50: Counter-clockwise, don't change rotation count
(N' - N) <= -50: Clockwise, increment rotation count

The point is that the device gives you a number that (going "clockwise") increments slowly to the maximum and then jumps to zero. In the "counter-clockwise" direction, it decrements slowly from the maximum and then jumps back to the maximum. You compare each reading with the previous one, and if the difference is more than 49, you assume that there was that sudden jump from max to min or vice versa, and that's when you increment/decrement the turns count. Smaller changes don't indicate a sudden jump and just tell you the position within a turn.

If I haven't made it clear enough, sketch out a sawtooth waveform on a piece of paper and run your finger along it. You can count cycles by detecting the jumps from maximum to minimum, or the opposite.

Hi John,

This was similar to the thought that I had in the beginning, but due to the fact that I have a blind spot from ~2500 to 65 (the range for the encoder in ticks is from 0 to 2565) because of my MCU I am looking into other ways.
 
Top