Internal Watchdog

kakolon

Member
Hi,
I need to automatically reset the picaxe from time to time if nothing happens, I’ve read that a watchdog is capable of doing this job, but couldn't find it in the Picaxe Doc's.
The watchdog should be internal; I can't use an external watchdog to reset the picaxe.

Thank you,
kakolon
 

hippy

Technical Support
Staff member
There is no watchdog function available with the PICAXE so the best option is an external one.

If you have the right PICAXE and a couple of spare I/O lines you can use the Timer1 to generate an interrupt and have the interrupt handler jump back to the start of code, but that may also entail some jiggery pokery to get the interrupt re-enabled after that.
 

tarzan

Senior Member
reset

For X1 parts “RESET” is available.
Some key words to get you started:
setintflags %10000000,%10000000
settimer t1s_4
interrupt:
return
toflag
 

kakolon

Member
Thanks for the replays,
I'm needing to reset the picaxe at some point, because the picaxe hangs randomly, and I have to reset it to continue working. The software RESET won't help me as the picaxe is hang when I need to reset it.
I thought there could be an internal watchdog, that could never get hang, and could be able to reset the picaxe within a period of time.
Does any PIC have this feature ?
 

Matt_C

Member
Why does the PICAXE hang?
Unless by design I can only think a PICAXE would hang due to errors in the program, wrong electrical connections, interferance or a faulty PICAXE.
 

kakolon

Member
Yes, I agree. The problem is electrical, but it's getting very hard to solve, so if the picaxe could reset if there where no activity then it could buy me some time.
Thanks
 

Matt_C

Member
Can you post a circuit diagram and maybe myself or others could see the fault?
If the PICAXE is crashing then it may only be a matter of time before it goes pop and if it's a project that's left unattended then you could have a fire hazard!
 

BeanieBots

Moderator
The "fault" should indeed be cured rather than worked around.
However, it is indeed recognised that a micro can hang for inexplicable reasons which is why watchdogs exist.
An internal watchdog would be be of no use because it would be part of the very device you are "watching". An internal watchgog is only of use for catching hung software (caused by a bug) rather than a hung micro caused by an EMI pulse or similar. It MUST be external to do its job properly.
The simplest is a counter with the MSB connected to the PICAXE reset pin.
The counter reset pin should be capacitively coupled to an output with a pull/up down resistor to hold OFF reset. Then only pulses can ever reset it. A steady state cannot cause a reset. It will also require a free running clock but many counters have a 'spare' inverter stage for making such clocks.
 

hippy

Technical Support
Staff member
There's no reason a PICAXE should "randomly hang" other than because of a coding or code design error, and if it's anything other than that a watchdog may be of very little use.

You really need to try and determine what is causing the hanging.
 

kakolon

Member
Hi, thanks for all responses and sorry for my delay in the response.

I'll start posting the code I use, maybe there is something there..... in the meantime I'll draw my circuit so I can post it.

Code:
setfreq m8
write 20,"1"

'blank stored numbers
for b0 = 1 to 18
write b0,"0"
next b0


main:
'Wait till receive barcode from barcode scanner
serin 1,N4800,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12


goto ticket_ok


'check for four fixed digits to know its my codebar
ticket_ok:
if b8="3" and b9 = "7" and b10 = "0" and b11 = "0" then 
goto  check1 'if its my codebar then go check
else
goto main
end if


 'This routines compares the received number with the last 3 saved numbers, if its different then it opens door

check1:

read 1, b13
if b13 <> b1 then goto check2
read 2, b13
if b13 <> b2 then goto check2
read 3, b13
if b13 <> b3 then goto check2
read 4, b13
if b13 <> b4 then goto check2
read 5, b13
if b13 <> b5 then goto check2
read 6, b13
if b13 <> b6 then goto check2
goto main


check2:

read 7, b13
if b13 <> b1 then goto check3
read 8, b13
if b13 <> b2 then goto check3
read 9, b13
if b13 <> b3 then goto check3
read 10, b13
if b13 <> b4 then goto check3
read 11, b13
if b13 <> b5 then goto check3
read 12, b13
if b13 <> b6 then goto check3
goto main


check3:

read 13, b13
if b13 <> b1 then goto open
read 14, b13
if b13 <> b2 then goto open
read 15, b13
if b13 <> b3 then goto open
read 16, b13
if b13 <> b4 then goto open
read 17, b13
if b13 <> b5 then goto open
read 18, b13
if b13 <> b6 then goto open
goto main

