This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADS1118: Error when reading ambient temperature & thermocouple simultaneously !!

Part Number: ADS1118

Hi

I'm working on a 1000 degree furnace controller using ATMEGA32A and ADS1118. I downloaded the ads1118 library from github.com/hydrosense. everything works fine when I read ambient temperature OR thermocouple separately but when I want to read these two's simultaneously the numbers become equal. I mean ambient temp & thermocouple show the same number (internal sensor value). if anyone could help, it will be appreciated.

regards

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>
#include "Ads1118.h"
#include <SPI.h>



const int LS100_LED = 8;
const int LS200_LED = 9;
const int METALCAST_LED = 10;
const int HP_LED = 11;
const int MP_LED = 12;
const int LP_LED = 13;
const int LS100_SW = 24;
const int LS200_SW = 25;
const int METALCAST_SW = 26;
const int HP_SW = 27;
const int MP_SW = 28;
const int LP_SW = 30;
const int START_SW = 29;
const int STOP_SW = 31;
const int SSR = 3;
const int RELAY = 4;
const int BUZZER = 2;
//const int TEMP = 1;   //ADS1232
//const int MUX = 0;   //ADS1232
//const int GAIN0 = 23;  //ADS1232
//const int GAIN1 = 22;   //ADS1232
//const int SPEED = 21;   //ADS1232
//const int PWDN = 20;   //ADS12332
//const int SCLK = 15;   //ADS1232
//const int DRDY = 19;   //ADS1232
float offset = EEPROM.read(10);
int Buffer = 0;
int Htemp = 900;
unsigned long lastmillis1 = 0;
unsigned long lastmillis2 = 0;
unsigned long lastmillis3 = 0;
unsigned long lastmillis4 = 0;
float Ctemp = 0;
//  int Eraser = 0b10000000;
//  int Prescaler = 0b01101010;

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  //  I2C address could be 0x3F OR 0x27

Ads1118 ads1118(1);

void setup()
{
  pinMode(LS100_LED, OUTPUT);
  pinMode(LS200_LED, OUTPUT);
  pinMode(METALCAST_LED, OUTPUT);
  pinMode(HP_LED, OUTPUT);
  pinMode(MP_LED, OUTPUT);
  pinMode(LP_LED, OUTPUT);
  pinMode(LS100_SW, INPUT_PULLUP);
  pinMode(LS200_SW, INPUT_PULLUP);
  pinMode(METALCAST_SW, INPUT_PULLUP);
  pinMode(HP_SW, INPUT_PULLUP);
  pinMode(MP_SW, INPUT_PULLUP);
  pinMode(LP_SW, INPUT_PULLUP);
  pinMode(START_SW, INPUT_PULLUP);
  pinMode(STOP_SW, INPUT_PULLUP);
  pinMode(BUZZER, OUTPUT);;
  pinMode(RELAY, OUTPUT);
  pinMode(SSR, OUTPUT);
  //  pinMode(TEMP, OUTPUT);   //ADS1232
  //  pinMode(MUX, OUTPUT);   //ADS1232
  //  pinMode(GAIN0, OUTPUT);   //ADS1232
  //  pinMode(GAIN1, OUTPUT);   //ADS1232
  //  pinMode(SPEED, OUTPUT);   //ADS1232
  //  pinMode(PWDN, OUTPUT);   //ADS1232
  //  pinMode(SCLK, OUTPUT);   //ADS1232
  //  pinMode(DRDY, INPUT);   //ADS1232
  //  digitalWrite(TEMP, LOW);
  //  digitalWrite(MUX, LOW);
  //  digitalWrite(GAIN0, HIGH);
  //  digitalWrite(GAIN1, HIGH);
  //  digitalWrite(SPEED, HIGH);
  //  digitalWrite(PWDN, HIGH);
  Wire.begin();
  delay(500);
  digitalWrite( SSR, LOW );
  digitalWrite( RELAY, LOW );
  lcd.begin(16, 2);
  lcd.clear();
  ads1118.begin();
  ads1118.setGain(0b101);
  //  //================ PWM Frequency PreScaler ================
  //  TCCR2 &= Eraser;
  //  TCCR2 |= Prescaler;
  //  OCR2 = 0x00;
  //  //=========================================================

  lcd.setCursor(0, 0);
  lcd.print("   LIDOMA Ltd   ");
  lcd.setCursor(0, 1);
  lcd.print("   Pressmatik   ");
  delay(3000);
  lcd.setCursor(0, 0);
  lcd.print(" CHOOSE PROGRAM ");
  lcd.setCursor(0, 1);
  lcd.print("                ");
}

