I am successfully reading external ADC value using ATmega32-A.
Unsigned int adc; adc = AD7798_16(0x58, 0xFFFF); // read register printf("ADC value is %d\r\n", adc);
I am getting ADC value as decimal number range between "0 to 65535". I want to convert it into analog voltage using the fallowing formula.
Code = 2N – 1 × [(AIN × GAIN / VREF) + 1]
AIN is the analog input voltage.
N = 16 for the AD7798, and N = 24 for the AD7799.
I have simplified the formula and calculating
// formula to caluculate analog voltage from digital output :Code = 2N – 1× [(AIN × GAIN/VREF) + 1]
// GAIN / VREF = 1 / 2.5 => 0.4
// 0.4 Ain = ((adc / 32768) - 1)
Ain=(((((float) adc) / 32768) - 1) / 0.416);
printf("value:%.2f [v]\r\n", Ain);
The above formula returns always negative value. I want to print that negative value. I have tried as above but its not working. How to print Ain value? here adc is unsigned value so I am converting into float.
I have tried like this also
Ain = (((adc / 32768.0) - 1) / 0.416); printf("value:%.2f [v]\r\n", Ain);
but I am not able to print that value.