'flahs led and open door
open:
high 4
high 5

pause 4000
low 4
low 5
gosub save 



'if the number was succesfull then save it 
save:
read 20,b13
select case b13

case "1"
b0 = 7
write 20,"2"

case "2"
b0 = 13
write 20,"3"

case "3"
b0 = 1
write 20,"1"


end select


write b0,b1
gosub sum_b0
write b0,b2 
gosub sum_b0
write b0,b3
gosub sum_b0
write b0,b4
gosub sum_b0
write b0,b5
gosub sum_b0
write b0,b6

goto main

sum_b0:
b0 = b0 +1
return
 

kakolon

Member
I'll quickly explain what the code do.
It is a code that will read barcodes, and determine if it is OK to open a barrier.
The first thing is to check if the barcode has 4 fix numbers, that tell me if it is my codebar and not the codebar of a cereal box.
The second check, verifies that the new barcode is'nt the same as the last 3 saved codebars, if it isn't the same, then it opens the barrier and then it saves the codebar in the firs position.
If the codebar is already saved in either of the 3 positions, then it does nothing.
 

hippy

Technical Support
Staff member
- gosub save
-
- 'if the number was succesfull then save it
- save:

I bet that "gosub" is causing a problem.
 

Matt_C

Member
I had a little play with your code and made some changes that gives you over 100 bytes back.

I've commented out some sections that I thought could be optimised for space.

Code:
	setfreq m8
	write 19,"1"
	
	'blank stored numbers
	for b0 = 0 to 17
	write b0,"0"
	next b0
	
main:
	'Wait till receive barcode from barcode scanner
	serin 1,N4800,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12
	
	'goto ticket_ok
	
	'check for four fixed digits to know its my codebar
	'ticket_ok:
	if b8="3" and b9 = "7" and b10 = "0" and b11 = "0" then goto check1
	'goto  check1 'if its my codebar then go check
	'else
	'goto main
	'end if
	goto main

'This routines compares the received number with the last 3 saved numbers, if its different then it opens door
check1:
	for b0 = 0 to 5
	read b0, b13
	lookdown b0,(b1,b2,b3,b4,b5,b6),b7
	if b13 <> b7 then goto check2
	next b0
	
	'read 1, b13
	'if b13 <> b1 then goto check2
	'read 2, b13
	'if b13 <> b2 then goto check2
	'read 3, b13
	'if b13 <> b3 then goto check2
	'read 4, b13
	'if b13 <> b4 then goto check2
	'read 5, b13
	'if b13 <> b5 then goto check2
	'read 6, b13
	'if b13 <> b6 then goto check2
	goto main

check2:
	for b0 = 6 to 11
	read b0, b13
	lookdown b0,(0,0,0,0,0,0,b1,b2,b3,b4,b5,b6),b7
	if b13 <> b7 then goto check3
	next b0
	
	'read 7, b13
	'if b13 <> b1 then goto check3
	'read 8, b13
	'if b13 <> b2 then goto check3
	'read 9, b13
	'if b13 <> b3 then goto check3
	'read 10, b13
	'if b13 <> b4 then goto check3
	'read 11, b13
	'if b13 <> b5 then goto check3
	'read 12, b13
	'if b13 <> b6 then goto check3
	goto main

check3:
	for b0 = 12 to 17
	read b0, b13
	lookdown b0,(0,0,0,0,0,0,0,0,0,0,0,0,b1,b2,b3,b4,b5,b6),b7
	if b13 <> b7 then goto open
	next b0
	
	'read 13, b13
	'if b13 <> b1 then goto open
	'read 14, b13
	'if b13 <> b2 then goto open
	'read 15, b13
	'if b13 <> b3 then goto open
	'read 16, b13
	'if b13 <> b4 then goto open
	'read 17, b13
	'if b13 <> b5 then goto open
	'read 18, b13
	'if b13 <> b6 then goto open
	goto main

