Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Reading Signed Data in Two Parts

Status
Not open for further replies.

kingneb

Newbie level 3
Newbie level 3
Joined
Sep 7, 2010
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,306
Hello,

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,

https://www.ti.com/lit/ds/symlink/ads7824.pdf

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
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top