Reading Multiple ADCs and Setting Multiple PWMs in Parallel

Aurora
Posts: 8
Joined: Fri Aug 11, 2023 1:27 am

Reading Multiple ADCs and Setting Multiple PWMs in Parallel

Postby Aurora » Wed Jan 03, 2024 12:49 am

Hello everyone,

I am programming an ESP32 with Arduino IDE. Due to my specific application, my program reads analog signals from 8 ADC pins sequentially, just like the following code shows:

Code: Select all

adc[0] = analogReadMilliVolts(15);
adc[1] = analogReadMilliVolts(25);
adc[2] = analogReadMilliVolts(32);
adc[3] = analogReadMilliVolts(33);
adc[4] = analogReadMilliVolts(34);
adc[5] = analogReadMilliVolts(35);
adc[6] = analogReadMilliVolts(36);
adc[7] = analogReadMilliVolts(39);
However, this introduces a delay of ~90 microseconds between each analogRead() and is unfavorable for me. I would like to ask if there is a way that I can sample all of them simultaneously, which means reading all ADCs in parallel.

Another question I have is somewhat similar to the above. Currently, my program also sets up multiple PWM channels sequentially, as shown in the following code. I am seeking a way to set up multiple channels simultaneously, therefore, multiple channels are synchronized and there is no delay due to the runtime required by sequentially executing the program.

Code: Select all

ledcChangeFrequency(13, parameter[0], timerResolution);
ledcWrite(13, parameter[1], parameter[2]);

ledcChangeFrequency(0, parameter[3], timerResolution);
ledcWrite(0, parameter[4], parameter[5]);

ledcChangeFrequency(1, parameter[6], timerResolution);
ledcWrite(1, parameter[7], parameter[8]);

ledcChangeFrequency(14, parameter[9], timerResolution);
ledcWrite(14, parameter[10], parameter[11]);
Any input or suggestion is highly appreciated. Thank you very much and happy new year!

Who is online

Users browsing this forum: Google [Bot] and 40 guests