Go Down

Topic: Problem with ADS1256 board (Read 11309 times) previous topic - next topic

nchazarra

Hi to everybody,

This is my first message to the forum. I've been reading it a lot since I started a year ago working with Arduino for my geology projects, and first, I would like to say thanks for the big community support I always find in the board.

Now I've got one question. Two weeks ago I bought an ADS1256 board (the one of the attached image). I've been struggling to make it work and get some readings, but I didn't succeed. I tried to use the ADS1213 library, and also the ADS1248, but the only values I've got are -1 or 0 with an Arduino UNO board and also with a DUE.

Anybody can help?

Thanks in advance.


knut_ny

for some reason I cannot download your picture.  post a link to shop?   Show connections & code
Ny

nchazarra

I bought this model: http://www.ebay.com/itm/ADS1256-24Bits-ADC-AD-Module-Communication-Modules-Capture-Board-Module-Kit-/151512712677

I was using the code from the ADS1213 library:

Code: [Select]
// This sketch demonstrates the use of the ADS1213 library by first initializing
// it with the neccesary parameters, then reading it every half second while cycling through the channels.

#include <ADS1213.h>

ADS1213 ADC_ext(16,false,13,11,2,0);
// clock speed MHz, true=offset binary (false=two's complement (can be negative)), SCLK pin, IO pin, DRDY pin, CS pin (0 if not in use)

void setup() {
  Serial.begin(115200);
  ADC_ext.CMRwrite(3,B001,1,1,255);
  // channel 3, mode 001 (self-calibration), gain 1, TMR 1, DR 255
  Serial.println("Done with setup");
}

void loop() {
  static byte Channel=1; // Static makes sure it doesn't get re-initialized every time
  Serial.print(Channel,DEC); Serial.print(" ch ");
  Serial.println(ADC_ext.readSigned(3),DEC); // Read and print the signed value
  Channel += 1;
  if (Channel>4) Channel = 1;
  ADC_ext.channel(Channel); // Set the current (incremented) channel by using the channel() function
  delay(500);
}


The connections were the SCLK to the pin 13, IO to the pin 11, DRDY to the pin 2, and tested the cable select option connected to a pin, and without any connection, but got the same results.

knut_ny

I believe you found library from here.

Chips are very alike, so the lib may work.  Choose other pin (than pin 0) for CS
Channel 3 is read in your code. (not full bridge with differential inputs)
Ny

nchazarra

I just continue to have readings like -1. When I get my hands close to the Analog pins, the readings change to 0, but nothing else.

nchazarra

Now, using the ADS1213 I got lectures, but only when I put my hands over the geophone, using this code, but the lectures don't make any sense to me.:
Code: [Select]
#include <ADS1213.h>

ADS1213 ADC_ext(16,true,13,10,3,0);
// clock speed MHz, true=offset binary (false=two's complement (then the output can be negative)), SCLK pin, IO pin, DRDY pin, CS pin (0 if not in use)

void setup() {
  Serial.begin(115200);
  ADC_ext.CMRwrite(3,B001,1,1,50);
  // channel 3, mode 001 (self-calibration), gain, TMR, Decimation Ratio
  Serial.println("Done with setup");
}

const int NoOfSamples = 60; // Warning: if set too high, DeviationSqSum may overflow!
// This will happen sooner when the real standard deviation is higher.
unsigned long Values[NoOfSamples];

void loop() {
 
    double lec=ADC_ext.read(B000,3);
    Serial.println(lec);

  delay(20); // Wait a second to avoid overflowing the serial monitor with data
}



knut_ny

#6
May 10, 2016, 07:46 pm Last Edit: May 10, 2016, 08:17 pm by knut_ny
Try using hardware SPI.. pins clk 13, MISO 12 and MOSI 11
I'll download https://github.com/Flydroid/ADS12xx-Library this one and take a peek inside..
-----------
There in an .ino-file included..  It tells you to alter the "ads12xx.h"
(I can see it needs to be changed)
In the example, change RDY, CS and Start to match any digital pin (except 11..13)
Ny

