(1).PLC Programming Design Requirements
A complete set of PLC program is not only to make the system can run up so simple, it also needs complete annotation, fine architecture, good scalability, complete alarm protection system, simulation system before running.
1,Simplicity
Make the PLC program as simple as possible. The meaning of simplicity is to use a standardized program framework as much as possible, as far as possible to use simple instructions. To make the program simple, from a large perspective, to optimize the program structure, with flow control instructions to simplify the program, from a small perspective, but also with a strong function of the instruction instead of a single function of the instruction, as well as pay attention to the order of the arrangement of instructions, etc., and so on.
2,Readability
Requirements of the designed program readability should be good. This not only facilitates the program designer to deepen the understanding of the program, to facilitate debugging, but also to facilitate others to read and understand your program, to facilitate user maintenance. If necessary, you can also make the program push
To make the program readable, the program designed to be as clear as possible. Pay attention to hierarchy and implement modularity to the point of designing with object-oriented methods. To use more standard designs.
If you use language programming in special cases, please use ladder programming in most cases for easy reading.
Then the IO allocation should be regular, easy to memorize and understand. If necessary, also do some annotation work. The use of internal devices should also be regular, not randomly used.
Readability should be noted at the beginning of the program design. This is not easy to do. Because in the process of program debugging, the increase or decrease of instructions, the use of internal devices change, may make the original clearer program, become a bit chaotic. So in the design of the debugging of the increase or decrease to leave some room, and then debugging is completed and then do a bit of organization, so that the design of the program has a higher quality!
program comments, at least there should be the following aspects:
A. System Notes: the copyright of the entire program company and the use of this set of programs
B. Program block comments: the main purpose of the block and the author of the program
C. paragraph comments: the use of this code
D. Variable comments: the importance of the need to say, including / 0 comments, intermediate variable comments

