Generic programming rules

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. Regardless of the software development platform, the final program must satisfy some basic requirements.

By Frank Lamb October 29, 2014

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, digital values of "On" and "Off," True or False, or 1 and 0 represents inputs and outputs. 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. Entering the tag or variable it interfaces with configures objects on that screen. Logical functions are sometimes embedded in the objects to execute when the user activates them.

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.
  • Robust: the program should anticipate problems not due to programmer error, such as incorrect input and corrupted data.
  • Usable: textual, graphical and even hardware elements should improve the clarity, intuitiveness and completeness of the user interface.
  • 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.
  • 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.
  • Efficient: the code should consume as few resources as possible, memory leaks should be eliminated and unused code deleted.

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.


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