Watchdog

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Eric
Posts: 99
Joined: Tue Nov 06, 2007 11:04 pm
Been thanked: 1 time
Contact:

Watchdog

Post by Eric »

Hi Ben,

In the project options of V4 it is possible to mark "auto clear watchdog".
Does this means that Flowcode enters at regular places in the code the function "clear watchdog"?
I noticed that when I set the config bytes of the processor to "enable watchdog" and when I set the marker "auto clear" on, that the wachdog effectively is cleared during execution of the program so that the program kept running. When I unmarked the marker, then the program stopped as expected.
However, looking at the produced C-code, I don't see any code for clearing the watchdog.
Can you explain how this procedure in Flowcode exactly works and how I can influence the timing between 2 watchdog checks?
At this moment it is about 1 second between 2 checks (osc= 8.000.000 Mhz and prescaler set to 128).
How can I make it longer or is this the maximum? ( processor is 18F452 )

Best regards,

Eric

Eric
Posts: 99
Joined: Tue Nov 06, 2007 11:04 pm
Been thanked: 1 time
Contact:

Re: Watchdog

Post by Eric »

Sorry Ben, I posted in the wrong index. Can you please change it to the V4 group?

Thx,

Eric

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Watchdog

Post by Benj »

Hello Eric

The auto clear watchdog function does add the clear_wdt(); C code into your program automatically for you so it should not reset the device unless for some reason the code stops running correctly.

The prescaler can only go up to 128 by looking at the datasheet. I thought there may be another scaler that could be used but it is not available on this device.

The clear watchdog functions are added to the millisecond and second delays and are also added to the delays inside of component macros.

Eric
Posts: 99
Joined: Tue Nov 06, 2007 11:04 pm
Been thanked: 1 time
Contact:

Re: Watchdog

Post by Eric »

Ok, thx.
Something that still puzzles me is the behaviour of the watchdog in a deliberate end loop.
Suppose you have somewhere in your program an error routine like this (just an example):
snap0251.jpg
snap0251.jpg (28.35 KiB) Viewed 4475 times
The intention of this code is to stop the program from continuing in case of a critical error.
However, if the watchdog is on and the program has entered the endless loop in the error routine to prevent it from continuing, than the processor will be reset by the watchdog after some time. The result is that the errormessage is gone and that the errorsituation will repeat itself.

Is there is a possibility to switch the watchdog on and of during program execution?
Or is there a better way to handle this kind of situations?

Rgds,

Eric

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Watchdog

Post by medelec35 »

If it was me , I would place any critical testing like boiler temperature at the beginning of the program E.g A call to macro, as well as in the normal place. That way, If watchdog does reset program to beginning, then first thing program does is recheck the temperature, and shuts down heat power source (Gas electric etc) and displays error. If you have got a microcontroller with EEPROM, then error message then be stored in that as soon as it occurs. Then if watchdog or brownout resets program, then EEPROM contents can be retrieved at the start as well.
Sorry if not much help to you.
Martin

Eric
Posts: 99
Joined: Tue Nov 06, 2007 11:04 pm
Been thanked: 1 time
Contact:

Re: Watchdog

Post by Eric »

Good idea, I will give it a try.
Rgds
Eric

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Watchdog

Post by Benj »

The watchdog timer on a 18F452 is software configurable so if you have is disabled in the chip configuration you can later enable it in software by using the following line of C code.

set_bit(wdtcon, SWDTEN);

if your using v4.2 of Flowcode or later then the command is

st_bit(wdtcon, SWDTEN);

However Medelec's suggestions are probably better as that way the watchdog is always enabled.

Post Reply