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:
ESP32 Interrupt test if correct
-
- 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
-
- 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
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?
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?
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
-
- 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
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 :
My testloop: All the printscreen:
nice signal for the first 2 Seconds
Perfect! after 2 second
should be switched off. But is not Then later it's stable wrong:
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 :
My testloop: All the printscreen:
nice signal for the first 2 Seconds
Perfect! after 2 second
should be switched off. But is not Then later it's stable wrong:
-
- 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
Hi Stefan,
Great thanks, much appreciated.
I'll see if I can replicate and get to the bottom of why this is happening.
Great thanks, much appreciated.
I'll see if I can replicate and get to the bottom of why this is happening.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
-
- 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
Could you try using timer_pause()
See https://docs.espressif.com/projects/esp ... tart%28%29.
Martin
See https://docs.espressif.com/projects/esp ... tart%28%29.
Martin
-
- 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
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]
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]
-
- 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
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 seems to be for the newer timer component
Martin

So here - a simple example that toggles a pin every 50ms for 1s then pauses for 1s .. and repeats.
timer_pause seems to be for the newer timer component

Martin
-
- 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
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
Then 'main' can do it's own thing and not worry about the timing at all.
Martin
-
- 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
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
Yes, your suggestion works. As long as the interrupt is only enabled once.
The interrupt should never be stopped
or be restarted.
regards
Stefan
-
- 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
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?
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.