In practical applications, it is often the case that a certain relay bit is turned ON for a fixed period of time and turned OFF for a period of time. For example, use the digital output drive indicator to flash or drive the buzzer to make a intermittent sound.
It summarizes four ways to implement this function in the Siemens S7-200 program. The following are introduced separately:
The first method uses a special memory bit SM.
The special memory bit SM0.4 provides a one minute clock pulse that is turned off (OFF) for 30 seconds and turned ON for 30 seconds in a one minute period.
The special memory bit SM0.5 provides a one second clock pulse that is turned off (OFF) for 0.5 seconds and turned ON for 0.5 seconds in a one second period.
The special memory bit SM0.6 provides a scan cycle clock pulse that is turned on for one scan and then turned off for the next scan.
This method is simple to use, but the clock cycle and switching time are fixed, and in many cases it cannot meet the requirements.
The second method utilizes a time base interrupt routine time base interrupt including a timer interrupt and a timer interrupt.
The timed interrupt can be used to support a periodic activity. The cycle time is measured in 1ms, and the cycle time can be from 5ms to 255ms. For the timer interrupt 0, the cycle time is written to SMB34, and for the timer interrupt 1, the cycle time is written to SMB35. Whenever the timer time value is reached, the relevant timer overflows and the interrupt handler is executed.
A timer interrupt can use a timer to generate an interrupt for a specified period of time. This type of interrupt can only be used with the 1ms power-on and power-down delay timers T32 and T96. When the current value of the used timer is equal to the preset value, the interrupt is executed during the normal timing refresh of the host. The program examples are given below:
ORGANIZATION_BLOCK main program: OB1
TITLE=Main Program: Generate Clock Pulses with Timed Interrupts-Author:Smartsys-
BEGIN
Network 1
LD SM0.1
MOVB 100, SMB34
ATCH INT0, 10; associates an interrupt event (EVNT) with the interrupt routine number (INT) and enables an interrupt event.
ENI; allow interrupts
END_ORGANIZATION_BLOCK
INTERRUPT_BLOCK INT_0: INT0
TITLE=Interrupt Program: Generate Clock Pulses with Timed Interrupts-Author:Smartsys-
BEGIN; start
Network 1
LD SM0.0
INCB VB0
Network 2
LDB>= VB0, 10
XORB 2#1, QB0
XORB VB0, VB0
END_INTERRUPT_BLOCK
ORGANIZATION_BLOCK main program: OB1
TITLE=Main Program: Generate Clock Pulses Using Timer Interrupts-Author:Smartsys-
BEGIN
Network 1
LD SM0.1
ATCH INT0, 21
ENI
Network 2
LD SM0.0
LPS
AN M0.0
TON T32, 1000
LPP
A T32
= M0.0
END_ORGANIZATION_BLOCK
INTERRUPT_BLOCK INT_0: INT0
TITLE=Interrupt Program: Generate Clock Pulse with Timer Interrupt-Author:Smartsys-
BEGIN
Network 1
LD SM0.0
XORB 2#1, QB0
END_INTERRUPT_BLOCK
This method clock cycle can be adjusted, but the opening and closing times are the same. Copy the program code, paste it into a text file, and import it in Step7-MicroWIN.
We have already introduced two methods. The following two methods are introduced. The third method is implemented by using the power-on and power-off delay timers. This method can not only adjust the clock cycle, but also generate clocks with different on and off times. pulse. Two example programs are given below.
In the first example program, we use two timers to generate the clock pulse. The principle is that the timer 1 counts to the position bit output relay bit, and the timer 2 starts to start timing. The timer 2 counts the bit reset output relay bit and starts at the same time. Timer 1 starts counting and loops back and forth. The sum of the preset values ​​of the two timers is a clock cycle, and the preset value of the timer 1 or the preset value of the timer 2 is respectively adjusted, so that clock pulses with different opening and closing times can be realized.
ORGANIZATION_BLOCK main program: OB1
TITLE=Main Program: Generate clock pulses with two timers-Author:Smartsys-
BEGIN
Network 1
LD SM0.0
LPS
AN Q0.0
TON T37, 10
LPP
A T37
S Q0.0, 1
Network 2
LD SM0.0
LPS
A Q0.0
TON T38, 20
LPP
A T38
R Q0.0, 1
END_ORGANIZATION_BLOCK
In the second example program, we can use the same timer to achieve the effect of the previous example. The realization principle is to use a timer to generate a cycle, that is, the timer resets the bit again, and uses a comparison command. When the current value of the timer is greater than a certain value, the output relay is set, and the output relay is reset when the timer is in time. The timer preset value can adjust the clock period and change the comparison value to realize clock pulses with different opening and closing times.
ORGANIZATION_BLOCK main program: OB1
TITLE=Main Program: Generate a clock pulse with a timer-Author:Smartsys-
BEGIN
Network 1
LD SM0.0
LPS
AN M0.0
TON T37, 30
LRD
AW>= T37, 10
S Q0.0, 1
LPP
A T37
R Q0.0, 1
= M0.0
END_ORGANIZATION_BLOCK
We recommend this method for applications that generally require less precision.
We have experience and skill to support customers to tooling for their required waterproof connectors, like IP68 series,micro fit connectors. Etop wire assemblies for various industries have been highly recognized by all the customers and widely used for automobiles, electrical and mechanical, medical industry and electrical equipemnts, etc. Products like, wire harness for car audio, power seat, rear-view mirror, POS ATM, Diesel valve Cover gasket fit, elevator, game machine, medical equipment, computer, etc.
JST Connector,Molex Connector, Multi-Contact Connector, Micro Fit Connectors
ETOP WIREHARNESS LIMITED , https://www.wireharness-assembling.com