getting angle from encoder

I want to convert he value from a rotary encoder to an angle value. I looked it up but couldn't find anything. Is there a way to do it?
One solution I think of is to turn the encoder 360 degrees, read the values, see how much it changes and use that as the basis for and angle.
(value read) / 360 would give me how much it changes for every angle.
then I can do angle = (value read/(total value for 360 degrees) * 360

You'll always be guessing that way.
An encoder (2 out of phase switches) does not give you this information.
You need at least an extra reference signal, telling you you reached your zero or home position.
If you want an immediate angle readout without a need to go to some home position, look into "gray code".
That will give you an exact angle, but you will need more than 2 bits for that.

The whole point of a rotary encoder is that it ISN'T position oriented. If you want to have a control that's positional, use a potentiometer. Encoders simply give you pulses to tell you that it's moving in one direction or the other.

You must first start with finding out how many pulses per revolution your rotary encoder is. Then you need a Home position sensor and it has to find that first. Or is this a relative angle measure only?

Which rotary sensor? Website link?

What's the application ?

There are 3 kinds of encoder the OP might be talking about:

incremental
incremental with index pulse,
absolute.

The first one can't do absolute position and only the last one can do absolute
position without a calibration action at start up.

This is a very cheap absolute encoder.
Absolute encoder

Thank you for the replies. I have an incremental encoder. The project is that I have a gear attached to the encoder and meshed with another gear attached to a continuous rotation servo. I can turn the servo to a particular angle and know where it is, but if the servo gets turned manually I won't know the position and that's why I need the encoder.

Encoders vary in resolution. Some have only 2 or 4 pulses per revolution, which would be almost useless for estimating the angle. Others have 100 or 200 or 1000 pulses per revolution, which would be quite useful for estimating angle, provided you had a means of identifying the reference or zero position.

KenF:
The whole point of a rotary encoder is that it ISN'T position oriented. If you want to have a control that's positional, use a potentiometer. Encoders simply give you pulses to tell you that it's moving in one direction or the other.

You seem to lack a knowledge of what a rotary encoder is.

Encoder means any one of a number of technologies for detecting position or change in position, here rotary position.

You can get analog encoders, digital encoders analog+digital encoders, incremental encoders, absolute encoders and
incremental encoders with index pulse. Rotary and linear encoders both come in absolute,
incremental and incremental with index pulse forms.

An absolute encoder returns angle directly (many give you the turn count too, some are
accurate to millions of steps per revolution). They can be expensive or extremely
expensive.

Incremental encoders are generally cheaper, but the ones which generate an index pulse
can be used as absolute position sensors once calibrated.

Incremental encoders require constant attention to maintain a position / angle value,
which often means interrupt handler is used to let that all work in the background.

Here are examples of several. The top row are relative encoders, only telling you how far it has moved. The second row (I don't know about the one bottom right) are absolute encoders. Grey code works better than binary, as only one bit changes at a time.

This can generate printable encoder wheels.

https://code.google.com/p/wheel-encoder-generator/

Here is one torn out of something:

Great link for the encoder wheel generator !

Printability is an issue.

hi,recently i am doing a project similar to you. i have a optical rotary encoder from a printer.I want to read the angle from the encoder like you but have no idea.Did you fix the problem?

jhern:
I want to convert he value from a rotary encoder to an angle value. I looked it up but couldn't find anything. Is there a way to do it?
One solution I think of is to turn the encoder 360 degrees, read the values, see how much it changes and use that as the basis for and angle.
(value read) / 360 would give me how much it changes for every angle.
then I can do angle = (value read/(total value for 360 degrees) * 360

I bought a few 10-bit 'absolute' rotary encoders (TRD-NA1024NW) from ebay ... which I had initially assumed to use 'common gray code', but unfortunately they used some unorthodox or unconventional gray code.

I ended up needing to measure (automatically) the 1024 consecutive gray code patterns to get the full set of patterns for the unconventional gray code (of this particular rotary encoder). But once all the patterns were obtained, there was the issue of how to 'quickly' translate any single pattern to an angle.

The reason why I ordered TRD-NA1024NW encoders was because I had assumed that they had typical gray code patterns. My rotary encoders that I ordered did not have typical patterns. But.... it doesn't mean to say that all TRD-NA1024NW encoders are like that. So I recently ordered 1 more (from a different source), but haven't yet tested it to see whether it has conventional gray code patterns.

There's a link to some discussion about my particular decoders at......click here....

Once worked on a German mach. that had absolute encoders that produced 5 digit BCD Gray code, they called it "Petherick code" or something similar, it was decoded by a slab of EPROMs to binary for the DACs.