Repetition
We have already described the following instructions:
- LD (Load) or F5 - normally open contact
- LDI (Load Inverse) or F6 - normally closed contact
- LDP (Load Pulse) or Shift+F5 - positive edge
- LDF (Load Falling Edge) or Shift+F6 - negative edge
- OUT or F7 - coil / output, also start timer immediately & increase counter
- TMR - start timer at the beginning of the next cycle
- SET or F8 - set coil / output
- RST or Shift+F8 - Reset coil / output, also reset timer & counter
- STR, STRR, STRS - commands for precision timer
- CJ (Conditional Jump) - Jump to marker P
- CALL - jump to subroutine P, return by SRET
- FEND (Flow End) - End of the main program
- FOR ... NEXT - counting loop
- SET, ST, STL and STLE - commands for step control via status bits S
- I.., IRET, EI, DI - commands for interrupt control
Further basic operations
The following basic commands complete the basic instructions:
- LDD (Load Direct) - normally open contact that reads the input terminal directly instead of from the memory image like LD
- LDDI (Load Direct Inverse) - normally closed contact that reads the input terminal directly instead of from the memory image like LDI
- OUTD (Out Direct) - sets output directly, instead of output in the memory image like OUT
- ALT (Alternate) - command that toggles a bit
- PLS (Pulse) - positive edge on output
- PLF (Pulse Falling Edge) - negative edge on output
- END - end of the program, useful for deactivating program parts during debugging
The following commands are actually only relevant in IL, as they are implemented graphically in the ladder diagram via connecting lines. They are only listed here for the sake of completeness: AND, ANDD (direct), ANI (And Inverse), ANDDI, ANDP (And Pulse), ANDF (And Falling Edge), OR, ORD, ORI, ORDI, ORP, ORF, ORB (Or Block), MCS (Master Control Start) and MCR (Master Control Return). Further information can be found in the manual.
Comparison operations
The following comparison operations are available:
- LD= Dx Dy - compares two words, example closes if Dx is equal to Dy; instead of D, FD, TD, CD, K etc. can also be compared
- LD> Dx Dy - closes if Dx is greater than Dy
- LD< Dx Dy - closes if Dx is less than Dy
- LD<>Dx Dy - closes if Dx is not equal to Dy
- LD<= Dx Dy - closes when Dx is less than or equal to Dy
- LD>= Dx Dy - closes if Dx is greater than or equal to Dy
Comparison operations are also available as 32-bit operations. The commands DLD=, DLD > etc. compare two consecutive DoubleWords. (In IL, AND=, OR= etc are also available; these links can be described graphically with LD= via ladder diagram).
Data operations
The following data operations (each with the data type of the parameters) are supported:
- CMP Word Word Bit - Data comparison (16 bits) - Example CMP D0 D1 M0 compares D0 and D1 and sets the bits M0, M1 or M2 as follows:
- D0 > D1 then M0 =1
- D0 = D1 then M1 =1
- D0 < D1 then M2 =1
- ZCP Word (lower limit) Word (upper limit) Word (comparison value) Bit (result) - Data zone comparison (16 bits) - Example ZCP D10 D20 D0 M0 checks how D0 relates to D10 and D20:
- D0 < D10 then M0 =1
- D10 <= D0 <= D20 then M1 =1
- D0 > D20 then M2 =1
- MOV Word (source) Word (destination) / DMOV DWord DWord - Move (16/32 bit) Example MOV K20 D0 writes the number 20 to register D0
- BMOV Word (source) Word (destination) Word (length) - Block Move (16 bit) Example BMOV D2 D10 K2 writes registers D2 and D3 to D10 and D11
- PMOV Word (source) Word (destination) Word (length) - faster Block Move (16 bit) same as BMOV only faster
- FMOV Word (source) Word (destination) Word (length) - Fill Move (16 bit) - Example FMOV K10 D0 K5 fills registers D0 to D4 with the number 10
- DFMOV DWord (source) DWord (destination) Word (length) - Fill Move (32 bit)- same as FMOV as 32 bit instruction
- MOV, DMOV, BMOV, FMOV and DFMOV cannot write to the flash memory, for this you use FWRT
- FWRT Word (source) Word (destination) optional Word (length) - Flash Write (16 bit, DFWRT 32 bit), writes to flash registers (flash registers can only be written about 1 million times, this instruction should therefore be used moderately)
- MSET Bit (Start) Bit (End) - Multiple Set Example MSET M10 M15 sets all bits between M10 and M15
- ZRST Bit (Start) Bit (End) - Zone reset Example ZRST Y0 Y5 resets all outputs between Y0 and Y5
- SWAP Word - Exchanges the high and low byte in a word Example SWAP D0 exchanges the first byte in D0 with the second
- XCH Word Word - Exchange (16 bit, DXCH 32 bit) exchanges two words (DWords)
Arithmetic and Boolean operations
The following arithmetic and Boolean operations (each with parameter data type) are supported:
- ADD, SUB, MUL, DIV - basic arithmetic operations (16 bit) each with parameters Word (operator) Word (operator) Word (result)
The result of DIV is a DWord, the first word contains the result, the second the rest - DADD, DSUB, DMUL, DDIV - as above as a 32-bit instruction, note that the result of DDIV is two DWords
- INC, DEC, DINC, DDEC - Increment / decrement (16 bit / 32 bit) - Parameter Word (DWord)
- MEAN Word (source) Word (result) Word (length) - Average (16 bit) - Example MEAN D0 D10 K4 calculates the average of registers D0 to D3 and writes the result to D10
- WAND, WOR, WXOR - Boolean operations (16 bit) Parameter Word (operator) Word (operator) Word (result)
- DWAND, DWOR, WXOR - same as above as 32 bit operation, requires DWords
- CML / DCML - Compliment (16 bit / 32 bit) - converts a register into its complement, all bits are swapped
- NEG - Negation (16 / 32 bit) - negates a number in a register (sign change)
Shift operations
The following instructions are available for shift operations: SHL/DSHL Arithmetic shift left, SHR/SHR Arithmetic shift right, LSL/DLSL Logic shift left, LSR/DLSL Logic shift right, ROL/DROL Rotation left, ROR/DROR Rotation right, SFTL/DFTL Bit shift left, SFTR/DFTR Bit shift right, WSFL/DWSFL Word shift left, WSFR/DWSFR Word shift right. It should be noted that the bit for the transfer is M8022. Further information can be found in the programming manual chapter 4.
Conversion operations
Again, just a simple list. WTD Single Word to Double Word, FLT 16 Bits Integer To Float (16 Bit), DFLT 32 Bits Integer converts Float (32 Bit), FLTD 64 Bits Integer to Float (64 Bit), INT / DINT converts Float to Integer, BIN converts BCD to Binary, BCD converts Binary to BCD, ASCI converts Hex. to ASCII, HEX converts ASCII to Hex, DECO ASCII to hex decoding, ENCO high bit coding, ENCOL low bit coding. Worth mentioning is the possibility of generating 64-bit floating point numbers. However, the following floating point operations only support 32 bit floating point numbers. Further information in the programming manual chapter 4.
Floating point operations
Here is the list of floating point operations. All floating point operations are 32 bit operations. ECMP Float Compare, EZCP Float Zone Compare, EADD Float Add, ESUB Float Subtract, EMUL Float Multiplication, EDIV Float Division, ESQR Float Square Root, SIN Sine, COS Cosine, TAN Tangent, ASIN Arcsine, ACOS Arccos, ATAN arctan.
A detailed description of all commands, their valid memory areas and triggers can be found in chapter 4 of the programming manual.
Exercise
Write the values 10, 30 and 458 to registers D10, D11 and D12 and calculate the average of these values in register D13.