Download User Manual - sbc
Transcript
4-9 Saia-Burgess Controls Ltd. 4.2.3 Constants Constants are fixed values that can be used directly, or loaded into registers, timers or counters. Constants can be integer or floating point numbers, e.g. 100. 0.25, or Pi 3.1415. Timers and counters accept only unsigned integer values 0..2,147,483,647. Example The following example loads register R 4 with an integer value (100), which is divided by floating point value (0.25). Because register R 4 contains an integer and we want to divide it by a floating point value, R 4 must first be converted from integer to floating point. First, copy R 4 to R 35 (a work register which we know is not being used) and convert R 35 to a floating point value, then divide R 35 by 0.25 which has been loaded into R 36. The floating point result of the division is put in R 5. R 5 is then copied to R 6 to be converted back to an integer value (some of these steps are not really necessary, they could use the same workspace registers.) Instruction list program: COB 0 0 ;cyclic block LD R 4 100 ;load 100 into R 4 COPY R 4 R 35 IFP R 35 0 ;convert integer R 4 ; to floating point ; in R 35 ; (0 = 10^0) LD ;Load 0.25 into R 36 R 36 0.25 FDIV R 35 R 36 R 5 COPY R 5 R 6 FPI R 6 0 Fupla program: ;divide R 35 by 0.25 ;put result in R5 ;convert result back ; to integer in R 6 ECOB PG5 User Manual I Chapter 4 I PCD Data I 10.12.13 FBox: - Integer, Move - Converter, Int to float - Floating point, Divide - Converter, Float to Int