Knowledge Base

MultiTrack (Advanced): Permitting infinite loops.

If a MultiTrack task executes more than 255 instructions without yielding, the controller will suffer a fatal runtime error. This is a deliberate mechanism designed to prevent you from locking up your program with an infinite loop inside a task. The ClrInstCount instruction resets the counter each time it is executed, effectively defeating the protection mechanism.

Example:

You may have a controller that you want to perform a set of tasks when powered up, but then, once the job is done, go into a dormant state until the next time it is turned off and back on again. The following task could be launched (LaunchTask) by some other task that decides it is time go dormant:

;Go to sleep until powered down and back up
GoodNight:      ClrInstCount
                GoTo          GoodNight

If you attempted that without the ClrInstCount it would fail to work, because after 256 instructions the board would suffer a fatal runtime error, reset itself and run again.

The ClrINstCount instruction is potentially dangerous, for the very reason it can allow you to put the controller to sleep. Use it only if you are very sure of what you are doing.

Note that some of the instructions you may use actually translate into several machine instructions. The 255 instruction limit is machine instructions. Instructions like OBLCD_SetCur are translated by SPLat/PC into several low level instructions.