Building a PLC Program That You Can Be Proud Of – Part 3

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.

Lets look at the inputs:

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.

Lets look at the outputs:

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.

Masking Inputs:

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.
Example:
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.
Thank you,
Garry



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.

How PLC Outputs Work

This post is a further follow up from my original ‘Here’s a Quick Way to Understand PLC Inputs and Outputs’. There are basically two different kinds of PLC outputs, Discrete and analog. Discrete outputs are either ‘ON’ or ‘OFF’; 1 or 0. You can think of them as a single light bulb. Analog outputs have a range to them. They are outputs that usually will control proportional valves, drive speeds, etc. They usually have one of the following signals that are outputted from the PLC: 4-20mA, 0-10VDC, 1-5VDC.

Discrete Outputs

The above diagram has three outputs. A coil, light and motor. The Ladder outputs Y0, Y1 and Y2 control the outputs respectfully. You will notice that when the Ladder output turns on, the corresponding output card bit LED turns on. This then will energise the output hardwired to the device.

The outputs are turned on or off at the end of every PLC Scan. The PLC logic is solved left to right, top to bottom in most PLCs. Physical outputs are not set / reset until an I/O refresh is performed at the end of every scan. This means that if I have a scan of 1msec, then the maximum time it will take to turn on/off the output is 1msec.

PLCs will sometimes have the ability to update the I/O in the middle of a scan. Please refer to your PLC manufacturers manual for this instruction. This can be used for updating the I/O quickly or controlling stepper drives for motors by giving them a pulse train output from the discrete PLC output. A pulse train is just a quick series of on/off states of the output.

Analog Outputs

An analog output converts a digital value to a voltage or current level that can be used to control (vary) physical outputs. In the example above we are controlling the speed of the motor. Words in the PLC will control the analog value.
Example:
4 – 20 mA current Output – 8 bit resolution
4 mA = 00000000 base 2 = 00 base 16
20 mA = 11111111 base 2 = FF base 16
For a review of numbering systems, follow the link below:
What Everybody Ought to Know About PLC (Programmable Logic Controller) Numbering Systems

In the industrial environment noise from variable frequency drives, improper grounding, etc. can interfere with your analog input. The following post will show a quick method to reduce this noise.
The Secret Of Getting Rid Of Noise On Your Analog Signal

Previous Post:
How PLC Inputs Work

Watch on YouTube : How PLC Outputs Work

If you have any questions or need further information please contact me.
Thank you,
Garry



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.