Hello.
I have an Arduino uno reading output values from a 24 bit adc ADS1231 I am able to get the data in 2's compliment format as expected (page 12 data sheet attached), but the problem is I would like it to be in Decimal format with a positive range as an example (0 to 20000) instead of (800000h to 7FFFFFh) and or at least initially a format like (-10000 to + 9999). Please help with how I could do this conversion. I know that 2's compliment to Decimal this is what I have to do:
first check if the number is negative or positive by looking at the sign bit. If it is positive, simply convert it to decimal. If it is negative, make it positive by inverting the bits and adding one. Then, convert the result to decimal. The negative of this number is the value of the original binary. But how do I actually do this in an arduino platform c.
To read the adc values at the moment I am using:
data types:
Code:
uint32_t adcvalue;
uint32_t c,y;
reading the adc data:
Code:
void readADS1231(void)
{
adcvalue=0;
while(digitalRead(D_OUT));//WAIT UNTIL DATA IS READY
//24-->21 bits
clock ();
if(digitalRead(D_OUT)){adcvalue=adcvalue+0x800000;} //24
clock ();
if(digitalRead(D_OUT)){adcvalue=adcvalue+0x400000;}//23
clock ();
if(digitalRead(D_OUT)){adcvalue=adcvalue+0x200000;}//22
.... etc
displaying the data:
Code:
void displaydata(void)
{
readADS1231();
y=(adcvalue);
Serial.print("adcvalue DEC = ");Serial.print(y);
delay(1000);
}