I am using C on an ARM processor and am attempting to properly read parallel data off of a TI ADS7824 analog to digital converter. I would use serial but the application calls for parallel. Anyway, if you look at the datasheet,
you will see that, according to the state of the byte input, either the first four bits or the remaining eight are placed on the output pins. That data to my knowledge is signed, since the unit accepts +/- 10 volts on its analog inputs. How do you join, using C variables, the contents of a signed 12-bit quantity (in this case four and eight bits), broken into two parts? It is easy with unsigned data. I just do this:
Code:
short byteA = 0x00;
short byteB = 0x00;
byteB <<= 4
byteA |= ByteB
you test the sign bit of the 12 bit data and sign extend e.g. assuming twos complement data
(msb and lsb contain the most and least significant bytes respectively)
Code:
if(msb & 8) msb |= 0xf0; // if negative sign extend to left nibble
int data = (msb << 8) | lsb; // create a 16 bit int
if data is a 32 bit int you need to sign extend into the top 16 bits