1
\$\begingroup\$

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
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Will the clockwise sequence be LH, HH, HL, LL (briefly), LH; or will it be LH, HH (for awhile), HL, HH (briefly), LH; or could it be either? One should never rely upon two asynchronous signals to switch and precisely the same time; if one expects them simultaneously, one must be prepared for either to actually happen first. \$\endgroup\$
    – supercat
    Commented Mar 8, 2011 at 16:45
  • 1
    \$\begingroup\$ Instead of "LH-HH-HL-LH" I think you mean "LH-HH-HL-LL" and instead of "LH-HL-HH-LH" I think you mean "LL-HL-HH-LH". You never want two bits to be changing at the same time, because they are never at exactly the same time, so there is a glitch when one has changed but not the other. AS code with one bit changing at a time is called a Gray code. \$\endgroup\$
    – markrages
    Commented Mar 8, 2011 at 16:46

2 Answers 2

1
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

I noticed that clockwise has a high pulse 4 bits wide and a low pulse 2 bits wide as well as one 1 bit wide. But the anticlockwise pulse has a high pulse 2 bits wide and all the low pulses are 1 bit wide. So if you measured the duration of the pulses and tested the ratio of high to low time using carefully chosen pulses, you could make a decision. But you must use ratio and not absolute times because these will change with the speed of the wheel.

(When it is a homework question, people will give you hints and tips but not a complete solution otherwise you do not learn the objective of the course).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.