'flahs led and open door
open:
	high 4
	high 5
	pause 4000
	low 4
	low 5
	'gosub save 
	
	'if the number was succesfull then save it 
	'save:
	read 19,b13
	select case b13
		case "1"
			b0 = 6
			write 19,"2"
		case "2"
			b0 = 12
			write 19,"3"
		case "3"
			b0 = 0
			write 19,"1"
	end select
	
	for b7 = 0 to 5
		lookdown b7,(b1,b2,b3,b4,b5,b6),b8
		write b0,b8
		inc b0
	next b7
	
	'write b0,b1
	'gosub sum_b0
	'write b0,b2 
	'gosub sum_b0
	'write b0,b3
	'gosub sum_b0
	'write b0,b4
	'gosub sum_b0
	'write b0,b5
	'gosub sum_b0
	'write b0,b6
	goto main
	
'sum_b0:
	'b0 = b0 +1
	'return
I also removed your GOSUB's and an un-needed GOTO.
Just to highlite one possible problem. You have the following line -
Code:
if b8="3" and b9 = "7" and b10 = "0" and b11 = "0" then goto check1
Is the value that is being returned from your hardware numeric or text?
It's just that your line is checking for text.
The character "3" has a decimal value of 51, "7" has a decimal value of 55 and "0" has a decimal value of 48.
So if you are checking for decimal values then just remove the quotes from this line.
 

Matt_C

Member
BTW if you are needing to test decimal then you need to remove the quotes from the values in the WRITE commands too.
 

Technical

Technical Support
Staff member
gosub save

save:
...
return

As Hippy says, gosub save, do the save routine, return to the line below.

Line below is actually fall into save again, do the stuff again, then error (stack crash) when trying to process a return that is not associated with a gosub.
 

hippy

Technical Support
Staff member
Thanks Technical for filling in.

The Save routine also isn't a subroutine ( no return at its end, there's a goto main instead ) so something is likely to fall over at some point.
 

jglenn

Senior Member
PICs have watchdogs, why not PICAXE's?

I am just getting into the PICAXE, over here in the USA (Ohio) I read with interest several articles in Nuts and Volts mags on it. My primary experience is with assembly and PICS. They have a separate watchdog timer you can set, a CLRWDT command must be executed periodically or it will reboot.

Many over here are interested in the 'AXE, as Basic Stamps are much more expensive, and although many "real" programmers look down on basic, I do not, as C is too complex for me. Things like serial comm, etc are a pain in assembly.

Is the PICAXE derived from the Stamp or is it totally different? Depending on who you ask, the Stamp has a watchdog. Parallax says the interpreter will reboot in about 2.3 sec if it crashes. But Phil Anderson (a university type supplier here) says this:

Lack of Watch Dog Timer.

Another disadvantage in using the Stamp is the lack of a watch dog timer. Thus, if it goes into "never never land" it will most probably stay there. However, this really is not a disadvantage in applications where the Stamp is "reset driven". This an operator may push a button or a master processor may reset the slave Stamp which may read its task, do the task, and report back with lamps or serial data. I would hesitate to use it in applications where it is operating independently over long periods of time without using an outboard watch dog timer.

http://www.phanderson.com/stamp/commercial.html

So I am even more confused now! :eek:

Raw PIC watchdogs are very useful. Many of my solutions are used in industrial systems where specialized/expensive/dangerous eqpt is being run, such as a 200HP natural gas engine driven compressor I worked on. Electrical noise coming in I/O lines, the ground, or 5V can cause crashing or bizarre behavior. This customer had 4 machines supplying compressed air to a steel mill, and DID NOT want the units to stop. But if the chip rebooted, it would return to the start sequence, and halt the engine. We fixed it by putting an "engine run" sensing routine at the beginning, to force it into the run loop if it crashed.

But........bad software or marginal timing or funny I/O or whatever is NOT the only thing that can crash ANY computer, electrical noise coming in the wiring or even airborne RF can do the same thing. Some people even put the computer in a sealed metal box with a battery, and optoisolate all the I/O.
Military devices use ferrite chokes where leads enter, and cap bypass right to the case.

So anyway, if the PIXAXE does not have a watchdog, why did they waste the one that comes with every PIC chip?
 

leftyretro

New Member
I am just getting into the PICAXE, over here in the USA (Ohio) I read with interest several articles in Nuts and Volts mags on it. My primary experience is with assembly and PICS. They have a separate watchdog timer you can set, a CLRWDT command must be executed periodically or it will reboot.

Many over here are interested in the 'AXE, as Basic Stamps are much more expensive, and although many "real" programmers look down on basic, I do not, as C is too complex for me. Things like serial comm, etc are a pain in assembly.

