Traffic light on PLC - all languages IEC 61131-3
In the last article, Traffic Light on PLC - 30 blocks, the program for PLC traffic lights was written only in FBD. The new program uses all 5 languages of the IEC 61131-3 standard. The first section on IL . This is an assembler-like language. There are only 2 lines in the section: LD - load the value in the battery S - setting the variable to true if the battery is true, otherwise the variable does not change. The pulse generator with a period of 0.5 seconds is written in FBD , as in the previous version. The main section is written in SFC . It seems to me that this is the most difficult language to use in the IEC 61131-3 standard. The program consists of steps and transitions. When the program starts, the Init step is executed. The next step is performed if the transition transition is true. The step can be performed with a delay, the step time can be limited. In the figure below, only one transition contains a condition. The remaining transitions are always performed. At the end of the chain, an unconditional jump to the WaitPeople label is performed. Each step is performed with a delay corresponding to the required time of the traffic light in a given state. Each step performs a specific action. In my program, the execution of a section in the ST language is specified. In the project, the uState variable is added, corresponding to the state of the traffic light. Here are the contents of all sections performed in steps: The section on ST , depending on the state of uState, writes the value to boolean variables, which will then be written to the outputs. This could be done in the stStep_1..stStep_8 sections, but then you would not see the CASE operator and would not understand that ST is the closest language for a programmer from IEC 61131-3. Also in this section introduced protection against software errors in the form of flashing yellow in an uncertain state. The LD language is close to ladder logic. The basis of LD - contacts and coils. The diagram shows that the conductor is located on the left, from which the “voltage” (true) is distributed to the right along the branches. A normally open contact (similar to a capacitor) closes if the variable associated with it is true. A normally closed contact (similar to a capacitor with a slash inside) closes if the variable associated with it is false. A coil (2 brackets) passes the “voltage” through itself and rewrites its value (false or true) into the variable bound to it. In the program, this section is used to rewrite intermediate variables into variables associated with the outputs, with protection against a program error. Green light is illuminated only if there is no red at this traffic light and green at another traffic light. The result of the program:
The use of all 5 languages in one program is not justified. But in real projects sometimes you have to use 2..3 languages simultaneously. Most of the time, I use ST, less often FBD, even less so IL. I did not have to use SFC and LD in real projects.
UPD. Made a correction - removed an extra zero from the name of the standard by the remark RouR