Sie sind auf Seite 1von 10

Addressing the High-Speed Counters (HC) Back to Top To access the count value for the high-speed counter,

you specify the address of the highspeed counter, using the memory type (HC) and the counter number (such as HC0). The current value of the high-speed counter is a read-only value and can be addressed only as a double word (32 bits), as shown below. Format: HC[high-speed counter number] as for example HC2.

Understanding the Different High-Speed Counters Back to Top All counters function the same way for the same counter mode of operation. There are four basic types of counter modes as shown above. Note that every mode is not supported by every counter. You can use each type: without reset or start inputs, with reset and without start, or with both start and reset inputs. When you activate the reset input, it clears the current value and holds it clear until you deactivate reset. When you activate the start input, it allows the counter to count. While start is deactivated, the current value of the counter is held constant and clocking events are ignored. If reset is activated while start is inactive, the reset is ignored and the current value is not changed. If the start input becomes active while the reset input is active, the current value is cleared. Before you use a high-speed counter, you use the HDEF instruction (High-Speed Counter Definition) to select a counter mode. Use the first scan memory bit, SM0.1 (this bit is turned on for the first scan and is then turned off), to call a subroutine that contains the HDEF instruction. Control Byte Back to Top Once you have defined the counter and the counter mode, you can program the dynamic parameters of the counter. Each high-speed counter has a control byte that allows the following actions: Enabling or disabling the counter

Controlling the direction (modes 0, 1, and 2 only), or the initial counting direction for all other modes

Loading the current value Loading the preset value to be loaded

Examination of the control byte and associated current and preset values is invoked by the execution of the HSC instruction. The following table describes each of these control bits.

Setting Current Values and Preset Values Back to Top Each high-speed counter has a 32-bit current value and a 32-bit preset value. Both the current and the preset values are signed integer values. To load a new current or preset value into the high-speed counter, you must set up the control byte and the special memory bytes that hold the current and/or preset values. You must then execute the HSC instruction to cause the new values to be transferred to the high-speed counter. The following table describes the special memory bytes used to hold the new current and preset values. In addition to the control bytes and the new preset and current holding bytes, the current value of each high-speed counter can be read using the data type HC (High-Speed Counter Current) followed by the number (0, 1, 2, 3, 4, or 5) of the counter. Thus, the current value is directly accessible for read operations, but can only be written with the HSC instruction described above. Assigning Interrupts Back to Top

All counter modes support an interrupt on current value equal to the preset value. Counter modes that use an external reset input support an interrupt on activation of the external reset. All counter modes except modes 0, 1, and 2 support an interrupt on a change in counting direction. Each of these interrupt conditions may be enabled or disabled separately. Note: A fatal error can occur if you attempt either to load a new current value or to disable and then re-enable the high-speed counter from within the external reset interrupt routine. Initialization Modes 0, 1, or 2 The following steps describe how to initialize HSC1 for Single Phase Up/Down Counter with Internal Direction (Modes 0, 1, or 2): 1. Use the first scan memory bit to call a subroutine in which the initialization operation is performed. Since you use a subroutine call, subsequent scans do not make the call to the subroutine, which reduces scan time execution and provides a more structured program. 2. In the initialization subroutine, load SMB47 according to the desired control operation. For example: SMB47 = 16#F8 produces the following results: Enables the counter Writes a new current value Writes a new preset value Sets the direction to count up Sets the start and reset inputs to be active high 3. Execute the HDEF instruction with the HSC input set to 1 and the MODE input set to 0 for no external reset or start, to 1 for external reset and no start, or to 2 for both external reset and start. 4. Load SMD48 (double word size value) with the desired current value (load with 0 to clear it). 5. Load SMD52 (double word size value) with the desired preset value.

6. In order to capture the current value equal to preset event, program an interrupt by attaching the CV = PV interrupt event (event 13) to an interrupt routine. 7. In order to capture an external reset event, program an interrupt by attaching the external reset interrupt event (event 15) to an interrupt routine. 8. Execute the global interrupt enable instruction (ENI) to enable interrupts.

9. 10.

Execute the HSC instruction to cause the S7-200 to program HSC1. Exit the subroutine

Change Direction in Modes 0, 1, or 2 The following steps describe how to configure HSC1 for Change Direction for Single Phase Counter with Internal Direction (Modes 0, 1, or 2):

1. Load SMB47 to write the desired direction: SMB47 = 16#90 Enables the counter Sets the direction of the HSC to count down SMB47 = 16#98 Enables the counter Sets the direction of the HSC to count up

2.

Execute the HSC instruction to cause the S7-200 to program HSC1.

