More answers: Tips and tricks for next-generation automation programming

Programming instructor provides more answers from audience questions after the Control Engineering webcast, “Programming tips and tricks appropriate for next-generation applications.”

By Frank Lamb November 14, 2024
Figure 2: Programming language samples of FBD - Function Block and SFC - Sequential Function Chart are explained in the Control Engineering Sept. 10 webcast, archived for a year: “PLCs: Programming tips and tricks appropriate for next-generation applications.” This is from webcast instructor Frank B. Lamb, founder and owner of Automation Consulting LLC and creator of The Automation Primer blog and The Automation Academy. Courtesy: Automation Consulting LLC, Control Engineering

PLC programming tips, more answers, insights

  • More PLC programming advice follows the webcast, “Programming tips and tricks appropriate for next-generation applications.”
  • Additional PLC programming audience questions, not answered during the live webcast, answered by one of the instructors, PLC programming instructor, are answered here.

More tips and advice about programmable logic controller (PLC) programming follows from an instructor for the Control Engineering webcast, “Programming tips and tricks appropriate for next-generation applications.” Frank Lamb, founder and owner, Automation Consulting LLC, webcast speaker and Control Engineering Editorial Advisory Board member, provides PLC programming instruction, including the answer to the question: “What are the main languages programming that a good plc programmer must know?”

The International Electrotechnical Commission’s standard IEC 61131-3 programming languages are:

IL – Instruction List, text

LAD – Ladder Logic, graphical

FBD – Function Block, diagram graphical

ST – Structured Text, text

SFC – Sequential Function Charts, graphical.

Webcast instructors answered audience questions during the end of the PLC programming webcast, and Lamb some additional questions below.

Figure 5: Frank B. Lamb is founder and owner of Automation Consulting LLC and creator of The Automation Primer blog and The Automation Academy and member of the Control Engineering editorial advisory board. Nathan Phillips is process control engineering, APCO Inc. – Advanced Process Control and Optimization Mark T. Hoske is editor-in-chief, Control Engineering, WTWH Media, mhoske@wtwhmedia.com, and moderator for this PLC programming webcast.

Figure 5: Frank B. Lamb is founder and owner of Automation Consulting LLC and creator of The Automation Primer blog and The Automation Academy and member of the Control Engineering editorial advisory board. Nathan Phillips is process control engineering, APCO Inc. – Advanced Process Control and Optimization Mark T. Hoske is editor-in-chief, Control Engineering, WTWH Media, mhoske@wtwhmedia.com, and moderator for this PLC programming webcast. Courtesy: Control Engineering

What path should a person take who is just starting to work with PLCs but doesn’t have Ladder programming knowledge?

Use free resources on YouTube and vendor websites to learn ladder logic and other languages.

What engineering tools are available to help with modern methods of PLC programming?

While there are some commercial vendors, I have created my own tools in Microsoft Excel to aid in rapid code development.

How is artificial intelligence (AI) being used for PLC programming and machine learning?

AI can generate text-based code, commonly used for Python programming. Neural networks are used for vision (machine learning). Most professional PLC programming does not use AI, but may use commercial programs that aid in rapid development.

Could ladder logic programs be more portable to different PLCs?

While the logic works the same in ladder programs, some special instructions are custom to the platform. The IL versions of the logic also does not usually use the same mnemonics. Companies have written conversion software for specific platforms, but major manufacturers’ ladder programming is not directly portable. There is an exception: CODESYS-based ladder is portable.

What tips and recommendations do you have for communicating with manufacturing execution system (MES) software?

I have no specific advice, though something needs to translate native PLC communications to MES system protocol. Protocol converters, different drivers and field servers can help, though you may still require assistance from system integrators.

What about language standardization across platforms? It was mentioned that LLL comes with every platform but others do not.

Language implementation differs across platforms because of PLC manufacturers’ legacy [platform design] choices. The more modern the software, the more likely it is to be fully compliant with standard IEC 61131-3 control programming languages. Styling and other details are still not standardized across the major PLC manufacturers, and different manufacturers emphasize different languages.

Can you provide specific resources for online PLC programming training?

I offer online PLC training at www.automationllc.com/automation-academy.

Editor’s note: Related PLC programming Control Engineering articles include:

PLC programming fundamentals and uses in discrete manufacturing

https://www.controleng.com/articles/plc-programming-fundamentals-and-uses-in-discrete-manufacturing/

