Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 16:13 12 Aug 2026 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Watchdog timer  - PicoMite 6.03.00

Author Message
Nimue

Guru

Joined: 06/08/2020
Location: United Kingdom
Posts: 437
Posted: 11:31am 11 Aug 2026
Copy link to clipboard 
Print this post

Hi all - lots of lurking, trying to keep up.

Not sure if this is Watchdog question or not.

I am coding an "attractor" mode for a static display - which cycles through demos of various games I have written (think Defener, Missile Command etc)  [Will post those else where).  

The idea is to leave the screen running, boot the Picomite, select a game and play portion of the game, reboot and then pickanother -- this is then left on to cycle randomly though the games.

So far I have a Menu that is autorun on boot that looks like:

OPTION EXPLICIT
OPTION DEFAULT NONE

dim attract$ as string

SELECT CASE INT(RND * 4) + 1
   CASE 1
       attract$ = "defender.bas"
   CASE 2
       attract$ = "asteroids.bas"
   CASE 3
       attract$ = "lander.bas"
   CASE 4
       attract$ = "missile.bas"
END SELECT

chain attract$


This works, as in it selects a random game demo to load.

Each game has
Option Explicit
Option Default Integer
Option Base 0
Watchdog 10000


as a standard header.

On first running, as said, a game is selected randomly, loads and plays.  Then the watchdog kicks in and it restarts the CPU. BUT at that point the game just loaded restarts.

It looks like the autorun menu is not running.

Now, this might be the way watchdog is supposed to run.

If so, what are my options to:

(1) Randomly load a game
(2) Restart with a different random game


I see I can:
SETTICK period, target [, nbr]


So I could modify all the game code for those to be loaded to fire off a random interrupt to chain a new file after a random amout of time and abandon a menu load all together --- but it seems like there should be an easier way.

Current have "self playing demos" of:

Defender
Asteroids
Moon Lander
Missile Command
Tron (not great)
Gunslinger
SubHunt
Tempest (also not great)
Centipede
SeaWolf
Space Invaders
Arkanoid
Dino Jump (the Google game that plays when the internet is dead)
Pong
Plus Conway's Life and Matrix Rain)

And adding more - so would rather a menu that adding boiler plate to each one.

Any MMBasic / PicoMite way to force a new program (randomly) to load on boot from a watchdog?   OR other clever stuff?

Appreciate this could be a DOH!!! question and the answer is there alluding me  

Cheers
G
Entropy is not what it used to be
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11737
Posted: 11:37am 11 Aug 2026
Copy link to clipboard 
Print this post

Not tested, but try putting the menu program into flash slot 1 and use OPTION AUTORUN 1
 
Nimue

Guru

Joined: 06/08/2020
Location: United Kingdom
Posts: 437
Posted: 12:23pm 11 Aug 2026
Copy link to clipboard 
Print this post

  matherp said  Not tested, but try putting the menu program into flash slot 1 and use OPTION AUTORUN 1


No joy - when first run - the selection is random, but then every time watchdog kicks in, the program that called it is the one that is restored -- it never goes back to the menu, even when menu is in slot 1 and autorun set.

Added some diagnostic Prints.

When first powered on, autoloads menu >> random game fired off.
On watchdog reboot, it doesnt load the menu (no diagnostics fired off) - but restores the last program in memory instead.  

Digging....
Entropy is not what it used to be
 
Nimue

Guru

Joined: 06/08/2020
Location: United Kingdom
Posts: 437
Posted: 12:30pm 11 Aug 2026
Copy link to clipboard 
Print this post

For clarity "all" that I'm looking to do is:

(1) Load a random file - let it run for a time
(2) Fire a watchdog reboot
(3) Repeat

The "issue" seems to be that rebooting after a watchdog doesnt fire off the autorun file but restarts the file that called the watchdog.

Will test with random tick interrupts in each file to load that way (but that feels like it will just work ;-)  -- not a biggie, but watchdog functioning differently than expected.
Entropy is not what it used to be
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 3348
Posted: 01:07pm 11 Aug 2026
Copy link to clipboard 
Print this post

Sub MM.STARTUP will always run before the program in memory.
Put your randomizer in there.

The problem with random numbers is you will get a fair bit of repetition, which doesn't look random. Even adding another level of randomness doesn't help.
Eg.
> do : pause RND * 9999 : GameNo = (epoch(now)+ RND*10) mod 4 : ? GameNo; : loop
0 1 1 1 3 0 0 1 3 1 2 0 2 0 2 3 1 1 0 0 2 3 3 3 0 2 0 3 1 0 2 3 0 1 2 2
>


To avoid that the last game needs to be excluded from the next choice.

Use VAR SAVE / RESTORE or the EEPROM on an RTC module to record the current program number and restore it at the start of MM.Startup.
 
Nimue

Guru

Joined: 06/08/2020
Location: United Kingdom
Posts: 437
Posted: 01:28pm 11 Aug 2026
Copy link to clipboard 
Print this post

  phil99 said  Sub MM.STARTUP will always run before the program in memory.
Put your randomizer in there.


Nice -- but in fairness, its not the randomness here - its been running for 30mins now and only restarts to the last loaded program -- so watchdog is doing something different than a clean power on start.  It's never re-running the program in the Autorun slot after a watchdog.

That said, I'll see what I can do with this.

G
Entropy is not what it used to be
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4366
Posted: 01:50pm 11 Aug 2026
Copy link to clipboard 
Print this post

Maybe try using MM.INFO(BOOT) in each program to see how you got there and if it's the watchdog them call your startup code.

John
 
