Course Computer Based Automation WS 06/07 1 Stephan Simons
Computer Based Automation
Winter Term 06/07 Prof. Dr. Stephan Simons University of Applied Sciences Darmstadt Master of Science in Electrical Engineering Course Computer Based Automation WS 06/07 2 Stephan Simons Contents of the course 1. Introduction to automation systems 2. Fundamentals a) numerical representations, b) logical functions and operations 3. Programmable Logic Controller (PLC) a) basics, b) principle of operation, c) architecture, d) PLC family 4. PLC S7-300 with interface modules 5. Programming of a PLC 1. Overview PLC standard IEC 1131-3 2. Programming Languages for S7 family & program structure 3. Basic operations of STEP 7 in STL, LAD and FBD: Flags, Edge evaluation, Result of logic operation & Status word, Set and reset operations (flip flop), Timer instructions, Counter instructions, Particular instructions 4. Program organization units 5. Sequential Control Language (S7-Graph) 6. Structured Control Language (S7-SCL) 7. Indirect Addressing 6. PLC standard IEC 1131-3
today
Course Computer Based Automation WS 06/07 3 Stephan Simons
Repetition of last lecture Timer functions On delay timer, retentive on delay timer, off delay timer, pulse timer, extended pulse timer (symbols, example programs, timing diagrams, differences FBD, LAD, STL) Setting the timer value as S5-Time or as hexadecimal value Unused inputs and outputs Example for timer functions (oscillator) S7 Counter Up counter, Down counter, Up and down counter (Symbols an program example for LAD, FBD and STL) Overview over counter operations Signal state chart Example for counter usage (frequency divider) Standard data types and their internal representation Load and transfer commands Load and transfer commands in STL; MOVE blocks in LAD & FBD Examples for load and transfer instructions Example loading and transfering an analog value (AI & AO) Course Computer Based Automation WS 06/07 4 Stephan Simons Instruction contents of lecture Bit logic instructions Bit logic instructions with expressions in parenthesize Edge triggered instructions Memory functions: Setting / Resetting bit addresses Timer instructions Counter instructions Load and transfer instructions Comparison instructions Integer and floating-point arithmetic instructions Floating point mathematical instructions Jump instructions
Course Computer Based Automation WS 06/07 5 Stephan Simons
S_ODT
S BI
TV BCD
R Q T1 I0.0 S5T#2S I0.1 MW0 MW2 Q 4.0 A I 0.0 L S5T#2S Load time (2s) in ACCU 1 SD T1 Start timer T1 as a pulse A I 0.1 R T1 Reset timer T1 L T1 Load timer T1 DUAL-coded T MW0 LC T1 Load timer T1 BCD-coded T MW2 A T1 Query of the timer T1 = Q 4.0 S_ODT
S Q
TV BI
R BCD T1 I0.0 S5T#2S MW0 MW2 Q 4.0
( ) I0.1
On-delay Timer FBD LAD STL Course Computer Based Automation WS 06/07 6 Stephan Simons S5-Time If a delay time of 2 hours, 35 minutes, 24 seconds and 60 milliseconds shall be set use the S5 Time: S5T#2h35m24s60ms The possible time range is from 10ms to 2h46m30s with a resolution of 10ms. The S5 time is transferred to the ACCU 1 with the load instruction L. The time is stored into the ACCU 1 as a 16 bit word with the following format: 15 14 13 12 11 8 7 4 3 0 Bit 10 2 10 1 10 0 time base factor for time base in BCD Irrelevant 00 (2) 0 (16) 0,01sec 01 (2) 1 (16) 0,1sec 10 (2) 2 (16) 1sec 11 (2) 3 (16) 10sec Time base: Examples: S5T#3s 2003 (16) or 0300 (16) S5T#100ms 1001 (16) or 0010 (16) S5T#2h46m30s 9990s 3999 (16) As a rule the smallest possible time base is used to achieve a better precision. Course Computer Based Automation WS 06/07 7 Stephan Simons No. STL Comments 1 L 16#1350 // Load time (35s) as hex literal (const.) 2 T MW10 // Transfer to MW 10 3 A I2.1 // Start delay time with positive edge of I2.1 4 L MW10 // Transfer time into ACCU 1. 5 SD T4 // Start timer T4 as an on-delay timer. 6 NOP 0 // Reset 7 L T4 // Load current time value of T4 as binary. 8 T QW4 // Transfer binary current time value to QW4. 9 NOP 0 // Current time value as BCD not used. 10 A T4 // Check signal state (binary output) of timer T4. 11 = Q4.0 // Transfer to Q4.0. Changing the on-delay program: The instructions no. 7 and 8 transfer the current time value of T4 as binary to the output word QW4. The output word QW4 consists of the two bytes QB4 and QB5 QB4 holds the more significant value: QW4 [ QB4, QB5 ] Course Computer Based Automation WS 06/07 8 Stephan Simons Choosing the right timer Course Computer Based Automation WS 06/07 9 Stephan Simons S7 Counter
S_CUD CU
CD
S CV
PV CV_BCD
R Q C1 I0.0 C#5 I0.3 QW2 QW4 Q 0.0 FBD STL A I 0.7 Release (only in STL) FR C1 A I 0.0 CU C1 Count up A I 0.1 CD C1 Count down A I 0.2 L C#5 Load counter with default value S C1 Set counter with default value A I 0.3 R C1 Reset counter C1 L C1 Load counter C1 DUAL-coded T QW2 LC C1 Load counter C1 BCD-coded T QW4 A C1 Query of the counter C1 = Q 0.0 S_CUD CU Q
CD
S
PV CV
R CV_BCD C1 I0.0 C#5 I0.2 QW2 QW4 Q 0.0 LAD
( ) I0.1 I0.1 I0.3 I0.2 Counter limits: 0 999 Course Computer Based Automation WS 06/07 10 Stephan Simons S7 Counter: Signal state chart
FR CU CD S R Q 0.0 1 2 3 4 5 0 Course Computer Based Automation WS 06/07 11 Stephan Simons Load and transfer commands in STL Load function consists of operation L(load) and an operand. Operand is Byte, Word, DWord. Operand is loaded into ACCU 1. Examples for types of Operands: L 16#F8A4 Load a constant value (Immediate addressing) L IW16 Load an operand (Direct adrdressing) L ActValue Load a variable (Symbolic addressing) Loading takes place in two steps: Step 1: The content of ACCU 1 is moved into ACCU 2. Step 2: The operand of the load instruction is loaded into ACCU 1. Both Accumulators ACCU 1 and ACCU 3 have 32 bits each (Width of DWORD data type). Course Computer Based Automation WS 06/07 12 Stephan Simons Examples for loading of binary operands in STL Loading of inputs: L IBn // Byte L IWn // Word L IDn // Doubleword Loading of outputs: L QBn // Byte L QWn // Word L QDn // Doubleword Laden fromperiphery: L PIBn // Byte L PIWn // Word L PIDn // Doubleword Loading of flags: L MBn // Byte L MWn // Word L MDn // Doubleword n : Address parameter e.g. 4 or 32 Course Computer Based Automation WS 06/07 13 Stephan Simons Transfer instruction T in STL T: Transfers contents of ACCU 1 to the operand Operand: Byte, Word or Doubleword T MW120 Contents ACCU 1 Flag (absolute addressing) T RefValue Contents ACCU 1 Variable (symbolic addressing) This function also works with Twisting (Exchanging byte positions). QW10 = [QB11, QB10] QW10 consists of the two bytes QB10 and QB11. The lower byte of ACCU 1 is stored as the most significant byte QB11. The higher byte of ACCU 1 is stored as the least significant byte QB10. Examples for transfer instructions: T QB15 // Transfers ACCU 1 to output byte 15. T IW20 // Transfers ACCU 1 to process image of the inputs at // word address 20. T MD30 // Transfers ACCU 1 to flag doubleword at address 30. T PQW320 // Transfers ACCU 1 to the periphery output word 320, // e.g. to an analog output. Course Computer Based Automation WS 06/07 14 Stephan Simons MOVE function in FBD and LAD LAD FBD Input at IN and output at OUT can be of any elementary data type except BOOL. Variables at input IN and output OUT may be of different data types. Course Computer Based Automation WS 06/07 15 Stephan Simons Comparison functions in STL Comparison function INT DINT REAL Equal ==I ==D ==R Not equal <>I <>D <>R Greater >I >D >R Greater or equal >=I >=D >=R Less <I <D <R Less or equal <=I <=D <=R INT: Integer DINT: Doubleinteger REAL: floating point Course Computer Based Automation WS 06/07 16 Stephan Simons Comparison functions in FBD and LAD Comparison function INT DINT REAL Equal CMP ==I CMP ==D CMP ==R Not equal CMP <>I CMP <>D CMP <>R Greater CMP >I CMP >D CMP >R Greater or equal CMP >=I CMP >=D CMP >=R Less CMP <I CMP <D CMP <R Less or equal CMP <=I CMP <=D CMP <=R INT: Integer DINT: Doubleinteger REAL: floating point Course Computer Based Automation WS 06/07 17 Stephan Simons Example: Comparison functions in STL The input word IW0 is compared with the literal 120 (10) . If both values are equal Bit Q4.0 shall be set to 1 , otherwise Q4.0 shall be 0. No. STL Comments 1 A Q4.0 Q4.0 IW0 120 Q4.0 2 R // Q4.0 is set to 0 3 L // load IW0 into ACCU 1 4 L // transfer IW0 from ACCU 1 into ACCU 2 and load 120 // into ACCU 1 5 ==I // Compare ACCU 1 with ACCU 2 to be equal 6 S // Set Q4.0 to 1 if ACCU 1 = ACCU 2 Course Computer Based Automation WS 06/07 18 Stephan Simons Example: Comparison functions in STL The input word IW0 is compared with the literal 120 (10) . If both values are equal Bit Q4.0 shall be set to 1 , otherwise Q4.0 shall be 0. No. STL Comments 1 A Q4.0 Q4.0 IW0 120 Q4.0 2 R // Q4.0 is set to 0 3 L // load IW0 into ACCU 1 4 L // transfer IW0 from ACCU 1 into ACCU 2 and load 120 // into ACCU 1 5 ==I // Compare ACCU 1 with ACCU 2 to be equal 6 S // Set Q4.0 to 1 if ACCU 1 = ACCU 2 Course Computer Based Automation WS 06/07 19 Stephan Simons Example comparison function in FBD The input word IW0 is compared with the literal 120 (10) . If both values are equal Bit Q4.0 shall be set to 1 , otherwise Q4.0 shall be 0. Course Computer Based Automation WS 06/07 20 Stephan Simons Example comparison function in LAD The input word IW0 is compared with the literal 120 (10) . If both values are equal Bit Q4.0 shall be set to 1 , otherwise Q4.0 shall be 0. Course Computer Based Automation WS 06/07 21 Stephan Simons Arithmetic functions Additional: DEC n (Decrements ACCU 1 by the value of n) INC n (Increments ACCU 1 by the value of n) Arithmetic function INT DINT REAL Addition +I +D +R Subtraction -I -D -R Multiplication *I *D *R Division with quotient as result /I /D /R Division with remainder as result - MOD - Course Computer Based Automation WS 06/07 22 Stephan Simons Arithmetic functions in FBD and LAD No DEC or INC functions in FBD and LAD Arithmetic function INT DINT REAL Addition ADD_I ADD_DI ADD_R Subtraction SUB_I SUB_DI SUB_R Multiplication MUL_I MUL_DI MUL_R Division with quotient as result DIV_I DIV_DI DIV_R Division with remainder as result - MOD_DI - Course Computer Based Automation WS 06/07 23 Stephan Simons Examples for arithmetic functions L MW0 L MW2 +I T MW10 L MD0 L MD2 -D T MD10 L MD0 L MD2 *R T MD10 L MD0 L MD2 /R T MD10 Fct. LAD FBD STL I1-I2 I1+I2 I1*I2 I1/I2 Course Computer Based Automation WS 06/07 24 Stephan Simons Meaning of EN and ENO within functions EN Explanation ENO EN = FALSE If EN is FALSE when calling the function, the code-part of the function may not be executed. In this case output ENO will be set to FALSE upon exiting in order to indicate that the function has not been executed. ENO = FALSE EN = TRUE If EN is TRUE when calling the function, the code-part of the function can be executed nor- mally. In this case ENO will initially be set to TRUE before starting the execution. ENO = TRUE ENO can afterwards be set to TRUE or FALSE by instructions executed within the function body. ENO = individual value If a program or system error (as described in Appendix E) occurs while executing the function ENO will be reset to FALSE by the PLC. ENO = FALSE (error occurred) a TRUE = logical 1, FALSE = logical 0 Course Computer Based Automation WS 06/07 25 Stephan Simons Example: Two-step controller (two-position controller, bang-bang servo) (e.g. for temperature control) Voltage range 0 10 V 16 bit integer value in the range 0 27648 1,5 V is equivalent to 4147 (= 1,5V * 27648) / 10V (PIW288) (PIW290) (Q4.0) w: reference value (010V) X: actual value (010V) Y: control variable (bit) X d : control deviation X d = w - x Course Computer Based Automation WS 06/07 26 Stephan Simons Two-step controller: FBD program (PIW288) (PIW290) (Q4.0) y Course Computer Based Automation WS 06/07 27 Stephan Simons Mathematical functions Square, square-root Sine, cosine, tangent Arc sine, arc cosine, arc tangent Exponential function to base e, natural logarithm All these mathematical functions only work with values of the data type REAL! Course Computer Based Automation WS 06/07 28 Stephan Simons Mathematical functions Square, square-root Sine, cosine, tangent Arc sine, arc cosine, arc tangent Exponential function to base e, natural logarithm All these mathematical functions only work with values of the data type REAL! Conversion functions for REAL INTEGER (in STL): lTD Conversion of INT to DINT ITB Conversion of INT to BCD DTR Conversion of DINT to REAL RND Conversion of REAL to DINT with rounding to the next higher integer number Course Computer Based Automation WS 06/07 29 Stephan Simons Conversion 16 bit Integer to 32 bit Integer Conversion 32 bit Integer to REAL Input Data Integer 16 Bit Program algorithms using REAL Conversion functions INT DINT REAL LAD FBD STL MW12 MD20 MD20 MD28 L MW12 ITD T MD20 L MD20 DTR T MD28 MW12 MD20 MD20 MD28 Course Computer Based Automation WS 06/07 30 Stephan Simons Conversion function: Example (PIW288) (PQW320) Analog Input: PIW288 (16 bit Integer) Analog Output: PQW320 (16 bit Integer) Realize the following function f(x) with a PLC: x * . y 16 3 = with: 0V <= x <= 10V, 0V <= y <= 10V 0V 10 V 0 27648 (10) Course Computer Based Automation WS 06/07 31 Stephan Simons Normalization (Scaling) x y * 16 , 3 = V 10 27648 int = 8 , 2764 * int y y = 8 , 2764 * int x x = 8 , 2764 * 16 , 3 8 , 2764 int int x y = int int * 8 , 2764 * 16 , 3 x y = int int * 157 , 166 x y = 7) 1) 2) 3) 4) 5) 6) Course Computer Based Automation WS 06/07 32 Stephan Simons Realizing a square root extraction (I) Course Computer Based Automation WS 06/07 33 Stephan Simons Realizing a square root extraction (II) Course Computer Based Automation WS 06/07 34 Stephan Simons Conversion fromReal 32 bit DINT Round (FBD & LAD) / RND (STL): Rounds to the next integer. When the fraction of the number is exactly between an even and uneven result, the operation chooses the even result. Examples: +1.49 +1; 1.5 2; 2.5 2; 2.51 3 Trunc: Round with truncation of the fraction part. The result is only the integer part of the real data. Examples: 1.6 1. Ceil / RND+: Round to the next highest integer. This operation rounds the converted number to the smallest integer, that is greater than or equal to the converted integer. Examples: +1.2 +2; -1.5 -1. Floor / RND-: Round to the next lowest integer. This operation rounds the converted number to the largest integer, that is smaller or equal to the converted integer. Examples: +1.5 +1; -1.5 -2. Course Computer Based Automation WS 06/07 35 Stephan Simons Rounding Modes for the Conversion of REAL numbers Course Computer Based Automation WS 06/07 36 Stephan Simons Revolution measurement: transducer 10 V, 20 mA, 16 mA 1000 U/min 365 500 865 1500 rpm 0 10 V 0 20 mA 4 20 mA 10 V : 1000 rpm = 0,01 V/U/rpm 365 U/min 3,65 V Course Computer Based Automation WS 06/07 37 Stephan Simons Internal representation of analog value in case of bipolar measurement range Increments Voltage measurement range Current measurement range Range dec. hex. 10 V 20 mA 32767 7FFF 11,851 V 23,70 mA 32512 7F00 32511 7EFF 11,759 V 23,52 mA 27649 6C01 27648 6C00 10 V 20 mA 20736 5100 7,5 V 15 mA 1 1 361,7 V 723,4 nA 0 0 0 V 0 mA 1 FFFF -361,7 V -723,4 nA 20736 AF00 7,5 V 15 mA 27648 9400 10 V 20 mA 27649 93FF 32512 8100 11,759 V 23,52 mA 32513 80FF 32768 8000 11,851 V 23,70 mA Underflow Underrange Rated range Overange Overflow Course Computer Based Automation WS 06/07 38 Stephan Simons Internal representation of analog value in case of unipolar measurement range System Voltage measurement range Current measurement range Range dez. hex. 0..10 V 0..20 mA 4..20 mA 32767 7FFF 11,851 V 23,70 mA 22,96 mA 32512 7F00 32511 7EFF 11,759 V 23,52 mA 22,81 mA 27649 6C01 27648 6C00 10 V 20 mA 20 mA 20736 5100 7,5 V 15 mA 16 mA 1 1 361,7 V 723,4 nA 4 mA + 578,7 nA 0 0 0 V 0 mA 4 mA 1 FFFF 4864 ED00 3,52 mA 1,185 mA 4865 ECFF 32768 8000 Negative values not possible Negative values not possible Underflow Underrange N e g a t i v e
v a l u e s n o t p o s s i b l e Rated range Overrange Overflow Course Computer Based Automation WS 06/07 39 Stephan Simons Revolution measurement AD converter 0 27648 0 10 V 0 20 mA 4 20 mA 13824 12 10 5 Course Computer Based Automation WS 06/07 40 Stephan Simons Revolution measurement: transducer 10 V, 20 mA, 16 mA 1000 U/min 365 500 865 1500 rpm 0 27648 Incr. 13824 1000 10092 Course Computer Based Automation WS 06/07 41 Stephan Simons Table for normalization System Voltage measurement range Current measurement range Range dez. hex. 10 V 0..10 V 20 mA 0..20 mA 4..20 mA 27648 6C00 10 V 10 V 20 mA 20 mA 20 mA 0 0 0 V 0 V 0 mA 0 mA 4 mA 27648 9400 10 V 20 mA Rated range Course Computer Based Automation WS 06/07 42 Stephan Simons Task: Reading and normalizing of an analog value Acquire an analog value in the range of 0V to 10V with an analog input module in rack 0 (central unit), slot 6 (PIW288), map it onto the range 100 to 1000 as a REAL value and store the result as MD10! L PIW 288 // Analog value input 0 to 10 V contains 0 to 27648 integers (16 Bit) ITD // Value of integer (16 Bit) converted into integer (32 Bit) DTR // Value of integer (32 Bit) converted into a real number L 2.7648e+4 /R // Division with real number 27648 mapping value to range 0 to 1 L 9.000e+2 *R // Multiplication with real number 900 (1000-100) -> range 0 to 900 L 1.000e+2 +R // Addition with real number 100 (Offset) range 100 to 1000 T MD10 // Normalized value 100 to 1000 in real format Course Computer Based Automation WS 06/07 43 Stephan Simons Analog value conversion and processing 835 rpm 3,65 V 10092 Incr 10092 (INT) 10092 (DINT) 10092,0 10092,0 *2,2 22202,4 22202,4 22202 (DINT) 22202 Incr 22202 Incr 8,03 V 1303 rpm Transducer A/D-Converter L PIWn ITD DTR Programmed algortihm RND T PQWn Actuator D/A-Converter Course Computer Based Automation WS 06/07 44 Stephan Simons J ump instructions Unconditionally jumps: Are executed always no matter of a condition. Conditionally jumps: Are executed only if the condition is fullfiled. LOOP: instruction to call a program segment multiple times (only in STL) Course Computer Based Automation WS 06/07 45 Stephan Simons J ump unconditional LAD FBD STL Course Computer Based Automation WS 06/07 46 Stephan Simons J umps conditional LAD FBD STL Course Computer Based Automation WS 06/07 47 Stephan Simons All jump instructions in STL Unconditionally jumps: JU label J ump Unconditional JL label J ump to Labels J umps based on RLO: JC label J ump if RLO = 1 JCN label J ump if RLO = 0 JCB label J ump if RLO = 1 with BR JNB label J ump if RLO = 0 with BR J umps based on another bit in the status word: JBI label J ump if BR = 1 JNBI label J ump if BR = 0 JO label J ump if OV = 1 JOS label J ump if OS = 1 J umps based on the result of a calculation: JZ label J ump if Zero JN label J ump if Not Zero JP label J ump if Plus JM label J ump if Minus JPZ label J ump if Plus or Zero JMZ label J ump if Minus or Zero JUO label J ump if Unordered Loop instruction LOOP label call a program segment multiple times Course Computer Based Automation WS 06/07 48 Stephan Simons J ump distributor: J L The jump distributor allows specific (calculated) jumping to a program section in the block conditional on a number of positions. It works in conjunction with a list of J U jump functions following immediately the J L instruction. The list can contain up to 255 entries. The label of the J L instruction points to the end of the list. L Number_of_jump; J L End; // jump label points to the first statement after the list J U L0; // jump to L0 if Number_of_jump = 0 J U L1; // jump to L1 if Number_of_jump = 1
J U Lx; // jump to Lx if Number_of_jump = x
End: Course Computer Based Automation WS 06/07 49 Stephan Simons LOOP J ump L NumberOffLoops; Next: T ActLoopCountNo;
L ActLoopCountNo; LOOP Next;
The loop jump LOOP allows a simplified programming of program loops.
When processed, LOOP first decrements the contents of ACCU 1 by 1. If the value is not zero afterwards, the jump is executed to the jump label specified. If the value is zero, the jump is not executed and the next statement is processed. The start value in ACCU 1 thus corresponds to the number of program loops to be passed. This value has to be stored in a loop counter. Course Computer Based Automation WS 06/07 50 Stephan Simons Example: Using the jump instruction to restrict an analog value (PIW288) (PQW320) Internal representation of the limits: Lower limit: 0V 0 Upper limit: 8V (8V * 27648) / 10 V = 22118 Course Computer Based Automation WS 06/07 51 Stephan Simons Restriction of an analog value: STL program (PIW288) (PQW320) Course Computer Based Automation WS 06/07 52 Stephan Simons Restriction of an analog value: FBD program(I) Course Computer Based Automation WS 06/07 53 Stephan Simons Restriction of an analog value: FBD program(II) Course Computer Based Automation WS 06/07 54 Stephan Simons Instruction contents of lecture Bit logic instructions Bit logic instructions with expressions in parenthesize Edge triggered instructions Memory functions: Setting / Resetting bit addresses Timer instructions Counter instructions Load and transfer instructions Comparison instructions Integer and floating-point arithmetic instructions Floating point mathematical instructions Jump instructions