Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
09/30/08 13:50
Read: times


 
#158681 - Gray Code To Binary 8051
Responding to: ???'s previous message
To follow-up briefly on my application.

I have a Linear Position Sensor, it's output is 24-bit Gray Code.

To get a position reading from the sensor, I must convert the Gray Code to Binary. Then I take this binary count and divide by resolution of the sensor and I get the displacement/position reading.

The Interface box the sensor is connected to uses the P89C668 micro. My code is in ASM. Basically, I'd like to have the sensor configured for Gray Code, my box reads this Gray Code, then converts it to binary so it can calculate displacement.

To get the displacement reading from the position sensor , you have to take:

Binary count/resolution = position/displacement of sensor.
Gray count/resolution = NOT CORRECT position reading.

BTW, side note, this position sensor can also be configure for straight 24-bit binary output, as well. And this works fine.When the sensor is configured for 24-bit binary, the code is pretty straigt forward.

However, I would like to get it to work with the Gray Code output.

To manually convert from Gray Code to Binary I do the following:
((assume 8-bit code in this example))
1. GRAY MSB(bit 8) = BINARY MSB(bit 8)
2. BINARY MSB(bit 8) xor GRAY MSB-1(bit 7) = BINARY bit 7
3. BINARY bit 7 xor GRAY bit 6 = BINARY bit 6
....etc

I have implemented the above is ASM but it aint pretty! It does work. But I just figured that someone else has done this and why try to re-invent the wheel.

Thanks for all the responses!

-Robert







List of 20 messages in thread
TopicAuthorDate
Gray Code To Binary 8051            01/01/70 00:00      
   huge table            01/01/70 00:00      
      RE: Take a pen and paper            01/01/70 00:00      
   Here are a few places to look...            01/01/70 00:00      
   What for?            01/01/70 00:00      
   Algorithm            01/01/70 00:00      
      Gray Code To Binary 8051            01/01/70 00:00      
         Post it            01/01/70 00:00      
            Yes!            01/01/70 00:00      
               Shifting ?            01/01/70 00:00      
                  Gray Code To Binary 8051            01/01/70 00:00      
                     Posting times            01/01/70 00:00      
   Gray Code To Binary 8051            01/01/70 00:00      
      2^n - 1 is not fast for large n            01/01/70 00:00      
         Ouch            01/01/70 00:00      
            Gray Code To Binary 8051            01/01/70 00:00      
               hardware            01/01/70 00:00      
               gray to bin            01/01/70 00:00      
                  asm            01/01/70 00:00      
                     Gray Code To Binary 8051            01/01/70 00:00      

Back to Subject List