I recently got an ADS 1015 (in order to make high frequency measurement of a voltage accros a capacitor). The datasheet specified 3.3 kSPS (Sample per seconds). However I only get around 500SPS maximum. And after looking all around, I've found several ressources which talked about a register override... However, I'm not an expert in this field and need your help!
Here is the code I use to test the sampling rate (using an Arduino nano, arduino code is a C++ variant):
#include <Wire.h>
#include <Adafruit_ADS1015.h>
#include <SPI.h>
Adafruit_ADS1015 ADS_0(0x48);
int i = 0;
long results = 0;
void setup(void)
{
Serial.begin(9600);
// CODE FOUND ON THE INTERNET BUT REJECT ERROR BC OF readRegister function not defined... However, I haven't found any library missing... Strange ---------------
const uint8_t adcAddress = 0x48;
const uint8_t configRegister = 0x01;
uint16_t configValue = readRegister( adcAddress, configRegister );
Serial.print( "read config value 0x" );
Serial.println( configValue, HEX );
configValue = ( configValue & !ADS1015_REG_CONFIG_DR_MASK) | ADS1015_REG_CONFIG_DR_3300SPS;
writeRegister( adcAddress, configRegister, configValue );
Serial.print( "sent config value 0x" );
Serial.println( configValue, HEX );
configValue = readRegister( adcAddress, configRegister );
Serial.print( "verifying by rereading config value 0x" );
Serial.println( configValue, HEX );
// -------------------------------------------------------------
ads1015.begin();
}
void loop(void)
{
int i=0;
long depart = micros();
while(i != 1000) {
i++;
results = ads1015.readADC_SingleEnded(0);
}
Serial.println(micros() - depart);
}
This code return about 2,000,000 which correspond to 2 sec or 500 Hz sampling rate...
Thanks in advance, ~TBD
According to the datasheet I think you have to first set
MODE
to0
(Continuous-conversion mode) andDR
to0b111
in the Config Register (pg 24).Then you can probably use an
ISR
onALERT/RDY pin
(after proper configuration - pg 15) and read the data each time the interrupt is triggered.Page 15: