Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 10:00 15 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 : Prevent HW Error from stopping Program

Author Message
atmega8

Guru

Joined: 19/11/2013
Location: Germany
Posts: 712
Posted: 02:30am 21 Aug 2015
Copy link to clipboard 
Print this post

Hello,



how can i prevent a Hardware error, for example broken cable of RTC, from stopping the Programm?


RTC Gettime
Error: RTC not responding


THX,

Atmega8


 
atmega8

Guru

Joined: 19/11/2013
Location: Germany
Posts: 712
Posted: 08:50am 23 Aug 2015
Copy link to clipboard 
Print this post

Hi Forum,

may be this is really no problem and i'am wrong ?!
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3676
Posted: 10:55am 23 Aug 2015
Copy link to clipboard 
Print this post

Generally you can't and should not expect to.

As there are far more of them it's more likely you'll have badly soldered power or grounds.

The fix is to solder properly. If you can't then buy boards from someone who can.

Or, use multiple boards and vote. Much as the US moon rockets did.

(They did use pretty reliable hardware, too.)

JohnEdited by JohnS 2015-08-24
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 11:46am 23 Aug 2015
Copy link to clipboard 
Print this post

You can set the watchdog timer which will restart the processor... but then it will fall over again when it tries to read the RTC. Other than that there is nothing that you can do as MMBasic treats a failed RTC as a fatal error.
Geoff Graham - http://geoffg.net
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1139
Posted: 12:14pm 23 Aug 2015
Copy link to clipboard 
Print this post

I think this could be done with a extended version of "ON ERROR CONTINUE".
But this wold make MMBasic (source) more komplex ...
 
srnet
Senior Member

Joined: 08/08/2014
Location: United Kingdom
Posts: 164
Posted: 09:41pm 23 Aug 2015
Copy link to clipboard 
Print this post

Perhaps a specific function that would just return an error if there was no device found on the I2C bus would be an idea.

At last then the program could be written so that it could, at startup for instance, test for the devices and flag and report an error in some way.

Edited by srnet 2015-08-25
$50SAT is Silent but probably still working.
For information on LoRa visit http://www.loratracker.uk/

 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1139
Posted: 01:06am 24 Aug 2015
Copy link to clipboard 
Print this post

Yes, if the concern is only to the RTC error intercept you can write your own RTC procedure.

Something like this (not tested yet!):

Sub SaveRTC
DIM temp, i2caddr, RTCavail
i2caddr = &h68 ' Your RTC address for DS3231

I2C open 100, 1000 ' i2c enable 100kHz, 1000ms timeout
I2C read i2caddr, 0, 1, temp

If MM.I2C = 0 Then
RTCavail=1
else
RTCavail=0
Print "RTC Error "; i2caddr
EndIf
I2C close ' i2c disable
if RTCavail then RTC GETTIME
End sub


Michael
 
atmega8

Guru

Joined: 19/11/2013
Location: Germany
Posts: 712
Posted: 09:36am 24 Aug 2015
Copy link to clipboard 
Print this post

I think, that in general, a malefunktion of a peripheral Hardware device, should not stop the program execution.
Instead it should set an error flag, like MM.errno.
So the software programmer is responsable for the correct error Handling.

What do you think?

Should not be to hard, to implement?!
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1139
Posted: 10:43am 24 Aug 2015
Copy link to clipboard 
Print this post

  atmega8 said   I think, that in general, a malefunktion of a peripheral Hardware device, should not stop the program execution.
Instead it should set an error flag, like MM.errno.
So the software programmer is responsable for the correct error Handling.

What do you think?

I agree, in many cases it could be done easily. But there are limits (execution speed, memory usage, development cycle time). And for a one man project seems MMBasic pretty well made.

Please remember: If you need you can take the original sources and build your own (better/safer) CFunctions ... and share here.

On the other hand, I think perhaps it would be important to remember not only as many functions as possible to have but also a good error handling.

Just my 2c.
 
Positron

Newbie

Joined: 09/08/2015
Location: Argentina
Posts: 15
Posted: 02:54pm 24 Aug 2015
Copy link to clipboard 
Print this post

  Geoffg said   You can set the watchdog timer which will restart the processor... but then it will fall over again when it tries to read the RTC. Other than that there is nothing that you can do as MMBasic treats a failed RTC as a fatal error.


Just elaborating on Geoff's idea of using the Watchdog timer to reset the CPU, if you combine this with using a persistent variable to indicate if a hardware operation is pending, you could recover easilly.

Some quick and dirty pseudocode to implement this idea (not tested...):

1. Outside your program (command line) use RTC SETREG to set a Flag that indicates a pending HW operation initially =0 (only once or after you fixed the faulty hardware).
2. In your program check that Flag with RTC GETREG, if =0 you set it to =1 and perform the HW operation.
3. If it hangs up, the watchdog will reset the CPU and your Flag will be =1 indicating that the previous operation failed, so on the next execution of your routine it knows you have a faulty HW and perform whatever recovery or ignore sequence you like.
4. If the HW operation succeeds, you reset the Flag to =0 and execute your normal code.

I think this could work for you, let me now.

