Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 14:44 08 May 2024 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 : MMBasic on error set state?

Author Message
Gizmo

Admin Group

Joined: 05/06/2004
Location: Australia
Posts: 5030
Posted: 11:16am 07 Jun 2013
Copy link to clipboard 
Print this post

Hi Guys

Not sure if this has been covered before, but couldn't find anything.

I'm using a Maximite clone to control my solar array for my off grid power system. The maximite monitors battery voltage and current, and switches 3 solid state relays. The solar panels are grouped so that by switching the relays in a certain way I can step up the power in 6 steps, sort of like a binary counter. This is used to regulate the voltage for the charging cycles, eg boost at 60 volts for a couple of minutes, absorb at 57 volts for 3 hours, float, etc.





The other day while I was welding, the output current readings on the display went over 100 amps and caused a error, due to MMBasic trying to format a number longer than it expected. This caused the program to exit, at a time when all 3 relays were switched on, meaning the batteries were fed full power from the solar panels. Lucky I noticed it within a few minutes, and restarted the program. Later I fixed the bug in my code to stop it happening again.

Now this raised a concern for me. If the program crashes while I'm away for the day, and the relays were on at the time, I risk overcharging my battery bank, or possibly sending it flat if all the relays were off.

So, what I would like is a command that can be set at the start of the program to set the maximite outputs to a preset state if there is a error. Something like...

On Error SetState "0000000000"

Or similar. The number could be binary. The idea is if my program crashes, the output pins are put in a state that is safe. In my case, I would turn off all solar panels except for the lowest power panel, just enough to trickle charge a battery without overcharging it.

What do you think?

Glenn
The best time to plant a tree was twenty years ago, the second best time is right now.
JAQ
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 11:44am 07 Jun 2013
Copy link to clipboard 
Print this post

I would go for a hardware / firmware solution external to the Maximite. A watchdog timer is one that has a bit of discussion lately. Another thought is a timer to lockout the higher power states if they are on too long. Given this is mission critical I wouldn't rely entirely on the MM as it can get into a state where if it crashes, it will not restart. Geoff G said that yesterday. When I checked it was at 2:22am today here. Edited by BobD 2013-06-08
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 02:38pm 07 Jun 2013
Copy link to clipboard 
Print this post

I believe that an external watchdog circuit is the best approach. It only requires a couple of 555s and will always work.

I have not tried to implement a software solution as it is impossible to predict and handle all the failures that could stop your program. Your experience is something I had not thought of but other failures could include a CPU freeze due to a power glitch or a hang up due to a corrupt I2C transaction.

With a simple external circuit you can always be sure that, in the absence of a regular signal, the PIC32 is reset and starts up in a clean state... regardless of the failure mode.

While the Error State command would fix one possible issue there are too many other failure modes to make it generally useful. But I will re look at a WATCHDOG command using the PIC32's watchdog hardware as it would be a partial solution for people who do not want to bother with an external circuit.

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

Admin Group

Joined: 05/06/2004
Location: Australia
Posts: 5030
Posted: 07:08pm 07 Jun 2013
Copy link to clipboard 
Print this post

Just throwing idea's in here. What about...

on error run "recover.bas"

So on a unexpected exit, the maximite could call another program. If you wanted it to restart the current program, use its file name instead of another.

Glenn
The best time to plant a tree was twenty years ago, the second best time is right now.
JAQ
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 07:46pm 07 Jun 2013
Copy link to clipboard 
Print this post

Gosh, the ideas are flowing. I have just finished a prototype of the WATCHDOG command so I will rethink which approach is the best (or maybe both).

On Monday I hope to have another beta ready with the WATCHDOG command and the ability to specify the maximum length of strings used in arrays (to save on memory).

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

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 08:26pm 07 Jun 2013
Copy link to clipboard 
Print this post

I think a watchdog should just do a reset and nothing else.
Keep it as simple as possible because it is the solution to get out of unknown problems.
If the watchdog has more functionalities the chances for unknown problems increase.
The simplicity of only a reset has proven its worth over many many years.
Specifying which program to run is unnecessary because after a reset it will always be autorun.bas.
Maybe have the possibility to read out the watchdog registers with a command so that the reason the program started can be known. In the autorun.bas you could then do something like:

[code]
IF MM.Watchdog = 1 then .....
[/code]

When the Maximite is used to control external critical hardware the circuit must be made safe when the maximite itself is reset.

You would then also be able to test what happens by just resetting the Maximite.

I would suggest a 2-stage watchdog.
When a program uses a WATCHDOG command the responsibility of resetting the watchdog counter should be under full control of the program.
Preferably a time can be set (the specs of the pic32 state 1ms - 1048.576 seconds can be chosen using a postscaler ratio). A good range for use in a program probably starts with at least 1 second. You would then be unable to use INPUT and wait for user input, but in most cases a watchdog is only critical when no user input is expected.

When a WATCHDOG command is not used in a program, MMBasic can use it internally to ensure the Maximite still resets when unknown situations occur.
Edited by TZAdvantage 2013-06-09
Microblocks. Build with logic.
 
Print this page


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

© JAQ Software 2024