And as for confidentiality considerations, I think they should be considered in the encryption algorithm of the program or the encryption of the blocks, and not in such a clever way as reducing comments.
3,Correctness
PLC program must be correct, and should be verified by actual work to prove that it can work correctly. This is the most fundamental requirement of the PLC program, if this point can not be done, the other good and useless.
To make the program correct, must be accurate use of instructions, the correct use of internal devices. Accurate use of instructions and accurate understanding of the instructions are linked to the meaning of the instructions and the use of the conditions must be clear. If necessary, you can make some small programs to test some unclear instructions.
For the same instruction, some details of the instruction may be different due to the different batches of PLC from the factory or the different models of PLC series, so you should check the programming manual carefully.
The correct use of internal devices is also important. For example, some PLCs have power-down protection, while others do not. Be sure to do the power-down protection must be used to protect the device, and vice versa can not be used.
In short, to accurately use the instructions, the correct use of internal devices, so that the program can be programmed to work correctly, which is the most fundamental requirement of the PLC program, as a simple example, Siemens needs to use the rising edge and the lower rung with the storage function of the variable as an intermediate variable, such as the M point or the DB point, if you use the FC temp variable will be a problem.
4,Reliability
The program should not only be correct, but also reliable. Reliability reflects the stability of the PLC program, which is also the basic requirements of the PLC program.
Some PLC programs, under normal operating conditions or legal operation can work correctly, and the emergence of non-normal operating conditions (such as temporary power outages, and then quickly re-energized) or illegal operations (such as some buttons do not follow the order of press, or at the same time, press a number of buttons), the program can not work properly. This program, it is not very reliable, or unstable, is a bad program!
Good PLC program on the emergence of non-normal operating conditions, can be identified, and can make it with the normal conditions of convergence, can make the program to adapt to a variety of situations. Good PLC program can be rejected for illegal operation, and does not leave "traces". Only legal operations are accepted.
Interlocking is a common means of rejecting illegal operations, relay circuits commonly used in this way, PLC can also inherit this method.
5. Ease of modification
To make a program easy to change, that is, to make it easy to modify. one of the characteristics of PLCs is that they are convenient and can be flexibly adapted to a variety of situations. The way to do this is by modifying or redesigning the program.
Redesigning the program is used in the case of changing the usage requirements of the PLC process, not only the program is reprogrammed, but ! /0 is also reassigned. Most cases do not require reprogramming, and a few modifications are sufficient. This requires that the program be easy to change.
Ease of modification also means flexibility, requiring only a few changes, you can achieve the purpose of changing the parameters or rationalization of the action.
6. Extensibility
Many programs may have been programmed before entering the scene, but to the scene, may also need to add another program, in order to avoid disrupting the structure of the whole system, you need to reserve a certain amount of space in each functional area as a backup.
Hardware to leave enough margin, software in the preparation of manual, automatic, semi-automatic considerations, position left out.
7, complete alarm system
PLC systems are often used in industrial environments, each accident will cause large or small losses, in order to do the accident pre-treatment or in the accident will minimize the loss, we must pay attention to PLC alarms and protections, which will be taken out as an important part of the system.
8, program simulation
In order to ensure that the commissioning of the site progress or show customers, often before entering the scene, to their own programs for fully automated simulation. For this reason, you need to add a simulation program part of the program, the simulation program part of the normal site run after the disconnect. In order to equip the program with a simulation function, the following tasks are required.
(1) Convert the actual PLC I/O points into PLC intermediate variables or data block variables.
(2) Write the simulation program for each device according to the process requirements. In the process of designing a PLC program, one that meets the requirements of the above aspects can be called a good program.
(2) PLC programming tips
(1) Select the appropriate PLC model and the number of I / 0 points, there are special functional requirements to choose a special function module.
(2) Familiarize yourself with the selected PLC programming instructions and compilation software
(3) Conduct soft component planning, including internal relays, holding relays, data registers, timers, counters, etc.
(4) for program planning, generally to fault extraction, fault processing, manual processing, automatic processing, output processing such a sequence of programming. Larger projects or equipment according to the functional unit segmentation, block processing, such as an automated production line has a hoist, moving, top up the rotating device, etc., it should be programmed according to the above unit segmentation block.
(5) in the subsection of the program written in chunks should be added before a short paragraph notes, explaining the function of this section of the program, if necessary, you can indicate the corresponding process flow. Chunks or subsections of the program and then the overall program location order should be basically in accordance with the order of the process flow, to facilitate the readability of the program.
(6) before the program design, the equipment should be abstracted, such as stop, emergency stop, overload, overload, timeout, safety light curtains, touch stops, door switches, and other common factors to extract, placed in the start-up circuit or start the main control, interlocking circuits, as a prerequisite for the entire program structure, based on which, and then divided into two major automatic, manual program functional areas.
(7) The program structure of manual functional area common factors, such as manual, endangering the personal safety of the equipment and other factors to be extracted, placed in the manual master control, interlocking circuits, manual control for protection, shielding, alarm.
(8) The program structure of the automatic functional area common factors, such as automatic, overrun, timeout and other factors to be extracted, placed in the automatic master control, interlocking circuits, automatic control of the equipment for protection, shielding, alarm. A general principle is that, under the premise of ensuring safety, strict restrictions on the entry of equipment, loose restrictions on the exit of equipment
(9) program design should be designed to program the total reset function, to facilitate the user in the event of equipment failure, can be convenient as soon as possible to restore the normal work of the equipment. Total reset should be fully considered in the reset process equipment and personnel safety.
(10) automatic mode switch to manual mode, the program should clear the automatic mode output and intermediate state, especially in the automatic mode using the SET instruction, must be cleared in manual mode with the RESET instruction.
(11) It is strictly prohibited to use double outputs in compiling the program, i.e., the same output statement or the same output coil appears 2 times or more in the program. The outputs of the same output point under different mode conditions are relayed using intermediate relays, and finally centralized together and listed to the output point.
(12) when using the touch screen, the touch screen and PLC common control area and status area, shall not do other functions of programming use.
(13) PLC's special camphor block, before using, should first find out whether its control area and status area occupies the work word, if occupied, shall not do other aspects of programming these work words.
(14) PLC inputs, outputs, intermediate relays, timers, counters, data registers, etc. should be added to the Chinese comments. Inputs and outputs should also have the component name bit number. Corresponding to the input point, the general default for the peripheral switch connected to the NO contact, for the need to connect the NC contact shall be marked in the comments. All comments should be clear, not easy to misunderstand, and minimize the use of generalized references.
(15) After the completion of the project debugging, the system must retain the final software program, save the file name should contain the project number / author / date information / version number.
(16) about program encryption: for encryption program password must have a special file to be saved, and indicate the corresponding user name + password + permission, distributed to at least two people to understand the password, to prevent the loss of the empty code to bring the inability to open the program.
(17) PLC and the host computer (or touch screen) to form a monitoring system, many times on the screen need to have "manual", "automatic" and other control modes (generally more than one can only be a time). Inside the program you can use the "MOV" command. Such as: when you choose "manual" will be constant 1 MOV to a register VB10 inside, when you choose "automatic" will be 2 MOV to the same speech register VB10. as long as the judgment of the register data is how much, we know that the system is that kind of control mode. The advantage of this idea is that it is easy to understand, without the need for interlocks and other troublesome programs.

