Wheel encoder to find direction of wheel

encodermicrocontroller

I am doing an 8th semester project but I need to use an IR transmitter and receiver to find the wheel direction of car. I would like 8051 assembly level code to find wheel direction. I am using two IR transmitters and receivers to find direction. I am mounting these two IR modules to get following combination of output.

clockwise direction
LH-HH-HL-LH

Anti clockwise  direction
LH-HL-HH-LH

Best Answer

This isn't the usual rotary encoder pattern, but it should still work. See this wikipedia section for the normal gray-code implementation.

Basically, you will need to:

  1. Store the current state of the encoders to a register
  2. Wait for some length of time. (This must be short enough that only one transition occurs)
  3. Compare the new encoder state with the old encoder state to see if they are different.
  4. Based on your previous state, and the new state, decode the direction. (This step/algorithm would be easier if you used a typical implementation.)

The disadvantage of your setup is that it takes two transmitters, probably has a more complicated pattern drawn, and there's no way to identify if the encoder has gone 2 steps instead of 1. Additionally, only one bit changes with the gray code count, so the comparison routine is easier and not a look-up table.