Control applications
Three applications that come up again and again in industry, and that force you to bring together everything covered so far: weighing and dosing, elevator control and automatic verification and test systems. In all three, the microcontroller is the easy part; the hard part is the real problem.
Temperature and lighting control is covered in control with devices, sensors and actuators in sensors and actuators, and the internal peripherals in microcontroller peripherals. Here they are applied to three concrete problems.
01Weighing with a load cell
| Load cell parameter | What it means |
|---|---|
| Rated capacity | The maximum weight it can take without damage: 5, 50, 500 kg. Choose it with a margin over the actual load, including the weight of the container. |
| Sensitivity | Typically 2 mV/V: with 5 V of excitation it delivers 10 mV at full scale. It is a tiny signal. |
| Bridge resistance | 350 Ω is the usual value. It determines the excitation current and the heating. |
| Accuracy class | Defines linearity, hysteresis and drift. It is what separates a commercial scale from just any force sensor. |
| Temperature compensation | The range over which the cell keeps its accuracy. Outside it, the reading drifts. |
50 kg cell, sensitivity 2 mV/V, excitation 5 V, 24-bit converter with a gain of 128 and a ±20 mV input.
- Full-scale output: 2 mV/V × 5 V = 10 mV for 50 kg.
- That means 0.2 mV per kilogram, or 200 nV per gram.
- The converter has 24 bits over ±20 mV, that is, a step of about 2.4 nV. In theory that would be enough to resolve hundredths of a gram.
- In practice noise leaves about 17 to 19 useful bits: the real resolution is around 1 to 5 grams, and only with good filtering and averaging.
The conclusion matters: the converter’s bits are not the resolution. What rules is the noise of the whole chain, which is why the wiring, the power supply and the averaging decide the result.
- Load cell cable near power wiring: 200 nanovolts per gram forgive nothing. The cable must be shielded, kept apart and as short as possible.
- Noisy power supply: the cell’s excitation must be clean and stable. Any variation translates directly into weight.
- Poor mechanical mounting: the cell has to work in the direction it was made for. Loading it from the side, seating it crooked or letting the container rub against something introduces errors far larger than any electronic detail.
- Temperature: thermal drift is real. Let the equipment stabilize before calibrating.
First do the zeroing with the container empty —that reading is the tare— and then place a known reference weight. These two points define the line weight = (reading − zero) × slope. If the cell is good, two points are enough; if more are needed, the problem is mechanical or the cell is no good.
02Batch dosing
| Stage | What the control does |
|---|---|
| Tare | With the container empty and at rest, it takes the zero. The whole batch is measured from there. |
| Fast fill | Opens the high flow until the coarse shut-off point is reached, typically 90 to 95% of the target. |
| Slow fill | Low flow only. Accuracy is gained at the cost of time. |
| Early cutoff | Closes before the target, allowing for the in-flight material. That value is learned from the previous batches. |
| Settling and final weighing | Waits for the scale to settle and records the actual weight of the batch. |
| Correction | Adjusts the early cutoff according to the error of the previous batch. This is what makes the system improve on its own. |
A hopper discharges 2 kg/s at coarse flow and 0.2 kg/s at fine flow. The valve takes 150 ms to close and the material takes 120 ms to reach the scale.
- Cutting off at coarse flow: 2 kg/s × 0.27 s = 540 g of overweight. Unacceptable.
- Cutting off at fine flow: 0.2 kg/s × 0.27 s = 54 g. Can be compensated by cutting early.
- With automatic correction, the final error settles at a few grams.
That is why every serious doser has two speeds. With only one, it is either accurate and extremely slow, or fast and out of tolerance.
03Elevator control
- Calls: car calls and floor calls are stored in two tables of flags.
- Selection: while going up, it serves the calls that are above and in the same direction; when they run out, it reverses. This is the selective collective control, and it is what keeps the elevator from making absurd trips.
- Position: it is known from floor sensors and leveling-zone sensors, and is checked continuously. If the system loses the position, it makes a recovery trip to one end.
- Speed: starting and braking with ramps, and a slow approach to the floor. An elevator that brakes abruptly is a poorly controlled elevator.
It is a series circuit of contacts that, if opened at any point, cuts off the operation: landing door contacts, car door contacts, end-of-travel limit switches, overspeed governor, safety gear and emergency stop buttons.
This circuit is independent of the program and acts directly on the power. An elevator does not stop because the software decides so: it stops because the chain opened. The microcontroller reads the state of the chain to report and log, but it is not what protects.
It applies to the elevator and to any machine: safety is not implemented in software. It is implemented with physical interlocks, positively driven (forced-opening) contacts and safety relays, and the program takes care of comfort and service logic. A program can hang; a contact open in series with the coil cannot. We return to this in health and safety.
04Automatic verification and test systems
An automatic test bench subjects every manufactured unit to a sequence of tests, decides whether it passes or not, and stores the result. It is what allows a production run to have measurable quality instead of declared quality.
| Part | Function |
|---|---|
| Fixture | A device that positions the part the same way every time and makes contact with the test points. It is the part that most defines repeatability. |
| Stimulus | Power supplies, generators and input signals that put the unit under the test conditions. |
| Measurement | Multimeter, converters, counters. Each quantity with its instrument and its stated accuracy. |
| Sequence | The program that orders the tests, applies the limits and decides. It stops at the first failure or runs them all, as appropriate. |
| Log | Serial number, date, measured values and verdict. Without a log, the bench can sort units but cannot improve the process. |
A test has a specification limit —what the product must meet— and it is advisable to have in addition a stricter process limit. Units that fall between the two pass, but are flagged: they are the early sign that the process is drifting. When the whole production run starts to pile up near the limit, there is a problem even though nothing fails yet.
And something that is always forgotten: the test bench must also be verified. Periodically run a known good reference unit and another deliberately bad one, to confirm that the bench still detects what it should.
05In the lab
Build a scale with a load cell, an amplifier and a microcontroller. Calibrate with two points, measure the repeatability by weighing the same weight ten times and calculate the deviation. Repeat with the load cell cable near a running motor and compare.
With a simple hopper and a valve or a vibrator, dose a target quantity of granular material. Implement coarse and fine shut-off and automatic correction of the cutoff point. Plot the error of the first twenty batches: you can see how the system learns.
On a model with three or four floors, program the selective collective control with car and floor calls. Add a physical safety chain in series with the contactor and verify that opening any contact stops the movement, even if the program insists.
Build a bench that automatically verifies a simple board made in the workshop: supply voltages, current consumption, response of the outputs. Define limits, generate a verdict and store a log for each unit. Test the bench with a good board and with one deliberately sabotaged.
06Common mistakes
| Mistake | Consequence |
|---|---|
| Confusing converter bits with real resolution | An accuracy is promised that the noise of the chain does not allow to be reached. |
| Load cell cable next to power wiring | The weight reading jumps every time a motor starts. |
| Careless mechanical mounting | Rubbing and side loads produce errors far larger than any electronic detail. |
| Dosing with a single speed | It is either accurate and extremely slow, or fast and always overshoots. |
| Not allowing for the in-flight material | Systematic overweight in every batch. |
| Putting safety in the program | If the program hangs, there is no protection. Interlocks are physical and in series. |
| Test bench that is never verified | It may be passing bad units for months without anyone noticing. |
| Testing without logging | Product is sorted, but the process cannot be improved nor a batch traced. |
07Self-assessment
How much voltage does a 2 mV/V cell deliver with 5 V of excitation, at full scale?
10 mV. That is why an instrumentation amplifier and a high-resolution converter are needed.
Why don’t 24 bits mean resolving micrograms?
Because the noise of the whole chain leaves quite a few fewer useful bits, generally between 17 and 19. The real resolution is set by the noise, not by the converter.
How is a scale calibrated?
With two points: zero with the container empty —the tare— and a known reference weight. From these come the intercept and the slope.
What is in-flight material and why does it matter?
The material that has already left the hopper and has not yet reached the scale when the close command is given. You must cut off early by that amount, or every batch comes out overweight.
Why does a doser use two speeds?
Because the high flow gives speed but a lot of in-flight material, and the low flow gives accuracy but is slow. Combining them gives a batch that is both fast and accurate.
What is selective collective control?
The logic by which the elevator, while going up, serves only the calls that are above and in the same direction, and reverses only when it has used them up.
What is the safety chain of an elevator?
A circuit of contacts in series —doors, limit switches, overspeed governor, safety gear, emergency stops— that cuts off the operation if it opens at any point, independently of the program.
Why is safety not implemented in software?
Because a program can hang, become corrupted or have a bug; a contact open in series with the contactor coil cannot. Software takes care of service, not of protection.
What is the difference between the specification limit and the process limit?
The specification limit is what the product must meet; the process limit is stricter and serves as an early warning: if production approaches it, something is drifting even though nothing fails yet.
How do you verify that a test bench is still working?
By periodically running a good reference unit and another deliberately bad one through it, and confirming that it classifies them correctly.