⬆️ ⬇️

PLC - what is it?

Good day, dear residents of Habr!

After reading the post about programming a Siemens PLC of the S7 series , I climbed into the search for Habr, and was very surprised that the topic of industrial automation in general, and PLC programming in particular, was covered very, very poorly. I will take the liberty to share my experience in this field by describing the basic principles of PLC programming, in particular, from Beckhoff .





Introduction


I am engaged in building automation. It so happened that basically we build our systems on the basis of the Beckhoff PLC. This choice was made primarily because these controllers are free-programmable in the full sense of these words. What does it mean? Take the TAC Xenta controller, for example, and try on it to implement the exchange with an external device via RS232 using your own protocol, at the level “sent byte - received byte”. It does not work, these controllers do not know how - use only those protocols that the developer laid down in them. And Beckhoff can. But before you go into such a jungle, let's look at the development environment? In which, in fact, language, we will write?



IEC 61131-3 standard


Industrial PLCs are programmed in the languages ​​of the IEC 61131-3 standard. All these languages ​​are 5, some manufacturers add their own. Languages ​​are completely different from each other, and, watching colleagues, I can assume that the choice of a particular language is primarily related to what a person did before he came to this industry.

')

  1. IL, instruction list, list of instructions. Looks like an assembler. I did not see anyone who would use it, but I suspect that old-school coders who have punched memory cards will appreciate it.
  2. LD, ladder diagram. Visual language, for those who were engaged in the development of relay automation schemes.
  3. ST, structured text. Most reminiscent of "classic" programming languages, something similar to Pascal. This is why it is appreciated by those who, prior to the PLC, were engaged in programming in other languages ​​and platforms, in particular - by me.
  4. FBD, functional block diagram. Such a block diagram, we love first of all technologists who have decided to go into programming, for their clarity.
  5. SFC, sequential function chart. Graphic language, I will not say anything else. Never seen to be used.




Among not all supported languages, CFC (continuous flow chart) is worth noting, Beckhoff supports it. This further development of the FBD language, one of the most significant differences, in my opinion, is support for explicit feedback in the circuits. Why do you need it? For example, such a short pulse generator at CFC will work, but not at FBD.



The TON block is a standard block with a delayed on timer. Operation logic: output Q becomes TRUE, when the IN input is TRUE for at least PT time.

Perhaps the most popular development environment for PLC is CoDeSys . Many manufacturers take it as a basis, and either make a library for it to work with their PLC, or finish the environment for themselves.



How does the PLC work?


The PLC program operates cyclically. The cycle time can be from units of milliseconds to units of seconds, depending on the tasks assigned to this PLC. Most PLCs allow you to set the cycle time for the program developer, but in some models this is not possible. Many PLCs, in particular Beckhoff, allow you to create more than one cyclically executed task in one program and set the priority for these tasks. What gives us this opportunity?

Imagine the situation: the PLC controls the ventilation unit and the control panel is connected to it via RS232. The temperature in the rooms does not change quickly, and it simply does not make sense to launch the ventilation control algorithm more than once every 50–100 ms. But the operator panel polls the controller continuously, and the PLC response delay of more than 10 ms is already expressed in the “slowing down” of the user interface, and with a delay of 20 ms, the COM-port buffer will overflow. The presence of several tasks allows us to solve this problem beautifully: let the “fast” task work with the COM port, and be called every 2 ms, and the “slow” implements the logic of the ventilation, and it is called every 50 ms. Everything works well, the operator panel does not slow down, the user is satisfied.



And what of these glands inside?


It's all very, very dependent on the manufacturer. Someone makes his embedded platform on a RISC processor (for example, the domestic Aries) - this approach is very popular. Beckhoff went a different way - Windows CE 5.0 is installed on their PLCs (and if you update the firmware from the official site, then 6.0), or Windows XP Embedded, and the PLC task works as a service. Quite an interesting counter-argument for those who like to talk about the instability of Windows.

But this is the “head” of the controller, and in fact it still needs inputs and outputs to communicate with the outside world. There are two approaches:

  1. You can do “all in one box” - a head, a certain set of inputs / outputs, several configuration options - here we have more inputs, here are smaller, the head is more powerful, here is weaker. So do, for example, Carel , and many others. On a small project, such an approach justifies itself in something.
  2. But personally it seems to me that a different approach gives greater flexibility. The head is separate, and the type-setting "tail" of I / O modules is connected to it via the bus. We put those modules that we need, and in the quantities that we need. So do Beckhoff and Siemens, for example.


image

This is what the “all in one box” approach looks like. Photo: Carel pCO3.



image

But another option is the Beckhoff head of the CX9000 series (on the left of the photo) with a set of I / O modules.



In addition, there is still a certain tire on the head, which allows to unite the PLC into a network, and often also to change its program through the same network. What kind of network it will be depends on the PLC. It may be unfamiliar to those who have not come across industrial networks EIA-485 , Profibus , CAN , and maybe quite familiar Ethernet. It is through this network, called fieldbus, that the PLC is connected to the upper level - to the SCADA system, for example. In the photo above, you can see 2 8P8C connectors on Beckhoff’s head - this is Ethernet, and Carel has two 6P4C connectors at the top left (not so good, really) - they did RS-485. This interface, unfortunately, does not have a generally accepted connector.



So nevertheless, how to write programs for it?


In general, this topic is not an article, but a whole book. But I will tell what I saw on personal experience, and let it be a fly in the ointment.

For professional programmers, mastering PLC in many ways will seem like degradation. OOP? We do not have them, there are only structures, enumerations, and a kind of class, which is called a “functional block”. What is Private, Public, etc., too, can be forgotten immediately - not useful. From anywhere in your program, you can access any other place.

Dynamic memory allocation? We do not have them at all. Not sure how much data you will be sent to? Select a buffer with a margin, and forget about this memory - it will not be able to free it. Either show speed wonders and process data on the fly, if you manage to keep within the specified cycle time.

Exceptions? What did you ... I saw one miracle, which tightly hung in the construction of the form:

foo, bar: int; baz: real; foo := 2000; bar := 2000; baz := INT_TO_REAL (foo * bar); 


It is clear that the overflow does not fit foo * bar into 16 bits, but why hang something? Yes, even so that nothing but a reset on food does not help.

Development environment? Not all CoDeSys, many people want to originate and write their own thread. One of these samopisnyh environments crashed with a runtime error while trying to write the number 86400 to a 16-bit INT. And you say exception handling on the PLC. It and in a development environment not always normally can make.



BUT! But for lovers of the thin line that separates the iron from the software, software in common parlance - this is a very interesting branch of IT, it is true.



Hope this short review will be helpful. If this topic is interesting to the community, I will tell you more about the PLC.

Source: https://habr.com/ru/post/139425/



All Articles