PD: You could also use VAR SAVE/ RESTORE if you are not abusing the flash with writes every minute...
Edited by Positron 2015-08-26
 
atmega8

Guru

Joined: 19/11/2013
Location: Germany
Posts: 712
Posted: 06:54pm 24 Aug 2015
Copy link to clipboard 
Print this post


You can not check the proper function of an object with the object himself ( itself?) !
This results in a Perpetuum Mobile.
All in all it sounds a Little Bit abstrus.

Blut what about the MMBasic command "continue"?Edited by atmega8 2015-08-26
 
Positron

Newbie

Joined: 09/08/2015
Location: Argentina
Posts: 15
Posted: 05:36pm 25 Aug 2015
Copy link to clipboard 
Print this post

Sorry atmega8, perhaps I didn't expalain it well with my pseudocode, but I think this method will work because once that the hw function fails, the watchdog resets and next time you effectively know that it failed BEFORE executing the hw function again ! So you are not trapped in a loop.

I will write a small program to prove this tomorrow.
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2294
Posted: 06:39pm 25 Aug 2015
Copy link to clipboard 
Print this post

with delphi, there are quite complicated structures to handle errors. TRY / EXCEPT / END is the simplest one that could be useful in MMbasic - if it were practical to add in, of course. the (basic-ized) syntax is:

TRY
RTC GETTIME
print "time set OK"
EXCEPT
print "enter time (H, M, S)";
input H, M, S
time$ = str$(H) +":"+ str$(M) +":"+ str$(S)
ENDTRY
print "code carries on here"


geoff: how difficult would it be to add this sort of error/exception handling to MMbasic? in an ideal world, this sort of structure could be used to catch division by zero and other maths errors, even as an alternative to the current DS18B20, DISTANCE, and DHT22 error handling.


cheers,
rob :-)Edited by robert.rozee 2015-08-27
 
atmega8

Guru

Joined: 19/11/2013
Location: Germany
Posts: 712
Posted: 06:46pm 25 Aug 2015
Copy link to clipboard 
Print this post

Hi Rob,

a mailfunction of a ds1820 does Not stop the Program.

It returns a value of 1000 andrehe program resumes operation.

If you check for 1000 you have an Error Handling.

Atmega8
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2294
Posted: 06:56pm 25 Aug 2015
Copy link to clipboard 
Print this post

i'm thinking it could be available as a secondary method of handling the situation, perhaps providing a cleaner syntax. the structure could perhaps also be used to handle I2C and ONEWIRE failure conditions - again, even though the errors are not not fatal, the syntax may prove to be easier to read.

cheers,
rob :-)
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3165
Posted: 06:24am 26 Aug 2015
Copy link to clipboard 
Print this post

Implementing an ON ERROR function is not that easy. Currently the interpreter simply clears the stack and all status (ie, FOR loops, GOSUB returns, etc) and returns to the command prompt. This makes it easy, on every error it simply goes back to the start. But ON ERROR requires the interpreter to intelligently exit whatever command was being executed and keep the program's status. There are lots of errors that can occur so that would require a lot of extra code (and flash).

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

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 08:07am 26 Aug 2015
Copy link to clipboard 
Print this post

Hi Robert

Way back when, I once wrote an interpreter for a language called CESIL, "Customer Engineering Systems Integration Language", for Thorn EMI, which was an interpreter for process control of HVAC equipment.

In that interpreter we had a global var called ERRNO which was normally 0. When the interpreter encountered an error, it would set ERRNO to a non zero value, ie the error code. The program could then check after executing a command which might give rise to an error for a non-zero ERRNO value and if ERRNO was non-zero then decide what to do based on the value of ERRNO.

If I recall the syntax was something like

[code]
;Set ERRNO to 0 before we start the operation
ERRNO=0
I=ANALOGUE(20)
;Capture the state of ERRNO
J=ERRNO
ERRNO=0

;Error Handling block
IF J <> 0 THEN
;If conversion out of range, then try again
IF J=1
I=ANALOGUE(20)
ENDIF
;Check if another error condition
IF J=2
do something
ENDIF

ENDIF
;Reset ERRNO to 0
ERRNO=0

.... continue with rest of program

[/code]

Since this was an embedded control system, aborting to the console was not an option, and restarting was also deemed too drastic, hence the ERRNO concept. (restart being reserved for watchdog timeout).

In many ways ERRNO is similar to the "RESUME NEXT" of Visual Basic, leaving the error checking and handling up to the programmer.

When it comes to MMBasic, I would suggest that perhaps a new OPTION, OPTION ERROR RESUME | BREAK could be added to MMBasic, ie when OPTION ERROR RESUME is in force MMBasic simply updates a variable, eg MM.ERRNO with a non-zero code reflecting the error condition and then continues onto the next MMBasic statement, whereas with OPTION ERROR BREAK in force, MMBasic breaks out to the command prompt as it does now.

I don't know if MMBasic would permit a statement such as MM.ERRNO=0 to be issued, but that's surely a minor detail.

PeterEdited by G8JCF 2015-08-27
The only Konstant is Change
 
Print this page


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

© JAQ Software 2024