Electrical – How to get a position from an encoder

controlencodermicrocontrollermotor

I have a motor that drives a rail which I need to know the position of.

I have an AM102 encoder attached to the motor. But am unsure how to get a position from it.

I have powered it up and attached the two outputs to my Teensy 3.0. In my program I can see the value changing as I manually move the motor. (Either 1023 or 0 if I recall correctly).

I am wondering how I can use this to determine position. I'm guessing that I can determine position by counting how many times the value changes from 1024 to 0 and then multiplying that number by a distance (not sure how to get that value). But when the system is first turned on, how will it know the initial position? Is there a way to get this from the encoder or some other device/method?

n.b. I also have an Atmega328P which I've been told may how me determine position how would I use this?

Question summary:

  1. How do I get the distance multiplier?
  2. How do I get initial position?

Best Answer

How do I get the distance multiplier?

You measure or calculate how far your device will go for e.g. one full rotation, e.g. in cm. Then you take that length and divide it by the number of pulses per revolution the encoder delivers and you got your distance multiplier in cm/pulse.

How do I get initial position?

The encoder itself can only tell you the rotation angle relative to the "index" position. If the motor can do more than a single rotation in either direction there is no way the encoder alone could tell you the absolute position after power on.

A common solution is to have a limit switch, either mechanical, inductive, or optical (IR), at one end of the rail. Upon power up, the controller drives the motor toward the end of the rail with the limit switch until the switch detects arrival at the end. This is then the "0" position and any movement/rotation of the motor is measured via the encoder relative to that fixed position.