Spresense analogRead() is very slow

Asked 2 years ago, Updated 2 years ago, 322 views

I used Arduino and Spresense to measure the voltage of the analog input pin using the analogRead function, but it took 15 ms (1.5 seconds for 100 times in the program), is it this slow?
Is there any way to do it quickly?

int sensorPin=3;// select the input pin for the potentiometer
int sensorValue=0;// variable to store the value coming from the sensor

void setup() {
}

void loop() {
  for(int loop_count=0;loop_count<100;loop_count++){
    sensorValue=analogRead(sensorPin);
  }
  printf("read=%d\n", sensorValue);
}

spresense arduino

2022-09-30 21:58

1 Answers

http://www.musashinodenpa.com/arduino/ref/index.php?f=0&pos=2113
https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/
According to , it seems to be 100 usec per session, so it's too late for Arduino.

For your information, in today's inverter-controlled microcomputer, if you choose the fastest mode at the expense of absolute accuracy, you can convert 12 bits in about 1 usec.If you want to keep doing the fastest sampling all the time, you'll have to automate the process of receiving results with DMA or DTC instead of interrupt.

Looking at the presentation code, I doubt printf() is slower.If you are outputting on a serial port, the bps setting is not good.


2022-09-30 21:58

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.