More answers on PLC projects, programming best practices

https://www.controleng.com/articles/more-answers-on-plc-projects-programming-best-practices/

PLC projects: Programming best practices, part 1: Platform, history and differences

https://www.controleng.com/articles/plc-projects-programming-best-practices-part-1-platform-history-and-differences/

PLC projects: Programming best practices, part 2: Case studies, on-address structures

https://www.controleng.com/articles/plc-projects-programming-best-practices-part-2-case-studies-on-address-structures/

PLC projects: Programming best practices, part 3: Programming best practices

https://www.controleng.com/articles/plc-projects-programming-best-practices-part-3-programming-best-practices/

PLC programming language fundamentals for improved operations, maintenance

https://www.controleng.com/articles/plc-programming-language-fundamentals-for-improved-operations-maintenance/

How do PLC programming languages interact with CIP?

Common Industrial Protocol (CIP) is an [ODVA] communication protocol, not a PLC language. Not all brands use this.

How do you see programming for building automation systems (for HVAC) differing from PLC programming?

Building automation controllers may use some text or graphic languages, but are not compliant with IEC61131-3 requirements.

Do certain programming languages work better with MES systems?

Not really, though movements of large amounts of data may be easier with Structured Text.

How do you suggest addressing the divide among programmers, users, and technical staff with these other languages? (Visual nature of LLL is easier to understand for personnel without a programming background.)

Programmers of necessity have to be very good at writing complete programs and will have language preferences. They will understand the code much more easily than maintenance personnel because they work with code regularly. Maintenance will often prefer graphical languages because they require less reading. But technicians can be trained to be comfortable with any language. Time and study are required.

Is structured text a good option if maintenance technicians need to view the PLC program?

Maintenance technicians will find graphical languages quicker to learn and easier to read usually.

Do you see companies updating PLCs to take advantage of the newer languages?

Only switching to a newer language usually is not a good reason to update a program. Newer programming costs money. Companies usually want improved efficiency or financial return to invest in program changes.

Are the younger generation even attracted to programming in the heavy industries?

I know young people in every industry. Learning to program is important, but it is just as important to understand the process/action that you are programming.

What are your observations on engineers/technicians understanding control strategies?

Understanding what you want to do helps determine what language is the best to use. Programmers are still going to be biased toward their favorite language. Understanding the process is necessary for the programmer, this is the first thing custom programmers do before designing a software project. Large custom machine builders generally do not get to choose the language they program in; both their company and their customer will usually have software specs that dictate this.

I’m a mechanical engineer having to specify and program a PLC for a fairly simple HVAC logic for blower motor control and timers. I read schematics fairly well. Is ladder logic the easiest to learn, for first-time programming?

In my opinion, in the U.S., yes. There are a lot of online resources to learn simple ladder logic [and many applications].

I am in my 50s, so I have used a lot of traditional ladder. One safety-related aspect that I like about ladder is that all rungs get scanned (typically) since writing loops is uncommon. I fear that newer text-based language is prone to creating unsafe code. Comments?

Text-based languages are still subject to scanning. If a line of code is not active, the PLC does not wait like other microprocessors, it moves on. Loops can be used in ladder also, and do not have to be used in ST. Program control instructions like Jumps are available in both also, it is up to the programmer how to use them.

Can you speak a little bit more about State Machines Technique for programming PLCs?

State machines are common and usually used for sequences. There are two types of sequence, one numerical (state machine) and one bit-based (bit-of-word.) Numerical sequences are more common.

Isn’t it harder to troubleshoot Structured Text?

Yes, for untrained people ST can be harder to troubleshoot. It requires reading and a bit of training in logic principles rather than knowledge of electrical circuits. But ST coders without an electrical background have just as difficult a time reading ladder.

Have you heard of the IEC 61499 standard and, if so, what are your thoughts on the future of this standard? It defines a generic model for distributed control systems and is based on the IEC 61131 standard.

Yes, I have seen this. It will apply more to computer and message queuing and telemetry transport (MQTT) based systems; major PLC manufacturers are not on board with this yet. I consider this more of a communication protocol thing rather than something fundamental to PLC coding.

Do you think manufacturers will adopt IEC 61499?

If they have a financial or competitive reason to do so. Again, I see this initially being adopted on computer-based systems.

