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.

ADS1256: ads1256

Part Number: ADS1256
Other Parts Discussed in Thread: ADS131M04, ADS131M02, ADS131M08

Tool/software:

Hello, i am new to this component, and i try to calculate energy from a 50h volatge ans current.

i try to sample each ch0 and ch1 alternatively (ch0, ch1, ch0,ch1, etc) at 15ksps, with 100 samples by channel.

is it a way to make this, actually, the timing of the channel change is very long (900ms) for 200 samples.

what is the minimum time for a channel change spi (is fast enough) and the best way to do it?

i use the ads1256 library of curiousscientist on github with arduino ide and esp32.

Thanks in advance

  • Hi dan log,

    The ADS1256 is a multiplexed delta-sigma ADC, which has conversion latency due to the digital filter. In other words, the filter needs to reset every time you change the channel, which means you pay a latency penalty each conversion. If you want to learn more, refer to this app note: https://www.ti.com/lit/an/sbaa535a/sbaa535a.pdf?ts=1744386263696

    It sounds like you need a simultaneous sampling ADC - check out the ADS131M0x family of devices e.g. ADS131M02, ADS131M04, ADS131M08, etc. These devices include multiple ADCs in a single package and are designed for energy metering (voltage and current) applications. Here are some reference designs + metrology code library links:

    -Bryan

  • OK thanks i read all ,

  • Hello, i try to see settling time of each operation, but have a problem. In the script below, the channel does not change. Have you an idea? Thanks in advance. (globally i have 8 channel to sample, by pair and calculate energy for each pair)

    #include <SPI.h>

    #define DRDY_PIN  16
    #define CS_PIN    5
    #define CMD_RREG    0x10

    // SPI Settings
    SPISettings ads1256SpiSettings(2000000, MSBFIRST, SPI_MODE1);

    void setup() {
      Serial.begin(115200); // Faster baud rate for minimal print delay
      SPI.begin();
      pinMode(DRDY_PIN, INPUT);
      pinMode(CS_PIN, OUTPUT);
      digitalWrite(CS_PIN, HIGH);

      // Configure ADS1256 for 30kSPS
      writeRegister(0x03, 0xF0); // DRATE=30kSPS
      writeRegister(0x02, 0x48); // PGA=1
      writeRegister(0x01, 0x08); // ch0
      delay(10);
      Serial.println("fin setup");
    }

    void loop() {
      Serial.println("debut loop");
      uint32_t data_ch0, data_ch1;
      unsigned long t_start, t_end;

      // Sample CH0 and CH1 twice
      for (int i = 0; i < 3; i++) {
        // --- CH0 Sampling ---
        t_start = micros();
        setMUX(0x08); // AIN0
        t_end = micros();

        Serial.print("CH0 MUX set: "); Serial.println(t_end - t_start);

        t_start = micros();
        waitDRDY(); // Wait for conversion (includes MUX settling)
        t_end = micros();
        Serial.print("CH0 Conversion: "); Serial.println(t_end - t_start);
        Serial.print("Registre 1: "); Serial.println(readRegister(1));
       

        t_start = micros();
        data_ch0 = readData();
        t_end = micros();
        Serial.print("CH0 Read: "); Serial.println(t_end - t_start);

        // --- CH1 Sampling ---
        t_start = micros();
        setMUX(0x18); // AIN1
        t_end = micros();
        Serial.print("CH1 MUX set: "); Serial.println(t_end - t_start);
        Serial.print("Registre 1: "); Serial.println(readRegister(1));

        t_start = micros();
        waitDRDY();
        t_end = micros();
        Serial.print("CH1 Conversion: "); Serial.println(t_end - t_start);

        t_start = micros();
        data_ch1 = readData();
        t_end = micros();
        Serial.print("CH1 Read: "); Serial.println(t_end - t_start);

        Serial.println("-----");
      }

      while(1); // Stop after 2 samples
    }

    // Set MUX and restart conversion
    void setMUX(uint8_t mux) {
      digitalWrite(CS_PIN, LOW);
      SPI.transfer(0xFC); // SYNC (stop conversions)
      digitalWrite(CS_PIN, HIGH);
      delayMicroseconds(10); // t11 delay

      digitalWrite(CS_PIN, LOW);
      SPI.transfer(0x50);  // WREG (MUX register)
      SPI.transfer(0x00);  // 1 byte to write
      SPI.transfer(mux);
      digitalWrite(CS_PIN, HIGH);

      digitalWrite(CS_PIN, LOW);
      SPI.transfer(0x00);  // WAKEUP (start conversion)
      digitalWrite(CS_PIN, HIGH);
    }

    // Read data after conversion
    uint32_t readData() {
      digitalWrite(CS_PIN, LOW);
      SPI.transfer(0x01);  // RDATA command
      uint32_t val = SPI.transfer(0) << 16;
      val |= SPI.transfer(0) << 8;
      val |= SPI.transfer(0);
      digitalWrite(CS_PIN, HIGH);
      return val;
    }

    void waitDRDY() {
      while (digitalRead(DRDY_PIN) == HIGH);
    }

    void writeRegister(uint8_t reg, uint8_t val) {
      SPI.beginTransaction(ads1256SpiSettings);
      digitalWrite(CS_PIN, LOW);
      SPI.transfer(0x50 | (reg << 2)); // WREG command
      SPI.transfer(0x00); // 1 byte to write
      SPI.transfer(val);
      digitalWrite(CS_PIN, HIGH);
      SPI.endTransaction();
      delay(100);
    }

    uint8_t readRegister(uint8_t reg) {
      uint8_t value;
      SPI.beginTransaction(ads1256SpiSettings);
      digitalWrite(CS_PIN, LOW);
      SPI.transfer(CMD_RREG | reg);
      SPI.transfer(0x00);
      delayMicroseconds(10);
      value = SPI.transfer(0xFF);
      digitalWrite(CS_PIN, HIGH);
      SPI.endTransaction();
      delay(100);
      return value;
    }
    The result is :CH0 MUX set: 66
    CH0 Conversion: 217
    Registre 1: 240
    CH0 Read: 44
    CH1 MUX set: 67
    Registre 1: 240
    CH1 Conversion: 1
    CH1 Read: 43
    -----