UD70
Issue code: 70nu2
DPL programming 4-17
Integer division
When using integer division, accuracy may be lost in the result, as shown in
the following expression:
If #1.21 is equal to 5
Then we have the following:
a = 4.5 * (#1.21 /4)
= 4.5 * (5 /4)
= 4.5 * 1
= 4.5
The DPL compiler uses an integer divide, converts the result to a
floating-point value and uses a floating-point multiply.
To preserve accuracy, one of the arguments can be converted to a
floating-point variable, as follows:
a = 4.5 * (#1.21 / FLOAT(4) )
= 4.5 * (5 / FLOAT(4) )
= 4.5 * 1.25
= 5.625
See
FLOAT
instruction in Chapter 7 Reference.
PRINT instruction
Do not over-use the PRINT instruction. (See PRINT instruction in Chapter 7
Reference). It is preferable to use the WatchWatch window in the DPL Toolkit to
monitor variables (see Chapter 5 DPL Toolkit).
Use the
PRINT instruction only in the BACKGROUND task. If the PRINT
instruction is included in the SPEED, CLOCK or ENCODER tasks, the PRINT
instruction may have insufficient time to be executed. Text waiting for
printing may not then be printed.
BACKGROUND task
Place as much of the program as possible in the BACKGROUND task rather
than in the SPEED, CLOCK, ENCODER or other real-time tasks. Since the real-
time tasks are on a fixed timebase, the processing must be completed in this
time. The BACKGROUND task does not have this restriction.