First and foremost, you need to get your very own PLC to work with. Computer programming of any kind is not a spectator sport, and can only be learned by significant investment of time and effort at the keyboard. In many ways, learning to program is like learning a new spoken or written language: there is new vocabulary and new grammatical rules to master, and many ways to make mistakes.
Fortunately, many low-cost PLCs exist on the market for individuals to purchase. My own personal favorites are the “CLICK” PLC models manufactured by Koyo and marketed through Automation Direct, and also the Allen-Bradley MicroLogix series of PLC (especially the 1000 and 1100 models).
The first document you should read once you get your PLC is something called a Getting Started guide. Every PLC manufacturer publishes a document with this name (or something similar such as Quick Start or Getting Results). This manual will step you through all the basic procedures for entering a simple program into your PLC and getting it to run. It is generally far easier to learn programming by copying and adapting a worked example than it is to start from a “blank page” on your own, just as it is easiest to learn a spoken or written language by practicing sentences spoken in that language by other people before constructing your own sentences from scratch.
In order to work with your PLC, you will need a convenient way to simulate different input conditions coming from discrete (switch) devices. Any set of hand-operated switches will do, my recommendation being household light switches (very inexpensive and rugged). Attaching an array of these switches to a wooden board along with the PLC and interconnecting terminal blocks forms what is often called a PLC trainer. The following photograph shows one such trainer33 , using an Allen-Bradley MicroLogix 1000 PLC:
Another example of a student-built PLC trainer is this unit, housed inside of an attaché case. Not only does this trainer contain an Allen-Bradley MicroLogix 1100 PLC along with input switches and output indicator lights, but it also includes an HMI touch-screen panel on a fold-down bracket:
The educational value of building your own PLC trainer is difficult to overstate when learning about PLCs. Learning how to build properly-functioning I/O circuits is every bit as important to a working technician as learning how to develop PLC programs. Additionally, the experience gained in general wiring layout and fabrication are valuable skills for any instrumentation practitioner.
Once you have learned the basic steps for entering, running, and saving a PLC program, you are ready to begin building your knowledge of the language’s vocabulary and grammar. In computer programming (of all types), there are different functions of the language one must become familiar with in order to do useful tasks. A great way to learn how to use these functions is to create your own “demonstration” programs illustrating the use of each function.
For example, if you open up the pages of almost any computer programming book, somewhere near the beginning you will find a demonstration program called “Hello World!” The purpose of a “Hello World!” program is to do nothing more than display the words Hello World! on the computer screen. It is an entirely useless program to run, but it is highly useful for gaining teaching the programmer the basics of program construction and text message functionality.
By the same token, you may learn the basics of each programming function by writing simple “Hello World”-type programs illustrating each one of those functions. These demonstration programs will not serve any useful purpose (other than to help you learn), and should be kept as simple as possible in order to minimize confusion.
For example, every PLC provides instructions to perform the following tasks:
- Turn discrete outputs on and off
- Count discrete events
- Time events
- Control events in a specific sequence
- Compare numerical values (greater than, less than, equal, not equal)
- Perform arithmetic functions
Just as every spoken or written language has verbs, nouns, adjectives, and adverbs to describe actions and things, every PLC programming language has specific functions to perform useful tasks. The details of how to perform each function will vary somewhat between PLC manufacturers and models, but the overall functions are quite similar. The reference manuals provided for your PLC will describe in detail how to use each function. Your task is to write simple demonstration programs for each function, allowing you to directly explore how each function works, and to gain an understanding of each function by observing its behavior and also by making (inevitable) mistakes.
After writing each demonstration program, you should add a lot of comments to it, so you will be able to understand what you did later when you go back to your demonstration program for reference. These comments should cover the following points:
- Proper use of the function
- A verbal description of what the function does
- A list of possible (practical) uses for the function
- Idiosyncrasies of the function (i.e. odd or unexpected behavior, tricky points to watch out for)
- Mistakes you may have made (and thus might make again!) in using the function
Years ago when I was teaching myself how to program using the C language, I wrote a set of “tutorial” programs demonstrating common programming functions and techniques. The following is a partial list of these tutorial programs, which I still keep to this day:
- Program that accepts and then prints alphanumeric characters (including their equivalent numerical values)
- Program demonstrating how to use command-line arguments to the main() function
- Program demonstrating basic “curses” commands for plotting characters at arbitrary locations on the screen
- Program illustrating the declaration and use of data structures
- Program illustrating how to prototype and then call functions (subroutines)
- Program executing an infinite loop
- Program illustrating how to return a pointer from a function
Each one of these tutorial programs is heavily commented, to explain to myself in my own words how they work and what they are doing. Not only did they help me learn how to write programs in C, but they also serve as a handy reference for me any time in the future I need to refresh my knowledge. The act of writing tutorial programs is akin to journaling as a way to work through complex problems in life – in a way, it is like having a conversation with yourself.
12.11 Review of fundamental principles
Shown here is a partial listing of principles applied in the subject matter of this chapter, given for the purpose of expanding the reader’s view of this chapter’s concepts and of their general inter-relationships with concepts elsewhere in the book. Your abilities as a problem-solver and as a life-long learner will be greatly enhanced by mastering the applications of these principles to a wide variety of topics, the more varied the better.
- “Normal” switch status: the “normal” status of a switch contact as defined by the manufacturer is its resting condition (minimum stimulus).
- “Seal-in” circuit: when an electrical relay uses one of its own switch contacts to continue its own coil energization after the initial triggering event has passed. Relevant to all manner of relay control circuits.
- Sourcing versus sinking: whether the electronic device in question is outputting (conventional flow) current or inputting current. Relevant to the proper connection of discrete DC input and output cards.
References
“1758 PLC-5 Programmable Controllers Addressing Reference Manual”, Publication 5000-6.4.4, Allen-Bradley Company, Inc., Milwaukee, WI, 1995.
“Allen-Bradley I/O Modules Wiring Diagrams”, Publication CIG-WD001A-EN-P, Rockwell Automation, Inc., Milwaukee, WI, 2005.
IEC 61131-3, “International Standard, Programmable Controllers – Part 3: Programming Languages”, Edition 2.0, International Electrotechnical Commission, Geneva, Switzerland, 2003.
“Logix5000 Controllers I/O and Tag Data”, Publication 1756-PM004B-EN-P, Rockwell Automation, Inc., Milwaukee, WI, 2008.
“Programming with STEP 7”, Siemens AG, Nürnberg, Germany, 2006.
“S7-200 Programmable Controller System Manual”, Order Number 6ES7298-8FA24-8BH0, Edition 09/2007, Siemens AG, Nürnberg, Germany, 2007.
“SLC 500 Family of Programmable Controllers Addressing Reference Manual”, Publication 5000-6.4.23, Allen-Bradley Company, Inc., Milwaukee, WI, 1995.
“SLC 500 Modular Hardware Style User Manual”, Publication 1747-UM011E-EN-P, Rockwell Automation, Inc., Milwaukee, WI, 2004.