Electronics and Digital Logic
Behind every button, sensor, and control on a machine tool lies a bit of electronics: diodes that rectify, transistors that control relays, 24-volt power supplies, signals that travel as voltages or currents, and circuits that operate on 0s and 1s. In this chapter, we’ll start with semiconductor materials and move on to digital logic, analog-to-digital converters, and fieldbuses. Ohm’s and Kirchhoff’s laws are covered in Chapter 44; here, we’ll use them without repeating them.
46.1 Conductors, Insulators, and Semiconductors
A material conducts electricity if there are free charges moving within it. In conductors (copper, aluminum, silver), each atom contributes electrons that move freely throughout the metal: even a small voltage is enough to set them in motion. In insulators (plastic, glass, ceramic, rubber), the electrons remain bound to the atoms, and virtually no current passes. In between are semiconductors: the most commonly used is silicon, which, in its pure form, conducts very little but changes its behavior when a minimal amount of other elements is added.
| Type | Examples | Approximate resistivity (Ω·m) | Where it is used |
|---|---|---|---|
| Host | copper, aluminum | approximately 0.000 000 02 | cables, windings, busbars |
| Semiconductor | silicon, germanium | from 0.001 to a few thousand, depending on the adulteration | diodes, transistors, integrated circuits |
| Insulation | PVC, glass, ceramic | more than 1,000,000,000,000 | sheaths, supports, insulators |
Approximate values, rounded: these are provided solely to illustrate how far apart the three groups are.
Doping: N-type silicon and P-type silicon
Each silicon atom has four electrons with which it bonds to its four neighbors, forming an ordered lattice in which no electrons are free. If you replace some of the atoms with an element that has five bonding electrons (phosphorus, arsenic), four are used for the bonds and the fifth remains free: the silicon becomes an N-type material, because the mobile charges are negative. If, on the other hand, an element with three electrons (boron) is introduced, one bond is missing: that empty spot is called a vacancy and behaves like a positive charge that moves, because a nearby electron fills it and leaves a hole behind. This is P-type silicon. This controlled addition is called doping: just a few foreign atoms per million are enough to significantly alter the conductivity.
The PN junction
When a P-region and an N-region in the same crystal are brought into contact, a PN junction is formed. Near the boundary, the free electrons from the N-region fill the holes in the P-region: no mobile charges remain there, and a thin depletion region forms, acting as a barrier. In silicon, a voltage of about 0.6–0.7 V is required to overcome this barrier.
- Forward bias: the battery’s positive terminal is connected to the P-type region and the negative terminal to the N-type region. The charges are pushed toward the junction, the barrier thins, and once the voltage exceeds 0.6–0.7 V, current flows.
- Reverse polarization: the positive charge is on N. The charges are pulled away from the boundary, the depleted region expands, and only a very small current flows.
46.2 The Diode
A diode is a PN junction enclosed in a package with two terminals: the anode (A, P-side) and the cathode (K, N-side, marked with a band on the body). It allows current to flow from the anode to the cathode and blocks it in the opposite direction: it is the electrical equivalent of the check valve used in pneumatics and hydraulics (Chapters 42 and 43). Just as a valve requires a small amount of pressure on the spring to open, a diode requires a small voltage to begin conducting.
The curve in the figure is called the diode characteristic curve. You can read three things from it:
- the forward voltage (VF): for a silicon diode, approximately 0.6–0.7 V, which is typically rounded to 0.7 V in calculations; for Schottky diodes, it ranges from 0.3 to 0.4 V, while for LEDs, it ranges from 1.8 to 3.5 V;
- the maximum current direct current, as specified by the manufacturer in the technical data sheet (1 A for the standard 1N4007, 3 A for a 1N5408);
- the maximum reverse voltage, beyond which the diode breaks down (1000 V for the 1N4007).
When the diode is conducting, the voltage across it is approximately VF, so it heats up: the power loss is equal to the voltage multiplied by the current.
A diode is connected in series with the 24 V input of a board: if someone reverses the wires, the diode blocks the current and the board won't be damaged. The board draws 3 A. How much power does the diode dissipate, and how much would a 0.4 V Schottky diode dissipate?
46.3 Rectifiers and Smoothing Capacitors
The power grid supplies alternating current, but the control electronics require direct current. The first step is to rectify the current: to make it flow in only one direction using one or more diodes.
Half-wave rectifier
A single diode connected in series with the load allows the positive half-waves to pass and blocks the negative ones. The output voltage always has the same polarity but consists of “peaks” separated by pauses as long as the peaks themselves. It’s simple and inexpensive, but it wastes half the wave and is used only for small loads.
Bridge Rectifier (Graetz Bridge)
Four diodes arranged in a diamond pattern allow both half-waves to conduct: in each half-wave, two opposite diodes conduct, and the current in the load always flows in the same direction. The spikes double in frequency, occurring once every 10 ms with a 50 Hz power grid (spike frequency 100 Hz). The current always flows through two diodes, so approximately 2 × 0.7 = 1.4 V is lost at the output. The bridge can be purchased as a single, ready-made component with four pins: two marked “~” and two marked “+” and “−.”
The smoothing capacitor
The humps aren't enough: you need a nearly flat voltage. Connect a electrolytic capacitor large (thousands of microfarads; the capacitor as a component is described in Chapter 44). On the rising edge of each peak, the capacitor charges up to its peak value; when the peak declines, it supplies current to the load while discharging slightly, until the next peak arrives. At the output, a nearly continuous voltage remains with a small undulation (in English ripple) ΔV.
A transformer has a secondary winding rated at 18 V rms. What is the voltage across the capacitor when it is open-circuited, and when it is connected in series with a single diode?
It's a classic error: anyone who installs a 24-volt transformer to get 24 volts DC will end up with more than 32 volts across the capacitor.
The circuit in Example 46.2 supplies a 2 A load using a 4700 µF capacitor. What is the ripple voltage? What capacitance would be needed to reduce the voltage to 2 V?
With a half-wave rectifier at fr = 50 Hz, the ripple doubles (8.5 V): this is another reason to use a bridge rectifier.
46.4 Special Diodes: LEDs, Zener Diodes, and Recirculation Diodes
The LED and Its Resistance
An LED (light-emitting diode) is a diode that emits light when it conducts. It is found in button indicator lights, on PLC outputs, on proximity sensors, and in column lamps. Its threshold voltage depends on the color: approximately 1.8–2.2 V for red and yellow, 2–3 V for green, and 3–3.5 V for blue and white (these are approximate values; the exact values are listed in the datasheet). The operating current of an indicator LED is a few milliamps, typically ranging from 2 to 20 mA.
The LED should never be connected directly to the power supply: once the threshold is exceeded, the current rises very rapidly (Figure 46.3) and the LED burns out. A resistor is connected in series to “absorb” the excess voltage and stabilize the current, applying Ohm’s law (Chapter 44) to the resistor alone:
We want to light up a red LED (VLED = 2 V) with a current of 10 mA, powered by the 24 V from the control panel.
A 0.25 W resistor would operate nearly at its limit and get very hot; you should always choose a rated power that is at least double the calculated value. Also note that almost all of the power (0.22 W out of 0.24 W) is wasted in the resistor: this is why the LEDs in 24-volt industrial indicator lights often contain a small constant-current circuit.
The Zener Diode
A Zener diode is designed to operate in reverse bias, in the breakdown region, without breaking down. In that region, the voltage across it remains nearly constant at the value UZ (there are Zener diodes rated at 3.3, 5.1, 10, 12, 15, 24 V, and many others), even though the current varies considerably. With a resistor in series, it becomes a simple voltage regulator: the resistor absorbs the excess voltage, while the Zener diode keeps the output voltage stable. The symbol is that of a diode with the bar bent into a “Z” shape.
The resistance is calculated so that the load current plus a small minimum current (a few milliamps) flows through the Zener diode, which serves to keep it in the breakdown region:
A small circuit requires 12 V and draws 20 mA. A 12-V Zener diode with a minimum current of 5 mA is used, powered by 24 V.
The Zener stabilizer is suitable for currents of a few milliamps; for higher currents, the integrated regulators described in section 46.6 are used.
The recirculation diode on the coils
The coils of relays, contactors, and solenoid valves are inductors: they store energy in the magnetic field when current flows through them. An inductor resists any change in current: when the contact or transistor controlling it opens, the current would want to stop abruptly, and the coil, to keep the current flowing, generates a very high voltage of the opposite polarity across its terminals. This is the same phenomenon that causes the spark in the spark plugs of an internal combustion engine. That voltage spike—running into the hundreds or thousands of volts—burns out the output transistors, wears down the contacts with sparks, and sends interference throughout the control panel.
The solution is a recirculation diode (also called a free-wheeling diode) connected in parallel with the coil, but in the opposite direction: with the cathode toward the +24 V. When the coil is powered, the diode is in reverse bias and does nothing; when the circuit opens, the current from the coil flows through the diode, loops back, and dies out in a few milliseconds, heating the coil’s resistance. The voltage across the contact does not exceed 24 V plus 0.7 V for the diode.
A 24 V, 4 W solenoid coil has an inductance of approximately 0.3 H. Calculate the current, resistance, stored energy, the theoretical voltage if the current were to stop in 1 µs, and the turn-off time with the diode.
In practice, 50,000 V is never reached, because a spark will occur or the transistor will break down first—which is exactly what we want to avoid. The trade-off for using a diode is a slight delay in the release of the relay or valve; where rapid release is required, a Zener diode in series with the diode, a varistor, or a resistor-capacitor circuit is used. Many coils with industrial connectors already have this protection built in (you can tell by the LED in the connector).
46.5 The Transistor as a Switch
A bipolar transistor consists of three layers of doped silicon: N-P-N or P-N-P. The three terminals are called the base (B), collector (C), and emitter (E). In the NPN type, which is the most commonly used, a small current entering the base and exiting the emitter allows a much larger current to flow from the collector to the emitter. The ratio between the two is the current gain hFE (also called β), which for low-power transistors ranges from 50 to a few hundred.
A transistor can amplify signals, but in automation it is almost always used as a switch, with only two states:
- off (open): base at 0 V, no base current, no collector current. The load is off;
- Saturation (off): A current slightly greater than necessary is applied to the base; the transistor conducts the full current demanded by the load, and only 0.1–0.3 V (VCE,sat) remains between the collector and emitter. The load is on, and the transistor generates little heat.
There is a PN junction between the base and the emitter, so when it is conducting, there is a voltage of about 0.7 V (VBE) across its terminals, just like in a diode. The calculation for driving a load is always the same:
A microcontroller has 5 V outputs that can supply a maximum of 20 mA. It must drive a relay with a 24 V coil and a resistance of 480 Ω. An NPN transistor with a minimum hFE of 100 and a safety factor of k = 5 is used. Calculate the base resistance and the powers involved.
Round off RB to the lower value: a lower resistance provides more base current and ensures safer saturation. Rounding up risks leaving the transistor halfway, where it heats up and may burn out.
The MOSFET
A MOSFET is a transistor controlled by voltage rather than current. Its terminals are called the gate (G), drain (D), and source (S). The gate is isolated: under static conditions, it does not draw current; simply applying a voltage above the threshold (usually a few volts—10 V for full conduction in standard models, 4.5 V or less in “logic-level” models) causes the channel between the drain and source to close. When closed, it behaves like a very small resistor, RDS(on), which in power-type models is a few milliohms. This is why MOSFETs are used as switches in the static outputs of PLCs, switching power supplies, and—along with IGBTs—in inverters (Chapter 45). For a MOSFET, the power lost during conduction is P = RDS(on) · I²: with 10 mΩ and 10 A, this amounts to just 1 W.
46.6 The 24-V stabilized power supply
Almost all industrial automation systems (PLCs, sensors, solenoid valves, auxiliary relays, operator panels) operate at 24 V DC: this voltage is low enough to be safe to touch and high enough to travel long distances without being affected by interference. A classic power supply, known as a linear power supply, consists of four blocks:
- transformer: steps down the 230 V from the power grid and, most importantly, isolates the circuit from the grid (galvanic isolation);
- rectifier: a diode bridge (paragraph 46.3);
- filter: the smoothing capacitor;
- regulator: an integrated circuit containing transistors and a reference voltage, which keeps the output steady at 24 V regardless of the input voltage (as long as it is a few volts higher) and regardless of the load.
The linear regulator functions as a variable resistor in series: the excess voltage between the input and 24 V is converted into heat. Its efficiency is low, and it requires a heat sink. Today, switching power supplies are almost always installed in control panels: they directly rectify the mains voltage, then a MOSFET turns the current on and off tens of thousands of times per second through a very small transformer, because at high frequencies, very little iron is required. An electronic control circuit determines how long the circuit remains on during each cycle. They are lightweight, compact, accept a wide range of input voltages, and have efficiencies of 90% or higher; however, they are more complex and generate high-frequency noise, which must be filtered out.
I need 24 V and 2 A. In a linear power supply with a 24 V transformer, the regulator input receives an average of about 31.5 V (peak 33.9 V, minus 1.4 V for the bridge, minus the ripple). An equivalent switching power supply has an efficiency of 0.9. How much power is lost?
A 24-V control panel controls 6 4-W solenoid valves, 8 50-mA auxiliary relays, 20 25-mA sensors, a 0.6-A PLC, and a 0.5-A operator panel. A 25% margin is allowed. Which power supply should be chosen?
The margin accounts for inrush current (the coils and capacitors of the loads draw more current initially) and future additions. It’s also a good idea to distribute the loads across multiple protected circuits, so that a short circuit in one sensor doesn’t shut down the PLC.
46.7 Analog, Digital, and Industrial Signals
A signal is an electrical quantity that carries information. If it can continuously take on all values within a range, it is analog: for example, the voltage of a temperature sensor that rises gradually. If it can assume only two states—on and off—it is digital (or binary): a limit switch, a button, or a proximity sensor. The two states are called 1 and 0, or high and low, true and false.
Signs from the workshop
| Signal | Values | Examples | Strengths and Limitations |
|---|---|---|---|
| 24 V Digital | 1 = approximately 24 V (detected above 15 V) · 0 = approximately 0 V (below 5 V) | buttons, limit switches, inductive sensors, relay outputs | Simple and robust; the range between 5 and 15 V is invalid, so a small disturbance does not change the state |
| Analog 0–10 V | from 0 V to 10 V, proportional to the measurement | potentiometers, inverter speed reference | Economical; voltage drops over long cables, and disturbances accumulate; 0 V can mean either “zero reading” or “broken wire” |
| 4–20 mA Analog | from 4 mA to 20 mA, proportional to the measurement | pressure, level, temperature, and flow transmitters | The current is the same throughout the circuit, even with long wires; a broken wire is easy to spot |
The 24 V digital thresholds are the most common for PLC inputs (IEC 61131-2 standard, Type 1 inputs); the input data sheet provides the exact values.
Why 4–20 mA and not 0–20 mA?
The signal in current It is not affected by cable resistance: the transmitter regulates the current, and according to Kirchhoff’s law (Chapter 44), in a series circuit the current is the same throughout, even after 100 meters of cable. The “live zero” at 4 mA offers two advantages: the minimum measurement value corresponds to 4 mA rather than zero, so a current of 0 mA indicates a broken wire or a faulty sensor, and not “zero pressure”; furthermore, with those 4 mA, the two-wire transmitter is powered by the same circuit as the signal. By convention (NAMUR NE 43 recommendation), a current below 3.6 mA or above 21 mA is considered a fault.
From Current to Measurement: The Line Through Two Points
The relationship between current and the measured quantity is a straight line passing through two known points: (4 mA; full scale) and (20 mA; full scale). This is the line through two points from Chapter 7 (Section 7.4), with current in place of x and the measured value in place of y:
A pressure transmitter has a range of 0–10 bar and a 4–20 mA output. The PLC reads 12.8 mA.
Using the same sensor: What current corresponds to 7.5 bar and 3.2 bar? What conclusion should be drawn if the PLC reads 0 mA?
With a 0–10 V sensor, a reading of 0 V would have been indistinguishable from “zero pressure”: for a safety pressure (such as that of the workpiece’s hydraulic clamping system), this is a risk that the 4–20 mA signal eliminates.
46.8 Numbering Systems and Codes
A digital circuit recognizes only 0s and 1s. To represent numbers, it uses the binary system (base 2), which follows the same rules as our decimal system (base 10) but uses only two digits. In the decimal system, each digit is worth ten times the one to its right (ones, tens, hundreds); in the binary system, each digit is worth twice as much: 1, 2, 4, 8, 16, 32, 64, 128, and so on. Each binary digit is called a bit.
- bit: a binary digit, 0 or 1 (on or off);
- byte: 8 bits, numbers from 0 to 255;
- word (word): In 16-bit PLCs, numbers range from 0 to 65,535 (or from −32,768 to +32,767 if one bit is used for the sign); a double word is 32 bits long.
With n bits, you can represent 2n different numbers, ranging from 0 to 2n − 1.
From Decimal to Binary: Division by 2
Divide the number by 2 and write down the remainder (0 or 1); divide the quotient by 2 and write down the new remainder, and so on until the quotient is zero. The binary number is read with the remainders from bottom to top.
Hexadecimal
Long binary numbers are hard to read. So we use hexadecimal (base 16), which has sixteen digits: 0 through 9, followed by A = 10, B = 11, C = 12, D = 13, E = 14, and F = 15. The trick is that four bits correspond exactly to one hexadecimal digit: to convert from binary to hexadecimal, simply divide the number into groups of four bits starting from the right. A byte is written using two hexadecimal digits (from 00 to FF), and a word using four. To avoid confusion, hexadecimal numbers are written with a prefix: 16#D6 in PLCs according to IEC 61131-3, 0xD6 in programming languages, and D6h in many manuals.
A PLC displays the byte 11010110. What is its value in decimal and hexadecimal?
An alarm code for a drive is 16#3F8. What is its value in decimal and binary?
The BCD Code
In BCD (binary-coded decimal), each decimal digit is represented by four bits. The number 59 is not written as 111011 but as 0101 1001: “5” and “9.” A few combinations are wasted (1010 through 1111 are not used), but the conversion for digit displays and numerical switches (the old-style “contraves” with wheels) is immediate.
Gray Code and Absolute Encoders
A absolute encoder (Chapter 47) reads the position of a shaft from a disk with multiple concentric tracks, one per bit, read by an equal number of optical sensors. If the tracks were written in pure binary, when moving, for example, from 3 (011) to 4 (100), they would have to change three bits at the same time. But the sensors are never perfectly aligned: for a moment, one changes before the others, and the encoder reads incorrect values such as 111 (7) or 000 (0)—that is, a position jump that doesn't exist. The Gray Code It is designed so that between two adjacent numbers, there is a change a single bit: In the worst-case scenario, you'll see either the previous or the next position, but never one that's far away.
To convert from binary to Gray code: the most significant bit remains unchanged; each subsequent bit is 1 if the corresponding binary bit and the bit to its left are different, and 0 if they are the same (this is the XOR operation described in paragraph 46.9).
| Decimal | Track | Hexadecimal | BCD | Gray |
|---|---|---|---|---|
| 0 | 0000 | 0 | 0000 0000 | 0000 |
| 1 | 0001 | 1 | 0000 0001 | 0001 |
| 2 | 0010 | 2 | 0000 0010 | 0011 |
| 3 | 0011 | 3 | 0000 0011 | 0010 |
| 4 | 0100 | 4 | 0000 0100 | 0110 |
| 5 | 0101 | 5 | 0000 0101 | 0111 |
| 6 | 0110 | 6 | 0000 0110 | 0101 |
| 7 | 0111 | 7 | 0000 0111 | 0100 |
| 8 | 1000 | 8 | 0000 1000 | 1100 |
| 9 | 1001 | 9 | 0000 1001 | 1101 |
| 10 | 1010 | A | 0001 0000 | 1111 |
| 11 | 1011 | B | 0001 0001 | 1110 |
| 12 | 1100 | C | 0001 0010 | 1010 |
| 13 | 1101 | D | 0001 0011 | 1011 |
| 14 | 1110 | E | 0001 0100 | 1001 |
| 15 | 1111 | F | 0001 0101 | 1000 |
Write 59 in BCD and compare it to the binary representation; then write 5 (101) in Gray code.
46.9 Logic Gates and Boolean Algebra
Digital circuits are built using logic gates: small circuits (made of transistors) with one or more inputs and one output, each of which performs a logical operation. Their behavior is described by a truth table, which lists the output for all combinations of inputs: with n inputs, there are 2n rows.
- AND (logic product, “AND”): The output is 1 only if all inputs are 1. It is like two switches connected in series.
- OR (logical OR, “OR”): The output is 1 if at least one input is 1. Two switches connected in parallel.
- NOT (negation): The output is the opposite of the input. It is written with a bar above it: Ā, pronounced “A negated.”
- NAND and NOR: an AND and an OR followed by a NOT. The dot on the output indicates negation.
- XOR (exclusive OR): The output is 1 if the inputs are different. It is used to compare two bits.
| A | B | AND A · B | OR A + B | NOTE Ā | NAND | NOR | XOR A ⊕ B |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 |
| 0 | 1 | 0 | 1 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 0 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
NAND and NOR gates are called universal gates: all other gates can be built using only NAND gates (or only NOR gates). The first integrated circuits were manufactured in this way.
Boolean Algebra
Logical operations follow precise rules, which are set forth in Boolean algebra. Variables can only take the values 0 or 1; the product “·” is the AND operator, the sum “+” is the OR operator, and the vertical bar is the NOT operator. Many rules are similar to those of standard algebra (Chapter 1), while others are not: for example, A + A = A, and A + 1 = 1.
| Properties | With the OR | With the AND |
|---|---|---|
| Neutral element | A + 0 = A | A · 1 = A |
| An element that absorbs everything | A + 1 = 1 | A · 0 = 0 |
| Idempotence | A + A = A | A · A = A |
| Accessory | A + Ā = 1 | A · Ā = 0 |
| Commutative | A + B = B + A | A · B = B · A |
| Association | (A + B) + C = A + (B + C) | (A · B) · C = A · (B · C) |
| Distribution | A + B · C = (A + B) · (A + C) | A · (B + C) = A · B + A · C |
| Absorption | A + A · B = A | A · (A + B) = A |
| Negation Absorption | A + Ā · B = A + B | A · (Ā + B) = A · B |
| Double Negation | If you say "no" twice, you go back to A | |
The two most useful rules are De Morgan's theorems: the negation of a product is the sum of the negations, and the negation of a sum is the product of the negations. In practice: a NAND gate is equivalent to an OR gate with the inputs negated, and a NOR gate is equivalent to an AND gate with the inputs negated.
An example from the workshop: “The machine stops if not "It's true that both the pressure and the lubrication are fine" is equivalent to "the machine stops if there is no pressure" or "There's a lack of lubrication." That's what De Morgan said.
From an old diagram, we get Y = A · B + A · B + A · B. Can this be done with fewer gates?
46.10 From the truth table to the circuit
The method for designing a logic circuit is always the same:
- You write out in words what the machine is supposed to do and give each input and output a name;
- Fill in the truth table with all possible combinations of the inputs;
- For each row where the output is 1, write the product (AND) of the inputs, negating those that are 0; then sum (OR) all these products;
- You can simplify it using Boolean algebra and draw the circuit with logic gates, or write the PLC program (Chapter 49).
A press should only lower if the safety door is closed and the operator presses both buttons with both hands, or if the maintenance mode key is inserted. Inputs: P = door closed, S1 = left button, S2 = right button, K = key inserted (1 = true). Output: Y = descent.
| P | S1 | S2 | K | Y |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 |
| 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 | 0 |
| 1 | 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 | 0 |
| 1 | 1 | 0 | 0 | 0 |
| 1 | 1 | 1 | 0 | 1 |
| any | any | any | 1 | 1 |
46.11 Sequential Circuits: Memories, Counters, and Timers
In the circuits we've seen so far (called combinational circuits), the output depends only on the current inputs. Many functions, however, require memory: a motor started with a button must remain running even after the button is released. Circuits in which the output also depends on past events are called sequential circuits.
The SR Flip-Flop
The simplest memory is the SR flip-flop (or SR latch), made with two NOR gates, each of which receives the output of the other. The S (set) input sets the Q output to 1; the R (reset) input sets it to 0; when both S and R are 0, Q remains as it was: it is a single bit of memory. The combination of S = 1 and R = 1 is not allowed, because it would set both outputs to 0, and the final state would depend on which input returns to 0 last.
| S | R | Q next | Meaning |
|---|---|---|---|
| 0 | 0 | Q first | memory: nothing changes |
| 1 | 0 | 1 | set: turns on |
| 0 | 1 | 0 | reset: turns off |
| 1 | 1 | prohibited | In PLCs, you choose which one wins (set or reset takes priority) |
This is the same self-holding function found in relay circuits: the start button energizes the contactor; a contact on the contactor itself closes in parallel with the button and keeps it energized; the stop button, which is normally closed, breaks the circuit. In logic terms: Q = (RUN + Q) · STOP. In this configuration, the stop command takes precedence over the run command, which is the correct choice for safety. In PLCs (Chapter 49), self-holding is implemented as follows in contact-based language, or using the SET and RESET instructions, or with the SR and RS blocks defined in the IEC 61131-3 standard.
Counters and Timers
By filing several flip-flops together, you get a log (a multi-bit memory unit, such as a byte) and a counter: With each input pulse, the stored binary number increases by one (0000, 0001, 0010, 0011...). A counter with n The bit counts up to 2n − 1, and then it starts over from zero. A timer A digital counter is a device that counts the pulses from an internal clock (the clock) with a known frequency: when the count reaches the set value, the desired time has elapsed. This is how PLC timers and counters, machine piece counters, and dwell times—such as G04 in numerical control—work.
A timer counts the pulses of a 1-kHz clock. What value should be set for a delay of 2.5 s? What is the maximum count of a 16-bit counter using the same clock? And what is the maximum count of a 16-bit signed counter?
46.12 Analog-to-Digital Conversion
PLCs and numerical control systems work with numbers, but analog sensors provide voltages and currents. The analog-to-digital converter (ADC) acts as a bridge: at regular intervals champion the signal—that is, it reads its value at that instant—and it quantize, that is, it converts it to the nearest integer it can represent. A converter that n bit divides the input field into 2n steps: the width of a step is called resolution (or LSB, the least significant bit). A change smaller than one step is not visible.
An analog input card has a 12-bit converter. Calculate the resolution for 0–10 V and 4–20 mA, the code corresponding to 6.2 V, and the resolution in bar for the 0–10 bar sensor in Example 46.10.
In practice, many PLCs do not use the 0–4095 range directly but instead use their own scale: for example, some cards use a range from 0 to 27,648 for the entire nominal range and reserve the numbers above that to indicate an out-of-range condition. Conversion to technical units is always performed using the straight line through two points described in paragraph 46.7.
How often to sample
The converter detects the signal only at the sample instants: whatever happens in between is lost. The theoretical rule (the sampling theorem, or Nyquist-Shannon theorem) states that you must sample at least twice the highest frequency contained in the signal; in practice, to clearly see the waveform, you sample 5 to 10 times faster. A temperature that changes over tens of seconds can be read a few times per second; a motor’s current or the position of an axis must be read thousands of times per second, which is why drives have their own converters, much faster than the PLC’s cycle time.
The digital-to-analog converter (DAC) performs the reverse process: it converts a number into a voltage or current—for example, the 0–10 V speed reference that the PLC sends to a drive.
46.13 Microcontrollers, Fieldbuses, and Communication
From the circuit to the program
To create a complex function using logic gates, you would need thousands of them, and changing the function would mean rebuilding the circuit. The microprocessor solves this problem: it is a single integrated circuit that contains a processing unit capable of executing, one after another, simple instructions (add, compare, jump, read, write) retrieved from memory. By changing the instructions—that is, the program—the same circuit performs different tasks. The microcontroller also integrates program and data memory, digital inputs and outputs, A/D converters, timers, and communication ports into the same chip: it is a complete mini-computer on a chip, and can be found inside smart sensors, actuators, panels, and household appliances. PLCs (Chapter 49) and numerical control systems (Chapter 50) are, essentially, industrial computers of this type—robust and equipped with inputs and outputs suited for factory environments. The rate at which they execute instructions is determined by the clock, which today ranges from tens of megahertz to a few gigahertz.
Serial Communication
To communicate with each other, devices exchange bytes one after another over a few files: this is serial communication. In asynchronous serial communication, each byte is transmitted as a character that begins with a start bit and ends with at least one stop bit: in the most common format, “8N1,” there are 10 bits per byte. The speed is measured in bits per second (baud): 9,600, 19,200, 115,200.
A control unit sends a 100-byte message to another device over a 9,600-baud, 8N1 serial connection. How long does it take? And at 115,200 baud?
One-tenth of a percent-byte is nothing when loading a program, but it's too much to close the position loop of an axis, which updates every millisecond or less: that's why the drives use much faster buses.
- RS-232: the classic serial interface, point-to-point (from one device to another), with voltages referenced to ground. It has a range of about 15 meters. For decades, this was the port used to load programs into numerical control systems, and it can still be found on older machines.
- RS-485: uses a pair of twisted wires and transmits differentially: it measures the voltage difference between the two wires, not the voltage relative to ground. Any noise that enters both wires equally cancels itself out. It has a range of over 1,000 m and can connect up to 32 devices on the same line, with a termination resistor (usually 120 Ω) at both ends. Protocols such as Modbus RTU and Profibus DP run over RS-485.
- Industrial Ethernet: the same technology as office networks, but with rugged cables and connectors and protocols suited for real-time applications. The most widely used are Profinet (developed by Siemens and widely used in Europe with PLCs), EtherCAT (in which the message passes through all devices in sequence, and each one reads and writes its portion on the fly, with cycle times under a millisecond—ideal for motion control), EtherNet/IP, and Modbus TCP.
A fieldbus replaces hundreds of wires: instead of connecting each sensor and valve to the PLC with its own cable, input and output modules are placed near the machine and connected via a single communication cable. The numerical control communicates with its drives in the same way (Chapter 48).
46.14 Electromagnetic Interference and Best Practices
An electrical panel contains both cables carrying hundreds of volts and tens of amperes that switch within a few microseconds (motors, inverters, contactors) and signal cables carrying a few milliamps or a few millivolts (analog sensors, encoders). Rapidly changing currents and voltages generate electric and magnetic fields that induce interference in nearby cables: this is the problem of electromagnetic compatibility (EMC). Typical symptoms include fluctuating analog readings, encoders losing pulses, fieldbuses going into errors, and inputs tripping on their own.
- Separate power and signal lines: use separate conduits, or a metal conduit with a separator; the distances recommended by inverter manufacturers are approximately 20–30 cm for long parallel runs. Where cables must cross, they should cross at right angles to minimize crosstalk.
- Shielded cables for encoders, analog signals, fieldbuses, and inverter motor cables. The shield (the metal braid) must be connected to ground with a wide contact all around the cable (using cable ties or metal cable glands), and not with a long wire tail, which is virtually useless at high frequencies. For inverter power cables, the shield is grounded at both ends; for some slow analog signals, manufacturers specify grounding on only one side—follow their documentation.
- Twisted pairs: The two wires of a signal (transmit and receive) are twisted together to pick up equal and opposite noise, which cancels each other out. This is the same principle as RS-485.
- Star-shaped grounding and metal base plates: all ground connections must be connected to a common point or to an unpainted galvanized plate, using short, wide connections. The protective earth (PE) remains mandatory for personal safety (Chapter 44).
- Eliminate interference at the source: use recirculation diodes on DC coils (section 46.4), RC circuits or varistors on AC coils, line filters, and short cables between the inverter and the motor.
- Prefer robust signals: 4–20 mA instead of 0–10 V over long distances, encoders with differential outputs, and fieldbuses instead of multiple analog signals.
46.15 The Formulas in This Chapter
| What Are You Looking For? | Formula | Units |
|---|---|---|
| Power Lost in a Diode | P = VF · I (VF ≈ 0,7 V) | W |
| Peak voltage | Vpeak = Veff · √2 | V |
| The bridge came up empty-handed | Vu ≈ Vpeak − 1.4 | V |
| Capacitor-Induced Ripple | ΔV ≈ I / (fr · C), where fr = 100 Hz with the bridge | V |
| Series Resistance Across the LED | R = (V − VLED) / I | Ω |
| Zener Stabilizer Resistance | R = (Vin − UZ) / (IL + IZ,min) | Ω |
| Energy in a coil | E = ½ · L · I² | J |
| Coil time constant | τ = L / R | s |
| Minimum base current | IB,min = IC / hFE,min | A |
| Basic Resistance | RB = (Vin − 0.7) / (k · IB,min) | Ω |
| Efficiency of a Power Supply | η = Pu / Pin | pure number |
| 4–20 mA measurement signal | y = ymin + (I − 4) / 16 · (ymax − ymin) | unit of measurement |
| 4–20 mA current measurement | I = 4 + 16 · (y − ymin) / (ymax − ymin) | mA |
| n-bit numbers | from 0 to 2n − 1 | pure number |
| Digital Timer | t = N / fclock | s |
| Resolution of an A/D converter | q = field / 2n | signal unit |
| Serial Transmission Time | t = Nbyte · 10 / baud (8N1) | s |
| De Morgan | A · B = A + B · A + B = A · B | logic |
46.16 Exercises
Try to solve them on your own, using a calculator and a piece of paper, before looking at the solution.
Solution
R = (12 − 1.8) / 0.015 = 10.2 / 0.015 = 680 Ω (normalized value). PR = 10.2 × 0.015 = 0.153 W: a 0.5 W resistor is chosen (0.25 W would be too close to the limit).
Solution
128 + 32 + 16 + 2 + 1 = 179. Groups of four: 1011 = 11 = B, 0011 = 3, so 16#B3.
Solution
200 : 2 = 100 r 0; 100 : 2 = 50 r 0; 50 : 2 = 25 r 0; 25 : 2 = 12 r 1; 12 : 2 = 6 r 0; 6 : 2 = 3 r 0; 3 : 2 = 1 r 1; 1 : 2 = 0 r 1. From the bottom: 11001000. Check: 128 + 64 + 8 = 200. Groups: 1100 = C, 1000 = 8, so 16#C8.
Solution
1 · 256 + 10 · 16 + 7 = 256 + 160 + 7 = 423. In binary, digit by digit: 0001 1010 0111, or 110100111.
Solution
T = 0 + (10 − 4) / 16 · 150 = 6 / 16 · 150 = 56.25 °C. 3.0 mA is below the threshold of 3.6 mA: this is not a measurement but a fault (broken wire, disconnected or broken sensor).
Solution
d = 0 + (3.6 − 0) / 10 × 250 = 0.36 × 250 = 90 mm.
Solution
When C = 1, the output is always 0. When C = 0, the output is A + B. Rows (A B C → Y): 000 → 0; 001 → 0; 010 → 1; 011 → 0; 100 → 1; 101 → 0; 110 → 1; 111 → 0. The output is 1 in three lines.
Solution
A · B · C + A · B · C = A · B · (C + C) = A · B. Then A · B + A · B = A · (B + B) = A. Therefore, Y = A: the other variables do not matter.
Solution
Y = L · F = L + F: The alarm sounds if there is no oil or if the filter is dirty. A single NAND gate with inputs L and F is sufficient.
Solution
IB,min = 0.060 / 80 = 0.75 mA; IB = 5 × 0.75 = 3.75 mA; RB = (24 − 0.7) / 0.00375 = 23.3 / 0.00375 = 6213 Ω. We choose the lower standardized value, 5.6 kΩ: IB = 23.3 / 5600 = 4.16 mA. Power dissipated across the resistor: 23.3 × 0.00416 = 0.097 W, so 0.25 W. Don’t forget the feedback diode on the coil.
Solution
210 = 1024 steps; q = 10 / 1024 = 0.009 766 V = 9.77 mV. N = 3 / 0.009 766 = 307.2, so the code is 307.
Solution
ΔV = 0.5 / (100 × 0.0022) = 0.5 / 0.22 = 2.27 V.
Solution
4 = 0100, 7 = 0111, so 0100 0111. The BCD value 1001 0011 is 9 and 3, or 93 (in pure binary, the same byte would be 147: be careful not to confuse the two codes).
Solution
6 = 110 in binary → Gray 101; 7 = 111 → Gray 100. From 101 to 100, one bit changes. From 7 (100) to 0 (000), only one bit changes again: the Gray code is “cyclic,” meaning that even the transition from the last number to the first changes by one bit. In binary, going from 111 to 000 would change three bits.
Solution
t = 50 · 10 / 19,200 = 500 / 19,200 = 0.026 s = 26 ms.
Solution
R = (24 − 5.1) / (0.010 + 0.005) = 18.9 / 0.015 = 1260 Ω; we choose 1.2 kΩ. Current: 18.9 / 1200 = 15.75 mA. With the load disconnected, PZ = 5.1 × 0.01575 = 0.080 W; across the resistor, 18.9 × 0.01575 = 0.298 W, so a resistor rated for at least 0.5 W (preferably 1 W) is required.
