View previous topic :: View next topic |
Author |
Message |
Guest
|
Gray code |
Posted: Mon Apr 19, 2004 10:44 am |
|
|
How to convert gray to binary? |
|
|
stevev
Joined: 11 Nov 2003 Posts: 4 Location: Portland, Oregon
|
|
Posted: Mon Apr 19, 2004 12:07 pm |
|
|
What kind of gray code are you talking about? A simple optical encoder or aviation altitude gray code? Or something else? |
|
|
Cyril Guest
|
|
Posted: Mon Apr 19, 2004 7:38 pm |
|
|
Here is a function I use for an 8 bit absolute rotary encoder (on port B)
int read_encoder(){
int i,binary,gray;
gray = port_b;
binary = 255; //set all bit
if(!bit_test(gray,7)) bit_clear(binary,7);
for(i=7;i>0;i--){
if((bit_test(binary,i))==(bit_test(gray,i-1))) bit_clear(binary,i-1);
}
return(binary);
} |
|
|
|