Electromagnetics for firmware people - Embedded.com

Electromagnetics for firmware people

A firm grasp of electromagnetics, now the foundational science of all digital engineering, is important as systems get faster.

Programming classes and circuit theory were a breeze for me as an EE student at the University of Maryland many years ago. Math was a bit more of a struggle, especially the more advanced classes such as abstract algebra. But the two required electromagnetics classes were killers.

I had no idea what the professors were babbling about. Orthogonal E and B fields sounded pretty simple until instantiated into the baffling form of Maxwell's equations.

Maxwell said a lot of profound things, like:

I'm told that this equation is a thing of beauty, a concise expression that encapsulates complex concepts into a single tidy formula.

Despite two semesters wrestling with this and similar equations, to this day I have no idea what it means. We learned to do curls and circular integrals till our eyes bugged out, but beyond the mechanical cranking of numbers I never quite got the intent hidden in those enigmatic chunks of calculus.

Every aspiring RF engineer missed many parties in their attempts to not only pass the classes, but to actually understand the material. Secure in the knowledge that I planned a career in the digital domain I figured a bare passing grade would be fine. Digital ICs of the time switched in dozens of nanoseconds. Even the school's \$10 million Univac ran at a not-so-blistering 1.25MHz. At those speeds electrons behave.

Not long after college IC-fabrication techniques started to improve at a dramatic rate. Speeds crept to the tens of megahertz and then to the billions of hertz. Gate switching times plummeted to intervals now measured in hundreds of picoseconds.

Ironically, now electromagnetics is the foundational science of all digital engineering. Even relatively slow 8-bit systems have high-speed signals propagating all around the printed circuit board, signals whose behavior is far more complex than the pristine nirvana of an idealized zero or one.

I should have studied harder.

Speed kills
Most of us equate a fast clock with a fast system. That's fine for figuring out how responsive your World of Warcraft game will be or if Word will load in less than a week. In digital systems, though, fast systems are those where gates switch between a zero and a one very quickly.

In 1822 Frenchman Jean Baptiste Joseph Fourier showed that any function can be expressed as the sum of sine waves. Turns out he was wrong; his analysis applies (in general) only to periodic functions, those that repeat endlessly.

The Fourier series for a function ƒ(x ) is:

The coefficients a and b are given by mathematical wizardry not relevant to this discussion. It's clear that if n gets huge, if a and/or b is non-zero then ƒ(x ) has frequency components in the gigahertz, terahertz, or higher.

What does this mean to us?

Digital circuits shoot pulse streams of all sorts around the printed-circuit board. Most, especially the system clock, look a lot like square waves, albeit waves that are somewhat distorted due to the imperfection of all electronic components. The Fourier series for a square wave—a representation of that signal using sines and cosines—has frequency components out to infinity. In other words, if we could make a perfect clock, an idealized square wave, even systems with slow clock rates would have frequency components up to infinite hertz racing around the board.

In the real world we can't make a flawless square wave. It takes time for a gate to transition from a zero to a one. The Fourier series for a signal that slowly drools between zero and one has low-frequency components. As the transition speeds up, frequencies escalate. Fast edges create high-frequency signals much faster than high clock rates do.

How bad is this? An approximate rule of thumb tells us most of the energy from logic transitions stays below frequency F given the “rise time” (or time to switch from a zero to a one) Tr :

Older logic like TI's CD74HC240 sport a rise time of 18ns or so. Little of the energy from Fourier effects will exceed 28MHz. But don't be surprised to find measurable frequency components in the tens of megahertz even for a system with a 1Hz clock.

The same component in more modern CY74FCT240T guise switches in a nanosecond or less. The energy cutoff is around 500MHz, regardless of clock speed.

Bouncing
Why do we care about these high frequencies racing around our system, especially when the clock sputters along at a mere handful of megahertz?

At DC a wire or printed-circuit board trace has only one parameter of interest: resistance. Over short runs that's pretty close to zero, so for logic circuits a wire is nearly a perfect conductor.

Crank up the frequency, though, and strange things start to happen. That simple wire or trace now looks rather like a capacitor and an inductor. Capacitors and inductors exhibit a form of resistance to alternating current called reactance . As the frequency goes up, a capacitor's reactance decreases. So caps block DC (the reactance is infinite) and pass AC. An inductor has exactly the opposite characteristic.

The wire still has its (small) DC resistance, and at high frequencies some amount of reactance. Impedance is the vector sum of resistance and reactance, essentially the total resistance of a device at a particular frequency.

So here's the weird part: Shoot a signal with a sharp edge down a wire or printed-circuit board trace. If the impedance of the gate driving the wire isn't the same as the one receiving the signal, some of the pulse quite literally bounces back to the driver. Since there's still an impedance mismatch, the signal bounces back to the receiver. The bouncing continues till the echoes damp out. Bouncing gets worse as the frequencies increase. As we've seen, shorter rise times generate those high frequencies.

Figure 1: Ringing from mismatched impedances

Figure 1 is an oscilloscope trace of a not very fast pulse with about a 5ns rise time. The overshoot and subsequent ringing visible on top of the “one” state is this bouncing effect.

Clearly, if the signal overshoots or undershoots by enough then wrong data can get latched. The system crashes, people sue, and you've barricaded yourself behind the entrance as a reporter from 60 Minutes pounds on the door.

It gets worse. Most of the logic we use today is CMOS, which offers decent performance for minimal power consumption. When the input to a CMOS gate goes somewhat more positive than the power supply (as that overshoot in Figure 1 does) the device goes into SCR latchup : the device tries to connect power to ground through its internal transistors. That works for a few milliseconds. Then the part self-destructs from heat.

