I have used ESP32 and the ADC to test this library. I have included "SPI.h" in "ADS131M08.cpp"
and replaced "spi" to "SPI". By doing so i did not get the compilation error but for some reason the SPI clock is not being pushed (i used a scope to check).
Your advise on resolving this issue would be really helpful.
#include "ADS131M08.h"
#include "SPI.h"
ADS131M08 adc;
float curr_sig1;
unsigned int sampling_period_us;
unsigned long microseconds = 0;
const float samplingFrequency = 10000.0; //Hz, must be less than 10000 due to ADC
const int samples = 32768; //This value MUST ALWAYS be a power of 2
#define SCK 14
#define MISO 12
#define MOSI 13
#define CS 15
#define DRDY 25
#define RST 26
void setup()
{
Serial.begin(115200);
adc.begin(14, 12, 13, 15, 25,26);
delay(1000);
adc.setInputChannelSelection(0, INPUT_CHANNEL_MUX_AIN0P_AIN0N);
adc.setOsr(OSR_128); // 32KSPS only with 8MHZ clock
curr_sig1 = (float) ps_calloc(samples, sizeof(float));
sampling_period_us = round(1000000 * (1.0 / samplingFrequency));
}
void loop()
{
AdcOutput res;
microseconds = micros();
for (int i = 0; i < samples; i++)
{
res = adc.readAdcFloat();
curr_sig1[i]=res.ch[0].f;
while (micros() - microseconds <= sampling_period_us) {}
microseconds += sampling_period_us;
}
for (int i = 0; i < 512; i++){Serial.print(curr_sig1[i]);}
Serial.println();
}
I have used ESP32 and the ADC to test this library. I have included "SPI.h" in "ADS131M08.cpp"
and replaced "spi" to "SPI". By doing so i did not get the compilation error but for some reason the SPI clock is not being pushed (i used a scope to check).
Your advise on resolving this issue would be really helpful.
#include "ADS131M08.h"
#include "SPI.h"
ADS131M08 adc;
float curr_sig1;
unsigned int sampling_period_us;
unsigned long microseconds = 0;
const float samplingFrequency = 10000.0; //Hz, must be less than 10000 due to ADC
const int samples = 32768; //This value MUST ALWAYS be a power of 2
#define SCK 14
#define MISO 12
#define MOSI 13
#define CS 15
#define DRDY 25
#define RST 26
void setup()
{
Serial.begin(115200);
adc.begin(14, 12, 13, 15, 25,26);
delay(1000);
adc.setInputChannelSelection(0, INPUT_CHANNEL_MUX_AIN0P_AIN0N);
adc.setOsr(OSR_128); // 32KSPS only with 8MHZ clock
curr_sig1 = (float) ps_calloc(samples, sizeof(float));
sampling_period_us = round(1000000 * (1.0 / samplingFrequency));
}
void loop()
{
AdcOutput res;
microseconds = micros();
for (int i = 0; i < samples; i++)
{
res = adc.readAdcFloat();
curr_sig1[i]=res.ch[0].f;
while (micros() - microseconds <= sampling_period_us) {}
microseconds += sampling_period_us;
}
for (int i = 0; i < 512; i++){Serial.print(curr_sig1[i]);}
Serial.println();
}