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.
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)