CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Gray code

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








Gray code
PostPosted: Mon Apr 19, 2004 10:44 am     Reply with quote

How to convert gray to binary?
stevev



Joined: 11 Nov 2003
Posts: 4
Location: Portland, Oregon

View user's profile Send private message

PostPosted: Mon Apr 19, 2004 12:07 pm     Reply with quote

What kind of gray code are you talking about? A simple optical encoder or aviation altitude gray code? Or something else?
Cyril
Guest







PostPosted: Mon Apr 19, 2004 7:38 pm     Reply with quote

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);
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group