nchazarra

Knut_ny,

I've tried this library, but the program that is served as an example it doesn't work for me, just gets stuck after selecting any of the commands.

I see also that my board doesn't have a START pin, but I obviously must be doing anything else wrong.

My plan is using this board to get the data from three geophones as differential inputs to get a higher dinamic range than when I use a 16 bit ADC.

Thanks for your help.

knut_ny

The full datasheet has all info needed to program and read the chip.
RDY-line tells when a convertion is done and data can be fetched.  If the input is from an ocsillating source it may be difficult to interpret the reading.
Maybe some enveloping can be done before reading. (to read interval peak values)

What kind of signals/levels do you det from the geophones?   frequency?

..and take a look at ebay.. HX711  (differential, amplifying inputs 32/64/128 times) @<$3
Ny

nchazarra

The problem is that I don't have enough programming background, that is why I tried to use these already made libraries.

I usually read frequencies under 50 Hz, but I use three geophones simultaneously, two horizontal and one vertical. The HX711 only have two differential inputs, but I'm gonna give it a try.

Thanks for the advice!

knut_ny

!! See the HX711 datasheet.. You usually use only one channel as it it related to ampl. factor
Ny

yatinpurohit

hello

ADS1256 register read and write work properly but i have problem to read the data from ads1256 its show garbage value.

i send my code here.

#include <SPI.h>
#define DRDY_PIN 2
#define CS_PIN 7
#define NOP 0xFF
#define MISO_PIN 12
#define MOSI_PIN 11
#define SCK_PIN 13
#define WREG 0x50
#define RREG 0x10
#define RDATA 0x01 //Read data once
#define RDATAC 0x03 //Read data continously
#define SDATAC 0x0F //Stop reading data continously
#define WAKEUP 0x00 //Exit Sleep Mode
#define SYNC 0xFC
#define NOP 0xFF
#define ORDER_MSB // Most significant Bit first (default)
#define SPI_SPEED 4800000
#define PGA 1 // Programmable Gain = 1
#define VREF 2.5 // Internal reference of 2.048V
#define VFSR VREF*2/PGA
#define FSR (((long int)1<<23)-1)


//const int dataReadyPin = 6;
volatile byte MSB;
volatile byte data;
volatile byte LSB;
//volatile char SPI_RX_Buff[3];
//volatile byte *SPI_RX_Buff_Ptr;
uint8_t CONFIG_REG0_ADDRESS;
uint8_t CONFIG_REG1_ADDRESS;
uint8_t CONFIG_REG2_ADDRESS;
uint8_t CONFIG_REG3_ADDRESS;
uint8_t CONFIG_REG4_ADDRESS;
uint8_t CONFIG_REG5_ADDRESS;
uint8_t CONFIG_REG6_ADDRESS;
uint8_t CONFIG_REG7_ADDRESS;
uint8_t CONFIG_REG8_ADDRESS;
uint8_t CONFIG_REG9_ADDRESS;
uint8_t CONFIG_REG10_ADDRESS;
uint8_t Config_Reg0 ;
uint8_t Config_Reg1 ;
uint8_t Config_Reg2;
uint8_t Config_Reg3 ;
uint8_t Config_Reg4 ;
uint8_t Config_Reg5 ;
uint8_t Config_Reg6;
uint8_t Config_Reg7 ;
uint8_t Config_Reg8 ;
uint8_t Config_Reg9;
uint8_t Config_Reg10 ;




volatile int DRDY_state;

