ESP32 Can't sample ADC inside Interrupt Macro

For general Flowcode discussion that does not belong in the other sections.
Post Reply
pmgreene01
Posts: 35
http://meble-kuchenne.info.pl
Joined: Sat Jul 08, 2023 7:39 pm
Has thanked: 3 times
Been thanked: 4 times

ESP32 Can't sample ADC inside Interrupt Macro

Post 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.
Attachments
Interrupt_test_ESP32-01.fcfx
(26.2 KiB) Downloaded 171 times

pmgreene01
Posts: 35
Joined: Sat Jul 08, 2023 7:39 pm
Has thanked: 3 times
Been thanked: 4 times

Re: ESP32 Can't sample ADC inside Interrupt Macro

Post 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.

mnfisher
Valued Contributor
Posts: 953
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 507 times

Re: ESP32 Can't sample ADC inside Interrupt Macro

Post 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

stefan.erni
Valued Contributor
Posts: 758
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 149 times
Been thanked: 171 times

Re: ESP32 Can't sample ADC inside Interrupt Macro

Post 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 6067 times
Interrupt_test_ESP32-02.fcfx
(25.24 KiB) Downloaded 66 times

pmgreene01
Posts: 35
Joined: Sat Jul 08, 2023 7:39 pm
Has thanked: 3 times
Been thanked: 4 times

Re: ESP32 Can't sample ADC inside Interrupt Macro

Post by pmgreene01 »

Thank you for the response. I will play with that approach.

Post Reply