Signal integrity and EMC
Rise times, reflections, grounding and passing EMC.
When a wire stops being a wire
At low speeds, a trace between two pins is just a connection. Once signal edges are fast compared with the time it takes them to travel down the trace, the trace behaves as a transmission line: signals reflect, ring and couple into their neighbours. Embedded engineers meet this as SPI that works at 1 MHz but not at 20 MHz, a clock that glitches, or a product that fails its EMC test.
Edges, not frequency, set the problem
What matters is the rise time, not the clock rate. A 1 MHz signal from a modern MCU pin can have a 2 ns edge, which contains frequency content up to about 0.35 / t_rise ≈ 175 MHz.
A rule of thumb: a trace needs transmission-line treatment when its length exceeds about a sixth of the distance a signal travels during the rise time. Signals travel at roughly 15 cm per nanosecond on an FR-4 board.
#include <stdio.h>
int main(void) {
double cm_per_ns = 15.0; /* approximate speed on FR-4 */
double rise_ns[] = { 10.0, 2.0, 0.5 };
for (int i = 0; i < 3; i++) {
double bandwidth_mhz = 0.35 / rise_ns[i] * 1000;
double critical_cm = rise_ns[i] * cm_per_ns / 6;
printf("rise %4.1f ns: content to %4.0f MHz, treat traces over %4.1f cm as transmission lines\n",
rise_ns[i], bandwidth_mhz, critical_cm);
}
return 0;
}
This is why the GPIO speed (slew rate) setting matters: the slowest setting that meets timing makes every signal-integrity and EMC problem smaller.
Reflections and termination
A transmission line has a characteristic impedance (typically 50 Ω for single traces, 90 to 100 Ω for differential pairs). When a signal reaches a point where the impedance changes (the end of a line, a connector, a branch), part of it reflects back. The result is overshoot, undershoot and ringing that can cross logic thresholds twice, creating false clock edges.
Fixes:
- Series termination: a resistor (22 to 47 Ω) at the driver, so driver impedance plus resistor matches the line. Cheap and common on SPI clocks and fast GPIO.
- Parallel termination: a resistor at the far end matching the line impedance; used on buses such as CAN (120 Ω at each end) and RS-485.
- Short traces, no stubs, point-to-point routing for fast signals.
Crosstalk
Two traces running side by side couple through capacitance and inductance; a fast edge on one induces a pulse on the other. Reduce it by spacing traces (about three times the trace width), routing fast signals over a solid ground plane, keeping parallel runs short, and slowing edges.
Grounding and return paths
Every signal current returns to its source. At high frequencies the return current flows in the ground plane directly underneath the signal trace, because that path has the lowest inductance. Problems arise when that path is interrupted:
- A split or slot in the ground plane under a fast trace forces the return current around it, forming a loop antenna: a top source of radiated emissions.
- A signal changing layers needs a nearby ground via so its return can follow.
- Long, thin ground connections between boards add inductance; fast signals across connectors need ground pins next to them.
For most mixed-signal MCU boards, a single solid ground plane with careful component placement (analog parts away from switching regulators and digital buses) beats splitting analog and digital grounds.
EMC: emissions and immunity
Electromagnetic compatibility testing has two sides:
| Emissions | Immunity | |
|---|---|---|
| Question | Does the product radiate or conduct too much noise? | Does it keep working when exposed to noise? |
| Tests | Radiated and conducted emissions | ESD, fast transients (burst), surge, radiated and conducted RF |
| Standards | FCC Part 15, CISPR 32 (EN 55032) | IEC 61000-4-x series |
Common sources of emissions: switching regulators, clocks and their harmonics, fast edges on long traces and cables (cables are excellent antennas), and ground loops.
Design measures:
- slow edges (GPIO speed settings, series resistors)
- solid ground plane and short return paths
- decoupling at every IC, and filtering (ferrite beads, common-mode chokes) where cables leave the board
- spread-spectrum clocking, which smears clock harmonics across a band and reduces peaks
- shielding as a last resort
Immunity measures where firmware helps:
- ESD protection diodes on connectors, plus firmware that tolerates a glitch: re-initialise a peripheral that stops responding, check and refresh critical configuration registers periodically, use a watchdog
- debouncing and plausibility checks on inputs
- CRCs and retries on communication links
Firmware's part
- Choose the lowest GPIO speed that works.
- Use spread-spectrum on the PLL if the MCU supports it.
- Do not toggle pins faster than needed; turn off unused clock outputs (MCO).
- Write drivers that recover from a corrupted transfer instead of hanging.
- In immunity tests, log and count errors rather than resetting silently, so the test lab report shows what happened.
Pitfall: A logic analyser shows clean ones and zeros even when the real signal rings badly, because it only samples thresholds. Use an oscilloscope with a short ground spring on the probe to see signal integrity problems.
Interview question: How can firmware help a product pass EMC testing?
Answer: For emissions: use the slowest GPIO slew-rate settings that meet timing, enable PLL spread-spectrum clocking if available, disable unused clock outputs and peripherals, and avoid unnecessary fast toggling on pins that drive long traces or cables. For immunity: make drivers recover from errors (timeouts, re-initialisation of a peripheral that stopped responding), refresh critical configuration periodically, validate and retry communications with CRCs, debounce inputs, use the watchdog, and log error counters so the test results are diagnosable.
Interview question: Why should you avoid routing a fast signal over a gap in the ground plane?
Answer: The signal's return current flows in the plane directly under the trace at high frequency. A gap forces it to detour around the slot, enlarging the current loop. That loop's inductance causes ringing and makes it an efficient antenna, increasing radiated emissions and susceptibility, and it couples noise into other signals sharing the detour. Keep fast traces over continuous ground, and stitch with ground vias when changing layers.
Build it: ignore the spikes on the door wire
This is step 2 of the module project, the wireless door sensor. In some installs the reed switch sits at the end of a two-metre wire run through the door frame, next to mains cables and a fluorescent lamp. In the EMC immunity test (ESD on the frame, bursts on the mains), the wire picks up spikes that look like the door opening, and a false alarm at 3 a.m. is how alarm systems get switched off for good. The firmware filters the input, and counts what it rejected, so the test report shows the filter working.
Lab: An integrator filter that counts rejected glitches
door_sample(f, raw) is called every millisecond with the pin's level (1 = door open) and returns the filtered state.
- Keep a counter from 0 to
FILTER_MAX: add 1 for each sample of 1, subtract 1 for each 0, stopping at the ends. - The filtered state changes to 1 only when the counter reaches
FILTER_MAX, and to 0 only when it reaches 0. In between it keeps its last value. A spike has to outweigh the clean samples around it to get through, and a real change gets through afterFILTER_MAXsamples. - Count a glitch each time the counter leaves the end matching the current state and comes back to it without the state changing: noise was seen and rejected. A real change is not a glitch.
f starts all zeros: door closed, counter at 0.
Going deeper
Interview question: A greenhouse controller's readings jump when the pump switches on. How do you fix it?
Answer: Look at the supply and ground with a scope when the pump switches: the motor's current is likely shifting ground or coupling into the sensor wires. Separate the motor's power and ground return from the sensor ground, add a flyback diode and snubber, decouple the MCU and sensor supplies, route sensor cables away from motor wires, and filter readings in firmware.
Interview question: What is ground bounce?
Answer: When many outputs switch at once, the combined current spike flowing through the inductance of the package's ground pins and the board's ground path causes the chip's internal ground to jump relative to the board ground. Inputs referenced to it see false transitions and outputs glitch. It is reduced by more ground pins and vias, good decoupling, slower edges and not switching many outputs simultaneously.
Interview question: How does a common-mode choke help a cable pass EMC tests?
Answer: Signals on a cable pair carry equal and opposite currents (differential mode), while noise that radiates or is picked up tends to flow the same way on both wires (common mode). A common-mode choke presents high impedance only to common-mode current, so it suppresses the noise that makes the cable an antenna while passing the wanted differential signal. It is standard on USB, Ethernet and CAN lines.
Explain it: In your own words, explain why the GPIO speed setting affects EMC even at low toggle frequencies.
Answer: Radiated noise is set mostly by how fast a signal changes, its rise and fall times, not by how often it toggles. A fast edge contains energy up to hundreds of megahertz even if the pin only toggles once a second, and that energy radiates from traces and cables and couples into neighbouring signals. Selecting the slowest GPIO speed setting that still meets the interface's timing makes the edges slower, which removes most of that high-frequency content and helps the product pass emissions tests.