Tài liệu tham khảo - nhphuocdtcn ď BAI 30 tài liệu, giáo án, bài giảng , luận văn, luận án, đồ án, bài tập lớn về tất cả...
S7-200 Tip PID-Instruction SIMATIC Group Tip No 53 S7-200 Tips Topic Using the PID-Instruction CPUs required for this tip CPU 210 CPU 212 CPU 214 CPU 215 CPU 216 OTHER Overview The following S7-200 program is an short example of how to use the PID instruction The PID instruction will be explained using an example of a water tank The aim is to maintain a constant water pressure and also keep the tank from being emptied pump with the water supply water level 75 % Analog Output (0-10V) from PID process B+,B- and C+,Care unused inputs Analog Input (4-20mA) for PID PV A+ A- SIEMENS SIMATIC S7-200 SF I 0.0 I 1.0 Q 0.0 Q 1.0 RUN I 0.1 I 1.1 Q 0.1 Q 1.1 STOP I 0.2 I 1.2 Q 0.2 I 0.3 I 1.3 Q 0.3 I 0.4 I 1.4 Q 0.4 I 0.5 I 1.5 Q 0.5 I 0.6 Q 0.6 I 0.7 Q 0.7 L+ CPU 216 B+ B- EXTF Vo L+ M EM 235 AI 3x12Bit AQ 1x12Bit X 6ES7 214-1BC01-0XB0 M Figure 53.1 Copyright 1997 by SIEMENS Status: 10/97 page / 13 158 jpv1512760536.doc Version 1.1 SIMATIC S7-200 customers have free use of the application tips These tips are only a general approach to using the S7-200 with various applications Your specific application may be different It is your responsibility to use the SIMATIC S7-200 properly in your applications S7-200 Tip PID-Instruction Tip No 53 Hardware Requirements S7-200 PLC Expansion Module EM 235 Analog Combination AI 3/ AQ 1x 12 Bits General Description In this example, a water tank is used to maintain a constant water pressure Water is continuously being taken from the water tank at a varying rate A variable speed pump is used to add water to the tank at a rate that will maintain adequate water pressure and also keep the tank from being emptied The setpoint for this system is a water level setting that is equivalent to the tank being 75% full The process variable is supplied by a float gauge that provides an equivalent reading of how full the tank is and which can vary from 0% or empty to 100% or completely full The output is a value of pump speed that allows the pump to run from 0% to 100% of maximum speed The setpoint is predetermined and will be entered directly into the loop table The process variable will be supplied as a to 20 ma analog value from the float gauge The loop output will be written to the analog output (0 to 10 V), which is used to control the pump speed The span of both, the analog input and analog output is 32,000 NOTE: The Analog value (AIW0) can be averaged by an average subroutine, to filter the input before the value is used as the PV Refer tip no 54 for details Only proportional and integral control will be employed in this example The loop gain and time constants have been determined from engineering calculations and may be adjusted as required to achieve optimum control The calculated values of the time constants are: KC - 0.25 TS - 0.1 seconds and TI - 30 minutes The tank speed will be controlled manually until the water tank is 75% full, then the valve will be opened to allow water to be drained from the tank At the same time, the pump will be switched from manual to auto control mode A digital input will be used to switch the control from manual to auto This input is described below: I0.0 - Manual/Auto control: - manual, - auto While in manual mode, the pump speed will be written by the operator to VD108 as a real number value from 0.0 to 1.0 The following information documents the program and its operation as well as defining the variables, subroutines and interrupt routines used by the program Subroutines: SBR0 Initialization subroutine SBR1 Subroutine to check, if an error occurred at the analog module Copyright 1997 by SIEMENS Status: 10/97 page / 13 159 jpv1512760536.doc Version 1.1 SIMATIC S7-200 customers have free use of the application tips These tips are only a general approach to using the S7-200 with various applications Your specific application may be different It is your responsibility to use the SIMATIC S7-200 properly in your applications S7-200 Tip PID-Instruction Tip No 53 Interrupt Routines: INT 100 ms timed interrupt that invokes PID execution Description of variables: I0.0 Q0.7 Manual/Auto control Error on the Analog module The loop table is 36 byte long and the parameters in the V-memory table are all standard double words (VD) The loop table has the following format: Offset Calculation Process variable Setpoint 12 16 20 24 28 32 Format Double word - real Double word - real Output Double word - real Gain Double word - real Sample time Double word - real Integral time or Double word reset - real Derivative time Double word or rate - real Bias Double word - real Previous Double word process - real variable Data type In IN In/Out In In In In In/Out In/Out Description Contains the process variable, which must be scaled between 0.0 and 1.0 Contains the setpoint, which must be scaled between 0.0 and 1.0 Contains the calculated output, scaled between 0.0 and 1.0 Contains the gain, which is a proportional constant Can be a positive or negative number Contains the sample time, in seconds Must be a positive number Contains the integral time or reset, in minutes Must be a positive number Contains the derivative time or rate, in minutes Must be a positive number Contains the bias or integral sum value between 0.0 and 1.0 Contains the previous value of the process variable stored from the last execution of the PID instruction user definable NO YES NO YES YES YES YES YES NO (Note: The basic address of the example program is VD100.) VD100 VD104 VD108 VD112 VD116 VD120 VD124 VD128 VD132 process variable (PV), from the analog input AWI0 setpoint (SP) output (M), contains the calculated output gain (Kc), a proportional constant sample time (Ts) integral time (Ti) derivative time (Td) or rate bias (MX) or integral sum previous process variable (PV N-1) More information about the PID Instruction is provided in the S7-200 System manual Basics of Controlling with PID is explained in tip 32 Information about the analog module is provided in the S7-200 System manual and in tip 34 Copyright 1997 by SIEMENS Status: 10/97 page / 13 160 jpv1512760536.doc Version 1.1 SIMATIC S7-200 customers have free use of the application tips These tips are only a general approach to using the S7-200 with various applications Your specific application may be different It is your responsibility to use the SIMATIC S7-200 properly in your applications S7-200 Tip PID-Instruction Tip No 53 Program Structure main program Start On the first scan: Initialization (SBR 0) Set and enable time interrupts (INT 0) On every scan: Check if the analog module has an error (SBR1) Set Q0.7 if an error occured main program End Interrupt program Start Get the process variable value from the the anlog input word (AIW0), scale value and store the converted value in the loop table In auto mode : execute PID-instruction Update analog output Interrupt program End Copyright 1997 by SIEMENS Status: 10/97 page / 13 161 jpv1512760536.doc Version 1.1 SIMATIC S7-200 customers have free use of the application tips These tips are only a general approach to using the S7-200 with various applications Your specific application may be different It is your responsibility to use the SIMATIC S7-200 properly in your applications S7-200 Tip PID-Instruction Tip No 53 LAD (S7-MicroDOS) STL (IEC) program description and main program // PID Example Program │ SM0.1 ├─┤ ├────────────────────────( CALL │ │ │ SM0.0 ├─┤ ├────────────────────────( CALL │ │ ├──────────────────────────────( MEND │ ) LD CALL SM0.1 // On the first scan // Call the initialization // subroutine ) LD CALL SM0.0 // On each scan // Check if error at the analog //module ) MEND // End the main program Subroutines // SBR0: Initialization (set and enable timed interrupt) ┌──────────┐ │ SBR: │ └───┬──────┘ │ SM0.0 MOV_B───┐ ├─┤ ├───────────┬────────────┤EN │ │ │ K100┤IN OUT├SMB34 │ │ └───────┘ │ │ ATCH────┐ │ ├────────────┤EN │ │ │ K0┤INT │ │ │ K10┤EVT │ │ │ └───────┘ │ │ │ └────────────( ENI ) │ ├──────────────────────────────( RET ) SBR LD SM0.0 MOVB 100, SMB34 // time interval (100ms) for timed // interrupt ATCH 0, 10 //Set timed interrupt to invoke // PID execution ENI // Enable interrupts RET // SBR1: Check for errors at the analog module If an error occurs set the Q0.7 ┌──────────┐ │ SBR: │ └───┬──────┘ │ SMB8 KH19 Q0.7 ├─────┤ == B ├─────┤NOT├─┬──────( ) │ │ │ │ │ │ │ │ │ SMB9 KH0 │ ├─────┤ == B ├─────┤NOT├─┘ │ │ ├──────────────────────────────( RET ) Copyright 1997 by SIEMENS Status: 10/97 page / 13 SBR LDB= SMB8, 16#19 // Check, NOT // if analog module is plugged in LDB= SMB9, 16#0 // Check, NOT // if analog module has an error OLD = Q0.7 // Error reading analog module RET 162 jpv1512760536.doc Version 1.1 SIMATIC S7-200 customers have free use of the application tips These tips are only a general approach to using the S7-200 with various applications Your specific application may be different It is your responsibility to use the SIMATIC S7-200 properly in your applications S7-200 Tip PID-Instruction Tip No 53 │ // INT 0: Interrupt routine - PID- Routine (timed interrupt for PID-execution) ┌──────────┐ │ INT: │ └───┬──────┘ │ Q0.7 WXOR_DW─┐ 11 ├─┤ / ├───────────┬────────────┤EN │ │ │ AC0┤IN1 OUT├AC0 │ │ AC0┤IN2 │ │ │ └───────┘ │ │ MOV_W───┐ │ ├────────────┤EN │ │ │ AIW0┤IN OUT├AC0 │ │ └───────┘ │ │ DI_REAL─┐ │ ├────────────┤EN │ │ │ AC0┤IN OUT├AC0 │ │ └───────┘ │ │ SUB_R───┐ │ ├────────────┤EN │ │ │ KR+6400.00┤IN1 OUT├AC0 │ │ AC0┤IN2 │ │ │ └───────┘ │ │ DIV_R───┐ │ ├────────────┤EN │ │ │ AC0┤IN1 OUT├AC0 │ │ KR+25600.0┤IN2 │ │ │ └───────┘ │ │ MOV_R───┐ │ └────────────┤EN │ │ AC0┤IN OUT├VD100 │ └───────┘ │ I0.0 PID─────┐ 12 ├─┤ ├────────────────────────┤EN │ │ VB100┤TBL │ │ 0┤LOOP │ │ └───────┘ │ SM0.0 MUL_R───┐ 13 ├─┤ ├───────────┬────────────┤EN │ │ │ VD108┤IN1 OUT├AC0 │ │ KR+32000.0┤IN2 │ │ │ └───────┘ │ │ TRUNC───┐ │ ├────────────┤EN │ │ │ AC0┤IN OUT├AC0 │ │ └───────┘ │ │ MOV_W───┐ │ └────────────┤EN │ │ AC0┤IN OUT├AQW0 │ └───────┘ │ 14 ├──────────────────────────────( RETI ) Copyright 1997 by SIEMENS Status: 10/97 page / 13 INT LDN Q0.7 // If analog module is O.K.? XORD AC0, AC0 // Clear the accumulator MOVW AIW0, AC0 // save the analog value DTR AC0, AC0 // Convert 32-bit integer to real -R 6400.0, AC0 // Adjust for to 20 mA offset /R 25600.0, AC0 // Normalize the PV // value in the accumulator MOVR AC0, VD100 // Store accu in the loop Table LD PID I0.0 // When auto mode, VB100, // invoke PID execution // Analog Output LD SM0.0 MOVR VD108, AC0 // loop output to accu *R 32000.00, AC0 // scale value in accu TRUNC AC0, AC0 // Convert real to // 32-bit integer MOVW AC0, AQW0 // write the value to analog output RETI 163 jpv1512760536.doc Version 1.1 SIMATIC S7-200 customers have free use of the application tips These tips are only a general approach to using the S7-200 with various applications Your specific application may be different It is your responsibility to use the SIMATIC S7-200 properly in your applications S7-200 Tip PID-Instruction Tip No 53 Data Block DB1 (V Memory): // initialize values VD104 0.75 VD112 0.25 VD116 0.10 VD120 30.0 VD124 0.0 // setpoint = 0.75 = 75% full // loop gain = 0.25 // sample time = 0.1 seconds // integral time = 30 minutes // no derivation action Conversion Notes To Convert from IEC STL to S7-Micro/DOS STL: Add a ‘K’ before all non-Hex numerical constants (i.e ⇒ K4) Replace ‘16#’ with ‘KH’ for all Hex constants (i.e 16#FF ⇒ KHFF) Commas denote field divisions Use arrow or TAB keys to toggle between fields To convert an S7-Micro/DOS STL program to LAD form, every network must begin with the word ‘NETWORK’ and a number Each network in this Application Tip program is designated by a number on the ladder diagram Use the INSNW command under the EDIT menu to enter a new network The MEND, RET, RETI, LBL, SBR, and INT commands each receive their own networks Line-Comments denoted by ‘//’ are not possible with S7-Micro/DOS, but NetworkComments are possible General Notes The SIMATIC S7-200 Application Tips are provided to give users of the S7-200 some indication as to how, from the view of programming technique, certain tasks can be solved with this controller These instructions not purport to cover all details or variations in equipment, nor they provide for every possible contingency Use of the S7-200 Application Tips is free Siemens reserves the right to make changes in specifications shown herein or make improvements at any time without notice or obligation It does not relieve the user of responsibility to use sound practices in application, installation, operation, and maintenance of the equipment purchased Should a conflict arise between the general information contained in this publication, the contents of drawings or supplementary material, or both, the latter shall take precedence Siemens is not liable, for whatever legal reason, for damages or personal injury resulting from the use of the application tips All rights reserved Any form of duplication or distribution, including excerpts, is only permitted with express authorization by SIEMENS Copyright 1997 by SIEMENS Status: 10/97 page / 13 164 jpv1512760536.doc Version 1.1 SIMATIC S7-200 customers have free use of the application tips These tips are only a general approach to using the S7-200 with various applications Your specific application may be different It is your responsibility to use the SIMATIC S7-200 properly in your applications S7-200 Tip PID-Instruction Tip No 53 Tham khảo: Chương trình S7 – 200 ví dụ ngắn cách sử dụng PID thơng qua ví dụ điều khiển mức nước bể để vừa đảm bảo áp suất vừa đảm bảo nước bình khơng bị cạn hết Cấu trúc hệ thống hình đây: Yêu cầu thiết bị điều khiển: 01 PLC S7 200/ CPU 216 trở lên 01 khối EM 235 gồm có đầu vào analog đầu analog 12 bít Mơ tả hệ thống: Trong hệ thống này, bể nước dùng để khống chế áp lực nước không đổi Nước liên tục lấy từ vòi với tốc độ Bơm dùng để tăng thêm nước vào bể với tốc độ đủ để trì áp suất mức nước bình khơng hạ xuống mức cho phép Giá trị đặt hệ thống mức nước (trong ví dụ 75% bể) Đại lượng đầu vào hệ thống tín hiệu cảm biến đo mức đưa thông qua đầu vào analog A+, A- Tín hiệu đưa thay đổi từ – 20mA tương ứng với – 100% mức đầy bể Tín hiệu hệ thống tín hiệu điện áp thay đổi từ – 10 V dùng để điều khiển tốc độ bơm tương ứng – 100% tốc độ định mức Giá trị đặt định người sử dụng đưa trực tiếp vào trình Trong chương trình này, điều khiển sử dụng hai thông số P I, không dùng đến D Thời gian lấy mẫu Ts = 0.1 giây, KC = 0.25 Ti = 30 phút Trước tiên, bể nước tiếp đầy nước 75% Sau đó, van xả mở để lấy nước từ bể lúc bơm chuyển từ chế độ điều khiển tay sang chế độ tự động Trong trình điều khiển tay, tốc độ bơm qui định số thực lưu VD108 nằm khoảng 0.0 tới 1.0 Copyright 1997 by SIEMENS Status: 10/97 page / 13 165 jpv1512760536.doc Version 1.1 SIMATIC S7-200 customers have free use of the application tips These tips are only a general approach to using the S7-200 with various applications Your specific application may be different It is your responsibility to use the SIMATIC S7-200 properly in your applications S7-200 Tip PID-Instruction Tip No 53 SBR0 hàm thực khởi tạo hệ thống SBR hàm thực kiểm tra lỗi khối analog Đầu vào I0.0 dùng tín hiệu khởi động hệ thống điều khiển tự động Đầu Q0.7 báo lỗi xảy module analog Ngắt INT thực thuật toán PID 100 ms lần Bảng lặp dùng cho PID gồm có 36 byte thống số đặt vùng nhớ V tất dùng double word (VD) Khoảng Thơng số tính cách so tốn với địa bắt đầu PV SP M 12 KC 16 TS 20 Ti 24 Td 28 Bias (MX) 32 PVN-1 Định dạng Double word - real Double word - real Double word - real Double word - real Double word - real Double word - real Double word - real Double word - real Double word - real vào/ra Mơ tả Người dùng định nghĩa Tín hiệu mức nước bể, khoảng 0.0 – 1.0 tương ứng – 100% Giá trị đặt mức nước bể, phải nằm khoảng 0.0 – 1.0 Giá trị tín hiệu ra, nằm khoảng 0.0 – 1.0 NO YES In Hệ số khuếch đại P YES In Thời gian trích mẫu YES In Thời gian tích phân YES In Thời gian vi phân YES In/Out Tổng tích phân (bias MX or integral sum) YES In/Out Giá trị mức nước đo lần lấy mẫu trước NO vào IN In/Out NO Trong chương trình dùng địa bắt đầu bảng VD100 VD100 VD104 VD108 VD112 VD116 VD120 VD124 VD128 VD132 PV , lấy vào từ AWI0 SP M Kc Ts Ti Td MX PVN-1 Có thể tham khảo thêm PID tài liệu cung cấp Hướng dẫn sử dụng hệ thống S7 200 sách tham khảo khác Copyright 1997 by SIEMENS Status: 10/97 page / 13 166 jpv1512760536.doc Version 1.1 SIMATIC S7-200 customers have free use of the application tips These tips are only a general approach to using the S7-200 with various applications Your specific application may be different It is your responsibility to use the SIMATIC S7-200 properly in your applications S7-200 Tip PID-Instruction Tip No 53 Lưu đồ thuật toán Copyright 1997 by SIEMENS Status: 10/97 page / 13 167 jpv1512760536.doc Version 1.1 SIMATIC S7-200 customers have free use of the application tips These tips are only a general approach to using the S7-200 with various applications Your specific application may be different It is your responsibility to use the SIMATIC S7-200 properly in your applications S7-200 Tip PID-Instruction Tip No 53 CHƯƠNG TRÌNH ĐIỀU KHIỂN // PID │ SM0.1 ├─┤ ├────────────────────────( CALL │ │ │ SM0.0 ├─┤ ├────────────────────────( CALL │ │ ├──────────────────────────────( MEND │ ) LD CALL SM0.1 // ON vòng quét đầu // Gọi hàm khởi tạo hệ thống LD CALL SM0.0 // Luôn ON // Gọi hàm kiểm tra lỗi // khối analog ) MEND // Kết thúc ) Hàm chức // SBR0: Khởi tạo hệ thống khởi động ngắt thời gian ┌──────────┐ │ SBR: │ └───┬──────┘ │ SM0.0 MOV_B───┐ ├─┤ ├───────────┬────────────┤EN │ │ │ K100┤IN OUT├SMB34 │ │ └───────┘ │ │ ATCH────┐ │ ├────────────┤EN │ │ │ K0┤INT │ │ │ K10┤EVT │ │ │ └───────┘ │ │ │ └────────────( ENI ) │ ├──────────────────────────────( RET ) SBR LD SM0.0 MOVB 100, SMB34 // Thời gian ngắt 100 ms ATCH 0, 10 // Gọi chương trình ngắt thời gian (10) để thực thuật toán PID ENI // Chấp nhận hoạt động RET // Trở chươn trình // SBR1: Kiểm tra lỗi khối analog báo lỗi Q0.7 ┌──────────┐ │ SBR: │ └───┬──────┘ │ SMB8 KH19 Q0.7 ├─────┤ == B ├─────┤NOT├─┬──────( ) │ │ │ │ │ │ │ │ │ SMB9 KH0 │ ├─────┤ == B ├─────┤NOT├─┘ │ │ ├──────────────────────────────( RET ) │ SBR LDB= SMB8, 16#19 // Nếu khơng có khối EM235 báo lỗi NOT LDB= SMB9, 16#0 // Nếu có EM235 có lỗi báo lỗi NOT OLD = Q0.7 // Error reading analog module RET Copyright 1997 by SIEMENS Status: 10/97 page / 13 168 jpv1512760536.doc Version 1.1 SIMATIC S7-200 customers have free use of the application tips These tips are only a general approach to using the S7-200 with various applications Your specific application may be different It is your responsibility to use the SIMATIC S7-200 properly in your applications S7-200 Tip PID-Instruction Tip No 53 // INT 0: Thực thuật toán PID ┌──────────┐ │ INT: │ └───┬──────┘ │ Q0.7 WXOR_DW─┐ 11 ├─┤ / ├───────────┬────────────┤EN │ │ │ AC0┤IN1 OUT├AC0 │ │ AC0┤IN2 │ │ │ └───────┘ │ │ MOV_W───┐ │ ├────────────┤EN │ │ │ AIW0┤IN OUT├AC0 │ │ └───────┘ │ │ DI_REAL─┐ │ ├────────────┤EN │ │ │ AC0┤IN OUT├AC0 │ │ └───────┘ │ │ SUB_R───┐ │ ├────────────┤EN │ │ │ KR+6400.00┤IN1 OUT├AC0 │ │ AC0┤IN2 │ │ │ └───────┘ │ │ DIV_R───┐ │ ├────────────┤EN │ │ │ AC0┤IN1 OUT├AC0 │ │ KR+25600.0┤IN2 │ │ │ └───────┘ │ │ MOV_R───┐ │ └────────────┤EN │ │ AC0┤IN OUT├VD100 │ └───────┘ │ I0.0 PID─────┐ 12 ├─┤ ├────────────────────────┤EN │ │ VB100┤TBL │ │ 0┤LOOP │ │ └───────┘ │ SM0.0 MUL_R───┐ 13 ├─┤ ├───────────┬────────────┤EN │ │ │ VD108┤IN1 OUT├AC0 │ │ KR+32000.0┤IN2 │ │ │ └───────┘ │ │ TRUNC───┐ │ ├────────────┤EN │ │ │ AC0┤IN OUT├AC0 │ │ └───────┘ │ │ MOV_W───┐ │ └────────────┤EN │ │ AC0┤IN OUT├AQW0 │ └───────┘ │ 14 ├──────────────────────────────( RETI ) Copyright 1997 by SIEMENS Status: 10/97 page / 13 INT LDN Q0.7 // Nếu khối analog khơng có lỗi XORD AC0, AC0 // Xóa AC0 MOVW AIW0, AC0 // Lấy giá trị đo mức nước PV DTR AC0, AC0 // Chuyển đổi sang số thực 32 bít -R 6400.0, AC0 // Chuyển đổi sang tín hiệu – 20 mA /R 25600.0, AC0 // Chuyển PV giá trị thường dùng MOVR AC0, VD100 // Lưu vào vùng nhớ LD I0.0 // Chế độ Auto PID VB100, // Thực PID với địa bắt đầu VB100 // Tín hiệu đầu analog LD SM0.0 MOVR VD108, AC0 // Đưa AC0 *R 32000.00, AC0 // chuyển thang giá trị TRUNC AC0, AC0 //Chuyển sang số nguyên 32 bít MOVW AC0, AQW0 // Gửi đầu RETI // Trở lại chương trình 169 jpv1512760536.doc Version 1.1 SIMATIC S7-200 customers have free use of the application tips These tips are only a general approach to using the S7-200 with various applications Your specific application may be different It is your responsibility to use the SIMATIC S7-200 properly in your applications S7-200 Tip PID-Instruction Tip No 53 Dữ liệu DB1 (V Memory): // Khởi tạo VD104 VD112 VD116 VD120 VD124 0.75 0.25 0.10 30.0 0.0 // SV = 0.75 = 75% full // Kc = 0.25 // Ts = 0.1 seconds // Ti = 30 minutes // Td = Copyright 1997 by SIEMENS Status: 10/97 page / 13 170 jpv1512760536.doc Version 1.1 SIMATIC S7-200 customers have free use of the application tips These tips are only a general approach to using the S7-200 with various applications Your specific application may be different It is your responsibility to use the SIMATIC S7-200 properly in your applications ... (MX) 32 PVN-1 Định dạng Double word - real Double word - real Double word - real Double word - real Double word - real Double word - real Double word - real Double word - real Double word - real... - real Output Double word - real Gain Double word - real Sample time Double word - real Integral time or Double word reset - real Derivative time Double word or rate - real Bias Double word -. .. VD132 PV , lấy vào từ AWI0 SP M Kc Ts Ti Td MX PVN-1 Có thể tham khảo thêm PID tài liệu cung cấp Hướng dẫn sử dụng hệ thống S7 200 sách tham khảo khác Copyright 1997 by SIEMENS Status: 10/97