Nimue

Guru

Joined: 06/08/2020
Location: United Kingdom
Posts: 437
Posted: 01:59pm 11 Aug 2026
Copy link to clipboard 
Print this post

I've solved my problem with the following boilerplate to each program:

settick 6000,lnew
...

sub lnew
 SELECT CASE INT(RND * 4) + 1
     CASE 1
         attract$ = "defender.bas"
     CASE 2
         attract$ = "asteroids.bas"
     CASE 3
         attract$ = "lander.bas"
     CASE 4
         attract$ = "missile.bas"
 END SELECT

 run attract$
end sub


Which does as intended without the watchdog -- just works.

G
Entropy is not what it used to be
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11737
Posted: 02:09pm 11 Aug 2026
Copy link to clipboard 
Print this post

MM_STARTUP in the library should have fixed it as suggested by phil
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 6029
Posted: 02:10pm 11 Aug 2026
Copy link to clipboard 
Print this post

Nimue,

Agree, strange behaviour of the watchdog command. This is not a clean start.
Tested on V60300 picomiteVGA. I tried the version with autorun flash program.

It is possible that the whole automatic restart removes the randomness. So in essence the same "random chosen" program is restarted every time.

In my test case there was only 1 restart (you can observe because a restart resync the monitor).

Your solution is better (no CPU restart, no monitor resync). But programs need modification.

Volhout
Edited 2026-08-12 00:11 by Volhout
PicomiteVGA PETSCII ROBOTS
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11737
Posted: 02:20pm 11 Aug 2026
Copy link to clipboard 
Print this post

You don't say what version of the Pico. If the RP2040 then RND is S/W and will always give the same sequence.
 
Nimue

Guru

Joined: 06/08/2020
Location: United Kingdom
Posts: 437
Posted: 02:27pm 11 Aug 2026
Copy link to clipboard 
Print this post

Upfront, the soln I posted for me has nailed it.

MM_Startup - solves it too, with the addition of tick interrup in each program -- less boiler plate.

Now this solution is "better" that using the watchdog as the attached LCD screen does not now cycle through white on reset -- so good learning curve.

Will leave watchdog alone ;-)

I'll tidy these up and post the code.

FWIW - the "games" are not real - in so much as the 'mite plays itself - there are no user inputs as I was going for the "look and feel" of these classic games - but they work in so much as the scoring mechanism and the game play is sort of like the real things.

The point of all this being to swap out the fake screen on this robot to a screen that cycles randomly through some periodish games and graphics...









Entropy is not what it used to be
 
Nimue

Guru

Joined: 06/08/2020
Location: United Kingdom
Posts: 437
Posted: 02:29pm 11 Aug 2026
Copy link to clipboard 
Print this post

  matherp said  You don't say what version of the Pico. If the RP2040 then RND is S/W and will always give the same sequence.


Yes the 2040 - got that re the randomness -- happy enough with pseudo random as its just for display.

Thanks for the input - I'm learning ;-), got there in the end for my use case.

G
Entropy is not what it used to be
 
Nimue

Guru

Joined: 06/08/2020
Location: United Kingdom
Posts: 437
Posted: 02:44pm 11 Aug 2026
Copy link to clipboard 
Print this post

  JohnS said  Maybe try using MM.INFO(BOOT) in each program to see how you got there and if it's the watchdog them call your startup code.
John


Nope - the watchdog only seems to call the program from within which itself was called.

Anyway, problem "fixed" for my use case (see thread).

Thanks for the pointer.
Entropy is not what it used to be
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4366
Posted: 03:42pm 11 Aug 2026
Copy link to clipboard 
Print this post

  Nimue said  
  JohnS said  Maybe try using MM.INFO(BOOT) in each program to see how you got there and if it's the watchdog them call your startup code.
John


Nope - the watchdog only seems to call the program from within which itself was called.

That's why I posted that it would need to be in each program.

  Nimue said  Anyway, problem "fixed" for my use case (see thread).

Thanks for the pointer.

Hooray!

John
 
Nimue

Guru

Joined: 06/08/2020
Location: United Kingdom
Posts: 437
Posted: 06:50pm 11 Aug 2026
Copy link to clipboard 
Print this post

Calling "run" from within a Sub led to error related to Heap -- I assume that leaving the sub open evertime leaks memory away.

Switched to a If statment instead.

Seems OK now.

Live and learn!
Entropy is not what it used to be
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 6029
Posted: 06:54pm 11 Aug 2026
Copy link to clipboard 
Print this post

In stead of watchdog, you can use the same mechanism with SETTICK, and then do a CPU RESTART

Volhout
PicomiteVGA PETSCII ROBOTS
 
Nimue

Guru

Joined: 06/08/2020
Location: United Kingdom
Posts: 437
Posted: 07:00pm 11 Aug 2026
Copy link to clipboard 
Print this post

  Volhout said  In stead of watchdog, you can use the same mechanism with SETTICK, and then do a CPU RESTART

Volhout


OOooh - like this idea, will have a look later - will be cleaner, less boiler plate in each.

Currently wasting too much time watching the 'Mite play Lunar Lander by itself ;-)

G
Entropy is not what it used to be
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 6029
Posted: 05:09am 12 Aug 2026
Copy link to clipboard 
Print this post

Hi Nimue,

Some code you could share.? A pico playing the game autonomously is a Nice thing to Watch.
Like a screensaver.
My screensaver is currently a pico playing chess. Very interesting to see the pico play move I would not have seen, and Some work out great, Some don’t.

Volhout
PicomiteVGA PETSCII ROBOTS
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026