Load a New Current Value (Any Mode) The following steps describe how to change the counter current value of HSC1 (any mode): Changing the current value forces the counter to be disabled while the change is made. While the counter is disabled, it does not count or generate interrupts. 1. Load SMB47 to write the desired current value: SMB47 = 16#C0 Enables the counter Writes the new current value 2. Load SMD48 (double word size) with the desired current value (load with 0 to clear it). 3. Execute the HSC instruction to cause the S7-200 to program HSC1.

Disable a High-Speed Counter (Any Mode) The following steps describe how to disable the HSC1 high-speed counter (any mode): 1. Load SMB47 to disable the counter: SMB47 = 16#00 Disables the counter

2.

Execute the HSC instruction to disable the counter.

Although the above sequences show how to change direction, current value, and preset value individually, you may change all or any combination of them in the same sequence by setting the value of SMB47 appropriately and then executing the HSC instruction.

////////////////////////////////////// CT PLC:

-----------Bn c th t tm hiu phn ting Anh (dung Lacviet, Google cng c hoc khng dung cng tt) v lu nhng ch t mu m. Cng vic cn lm nh gi di y: C 1s l cp nht gi tr ca counter 1 ln. So snh v ra kt qu. Chu trnh lp li. -----------------[C 1s] cn: To mt counter m 1s th sinh ra mt ngt trn. [Cp nht gi tr ca counter 1 ln] cn: Ngt ny lm cng vic np li couter 1s v cp nht kt qu, chuyn kq m ra mt vng nh ca plc. Sau so snh kt qu vng nh ny vi cc mc chn trc to ng ra iu khin. [Chu trnh lp li] cn: Tr v t ngt, chy li t u ct. -------------------

To couter m 1s th sinh ra ngt trn: Nhan start I0.6 thi noi M0.0 cho ct. Nap SMB47 = 16#F8 : - cho php couter tc cao HSC. - Ghi mt gi tr hin thi mi cho HSC - Ghi mt gi tr t trc mi cho HSC. - Cho php HSC m ln. - Cho php ng vo reset, start c kch hot mc cao 1. Dung lnh HDEF : Xc nh HSC no, vd HSC0 ch 0 ( n gin lm vd), khng c reset, start t bn ngoi, ch c nhn tn hiu m s kin (clock) qua chn I0.0 (xem bng HSC mode phn u). Np SMD48 vi gi tr bt u l 0 (hoc ty : 32 bit=2 t-double word). Np SMD52 vi gi tr t trc l 10 ( hoc ty ). nh km ngt s kin 13 bt s kin gi tr m hin thi CV(current value) = gi tr t trc PV (preset value) th xy ra ngt v gi ct con phc v ngt INT_0 lm cc cng vic cn thit nh khi to li gi tr bt u m, m ln/xungcho HSC, ly kt qu m, chp ra vng nh khc lu li v sau em so snh ri cho kt qu ng ra ng/ngt v.v Cho php ngt tng ( ging nh ng cu dao tng trc th ng/m cng tc con mi c tc dng). Chy lnh HSC S7200 bt u lp trnh cho HSC0. -------------CT phc v ngt INT_0: Chp gi tr HSC0 t HC0 ra VD100. Np 16#C0 cho SMB47 cho php HSC0 tip tc v m ln. Np 0 cho SMD48 m li t 0. Chy HSC0. ------------Nhng ci khc lien quan: Bit nh SM0.1 c bit m ngun, qut ct ln u l n s thc hin m cha cn nhn start. Trn ch l phn c bn ca vic to ngt trn 1s bng HSC. y cn c 2 vic ging nhau cn lm ng thi: to ngt 1s u n v to mt vic tng t cng xy ra trong 1s nhng khng c gi tr t trc ch c gi tr hin thi chnh l s clock m c t bn ngoi (t cm bin trong ng c) qua chn I0.0. hy tm cch lng vo t c yu cu. Php so snh th cng n gin, tha 1 hoc 2 iu kin th tip im s thong. Gi tr trn (VD100-In1) s so snh vi gi tr di (In2) ti mi tip im. HC0 l vng nh ca gi tr hin thi ca HSC0, c th dung trc tip nh IN1 ca bit so snh nhng nn chp ra vng khc VD100 lu li v HC0 s thay i lien tc, khng th hin c gi tr cn xem ca HSC0 dng cho vic khc. Nhng con s ti dung i vd, cn th tnh c th ra t yu cu, vd 1800 vng/ pht =1800 xung/60 giy=30xung/giy (30), tn s cm bin m cn p ng t f>=30. -----------------

Das könnte Ihnen auch gefallen