Teensy 3.5 ADC functionality

Status
Not open for further replies.
Greetings

I have been tinkering with the ADC of the Teensy. I have found a project from the following forum post(https://forum.pjrc.com/threads/55492-Teensy-3-6-ADC-Continuous-read-giving-unexpected-results) where the user wanted to sample a sinusoidal input. The code can be found below.
////////////////////////////////////////////////////
#include <ADC.h>
#define SAMPLE_NO 1000
const int readPin = A22;
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);
pinMode(13,OUTPUT);
delay(6000);
Serial.begin(115200);
Serial.println("Teensy beginning data acquisition...");

//Configure ADC_0 for Continuous measurement
adc->adc1->setAveraging(1);
adc->adc1->setResolution(16);
adc->adc1->setSamplingSpeed(ADC_SAMPLING_SPEED::HIGH_SPEED);
adc->adc1->setConversionSpeed(ADC_CONVERSION_SPEED::HIGH_SPEED);
adc->adc1->setReference(ADC_REFERENCE::REF_1V2);
adc->adc1->analogRead(readPin); // performs various ADC setup stuff
adc-> adc1 -> startContinuous(readPin);
delay(1000);

//Start measurement timer
elapsedMicros dt;
j = 0;
uint16_t value;

//Fill buffer with ADC_0 output values
while (j < SAMPLE_NO) {
if (adc->adc1->isComplete()) {
value = (uint16_t) adc-> adc1 ->analogReadContinuous();
buffer[j] = value * 1.2 / adc->adc1->getMaxValue();
j++;
}
}

adc-> adc1 -> 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, 5);
}

Serial.println();


}

void loop() {
digitalWrite(13,HIGH);
delay(500);
digitalWrite(13,LOW);
delay(500);

}

///////////////////////////////////////

I have currently inputted a simple 1V dc from my power supply to test it as its simplest function and what I would expect is a straight line on the serial plotter, however, the current output can be found in the attached picture, which is just a blank plot. Please may someone help me or show me a way forward. Thank you

TeensyADC.jpg
 
Status
Not open for further replies.
Back
Top