Is the PICAXE derived from the Stamp or is it totally different? Depending on who you ask, the Stamp has a watchdog. Parallax says the interpreter will reboot in about 2.3 sec if it crashes. But Phil Anderson (a university type supplier here) says this:

Lack of Watch Dog Timer.

Another disadvantage in using the Stamp is the lack of a watch dog timer. Thus, if it goes into "never never land" it will most probably stay there. However, this really is not a disadvantage in applications where the Stamp is "reset driven". This an operator may push a button or a master processor may reset the slave Stamp which may read its task, do the task, and report back with lamps or serial data. I would hesitate to use it in applications where it is operating independently over long periods of time without using an outboard watch dog timer.

http://www.phanderson.com/stamp/commercial.html

So I am even more confused now! :eek:

Raw PIC watchdogs are very useful. Many of my solutions are used in industrial systems where specialized/expensive/dangerous eqpt is being run, such as a 200HP natural gas engine driven compressor I worked on. Electrical noise coming in I/O lines, the ground, or 5V can cause crashing or bizarre behavior. This customer had 4 machines supplying compressed air to a steel mill, and DID NOT want the units to stop. But if the chip rebooted, it would return to the start sequence, and halt the engine. We fixed it by putting an "engine run" sensing routine at the beginning, to force it into the run loop if it crashed.

But........bad software or marginal timing or funny I/O or whatever is NOT the only thing that can crash ANY computer, electrical noise coming in the wiring or even airborne RF can do the same thing. Some people even put the computer in a sealed metal box with a battery, and optoisolate all the I/O.
Military devices use ferrite chokes where leads enter, and cap bypass right to the case.

So anyway, if the PIXAXE does not have a watchdog, why did they waste the one that comes with every PIC chip?
I know where you are coming from. I worked for several decades in an oil refinery where they had tons of 'mission critical' control systems where failures could cause millions of $$ of downtime per day. Much time and expensive went in to ensuring that such systems were as fault tolerant as possible.

Most systems were very expensive industrial rated PLCs and Distributed Control Systems. External watchdog timers were the only accepted method of protection for detecting failures in such hardware or software systems. Internal watchdog timers, even if available would not be utilized without also the additional protection offered by external watch dog timers. In some designs a failure in one system would allow the external watchdog circuit to switch a redundant system on-line. Much cost would go into failure detection and automatic redundancy as well as in the basic control system.

So I can't answer your question about if a Picaxe has access to the underlining Pic's WDT or not. Possibly some peeking and poking folks could figure out a way to do it? If not, it certainly wouldn't take much to have a dedicated Picaxe 08M act as an external WDT for another Picaxe what was performing some critical or long term task.

Lefty
 

hippy

Technical Support
Staff member
Is the PICAXE derived from the Stamp or is it totally different?
The original PICAXE started very similar to the BS1 but the range has diverged considerably as it has expanded. The Basic programming language is very close but PICAXE Basic supports a lot of things like IF-THEN-ELSE and conditional compilation.

Depending on who you ask, the Stamp has a watchdog. Parallax says the interpreter will reboot in about 2.3 sec if it crashes. But Phil Anderson (a university type supplier here) says this:

Lack of Watch Dog Timer.

Another disadvantage in using the Stamp is the lack of a watch dog timer. Thus, if it goes into "never never land" it will most probably stay there.
There is a watchdog within the PICAXE but ( assuming it is implemented to do so ) it guards the Firmware rather than your downloaded user program. It is also used for timing control in NAP and SLEEP commands.


So anyway, if the PIXAXE does not have a watchdog, why did they waste the one that comes with every PIC chip?
It's not wasted, just used in a different way than it could be. There's only one watchdog available and it's not necessarily easy to use that for two different purposes, Firmware and user program.

It is possible, but that introduces some Firmware overhead and there's unlikely the unused code space to allow that except on the X1 where watchdog functionality can be achieved.
 

demonicpicaxeguy

Senior Member
Many over here are interested in the 'AXE, as Basic Stamps are much more expensive, and although many "real" programmers look down on basic, I do not, as C is too complex for me. Things like serial comm, etc are a pain in assembly.

So anyway, if the PIXAXE does not have a watchdog, why did they waste the one that comes with every PIC chip?

