Page 1 of 1

Read ADC in interrupt?

Posted: Mon Dec 31, 2018 8:35 pm
by fly135
Can you read the ADC in an interrupt routine? I'd like to read it then send the value in a queue to an application task.

John A

Re: Read ADC in interrupt?

Posted: Tue Jan 01, 2019 6:01 pm
by fivdiAtESP32
Do you mean if it's a good idea to invoke adc1_get_raw or adc2_get_raw in an interrupt routine?

If so, I don't think it's a good idea as invoking these functions involves spinlocks which isn't a good idea in an interrupt routine. See here.

In order to get good ADC readings multisampling is likely to be needed. Some of the esp idf examples sample 64 times to get a good readings. Here is such an example . Sampling 64 times will take over 2 milliseconds which is quite a long time.

Re: Read ADC in interrupt?

Posted: Wed Jan 02, 2019 6:27 pm
by fly135
Yeah oversampling will just make my problem worse. My intuition is telling me that signaling the app to invoke the scheduler to get a task to do a reading is causing to much CPU usage in my app. I thought maybe if I could just do the read in an interrupt and stick the value in a queue I could avoid invoking the scheduler. We have a lot going in and now somebody wants to read the ADC at 1Khz by having an interrupt signal the task to wake up every msec.