BAI 229 pot

8 212 0
BAI 229 pot

Đang tải... (xem toàn văn)

Thông tin tài liệu

S7-200 Tips SIMATIC S7-200 Tip High Speed Counters Tip No. 4 Group Topic 2 How to use High Speed Counters CPUs required for this tip CPU 210 ¨ CPU 212 ¨ CPU 214 þ CPU 215 þ CPU 216 þ OTHER ¨ Overview This Application Tip explains the function of one configuration for a high speed counter (HSC) on the SIMATIC S7-200. High speed counters can be used in many different configurations for processing the input signals of certain sensors (such as encoders). This example uses a pulse output to generate high speed signals for the HSC to count. It is possible to generate pulse strings along with pulse width modulations to control, for example, a servo-motor. Since a pulse output is used, a CPU 214 DC/DC/DC is required. The following application shows how a program should be structured to use a high speed counter, and a simple feedback loop demonstrates the pulse output function. Figure 4.1 Copyright 1997 by SIEMENS page 1 / 8 wxt1406913673.doc Status: 06/97 Version 3.3 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 High Speed Counters Tip No. 4 Program Structure 1,000 1,500 INT 0 INT 1 INT 2 1,000 Main Program SBR1: Start of HSC 0 SBR0: Initialization and start of Pules Program stops at the end of the Pulse string INT 0: First Preset INT 1: Second Preset INT 2: Third Preset Figure 4.2 Program Description This example demonstrates the usage of a high speed counter on the S7-200 CPU 214 DC/DC/DC. The counter used is a 2kHz software counter (also integrated in the CPU 212) and counts more rapidly than the PLC scan time. In addition to a 2 kHz counter, the CPU 214 has two 7 kHz hardware counters. Overall, the counters need 10 bytes of data memory for controlling, counting, storing values, and reading the current state. The size of the program is 96 words. The S7-200 System Manual provides more information about high speed counters. Copyright 1997 by SIEMENS page 2 / 8 wxt1406913673.doc Status: 06/97 Version 3.3 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 High Speed Counters Tip No. 4 LAD (S7-MicroDOS) STL (IEC) Main Program // The main program resets the output Q0.0 because it is needed for the // pulse functions. In addition, it initializes the high speed counter HSC0 // and calls the subroutines 0 and 1 . HSC0 is thus enabled with // the following features: updating of values possible and counting up. // The program ends after the number of pulses (specified in the SBR 0 (SMD72)) is reached. FIRST SCAN BIT ¦ SM0.1 Q0.0 K1 1 +-¦ + ( R ) ¦ ¦ ¦ ¦ MOV_B + ¦ + ¦EN ¦ ¦ ¦ ¦ ¦ ¦ ¦ KHF8¦IN OUT+SMB37 ¦ ¦ ¦ ¦ ¦ ¦ + + ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦ MOV_DW + ¦ + ¦EN ¦ ¦ ¦ ¦ ¦ ¦ ¦ K0¦IN OUT+SMD38 ¦ ¦ ¦ ¦ ¦ ¦ + + ¦ ¦ MOV_DW + ¦ + ¦EN ¦ ¦ ¦ ¦ ¦ ¦ ¦ K1000¦IN OUT+SMD42 ¦ ¦ ¦ ¦ ¦ ¦ + + ¦ ¦ HDEF + ¦ + ¦EN ¦ ¦ ¦ ¦ ¦ ¦ ¦ 0¦HSC ¦ ¦ ¦ 0¦MOD ¦ ¦ ¦ + + ¦ ¦ 0 ¦ + ( CALL ) ¦ ¦ ¦ ¦ 1 ¦ + ( CALL ) ¦ ¦ 2 + ( MEND ) ¦ LD SM0.1// First scan bit R Q0.0, 1 // Resetting of output Q0.0 // for pulse strings MOVB 16#F8, SMB37 // Load control bits for // high speed counter // HSC0 (Enable HSC0, // update CV, update PV, // update direction, // and count up). The // HSC instruction uses // these control bits to // configure the HSC. MOVD 0, SMD38 // Start value of high speed // counter HSC0 (CV) MOVD 1000, SMD42 // First Stop Value of // HSC0 (PV) HDEF 0, 0 // Definition of high speed // counter 0 in Mode 0 CALL 0 // Calling Subroutine 0 CALL 1 // Calling Subroutine 1 MEND // End of Main Routine Copyright 1997 by SIEMENS page 3 / 8 wxt1406913673.doc Status: 06/97 Version 3.3 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 High Speed Counters Tip No. 4 Subroutines // Subroutine 0 initializes and enables the pulse output. // The output is defined in special memory byte SMB67: pulse strings, time base, // updateability of values and enable. The word SMW68 contains the // pulse time as a multiplier of the time base. Finally, the number of pulses // to be generated will be specified in the special memory-double word. + + ¦ SBR: 0 ¦ + + ¦ ALWAYS ¦ ON BIT ¦ SM0.0 MOV_B + 4 + ¦ + ¦EN ¦ ¦ ¦ ¦ ¦ ¦ ¦ KH8D¦IN OUT+SMB67 ¦ ¦ ¦ ¦ ¦ ¦ + + ¦ ¦ MOV_W + ¦ + ¦EN ¦ ¦ ¦ ¦ ¦ ¦ ¦ K1¦IN OUT+SMW68 ¦ ¦ ¦ ¦ ¦ ¦ + + ¦ ¦ MOV_DW + ¦ + ¦EN ¦ ¦ ¦ ¦ ¦ ¦ ¦ K30000¦IN OUT+SMD72 ¦ ¦ ¦ ¦ ¦ ¦ + + ¦ ¦ PLS + ¦ + ¦EN ¦ ¦ ¦ ¦ ¦ 0¦Q.X ¦ ¦ ¦ ¦ ¦ + + ¦ 5 + ( RET ) ¦ SBR 0 // Subroutine 0 LD SM0.0 //Always on bit MOVB 16#8D,SMB67 // Pulse Output: 1ms, PTO, // Enable, Updating MOVW 1,SMW68 // Length of a pulse in ms MOVD 30000, SMD72 // Number of pulses to be // generated PLS 0 // Enabling of pulse function // on output Q0.0 RET // End of Subroutine 0 // Subroutine 1 starts the high speed counter HSC0 and assigns the Interrupt // Routine 0 to Interrupt Event 12 (HSC0 current value = preset value). This event occurs // as soon as the number of pulses counted (current value) reach the stop value (Preset). // Finally, the interrupts are enabled. + + ¦ SBR: 1 ¦ + + ¦ ALWAYS ¦ ON BIT ¦ SM0.0 ATCH + 7 + ¦ + ¦EN ¦ ¦ ¦ ¦ ¦ ¦ ¦ K0¦INT ¦ ¦ ¦ K12¦EVT ¦ ¦ ¦ + + ¦ ¦ ¦ + ( ENI ) ¦ ¦ SBR 1 // Subroutine 1 LD SM0.0 // Always on bit ATCH 0, 12 // Assignment of INT 0 to // Interrupt Event 12 (HSC0 // CV=PV) ENI // Enabling the interrupts Copyright 1997 by SIEMENS page 4 / 8 wxt1406913673.doc Status: 06/97 Version 3.3 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 High Speed Counters Tip No. 4 ¦ ¦ ¦ ¦ HSC + ¦ + ¦EN ¦ ¦ ¦ ¦ ¦ 0¦N ¦ ¦ ¦ ¦ ¦ + + ¦ 8 + ( RET ) ¦ HSC 0 // Starting high speed // counter 0 as earlier // configured RET // End of Subroutine 1 Interrupt routines // Interrupt Routine 0 is called when the first Preset value (1000) // of high speed counter 0 is reached. Output Q0.1 is set, and a // new Preset value (1500) is loaded for the high speed counter. // Interrupt Routine 1 is now assigned to Interrupt Event 12 instead of INT 0. + + ¦ INT: 0 ¦ + + ¦ ALWAYS ¦ ON BIT ¦ SM0.0 Q0.1 K1 10 + ¦ + ( S ) ¦ ¦ ¦ ¦ MOV_B + ¦ + ¦EN ¦ ¦ ¦ ¦ ¦ ¦ ¦ KHA0¦IN OUT+SMB37 ¦ ¦ ¦ ¦ ¦ ¦ + + ¦ ¦ MOV_DW + ¦ + ¦EN ¦ ¦ ¦ ¦ ¦ ¦ ¦ K1500¦IN OUT+SMD42 ¦ ¦ ¦ ¦ ¦ ¦ + + ¦ ¦ ATCH + ¦ + ¦EN ¦ ¦ ¦ ¦ ¦ ¦ ¦ K1¦INT ¦ ¦ ¦ K12¦EVT ¦ ¦ ¦ + + ¦ ¦ HSC + ¦ + ¦EN ¦ ¦ ¦ ¦ ¦ 0¦N ¦ ¦ ¦ ¦ ¦ + + ¦ 11 + ( RETI ) ¦ INT 0 // Interrupt Routine 0 LD SM0.0// Always on bit S Q0.1,1 // Setting output Q0.1 MOVB 16#A0, SMB37 // Set control bits to only // load a new preset value // (PV) MOVD 1500, SMD42 // Next Preset value of // HSC0 ATCH 1, 12 // Assign Interrupt Event 12 // to INT 1 instead of INT 0 HSC 0 // Load new Preset to High // Speed Counter 0 RETI // End of Interrupt Routine 0 // Interrupt Routine 1 is called when the second Preset value (1500) // of high speed counter 0 is reached. Output Q0.2 is set, // the counting direction is switched to down, and a new // Preset value (1000) is loaded. // Interrupt Routine 2 is assigned to Interrupt Event 12 (HSC0 CV=PV). Copyright 1997 by SIEMENS page 5 / 8 wxt1406913673.doc Status: 06/97 Version 3.3 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 High Speed Counters Tip No. 4 + + ¦ INT: 1 ¦ + + ¦ ALWAYS ¦ ON BIT ¦ SM0.0 Q0.2 K1 13 + ¦ + ( S ) ¦ ¦ ¦ ¦ MOV_B + ¦ + ¦EN ¦ ¦ ¦ ¦ ¦ ¦ ¦ KHB0¦IN OUT+SMB37 ¦ ¦ ¦ ¦ ¦ ¦ + + ¦ ¦ MOV_DW + ¦ + ¦EN ¦ ¦ ¦ ¦ ¦ ¦ ¦ K1000¦IN OUT+SMD42 ¦ ¦ ¦ ¦ ¦ ¦ + + ¦ ¦ ATCH + ¦ + ¦EN ¦ ¦ ¦ ¦ ¦ ¦ ¦ K2¦INT ¦ ¦ ¦ K12¦EVT ¦ ¦ ¦ + + ¦ ¦ HSC + ¦ + ¦EN ¦ ¦ ¦ ¦ ¦ 0¦N ¦ ¦ ¦ ¦ ¦ + + ¦ 14 + ( RETI ) ¦ INT 1 // Interrupt Routine 1 LD SM0.0 // Always on bit S Q0.2, 1 // Setting output Q0.2 MOVB 16#B0, SMB37 // Set control bits load a // new PV and to start // counting down MOVD 1000, SMD42 // Next Preset Value (PV) ATCH 2, 12 // Assign Interrupt Event // 12 to INT 2 instead of // INT 1 HSC 0 // Load new Preset and // direction to High Speed // Counter 0 RETI // End of Interrupt // Routine 1 // Interrupt Routine 2 is called when the third Preset value (1000) of // high speed counter 0 is reached. Outputs Q0.1 and Q0.2 are // reset, the counting direction is switched to up again, and the // current counting value is reset to zero. The Preset value remains unchanged. // By reassigning Interrupt Routine 0 to Interrupt Event 12, the // program run starts again. // The program ends when the number of pulses specified in SBR 0 (SMD72) has been // reached. + + ¦ INT: 2 ¦ + + ¦ ALWAYS ¦ ON BIT ¦ SM0.0 Q0.1 K2 16 + ¦ + ( R ) ¦ ¦ ¦ ¦ MOV_B + ¦ + ¦EN ¦ ¦ ¦ ¦ ¦ ¦ ¦ KHD8¦IN OUT+SMB37 ¦ ¦ ¦ ¦ ¦ ¦ + + INT 2 // Interrupt Routine 2 LD SM0.0 // Always on bit R Q0.1, 2 // Reset outputs Q0.1 // and Q0.2 MOVB 16#D8, SMB37 // Set control bits to load a // new CV and start // counting up Copyright 1997 by SIEMENS page 6 / 8 wxt1406913673.doc Status: 06/97 Version 3.3 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 High Speed Counters Tip No. 4 ¦ ¦ MOV_DW + ¦ + ¦EN ¦ ¦ ¦ ¦ ¦ ¦ ¦ K0¦IN OUT+SMD38 ¦ ¦ ¦ ¦ ¦ ¦ + + ¦ ¦ ATCH + ¦ + ¦EN ¦ ¦ ¦ ¦ ¦ ¦ ¦ K0¦INT ¦ ¦ ¦ K12¦EVT ¦ ¦ ¦ + + ¦ ¦ HSC + ¦ + ¦EN ¦ ¦ ¦ ¦ ¦ 0¦N ¦ ¦ ¦ ¦ ¦ + + ¦ 17 + ( RETI ) ¦ MOVD 0, SMD38 // Reset the current value of // HSC0 ATCH 0, 12 // Reassign INT 0 to // Interrupt Event 12 HSC 0 // Restarting high speed // counter 0 RETI // End of Interrupt // Routine 2 Conversion Notes To Convert from IEC STL to S7-Micro/DOS STL: l Add a ‘K’ before all non-Hex numerical constants (i.e. 4 ⇒ K4) l Replace ‘16#’ with ‘KH’ for all Hex constants (i.e. 16#FF ⇒ KHFF) l Commas denote field divisions. Use arrow or TAB keys to toggle between fields. l 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. l Line-Comments denoted by ‘//’ are not possible with S7-Micro/DOS, but Network- Comments are possible. Copyright 1997 by SIEMENS page 7 / 8 wxt1406913673.doc Status: 06/97 Version 3.3 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 High Speed Counters Tip No. 4 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 do not purport to cover all details or variations in equipment, nor do 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 page 8 / 8 wxt1406913673.doc Status: 06/97 Version 3.3 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.

Ngày đăng: 02/08/2014, 00:21

Tài liệu cùng người dùng

Tài liệu liên quan