Setting Up a PLC Programming Environment: Configuration and Use of Bit Operations

Setting Up a PLC Programming Environment: Configuration and Use of Bit Operations

Many people keep asking me how to set up a PLC environment. To be honest, it’s really annoying! Such a basic question, and they still ask. The younger generation really… never mind. Today, I will talk to you about the PLC programming environment and those bit operations, especially Siemens, which I have been using for over a decade, so I know it inside out.

1

Common Pitfalls in Environment Setup

Let’s start with Siemens. Installing that TIA Portal software is really a hassle. Back in 2021, I was at a steel plant, and it was a real struggle. Remember one thing, never install it on the C drive! If you do, not only will it take up a lot of space, but if the system crashes later, everything will be gone. This software can easily exceed 20GB, just think about how much space that takes!

Then there’s the version issue. The old Siemens TIA V15.1 is not compatible with V16, and V16 is not fully compatible with V17, which is really frustrating. I’ve seen newbies install V17 and then open a client’s V15.1 project, and… boom, it crashes! The project files get upgraded without a backup, and it’s game over. Remember, always ask the client what version they are using before installing software! If you don’t even know this basic knowledge, what are you doing in automation? You might as well go home and grow sweet potatoes.

By the way, speaking of this, licenses are also a big pitfall. Some people think they can just crack it, but I say no way! Who dares to use a cracked version for serious projects? If something goes wrong on-site and you have to call the foreign support, and they ask for your version number, and you stutter, isn’t that asking for trouble? I usually install both V15.1 and V16 together; the company can afford it.

// Recommended installation configuration, not just randomly installed
D:\Siemens\  // Installation root directory
├── TIA_V15.1_SP1  // Most stable old version
└── TIA_V16  // New feature support

2

Bit Operations

Alright, now that the environment is set up, let’s talk about bit operations. I’ve seen the dumbest practice of defining 8 separate variables for each bit of a byte. What are you playing at? The memory of the 1200 series PLC is already limited, and doing this is just asking for trouble!

Siemens’ bit operations can be done directly by defining a Byte or Word in a DB block and accessing the bits using the dot operator, which is simple and efficient.

By the way, the old AB’s bit operations are also quite silly, insisting on using the .0, .1 format. That’s fine, at least they have a Tag. Some domestic PLCs can’t even do this right, using D0.1, who can understand that? Maintenance is a disaster. In 2020, I went to a paper mill to modify their program, and it was all written like D0.1, D0.2, thousands of lines of code, it made me want to bang my head against the wall!

My habit is to first give the bit variables a good name in the symbol table, for example:

// Symbol table definition example
Motor1_Run    DB1.DBX0.0    // Motor 1 run bit
Motor1_Error  DB1.DBX0.1    // Motor 1 error bit
Valve2_Open   DB1.DBX0.2    // Valve 2 open bit

Now let’s talk about the performance issues of bit operations. Some people like to use the MOVE instruction to assign bits to bytes and then assign bytes to bits. I just want to ask, are you out of your mind? It’s much better to use the SET and RESET instructions directly! For the old Siemens S7-300/400, a single bit operation instruction may only take 0.1 microseconds, polling it is much more efficient than your lousy loop.

3

Idiotic Operations Found On-Site

Last year, there was a guy, a graduate from a 211 university, a computer whiz, working on a system for a water plant. When I went to help, I found this fool had copied all the I/O points into a single DB block, claiming it was for “better management”… I asked him if he knew how the PLC scan cycle works. He was still unconvinced, saying his way was clearer. Clearer my foot! The scan cycle was extended by more than double, and a bunch of valves on-site were responding slowly, almost causing a major accident.

And those who like to use BOOL arrays are also ridiculous. Siemens’ Bool array access efficiency is terribly low; if you really want to access by bit, wouldn’t a BYTE or WORD array be better?

By the way, let me tell you something. Last year, I encountered an industrial control computer that crashed once every two months. After searching everywhere, it turned out that some idiot used POINTER to manipulate bits in the program, and wrote the wrong memory address, crashing the system memory. Don’t learn C language tricks when doing PLC, it’s unnecessary! Why not just use the existing bit operation instructions?

In summary, bit operations may seem simple, but there are many pitfalls. Remember these points:

First, manage bit variables using DB blocks, don’t just use the M area, because the M area will be lost when power is off. If the PLC loses power one day, you will have to start all over again; Second, naming of bit variables should be standardized, don’t use nonsensical names like Data_1, Data_2; Third, bit operations are more efficient than word operations, if you can use bits, don’t use words, it saves memory and cycles.

Alright, I’ve said so much, I don’t know how much you can take in. Anyway, this is how I do it, and I’m not charging you for training. If you ask me, the real skill is to learn from on-site mistakes, reading theory is all nonsense.

Setting Up a PLC Programming Environment: Configuration and Use of Bit Operations

Before you leave, remember to click on Looking~

Leave a Comment