ADS1115 Freezing

Hi all,

I'm using the very simple sampling sequence below, which runs once per hour. The ADS1115 is sampling a 4-20mA component over a 250Ohm resistor, and moves the cursor of the LCD as a simple animation. When the ADS reading is within the 4mA and 20mA bounds, we speed up the reading (readyToReadCount += 10;), otherwise it progresses at a regular pace (readyToReadCount += 1;).

I have 9 PCBs running this sketch. After ~1 month, one of them froze with the cursor ~ halfway through the screen. I replaced the PCB and have had no problems since. I then added 3 more PCBs. 2 have been working fine for a month. The other froze after 2 days. I reset it, and it froze again after two days.

I'm wondering what you all think about this. I initially though I may have an issue with i2c communication, but it looks fine on the scope. It's a bit of a challenging problem to recreate given the rarity of occurrence.

Thanks for any advice!

Links:
ADS1115 Datasheet
LCD Datasheet

  Serial.println(F("READING SENSOR------------"));
  avgReading = 0.0;
  readyToReadCount = 0;
  while (readyToReadCount < 80)
  {
      avgReading = 0.0;
      for (int i=0; i<5; i++)
      {
          adc0 = ads.readADC_SingleEnded(0);
          avgReading += adc0/5.0;
          delay(10);
      }
      delay(150);
      lcd_set_cursor((readyToReadCount/4),3);
      if(avgReading > 23544.0 || avgReading < 4000.0)
      {
          readyToReadCount += 1;
      } else {
          readyToReadCount += 10;
      }
  }
  avgReading = 0.0;
  for (int z=0; z<50; z++)
  {
      adc0 = ads.readADC_SingleEnded(0);
      Serial.println(adc0);
      avgReading += adc0/50.0;
      delay(10);
  }

Why do you think the issue is in the snippet you posted?

Before this sequence starts, the PCB is sleeping for an hour and the LCD shows a sleeping page. When the unit starts to sample the sensor, it displays "calculating" with the cursor moving across the bottom. The freezing occurs when the cursor is part-way across the screen.

the snippet looks fine. so there is something else happening somewhere else

what's connected to Serial? what type of Arduino?


side note you could optimize a bit your code by doing only one division rather than 5

      avgReading = 0.0;
      for (int i=0; i<5; i++)
      {
          adc0 = ads.readADC_SingleEnded(0);
          avgReading += adc0/5.0;
          delay(10);
      }
      delay(150);

by doing

      avgReading = 0.0;
      for (int i=0; i<5; i++)
      {
          adc0 = ads.readADC_SingleEnded(0);
          avgReading += adc0;
          delay(10);
      }
        avgReading = avgReading/5.0;
      delay(150);

does reading 5 times at 10ms interval make sense? is your voltage varying so quickly? usually reading once (or twice if the previous read was done recently on another Analog Pin) is good enough

Thanks; this is a 16 bit chip, so 20mA readings are 21k+ which caused the int avgReading to overrun. I figured this would be more efficient than changing to a double.

This is a Mega2560. Originally I thought that it may be wavering on i2c communication, but the rarity of this is puzzling (11% of units, and only after 3 weeks, on average).

There's nothing connected to serial at the time of running; I use it for debugging with my computer ahead of time.