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
Read ADC in interrupt?
-
- Posts: 47
- Joined: Thu Dec 20, 2018 9:47 am
Re: Read ADC in interrupt?
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.
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?
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 135 guests