void setup()
{
delayMicroseconds(500);
delayMicroseconds(500);
pinMode(MOSI_PIN, OUTPUT);
pinMode(MISO_PIN, INPUT);
pinMode(CS_PIN, OUTPUT);
pinMode(DRDY_PIN, INPUT);
pinMode(SCK_PIN, INPUT);
digitalWrite(CS_PIN, HIGH);
digitalWrite(SCK_PIN, LOW);
volatile int DRDY_state = HIGH;
SPI.begin();
Serial.begin(9600);
void writeRegister(uint8_t address, uint8_t value);
uint8_t readRegister(uint8_t address);
SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE1));
void DRDY_Interuppt();
attachInterrupt(digitalPinToInterrupt(DRDY_PIN), DRDY_Interuppt,FALLING);
CONFIG_REG0_ADDRESS=0x00;
CONFIG_REG1_ADDRESS=0x01;
CONFIG_REG2_ADDRESS=0x02;
CONFIG_REG3_ADDRESS=0x03;
CONFIG_REG4_ADDRESS=0x04;
CONFIG_REG5_ADDRESS=0x05;
CONFIG_REG6_ADDRESS=0x06;
CONFIG_REG7_ADDRESS=0x07;
CONFIG_REG8_ADDRESS=0x08;
CONFIG_REG9_ADDRESS=0x09;
CONFIG_REG10_ADDRESS=0x0A;
delay(100);
writeRegister(0x00, 0x01);
delayMicroseconds(50);
writeRegister(0x01, 0x0F);
delayMicroseconds(50);
writeRegister(0x02, 0x20);
delayMicroseconds(50);
writeRegister(0x03, 0xA2);
delayMicroseconds(50);
writeRegister(0x04, 0xE0);
delayMicroseconds(50);
writeRegister(0x05, 0x00);
delayMicroseconds(50);
writeRegister(0x06, 0x00);
delayMicroseconds(50);
writeRegister(0x07, 0x00);
delayMicroseconds(50);
writeRegister(0x08, 0x00);
delayMicroseconds(50);
writeRegister(0x09, 0x00);
delayMicroseconds(50);
writeRegister(0x0A, 0x00);
delayMicroseconds(50);
// digitalWrite(CS_PIN,HIGH); //release chip, signal end transfer

Config_Reg0 = readRegister(CONFIG_REG0_ADDRESS);
delayMicroseconds(50);
Config_Reg1 = readRegister(CONFIG_REG1_ADDRESS);
delayMicroseconds(50);
Config_Reg2 = readRegister(CONFIG_REG2_ADDRESS);
delayMicroseconds(50);
Config_Reg3 = readRegister(CONFIG_REG3_ADDRESS);
delayMicroseconds(50);
Config_Reg4 = readRegister(CONFIG_REG4_ADDRESS);
delayMicroseconds(50);
Config_Reg5 = readRegister(CONFIG_REG5_ADDRESS);
delayMicroseconds(50);
Config_Reg6 = readRegister(CONFIG_REG6_ADDRESS);
delayMicroseconds(50);
Config_Reg7 = readRegister(CONFIG_REG7_ADDRESS);
delayMicroseconds(50);
Config_Reg8 = readRegister(CONFIG_REG8_ADDRESS);
delayMicroseconds(50);
Config_Reg9 = readRegister(CONFIG_REG9_ADDRESS);
delayMicroseconds(50);
Config_Reg10 = readRegister(CONFIG_REG10_ADDRESS);
delayMicroseconds(50);
delay(100);


Serial.println("Config_Reg : ");
Serial.println(Config_Reg0,HEX);
Serial.println(Config_Reg1,HEX);
Serial.println(Config_Reg2,HEX);
Serial.println(Config_Reg3,HEX);
Serial.println(Config_Reg4,HEX);
Serial.println(Config_Reg5,HEX);
Serial.println(Config_Reg6,HEX);
Serial.println(Config_Reg7,HEX);
Serial.println(Config_Reg8,HEX);
Serial.println(Config_Reg9,HEX);
Serial.println(Config_Reg10,HEX);
Serial.println(" ");
delay(200);
digitalWrite(CS_PIN, HIGH);

}


