timer self-overlay

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
nesergen
Posts: 23
Joined: Mon Oct 26, 2020 9:17 pm

timer self-overlay

Post by nesergen » Mon Jul 05, 2021 11:57 am

I added a timer to the program, but I can't figure out one thing. Set the timer to fire every 1 second. Now the timer will perform a certain task. But what if the duration of the task is more than 1 second? It turns out that the timer will work again and interrupt the execution of the previous task and restart it? And then the task will never be completed? Or is the timer unable to interrupt itself?

davef
Posts: 813
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: timer self-overlay

Post by davef » Mon Jul 05, 2021 7:03 pm

Search for <Simple software WDT implementation> on the forum. I use a 70 second time period.

I think wdt_callback() and wdt_feed() takes care of the problem you raise.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: timer self-overlay

Post by jimmo » Tue Jul 06, 2021 6:38 am

nesergen wrote:
Mon Jul 05, 2021 11:57 am
Or is the timer unable to interrupt itself?
That's right.

Depending on which port/board you're using for the specific implementation, but neither a hard or soft IRQ can interrupt themselves.

In general it's a really bad idea to have interrupt handlers take long to execute (i.e. they should do the minimum possible work, i.e. set a flag), and then have your main program deal with the flag.

Post Reply