Siemens PLC Classification: Siemens programmable logic controllers (PLCs) are widely used in my country, particularly in metallurgy, chemical engineering, and printing production lines. Siemens PLC products include the LOGO, S7-200, S7-1200, S7-300, and S7-400 series. The Siemens S7 series PLCs are small, fast, standardized, and feature network communication capabilities, offering enhanced functionality and high reliability. S7 series PLCs can be categorized into micro PLCs (such as the S7-200), PLCs for small-scale performance requirements (such as the S7-300), and PLCs for medium to high performance requirements (such as the S7-400).
The working principle of Siemens PLC programming: After a PLC is put into operation, its working process generally consists of three stages: input sampling, user program execution, and output refresh. The completion of these three stages is called one scan cycle. Throughout the entire operation, the PLC's CPU repeatedly executes these three stages at a certain scan speed.
Input sampling
During the input sampling phase, the PLC sequentially reads all input states and data in a scanning manner and stores them in the corresponding cells of the I/O image area. After input sampling is completed, the process transitions to the user program execution and output refresh phases. During these two phases, even if the input states and data change, the states and data in the corresponding cells of the I/O image area will not change. Therefore, if the input is a pulse signal, the width of the pulse signal must be greater than one scan cycle to ensure that the input can be read under any circumstances.
User program execution
During the user program execution phase, the PLC always scans the user program (ladder diagram) sequentially from top to bottom. When scanning each ladder diagram, it always first scans the control circuit composed of each contact on the left side of the ladder diagram, and performs logical operations on the control circuit composed of contacts in the order of left to right and top to bottom. Then, based on the result of the logical operation, it refreshes the state of the corresponding bit in the system RAM storage area of the logic coil; or refreshes the state of the corresponding bit in the I/O image area of the output coil; or determines whether to execute the special function instruction specified by the ladder diagram.
That is, during the execution of the user program, only the state and data of the input points in the I/O image area remain unchanged, while the state and data of other output points and soft devices in the I/O image area or system RAM storage area may change. Moreover, the program execution result of the ladder diagram above will affect the ladder diagram below that uses these coils or data; conversely, the state or data of the logic coils refreshed in the ladder diagram below can only affect the program above it in the next scan cycle.
Output refresh
After the user program scan is complete, the PLC enters the output refresh phase. During this period, the CPU refreshes all output latch circuits according to the corresponding states and data in the I/O image area, and then drives the corresponding peripherals through the output circuits. This is when the PLC actually outputs data.
The same set of ladder diagrams, arranged in different orders, will produce different results. Furthermore, the results of scanning the user program differ from those of parallel execution of the hard logic in a relay control device. Of course, if the time occupied by the scan cycle is negligible in the overall operation, then there is no difference between the two.
Issues to be aware of when programming Siemens PLCs:
1. Subroutines can be called within an interrupt routine.
Accumulators and logical stack-style storage are shared by both interrupt routines and called subroutines.
2. Data can be shared between interrupt routines and the main program.
Although interrupt routines can be shared, we need to pay attention to the impact of the asynchronous nature of events in interrupt events to solve the consistency problem of shared data. Interrupt events can occur anywhere in the main program's execution.
3. Interruption of communication interface
The serial communication port of a PLC can be controlled by ladder diagrams or statement lists. This operating mode of the communication port is called the free port mode. In this free mode, the baud rate, the number of bits per byte, etc., can be defined programmatically. During the execution of the main program, an interrupt must be requested to define the free port mode. Utilizing receive and transmit interrupts simplifies the program's control over communication.
4.I/O interrupt
I/O interrupts include rising or falling edge interrupts, tell-counter interrupts, and burst output interrupts.
When the S7-200 CPU generates an interrupt using the rising or falling edge of inputs I0.0 to I0.3, the event is captured by the input terminal. Such a rising or falling edge can be used to indicate a condition that must be noted when an event occurs.
5. Time base interruption
6. Interrupt priority and queuing
7. Interruption restrictions
8. Interrupt program programming steps