if you look at what most of the basic compilers spit out and the c compilers spit out in terms of asm code for the pic there usaully isn't usaully much difference ,

you generally get from the compiler what you'd normally do in asm by hand only it's formatted consistantly and you save large amounts of time debugging a sub that could be a few hundred lines long by using pre written and tested subs

as for the watchdog timer on the picaxe's , chances are it's not used at all , bear in mind that also executing "clrwdt" takes 200ns at 4 mhz, doing that as trivial as it is takes up more time and program space and when you're trying to write an interpreter using as little space as possible and trying to make it as quick as possible clrwdt instructions everywhere just aren't welcome

implementing somting like a watchdog timer for the picaxe shouldn't be too hard with another small pic and two io pins,
 

hippy

Technical Support
Staff member
many "real" programmers look down on basic, I do not, as C is too complex for me
Those who look down on Basic are the ones who often have little right to call themselves "real programmers"; a "real programmer" IMO recognises the value of using the right tool for the job, the ease of use and everything which goes with it. That doesn't mean that Basic is the right tool for all jobs or there aren't better tools available but it doesn't mean it's the wrong tool either.

Those who say their preferred programming language is the be all and end all of it can usually be safely ignored; don't get tainted by their ignorance and refusal to have open minds. It's also rarely worth arguing with them because they've made their minds up no matter how wrong they may actually be. It's usually about them "being right" and "everyone else is wrong" mentality than anything else; simple prejudice and bigotry.
 

jglenn

Senior Member
here's my reply, you don't have to copy and paste the whole thing in response!

Lefty: Ha, I could tell you several stories of how simple software errors or mechanical glitches such as a broken microswitch have killed people. Using a CPU to control complex machinery where lots of high energy events are occuring rapidly can be treacherous. I did a lot of work with medical X-ray units in the past, when you shoot a high voltage shot of 150KV at one amp tube current, it can arc over, sending transients back into the control circuit and smoking out parts. Time to get out the soldering iron.

I was just pondering the 2.3 sec watchdog which I guess is in the PICAXE (hippy, what do you mean it has to be "Implemented to do so"?). Is there a command or directive you put in your program? A lot of evil can happen in the 2.3 seconds when your system is "out of control". Perhaps we should also study the rapidity of various watchdog implementations. It looks like an external one may be desired. Have not gotten to try my 18X and 08 eval boards yet, have the programming software loaded, will be getting to soon. I have a couple projects I want to do with the AXE!

Dual redundancy is another way critical systems are protected. Like our flying brick SPACE SHUTTLE, the darn thing has 5 computers that evidently vote for what action to take, including shutting off one of them if they get belligerent.
Sort of like an onboard moderator. I've tinkered with some controls in weapons, mostly electronic, but some have motor drives that enabled switches. In one case you have 2 motors, but there has to be a clutch for each one. What if one seizes? Cannot let it lock up the final drive. One could apply this concept in electronics by using FETs or relay contacts to disconnect one control circuit and enable another, preventing the failed circuit from interfering with the good one.

Hippy/Demon: I don't really know any software snobs, but some heavy duty C types seem to look down on basic, considering it wordy. With C and perhaps some assembly snippits for speed, you can do just about anything. I guess object oriented programming might be above that. Basic is fine with me, I am especially interested in the flowcharting capability, as it should generate documentation which is normally sorely lacking in my machine code scrawlings.

In our only hobby electronics magazine left, Nuts and Volts, some rave about the PICBASIC PRO compiler for pics. Cost a few bucks, though. A very interesting article was in the April 2007 issue, by Chuck Hellebuyck.

He compared several pic implementations, some compiled C and basic, with a benchmark simple looping test program, for execution speed. Here is the results:

PICAXE 28X @ 4 MHZ 368 mS

BASIC STAMP2@20MHZ 278 mS

BASIC ATOM@20MHZ 68 mS

PICBASIC IN 16F876@4MHZ 28 mS

PICBASIC PRO,16F876@4MHZ 1.76 mS

PICBASIC PRO,16F876@20MHZ 0.350 mS

PICC-LITE IN 16F877@4MHZ 3.60 mS


This program just flashes a led and loops. PICbasic can handle 2K programs, but the PRO version can handle 128K, pretty huge, with the chip specified.

He did have an error, it was addressed in the June 2007 column:

