1

Below is the sketch I'm using with the TI 32-bit adc ADS1262. I've been trying to achieve maximum resolution by setting the MODE2 register gain to 101, which is 32V/V. The default PGA setting is 000 or 1V/V. The line I set the gain is: "PC_ADS1262.ads1262_Reg_Write(MODE2, 5<<4 | 2);" I think it is probably set for the 32V/V, but I was wanting to do a register read to make sure where it is actually set at. I do not know how to do the register read, any suggestions? The ADS1262 datasheet page 85 shows a RREG read register command, but I simply do not know how to use it. BTW, with the adc connected to a 10mV voltage the best results I get are 0.00997589244 volts or 0.00997589149 volts. It jumps between those two voltage readings. So the increment is 0.00000000095 volts. That's pretty good precision, but its not 32-bit. ADS1262 datasheet

 example.ino
 this example gives differential voltage across the AN0 And AN1 in volts
 Hooking-up with the Arduino
 ----------------------
|ads1262 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              |
| START           | Start Conversion     |  D5              | 
| PWDN            | Power Down/Reset     |  D4              |
| DVDD            | Digital VDD          |  +5V             |
| DGND            | Digital Gnd          |  Gnd             |
| AN0-AN9         | Analog Input         |  Analog Input    |
| AINCOM          | Analog input common  |                  |
| AVDD            | Analog VDD           |  -               |
| AGND            | Analog Gnd           |  -               |
-----------------------------------------------------------------
*/
#include <SPI.h>
#include <SoftwareSerial.h>
#include <math.h>
#include <ads1262.h>

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

ads1262 PC_ADS1262;                     // class

float volt_V=0;
float volt_mV=0;
volatile int i;
volatile char SPI_RX_Buff[10];
volatile long ads1262_rx_Data[10];
volatile static int SPI_RX_Buff_Count = 0;
volatile char *SPI_RX_Buff_Ptr;
volatile int Responsebyte = false;
volatile signed long sads1262Count = 0;
volatile signed long uads1262Count=0;
double resolution;



void setup() 
{
  // initalize the  data ready and chip select pins:
  pinMode(ADS1262_DRDY_PIN, INPUT);                  //data ready input line
  pinMode(ADS1262_CS_PIN, OUTPUT);                   //chip enable output line
  pinMode(ADS1262_START_PIN, OUTPUT);               // start 
  pinMode(ADS1262_PWDN_PIN, OUTPUT);                // Power down output   

  Serial.begin(9600);
  //initalize ADS1292 slave
  PC_ADS1262.ads1262_Init();                      // initialise ads1262
  Serial.println("ads1262 Initialised successfully....");

 }

void loop() 
{
  volatile int i,data;


 if((digitalRead(ADS1262_DRDY_PIN)) == LOW)               // monitor Data             ready(DRDY pin)
  {  
    SPI_RX_Buff_Ptr = PC_ADS1262.ads1262_Read_Data();      // read 6 bytes  conversion register
    Responsebyte = true ; 
  }

  if(Responsebyte == true)
  {
    for(i = 0; i <5; i++)
    {
      SPI_RX_Buff[SPI_RX_Buff_Count++] = *(SPI_RX_Buff_Ptr + i);              
    }
    Responsebyte = false;
  }

  if(SPI_RX_Buff_Count >= 5)
  {     


    ads1262_rx_Data[0]= (unsigned char)SPI_RX_Buff[1];  // read 4 bytes adc count
    ads1262_rx_Data[1]= (unsigned char)SPI_RX_Buff[2];
    ads1262_rx_Data[2]= (unsigned char)SPI_RX_Buff[3];
    ads1262_rx_Data[3]= (unsigned char)SPI_RX_Buff[4];


     uads1262Count = (signed long) (((unsigned long)ads1262_rx_Data[0]<<24)|   ((unsigned long)ads1262_rx_Data[1]<<16)|(ads1262_rx_Data[2]<<8)|ads1262_rx_Data[3]);//get the raw 32-bit adc count out by shifting
     sads1262Count = (signed long) (uads1262Count);      // get signed value
     PC_ADS1262.ads1262_Reg_Write(MODE2, 5<<4 | 2);  //Here is where I set the gain
     resolution = (double)((double)VREF/pow(2,31));       //resolution= Vref/(2^n-1) , Vref=2.5, n=no of bits
    // Serial.print(resolution,15);
     volt_V      = (resolution)*(float)sads1262Count;     // voltage = resolution * adc count
     volt_mV   =   volt_V*1000;                           // voltage in mV
     Serial.print("Readout voltage");
     Serial.print(" : ");
     Serial.print(volt_V,9);
     Serial.print(" V ,");

   }

  SPI_RX_Buff_Count = 0;

}

float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
  • How many digits does float/double give you? en.wikipedia.org/wiki/Single-precision_floating-point_format – Mikael Patel Dec 26 '16 at 20:57
  • Not sure if this is what you want Mikael but I did "Serial.print(resolution,35);" and got 0.00000003890134334564208984375000000 – Rico Dec 26 '16 at 23:02
  • In AVR gcc float and double are 32-bit (single precision). This gives from 6 to 9 significant decimal digits precision (as stated in the wiki). You loose 8-bits of information when converting from 32-bit integer to 32-bit floating point. – Mikael Patel Dec 26 '16 at 23:22
  • I think the answer to your original question is 10 digits. For example, 9.997589244mV. But the last two digits are not really that precise and should be rounded off, to 9.9975892, giving 8 digits. That is probably in the 24-bit accuracy area. Do you agree? – Rico Dec 27 '16 at 1:00
  • Yes, 32-8 is 24 :). – Mikael Patel Dec 27 '16 at 9:21
1

Here are the important parts of the code I use to READ or WRITE to registers in the ADS1263 chip... I hope this helps you over this hurdle...

// The ADS1263 2 byte commands.
// Note the 3 msb are the command, the remaining bits are the starting register address.
// Refer to table 37 on page 85 of the SBAS661B.PDF for details of the ADC command map.
// Read XXXn nnnn register(s) starting at address XXXr rrrr. The first byte 001r rrrr and the second byte 000n nnnn.
// Write XXXn nnnn register(s) starting at address XXXr rrrr. The first byte 010r rrrr and the seconf byte 000n nnnn.
const byte WREG = 0x40; // 0b01000000 ADS1263 Command Write 40h + reg address.
const byte RREG = 0x20; // 0b00100000 ADS1263 Command Read  20h + reg address.
const byte MASK = 0x03; // 0b00000011 mask out the msb's and limit block size from 0 to 3 bytes.

unsigned int ads1263_Read_Reg(byte thisRegister, byte bytesToRead)
{
byte inByte = 0;
unsigned int result = 0;
byte readStatus = 0;
byte readCRC = 0;

... REDACTED 
// ADS1263 expects the register address in the lower 5 bits of the byte. So no shifting of the bits is necessary:
// Now combine the address and the command into one byte bit masked to add the read register command.

byte dataToSend = thisRegister | RREG;
byte lengthToRead = byte bytesToRead & MASK; // Enforce a maximum of 3 bytes.

... REDACTED

SPI.transfer(dataToSend);
result = SPI.transfer(0x00);
lengthToRead--;
if (lengthToRad > 0)
    {
    result = result << 8;
    inByte = SPI.transfer(0x00);
    result = result | inByte;
    lengthToRead--;
    }

... REDACTED

Serial.print("Register Data: ");
Serial.println(result, BIN);

... REDACTED
}

If you used an array for a read buffer you would not have to enforce a maximum of four bytes at a time reading as unsigned int can only hold four bytes...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.