Don't believe me? Back when I was in the in-circuit emulator business we finally shipped the first of a new line of debuggers. This 64180 emulator ran at a paltry 6MHz, but we drove signals to the user's target board very fast, with quite short rise times. The impedance of the customer's board was very different than that of our emulator; the overshoot drove his chips into SCR latchup. Every IC on his board quite literally exploded, plastic debris scattering like politicians dodging Michael Moore.

As I recall we never got paid for that emulator.

Firmware implications
Work with your board developers to ensure that the design not only works, but is debuggable. You'll hang all sorts of debug and test tools onto nodes on the board to get the code working properly. In-circuit emulators, for instance, connect to many dozens of very fast signals and always create some sort of impedance mismatch.

Figure 2: Termination resistors at the end of a driven line match impedances

Resistors are your friend. It's easy to add a couple of impedance-matching resistors, called terminators , at the receiving end of a driven line, as shown in Figure 2. Commonly used values are 220Ω for the pullup resistor and 270Ω for the one to ground. Since the power supply has a low impedance (otherwise the voltage to the chips would swing wildly as the load changes) the two resistors are essentially in parallel. With the values indicated the line sees about 120Ω, not a bad value for most circuits.

These terminators will greatly increase the power consumption of the board. Alternatively, you could replace the bottom resistor with a small, couple-of-hundred-picofarad capacitor.

Make sure the designers put terminations on critical signals. Any edge-triggered input to the processor (or to the circuit board) is particularly susceptible to electromagnetic-induced noise and reflections. For instance, the nonmaskable interrupt is often edge-triggered. Without termination the slight impedance change resulting from connecting a tool to the line may cause erratic and mysterious crashes.

Many processors reduce pin counts using a multiplexed bus. The CPU supplies the address first, while asserting a strobe named ALE (address latch enable), AS (address strobe), or something similar. External logic latches the value into a register. Then the processor transfers data over the same pins. Just a bit of corruption of ALE will—once in a while—cause the register to latch the wrong information. Without termination, connecting a tool may give you many joyous days of chasing ghostly problems that appear only sporadically.

Clocks are an ever-increasing source of trouble. Most designs use a single clock source that drives perhaps dozens of chips. There's little doubt that the resulting long clock wire will be rife with reflections, destroying its shape. Unfortunately, most CPUs are quite sensitive to the shape and level of the clock.

But it's generally not possible to use a termination network on a clock, as many CPUs need a clock whose “one” isn't a standard logic level. It's far better to use a single clock source that drives a number of buffers, each of which distribute the clock to a different part of the board. To avoid skew (where the phase relationship of the signal is a bit different between each of the resulting buffer outputs), use a single buffer chip to produce these signals.

One of my favorite tools for debugging firmware problems is the oscilloscope. A mixed-signal scope, which combines both analog and digital channels, is even better. But scopes lie. Connect the instrument's ground via a long clip lead and the displayed signal will be utterly corrupt since Fourier frequencies that far exceed what you're measuring turn long ground wires into complex transmission lines.

Use that short little ground lead at the end of the probe and things might not get much better. As speeds increase that 3-inch wire starts to look like an intricate circuit. Cut it shorter. Or remove the ground lead entirely and wrap a circle of wire around the probe's metal ground sheath. The other end gets soldered to the printed-circuit board and is as short as humanly possible.

A reference
After staggering through those electromagnetics classes I quickly sold the textbooks. They were pretty nearly written in some language I didn't speak, one as obscure to me as Esperanto.

But there is a book that anyone with a bit of grounding in electronics can master, one that requires math no more complex than algebra: High-Speed Digital Design: A Handbook of Black Magic , by Howard Johnson and Martin Graham (1993, PTR Prentice Hall, Englewood Cliffs, NJ).

Reviewers on Amazon either love the book or hate it. Me, I find it readable and immediately useful. The work is for the engineer who simply has to get a job done. It's not theoretical at all and presents equations without derivations. But it's practical.

And as for theoretical electromagnetics? My son goes to college in the fall to study physics. I've agreed to write the checks if he answers my physics questions. Maybe in a few years he'll be able to finally explain Maxwell's equations.

Till then you'll have to pry my termination resistors from my cold, dead hands.

Jack G. Ganssle is a lecturer and consultant on embedded development issues. He helps companies with their embedded challenges, and is conducting one-day seminars about building better firmware faster in Austin and Baltimore in April. Contact him at .

Interesting article; however, you probably shouldn't have thrown away your E-M book. Maxwell's curl equations relate electric fields to magnetic fields. For a steady-state sinusoidal field, I believe that the curl of the electric field vector E–not–B is equal to the negative partial derivative of the magnetic flux density B w.r.t. time. The multiplicative factor depends on whether you use D instead of E and H instead of B.

– Tom Taylor

In the form of Maxwells' equation you have listed, the letter on the left of the = should be E and the letter on the right should be H. Change the letters to D & B, respectively, and the constants go away. This equation simply states that a time-varying magnetic field produces an electric field(in a vacuum, for the constants you listed).

– Jack Crack

I believe PCBs are being designed for very high frequencies utilizing the emag properties you write about here. By strategically placing conductors on the board, they create transmission lines that mimic capacitors and inductors and help alleviate some of the design issues you are facing. I think this also helps match impedance, removing reflections, without requiring as much of a power drain as your termination resistors. Bear in mind my knowledge/experience on this is roughly 2 years old now, so I may have something backwards or totally wrong. 🙂 RF is cool!

– Rob

This site uses Akismet to reduce spam. Learn how your comment data is processed.