I did a simple for-next loop that contained 255 iterations, and within that loop I processed a simple math equation to increment a variable. I toggled a pin outside the loop so I could measure the processing time on a scope. Several c programmers pointed out an error. I declared two "int" variables in the c compiler version of the speed test code. INT creates a 16 bit variable in the c program, in the basic programs I declared 8 bit variables. This affected the speed results.

He also had another bug involving a variable changing from 255 to 256.
After fixing these it turns out that the PICC-LITE C compiled program is actually faster than the PICBASIC PRO program, BY 460 uS. It won the contest at 1.3 mS.

So all compilers may not generate exactly the same results. I myself do not have any high speed applications at this time, not really worried about pushing the PICAXE into overdrive, but these comparisons are interesting.

Demon: a raw pic running at 4 MHZ executes most instructions a 1 uS, like NOP, CLRWDT, INC. Branch instructions like JMP take 2 uS.

In fooling around with a 4 MHZ raw pic, I made a servo controller that has 255 output steps, a few more than the PICAXE servo command (ya might need a digital servo to fully exploit the extra resolution). The high speed of the fastest pic branch enables this (decrement and test in one instruction, cool). The loop time is 3 uS. This might be used with an a/d pic and accelerometer for a model plane wing leveling system. Man, I have a lot of projects to get to. Work on generator controls full time. Need more than 24 hours in a day!

Here is the last Nuts and Volts article ref to blow your mind. August 2007, article titled: REWRITING C IN PICBASIC PRO. Wild and crazy stuff.....

:D:D
 

hippy

Technical Support
Staff member
I was just pondering the 2.3 sec watchdog which I guess is in the PICAXE (hippy, what do you mean it has to be "Implemented to do so"?). Is there a command or directive you put in your program?
The watchdog is used in the PICAXE, but how it's used exactly isn't clear or been stated by Rev-Ed. I know it's used in timing commands, but whether it's used to rescue crashed / hung Firmware I don't know. That would depend upon Rev-Ed's implementation. I expect it does but one would have to be able to crash the Firmware to prove it :)
 

Technical

Technical Support
Staff member
... A very interesting article was in the April 2007 issue, by Chuck Hellebuyck.

He compared several pic implementations, some compiled C and basic, with a benchmark simple looping test program, for execution speed. Here is the results:

PICAXE 28X @ 4 MHZ 368 mS
BASIC STAMP2@20MHZ 278 mS
BASIC ATOM@20MHZ 68 mS
...
Already well discussed on this forum - hardly a fair test as he was running the 28X at 4MHz instead of the max supported (16MHz) - ie divide the PICAXE result by 4 for a fairer comparison . A 28X1 could be run at 20MHz...

All PICAXE chips run the internal watchdog that will reset an active chip 2.3 seconds after no internal processing. The watchdog is also used in some commands such as sleep and nap. However remember the firmware could be processing commands that do nothing e.g. a loop to the same line or similar, this will not cause a timeout.

However, as Beaniebots highlighted earlier, the PICs internal watchdog is only good for software issues whilst the PIC is active anyway. The internal watchdog uses a separate internal timer to operate. If the PIC is completely 'hung' (ie doing nothing at all) the internal timer will not operate either, so it does not get to count up to 2.3seconds as the internal timer is not running!

A brownout/over voltage zap is a different situation to the situation requiring an internal watchdog. That is why a brownout circuit and/or external watchdog is far more important that the internal watchdog (which is already active on PICAXE anyway!).

The only way to disable the internal watchdog is via a 'hibernate' command. But it will then be reset when hibernation is over anyway.
 
Last edited:

jglenn

Senior Member
mycroft:

One of my points is just that it is good to be aware of speed of the PICAXE compared to other chips and software systems. Not picking on it for speed at all, the tester should have used the 16MHZ version. It must be because it is interpreted that slows things down. The PICAXE has so many other advantages that it is certainly useful for hobby and some industrial applications. It's low cost certainly blows away the original Stamp!

Technical said:

The internal watchdog uses a separate internal timer to operate. If the PIC is completely 'hung' (ie doing nothing at all) the internal timer will not operate either, so it does not get to count up to 2.3seconds as the internal timer is not running!

I THINK there is a misconception here! The watchdog is an OSCILLATOR, not a timer in all pic chips. It is free running completely independent of the cpu. If the software hangs, assuming the WDT has been made active, and CLRWDT inst are executed frequently to prevent reboot, IT WILL ALWAYS
cause reboot and save the program from getting lost, stuck, or whatever.

