I am testing out the ADC functionality of my new Teensy 3.6 and have encountered an issue I do not understand. I setup a simple test using the signal generator on my oscilloscope to output a 5 kHz sine wave into pin 17 on the Teensy. The ground connection on the signal generator was made to the Analog Ground pin. Here is the code I used:
And here is the output I got for different ADC speeds:
I am thoroughly confused by this data. It seems clear that the program is collecting 1000 samples within 487 us for each speed. That gives a sampling speed of roughly 2 Msps! How is this possible? I feel like I am missing something simple. I hope someone can help me out.
Code:
#include <ADC.h>
#define SAMPLE_NO 1000
const int readPin = A3;
int j;
float buffer[SAMPLE_NO];
ADC *adc = new ADC();
void setup() {
//Read pin is A3 (pin 17) on Teensy 3.6
//Oscilloscope signal generator attached to A3 and Analog GND
pinMode(readPin, INPUT);
delay(6000);
Serial.begin(115200);
Serial.println("Teeny beginning data acquisition...");
//Configure ADC_0 for Continuous measurement
adc->setAveraging(1);
adc->setResolution(16);
adc->setSamplingSpeed(ADC_SAMPLING_SPEED::LOW_SPEED);
adc->setConversionSpeed(ADC_CONVERSION_SPEED::LOW_SPEED);
adc->setReference(ADC_REFERENCE::REF_1V2);
adc->startContinuous(readPin, ADC_0);
delay(1000);
//Start measurement timer
elapsedMicros dt;
j = 0;
uint16_t value;
//Fill buffer with ADC_0 output values
while (j < SAMPLE_NO) {
value = (uint16_t) adc->analogReadContinuous(ADC_0);
buffer[j] = value*1.2/adc->getMaxValue(ADC_0);
j++;
}
adc->stopContinuous();
//Convert buffer to float values and print to Serial
Serial.print("Measurement time [us]: ");
Serial.println(dt);
Serial.println("Buffer Values [V]: ");
for (int i = 0; i<SAMPLE_NO; i++) {
Serial.println(buffer[i], 5);
}
Serial.println();
}
void loop() {}
And here is the output I got for different ADC speeds:
I am thoroughly confused by this data. It seems clear that the program is collecting 1000 samples within 487 us for each speed. That gives a sampling speed of roughly 2 Msps! How is this possible? I feel like I am missing something simple. I hope someone can help me out.