Hello E2E Experts,
Good day.
I have an ADS1256 board which is been interfaced with an ESP32 microcontroller board. I'm acquiring a single channel sine signal of 1V with 500mv DC offset in single-ended mode.
I have set samples per second to be 30k in the program. I'm using Arduino IDE for programming the controller and for reading data.
As I understand from the datasheet if we read from a single channel continuously, then you can get 30000 samples per second out of it, and also that if we read all the channels by switching the multiplexer we will only get 4374Hz. Please correct me if I'm wrong.
I'm trying to verify whether I'm getting 30ksps output. How can I do it? Any help is appreciated...
I'm attaching my Arduino code:
#include <SPI.h>#include <arduinoFFT.h>#define cs 5 // chip select#define rdy 22 // data ready, input#define rst 21 // may omit#define SPISPEED 2500000 // Teensy 3.2 @120 mhz#define SAMPLES 1024float value1;float value2;float value3;int i;float x;double VREF = 2.50;#define DEBUG 1double k[SAMPLES];void setup(){ Serial.begin(115200); pinMode(cs, OUTPUT); digitalWrite(cs, LOW); // tied low is also OK. pinMode(rdy, INPUT); pinMode(rst, OUTPUT); digitalWrite(rst, LOW); delay(1); // LOW at least 4 clock cycles of onboard clock. 100 microseconds is enough digitalWrite(rst, HIGH); // now reset to default values delay(100); SPI.begin(); //start the spi-bus delay(100); while (digitalRead(rdy)) {} // wait for ready_line to go low SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_MODE1)); // start SPI digitalWrite(cs, LOW); delayMicroseconds(100); SPI.transfer(0xFE); delay(5); byte status_reg = 0x00 ; // address (datasheet p. 30) byte status_data = 0x01; // 01h = 0000 0 0 0 1 => status: Most Significant Bit First, Auto-Calibration Disabled, Analog Input Buffer Disabled //byte status_data = 0x07; // 01h = 0000 0 1 1 1 => status: Most Significant Bit First, Auto-Calibration Enabled, Analog Input Buffer Enabled SPI.transfer(0x50 | status_reg); SPI.transfer(0x00); // 2nd command byte, write one register only SPI.transfer(status_data); // write the databyte to the register delayMicroseconds(100); byte adcon_reg = 0x00; //A/D Control Register (Address 02h) //byte adcon_data = 0x20; // 0 01 00 000 => Clock Out Frequency = fCLKIN, Sensor Detect OFF, gain 1 byte adcon_data = 0x00; // 0 00 00 000 => Clock Out = Off, Sensor Detect OFF, gain 1 //byte adcon_data = 0x01; // 0 00 00 001 => Clock Out = Off, Sensor Detect OFF, gain 2 SPI.transfer(0x50 | adcon_reg); // 52h = 0101 0010 SPI.transfer(0x00); // 2nd command byte, write one register only SPI.transfer(adcon_data); // write the databyte to the register delayMicroseconds(100); byte drate_reg = 0x03; //DRATE: A/D Data Rate (Address 03h) byte drate_data = 0xF0; // F0h = 11110000 = 30,000SPS SPI.transfer(0x50 | drate_reg); SPI.transfer(0x00); // 2nd command byte, write one register only SPI.transfer(drate_data); // write the databyte to the register delayMicroseconds(100); SPI.transfer(0xF0); delay(100); digitalWrite(cs, HIGH); SPI.endTransaction();}void loop(){unsigned long msec0 = millis();saveinarray();unsigned long msec1 = millis();//Serial.print ("capture interval ");//Serial.println (msec1 - msec0);//Serial.println("Iteration completed");delay(10);}void test(){ unsigned long adc_val[1] = {0}; // store readings in array byte mux[1] = {0x08}; int i = 0; SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_MODE1)); // start SPI digitalWrite(cs, LOW); delayMicroseconds(2); for (i=0; i <1; i++){ // read all 8 Single Ended Channels AINx-AINCOM byte channel = mux[i]; // analog in channels # while (digitalRead(rdy)) {} ; SPI.transfer(0x50 | 0x01); // 1st Command Byte: 0101 0001 0001 = MUX register address 01h SPI.transfer(0x00); // 2nd Command Byte: 0000 0000 1-1=0 write one byte only SPI.transfer(channel); // Data Byte(s): xxxx 1000 write the databyte to the register(s) delayMicroseconds(2); //SYNC command 1111 1100 // ********** Step 2 ********** SPI.transfer(0xFC); delayMicroseconds(2); SPI.transfer(0x00); delayMicroseconds(250); // Allow settling time SPI.transfer(0x01); // Read Data 0000 0001 (01h) // ********** Step 3 ********** delayMicroseconds(5); adc_val[i] = SPI.transfer(0); adc_val[i] <<= 8; //shift to left adc_val[i] |= SPI.transfer(0); adc_val[i] <<= 8; adc_val[i] |= SPI.transfer(0); delayMicroseconds(2); } // Repeat for each channel ********** Step 4 ********** digitalWrite(cs, HIGH); SPI.endTransaction(); //The ADS1255/6 output 24 bits of data in Binary Two's //Complement format. The LSB has a weight of //2VREF/(PGA(223 − 1)). A positive full-scale input produces //an output code of 7FFFFFh and the negative full-scale //input produces an output code of 800000h. for (i=0; i <1; i++) { // Single ended Measurements if(adc_val[i] > 0x7fffff) { adc_val[i] = adc_val[i]-16777216; //do 2's complement } float voltage = ((2*VREF) / 8388608)*adc_val[0]; float Read_Data = adc_val[i] *0.0000002980232;value1 = adc_val[0] *0.0000002980232;value2 = adc_val[1] *0.0000002980232;value3 = adc_val[2] *0.0000002980232;x = (voltage - 0.5);// Serial.print(Read_Data); // Raw ADC integer value +/- 23 bits// Serial.print(" ");//Serial.println(x);}}void saveinarray(){ for( i=0; i<SAMPLES1; i++) { test(); k[i]=x; Serial.print("k[i] is :"); Serial.print("\t"); Serial.print(i); Serial.print("\t"); Serial.println(k[i]); }}