I don't mean to rant so much about raw pic chips, so will shut up about them.
It's just that they are all I have used for a long time, after the Fairchild F8, RCA cosmac 1802 (ok, who remembers those?), and a little motorola work.
We use Freescale chips at my full time job.

Again, sorry if any comments I made were misunderstood, I am looking forward to using the PICAXEs for some projects, and am in awe of the large crowd over in Europe employing them, along with this forum. I've scanned quite a few threads and gotten plenty of ideas from them.
 

hippy

Technical Support
Staff member
It's just that they are all I have used for a long time, after the Fairchild F8, RCA cosmac 1802 (ok, who remembers those?), and a little motorola work.
The happy days of original microcomputers ( no microcontrollers then ) which cost an arm and a leg ( and maybe someone else's too ) and another slice of body to get 16 x 4-bit of memory :)

My first job was with 6800, eventually moving to the superior 6301. Never did get to use a 6809, and unfortunately missed out on using the MC14500, a one-bit computer ( more bit-slice I suppose ) ... http://freenet-homepage.de/dieter.02/m14500.htm
 

Mycroft2152

Senior Member
Yes, JG, there are a lot of "old kids on the block" here on the PICAXE forum. We like the simplicity and power of the PICAXE and enjoy bringing along the new users.

Most of the time, we do keep our ego's in check...

My firsdt copmputer....I just missed out buying a MITS Altair 8080, instead I bought the Commodore KIM (Keyboard Interface Monitir). I think it was $400 in 1975 dollars! It was 6502 based with a whole 1K of memory. There was a hex keypad and a six digit hex display and programs were stored on a tape recorder. You had to build the interface and power supply yourself. Programming was done in assembly language.

I bought used hand teletype machine and used that for a printer!

Just amazing for the time and a lot of fun. http://www.commodore.ca/products/kim1/mos_kim1.htm

My point is, don't be fooled by the novice questions you see here on the forum. There is a wealth of experience that us old farts are sharing.

Myc
 

Technical

Technical Support
Staff member
mycroft:
The watchdog is an OSCILLATOR, not a timer in all pic chips. It is free running completely independent of the cpu. If the software hangs, assuming the WDT has been made active, and CLRWDT inst are executed frequently to prevent reboot, IT WILL ALWAYS
cause reboot and save the program from getting lost, stuck, or whatever.
This is a misconception that people make about the internal watchdog. Yes it does run on a separate internal oscillator, and can have a prescalar allocated to it.

But the main purpose of the watchdog is to protect against software errors when the code gets into a loop where a clrwdt is not issued regularly e.g. an assembler coding bug when program jumps to the wrong memory page.

There can be very rare conditions (on under voltage brownout etc), as we tried to explain earlier, when even the watchdog timer oscillator stops oscillating. The chip will then not reset - any internal watchdog is never 100% reliable!
 

moxhamj

New Member
I'm a bit paranoid about failure modes in mission critical situations. Consider the space shuttle, which has 3 seperate CPUs all running independently and two of which have to agree on an output before a decision is made. Microprocessors can and will fail in spectacular fashion. Consider a system built by "experts", the USB comms system in a PC. Have a read of this thread http://forums.techguy.org/windows-nt-2000-xp/582627-usb-suddenly-not-working-usb.html#post5218246 and scroll down a bit for a solution I found - pull out the power plug to fix a major computer fault. This is a design error of the first order and while it may be fine for computers I would not be happy if this was the system guiding me into orbit!

Being a medical doctor, I have tried to consider microcontrollers as devices that are somehow "alive". A MCU can fail with an output either high or low, but it is very unlikely to fail with an output that pulses at, say, 100Hz. So put a band pass filter on a pin and convert that 100Hz into a voltage and detect that voltage with a circuit made of highly reliable discrete components (eg a 555 or an op amp) and use that circuit to reset the picaxe/MCU if the pulses fails to arrive. There are a number of fairly standard "missing pulse" detectors built around a 555 that can do the same task.

I've built watchdog circuits out of components that cost less than $2 - please let me know if you want some pointers.

Re Mycroft/Hippy and 6800s, my first MCU was the Z80. Back then 6800s wouldn't even talk to Z80s - all a bit silly really. And fortunately for the younger generation, Picaxe reunites all into one big happy family!

Time to shuffle off to the nursing home... :(
 
Last edited:

papaof2

Senior Member
Hmm, a Z80, must have been one of the Sinclair's ZX81 or Spectrum!

Another great little machine of its time!
That brings back memories ;-)

I had a much-hacked ZX80 with a 14 pin socket for plugging in an external keyboard (one of the ultra-reliable ring-magnet-around-a-reed-switch versions) that was 3 times the size of the ZX80 and my own expansion bus with a whopping 2K of static RAM and a PIO chip to drive a Radio Shack LP VII parallel printer. I had hand-coded assembly functions to print a string or the screen.

Printing with a PICAXE is easier - just connect an under $20US Sipix A6 printer via serial.
http://www.geeks.com/details.asp?invtid=PPA6-BLU&cat=PRN

Since the Sipix can run on batteries (4 AA cells) or AC, it's a good match for the PICAXE.
Paper for the Sipix is usually available from the vendors that still have them, but you can probably find it cheaper on Ebay.

John
 

hippy

Technical Support
Staff member
I'm a bit paranoid about failure modes in mission critical situations. Consider the space shuttle, which has 3 seperate CPUs all running independently and two of which have to agree on an output before a decision is made.
Beyond there being three CPU's there should also be three programs all written by entirely independent teams so they hopefully do not produce the same bugs as each other, and that can extend to there being three entirely different CPU types on different motherboards with separate power supplies so they don't all exhibit the same faults.

That's a massive scaling of effort and cost. And there will still always be some weak point. Get the software specification wrong and each team will dutifully design their own perfect but flawed implementations.
 

jglenn

Senior Member
The Z80 cpu came out in about 1976 from Zilog. It's claim to fame was 2 completely separate sets of registers that could be swapped with one command.

Hippy: I remember the bit slice concept, make any cpu word size ya want, heck, wasn't 16 bit enough for almost anything? Bit slice seems to have gone the way of magnetic bubble memories and tunnel diodes.

Croft: The MITS altair came out just as I graduated and headed off to new mexico for some work for the gov. I was not fond of computers at that time as I had a foreign instructor who would just draw part of the guts of an IBM 360 on the board and rap about it in undecipherable jabber. So on my first job I thought I was safe until the boss walked up with a microcomputer, 1802 dev sys, and Hazeltine terminal, and said to hook them up and start programming! Wow, I almost went back home. But after a month I was running some safety switches, when I got the clearance wrote some code for secret switches involved in arming things. Lots o fun.

Technical: yep, less than 4V will wipe out a lot of chips. Some people like to use reset chips that sense when the 5V goes too low.

I plan on trying some watchdog eval tests on the picaxe soon, to see exactly what happens if it can be enticed to crash. One way is a brief power interruption, our eng here also says to try a radio xmtr. I have a 7W homebrew 27 mhz tracking xmtr that should work. Will post anything useful I find.

Dr. Acula: come on now, chips are not life forms! Unless perhaps neural networks! Your idea is unique of an ac signal sensing WD trigger.

Someone here did mention the overhead time of WD housekeeping in an add on scheme for the picaxe. Each instruction takes precious time, too bad a pure hardware solution is not possible, maybe it is. One of my apps is a special purpose data logger, for sure I don't want it to crash, or if it does, start up again.

A "crazy" idea might be a dual cpu system, where each one watches the other. If one crashes, the other could step in to seamlessly provide operations until the other has rebooted. Sounds complex and expensive, but in some cases might be worth it.
 

hippy

Technical Support
Staff member
Hippy: I remember the bit slice concept, make any cpu word size ya want, heck, wasn't 16 bit enough for almost anything? Bit slice seems to have gone the way of magnetic bubble memories and tunnel diodes.
My first mainframe use was a DECsystem-10, 36-bit architecture with two 18-bit half-words. I think the world only went away from wider systems because it was just too expensive when micros first came out, these days everything is heading towards 32-bit. I have to admit that it's just so much easier.

I'm reserving judgement on the new Microchip PIC32MX's. They've bought in a 'core' and have gone off at a tangent again from what one would call a traditional PICmicro instruction set and architecture. Some nice things in it though.

I've still got some Am2900 bit-slices somewhere which I keep thinking I ought to do something with.
 
Top