(18) When the program has analog control, if the analog reading is basically no error, you can take the time filtering method, delay for a period of time. If the read data error is very large, it is necessary to take other filtering methods, such as calculating the average value. You can check the relevant information.
(19) in the process of program debugging (especially when the equipment transformation, your program is added to the original equipment program), when the program statements in the conditions to meet the output coil is not connected, you can check whether this section of the program is between such statements, such as JMP \go to\ and other statements. Another possibility is that after interrupting the program, if the conditions are met and the output is not turned on, the program is usually not scanned.
(20) in the sequence control program, that is, after the completion of an action, into the next action, and other similar sequential control, the use of +10 +10 control mode, I think it is very convenient to think of: preset a register, the value of 0 in the initialization, when the system is started, it +10, at this time, the register for the 10, the register is equal to the 10 can be done in the first action; the first action is completed, and then After the completion of the first action, and then the register +10, the register is equal to 20, you can do the second action, the second action is completed and then +10, the register is equal to 30, so that as long as the judgment of how much data in the register, we know that action to be completed, when the need to jump action, you can no longer +10, you can add +20 \ +30..., depending on the actual snow to be determined. Why add 10 instead of adding 1, because after adding 10, if you insert a paragraph, just choose a position at random in this 10 free space.
(21) in the design of the program, when there is a process failure (non-control system control), it is best to keep the failure phenomenon, and light sound alarm. Until the operator reset, in order to let it know that the system malfunctioned, otherwise downtime, others still think your program problems. Generally are in the design of a new system to be aware of these.
(22) For frequently called subroutines, you can make sub-modules and call them frequently.
(23) Since the production machinery in the work cycle of each step movement in the execution of a certain amount of time, and these times have a certain limit, so you can use these times as a reference to start a timer at the same time as the start of the work step movement to be detected, the timer's time setting value is 20% to 30% longer than the time that the movement will last under normal circumstances, and the output signal of the timer can be used for the The output signal of the timer can be used for alarm or automatic stop device. When the production machinery of a step action time more than the specified time to reach the corresponding timer preset time, has not been transferred to the next step action when the timer issued a fault signal, the signal to stop the normal work cycle program, start the alarm or shutdown program, which is often referred to as over beat protection.
(24) Some safety detection switches (such as emergency stop button, safety light curtains, limit switches, etc.) practical normally closed (NC) input.
(25) for safety, energy saving considerations, try to design the output to need action only when the action, once in place to stop the output, rather than designing the usual has been the output, the need to stop when the output is disconnected.
(26) The principle of the action of the executive element should be rather immobile than chaotic!
(27) single device control: a single device must have a soft manual / automatic switching and soft manual can start / stop function, by automatic switching to soft manual, the device can not stop; by soft manual switching to automatic, equipment start / stop depending on the automatic program.
(28) a single piece of equipment (pumps, fans and other large equipment) running for 24 hours.




