Automation and programmable logic controllers
To automate is to make a process run by itself, in a repeatable and verifiable way. The programmable logic controller (PLC) is the tool that turned this from a relay panel impossible to modify into a program.
01What an automatic system is
The action is applied without checking the result: a timer that opens a valve for thirty seconds, a motor that runs as long as there is a run command.
It is simple and cheap, and it works when the process is very repeatable. If something changes—the pressure, the load, the ambient temperature—the result changes and nobody notices.
The variable is measured, compared with the setpoint, and action is taken on the difference. The system corrects itself in the face of disturbances and wear.
It costs a sensor and some complexity, and in return it gives stable, repeatable behavior. It is the basis of all process control, and it is developed in PID controllers.
| Part of the system | Function |
|---|---|
| Process | What is to be controlled: an oven, a conveyor, a filling line. |
| Sensors and transducers | Convert the state of the process into electrical signals the controller can read. |
| Control unit | Decides what to do. It can be a contactor, a pneumatic timer, a microcontroller or a PLC. |
| Actuators | Apply the action to the process: motors, valves, heating elements, cylinders. |
| Operator interface | Pushbutton panel, signaling, display. It is where a person gives commands and sees what is happening. |
| Safety | Emergency stops, interlocks and protections. Independent of the control. |
02What can be used to automate
| Technology | When it makes sense | Limits |
|---|---|---|
| Hardwired logic with relays and contactors | Very small, fixed automation: a direct-on-line start, a reversal of rotation. | Any change means rewiring. Difficult diagnosis and a lot of mechanical maintenance. |
| Pneumatics and pneumatic logic | Environments with explosion risk, high humidity, or where compressed air is already available. | Slow, noisy and hard to modify. It is developed in pneumatics and hydraulics. |
| Hardwired electronics | Fixed, fast functions, or very high production volumes. | Little flexibility. Redesigning means redoing the circuit board. |
| Microcontroller | A product of your own, made in series, where cost per unit rules. | You have to design everything: inputs, outputs, protections, enclosure. It suits a product, not a plant. |
| PLC | Industrial automation: rugged I/O already solved, standard programming, maintenance by third parties. | High cost per unit. For ten pieces, it is the wrong tool. |
| Industrial PC and SCADA | Supervision, historical logging, complex processes and many variables. | Less deterministic and more expensive. It always relies on PLCs below it. |
For three inputs and two outputs on a one-off machine, a couple of relays or a microcontroller cost a fraction and work just as well. A PLC is justified when there are many signals, when the automation is going to change, when the plant has already standardized on a brand, or when the maintenance will be done by someone who did not design it. That last point is the one that weighs most in real industry.
03The programmable logic controller
In 1968, General Motors asked for a replacement for its relay panels: every model change meant rewiring thousands of contacts and stopped the line for weeks. The request was clear: a reprogrammable device that would withstand the industrial environment and that the same electricians could maintain, without knowing how to program.
The first PLCs came out of that, and from that last requirement came the ladder diagram: a language drawn just like the relay schematics that plant personnel already knew how to read. That is why it is still, almost sixty years later, the most widely used language in industry.
| Advantage over hardwired logic | Where it shows |
|---|---|
| Flexibility | Changing the automation means changing the program, not the wiring. |
| Space | A small PLC replaces dozens of relays and timers. |
| Diagnostics | You can see the state of every input and output online, and why an output does not activate. |
| Functions | Timers, counters, calculations, communication and logging, without adding hardware. |
| Reliability | No moving contacts in the logic that can stick or pit. |
| Documentation | The commented program is the documentation, and it travels with the machine. |
| Format | Typical I/O | Use |
|---|---|---|
| Nano or micro | 8 to 20 | Simple machines, pumps, gates, small panels. Everything in one block. |
| Compact | 20 to 60 | With the option of adding expansion modules. It is the most common. |
| Modular | hundreds | Rack with power supply, CPU and modules of your choice. Large plants and processes. |
04The scan cycle
| Phase | What happens |
|---|---|
| 1 | Reading inputs: the physical state of all the inputs is copied to an area of memory, the process image. |
| 2 | Program execution: it runs from start to end, always reading from the image, never from the physical terminal. |
| 3 | Writing outputs: the output image is transferred all at once to the physical terminals. |
| 4 | System tasks: communication, self-diagnosis, watchdog timer. Then back to phase 1. |
- There is a delay: between an input changing and the output responding, up to twice the scan time can elapse. With scan times of 1 to 10 ms that is enough for almost everything, but not for a 200 µs pulse: that needs a fast input or an interrupt.
- Order matters: if an output is written in two places in the program, the last one wins, because it is the one left in the image at the end of the cycle. It is the most common mistake of people coming from hardwired logic, where everything happens at once.
- The inputs do not change during the cycle: the logic works on a consistent snapshot, which avoids erratic behavior and makes the program predictable.
A conveyor carries parts at 0.5 m/s and a sensor detects each part to trigger an ejector. The parts are 40 mm long. The PLC has a scan time of 8 ms.
- Each part covers the sensor for 0.040 m / 0.5 m/s = 80 ms.
- The worst case for detection is two cycles: 16 ms. There is plenty of time.
- But if the conveyor sped up to 4 m/s, the pulse would last 10 ms and could be missed between two readings. At that point a fast input with hardware capture is needed.
That calculation—event duration against scan time—is the first check for any automation, and the one most often forgotten.
05In the lab
Solve a start-stop circuit with a holding contact, first with relays and then with a PLC. Time how long each setup takes and, above all, how long it takes to modify the operation afterwards: adding a second stop pushbutton and a pilot light. The difference is the case for the PLC.
Write a program that toggles an output on every scan and measure its frequency with the oscilloscope: the period is twice the scan time. Add blocks to the program and watch how it grows. Compare with the value reported by the PLC itself.
Generate shorter and shorter pulses on an input and check from what duration the PLC stops detecting them. Compare the result with the measured scan time and with the configured input filter.
Deliberately write a program in which the same output is activated in one place and deactivated in another. Observe that only the last instruction counts, and verify it online with the program monitoring. It is the mistake that wastes the most time.
06Common mistakes
| Mistake | Consequence |
|---|---|
| Thinking of the program as if everything happened at once | The PLC executes in order, from top to bottom. What is written last is what counts. |
| Writing the same output in several places | Only the last one acts: the output seems “not to work.” |
| Ignoring the scan time | Fast events are lost and the diagnosis points at the sensor, which is fine. |
| Putting the emergency stop only in the program | If the CPU fails, there is no stop. It must cut the power by hardware. |
| Choosing a PLC for an automation with three signals | Unjustified cost compared with a few relays or a microcontroller. |
| A program without comments or names | Nobody can maintain it, and the program was precisely the documentation. |
| Confusing open loop with closed loop | The system is expected to correct disturbances that it actually never measures. |
07Self-assessment
What is the difference between open loop and closed loop?
In open loop the action is applied without checking the result; in closed loop the variable is measured, compared with the setpoint, and action is taken on the difference, so that disturbances correct themselves.
Why did the PLC appear?
Because in 1968 General Motors needed to replace relay panels that had to be rewired at every model change. It asked for a reprogrammable device, rugged and maintainable by electricians with no training in programming.
Where does the ladder diagram come from?
From that last requirement: it was designed to look just like the relay schematics that plant personnel already knew how to read. That is why it is still the most widely used language.
List the four phases of the scan cycle.
Reading the inputs into the process image, program execution, writing the outputs, and system tasks.
What is the maximum delay between an input and its output?
Up to two scan times: one if the change arrives just after the reading, plus the full cycle until the output is written.
If an output is written in two places in the program, which one counts?
The last one executed, because it is the one left in the output image when the cycle ends.
With a 5 ms scan time, can a 3 ms pulse be detected?
Not reliably: it can fall between two readings. You need a fast input with hardware capture, or a longer pulse.
When is a PLC not a good choice?
When there are very few signals and the automation is fixed, or when it is a product made in series where cost per unit rules: relays or a microcontroller go there.
Why can’t the emergency stop be only in the program?
Because if the CPU fails or the program hangs, there would be no stop. It must cut the power to the actuators by hardware, with positive-opening contacts.
What diagnostic advantage does a PLC give?
It lets you see online the state of every input, every output and every rung of the program, so you can tell exactly why an output does not activate.