Protocentral ADS1220 Adjusting Default Settings

Hi,

I am currently using Protocentral's ADS1220 24-bit ADC along with Arduino UNO. My goal is to be able to read data from an accelerometer to record data from all 3 axes at once at high resolution and data rates. To do this, I need to be able to change the default settings used in the example code to use single-ended measurements so I can read from 3 different channels. I also need to increase the data rate and set the device to turbo mode to get the highest data rate the device is capable of. So far I have been unable to figure out how to do this successfully. I have attached the libraries it comes with and the data sheet can be found at the following link.

Protocentral ADS1220

The example code is below.

/*************************************************************
Protocentral_ADS1220.ino
this example gives differential voltage across the AN0 And AN1 in mV
Hooking-up with the Arduino
|ads1220 pin label| Pin Function         |Arduino Connection|
|-----------------|:--------------------:|-----------------:|
| DRDY            | Data ready Output pin|  D6              |             
| MISO            | Slave Out            |  D12             |
| MOSI            | Slave In             |  D11             |
| SCLK            | Serial Clock         |  D13             |
| CS              | Chip Select          |  D7              |
| DVDD            | Digital VDD          |  +5V             |
| DGND            | Digital Gnd          |  Gnd             |
| AN0-AN3         | Analog Input         |  Analog Input    |
| AVDD            | Analog VDD           |  -               |
| AGND            | Analog Gnd           |  -               |
*************************************************************/

#include "Protocentral_ADS1220.h"
#include <SPI.h>

#define PGA 1                 // Programmable Gain = 1
#define VREF 2.048            // Internal reference of 2.048V
#define VFSR VREF/PGA             
#define FSR (((long int)1<<23)-1)  

volatile byte MSB;
volatile byte data;
volatile byte LSB;
//volatile char SPI_RX_Buff[3];
volatile byte *SPI_RX_Buff_Ptr;

Protocentral_ADS1220 ADS1220;

void setup()
{
  pinMode(ADS1220_CS_PIN, OUTPUT);
  pinMode(ADS1220_DRDY_PIN, INPUT);
  
  ADS1220.begin();
}
 
void loop()
{
  long int bit32;
  long int bit24;
  byte *config_reg;
  
  //if((digitalRead(ADS1220_DRDY_PIN)) == LOW)             //        Wait for DRDY to transition low
  { 
    SPI_RX_Buff_Ptr = ADS1220.Read_Data();
  }

  if(ADS1220.NewDataAvailable = true)
  {
  ADS1220.NewDataAvailable = false;

  MSB = SPI_RX_Buff_Ptr[0];    
  data = SPI_RX_Buff_Ptr[1];
  LSB = SPI_RX_Buff_Ptr[2];

  bit24 = MSB;
  bit24 = (bit24 << 8) | data;
  bit24 = (bit24 << 8) | LSB;                                 // Converting 3 bytes to a 24 bit int
    
  /*if (MSB & 0x80)
    bit32 = (bit24 | 0xFF000000);             // Converting 24 bit two's complement to 32 bit two's complement
  else    
    bit32 = bit24;
  */
  
  bit24= ( bit24 << 8 );
  bit32 = ( bit24 >> 8 );                      // Converting 24 bit two's complement to 32 bit two's complement
  
  float Vout = (float)((bit32*VFSR*1000)/FSR);     //In  mV
  
  delay(300);
  
  Serial.print("Vout in mV : ");  
  Serial.print(Vout);
  Serial.print("  32bit HEX : ");
  Serial.println(bit32,HEX);
  
 /* 
  config_reg = ADS1220.get_config_reg();
 
  Serial.print("Config Reg : ");
  Serial.print(config_reg[0],HEX);
  Serial.print(" ");  
  Serial.print(config_reg[1],HEX);
  Serial.print(" ");
  Serial.print(config_reg[2],HEX);
  Serial.print(" ");
  Serial.println(config_reg[3],HEX);
  
  //ADS1220.set_data_rate(DR_1000SPS);
  //ADS1220.set_data_rate(DR_330SPS);
  //ADS1220.set_pga_gain(PGA_GAIN_32);
 
  Serial.print(MSB,HEX);
  Serial.print(data,HEX);
  Serial.print(LSB,HEX);
  
  Serial.print(vout);
  Serial.print("    ");
  Serial.print(bit32,HEX);
  */
  }
}

The libraries come with a built in function to change the sample rate, and this appears to work. I tested this by reading the voltage from a sinusoidal signal every 10 ms. When I use the default settings, the voltage reading updates about every 5 measurements (~50 ms), which corresponds to the default 20 sps data rate. When I change use the built in function to change the sample rate to 45 sps, the voltage reading updates every 2 to 3 measurements (somewhere between 20 to 30 ms) which seems correct. The code I used for this is below, and I made a slight adjustment to the library to change the cs pin.

/*************************************************************
  |ads1220 pin label| Pin Function         |Arduino Connection|
  |-----------------|:--------------------:|-----------------:|
  | DRDY            | Data ready Output pin|  D6              |
  | MISO            | Slave Out            |  D12             |
  | MOSI            | Slave In             |  D11             |
  | SCLK            | Serial Clock         |  D13             |
  | CS              | Chip Select          |  D10             |
  | DVDD            | Digital VDD          |  +5V             |
  | DGND            | Digital Gnd          |  Gnd             |
  | AN0-AN3         | Analog Input         |  Analog Input    |
  | AVDD            | Analog VDD           |  -               |
  | AGND            | Analog Gnd           |  -               |
*************************************************************/

