Skip to content

Commit

Permalink
Merge pull request #5 from Protocentral/v1.1
Browse files Browse the repository at this point in the history
Merged new library re-write with v1.1
  • Loading branch information
protocentralashwin authored Jun 18, 2018
2 parents 600d519 + 139922a commit 2c0107e
Show file tree
Hide file tree
Showing 5 changed files with 373 additions and 343 deletions.
89 changes: 89 additions & 0 deletions examples/ADS1220_Read_Sequential/ADS1220_Read_Sequential.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//////////////////////////////////////////////////////////////////////////////////////////
//
// Demo code for the ADS1220 24-bit ADC breakout board
//
// Author: Ashwin Whitchurch
// Copyright (c) 2018 ProtoCentral
//
// This example sequentially reads all 4 channels in continuous conversion mode
//
// Arduino connections:
//
// |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 | - |
//
// This software is licensed under the MIT License(http://opensource.org/licenses/MIT).
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// For information on how to use, visit https://github.com/Protocentral/Protocentral_ADS1220
//
/////////////////////////////////////////////////////////////////////////////////////////

#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 FULL_SCALE (((long int)1<<23)-1)

#define ADS1220_CS_PIN 7
#define ADS1220_DRDY_PIN 6

Protocentral_ADS1220 pc_ads1220;
int32_t adc_data;

void setup()
{
Serial.begin(9600);

pc_ads1220.begin(ADS1220_CS_PIN,ADS1220_DRDY_PIN);

pc_ads1220.set_data_rate(DR_330SPS);
pc_ads1220.set_pga_gain(PGA_GAIN_1);

pc_ads1220.set_conv_mode_single_shot(); //Set Single shot mode
}

void loop()
{
adc_data=pc_ads1220.Read_SingleShot_SingleEnded_WaitForData(MUX_SE_CH0);
Serial.print("\n\nCh1 (mV): ");
Serial.print(convertToMilliV(adc_data));
delay(100);

adc_data=pc_ads1220.Read_SingleShot_SingleEnded_WaitForData(MUX_SE_CH1);
Serial.print("\nCh2 (mV): ");
Serial.print(convertToMilliV(adc_data));
delay(100);

adc_data=pc_ads1220.Read_SingleShot_SingleEnded_WaitForData(MUX_SE_CH2);
Serial.print("\nCh3 (mV): ");
Serial.print(convertToMilliV(adc_data));
delay(100);

adc_data=pc_ads1220.Read_SingleShot_SingleEnded_WaitForData(MUX_SE_CH3);
Serial.print("\nCh4 (mV): ");
Serial.print(convertToMilliV(adc_data));
delay(100);
}

float convertToMilliV(int32_t i32data)
{
return (float)((i32data*VFSR*1000)/FULL_SCALE);
}
104 changes: 26 additions & 78 deletions examples/ADS1220_Stream/ADS1220_Stream.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//
// |ADS1220 pin label| Pin Function |Arduino Connection|
// |-----------------|:--------------------:|-----------------:|
// | DRDY | Data ready Output pin| D6 |
// | DRDY | Data ready Output pin| D6 |
// | MISO | Slave Out | D12 |
// | MOSI | Slave In | D11 |
// | SCLK | Serial Clock | D13 |
Expand All @@ -30,99 +30,47 @@
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// For information on how to use, visit https://github.com/protocentral/ProtoCentral_fdc1004_breakout
// For information on how to use, visit https://github.com/Protocentral/Protocentral_ADS1220
//
/////////////////////////////////////////////////////////////////////////////////////////

#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)
#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;
#define ADS1220_CS_PIN 7
#define ADS1220_DRDY_PIN 6

Protocentral_ADS1220 ADS1220;
Protocentral_ADS1220 pc_ads1220;
int32_t adc_data;

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

ADS1220.begin();
Serial.begin(9600);

pc_ads1220.begin(ADS1220_CS_PIN,ADS1220_DRDY_PIN);

pc_ads1220.set_data_rate(DR_330SPS);
pc_ads1220.set_pga_gain(PGA_GAIN_32);
pc_ads1220.select_mux_channels(MUX_AIN0_AIN1); //Configure for differential measurement between AIN0 and AIN1

pc_ads1220.Start_Conv(); //Start continuous conversion mode
}

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();
}
adc_data=pc_ads1220.Read_WaitForData();

if(ADS1220.NewDataAvailable = true)
{
ADS1220.NewDataAvailable = false;
float Vout = (float)((adc_data*VFSR*1000)/FSR); //In mV

MSB = SPI_RX_Buff_Ptr[0];
data = SPI_RX_Buff_Ptr[1];
LSB = SPI_RX_Buff_Ptr[2];
delay(300);

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);
*/
}
Serial.print("Vout in mV : ");
Serial.print(Vout);
Serial.print(" 32bit HEX : ");
Serial.println(adc_data,HEX);
}


2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ProtoCentral ADS1220 24-bit ADC Library
version=1.0.1
version=1.1.0
author=ProtoCentral
maintainer=ProtoCentral
sentence=Library for the ProtoCentral ADS1220 breakout board
Expand Down
Loading

0 comments on commit 2c0107e

Please sign in to comment.