marcoconti
New member
I modified an example of code to determine the approximate speed of Teensy 4's analogRead() at 600Mhz; then, I tested different clock speeds ranging from from 24Mhz to 816Mhz to see if changing frequency led to slower or faster read speeds.
I noted that clock speed changes -apparently- did not affect the speed of the analogRead(); analogRead() took approximately 5 microseconds inside a for cycle and it did not move from there.
Is the analogRead() speed always a constant unrelated to the clock speed?
The code below explained: It take a start time with micros(). Executes 100 times analogRead() by a For{}. Takes the end time of the For{} and determines the average time needed by one analogRead() operation. 5 microsends.
Code:
I noted that clock speed changes -apparently- did not affect the speed of the analogRead(); analogRead() took approximately 5 microseconds inside a for cycle and it did not move from there.
Is the analogRead() speed always a constant unrelated to the clock speed?
The code below explained: It take a start time with micros(). Executes 100 times analogRead() by a For{}. Takes the end time of the For{} and determines the average time needed by one analogRead() operation. 5 microsends.
Code:
Code:
#define VREF (3.292) // ADC reference voltage (= power supply)
#define VINPUT (1.328) // ADC input voltage from NiCd AA battery
#define ADCMAX (4095) // maximum possible reading from ADC
#define EXPECTED (ADCMAX*(VINPUT/VREF)) // expected ADC reading
#define SAMPLES (1) // how many samples to combine for pp, std.dev statistics
const int analogInPin = A0; // Analog input is AIN0 (Teensy3 pin 14, next to LED)
const int LED1 = 13; // output LED connected on Arduino digital pin 13
int sensorValue = 0; // value read from the ADC input
unsigned long StartTime=0;
unsigned long TotTime=0;
unsigned long ReadTimeUnit=0;
int x=0;
void setup() { // ==============================================================
pinMode(LED1,OUTPUT); // enable digital output for turning on LED indicator
// analogReference(EXTERNAL); // set analog reference to internal ref
analogReadRes(12); // set ADC resolution to this many bits
analogReadAveraging(SAMPLES); // average this many readings
Serial.begin(115200); // baud rate is ignored with Teensy USB ACM i/o
digitalWrite(LED1,HIGH); delay(1000); // LED on for 1 second
digitalWrite(LED1,LOW); delay(3000); // wait in case serial monitor still opening
Serial.println("# Teensy ADC test start: ");
} // ==== end setup() ===========
void loop() { // ================================================================
StartTime = micros(); // record start time in microseconds
for (int i=0;i<100;i++) {
x = analogRead(analogInPin);
}
TotTime = micros()-StartTime; // record duration in microseconds
ReadTimeUnit=TotTime/100;
Serial.print("Microseconds/ADC-Read: ");
Serial.print(ReadTimeUnit,DEC);
Serial.print(" ADC VALUE: ");
Serial.print(x, DEC);
Serial.println();
delay(1000);
}
Last edited by a moderator: