This repository has been archived on 2025-01-02. You can view files and clone it, but cannot push or open issues or pull requests.
ads1256/src/adc1256.cpp

51 lines
1.1 KiB
C++

#include <HardwareSerial.h>
#include <ADS1256.h>
float clockMHZ = 7.68; // crystal frequency used on ADS1256
float vRef = 2.5; // voltage reference
// Construct and init ADS1256 object
ADS1256 adc(clockMHZ, vRef, false);
void adc1256_init(void)
{
SPI.begin();
sleep(0.5);
SPI.beginTransaction(
SPISettings(clockMHZ * 1000000 / 4, MSBFIRST, SPI_MODE1));
sleep(0.5);
adc.begin(ADS1256_DRATE_30000SPS, ADS1256_GAIN_1, false);
Serial.println("ADC Started");
// Set MUX Register to AINO-AIN1 so it start doing the ADC conversion
adc.setChannel(3);
}
void adc1256_reset(void)
{
adc.reset();
}
void adc1256_set_channel(uint8_t ch)
{
adc.waitDRDY();
adc.setChannel(ch);
}
float adc1256_read(void)
{
return adc.readCurrentChannel();
}
void adc1256_loop(void)
{
float rst;
adc.waitDRDY(); // wait for DRDY to go low before changing multiplexer register
adc.setChannel(3); // Set the MUX for differential between ch2 and 3
rst = adc.readCurrentChannel(); // DOUT arriving here are from MUX AIN0 and AIN1
Serial.print(rst, 6);
Serial.print("\n");
delay(1000);
}