Thursday, 16 April 2015

microcontroller - Analog to digital conversion


I am using an Atmega32-A microcontroller and an AD7798 external ADC. I am able to set the ADC registers and read back ADC values. I have written the following code:


  statusreg = AD7798_8(0x40, 0xFF);          // read STATUS register default value
Id = AD7798_8(0x60, 0xFF); // read ID register default value
mode = AD7798_16(0x48, 0xFFFF); // read MODE register default value
conf = AD7798_16(0x50, 0xFFFF); // read conf register default value

AD7798_16(0x10, 0x0010); // write Configuration reg = 0x0010. 2.5V range
value = AD7798_16(0x50, 0xFFFF); // read Configration register


if (value != 0x0010)
printf("unexpected conf setting %04x\r\n", value);

while ((statusreg & 0x80) != 0); // wait till ADC is ready
adc = AD7798_16(0x58, 0xFFFF); // read register
printf("ADC value is %04d\r\n", adc);

From the above code, I am reading the ADC values. According to the AD7798 datasheet and according to my configuration register setup, I have to find out the analog input voltage using following formula:



When the ADC is configured for bipolar operation, the output code is offset binary, with a negative full-scale voltage resulting in a code of 000...000, a zero differential input voltage resulting in a code of 100...000, and a positive full-scale input voltage resulting in a code of 111...111. The output code for any analog input voltage can be represented as



Code = 2N – 1 × [(AIN × GAIN / VREF) + 1]


where:
AIN is the analog input voltage.
N = 16 for the AD7798, and N = 24 for the AD7799.



I am getting an ADC value of 1EF2(hex) for 0.6V analog input. I have measured using an oscilloscope. I have calculated the analog input voltage using the above formula and I am getting 0.15V. Here GAIN is 1, VREF = 2.5V. Which is wrong because I have to get 0.6V. I have converted resultant hex ADC value into decimal 7922 and also binary 0001111011110010. My analog input voltage is varying from 0V to 0.6V. According to my analog input voltage my ADC output is also changing from 0002 to 1EF2.


If I change the configuration register setup to any other setup like bipolar to unipolar (from 0x0010 to 0x1010), at that time I am getting an ADC value of 0000 always. It is giving an ADC value of 0000 for any configuration other than 0x0010 in the configuration register.


More over, I am not able to understand what the following sentence means:



with a negative full-scale voltage resulting in a code of 000...000, a zero differential input voltage resulting in a code of 100...000, and a positive full-scale input voltage resulting in a code of 111...111.




How do I properly convert resultant digital signal to an analog voltage?
Are my ADC readings right or wrong?
Why does my code not work for any other configuration?



Answer



The AD7798 is a differential ADC. It has a negative input and a positive input. When configured for bipolar operation:




  • When the voltage between in+ and in- is positive (in+ > in-) at full scale the output will be all one.





  • When the voltage between in+ and in- is 0 (in+ == in-) the output will be 1000...0000.




  • And When the voltage between in+ and in- is negative (in+ < in-) at full scale the output will be all zero.




No comments:

Post a Comment

arduino - Can I use TI&#39;s cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...