Generic Programming Rules


I have covered a lot of material on ladder logic on this site, but not all programming is for PLCs. This is an excerpt from Industrial Automation: Hands On that applies to all programs, not just ladder ( 6.1.1 – Programming Concepts):

“Programming involves the entire process of design, coding, debugging and maintaining software. A computer program is a series of instructions that tells a computer or microprocessor to perform certain tasks. In the automation field, the processor of these instructions may be a controller, such as a PLC, DCS, embedded processor or robot controller. A computer may also execute instructions for data acquisition and display, database operations or control functions. Programs may be written in a low level, machine-specific language or in a high level machine-independent language.

In automation, inputs and outputs are represented by digital values of “On” and “Off”, True or False, or 1 and 0. Conditional statements such as “If,” “Then,” “Else,” “And” and “Or” are used in combination with variables to make statements that create the desired result. Variables are names that may represent physical I/O, data values in string, number or Boolean form or internal data. Variables may be as simple as a single letter, as in the statement “IF X AND Y, THEN Z,” or they can be more descriptive, such as in “IF Motor_On AND Button_Pressed, THEN Conveyor_On.” Descriptive variables, such as those stated in the previous sentence, are known as tags. In a dedicated controller, such as a PLC or DCS, there are usually registers dedicated to different types of data. Tags may then represent different types of data, such as bits, integers, floating point or REAL, timers and counters. Some PLC platforms allow the programmer to choose which registers are used for which data type and size memory accordingly.

The representation of a program may be text-based, using alphanumeric characters, or graphical in nature. Ladder logic, used in PLC programming, uses representations of electrical components, such as contacts and coils. Some software uses blocks similar to flow charts to program. The code inside of these blocks may take another form, such as text or ladder logic. HMI and other visual programs have a graphical representation of the screen that will be displayed to the user. Objects on that screen are configured by entering the tag or variable that it interfaces with. Logical functions are sometimes embedded in the objects to execute when they are activated by the user.

Regardless of the software development platform, the final program must satisfy some basic requirements. The program must be reliable; algorithms must produce the correct results, resources, such as buffer and data allocation size, should be correctly used, and there should be no logic errors. The program should also be robust; the program should anticipate problems not due to programmer error, such as incorrect input and corrupted data. The program should be usable; textual, graphical and even hardware elements should improve the clarity, intuitiveness and completeness of the user interface. If possible, the program should be portable; software should be able to run on all of the hardware and operating systems for which it is designed. Some software development programs only operate for the manufacturer’s proprietary hardware. The program should be maintainable; present or future developers should be able to easily modify the code for improvements or customizations, fix bugs or adapt it to new environments. Good practices and documentation during initial development help in this regard. Finally, a program should be efficient; the code should consume as few resources as possible, memory leaks should be eliminated and unused code deleted.”

Since the end of July when I finished up my last contracting job I have been working on a software development project for commercial use. After talking to a lot of software companies in the Nashville area I have decided to try and develop the prototype myself in Microsoft Excel. Much of the code supporting the application will therefore be in VBA (Visual Basic for Applications). The above rules certainly apply in this case.

I could definitely use some help in this. If anyone who reads this blog considers themselves an expert in Excel or VBA, give me a shout!


Electrical Engineer and business owner from the Nashville, Tennessee area. I also play music, Chess and Go.