In part 1 we looked at writing PLC programs to control a traffic light using discrete bits and then using timed sequencing using indirect addressing. Part 2 used indirect addressing for inputs as well as output to control the sequence of pneumatic (air) cylinders in the program. We will now return to the traffic light application and expand our program significantly.
Let’s build on the traffic light sequencing used in part one with inputs for pedestrian and car detection. We will also throw in the time of day so that during weekday peak hours an advanced arrow will be used. Advanced green (flashing) will be used when the traffic is detected in the turning lane during the off peak hours.
Programming using this method of sequencing requires allot of time up front before we start the actual PLC program. However this method makes the program easier to understand, troubleshoot and modify in the future.
Remember that the PLC programmer must know everything about the machine and operation before programming.
If we just start writing code, then we will constantly be correcting and modifying based on trial and error. I use a spreadsheet program to plot out the inputs, outputs and mask tables. We will go into the details of this below.
We set up the input table in words V0 to V499. Each bit in the table will be compared to the signals coming the actual signals wired or programmed in the PLC.
Bit 0 is the time input which will control the entire program interval. Next we have the Car Detection signals on Bits 1 to 4. The pedestrian signals are pushbuttons coming from Bits 5 and 6. The left turn signals are located in Bits 7 to 10. The real time clock functions will come from Bits 12 to 15.
The output table will be in words V1000 to V1499. The input word will be compared to the actual inputs and the corresponding output channel will be moved to the actual outputs. All of the output bits control lights. You will notice that there is a green light for each direction. This will give us the greatest flexibility when writing our PLC program. Pedestrian signals have a flashing output bit and just an output bit. There will be only one output but this bit will determine if it is flashing or not.
The masking table will be in words V500 to V999. The masking bits will correspond directly to the input table bits. Using the mask will allow us to ignore the status of certain bits when using the compare instruction and setting the outputs.
The Mask table will be used by using an ‘AND’ word instruction. If the mask bit is on for the input then it will be used in the compare instruction. If the mask bit is off for the input then the value is always off using the compare.
1 ‘AND’ 1 = 1
1 ‘AND’ 0 = 0
0’AND’ 1 = 0
0 ‘AND’ 0 = 0
Once we have this all laid out in the spreadsheet, we can start filling out our sequence of events. Fill in the events based upon the time frame from input bit 0. I usually start by thinking about what happens when power is applied to the unit the first time. This exercise can be a struggle because you must know exactly what you want the sequence to be in order to fill out the table.
We will continue this next time by writing the code to do what our tables want. A review of the numbering systems can be found on this post. A copy of the spreadsheet can be obtained at the following link: PLC Traffic Sequence
Part 4 will continue with the programming of the logic in the PLC.
If you have any questions or need further information please contact me.
If you’re like most of my readers, you’re committed to learning about technology. Numbering systems used in PLC’s are not difficult to learn and understand. We will walk through the numbering systems used in PLCs. This includes Bits, Decimal, Hexadecimal, ASCII and Floating Point.
To get this free article, subscribe to my free email newsletter.
Use the information to inform other people how numbering systems work. Sign up now.
The ‘Robust Data Logging for Free’ eBook is also available as a free download. The link is included when you subscribe to ACC Automation.