ADS1256 - Single-, and multi-channel continuous acquisition

In this video I show you how to receive data continuously from the ADS1256 by using two different approaches. One approach is when you cycle through multiple inputs and you build a formatted output by combining multiple values that you send to the serial terminal.The other approach is when you use the RDATAC command and push out data from a single channel continuously. Both methods can provide real time data with high resolution, however the RDATAC is faster due to the way how the conversion result is being read out and also because you do not have to cycle through multiple channels. Cycling decreases the datarate.



Cycling data

//Datasheet: http://www.ti.com/lit/ds/sbas288k/sbas288k.pdf
//This is just a code snippet, not the whole code
void cycleDifferential()
{
    //outside while() loop, we have to switch to the first differential channel ([AIN0+AIN1])
    writeRegister(1, 1); //B00000001 = 1;  [AIN0+AIN1]
    //this can be done also somewhere by another function
while(Serial.read() != 's')
{  
    for(muxcycle = 1; muxcycle < 5; muxcycle++)
    {
    //STEP 1, then STEP4
    waitforDRDY();
    //We select the multiplexer based on the current status of the for() loop
    switch (muxcycle)
        {
        case 1: //Channel 2
            writeRegister(0x01, B00100011); //AIN2+AIN3
            break;
 
        case 2: //Channel 3
            writeRegister(0x01, B01000101); //AIN4+AIN5
            break;
 
        case 3: //Channel 4
            writeRegister(0x01, B01100111); //AIN6+AIN7
            break;         
 
        case 4: //Channel 1
            writeRegister(0x01, B00000001); //AIN0+AIN1
            break;
        }
    //STEP 2
    SPI.beginTransaction(SPISettings(1700000, MSBFIRST, SPI_MODE1)); //Start SPI
    digitalWrite(CS_pin, LOW); //REF: P34: "CS must stay low during the entire command sequence"
    SPI.transfer(B11111100); //Restarting conversion using SYNC
    delayMicroseconds(4); //t11 delay 24*tau = 3.125 us //delay should be larger, so we delay by 4 us
    SPI.transfer(B11111111); //WAKEUP
    //STEP 3
    SPI.transfer(B00000001); //Issue RDATA (0000 0001) command
    delayMicroseconds(7); //Wait t6 time (~6.51 us) REF: P34, FIG:30.
    registerData = 0; //registerData should be zero before reading a new data
    registerData |= SPI.transfer(0x0F); //MSB comes in, first 8 bit is updated
    registerData <<= 8;                 //MSB gets shifted LEFT by 8 bits
    registerData |= SPI.transfer(0x0F); //MSB | Mid-byte
    registerData <<= 8;                 //MSB | Mid-byte gets shifted LEFT by 8 bits
    registerData |= SPI.transfer(0x0F); //(MSB | Mid-byte) | LSB - final result
    Serial.print(registerData); //Print it
    Serial.print('\t');// print a tab, so we will have a nicely formatted ouput
    digitalWrite(CS_pin, HIGH); //We finished the command sequence, so we switch it back to HIGH
    SPI.endTransaction(); //END SPI    
    }
    Serial.println();
}
}


RDATAC function

//Datasheet: http://www.ti.com/lit/ds/sbas288k/sbas288k.pdf
//This is just a code snippet, not the whole code 
void readSingleContinuous()
{
  //Some commands should only be initiated in the beginning of this type of acquisition (RDATAC)
  //Therefore, we run them outside the while().        
    SPI.beginTransaction(SPISettings(1700000, MSBFIRST, SPI_MODE1));
    digitalWrite(CS_pin, LOW); //REF: P34: "CS must stay low during the entire command sequence"
 
    waitforDRDY();//Wait for DRDY to go LOW
    SPI.transfer(B00000011);  //Issue RDATAC (0000 0011) command
    delayMicroseconds(7);    //Wait t6 time (~6.51 us) REF: P34, FIG:30.
   
    while (Serial.read() != 's')
    {
    registerData = 0; // every time we call this function, this should be 0 in the beginning!
    waitforDRDY();
       
    //Previously, we used 0x0F, here we use 0 for the SPI.transfer() argument;
    registerData |= SPI.transfer(0); //MSB comes in, first 8 bit is updated
    registerData <<= 8;                 //MSB gets shifted LEFT by 8 bits
    registerData |= SPI.transfer(0); //MSB | Mid-byte
    registerData <<= 8;                 //MSB | Mid-byte gets shifted LEFT by 8 bits
    registerData |= SPI.transfer(0); //(MSB | Mid-byte) | LSB - final result
       
    Serial.println(registerData);  
    }
    digitalWrite(CS_pin, HIGH); //We finished the command sequence, so we switch it back to HIGH
    SPI.endTransaction();   //Close SPI
}

Previous
Previous

ADS1256 - Analyzing SPI data

Next
Next

ADS1256 - Reading a single conversion result using RDATA