I'm working on a project that will use J-type thermo-couples to take generally precise measurements, however I want to use an external analog to digital converter over the ones on the Arduino Mega2560. I'm using TI's ADS1118 chip, and while I get a digital signal out, the conversion to volts is completely inaccurate (and static).
These are the data sheets I'm using for the ADC. I've set up the circuit shown in Figure 3 of the Accurate Temperature data sheet for testing purposes (with a slight modification in that the 3.3V supply on the schematic has been replaced with 5V):
http://www.ti.com/lit/ds/symlink/ads1118.pdf (ADS1118 Data Sheet)
http://www.ti.com/lit/an/sbaa189/sbaa189.pdf (Accurate Temperature)
And this code I found from a project that had used an ADS1118:
#include <SPI.h>
void setup() {
Serial.begin(9600);
// Set up and start the SPI serial interface
SPI.begin();
SPI.setBitOrder(MSBFIRST); // Most significant bit first
SPI.setClockDivider(SPI_CLOCK_DIV8); // Step down the arduino clock by 8
SPI.setDataMode(SPI_MODE1); //Serial interface timing
}
void loop()
{
Serial.println(readRaw());
Serial.println (readVoltage(),8);
delay(1000);
}
/* Allows the caller to read the raw value from the ADS1118 */
int readRaw(void) {
int rawValue; // Raw value received back from the ADS1118
byte MSB, LSB; //The most and least significant bits read from the ADS1118
byte MSBConf=B10001011; // Most Significant Bit configuration register
//11010001
byte LSBConf=B11110010; // Least Significant Bit configuration register
//10000010
// Read the ADS1118's channel's A0 and A1 as temperature in single-shot mode
MSB = SPI.transfer(MSBConf);
LSB = SPI.transfer(LSBConf);
//SPI.transfer(MSBConf);
//SPI.transfer(LSBConf);
// Build the raw value from the most and least significant bits
rawValue = (MSB << 8) | LSB;
return rawValue;
}
/* Allows the caller to read the raw voltage */
double readVoltage(void) {
int rawValue; // Raw value received back from the ADS1118
double volts; // Converted voltage from the raw value
const double amp = 0.256000; // FS multiplier in register (check data sheet)
// Get the raw value so that we can convert it to a voltage
rawValue = readRaw();
// Convert the raw value to the corresponding voltage (16 bits = 0 to 32767)
volts = amp * ((double)rawValue / 32768);
return volts;
}
And finally here is the serial debug, which appears to be a bunch of gobilty-gook:
(attached .png image)