This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADS1298 Setup for One Channel Input

Other Parts Discussed in Thread: ADS1298

Hello all,

I am using an Arduino Uno to communicate through SPI with the ADS1298.  I am able to write to registers and change the pulse timing of DRDY, but now I want to input a signal through one of the channels.  If I want to use an external function generator to connect to channel 1, what must I change in the code for this to work?  And are there any other connections that need to be made?

I was trying to follow the datasheet and tried multiple configurations of the code but no luck.  Output of DOUT is stuck at 11000000000000000000000 (only 23 bits).  I am assuming I must change the Channel 1 Setting but am unsure of what value, and also unsure what to leave channels 2-8 to be set as.  Also confused on Config 2 setting for this setup.

Any suggestions?

#include <SPI.h>
#include <SD.h>

#define MISOPIN 12
const int CS = 10;
const int START = 4;
const int DRDY = 6; 
const int RESET = 2;
const int CLKSEL = 5;
const int PWDN = 3;

void setup()
{
  pinMode(RESET, OUTPUT);
  pinMode(CS, OUTPUT);
  pinMode(START, OUTPUT);
  pinMode(DRDY, INPUT); 
  //init SPI bus, SCK, MOSI & SS to outputs. pull SCK and MOSI low, SS high
  SPI.begin();    
  Serial.begin(9600);
  //shifts data with MSB first
  SPI.setBitOrder(MSBFIRST);  
  delay(500);
  delay(100);  
  digitalWrite(CLKSEL,HIGH);
  delay(1000);
  //Power on reset
  digitalWrite(PWDN,HIGH);
  digitalWrite(RESET,HIGH);
  delay(1000);
  digitalWrite(RESET,LOW);
  delay(1000);
  digitalWrite(RESET,HIGH);
  delay(1000);
  //OPCODE: stop read data continuously 
  adc_send_command(0x11); 
  //Register write values
  adsSetup();
  digitalWrite(START, HIGH);
  delay(100);
  //RDATAC opcode
  adc_send_command(0x10);
  drdy_delay();
}
//Defining Struct function
struct{
 operator uint32_t() const {
   return (uint32_t( SPI.transfer(0x00) ) << 16) + (SPI.transfer(0x00) << 8) + SPI.transfer(0x00);
 }
} ADC_24Bit;

byte byte1; byte byte2; byte byte3;

void adsSetup()
{
  adc_wreg(0x03, 0xC0); //Write 0xC0 to CONFIG3 (0x03) as required in the flowchart
  adc_wreg(0x01, 0x86); //Write 0x86 to CONFIG1 (0x01) as required in the flowchart
  adc_wreg(0x02, 0x20); //Write 0x00 to CONFIG2 (0x02) as required in the flowchart
  adc_wreg(0x05, 0x00); //CHnSET (0x05 - 0x0C must be shorted with 0x01)
  adc_wreg(0x06, 0x01);
  adc_wreg(0x07, 0x01);
  adc_wreg(0x08, 0x01);
  adc_wreg(0x09, 0x01);
  adc_wreg(0x0A, 0x01);
  adc_wreg(0x0B, 0x01);
  adc_wreg(0x0C, 0x01);
}


  
void adc_send_command(int cmd)
{
  digitalWrite(RESET, HIGH);
  digitalWrite(CS, LOW);
  SPI.transfer(cmd);
  delayMicroseconds(3);
  digitalWrite(CS, HIGH);      
}



void adc_wreg(int reg, int val)
{ 
  digitalWrite(RESET, HIGH);
  digitalWrite(CS, LOW);
  SPI.transfer(0x40 | reg);
  SPI.transfer(0x0A);	
  SPI.transfer(val);
  delayMicroseconds(1);
  digitalWrite(CS, HIGH);
 }
 

void read_adc()
{
digitalWrite(CS, LOW);
Serial.println( ADC_24Bit, BIN );
} 

void drdy_delay()
{
  if (DRDY == 0)
  {
    delayMicroseconds(3);
  }
}

void loop ()
{
  if(digitalRead(DRDY) == 0 )
  {
    read_adc();
  }
  delay(10);
}

 

  • Hey Derek,

    I'd like to begin by pointing out that the data that you are getting is consistent with what you might expect given how the digital output is formatted on this device. If you'd look at page 45 on the datasheet, you'll notice that every data stream begins with a 24-bit status word. Only after that will the channel data begin. That means that if you are just trying to collect 1 channel worth of data, you'd have to send a total of 48 SCLK periods; the first half of which will be the status word.

    If you're just trying to acquire data from channel 1, I'd recommend powering down the other channels. For channel 1, I'd recommend using the PGA gain of 1 to get started. These are the settings in both channel 1 and the other channels to do what I've just described:

    CH1SET: 0x10 // Normal acquisition with a PGA gain of 1
    CHnSET (n != 1): 0x81 // Channel powered down and inputs internally shorted to minimize power consumption

    For your CONFIG2 register, the register defaults should work fine for what you're trying to do so I wouldn't worry about playing with them for now.

    Regards,
    Brian Pisani
  • Hey Brian,

    Thanks for the reply. Yes I assumed we were only getting the status bits and not any of the channel data. When you say send 48 SCLK periods, how is that done? Do I just introduce a delay after using the spi.transfer command or is there a specific way to generate the clock periods.

    Also, just to be sure, my connections should be fine right. I have everything connected according to datasheet for startup, with all the channels grounded except for channel 1 which I am inputting a function generator.

    Thanks again
  • Hi Derek,

    How to send SCLKs to your ADS1298 depends on your microcontroller so I may not be very much help here. I know from past experience, though, that some microcontrollers have a SPI FIFO that you can fill up with data and it will be shifted out until there is no data left. Another approach might be to send one byte of dummy data at a time while holding CS low the entire time.

    We recommend pulling unused analog inputs to AVDD, but I doubt holding them to ground will affect your ability to collect data.

    Regards,
    Brian