As a follow-up, IEC 61499 focuses on being hardware agnostic. It also uses “event-driven” execution rather then logic/code scanning on a cyclic basis. In this respect, it requires a very different approach to programming “real-time” control.

Unfortunately, I don’t think major PLC manufacturers will allow IEC 61499 to be hardware agnostic. It will likely not be portable across PLCs any more than add-on instructions (AOIs) and function blocks (FBs) are.

Do you see more applications demanding the use of Visual Basic or C# or python in comparison to traditional vendor specific SCADA/ HMI?

A free aid to VB.Net has great graphic capability and, most importantly for me, PLC drivers. It is harder to use than SCADA/HMI software and requires a knowledge of Visual Studio. It is also shareware under the GNU license, so cannot be proprietary.

What are the benefits and learning curve when switching from ladder logic to another language?

Languages all have advantages and disadvantages. ST is useful for data and array manipulation complex formulas, etc. FBD has some instructions ladder doesn’t, like XOR [exclusive OR]. SFC lends itself to sequences.

What programming language is most easy to use to aid maintenance in troubleshooting?

In the U.S., maintenance personnel, by and large, prefer ladder.

What are the main languages programming that a good plc programmer must know?

In order of preference for me: Ladder, ST, SFC, FBD. A good programmer should know all.

There is a big push by computer scientists to move away from IEC 61131 languages, will other programming languages take over? Which ones?

Just because computer programmers prefer other languages doesn’t mean PLC manufacturers will comply. If you can program Python and C#, you can easily learn ST.

I’d like to hear thoughts on programming commenting and ways to break up the program for ease of troubleshooting.

These are standards in templates, there is a fairly standardized format for breaking up and organizing programs. I use two different schemas, one for machine control and another for process control. The are both described in my “Advanced PLC” book.

How can I generate a more flexible PLC programming?

Flexible PLC programming is best done by creating encapsulated objects such as FBs and AOIs to accomplish tasks. Reusable code is important.

Do you know if there are efforts to update standards?

Updating standards is constantly being evaluated by the IEC [and contributing standards bodies] as technology changes.

I am 33. New talent needs to have understanding of ladder logic as well as more advanced methods to ensure a smooth transition, correct? We can’t just stop using ladder on a dime.

I agree. There is a need to understand ladder logic, and there will be a transition time.

What AI are you using?

I have used all of the major AI platforms with similar results.

With increased potential complexity of functions, I feel there is also an increase in the potential of fatal faults like bricking the PLC. How would you recommend mitigating this?

There are few ideas I have on mitigating this issue. One is to test all code thoroughly before hand. Both with virtual PLC testing available with some manufacturers or having a test PLC in your possession to upload and do factory acceptance test (FAT) and other testing. It is also always good practice, especially with complicated systems and code, to have another set of eyes pass over your code and catch what you may have missed.

How do you foresee maintenance personnel being able to troubleshoot structured text?

I believe AI will be beneficial down the road with this. As well, good coding practice is to comment and document your code explicitly and extensively, and that will help as well.

Are you seeing recent graduating engineers who are interested in learning about PLCs and programming?

Yes, it takes a certain kind of person, but I feel that it is a good intermediate for engineers who like engineering, but also like coding/programming, which is becoming more common.

Do you have any recommendations for online resources to learn structured text programming?

YouTube has some great videos out there that will run you through many different situations and skills you need to know and learn. That’s what I use when in doubt.

Edited by Mark T. Hoske, editor-in-chief, Control Engineering, WTWH Media,mhoske@wtwhmedia.com and webcast moderator.

KEYWORDS

PLC programming advice, PLC programming tips

LEARNING OBJECTIVES

  • Understand that more answers about PLC programming follows the webcast, “Programming tips and tricks appropriate for next-generation applications.”
  • Review additional PLC programming audience questions from the live webcast, answered by one of the instructors, PLC programming instructor.

CONSIDER THIS

Do you know all you need to know for efficient PLC programming?

ONLINE

Miss the PLC programming webcast? It’s archived for a year after the Sept. 10 broadcast date: https://www.controleng.com/webcasts/plcs-programming-tips-and-tricks-appropriate-for-next-generation-applications/

Control Engineering provides more on control system programming.

https://www.controleng.com/control-systems/programming/


Author Bio: Frank Lamb is founder and owner of Automation Consulting LLC and member of the Control Engineering editorial advisory board.