void loop()
{

delayMicroseconds(50);
delayMicroseconds(50);
long int bit32;
long int bit24;
byte *config_reg;
long int regData;


if((digitalRead(DRDY_PIN)) == LOW) // Wait for DRDY to transition low

{
long int regData;
digitalWrite(CS_PIN, LOW); //Pull SS Low to Enable Communications with ADS1247
delayMicroseconds(10);
// RD: Wait 25ns for ADC12xx to get ready
// SPI.transfer(0x51);
//SPI.transfer(0x00);
// SPI.transfer(0x0F);
// writeRegister(0x01,0x43);
//Issue RDATA
SPI.transfer(SDATAC);
SPI.transfer(SYNC);
SPI.transfer( WAKEUP);
SPI.transfer( RDATAC);
delayMicroseconds(1);
bit24 |= SPI.transfer(NOP);
delayMicroseconds(1);
bit24 <<= 8;
bit24 |= SPI.transfer(NOP);
delayMicroseconds(1);
bit24 <<= 8;
bit24 |= SPI.transfer(NOP);
delayMicroseconds(1);
//Serial.println(regData,HEX);
bit24= ( bit24 << 8 );
bit32 = ( bit24 >> 8 );
// Converting 24 bit two's complement to 32 bit two's complement
delayMicroseconds(10);
//Serial.println(bit24,HEX);

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


}
}



void writeRegister(uint8_t address, uint8_t value)
{
delayMicroseconds(10);
// waitforDRDY();
//SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE1)); // initialize SPI with SPI_SPEED, MSB first, SPI Mode1
digitalWrite(CS_PIN, LOW);
delayMicroseconds(10);
SPI.transfer(WREG | address); // send 1st command byte, address of the register
SPI.transfer(0x00); // send 2nd command byte, write only one register
SPI.transfer(value); // write data (1 Byte) for the register
delayMicroseconds(10);
digitalWrite(CS_PIN, HIGH);
}




uint8_t readRegister(uint8_t address)
{
uint8_t data;
// waitforDRDY();
// SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE1)); // initialize SPI with 4Mhz clock, MSB first, SPI Mode0
digitalWrite(CS_PIN, LOW);
delayMicroseconds(10);
SPI.transfer(RREG | address); // send 1st command byte, address of the register
SPI.transfer(0x00); // send 2nd command byte, read only one register
delayMicroseconds(10);
data = SPI.transfer(NOP); // read data of the register
delayMicroseconds(10);
digitalWrite(CS_PIN, HIGH);
//digitalWrite(_START, LOW);
// SPI.endTransaction();
return data;

}



void waitforDRDY()
{
while (DRDY_state)
{
continue;
}
noInterrupts();
DRDY_state = HIGH;
interrupts();
}

//Interrupt function
void DRDY_Interuppt()
{
DRDY_state = !DRDY_state;
// state = !state;
}



output on serial is








so garbage value is come......

so i not able to understand where i did mistake......

knut_ny

Read PM. - continue here with code and results
Ny

raltom

Hi,
The library ADS12xx.h doesn't work for me; my board haven't the pin START;

knut_ny

#14
May 20, 2016, 10:03 am Last Edit: May 20, 2016, 10:14 am by knut_ny
I sent this to "nchazarra".
Compare with datasheet and other libs.
The speed_setting 14MHz may be incorrect for the UNO.
Code: [Select]
/* ADS1256, datasheet: http://www.ti.com/lit/ds/sbas288j/sbas288j.pdf
compare: https://github.com/Flydroid/ADS12xx-Library/blob/master/ads12xx.cpp
    connections to Atmega328 (UNO)

    CLK  - pin 13
    DIN  - pin 11 (MOSI)
    DOUT - pin 12 (MISO)
    CS   - pin 10
    DRDY - pin 9
    RESET- pin 8 (or tie HIGH?)
    DVDD - 3V3

    Analog ch0 (input 0,1)
    Analog ch1 (input 2,3)
    Analog ch2 (input 4,5)
    (Analog ch3 (input 6,7))
*/

