PlanetaryAssaultSystems
New member
Greetings
I have recently acquired a teensy 3.5 and wanted to experiment with the ADC functionality of it. I looked up general usage and snippets of code to look into this. I found a project written by someone (can be found at https://forum.pjrc.com/threads/55492-Teensy-3-6-ADC-Continuous-read-giving-unexpected-results ) which sampled a 5kHz sinusoid wave and displayed it on the serial plotter. I have pasted the code below.
//////////////////////////////////////////////////////////
#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, 5);
}
Serial.println();
}
void loop() {}
///////////////////////End of code/////////////////////
The person posted because they had observed an undersampled output, and was helped according, as one may find in the link. However, I have tried compiling the code on my IDE, and the IDE gives me errors of non-detection of the "setAveraging" til the "startContinuous" functions, saying it cannot be found in the ADC.h header. However, Ive even verified that I have the example-projects for the Teensy on my IDE, and all those projects use the functions (such as the setAveraging function) and compile just fine, using the ADC.h header only. Can someone please assist me in finding the potential cause for the header file not working in a certain project, but functional in another??
I apologize for the long post, I have tried to be specific as possible, as I am aware this is an odd problem. Thank you, in advance.
I have recently acquired a teensy 3.5 and wanted to experiment with the ADC functionality of it. I looked up general usage and snippets of code to look into this. I found a project written by someone (can be found at https://forum.pjrc.com/threads/55492-Teensy-3-6-ADC-Continuous-read-giving-unexpected-results ) which sampled a 5kHz sinusoid wave and displayed it on the serial plotter. I have pasted the code below.
//////////////////////////////////////////////////////////
#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, 5);
}
Serial.println();
}
void loop() {}
///////////////////////End of code/////////////////////
The person posted because they had observed an undersampled output, and was helped according, as one may find in the link. However, I have tried compiling the code on my IDE, and the IDE gives me errors of non-detection of the "setAveraging" til the "startContinuous" functions, saying it cannot be found in the ADC.h header. However, Ive even verified that I have the example-projects for the Teensy on my IDE, and all those projects use the functions (such as the setAveraging function) and compile just fine, using the ADC.h header only. Can someone please assist me in finding the potential cause for the header file not working in a certain project, but functional in another??
I apologize for the long post, I have tried to be specific as possible, as I am aware this is an odd problem. Thank you, in advance.