Ladder Logic in Action
Ladder logic programming for industrial controllers has evolved significantly over the past 30 years, and now supports advanced functionality such as process control, motion control, data manipulation, networking, and data acquisition. However, when you start with a blank page to design a new control system, large or small, there are many basic functions this tried-and-true language is still asked to perform, and in fact, perform effortlessly.
Most every controls designer has implemented at least one of these functions in every system they have commissioned. Even when moving from one supplier’s platform to another, the ladder code design can be copied and adjusted for the particular controller, becoming tested “building blocks” of logic to speed up programming and reduce troubleshooting time. Let’s look at some of the most common control system functions and some practical ways to implement them.
One of the most pervasive functions of a control system is detecting the presence of an object. Whether you are detecting the presence of an object passing by on a conveyor, the closure of a gate, or the presence of a machine part as it goes through its motions, object detection is a staple of the automation industry. There are a myriad of object sensing technologies, such as mechanical, inductive, capacitive and ultrasonic devices that detect nearness (proximity); and photoelectric sensing using light beams.
The most basic sensor is a limit switch, an electromechanical device used to detect the presence or absence of an object. The switch operates its set of contacts when its actuator comes into physical contact with the sensed object. Actuator styles offer application-specific means of contact – rollers, levers, springs, wands, plungers, etc. However, since they consist of moving parts, they are prone to wear and damage; making physical contact with the sensed object is not always desirable or possible.
Inductive Proximity Switches
Inductive proximity switches are the most common and inexpensive non-contact sensing technology, used to detect the presence of metallic objects without actually touching it. Their high-speed switching and small size make them indispensable in automation applications. Inductive proximity switches consist of a coil driven by an oscillator. The oscillator creates an electromagnetic field that appears at the active face of the switch. If a metal target enters this area, the electromagnetic field is reduced and the switch turns on or off. Some typical inductive sensor applications are counting metallic objects, monitoring the position of elements in a machine, sensing the presence of metallic parts like screws, etc., and measuring rotational speed.
Proximity sensors typically come in shielded and unshielded styles. With a shielded proximity sensor, the face of the sensor can be mounted flush with metal, whereas an unshielded sensor should NOT be mounted flush with metal (otherwise the sensor will always be ON). In many applications, flush mounting is a requirement. Note that unshielded proximity sensors allow for greater sensing distances. Typical sensing ranges for inductive proximity sensors vary from 1 to 35mm.
Capacitive sensors detect objects with a dielectric constant different from air, which makes them ideal for a much wider range of material detection, such as wood, liquids and plastic. Their operation is similar to inductive sensors, but instead creating an electrostatic field (vs. electromagnetic) that is changed by the presence of the object. Capacitive sensing ranges can typically reach up to 40mm.
Ultrasonic proximity sensors are based on the emission of a sound impulse and the measurement of the time elapsing of the return echo signal reflected by the detected object. The ultrasonic beam is well reflected by almost all materials (metal, wood, plastic, glass, liquid, etc.) and is not affected by colored, transparent, or shiny objects. This allows the user to standardize on one sensor for many materials without any extra setup or sensing concerns. This sensing technology typically offers ranges up to 6 meters.
Photoelectric sensors use a variety of sensing technologies that address diverse application configurations, all using light beams as the detecting medium. The three most popular are diffuse, reflective and through-beam styles. The light source used – visible, infrared, LED, laser – will affect the sensing distance.
In diffuse sensors, the emitter and receiver form part of the same unit. The optical beams are either parallel or slightly converging. The presence of an object in the optical field causes diffused reflection of the luminous beam. The receiver detects the reflection from the object itself. The reflective properties of the object are important. It is generally possible to reliably detect the presence of any object unless it is perfectly reflective or black. Diffuse sensors offer a typical sensing range of up to approximately 2 meters.
A reflective sensor also houses the emitter and receiver in the same unit, with the optical beams being parallel. The emitter’s luminous beam hits a reflector mounted on the opposite side of the object’s travel path and is redirected toward the receiver. Detection occurs when the path of the beam is interrupted by the presence of an opaque object. Operating distance mainly depends on the quality of the reflector used and on the optical-beam angle; ranges are typically up to 15 meters.
With through-beam sensors, the emitter and receiver are housed in two separate units and are installed in line with each other on either side of the object path. Detection occurs when the beam is interrupted by the presence of an opaque object. This style is the most accurate, with the farthest sensing ranges, up to 30 meters, and 50 meters or longer when using laser sensors.
Object Detection + Ladder Logic
So how does this look in Ladder Logic? Well, once the sensor has been wired to the input module and the module has been configured in the software’s hardware configuration (done automatically with the auto-discover feature), the PLC CPU will assign a memory location to it. In the image below, you can see that the Productivity2000, which is a tag name-based controller, has assigned the names DI-0.1.1.1, DI-0.1.1.2, DI-0.1.1.5 and DI-0.1.1.6 to the sensor inputs. These tag names identify the type of module (DI = discrete input), base group (DI-0 = local base, DI-1 = remote base), expansion rack number (DI-0.1 = 1st rack in local base group, DI-1.2 would be 2nd rack in the remote base group), slot of base the module is in (DI-0.1.1 = slot 1, DI-0.1.5 = slot 5, etc.) and the point on the module the sensor is wired to (for our example the sensors are wired to points 1, 2, 5, and 6). The programmer can easily change these to more meaningful names.
Click on image to view larger or click here.
Four normally-open contacts are then added to four individual rungs in the main program of the ladder code. These contacts are assigned the tag names that were configured for our object detection sensors.
Normally-closed contacts and edge-driven contacts could have also been chosen. As you can see in rung 4, when the sensor detects an object, the contact will change state and the rung will activate the C3 output coil. This coil is an internal bit but if a discrete output module is installed, this coil can be programmed as a physical output used to activate an alarm, turn on a light, fire a diverter arm, etc.
To learn more, see this series of videos on the different types of sensing technologies and their suitable application spaces; see typical ladder logic programming for detecting objects with CLICK, Do-more and Productivity series PLCs.
A more advanced object detection function involves measuring the actual distance of an object from the sensing point. Ultrasonic sensors and laser distance sensors are commonly used to measure how far away an object is, out to 100 meters and beyond. Laser devices can be incredibly accurate, with resolutions down to 8um.
Ultrasonic sensors use sound waves to measure distance, sending out a burst of audio energy and waiting for it to return. Given the rate sound travels through air, the distance is just the time it takes for the energy to get to the object and back to the sensor, divided by two. Using sonic energy, these sensors do not have issues with things that plague optical sensors like smoke, dust, fog and steam. Conversely, they can be less effective in environments with high vibration.
Ultrasonic sensors fill the gap between laser distance sensors, which have long ranges but are more expensive, and proximity sensors, which have very short ranges and are typically inexpensive. Ultrasonic sensors can measure distances up to several meters, which is all that is needed in many applications such as bulk material distance measurements.
Laser sensors use highly-focused (coherent) light beams to perform distance measurement. Techniques include triangulation, time of flight, phase-shift and frequency modulation. Laser sensors for industrial use typically employ time of flight (transit time), similar to the ultrasonic method in that they measure the time it takes the laser pulse from the emitting device to reach the target and return.
Typical laser distance sensors come in two power ranges referred to as Class-I and Class-II lasers. The main difference is Class-I lasers have a maximum output of 0.5 mW, where Class-II lasers can have up to 1mW of output. In an industrial environment with subdued lighting, the Class-I laser devices will work just fine. But, if in a brightly lit area the more powerful Class-II laser may warrant consideration. Keep in mind that the safety requirements are different for each. Class-I lasers are considered safe from creating any potential hazards. Class-II lasers are also considered safe because of the assumption that your eye’s blink reflex will protect you. You probably don’t want to be the one that tests that, so you will want to be sure the Class-II laser is not used where potential eye contact can be made either directly or via reflection.
The extreme resolution and fast response time of a laser sensor make it ideal for precision measurements, such as thin film thickness, or even detecting the diameter of rolls of film.
One issue with laser sensors is since they depend on visible light, they have a tough time detecting transparent objects like glass, plastic bottles, etc. Laser sensors will also suffer in environments with lots of dust and particulates floating in the air, since they have to ‘see’ the object, and they have different responses depending on the color of the object. Some objects reflect laser light better than others.
Distance Measurement + Ladder Logic
Now, let’s look at some distance values in Ladder Logic. Laser and ultrasonic distance sensors provide an analog value to the PLC; therefore, they will need to be wired to an analog input module. For this example, the CLICK PLC will be used. The CLICK PLC does offer the auto-discover feature and once the modules have been installed, the PLC CPU will recognize all of the I/O modules available. Since these inputs are analog, we will need to scale them appropriately. With the CLICK PLC, analog scaling can be done in the system configuration as seen below. Our ultrasonic sensor is connected to channel one of the C0-04AD-1 analog input card. The raw analog (4-20mA) input value from this channel is scaled to a range of 3 to 12 inches and is stored in memory location DF1.
Click on image to view larger or click here.
Now that the input has been wired, configured, and scaled, it can be used in the ladder code. Below is the ladder program and you can see that the ultrasonic sensor input is being compared to a static value (8 inches) on rung one. The compare contact is provided by the software and the output of the comparison is connected to a physical output coil. As mentioned previously, this output can be used to turn on a light, activate an alarm, open a valve, etc.
Click on image to view larger or click here.
With this series of videos, you will learn more about distance measuring technologies including ultrasonic and laser sensors; selecting the correct measuring style depending on the environment and object types; how to set up and use distance sensors, see typical ladder logic programming for distance measuring with CLICK, Do-more and Productivity series PLCs.
A/C Motors (On/Off Control)
Most control systems have to make things move, and that usually involves motors. Lifting, pumping, robotics, conveyors, fans – pretty much everything uses a motor of some kind. General purpose three-phase AC motors are great for simple on/off systems, and Inverter-duty motors are specifically designed for operation with variable frequency drives, or VFDs.
General Purpose Motors
General purpose motors are typically connected to the main power circuit with a master circuit breaker or fuses, and use contactors to enable and disable the power to the motor; overloads protect your equipment from unexpected overcurrent/overheating that can be caused by jams or breakdowns.
A motor starter is a combination of devices used to start, run, and stop an induction motor based on commands from an operator or a controller. The motor starter must have at least two components to operate: a contactor to open or close the flow of energy to the motor, and an overload relay to protect the motor against thermal overload.
A contactor is a 3-pole electromechanical switch whose contacts are closed by applying voltage to a coil. When the coil is energized, the contacts are closed, and remain closed, until the coil is de-energized. The contactor is specifically designed for motor control, but can be used for other purposes such as resistive and lighting loads. Since a motor has inductance, breaking the current is more difficult, so the contactor has both a horsepower and current rating that needs to be adhered to.
The overload relay is a device that has three current sensing elements and protects the motor from an overcurrent. Each phase going from the contactor to the motor passes through an overload relay current-sensing element. The overload relay has a selectable current setting based on the full load amp rating of the motor. If the overload current exceeds the setting of the relay for a sufficient length of time, a set of contacts opens to protect the motor from damage.
Since the signals between the contactor and PLC are inductive, it is incredibly important to protect your control system from power surges and inductive kickback. Surge protection comes in several different types – Diode, Transorb, RC networks. Which one you use depends on your application. Diodes are great if you have a DC circuit – they will offer the maximum protection BUT increase the time it takes to turn the motor off. Transorbs are great for AC or DC circuits, are inexpensive, and have a medium to short delay but only attenuate surges above their rated value, which can be above the threshold allowed by the PLC’s I/O. RC circuits mostly filter noise and are not terribly effective for true surge protection.
Some control systems require that the motor be reversible. On a three-phase motor that simply involves swapping any two of the three wires. Reversing kits are bus bars that are pre-wired to perform the wire swapping function and some even include extra wiring to help protect against trying to drive the motor in both directions at the same time.
AC motor On/Off + Ladder Logic
In its simplest form, the ladder code to start an AC motor uses a start input to activate an output wired to a motor contactor. The image below is from a Do-more PLC and it shows how a start contact is used to activate the forward motor contactor. This start contact is controlled by a C-more HMI. The HMI will close the normally open start contact in rung one whenever the Start button on the HMI screen is pressed, and the motor will start in the forward direction.
Click on image to view larger or click here.
In reality, most motor starter code is not that simple. There are a lot of other factors involved with starting a motor. The next image shows some of the possible permissive bits that can be used to start/stop a motor. You can see that a MOTOR_COASTING bit has been added. This bit will block the start command when the motor is still coasting to a stop. The MOTOR_STOP_BTN contact is added to stop the motor from starting when it is being requested to stop. A REVERSE_ACTIVE bit is added so the motor does not start in the forward direction when already started in reverse. The OVERLOAD_STATUS contact will stop the motor if an overload condition is detected. The CB_STATUS contact doesn’t allow the CPU to attempt a start when there is no power applied to the contactor. A “seal-in” or “latching” bit is also added below the rung to keep the motor running once the contactor is closed. The seal can be broken by any of the contacts to the right of the MOTOR_COASTING contact. Other possible additions include: an emergency stop pushbutton contact, a rung for the reversing contactor, a shunt trip contact, an alarm-on-start function, etc.
Click on image to view larger or click here.
Learn more about AC motor control in this series of videos, from a simple switch to full reversing contactor configurations; selecting and using contactors and associated circuit breakers, overload protectors, and surge protectors; see typical hardware components and ladder logic programming for motor control with CLICK, Do-more and Productivity series PLCs.
From curing ovens to milk pasteurization, temperature sensing and control has become an important part of automation. Two of the most commonly used temperature sensors in the industry are the Resistance Temperature Detector (RTD) and the thermocouple.
Resistance Temperature Detectors
RTDs are devices with an internal resistance that changes with temperature in a predictable, linear way. They are typically made from a very fine wire wrapped around a ceramic or glass core, or they can be created using thin film technology. Traditionally, platinum, copper, or nickel wire is used and is wound to achieve a specific resistance value. This resistance value will change as temperature does and by supplying a constant current, the measured voltage drop across the resistor can be used to determine the new resistance, and thus the temperature.
RTDs come in a variety of types, with the most common being a Pt100. It’s made from platinum that has been calibrated to be 100 ohms at 0 degrees C. Platinum is an ideal metal for RTDs because of its stability, resistance to corrosion, and higher melting point. RTDs are great for applications up to around 600 degrees Fahrenheit. They provide accurate, repeatable results over the long term, but they are also fragile, have a long response time and are bigger than thermocouples.
For wider temperature ranges up to a couple thousand degrees, a thermocouple is a better fit. Thermocouples work based on the Seebeck effect, a phenomenon where a small voltage is produced across a junction of two dissimilar metals when exposed to a temperature gradient. This is believed to be a result of heated electrons in the warmer metal traveling toward the colder area because of their thermal energy.
The amount of voltage produced within the thermocouple is very small, usually millivolts, and is directly related to the difference in temperature across the junction. There are numerous types of thermocouples and each is represented by a letter. The most common ones are J, K and T, which designate a specific temperature range and the wires of each type are color coded to identify them.
Most PLCs today have I/O modules designed to accept RTD or thermocouple signals directly. If using a temperature transmitter, I/O modules that accept 4-20 mA or 0-10V are often used to bring the signals into the controller.
Temperature Sensing + Ladder Logic
For temperature sensing using Ladder Logic, we can look back at an earlier example. Remember our freezer full of frozen fish from the Basic Instructions in Ladder Logic chapter? If not, no biggie, we were just using a temperature sensor to monitor the temperature of our fish freezer. To do so, we used a CLICK PLC and a compare contact. The temperature sensor’s output produces an analog signal that is wired into the thermocouple module of the PLC. The CPU will convert this raw signal into degrees Fahrenheit and store it into DF16. Using the Compare contact instruction below, we compare our actual Freezer Temperature (DF16) to the constant 32, which represents 32 degrees Fahrenheit.
Click on image to view larger or click here.
An Out coil is then programmed from our Compare contact and will provide the signal that is wired to the external Alarm Horn. If the temperature of the freezer reads greater than 32 degrees, an alarm will sound to alert us that the frozen fish will soon thaw and spoil.
See this series of videos to learn about types of temperature sensors and how they work; hardware review of temperature probe styles and transmitters; how to select the right temperature sensor for your application; see typical ladder logic programming for temperature sensing with CLICK, Do-more and Productivity series PLCs.
Automation Cookbook is a collection of short video chapters covering a wide variety of automation application topics. Each chapter starts with a “U can do it!” overview, which explains the capabilities and usefulness of a specific automation task. There is also a group of “Tech Tips” videos in each chapter with technical nuggets and the gotcha’s that can slow down experts and novices alike when specifying and implementing the topic in question. The practical “How To” videos show step-by-step demonstrations of exactly how to connect and troubleshoot, along with sample programming shown for the basics of the task. The Cookbook currently includes chapters on Temperature Sensing, Object Detection, A/C Motors (On/Off Control), and Distance Measuring.
Don’t forget to bookmark this page!