Using XOR to convert a Graycode Encoder
Posted: Sun Jul 28, 2019 3:42 pm
Setup:
EasyPIC V7 board/ICD3/MCC
Using PIC18F45K22/8MHz
XC8/C90
Continuing on the same project http://picforum.ric323.com/viewtopic.php?f=32&t=735 but a different subject (it was getting off topic).
My research leads me to think I need to XOR the input from the encoder. From what I've done so far (created a excel spreadsheet to convert gray to binary & hex) it seems that each capture of the 10 pins needs 10 iterations of the XOR to create a converted hex value.
My question is:
Can I just apply the XOR to the 16bit value (something like below), because its taken care of in the background, or will i need to create a loop to iterate through the bits.
Regards
Les
EasyPIC V7 board/ICD3/MCC
Using PIC18F45K22/8MHz
XC8/C90
Continuing on the same project http://picforum.ric323.com/viewtopic.php?f=32&t=735 but a different subject (it was getting off topic).
My research leads me to think I need to XOR the input from the encoder. From what I've done so far (created a excel spreadsheet to convert gray to binary & hex) it seems that each capture of the 10 pins needs 10 iterations of the XOR to create a converted hex value.
My question is:
Can I just apply the XOR to the 16bit value (something like below), because its taken care of in the background, or will i need to create a loop to iterate through the bits.
- Code: Select all
Volatile int GC_Raw = 0000000000001100; // set/change values for testing
Volatile int Binary_XORd = 0000000000000000;
void main (void)
while
{
//GC_Raw = PORTB; // Use when tested
Binary_XORd = Binary_XORd ^ GC_Raw ;
printf("Binary value: %d",Binary_XORd);
}
Regards
Les