#include "Protocentral_ADS1220.h"
#include <SPI.h>

#define PGA 1                 // Programmable Gain = 1
#define VREF 2.048            // Internal reference of 2.048V
#define VFSR VREF/PGA
#define FSR (((long int)1<<23)-1)

volatile byte MSB;
volatile byte data;
volatile byte LSB;
volatile byte *SPI_RX_Buff_Ptr;

long int bit32;
long int bit24;
byte *config_reg;

unsigned long dt, t, l;

Protocentral_ADS1220 ADS1220;

void setup() {
  pinMode(ADS1220_CS_PIN, OUTPUT);
  pinMode(ADS1220_DRDY_PIN, INPUT);

  ADS1220.begin();

  // Functions I added:
//  ADS1220.set_read_mode(MUX_AIN0); // Change to differential or single-ended readings
//  ADS1220.set_op_mode(OM_TURBO); // Change operating mode
//  ADS1220.set_volt_ref(VR_REFP); // Change voltage reference used

  // Built-in functions that came with library:
  ADS1220.set_data_rate(DR_45SPS);
//  ADS1220.set_pga_gain(PGA_GAIN_2);


}

void loop() {
  if (dt >= 10) {
    SPI_RX_Buff_Ptr = ADS1220.Read_Data();

    if (ADS1220.NewDataAvailable = true) {
      ADS1220.NewDataAvailable = false;

      MSB = SPI_RX_Buff_Ptr[0];
      data = SPI_RX_Buff_Ptr[1];
      LSB = SPI_RX_Buff_Ptr[2];

      bit24 = MSB;
      bit24 = (bit24 << 8) | data;
      bit24 = (bit24 << 8) | LSB; // Converting 3 bytes to a 24 bit int

      bit24 = ( bit24 << 8 );
      bit32 = ( bit24 >> 8 ); // Converting 24 bit two's complement to 32 bit two's complement

      float Vout = (float)((bit32 * VFSR) / FSR); //In  V
      int A = analogRead(A2);
      float V = A / 1023.0 * 5.0;

      Serial.print(Vout, 3);
      Serial.print('\t');
      Serial.println(V);
      l = millis();
    }
  }
  t = millis();
  dt = t - l;
}

So what I tried to do next was modify the library to add similar functions for the other settings, but these modified functions don't work. I tried to copy exactly what the built-in functions did, so I'm not really sure what exactly I did wrong. When I try to upload a script that uses any of the functions I added I get the following compiling error.

C:\Users\Susie\AppData\Local\Temp\ccE95pjt.ltrans0.ltrans.o: In function `setup':

C:\Users\Susie\Documents\Arduino\myProtocentral_UNO/myProtocentral_UNO.ino:44: undefined reference to `Protocentral_ADS1220::set_read_mode(int)'

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Uno.

When I upload the script using the modified libraries with the added functions commented out it compiles and uploads fine, and the built-in functions still work. I used the same script as above, I just modify it by commenting/uncommenting the settings I want to change. I've attached my modified versions of the libraries as well.

I'm also not sure which settings to use in order to read single-ended measurements from multiple channels on the ADS1220 sequentially. The data sheet indicates that you need to change the MUX bits to change to single-ended measurements, but I'm not sure how to set multiple channels to single-ended measurements or how you read the data from different channels, since the library just has one Read_Data function.

Thanks for any help in advance!

Protocentral_ADS1220.cpp (5.91 KB)

Protocentral_ADS1220.h (2.41 KB)

Protocentral_ADS1220_edited.cpp (7.57 KB)

Protocentral_ADS1220_edited.h (3.31 KB)

Do you have two copies of the library with the same name, but in different folders?

Where is the sketch file that uses the library?

I have a folder that contains both the sketch and the folder containing all the libraries. Inside the Protocentral library folder I put the library files I'm currently using and I put the library files I'm not using into another folder inside the Protocentral library folder so those files aren't used.

so those files aren't used.

I think you need to enable Verbose mode when compiling. You may be surprised are which files ARE used.

I enabled Verbose mode, and it was using the library files it should have been. However, for some reason, simply enabling Verbose mode somehow made it work. Now the functions that I added to the library seem to be working.

Thanks for your help. Do you have any insight on how I can read data from multiple single-ended channels?

Do you have any insight on how I can read data from multiple single-ended channels?

I don't even know what that means.

The Protocentral ADS1220 has 4 analog input channels. I want to be able to hook up 3 different signals to 3 of these analog input channels, and then use Arduino to record measurements from these 3 different signals sequentially (measurement from channel 1, measurement from channel 2, measurement from channel 3, measurement from channel 1, etc).

The library just has one function used to read data, and I'm not sure how you can get readings from the different channels.

I love the example sketch provided with the library:

  if(ADS1220.NewDataAvailable = true)
{

I was experiencing the same phase when I first tried the ads1220.I suggest you go through the library carefully. I made duplicate begin functions for each channel by changing the configuration registers 0x91,0xA1. I'm able to read the data from other channels but the values are not accurate. I also observed that the ADC giving 40mv,33mv,25mv randoms when there are no inputs connected to the AN0, AN1, AN2. I connected pulldown resistor of 450Kohms, then the values showing are 0.18,0.9,0,1 mV etc., when no analog inputs are connected. I have been spending many hours but could not succeed from reading my 3 channel analog data from the sensor. :frowning: