Soft PLC control technology is based on the idea that software and hardware are equivalent in logical functions. It adopts an open architecture and implements the functions of PLC hardware through software. The soft PLC system consists of a host computer and a slave computer. The host computer provides users with an editing interface and a variety of programming language environments, making it easy for users to edit PLC programs on a PC. It also monitors some state quantities of the slave computer and sends instructions to the slave computer.
After the user edits the ladder diagram and instruction table program of the PLC, the program can only be run according to the working principle of the PLC after the program logic is obtained by compiling the program. In order to cooperate with the soft PLC editing and development system running on the PC and enable the PC to complete the corresponding control functions, a soft PLC compilation system was developed.
1. Composition of soft PLC program compilation system
The PLC compilation module consists of a ladder diagram syntax check module, a ladder diagram program logic check module, and an instruction table program syntax check module. The ladder diagram program syntax check module checks whether the user's PLC graphic program has syntax errors such as repeated instruction marks and instruction addresses out of bounds; the ladder diagram program logic check module checks whether the PLC graphic program has logic errors; the language program syntax check module checks whether the user's statement program has syntax errors such as spelling, instruction format, and instruction address out of bounds.
The construction of the compiler includes lexical analysis, syntax analysis, semantic analysis, error checking and handling, as well as code generation and code optimization.
2. Traversal algorithm of soft PLC program
The traversal algorithm of the soft PLC program mainly includes the ladder diagram traversal algorithm and the instruction table traversal algorithm. The ladder diagram program consists of several rungs. The traversal is done in units of rungs, using a depth-first scanning method. It is performed from top to bottom and from left to right. During the scanning process, when a parallel node is encountered, it will go to the next row for scanning. The switching between rows is achieved by the transformation of the pointer. The pointer at the original position is pre-stored and waits for the parallel module to be scanned. Then start scanning from the original position. The rungs and scanning order are shown in Figure 1.
Figure 1 Ladder and scan diagram
The instruction table is composed of a series of instructions. The instructions are stored in a chain structure, and the instruction table can be traversed by reading the instructions in sequence.
3. Conversion between ladder diagram and instruction table program
3.1 Convert ladder diagram to instruction list
The ladder diagram is converted into an instruction table in units of steps.
For rungs without parallel branches, the ladder diagram can be converted into an instruction list based on the position of the ladder diagram elements in the rung and the type of the elements. For rungs containing parallel branches, you can traverse and convert them at the same time by following the method of traversing the ladder diagram. During the conversion process, first set a global variable nDepth (rung depth) to determine the depth of the rung, and then determine whether a rung contains a parallel branch. If it does, call the conversion program containing the parallel branch, and then read the ladder diagram elements at the current rung depth level in sequence; if no parallel branch is found, call the conversion program without parallel branches to convert them in sequence. During the conversion process. Add an ORB branch parallel instruction after each branch is converted.
When converting the entire ladder diagram program, first generate two global variables nLine (line number) and nDepth, then start converting from the beginning, and after converting one rung, the next rung starts from the nLine (nLine = nLine + nDepth + 1)th line until the end of the ladder diagram file.
3.2 Convert instruction table to ladder diagram
The process of converting the instruction table into a ladder diagram is the process of generating the corresponding ladder diagram element list according to the PLC instruction statement. Because the ladder diagram and the instruction table program are in a one-to-one correspondence, the corresponding ladder diagram elements can be generated according to the statement correspondence, and the corresponding relationship between the identifier and the bitmap can be established by using the bitmap resources designed in the ladder diagram to language table conversion file. During the conversion, the statement table is stored in the text file in the form of a file stream, analyzed line by line, and processed by appropriate algorithms, and the corresponding ladder diagram symbols are drawn in the window until the end of the file. In addition, during the conversion process, the program needs to be divided into several sections, each section corresponding to one rung in the ladder diagram. In the instruction table, the division of the rungs can be carried out according to the OUT instruction. The division of the series-parallel module can be carried out according to the ANB and ORB instructions.
4. Syntax analysis of soft PLC program
When compiling a PLC program, the program written in other PLC languages is first converted into an instruction list before being processed. The grammar of a programming language usually includes I groups of terminal symbols, I groups of non-terminal symbols, 1 start symbol and 1 group of production rules.
4.1 Grammar Design of Soft PLC Program
The grammar of soft PLC program mainly refers to the grammar design of PLC instruction table language. There is a one-to-one correspondence between PLC instruction table language and ladder diagram language. The instruction table program of PLC consists of several statements, each of which includes statement number, operation code and operand. The operation code is the instruction code in the PLC instruction system, including logic fetch, contact series instruction, contact parallel instruction, branch parallel instruction, branch series instruction and coil drive instruction. The operands are mainly relays, timers and counters inside PLC. The following is a PLC instruction table routine.
The design of instruction table grammar is illustrated by taking the logic instructions of Mitsubishi's F1 series as an example, and a subset of the instruction set is selected as the research object. The subset consists of basic instructions such as logic fetch instructions (LD, LDI), contact series instructions (AND, ANI), contact parallel instructions (OR, ORI), branch parallel connection instructions (ORB), branch series connection instructions (ANB) and coil drive instructions (0UT).
For ease of analysis, single lowercase letters are used to replace instructions, namely LD, LDI→a; AND, ANI→b; OR, ORI→c; ANB→d; ORB→e; 0UT→f. The grammar of the instruction table can be expressed as a quadruple (Vt, VN, S, φ), where Vt is a terminal symbol set, including {a, b, e, d, e, f}; VN is a non-terminal symbol set, including {S, H, K, A, B, D, E}; S is the start symbol; φ is the production set (@ represents an empty set).
Here, the grammar G[S] of the instruction table program is S→aHfS; S→AfS; S→@; H→EH; H→@; K→EK; K→@, A→DA; A→@; B→e; D→b; D→c; E→D; E→aKB.
From the G[S] production rule, we can deduce that the set of non-terminal symbols of the empty string is {S, H, K, A}.
4.2 Syntax Analysis of Soft PLC Program
The top-down LL(1) analysis method is used for syntax analysis. To use the LL(1) analysis method, a prediction analysis table is first constructed, and the FIRST set and FELLOW set of all non-terminal symbols are obtained.
FIRST set: FIRST(S)={a,@,b,c}; FIRST(H)={@,b,c,a}; FIRST(K)={@,b,c,a}; FIRST( A)={@,b,c}; FIRST(B)={e,d}; FIRST(D)={b,c}; FIRST(E)={b,c,a}.
FOLLOW set: FOLLOW(S)={#}; FOLLOW(H)= {f}; FOLLOW(K)={e, d}; FOLLOW(A)={f};
FOLLOW(B)={b,c,a,f,e,d}; FOLLOW(D)={b,c,f,a,e,d}; FOLLOW(E)={b,C,a, f,e,d}.
SELECT set of each production: SELECT (S→aHfS)={a}; SELECT (S→AfS)={b, c, f}; SELECT (S→@)={@, #}; SELECT (H→ EH)={b,c,a}; SELECT(H→@)={@,f}; SELECT(K→EK)={b,c,a}; SELECT(K→@)={@,e , d}; SELECT (A→DA)={b, c}; SELECT (A→@)={@, f}; SELECT (B→e)={e}; SELECT (B→d)={d }; SELECT(D→b)={b}; SELECT(D→c)={c}; SELECT(E→D)={b,c}; SELECT(E→aKB)={a}
According to the above calculation, the generated PLC grammar prediction analysis table is shown in Table 1.
Table 1 PLC grammar prediction analysis table
According to Table 1, a non-recursive prediction analysis method is adopted to construct a prediction analyzer model, as shown in Figure 2.
Figure 2 Non-recursive predictive parser model
The predictive analyzer's control program always determines the predictive analyzer's actions based on the top symbol on the stack and the current input symbol. The predictive analyzer's control program algorithm is as follows:
Set pointer ip to point to the first character of the input string
while(1)
Let X be the symbol on the top of the stack. a is the symbol pointed to by ip;
if(X is a terminal symbol or $)
if X==a
pop(X), update ip;
else
error();
else(X is a non-terminal symbol)
if M[X,a]:X—yly2?K
pop(X);
push(Y1Y2?K);
else
error();
else(X==$)
Analyze success;
break;
Among them, M[X, a] refers to the production rule at the intersection of row x and column a in the prediction analysis table.
The following example illustrates the working process of the PLC program syntax analysis program.
After replacing the instruction with lowercase letters, the program instruction becomes acababecdcf. This string is used as input and the analysis process is shown in Table 2.
Table 2 PLC program syntax analysis table
5. Implementation of soft PLC program compilation
The analysis of the PLC instruction list program is to obtain the logic of the program by interpreting the instruction list program, and to demonstrate the logical state of the program in the form of a dialog box. During the interpretation process, two variables are constructed, one for storing the logical value of the branch block, and the other for storing the logical value of the statement before the branch block. At the same time, a stack is constructed to store the results of the interpretation process. The value before the branch block is saved in the stack, and the value of the entire branch block is saved in a temporary variable.
The interpretation process of the PLC instruction table program is as follows: 1) When the interpreter finds the LD or LDI instruction, the temporary variable value is pushed into the stack, the temporary variable is assigned to 1, the temporary variable is logically ANDed with the element after the instruction, and the result is saved in the temporary variable; 2) When the interpreter finds the AND or ANI instruction, the temporary variable is ANDed with the element after the instruction, and the result is saved in the temporary variable; 3) When the interpreter finds the OR or ORI instruction, the temporary variable is ORed with the element after the instruction, and the result is saved in the temporary variable; 4) When the interpreter finds the ANB instruction, the temporary variable is ANDed with the value at the top of the stack, and the result is saved in the temporary variable, and the stack pops the top element; 5) When the interpreter finds the ORB instruction, the temporary variable is ORed with the value at the top of the stack, and the result is saved in the temporary variable, and the stack pops the top element; 6) When the interpreter finds the OUT instruction, the temporary variable is ANDed with the value at the top of the stack, and the result is saved in the temporary variable. The stack is cleared at the same time.
The simulation interface of program logic is shown in Figure 3.
Figure 3 Program logic simulation interface
The PLC elements included in the program are listed in a table by category. The different colors of the elements represent the switch status of the elements, red represents high level, and white represents low level. When the state of the input element is changed with the mouse, the state of the output element will change according to the program logic, and the result of the change can be shown by the change of color.
6. Conclusion
The logic simulation results of the soft PLC program show that the developed soft PLC compiler system can realize the mutual conversion between the soft PLC ladder diagram and the instruction table program, complete the grammar design and syntax analysis of the soft PLC program, correctly interpret the running instructions of the soft PLC program, and can run according to the working principle of the PLC, so that the PC can complete the corresponding control functions. The developed software system can easily realize the editing and logic simulation of the PLC program. The system structure is simple and easy to use. It lays a foundation for further research and development of the lower computer system of the soft PLC, continuous improvement of the functions of the soft PLC system and realization of its good control characteristics.
Previous article:Application of PLC and AC Servo System in CNC Drilling and Milling Machine
Next article:PLC-based control system for mobile robot under slurry
- Popular Resources
- Popular amplifiers
- Molex leverages SAP solutions to drive smart supply chain collaboration
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- CGD and Qorvo to jointly revolutionize motor control solutions
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Nidec Intelligent Motion is the first to launch an electric clutch ECU for two-wheeled vehicles
- Bosch and Tsinghua University renew cooperation agreement on artificial intelligence research to jointly promote the development of artificial intelligence in the industrial field
- GigaDevice unveils new MCU products, deeply unlocking industrial application scenarios with diversified products and solutions
- Advantech: Investing in Edge AI Innovation to Drive an Intelligent Future
- CGD and QORVO will revolutionize motor control solutions
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Greenhouse automatic spraying system ---- H743temperature sensor
- Hongmeng Development Board Neptune (Part 1) - Unboxing
- Can you help me find out what type of diode this is? Thank you.
- Website controlled Christmas tree
- Share: PD fast charging technology has been significantly updated, USB PD3.1 has been released, supporting 48V and 240W output
- How to choose a suitable infrared thermal imager?
- Summary of issues that should be paid attention to in analog circuit design
- Complete learning and application of analog electronic technology with examples
- [GD32L233C-START Review] + Unboxing and Building a Development Environment
- 2.5V voltage regulator circuit