#define cs 10 // chip select
#define rdy 9 // data ready, input
#define rst 8 // may omit

// ** asd1256 Register map and data to write **
#define status_reg 0   // address (datasheet p. 30)
#define status_data 0x01 // default contents after reset (no need to write this)

#define mux_reg 1
//  mux_data to be changed while running, to select input ports

#define adcon_reg 2
#define adcon_data 0x24 // 0 01 00 100 => clk_out(default), sensor detect OFF, gain 16 (p.31)

#define drate_reg 3
#define drate_data 0x82 // => 100 SPS (samples/secons)

#include <SPI.h>

byte i; // general use

void setup()
{
  SPI.begin(); //start the spi-bus
  pinMode(cs, OUTPUT);
  digitalWrite(cs, LOW); // tied low is also OK.
  pinMode(rdy, INPUT);
  pinMode(rst, OUTPUT);
  Serial.begin(115200);
  digitalWrite(rst, LOW);
  delay(1); // LOW at least 4 clock cycles of onboard clock. 100 microsecons is enough
  digitalWrite(rst, HIGH); // now reset to deafult values
  delay(1); // unsure if needed
  // now set working parameters
  writereg(status_reg, status_data); // parameters defined on top
  writereg(adcon_reg, adcon_data);
  writereg(drate_reg, drate_data);
}

void writereg(byte reg_num, byte data) // write to a single register
{
  // digitalWrite(cs, LOW);
  while (rdy) {}  // wait for ready_line to go low
  SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE1)); // start SPI
  delayMicroseconds(10);
  SPI.transfer(0x50 | reg_num); // dataseheet p.34
  SPI.transfer(0x00);   // 2nd command byte
  SPI.transfer(data);   // write tge databyte to the register
  delayMicroseconds(10);
  SPI.endTransaction();
  // digitalWrite(cs, HIGH);
}

byte readreg(byte reg_num)  // read from a single register
{
  // digitalWrite(cs, LOW);  // cs is tied low for now? Theese two lines may be added if other components uses SPI-bus
  while (rdy) {}  // wait for ready_line to go low
  SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE1)); // start SPI
  byte bufr;
  while (rdy) {}  // wait for ready_line to go low
  delayMicroseconds(10);
  SPI.transfer(0x10 | reg_num); // send 1st command byte, address of the register
  SPI.transfer(0);  // one byte only
  delayMicroseconds(10);
  bufr = SPI.transfer(0xff); // read data from register (dummy parameter)
  delayMicroseconds(10);
  SPI.endTransaction();
  // digitalWrite(cs, HIGH);
  return bufr;
}

void loop()
{
  long adc_val; // store reading
  //Read 4 channels from ads1256
  for (i = 0; i < 5; i += 2)
  {
    // digitalWrite(cs, LOW);
    adc_val = 0;
    while (rdy) {} ;
    // send command - select ADC-channel 0000 0001 / 0010 0011 / 0100 0101
    SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE1)); // start SPI
    delayMicroseconds(10);
    writereg(mux_reg, i << 4 | i + 1 ); // positive to analog 0,2,4,6, Neg to 1,3,5,7
    while (rdy) {} ;
    SPI.transfer(1); // command for: READ DATA  (p.34)
    delayMicroseconds(10);// read three bytes (adc-value)
    adc_val = SPI.transfer(0)<<8;
    //delayMicroseconds(10); // needed ?
    adc_val |= SPI.transfer(0);
    //delayMicroseconds(10); // ??
    adc_val <<= 8;
    adc_val |= SPI.transfer(0);
    delayMicroseconds(10);
    // digitalWrite(_CS, HIGH);
    SPI.endTransaction();
    Serial.print(adc_val);
    Serial.print(" / ");
    // digitalWrite(cs, HIGH);
  }
  Serial.println();
}

Ny

Go Up