void loop() {
  if ( digitalRead( LS100_SW ) == LOW ) {
    digitalWrite( LS100_LED, HIGH );
    digitalWrite( LS200_LED, LOW );
    digitalWrite( METALCAST_LED, LOW );
    digitalWrite( LP_LED, LOW );
    digitalWrite( MP_LED, LOW );
    digitalWrite( HP_LED, LOW );
    Buffer = 10;
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("     100 g      ");
    //Display();

  }
  else if ( digitalRead( LS200_SW ) == LOW ) {
    digitalWrite( LS100_LED, LOW );
    digitalWrite( LS200_LED, HIGH );
    digitalWrite( METALCAST_LED, LOW );
    digitalWrite( LP_LED, LOW );
    digitalWrite( MP_LED, LOW );
    digitalWrite( HP_LED, LOW );
    Buffer = 20;
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("     200 g      ");
    //Display();

  }
  else if ( digitalRead( METALCAST_SW ) == LOW ) {
    digitalWrite( LS100_LED, LOW );
    digitalWrite( LS200_LED, LOW );
    digitalWrite( METALCAST_LED, HIGH );
    digitalWrite( LP_LED, LOW );
    digitalWrite( MP_LED, LOW );
    digitalWrite( HP_LED, LOW );
    Buffer = 30;
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("   PFM PREHEAT  ");
    //Display();

  }
  else if ( ( digitalRead( LP_SW ) == LOW ) && ( Buffer == 10 || Buffer == 12 ) ) {
    digitalWrite( LP_LED, HIGH );
    digitalWrite( MP_LED, LOW );
    digitalWrite( HP_LED, LOW );
    Buffer = 11;
    Htemp = 910;
    //lcd.clear();
    lcd.setCursor(0, 1);
    lcd.print("HT-MT-HO-Impulse");
    //Display();

  }
  else if ( ( digitalRead( MP_SW ) == LOW ) && ( Buffer == 10 || Buffer == 11 ) ) {
    digitalWrite( LP_LED, LOW );
    digitalWrite( MP_LED, HIGH );
    digitalWrite( HP_LED, LOW );
    Buffer = 12;
    Htemp = 915;
    //lcd.clear();
    lcd.setCursor(0, 1);
    lcd.print("     LT-MO      ");
    //Display();

  }
  else if ( ( digitalRead( LP_SW ) == LOW ) && ( Buffer == 20 || Buffer == 22 || Buffer == 23 ) ) {
    digitalWrite( LP_LED, HIGH );
    digitalWrite( MP_LED, LOW );
    digitalWrite( HP_LED, LOW );
    Buffer = 21;
    Htemp = 915;
    //lcd.clear();
    lcd.setCursor(0, 1);
    lcd.print("HT-MT-HO-Impulse");
    //Display();

  }
  else if ( ( digitalRead( MP_SW ) == LOW ) && ( Buffer == 20 || Buffer == 21 || Buffer == 23 ) ) {
    digitalWrite( LP_LED, LOW );
    digitalWrite( MP_LED, HIGH );
    digitalWrite( HP_LED, LOW );
    Buffer = 22;
    Htemp = 917;
    //lcd.clear();
    lcd.setCursor(0, 1);
    lcd.print("       LT       ");
    //Display();

  }
  else if ( ( digitalRead( HP_SW ) == LOW ) && ( Buffer == 20 || Buffer == 21 || Buffer == 22 ) ) {
    digitalWrite( LP_LED, LOW );
    digitalWrite( MP_LED, LOW );
    digitalWrite( HP_LED, HIGH );
    Buffer = 23;
    Htemp = 920;
    //lcd.clear();
    lcd.setCursor(0, 1);
    lcd.print("       MO       ");
    //Display();

  }
  else if ( digitalRead( START_SW ) == LOW ) {
    STARTPRESS();
  }
  
  
  //delay(50);
  
  float A = ( ads1118.adsReadRaw(ads1118.DIF01) * 0.256 / 32768 ) * 1000 ;
  //float B = ads1118.readTemp();
  
  lcd.setCursor(0, 0);
  lcd.print( "      " );
  //lcd.print( B, 1 );
  lcd.print( "      " );
  lcd.setCursor(0, 1);
  lcd.print( "      " );
  lcd.print( convert(A), 5 );
  lcd.print( "      " );
  //ads1118.update_config(0x008B);
  delay(50);

}

void STARTPRESS() {

}

float convert ( float MV ) {
  float T = 137.9263 + (((MV - 0.93395) * (0.09615 * MV * MV * MV + 19.62905 * MV * MV + 73.97377 * MV + 41.33051)) / (0.20813 * MV * MV + 0.57668 * MV + 0.27986));
  //float T = 137.92 + (127.61*(MV - 0.933) + 110.89*(MV - 0.933)*(MV - 0.933) + 19.89*(MV - 0.933)*(MV - 0.933)*(MV - 0.933) + 0.096*(MV - 0.933)*(MV - 0.933)*(MV - 0.933)*(MV - 0.933)) / ( 1+0.965*(MV - 0.933)+0.208*(MV - 0.933)*(MV - 0.933) );
  return T;
}

ADS1118-master.zip

  • Milad,


    The ADS1118 cannot simultaneously sample the ambient temperature and the thermocouple. This device has a single ADC and there is an input multiplexer that is used to collect data from different channels (including the on-board temperature sensor). If you read the data from the thermocouple, and then change the setting for the temperature sensor, the device completes the conversion in progress, and then moves to the next multiplexer setting.

    The best that you can do is to interleave conversions between channels. First start a conversion to read the thermocouple, wait for the conversion to complete, and then set the next channel/read back the first conversion. Then wait for the next conversion to complete and then repeat with the previous channel.

    Because you want to alternate channels, I would recommend using single shot conversion mode. This is the most reliable way to set channels and to get back data. With continuous conversion mode, you can change the channel, but the settings do not get changed until the conversion in progress completes.


    Joseph Wu
  • Dear Joseph
    your suggestions help me a lot , So finally I solve the problem and make some modifications on library files. first of all I have to thank you because this project is very important to me, So I will get allowance from Ex-library writer to put my codes here
    regards
    milad chalipa