Danaher Motion
06/2005
Error Handling
M-SS-005-03 Rev
E
161
11.2.1. WatchDog
Setup
To set up the MC to enable the WatchDog, follow these steps:
1.
Create a new task solely for the WatchDog. Use BASIC Moves with
File
,
New
.
2
Define a local variable as a
Long
. For the example below, we use
MyVar
.
3
Initialize the WatchDog timer in the main program. Store the return
value of the initialization step in the local variable from Step 1.
4
Write an event inside the task to reset the WatchDog timer. The event is
fired with fast I/O (SYSTEM.VIN.1 to 32).
5
Set the task to run infrequently so it does not consume more
computational resources than necessary. The following example
demonstrates a WatchDog timer task:
Dim Shared MyVar as Long
Program
‘Event which runs once for each WatchDog cycle
OnEvent WDevent System.Vin.1 = 1 ScanTime = 4 ‘Check every 4th cycle
WDCycle(MyVar) ‘Cycle the WatchDog
System.Vin.1 = 0 ‘Reset the WatchDog bit
End OnEvent
EventOn WDEvent ‘Enable the Wdog Event
MyVar = WDInit(5) ‘Set Wdog time for 5 Wdog cycles or 100 ms
WDCycle(MyVar) ‘You must cycle the Wdog once to begin
While 1 = 1 ‘Infinitely loop so event will be active
Sleep 1e6 ‘Use sleep to conserve CPU time
End While
End Program
With this example, the WatchDog must be reset every fifth cycle (every 100
ms) to avoid a fault.
11.2.2. Cycle the WatchDog
The last step in using the MC WatchDog is to issue watch cycle commands
from the host PC. These are issued more frequently than the specified
maximum cycle time in
WDINIT
. For example, if the maximum cycles are
specified as 5 (equivalent to 100 ms), reset the WatchDog every 50 or 60
ms. In Visual Basic, this is as simple as setting the fast I/O to 1 based on a
50 ms timer.
11.2.3. Reset the WatchDog
You can reset the WatchDog directly from the host PC using
WDCYCLE
This is simpler than the method presented above because you need not
generate a task. However, this is not normally recommended because it is
much slower than the fast-I/O method as it requires 15 to 20 ms to pre-
compile commands issued directly from the API to the MC. However, should
you decide to use the direct method, you need only use the following steps
directly from the API:
1.
Create a global variable.
2.
Initialize the WatchDog timer.