# How to count rotations with a Precision Hall Effect Rotational sensor

Hi,

I would like to count rotations with a Precision Hall Effect sensor. It outputs me the rotational angle from 0° to 360°.
To get the rotational direction I compare each value with the value before. So if it is bigger it is rotating clockwise and if it is smaller it is rotating counter clockwise.

But I have no idea how to count full rotations in both directions?
I would be very grateful if you could help me to find a good approach for my problem.

Kind regards,
Tom

I have no idea how to count full rotations in both directions?

If the angle changes from 0 to 360 or 360 to 0 degrees then add or subtract 1 from the rotation count as appropriate.

Thanks for your answer! So should I check if the actual angle is much smaller or bigger than the last angle to detect when it passes 360° or 0°?
I fear this will only work if it is rotating slow.

Something like:
if oldAngle>355 and newAngle<5 then full rotation count++
if oldAngle<3 and newAngle>355 then full rotation count–

Although I expressed the decision as going between 0 and 360 or 360 and 0 you would be better to allow for some measurements being missed so the angle may not be precisely 0 or 360 , but remember that the Arduino can take several thousands of measurements a second if the code is written correctly. Actually if the range were 0 to 360 then there would be 361 degrees in a full circle so is the range really 0 to 359 then back to 0 ?

How are you dealing with the rollover at the moment bearing in mind that you said

So if it is bigger it is rotating clockwise and if it is smaller it is rotating counter clockwise.

The sensor is showing me values from about 0.01 degree to 359.99 degree.

UKHeliBob:
How are you dealing with the rollover at the moment bearing in mind that you said

That is my problem at the moment, if I am to slow it does not work.

I did not find a solution so far. Although I am sure there is a convenient and short solution for such a problem!

Any idea?

Is there really nobody with an idea?
I don't know where to look and search for an example of a similar problem.

Although I am sure there is a convenient and short solution for such a problem!

So much depends upon your application and the motion you experience across 0. You were on the right track with what you posted.

Something like:
if oldAngle>355 and newAngle<5 then full rotation count++
if oldAngle<3 and newAngle>355 then full rotation count–

Perhaps if you provided your code, and more information about the type of application and the motion expected we could do better than what has already been provided.

Hi,
Before we go anyfurther, can you post a link to the datasheet of the encoder.
Encoder can mean many different things..
How many outputs does it have?
Is it an absolute encoder?

Thanks.. Tom...
7 posts and no specs....