Wednesday, September 3, 2014

Building a PLC Program That You Can Be Proud Of - Part 1

What is the best way to program a PLC? 
My answer is simple. The best way is one in which someone can look at your program and understand it. I cannot stress enough the need for good documentation of your program. The best programs are ones that I can return to after several years and understand what it is doing within a few minutes. Programs should read like a book. This will aid in troubleshooting, modifying or teaching.

 How do you approach a PLC program?
You must know everything about the logic or process before starting your program. Making a flow chart is one good method to learning the logic and process. The flow chart will bring out questions like the following:
What happens after a power outage? (In each condition of the outputs)
What happens if a sensor is not made? How long do you wait?
What are the critical items to monitor? (Ex. Air Pressure, Weight, Length, etc)
What happens...
Once you have written your program and are in the troubleshooting stage you can usually go back and add to your flow chart. Usually there is always something that needs to be added, changed or modified based upon the actual functioning of the program.
Consider each project a complete leaning opportunity.

Once you know what you want to do with the PLC and have a good understanding of the logic flow, then it is time to start coding. Remember that there is no write or wrong method to program the PLC, either the program will work or it will not work.

Let's look at an example. We will start with something that we all know how it works.
Traffic Lights

We will look at three programming examples for the lights. Two different approaches to programming will be used, but the program function is the same. The last example will modify the logic for a car being sensed.
Logic: 
First Example:
Traffic Light Program 

Sample program for traffic light intersection with lights facing North /South and West /East. 
Green is on for 5 seconds
Yellow is on for 2 seconds
Red has an overlap of 3 seconds

This program uses discrete bits and timers to accomplish this task.

The $FirstScan bit will reset the timers so if power is lost, the lights will start with Red / Red overlap before starting the sequence again.

The outputs are controlled by when the timers are on (Done) or off (Not Done)
North / South Traffic Lights
West / East Traffic Lights
You will notice that this program is fully documented and easy to understand.