The Unidrive M onboard program can use two tasks:
• | A Freewheeling task |
The Freewheeling task is called repeatedly in a background thread on the drive. When the task completes execution, the task will be executed again. This process will be repeated while the user program is running. The rate at which the task is called is non-deterministic.
• | A Clock task |
The Clock task is called at a regular rate. The code placed in the Clock task must complete execution within a single scheduling period. For example, if the Clock task is set to execute once every 8ms, a single scan of the task must complete within 8ms or a run-time error will occur, the drive will be tripped (trip 249, sub-trip 40) and the user program will stop.
Note: Do not code an infinite loop into either the Freewheeling or Clock tasks. Both tasks should run to completion. In the case of the Clock task, the task will be executed repeatedly by the drive at the requested rate; in the case of the Freewheeling task, the drive will repeatedly call the task giving the effect of a continually running piece of code without the user needing to implement any loops.
Figure 7 below demonstrates the behavior of the two tasks in the Unidrive M Onboard target controller. The Clock task is a high priority real-time task, and the Freewheeling task is a non-realtime background task.
Note: When the user program begins execution, the Freewheeling task completes one scan BEFORE the Clock task runs for the first time (if present).
As described above, the user has the ability to set the Clock task interval (shown as tcti in the diagram below). When the system starts running, the Clock program will begin running, and must run to completion within the tcti period. If the Clock program does not complete within the tcti period, a runtime error will occur.
If the Freewheeling task is executing when the Clock task is due to run, the Freewheeling task will suspended. On completion of the Clock task, the Freewheeling task will continue execution from the point where it was suspended until the Clock is ready to run again.