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

Help understanding 2's complement conversion

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



Joined: 08 Sep 2003
Posts: 492
Location: India

View user's profile Send private message Send e-mail

Help understanding 2's complement conversion
PostPosted: Sun Apr 15, 2007 4:47 am     Reply with quote

Hi,

I am trying to develop a load cell amplifier that uses the CS5520 load cell amplifier ADC, the datasheet mentions that the ADC outputs conversion words MSB first (with the sign bit being outputed first). The entire word length is 24 bits long, 4 bits are flag settings, and the other 20 bits the data, the first bit is the sign bit. The flag bit is outputted last.

It is also mentioned that the data is outputted in 2's complement.

I am able to read the outputted bytes from the ADC, but I do not know how to convert a 2's complement data to the corresponding decimal format.

Kindly also advise how I can convert the data to voltages, the VREF- and VREF+ voltages are -1.29 and 1.23 respectively.

thanks
arunb

Here are some samples of ADC readings (they contain the flag, data and the sign bit), the sign bit is at the extreme left side

Sample 1: 010000000010110100001000
Sample 2: 010000000010110100001000
Sample 3: 010000001010110100001000
Sample 4: 010000001100110100000001
Ttelmah
Guest







PostPosted: Sun Apr 15, 2007 6:51 am     Reply with quote

Write the data into a signed int32 called (say) value.
Then:
Code:

int1 sign=false;
if (value & 0x800000) sign=true;
value &= 0x7FFFF0;
value /=16;
if (sign) value &= 0xFFF80000;

I think this should be close. Basically, the signed integers in CCS, are already 'twos complement', but you need to remove the low four bits from the incoming value, and then 'extend' the single sign bit, to make a 32bit number (generating 13 bits from this).

Best Wishes
arunb



Joined: 08 Sep 2003
Posts: 492
Location: India

View user's profile Send private message Send e-mail

RE:
PostPosted: Sun Apr 15, 2007 9:53 pm     Reply with quote

Thank you for the reply,

Kindly explain the code you have mentioned in the previous post.

Also is it not necessary to convert the 2's complement data to the 'normal' binary form before converting to voltage levels ???.

Please also mention how I can change the binary data to the equivalent voltage level (read by the ADC), as mentioned before the ADC has VREF+ = 1.28 and VREF- = -1.23 V, the resolution the ADC is 20 Bits

thanks
arunb
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