ESP32 Interrupt test if correct

For general Flowcode discussion that does not belong in the other sections.
Post Reply
stefan.erni
Valued Contributor
Posts: 997
http://meble-kuchenne.info.pl
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 190 times
Been thanked: 217 times

ESP32 Interrupt test if correct

Post by stefan.erni »

Hi Ben

On ESP32 Wroom I have a problem with the Interrupt

I can set the interrupt to 20hz and it works very well. I can test this with the osciloscope and it works perfectly.

Only sometimes after a restart it happens that it is too fast and instead of 20Hz it has 25Hz or 50 Hz.
If I repeat the command 3 times it works much better.

The interrupt always works between 20Hz and 50Hz and only get faster, but not slower

Is there a possibility of reading a register or variable where I can test how the interrupt is set?

the interrupt is more stable if I do the command several times:
2024-08-30_13-33-18.PNG
2024-08-30_13-33-18.PNG (22.51 KiB) Viewed 7206 times
2024-08-30_11-22-46.PNG
2024-08-30_11-22-46.PNG (38.88 KiB) Viewed 7206 times

BenR
Matrix Staff
Posts: 1924
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 501 times
Been thanked: 684 times

Re: ESP32 Interrupt test if correct

Post by BenR »

Hello,

Are you enabling the interrupt right at the start of the program? I wonder if the oscialltor is potentially still a little unstable at this point. What if you add say a 100ms or 1s delay before enabling the interrupt? does this make any difference?

We pass over the interrupt to the IDF so this should be doing things properly and it should work correctly first time but only thing I can think is it could be based on transient clock speeds?

stefan.erni
Valued Contributor
Posts: 997
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 190 times
Been thanked: 217 times

Re: ESP32 Interrupt test if correct

Post by stefan.erni »

Hi Ben

The interrupt works well and is easy to set.
It also works when I use 80Mhz or 200Mhz as ESP32 clock speed. I don't have to change the code.
When I use the interrupt for the first time it is perfect!
Only when i want to stop the interrupt it does not stop and then the second time i set it it, is already wrong and from the third time it is even worse but then it stays this bad.it triggers too many interrupts, so that makes my interrupt too fast

My test macro set on a pin33 for the osciloscope :
2024-09-04_16-05-09.PNG
2024-09-04_16-05-09.PNG (39.67 KiB) Viewed 6643 times
My testloop:
2024-09-04_16-21-53.PNG
2024-09-04_16-21-53.PNG (101.43 KiB) Viewed 6643 times
All the printscreen:

nice signal for the first 2 Seconds
Perfect!
first.png
first.png (31.14 KiB) Viewed 6643 times
after 2 second
should be switched off. But is not
second.png
second.png (37.33 KiB) Viewed 6643 times
Then later it's stable wrong:
rest.png
rest.png (37.7 KiB) Viewed 6643 times

BenR
Matrix Staff
Posts: 1924
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 501 times
Been thanked: 684 times

Re: ESP32 Interrupt test if correct

Post by BenR »

Hi Stefan,

Great thanks, much appreciated.

I'll see if I can replicate and get to the bottom of why this is happening.

mnfisher
Valued Contributor
Posts: 1453
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 135 times
Been thanked: 707 times

Re: ESP32 Interrupt test if correct

Post by mnfisher »

Could you try using timer_pause()

See https://docs.espressif.com/projects/esp ... tart%28%29.

Martin

stefan.erni
Valued Contributor
Posts: 997
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 190 times
Been thanked: 217 times

Re: ESP32 Interrupt test if correct

Post by stefan.erni »

Hi Martin

I will test this soon. I found the fitting command and parameter.
timer_pause(timer_group_tgroup_num, timer_idx_ttimer_num)

How exactly are these parameters to be used?
just like this?

timer_pause(timer_group_t0,timer_idx_t0)

for Timer group number, 0
and Timer index, 0 for hw_timer[0]
2024-09-06_15-09-53.PNG
2024-09-06_15-09-53.PNG (47.05 KiB) Viewed 6304 times

mnfisher
Valued Contributor
Posts: 1453
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 135 times
Been thanked: 707 times

Re: ESP32 Interrupt test if correct

Post by mnfisher »

I thought of a simple way to do it... All Flowcode too :-)

So here - a simple example that toggles a pin every 50ms for 1s then pauses for 1s .. and repeats.
Timer_Pause.fcfx
(9.86 KiB) Downloaded 287 times
timer_pause seems to be for the newer timer component :-(

Martin

mnfisher
Valued Contributor
Posts: 1453
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 135 times
Been thanked: 707 times

Re: ESP32 Interrupt test if correct

Post by mnfisher »

A further thought - if you do want a cyclical pattern like this - move the toggle of enable to a separate task using vTaskCreate.

Then 'main' can do it's own thing and not worry about the timing at all.

Martin

stefan.erni
Valued Contributor
Posts: 997
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 190 times
Been thanked: 217 times

Re: ESP32 Interrupt test if correct

Post by stefan.erni »

Hi Martin

Yes, your suggestion works. As long as the interrupt is only enabled once.
The interrupt should never be stopped
or be restarted.


regards

Stefan

stefan.erni
Valued Contributor
Posts: 997
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 190 times
Been thanked: 217 times

Re: ESP32 Interrupt test if correct

Post by stefan.erni »

Hi Ben

Do you already have an idea why the interrupt cannot be stopped and restarted correct?
Maybe you can also check why the esp32 crashes when flowcode commands are written into the interrupt macro,
that would make a lot of things easier.
Is this the problem with all esp32? or I can just change to another ESP32 like the ESP32-C6?
I'll see if I can replicate and get to the bottom of why this is happening.

Post Reply