Read ADC in interrupt?

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Read ADC in interrupt?

Postby fly135 » Mon Dec 31, 2018 8:35 pm

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

fivdiAtESP32
Posts: 47
Joined: Thu Dec 20, 2018 9:47 am

Re: Read ADC in interrupt?

Postby fivdiAtESP32 » Tue Jan 01, 2019 6:01 pm

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.

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Read ADC in interrupt?

Postby fly135 » Wed Jan 02, 2019 6:27 pm

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.

Who is online

Users browsing this forum: No registered users and 139 guests