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.

2's complement output in ADC...

Status
Not open for further replies.

Priya

Newbie level 5
Joined
Dec 13, 2003
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
117
adc 2s complement

I have CS5550 ADC from cirrus logic. The output register is of the form

-(2^0) (2^-1) (2^-2) .......... (2^-23)

This is a 24-bit register. It is given in the datasheet that : These register contain the last value of the measured results of AIN1 and AIN2. The results will be within the range of -1.0 <= AIN1, AIN2 < 1.0. The value is represented in 2's complement notation, with the binary point place to the right of the MSB (MSB have a negative weighting. These values are 22 bits in length. The 2 least significant bits,(located at the far right-side) have no meaning, and will always have a value of "0". I use this ADC for weighing scale application. How can I use the output from ADC to calculate the weight? So far I dealt with ADC's which give output in binary coding and I can directly map into corresponding weight. I have no idea with the 2's complement form.

Help me.
 

float to 2s complement

In order to compute a 2's complement value you need to invert all bits and then add one.

For example for signed integer with 16 bit:

+1 = 0001
-1 = FFFF
( inverting +1 you'll have FFFE
then add 1 you'll achieve FFFF )

So, positives number are simply represented with binary value and negatives are reperesented with the binary value that null a positive binary with the same magnitude.

The MSB is the sign (sign bit) of number: if 0, the number is positive, negative if 1.

2's complement is used usually to represent signed integers.
 

2s complement conversion + adc

To convert this 2's complement format to the one you are familiar with is quite simple.

You only need to invert the highest bit of what you read in.
For example +1(0x001 becomes 801). -1(0xFFF) becomes(7FF). In this way the highest value corresponds to highest actual voltage, lowest value corresponds to lowest actual voltage.

regards
 

output the adc value

Hi,
MSB
------------------------------------------------------------------------
|-(2^0)| (2^(-1)) | (2^(-2)) | (2^(-3)) | (2^(-4)) | (2^(-5)) |
------------------------------------------------------------------------

-----------------------------------------------------------------------------
|(2^(-6))| (2^(-7)) | (2^(-8)) | (2^(-9)) | (2^(-10)) | (2^(-11)) |
-----------------------------------------------------------------------------

-----------------------------------------------------------------------------------
|(2^(-12))| (2^(-13)) | (2^(-14)) | (2^(-15)) | (2^(-16)) | (2^(-17)) |
-----------------------------------------------------------------------------------

-----------------------------------------------------------------------------------
|(2^(-18))| (2^(-19)) | (2^(-20)) | (2^(-21)) | (2^(-22)) | (2^(-23)) |
-----------------------------------------------------------------------------------
LSB

This means the value is in fraction. Isn't it? It will exist in between -1 to 1 as it is a signed register. If this register value has 0x808080 then should it be like (-1 + 1*(2^(-8)) + 1*(2^(-16))) = (-1 + 0.00390625 + 0.0000152587890625) = -0.9960784912109375 ? Should I map this value into weights?

Help me?
 

convert register to 2s complement

Hi,
How are you processing the output of the ADC? FPGA/DSP.
It seems like you using some processor. You need not map the values. You may just use some logical operations to convvert it into 2s complement. Some of them are suggested in previous responses. Check what is the reference voltage to the ADC. This will determine whether the input is from -1 to 1 or some other range. If you have more problems PM me.
BR
 

converting back 2s complement

I am using Atmels 89C51 microcontroller. Why it is necessary to convert into 2's complement form. Already the result is in the 2's complement form. Before I had dealt with ADUC816. The 16-bit result would be available in the data register in binary coding. Suppose the result in the register is
0010 0101 1111 1001b = 0x25F9. I would map this value into corresponding weight by 0x25F9/x = y and z=y*0.1. where 0.1 is the resolution and z is my resultant weight. Here with 2's complement output how shall I proceed?
 

adc weigh scale application

Hi,
I had a look at the data sheet. Is u'r problem
how to map the output to weight?
Seems like you have to tkae into account the gain and offset. If you have already done it do ignore this. It might take a while before someone can really get your problem and help you.
BR
 

two complement adc

Priya,

your value, 0010 0101 1111 1001b = 0x25F9, is a positive value, so you need to scale 0x25F9 in eng units (i.e 25F9(hex) = 9721(dec) and y=9721/x. You know above value is positive because MSB = 0.

Otherwise, if number would be 1101101000000111 = DA07 you recognize this value as negative. Hence, test MSB, if 1 the value is negative. In this case subtract one from DA07. (i.e. 1101101000000111 - 1 = 1101101000000110 = DA06 ). Then invert result. i.e inv (DA06) = 25F9 = 9721 * -1 = -9721. Finally do the scale in eng units.
 

cs5550 claim

Is it looks like this, the 2^-23 corresponds to the least value of AIN1 which causes a change in LSB?
 

what is twos complement adc

I downloaded datasheet of this baby and got a quick reading. It's a complex one though featured one. If you read page 22 of CIRRUS LOGIC doc (DS630PP1) you would have an answer to latter question.

I suppose you want use the signed format (-1 to 1) so 2^-23 and 2^-22 are located to the righ-side of word (LSB) and they have been declared always "zero" so will not contribute to resolution. The true LSB will be (following them) 2^-21 so resolution will be a 22 bits, even though the full word is 24 bits.

Another thing about unusual format they claim. They said the number is the binary representation of -1 to 1 (signed format), so the binary point is placed to the right of MSB (2^0). However I think you can consider it a 2^23 binary number and rationalize it with (2^23)-1/2^23 for positive numbers (so never equal to +1) and 2^23/2^23 *-1 for negative.
 

lsb msb 2s complement

As the last 2 bits are always 0, should I take the 24 bits (ie considering last 2 bits as zero) and map into weight or should I take the first 22 bits alone(discarding the last 2 bits and treating as 22 bit value) and map into weight.
 

adc negative number binnary

I did it like this. Is it correct? 2^24 = 16777216. I want my weight in kg with resolution of 0.1. So divided 16777216/1500 = 11184 (2BB0). 2BB0 when represented in fractional form gives 0.001333237.
I calculate how many 0.001333237 are in the obtained result. The digital output 0xFFFFFF maps to 0 weight, 0x000000 to 75kg and 0x7FFFFF maps to 150kg. That value divide by 10 gives the weight.

long int DigitalOutput;
int RaiseToPower;
int ShiftBit;
float CalculatedValue = 0.0f ;
float sign = (DigitalOutput & 0x800000) ? -1.0f : 1.0f ;
float weightvalue;
int WeightInt;

for (RaiseToPower=23; RaiseToPower>0; RaiseToPower--)
{
if (DigitalOutput & ((long)1<<ShiftBit))
{
CalculatedValue += 1.0f / (float)((long)
1<<RaiseToPower) ;
}
ShiftBit++;
}
weightvalue = sign * CalculatedValue ;
WeightInt = weightvalue/0.001333237;
WeightInt = WeightInt + 750;
weightvalue = (float)WeightInt/10;

Regards,
Priya.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top