Disable All Interrupts

fnord_disc
Posts: 2
Joined: Fri Aug 06, 2021 10:25 am

Disable All Interrupts

Postby fnord_disc » Fri Aug 06, 2021 10:46 am

Hello,

I wish to disable my custom interrupts for parts of the code. The scenario is this:

I use the ESP32 as an RC flight controller. It monitors 6 GPIO pins for PWM signals from the receiver using interrupt routines to measure the length of the pulses (1-2ms). 2 of those pins are GPIO 36 and 39. These are pulled low for 80ns when the ESP32 queries the battery voltage using the ADC. This issue is documented here

https://www.espressif.com/sites/default ... p32_en.pdf

in section 3.11 and the given workaround is "ignore input from GPIO36 and GPIO39." The 80ns are enough to consistently trigger undesirable interrupts on PWM pulses, splitting ordinary pulses into 2 short ones. It's not possible to dismiss these measurements out of hand because one of them might still be inside the valid 1-2ms range.

Using the Arduino routines noInterrupts(); and interrupts(); around the ADC measurement has no effect. Detaching the interrupts and reattaching leads to somewhat better results, but also seems to disturb the pulse measurement for unclear reasons and is also fairly slow (~50 µs).

Please do not suggest I use different GPIO pins. I use every single pin on the ESP32 for something or other and if I don't have this problem in the PWM monitoring I would have it somewhere else.

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: Disable All Interrupts

Postby ESP_igrr » Fri Aug 06, 2021 12:55 pm

Hi fnord_disc,
If you are using Arduino-esp32 core with versions 1.0.6, 2.0.0-rc1, or the latest "master" branch, there is another workaround for the GPIO glitch issue that doesn't involve disabling the interrupts.

You can call adc_power_acquire function in the "setup" of your sketch. It will force the ADC module to be on, eliminating the glitches occurring due to ADC being enabled or disabled.

Code: Select all

#include "driver/adc.h"

void setup()
{
    adc_power_acquire();
}


fnord_disc
Posts: 2
Joined: Fri Aug 06, 2021 10:25 am

Re: Disable All Interrupts

Postby fnord_disc » Fri Aug 06, 2021 1:29 pm

Thank you very much! That solution works perfectly.

Who is online

Users browsing this forum: No registered users and 69 guests