Control System Applications (2) Programming Logic Controllers PLCs Lect. 9 Dr. Tarek Ahmed Mahmoud Tarek_momeen@yahoo.com
Outlines Numerical Processing Word Objects Word Format Word Types Numerical Instructions
Word Objects Word Format Word objects are addressed in the form of words of 16 bits Word Format 1 16384 +/- 8192 14 15 Bit position Bit state Bit value 13 2 3 4 5 6 7 8 9 10 11 12 4096 2048 1024 512 256 128 64 32 16 Bit 15 at 0 is a positive value. Bit 15 at 1 the word is a negative value (negative values are expressed in two's complement logic).
Word Format (cont.) Decimal 1579 (max : 32767, min :-32768) Hexadecimal 16#A536 (max : 16#FFFF, min : 16#0000) Alternate syntax : #A536.
Word Types in NANO PLC 1- Immediate values 2- Internal words - They are used to store values during the operation. - They are stored in the data memory. - They are read or written to directly by the program. - They are used as working words. %MW0 to %MW255
Word Types in NANO PLC (cont.) 3- Constant words They store constant values Their contents can only be written or modified in the CONFIGURATION editor. - They are read-only access by the program. %KW0 to %KW64 4- Function Block Words - They are read or modified in the program. - Such as %TMi.P and %Ci.P, %Ti.v, . . . etc.
Word Types in NANO PLC (cont.) 5- System words Words have special functions related to the PLC operation %SW0 to %SW127 %SW30 Shows execution time of the last PLC scan cycle 6- I/O exchange words Words %IW and %QW are used to exchange data between PLCs.
Word Types in NANO PLC (cont.) Bit objects extracted from words % Word object : Xk k = 0 to 15 % MW5:x6 Bit position 6 of internal word %MW5.
Word Types in NANO PLC (cont.)
Numerical Instructions Numerical instructions generally apply to 16-bit words They are written - Between square brackets (instruction list) [ Instruction ] - In a rectangular (in ladder diagram). Instruction
Numerical Instructions 1- Assignment instructions These are used to load operand Op2 into operand Op1 Syntax : [Op1:=Op2] Op1 is a memory word Op2 is a memory word or an immediate value Example LD 1 [%MW10:%MW20] %MW10:= %MW20
LDR %I0.3 [%MW10:=100]
Numerical Instructions 2- Arithmetic instructions + : Add two operands - : Subtract two operands * : Multiply two operands / : Divide two operands SQRT : Square root of an operand INC : increment an operand
- Examples
Numerical Instructions 3- Comparison Instructions > : test if greater than. >= : test if greater than or equal. < : test if less than. <= : test if less than or equal. = : test if equal. <> : test if not equal (different from). The result is 1 when the comparison requested is true.
- Examples
Numerical Instructions 4- Logic instructions AND : AND (bit-wise) between two operands OR : Logic OR (bit-wise) between two operands XOR : Exclusive OR (bit-wise) between two operands NOT : Logic complement (bit-wise) of an operand
- Examples LD %M0 [%MW0 := %MW10 AND 16#FF00] LD %I0.3 [%MW102:= NOT (%MW100)] LD 1 [%MW0 := %KW5 OR %MW10]
Numerical Instructions 4- Shift instructions SHL (op2,i) logic shift of i positions to the left. SHR (op2,i) logic shift of i positions to the right.
Application Automatic Traffic Lights steps green yellow red time 15 sec. 1 4 sec. 2 12 sec. 3 3 sec.