Hello,
I am looking to use a teensy 4.1 as a datalogger and have simplified my code to a minimum working example. In the full version of the code, I would take ~1000 samples instead of 10 and write them to an SD card. For this code, the time between the samples is 7-8 microseconds and I would like to know what I can do to increase the sampling rate.
Thanks,
David
I am looking to use a teensy 4.1 as a datalogger and have simplified my code to a minimum working example. In the full version of the code, I would take ~1000 samples instead of 10 and write them to an SD card. For this code, the time between the samples is 7-8 microseconds and I would like to know what I can do to increase the sampling rate.
Code:
#include <ADC.h>
int signalPin = A1; // Set the pin for the incoming signal
ADC *adc = new ADC(); // adc object
String dataBuffer = ""; //Initialize the databuffer
void setup() {
Serial.begin(9600); //Initialize the serial monitor
pinMode(signalPin, INPUT_DISABLE);
adc->adc0->setAveraging(4); // Set the number of averages
adc->adc0->setResolution(12); // Set the resolution of the ADC
adc->adc0->setConversionSpeed(ADC_CONVERSION_SPEED::HIGH_SPEED); // Set high-speed conversion
adc->adc0->setSamplingSpeed(ADC_SAMPLING_SPEED::VERY_HIGH_SPEED); // Set high-speed sampling rate
for (int i = 0; i < 10; i++) { //Take 1 reading per iteration; each iteration takes 7-8 microseconds (sampling rate ~138 kHz)
int sensorValue = adc->adc0->analogRead(signalPin); //Record the value of the sensor pin
dataBuffer += String(micros()) + "," + String(sensorValue) + "\n"; //Write the time and the senor value to the data buffer
}
Serial.print(dataBuffer); //Print the data buffer, or write to SD card
dataBuffer = ""; //Reset the data buffer
}
void loop() {
}
Thanks,
David