Structure of a programmable logic controller
On the outside it is a box with terminal blocks and lights. On the inside it is an industrial microcontroller surrounded by everything needed so that real-world signals—24 V, bouncing contacts, motor noise—can come in and go out without destroying anything.
01External structure
| Block | Function |
|---|---|
| Power supply | Powers the internal logic and, in many units, also delivers the 24 V for the sensors. Its capacity limits how many modules can be mounted. |
| CPU | Runs the program, manages memory, handles communication and performs self-diagnosis. |
| Input modules | Adapt the field signals to the logic level: they filter, limit and isolate. |
| Output modules | Convert commands into usable power: relay, transistor or triac. |
| Communication modules | Serial ports, fieldbus or Ethernet, to talk to other devices and to the supervisory system. |
| Rack and internal bus | Mechanical support and data bus that connects the CPU with all the modules. |
| Programming terminal | The PC with the manufacturer’s software. It is also used to monitor online and to force signals. |
The 24 V output built into the PLC usually delivers only a few hundred milliamperes. Hanging twenty inductive sensors, the relay coils and the pushbutton panel lighting from it ends up loading it to the limit: the voltage drops, the sensors start to fail intermittently and the diagnosis points everywhere except at the power supply. As soon as there are several loads, an external supply is added and the common is shared.
02Memory and addressing
| Area | What it stores |
|---|---|
| Program memory | The user program, in non-volatile memory. It is kept without power. |
| Input image | The snapshot of the state of all the inputs at the start of the cycle. It is what the program reads. |
| Output image | What the program writes, which is transferred to the terminals at the end of the cycle. |
| Internal markers | Auxiliary bits: flags, intermediate states, comparison results. They have no physical terminal. |
| Data | Words, integers and reals for calculations, setpoints and process values. |
| Timers and counters | Blocks with their preset value, their current value and their output bit. |
| Retentive area | Part of the memory that survives a power failure: accumulated production, setpoints, machine state. |
The notation varies between manufacturers but the idea is the same: a type identifier, a byte and a bit. For example %I0.3 is the fourth input of the first byte, %Q1.0 the first output of the second byte, %M10.2 an internal marker and %IW64 an analog input word.
What matters is not the syntax but the discipline: every signal has a
symbolic name—arranque_bomba, nivel_alto—and the program is written
with those names. A program full of %I and %Q with no symbols is indecipherable for whoever comes
afterwards, who is almost never the person who wrote it.
03Input modules
- They typically operate at 24 V DC; 110 and 220 V AC versions also exist.
- Each input has a filter of a few milliseconds that removes contact bounce and noise. That filter adds to the scan time.
- One LED indicator per channel shows the true state: it is the first diagnostic tool.
- Defined thresholds: below about 5 V is a sure zero, above about 15 V is a sure one. In between, undefined.
A PNP sensor delivers +24 V when it detects; an NPN one delivers 0 V. The input module has to be wired accordingly: common at 0 V for PNP sensors, common at +24 V for NPN.
Mixing the two types in the same group of inputs is one of the most frequent wiring mistakes, and it produces inputs that stay always on or always off.
| Analog input | Characteristics |
|---|---|
| 4 to 20 mA | The industrial standard. Being a current, it is not affected by the voltage drop in the cable, and the live zero makes it possible to tell “zero of the variable” from “cable cut.” |
| 0 to 10 V | Simple and economical, but sensitive to noise and cable length. For short runs inside the panel. |
| Thermocouple and PT100 | Dedicated modules with linearization and cold-junction compensation already handled internally. |
| Resolution | Usually 12 to 16 bits over the range. The program receives an integer that has to be scaled to the engineering unit. |
A pressure transmitter of 0 to 10 bar delivers 4 to 20 mA. The PLC module converts that range to an integer from 0 to 27648.
pressure = reading × 10 / 27648
With a reading of 13,824: pressure = 13,824 × 10/27,648 = 5.0 bar. And if the cable is cut, the current drops to 0 mA, the reading goes below zero and the program can detect the fault instead of believing the pressure is zero. That is the whole advantage of the live zero, and it is the reason 4-20 mA is still in use.
04Output modules
| Type | Current | Speed | When it is used |
|---|---|---|---|
| Relay | 2 to 5 A | slow (ms) | The most versatile: it works for DC and AC, and with a voltage-free contact. It wears out with switching operations. |
| Transistor | 0.5 to 2 A | fast (µs) | DC only. For solenoid valves, signaling and PWM or pulse outputs. |
| Triac | 0.5 to 2 A | medium | AC only, with no contacts to wear out. Good for loads that switch very often. |
- Flyback (freewheeling) diode across every DC coil, as close to it as possible. Without it, the turn-off spike destroys the output transistor.
- Snubber circuit—a resistor and capacitor in series—across AC coils.
- A fuse per group of outputs: a short circuit in the field must not take out the entire module.
- Interposing relays or contactors for large loads. The PLC output commands, it does not supply power.
- Respect the current per group, which is always lower than the sum of the maximum individual currents.
05In the lab
On a real PLC: identify the power supply, CPU, modules and terminal blocks; read the nameplate; determine the supply voltage, the number and type of I/O, and the current available at the 24 V output. Draw the complete terminal diagram before connecting anything.
Wire a PNP inductive sensor and an NPN one to the inputs, with the correct common in each case. Then swap them on purpose and observe the behavior: inputs always on or always off. Document how each case is recognized from the module’s LEDs.
Connect a potentiometer or a transmitter to an analog input and read the raw value. Write the conversion to engineering units and verify it with a multimeter at several points. Add wire-break detection below 4 mA.
Drive a DC solenoid valve from a transistor output, with and without a freewheeling diode, observing the turn-off spike with the oscilloscope. Measure the reverse voltage that appears without the diode: it often exceeds one hundred volts.
06Common mistakes
| Symptom | Usual cause |
|---|---|
| Inputs always on or always off | PNP sensor wired as NPN, or common wrongly connected. |
| Sensors that fail intermittently | The internal 24 V supply is overloaded and the voltage drops. |
| The transistor output burns out | The freewheeling diode across the coil is missing. |
| Outputs in a group that do not respond | Group fuse blown, or total current above what is allowed. |
| Noisy analog reading | 0-10 V signal over a long cable or next to power wiring. Use 4-20 mA and shielded cable. |
| The program thinks the pressure is zero | Cable cut without detection: the live zero of 4-20 mA was not used. |
| Data is lost when power is cut | The variables were not in the retentive area. |
| Program impossible to maintain | Signals without symbolic names or comments. |
07Self-assessment
What is the process image?
The copy in memory of the state of all the inputs, taken at the start of the cycle. The program reads from there, never from the physical terminal, and so it works on a consistent snapshot.
What is galvanic isolation used for in the I/O?
So that there is no electrical connection between the field and the logic: the noise, overvoltages and potential differences of the plant do not reach the processor.
Difference between a PNP and an NPN sensor.
The PNP delivers +24 V when activated and the NPN delivers 0 V. The input module must be wired with the corresponding common in each case.
Why is 4-20 mA preferred over 0-10 V?
Because being a current it is not affected by the voltage drop in the cable, it resists noise better, and the live zero makes it possible to tell a variable at zero from a cut cable.
Scale a reading of 6912 out of 27648 for a range of 0 to 10 bar.
6912 × 10/27,648 = 2.5 bar.
What type of output is appropriate for an AC load that switches very often?
A triac output: it has no contacts to wear out and it handles AC. A relay would pit with so many switching operations.
What is added to a DC coil driven by a transistor output?
A flyback (freewheeling) diode in antiparallel, as close to the coil as possible. Without it, the turn-off spike destroys the transistor.
What is the retentive area of memory?
The part that keeps its contents when the power is cut: accumulated production, setpoints, machine state.
Why does the input filter increase the response time?
Because the module ignores changes shorter than the filter in order to eliminate bounce and noise. That delay adds to the scan time.
Why must every signal have a symbolic name?
Because the program is the documentation of the machine, and whoever maintains it years later will not be the person who wrote it. A program full of %I and %Q with no symbols is indecipherable.