According to numerous online sources, the Raspberry Pi Pico can perform 500,000 A to D reads a second, i.e., 2 microseconds per read. I am programming in C++ using the Arduino IDE and cannot get better than 7.7 microseconds. Given a clock speed of 125 MHz, this implies the loop adds an overhead of 713 clock cycles per execution which seems unlikely.
In the attached code, the additional step to store the value in the array, only adds about 0.1% to the execution time.
Example line of the output:
time for 1000 ADC reads without store to array: 7732 microseconds.
time for 1000 ADC reads with store to array: 7688 microseconds.
In MicroPython, each read takes twice as long.
How can I speed this up?
// using Arduino IDE 1.8.19 to program Raspberry Pi Pico
#define ADC 27
#define DATALENGTH 1000
void setup() {
Serial.begin(9600);
}
void loop() {
int data[DATALENGTH];
unsigned long start = micros();
unsigned long adcTime = 0;
for (int i=0;i<DATALENGTH;i++)
{
analogRead(ADC);
}
adcTime = micros() - start;
Serial.println("time for " + String(DATALENGTH) + " ADC reads without store to array: " + String(adcTime)+ " microseconds.");
start = micros();
for (int i=0;i<DATALENGTH;i++)
{
data[i] = analogRead(ADC);
}
adcTime = micros() - start;
Serial.println("time for " + String(DATALENGTH) + " ADC reads with store to array: " + String(adcTime)+ " microseconds.");
delay(5000);
}