Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 15:43 06 Jul 2025 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 : Error

Author Message
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 12:33am 30 Dec 2016
Copy link to clipboard 
Print this post

I have a micromite with OPTION AUTORUN ON

Is there ANY way to restart the micromite if it crashes?

Something like "IF ERROR THEN RUN" ?
Edited by lew247 2016-12-31
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9589
Posted: 12:55am 30 Dec 2016
Copy link to clipboard 
Print this post

If by "Crash" you mean it stops to the command-prompt with an error, then the WATCHDOG command would probably help you there.

If by "Crash" you mean that the PIC32 core actually crashes - which means that the MMBASIC firmware crashes also and stops working - then you would PROBABLY need an external watchdog to force a reset.

I am not sure if WATCHDOG actually interfaces to the watchdog in the PIC32, but it quite probably does - Geoff or Peter(matherp) will know this, and be able to say.

If it DOES talk to the internal watchdog, and provided that runs seperate from the core, then WATCHDOG should still reset a crashed core, but that is possibly a big ask as I would expect if something bad enough to crash the core happens, then a software watchdog won't help you either.

Perhaps you could clarify which one of those crashes you mean.
Smoke makes things work. When the smoke gets out, it stops!
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 1000
Posted: 12:58am 30 Dec 2016
Copy link to clipboard 
Print this post

Hi Lewis,

The WATCHDOG command should help.
See the extract from the manual below.


Regards
Gerry





WATCHDOG timeout
or
WATCHDOG OFF
Starts the watchdog timer which will automatically restart the processor
when it has timed out. This can be used to recover from some event that
disabled the running program (such as an endless loop or a programming or
other error that halts a running program). This can be important in an
unattended control situation.
'timeout' is the time in milliseconds (mS) before a restart is forced. This
command should be placed in strategic locations in the running BASIC
program to constantly reset the timer and therefore prevent it from counting
Micromite User Manual Page 73
down to zero.
If the timer count does reach zero (perhaps because the BASIC program has
stopped running) the Micromite will be automatically restarted and the
automatic variable MM.WATCHDOG will be set to true (ie, 1) indicating
that an error occurred. On a normal startup MM.WATCHDOG will be set to
false (ie, 0).
At any time WATCHDOG OFF can be used to disable the watchdog timer
(this is the default on a reset or power up). The timer is also turned off when
the break character (normally CTRL-C) is used on the console to interrupt a
running program.


Latest F4 Latest H7 FotS
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 01:39am 30 Dec 2016
Copy link to clipboard 
Print this post

hanks
I did search the manual but I was looking for error not watchdog

If I understand what was said above, if the program stops with something similar to
Error: device not found or something similar, if the watchdog is turned on then the program will wait a set number of seconds and then run again?

What time would you set the watchdog to?
The program I'm using has a timer that counts in seconds so I would "assume" if I put something like
WATCHDOG 60 would tell the micromite to run the program again if it does stop on an error?

Where would you recommend the command is put in the program?
Or can you have it in several places?


 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 02:45am 30 Dec 2016
Copy link to clipboard 
Print this post

  Quote  
If I understand what was said above, if the program stops with something similar to
Error: device not found or something similar, if the watchdog is turned on then the program will wait a set number of seconds and then run again?[/quote]
As noted above, the watchdog timer is just a timer to start a reboot. It does not respond to particular causes. If the program fails to get to the next watchdog command in time, for any reason, then it reboots.
[quote]
What time would you set the watchdog to?
The program I'm using has a timer that counts in seconds so I would "assume" if I put something like
WATCHDOG 60 would tell the micromite to run the program again if it does stop on an error?[/quote]
the choice of where and how long is yours to make depending on how long you expect each section of the program would take to execute. Note that any times specified in the WATCHDOG command are in MILLISECONDS. A time of 60 seconds is specified by WATCHDOG 60000

[quote]Where would you recommend the command is put in the program?
Or can you have it in several places?[/quote]
You may put the command multiple times in your program with differing timer values as needed to protect each section of the program. You can even turn it off and then on again later if you know that the time to execute the next WD command is unpredictable.

The idea is that your program gets to execute the next WD command before the previous one times out. If it doesn't then the system reboots.
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3282
Posted: 03:57am 30 Dec 2016
Copy link to clipboard 
Print this post

  Grogster said  I am not sure if WATCHDOG actually interfaces to the watchdog in the PIC32, but it quite probably does - Geoff or Peter(matherp) will know this, and be able to say.

No, The MMBasic WATCHDOG feature does not use the PIC32 hardware watchdog timer. This is because that timer's timeout must be set at compile time.

If there is an exception (an internal PIC32 error) the processor will immediately restart and if autorun is on the BASIC program will restart - so the MMBasic WATCHDOG can be used to recover from all errors.

Geoff
Geoff Graham - http://geoffg.net
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 04:04am 30 Dec 2016
Copy link to clipboard 
Print this post

Thanks everyone
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9589
Posted: 12:46pm 30 Dec 2016
Copy link to clipboard 
Print this post

@ BobD - Nice explanation.

@ Geoff - OK. Thanks. Was not sure.

The common way to do the watchdog thing in days gone past, was with a 555 timer or similar circuit. We even developed one here on the forums a few years ago.

Back in the 80's and 90's before the plethora of MCU's we have now, the main controller used to output a pulse on a pin, often referred to as a 'Heartbeat' or just 'Watchdog'. This pulse would continuously reset an external timer. Now, if the controller fell over for some reason, these heartbeat pulses would stop, and the external timer would time-out(normally about 5-10 seconds depending on design), and it would then pulse the RESET pin of the main controller, forcing it to restart.

A very old idea, but still a very relevant one, and any modern system designer HAS to consider failure recovery if the system is important - such as security. Luckily for us, the MM WATCHDOG command makes this child's-play these days. I particularly love the MM WATCHDOG for it's MM.WATCHDOG variable - see page 73 of standard manual - as you can look at this variable at start-up, and in my case, I use that to append to the system log along with date and time, any time the watchdog has reset the system for some reason.
Smoke makes things work. When the smoke gets out, it stops!
 
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 2025