Data Sheet
MicroBasic Scripting
194 Advanced Digital Motor Controller User Manual V1.8, August 28, 2017
top
Initialization Steps
Process Events
Time, Input or
Controller events
Wait
Y
N
Start
FIGURE 18-2. Continuous execution scripts
Often, some actions must be done only once when script starts running. This could be
setting the controller in an initial configuration or computing constants that will then be
used in the script’s main execution loop.
The main element of a continuous script is the scanning of the input ports, timers, or
controller operating parameters. If specific events are detected, then the script jumps to
steps related to these events. Otherwise, no action is taken.
Prior to looping back to the top of the loop, it is highly recommended to insert a wait time.
The wait period should be only as short as it needs to be in order to avoid using process-
ing resources unnecessarily. For example, a script that monitors the battery and triggers
an output when the battery is low does not need to run every millisecond. A wait time of
100ms would be adequate and keep the controller from allocating unnecessary time to
script execution.
Optimizing Scripts for Integer Math
Scripts only use integer values as variables and for all internal calculation. This leads to
very fast execution and lower computing resource usage. However, it does also cause lim-
itation. These can easily be overcome with the following techniques.
First, if precision is needed, work with smaller units. In this simple Ohm-law example,
whereas 10V divided by 3A results in 3 Ohm, the same calculation using different units
will give a higher precision result: 10000mV divided by 3A results in 3333 mOhm
Second, the order in which terms are evaluated in an expression can make a very big
difference. For example (10 / 20) * 1000 will produce a result of 0 while (10 * 1000)/20 pro-
duces 5000. The two expressions are mathematically equivalent but not if numbers can
only be integers.