interrupt management

If doesn't fit into any other category ....
its1000
Posts: 55
Joined: Thu May 20, 2021 6:57 pm
Has thanked: 1 time
Been thanked: 1 time

interrupt management

Post by its1000 »

Hello to everybody.

I have a question regarding the interrupt function. I read the docs carrefully but the working mode is not really clear for me.
it seems that while the program is waiting for an interrupt, nothing else happens ?

i will have a small program running in an amplifier. i will display some infos on an ili9486 tft (preheating countdown, welcoming message, etc...) then a logo will be displayed.
to avoid the logo to get "burned" in the LCD screen, i will move it every 10mn on the screen.

while this part of the program loops in order to move le logo, I would like the ESP to detect if I press a button in order to execute something else.
it seems that if I put an interrupt and wait command in the part of this logo loop, the wait command will halt the program and my logo won't move anymore.

Am I right?
thank you in advance for your help
User avatar
Electroguard
Posts: 179
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 40 times
Been thanked: 102 times

Re: interrupt management

Post by Electroguard »

Interrupts and continuous polling don't make good bed-fellows, cos if the script is waiting for interrupts at the WAIT instruction it cannot be sequentially executing script lines, or conversely if the script is executing script lines it cannot be waiting for interrupts at a WAIT instruction.

But is not a problem, cos you can test for a button press without using interrupts... simply include a test for the button pin at one or more places within the loop, ie: if pin(button_pin) = 0 then gosub Pressed.
User avatar
PeterN
Posts: 97
Joined: Mon Feb 08, 2021 7:56 pm
Location: Krefeld, Germany
Has thanked: 41 times
Been thanked: 45 times
Contact:

Re: interrupt management

Post by PeterN »

Good morning
One more aspect to what Electroguard said:
On one hand you can make your main program loop as fast as possible and do all the tasks. That may then even require a "pause" to slow down things . And the system will get no time to "WAIT" for events in this construct.

To overcome this:
There are two timers on board.
The program may do all presets, initialize interrupt routines etc, ...
then start at least the first timer to call your main-routine , ...
maybe start a second timer to do regularly less frequently things ...
and then finally do a "WAIT" as the last line.

So the main routine does not loop in itself but is called regularly by the timer. And WAIT has time to wait and react fast .
its1000
Posts: 55
Joined: Thu May 20, 2021 6:57 pm
Has thanked: 1 time
Been thanked: 1 time

Re: interrupt management

Post by its1000 »

thank you Peter and Electro for your answers.
I have to say that I thought about what Electro proposed, but I don't think it will work.

if we try to sumup how will work the program it will be like this :

--------------------------------------
1st phase :
1/ initialization
2/ welcome message,
3 / pre-heating countdown 20s
4/ contact a relay on a pinout to send high tension to amplifier
5/ get from a file in Flash the old hours count total run from last start and store it in variable oldcount$

2nd phase:
1/ screen a logo on the tft on a position
2/ wait 10mn
3 / screen the logo on a different position
4 / wait 10 mn
5 / screen the logo on a different position
go back to phase 2 start

this is the normal running of my program, during the phase 2 run, 2 actions should be detected :

interruption case 1, push button info
if a push button info is pressed :
1/ the screen stop displaying the moving logo,
2/ instead an info screen with some other texts is displayed
3/ the program wait 15s
4/ go back to running phase 2

interruption case 2, loss of power
if High power level disapears from pin x:
1/ add millis() to oldcount
2/ write oldcount in flash file
this cycle will be possible because ESP run on a Supercapa
then the whole system will stop
-------------------------------------------------------------------------

if i try to put the interruption detection in the phase 2 part of the program, due to the fact there is 10mn pauses, it will be impossible to detect the pin state to activate interupt case 1 or case 2 ...
am I wrong?

regarding what Peter proposed, I will go into the documentation to understand well the timer function in order to test it, because to be honnest, i am a little bit lost because I never used it.

again thank you very much for your time an patience to explain to noobies like me how it works it's a real chance having guys like you to help us.
User avatar
PeterN
Posts: 97
Joined: Mon Feb 08, 2021 7:56 pm
Location: Krefeld, Germany
Has thanked: 41 times
Been thanked: 45 times
Contact:

Re: interrupt management

Post by PeterN »

Good morning its1000

Wouldn't it be sufficient to write the countdown once per minute to the file?
To make it a bit more accurate, you could then additionally try to write in case of a power failure.
This would also ensure that a runtime is logged reasonably accurately, even if the ESP should fail or run into an error in between.
User avatar
PeterN
Posts: 97
Joined: Mon Feb 08, 2021 7:56 pm
Location: Krefeld, Germany
Has thanked: 41 times
Been thanked: 45 times
Contact:

Re: interrupt management

Post by PeterN »

... and take a look at the "Projects" thread in this forum. There you will find very good examples from which you can learn.

This example may correspond to your display setting:
[Local Link Removed for Guests]

And this example could give some hints to display and log the status and runtime of two pumps on a regular basis
[Local Link Removed for Guests]
its1000
Posts: 55
Joined: Thu May 20, 2021 6:57 pm
Has thanked: 1 time
Been thanked: 1 time

Re: interrupt management

Post by its1000 »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Tue Jul 20, 2021 5:45 am Good morning its1000

Wouldn't it be sufficient to write the countdown once per minute to the file?
To make it a bit more accurate, you could then additionally try to write in case of a power failure.
This would also ensure that a runtime is logged reasonably accurately, even if the ESP should fail or run into an error in between.
This is what I wanted to do at first instead of writing the counter only when power run out, but I really thought it was not a good idea to write every minutes in the flash memory of the ESP to avoid killing it...
it is something I read from Arduino memory management. it is true that amplifier will be ON about 2hrs a day. and i can also write every 10 mn it is enough. so maybe the memory will last more than my amplifier...
regarding SD card, I need to understand the file management between internal flash and SD, I never tried to use an SD card
its1000
Posts: 55
Joined: Thu May 20, 2021 6:57 pm
Has thanked: 1 time
Been thanked: 1 time

Re: interrupt management

Post by its1000 »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Tue Jul 20, 2021 6:08 am ... and take a look at the "Projects" thread in this forum. There you will find very good examples from which you can learn.

This example may correspond to your display setting:
[Local Link Removed for Guests]

And this example could give some hints to display and log the status and runtime of two pumps on a regular basis
[Local Link Removed for Guests]
thank you. I will dive in this to understand. if I manage the file writing without interrupt,
my only issue is to move the logo on the screen to avoid burning it, and to detect a pin state change at any time, even if the programm is halted waiting for the next logo move.
User avatar
PeterN
Posts: 97
Joined: Mon Feb 08, 2021 7:56 pm
Location: Krefeld, Germany
Has thanked: 41 times
Been thanked: 45 times
Contact:

Re: interrupt management

Post by PeterN »

The file system of the SD completely replaces the internal file system. They do not exist in parallel.
So even your program is on the SD card.
its1000
Posts: 55
Joined: Thu May 20, 2021 6:57 pm
Has thanked: 1 time
Been thanked: 1 time

Re: interrupt management

Post by its1000 »

VERY CLEAR ! thank you.
and not too much dangerous? SD card are not so reliable...
Post Reply