Page 1 of 1

ESP32 Can't sample ADC inside Interrupt Macro

Posted: Fri Dec 08, 2023 2:25 pm
by pmgreene01
I am trying to port a program that I have working on an Arduino nano over to an ESP32.

One of the things I do in my program is sample 4 ADC channels in an interrupt running at 1kHz. Ideally, I would like to run my interrupt at 2kHz, but the nano can't do it, so I wanted to see if the ESP32 could do it faster.

I wrote a simple test program on the ESP32 and got the interrupt running at 500 microseconds. All I do in the ISR is toggle an output so that I can measure the timing on a scope.

I can read one ADC channel outside the interrupt and it takes 140 microseconds to read the ADC. As soon as I put the read ADC command inside the ISR macro, the interrupt stops running and my program keeps restarting.

I attached my program. Please let me know if you have any ideas.

Re: ESP32 Can't sample ADC inside Interrupt Macro

Posted: Sat Dec 09, 2023 8:43 pm
by pmgreene01
I have continued investigation and found these additional symptoms.

- I can only create an interrupt based on Timer0, timers 1,2 and 3 fail.
- I can do integer math in the interrupt macro, if I try anything with a floating point value, the interrupt won't run.

If anyone has any ideas, I would appreciate it. Maybe ESP32 is not the right choice for me. Just need something that runs 30% or more faster than the Arduino nano that I am currently using.

Re: ESP32 Can't sample ADC inside Interrupt Macro

Posted: Sat Dec 09, 2023 11:45 pm
by mnfisher
The esp32 has an adc_continuous mode which might do what you need.
It would take a little coding to use the api - but have a look at
https://www.google.com/url?sa=t&source= ... F6MU6fE4-7

Martin

Re: ESP32 Can't sample ADC inside Interrupt Macro

Posted: Thu Dec 14, 2023 8:36 am
by stefan.erni
Hi pmgreene01, Hi Martin


I know the IRQ of the ESP32 is not practical because almost all commands in the macro crash.

One possibility, i use at the moment is the following:

I set only one variable(t1_int) to 1 with the interrupt-macro and in the main program I check if it is 1.
If yes i sample the channel and set the variable back to 0.

So I have a more or less a constant sample rate.

For another project I used a PIC32MZ from Microchip. There the interrupt did not cause any problems with flowcode.

regards

Stefan

Info about main
Snag_2515e5.png
Snag_2515e5.png (23.14 KiB) Viewed 7976 times
Interrupt_test_ESP32-02.fcfx
(25.24 KiB) Downloaded 379 times

Re: ESP32 Can't sample ADC inside Interrupt Macro

Posted: Thu Dec 14, 2023 6:36 pm
by pmgreene01
Thank you for the response. I will play with that approach.