C Control The I Unit-M Advanced 5 Vdc Inputs / outputs 16 x digital I/Os / 8 x analogue or digital I/Os Program memory 2 198805 Datenbogen
Produktcode
198805
Review the sample program 2_FP_CONVERSION
LOOPS WITH FLOAT VARIABLES
FOR TO NEXT loops will not work together with FP variables. This does not matter because it is possible to
use DO LOOP UNTIL and here it is possible to create loops working with all valid floating point values.
DO
. . . . .
. . . . .
LOOP UNTIL (COUNTER>ENDVALUE)
. . . . .
. . . . .
LOOP UNTIL (COUNTER>ENDVALUE)
The end condition may not consist of terms or constants
LOOP UNTIL (COUNTER>123456) is not allowed
Example:
LOOP UNTIL (COUNTER>123456) is not allowed
Example:
'*********************************************************************
'*** LOOP WITH MIT FLOAT VARIABLES ***
'*********************************************************************
COUNTER=123.4567
ENDVALUE=999.567
'---- FOR COUNTER=123.4567 TO 999.567 STEP 0.123 ----
DO
COUNTER=COUNTER+0.123
LCD.POS 1,1
LCD.PRINT COUNTER & " "
LOOP UNTIL COUNTER>ENDVALUE
'*** LOOP WITH MIT FLOAT VARIABLES ***
'*********************************************************************
COUNTER=123.4567
ENDVALUE=999.567
'---- FOR COUNTER=123.4567 TO 999.567 STEP 0.123 ----
DO
COUNTER=COUNTER+0.123
LCD.POS 1,1
LCD.PRINT COUNTER & " "
LOOP UNTIL COUNTER>ENDVALUE
FUNCTIONS WITH PARAMETERS
The function calls are equally done with word or bytes. Parameters may also be mixed types.
FUNCTION MyFunction(FVAL1 as FLOAT,FVAL2 as FLOAT)
. . . . . . .
. . . . . . .
END FUNCTION
. . . . . . .
. . . . . . .
END FUNCTION
Because the memory usage is very intesive, when using float variables it is recommended to use referenced
float values as local variables. This means different variables as here in the example INPUT and WERT
share a memory location (FVALUE in this example).
float values as local variables. This means different variables as here in the example INPUT and WERT
share a memory location (FVALUE in this example).
35
define FVALUE as FLOAT
FUNCTION ABC(INPUT ref FVALUE)
RESULT=RESULT*INPUT
END FUNCTION
FUNCTION XYZ(WERT ref FVALUE)
RESULT=RESULT*WERT
END FUNCTION