User's Manual

Turbo PMAC User Manual
Motor Compensation Tables and Constants 171
Floating-Point vs. Fixed-Point Mathematics
Each statement in the Open Servo can be executed using either floating-point or integer (fixed-point)
mathematics. In a floating-point statement, all variables used are processed through an intermediate
working format that is 48-bit floating-point, regardless of the storage format of the variable. Floating-
point statements can utilize any of Turbo PMAC’s I, P, Q, or M-variables, and the compiler’s long F-
variable pointers. They cannot use the compiler’s short fixed-point L-variable pointers. All constants
used in these statements are stored as 48-bit floating-point values.
In an integer statement, all variables used are processed through an intermediate working format that is
24-bit signed integer, regardless of the storage format of the variable. Integer statements can only utilize
the compiler’s short fixed-point L-variable pointers. They cannot use the compiler’s long F-variable
pointers, or Turbo PMAC’s I, P, Q, or M-variables. All constants used in these statements are stored as
24-bit signed integers. All constants used and intermediate values computed must fit in the range of these
integers: -8,388,608 to +8,388,607. No mathematical functions (e.g. SIN, COS) may be used in an
integer statement.
If a constant appears on a line before any variable (e.g. IF (0=P1) …), the line is assumed to be
floating-point. This means that the statement IF (0=L1) is illegal, because it mixes floating-point and
fixed-point data types.
Short-word integer operations will execute more than 10 times faster than the same operations done as
long floating-point operations, but usually will not have the dynamic range to handle the actual control
calculations. They can be useful for efficient calculation of associated logic, however.
Note:
PMAC’s built-in servo algorithms (PID and Extended Servo Algorithm) use long
[48-bit/56-bit] fixed-point mathematics. This format is not supported in the Open
Servo.
If conversion between integer and floating-point data types is required, Open Servo provides the ITOF
(integer-to-float) and FTOI (float-to-integer) functions. The ITOF function (with an integer expression
as its argument) can be used in a floating-point statement, such as:
P20=ITOF(L10+L11)*3.14159/P628
The FTOI function (with a floating-point expression as its argument) can be used in a fixed-point
statement, such as:
L10=L9+FTOI(P5*100)-5
The FTOI function will round the value of the floating-point expression to the nearest integer.
It is not permissible to nest FTOI and ITOF functions within an expression.
Arrays. Open Servo algorithms support two types of arrays: variable arrays and register arrays. Both
provide useful capabilities.
Variable Arrays: Variable arrays work with the Turbo PMAC’s standard PMAC I, P, Q, and M-
variables. The number of the array index is placed inside parentheses, and specifies the variable number
for the specified type of variable. The expression that determines this number is a floating-point
expression, so it can use Turbo PMAC I, P, Q, or M-variables, constants (which will be treated as
floating-point values) and the compiler’s F-variables, but it cannot use the compiler’s L-variables (unless
the value has been converted to floating-point with the ITOF function). The resulting value of this
floating-point expression is rounded to the nearest integer automatically, to select the variable number to
be used. Some examples of statements using these variable arrays are:
P(P1)=P10*32
P30=I(ITOF(L10)*100+30)*P29