Travel, Code, and Engineering

on March 1, 2015 by Kurt Tomlinson

Buck converters work by switching on and off at very high frequencies. Examine the schematic below. The circle on the left is a voltage source at say 12V. The rectangle on the right is a load that we want to power with say 3V. Let's call the bottom of the load ground and define that voltage as 0V.

Examine the inductor and the capacitor as a pair. Together they act as a low-pass filter with the input on the left and the output on the right. Refer back to Buck Converter Concepts: LC Low Pass Filters if you don't remember how LC filters behave.

The voltage at the input of the LC filter can be one of two values: 12V when the high side switch is closed or 0V when the high side switch is open. It's obvious why the voltage is 12V when the high-side switch is closed. Why is the filter input voltage 0V when the high side switch is open?

The current through an inductor cannot change instantaneously. When the high side switch is closed, current is flowing to the right through the inductor. After the high side switch opens, current continues to flow through the inductor to the right. This draws current upwards through the diode. Since the diode is forward-biased by this current, the voltage at the top of the diode is equal to the voltage at the bottom of the diode minus the forward voltage of the diode. If we assume the diode is an ideal diode, then the forward voltage of the diode is 0V. Therefore, the voltage at the bottom of the diode (0V) minus the forward voltage of the diode (0V) gives the voltage at the top of the diode (0V).

Turning the high side switch on and off produces a square wave at the input of the LC filter. As we saw in Buck Converter Concepts: Frequency Content of Square Waves, square waves have a DC component and some frequency content at frequencies that are integer multiples of the wave's fundamental frequency. When properly designed, the LC filter removes everything but the DC component of the square wave.

In our example, the input voltage is 12V and the output voltage is 3V. If we turn on the high side switch for 25% of each cycle, then the average voltage at the input of the LC filter will be 3V. The high-frequency components of the square wave get filtered out, and only the smooth DC voltage of 3V shows up at the output of the filter.

Extra Credit: Why is the diode necessary? If the diode is not present, the switch would be destroyed. Suppose the load draws 1A of current. This means that the current through the inductor is 1A when the switch is closed. When the switch opens, the current through the inductor remains the same; the inductor current cannot change instantaneously. The resistance of the switch when it is open is some large but finite number. Let's say it's 10Mohm. Given that the current is 1A, and the resistance of the switch is 10Mohm, the voltage across the switch would be V = IR = 1A*10Mohm = 10MV. That's a huge voltage! (The dielectric breakdown of air occurs at about 3MV/m. A voltage difference of 10MV could arc over three meters through air!) This huge voltage will arc across whatever gap is present in the switch and cause catastrophic damage to the switch.

Photo by Paul Cross

on February 22, 2015 by Kurt Tomlinson

The LC low pass filter has just two components: an inductor and a capacitor. The inductor and capacitor are connected in series. The input to the filter is fed into the inductor, the output is taken from the node between the inductor and the capacitor, and the capacitor's other terminal is tied to ground.

The impedance of an inductor is Z_L = L*s where L is the inductor's inductance in Henrys, s=j*w, where j=sqrt(-1) and w=2pif where f is the signal frequency.

The impedance of a capacitor is Z_C = 1/(C*s) where C is the capacitor's inductance in Farads, s=j*w, where j=sqrt(-1) and w=2pif where f is the signal frequency.

Noting that the topology is that of a voltage divider, the transfer function for the filter can be written as

H(s) = Z_C / (Z_L+Z_C) H(s) = 1/(Cs) / (Ls+(1/Cs)) H(s) = (Cs)/(Cs) / ((Cs)(L*s+(1/Cs))) H(s) = 1 / (LCs^2 +1)) H(S) = (1/LC) / (s^2 +(1/LC)) H(S) = w_0^2 / (s^2 +w_0^2 )

H(s) = Z_C / (Z_L+Z_C)

H(s) = 1/(Cs) / (Ls+(1/Cs))

H(s) = (Cs)/(Cs) / ((Cs)(L*s+(1/Cs)))

H(s) = 1 / (LCs^2 +1))

H(S) = (1/LC) / (s^2 +(1/LC))

H(S) = w_0^2 / (s^2 +w_0^2 )

where |H(s)| is the gain, arg(H(S)) is the phase shift, and w_0 is the frequency in radians where the output is down -3dB from the input (|H(s)| = 1/sqrt(2) = -3dB).

Let's look at a real-life application of this circuit. The LM25574 is a chip that is used to convert a high input voltage (~12 VDC) into 5 VDC. The datasheet for this part has a helpful "Typical Application Circuit and Block Diagram" showing how it's used.

I've taken a portion of that circuit, simplified it, and added some color to make it easier to understand. I colored the chip light blue, ground is green, and the output of the LC low pass filter is red. This chip outputs a square wave on its SW pin at 1 MHz, and the LC filter is used to filter this so that only the DC component gets to the output. This filter is responsible for keeping the output of this circuit at a steady 5 VDC.

Let's see how well it should work. The cutoff frequency of this circuit is

w_0=sqrt(1/(L*C)) w_0=sqrt(1/(100e-6*22e-6)) w_0=21,320 rad/s f_0=3393 Hz

w_0=sqrt(1/(L*C))

w_0=sqrt(1/(100e-6*22e-6))

w_0=21,320 rad/s

f_0=3393 Hz

Right away we can see that any signal above 3.4 kHz will be attenuated by at least -3 dB. Since 1 MHz is much larger than 3.4 kHz, we can guess that it will be greatly attenuated by this filter.

H(0) = 1 so the DC component of the output will pass through unaffected. |H(j2pi*1e6)|=1.1514e-5=-98.8 dB! The 1 MHz component of the signal will be 98.8 dB less than it was in the original signal! The harmonics of the original signal are all at frequencies higher than 1 MHz, so they'll all be attenuated even more! Effectively, this filter takes in a 1 MHz square wave and outputs a smooth, constant 5V. Perfect for powering other circuits!

This entry is part two of a three-part series explaining how DC-DC buck regulators work.

Photo by spodzone

on February 15, 2015 by Kurt Tomlinson

Take a square wave with a duty cycle of 0<x<1, a frequency of f, and an amplitude of A. (The minimum value of this square wave is 0.) This signal can be decomposed into its frequency components by Fourier analysis. The frequency components of a signal are just the collection of sine waves that when added together give you the original signal.

"SquareWave" by Peretuset - Own work. Licensed under CC BY 3.0 via Wikimedia Commons.

The first sine wave of interest in our square wave is the 0 Hz sine wave. It's not really a sine wave, it's just the average value of the signal over one period. For our square wave, the average value over one period is Ax + 0(1-x) = A*x. This frequency component is the "DC value" of the signal.

The next sine wave of interest is the one at the fundamental frequency of our signal. The fundamental frequency of our signal is the lowest frequency component of the signal. It's determined by the period of the signal and is known as f_1: f_1 = 1/T. In the case of our square wave, the fundamental frequency is f.

The rest of the frequency components of our square wave all have frequencies that are greater than the fundamental frequency. In fact, all the other components are known as "harmonics" and have frequencies that are integer multiples of the fundamental. This is all true regardless of the duty cycle of our square wave.

This means that our square wave will have some power at 0 Hz and f HZ, but no power in between. Were we able to somehow remove all frequencies above n Hz where 0<n<f then we'd be left with a simple DC waveform. This is the basic concept behind a DC-DC buck regulator.

Photo by Rising Damp

on February 8, 2015 by Kurt Tomlinson

Never heard of Bunny Island? Its real name is Ōkunoshima. It's an island filled to the brim with cuddly "wild" bunnies. How many? Hundreds!

You have to take a ferry to get there because it's an island, obviously. When we first got off the ferry we saw a couple bunnies. "No big deal," I thought. But that was just the beginning.

We had planned ahead and brought two carrots and a head of cabbage. Bunnies like carrots, right? Wrong! Bunnies LOVE carrots. They smelled the produce as soon as we took it out of our bag and rushed over for a piece of the action. We were immediately surrounded by dozens of cute bunnies.

If you're sneaky you can pick one up. They will happily let you hold them as long as you give them something to munch on. Once the noms are gone, they start squirming to escape.

There's a hotel on bunny island that sells pellets. The bunnies just go crazy for them. We came across a girl who was tossing pellets into the air by the handful. She had amassed quite a bunny following.

During World War II, the Japanese had a poison gas factory on the island of Ōkunoshima. The factory had rabbits on hand for testing the poison. At the end of the war, the rabbits were released onto the island. Whether the rabbits on the island today are descendants of those rabbits or not isn't known. However they got there, it's still a fun place to visit.

Where is it located? It's in the southwestern part of Japan...

...east of Hiroshima...

...and just south of Tadanoumi Station.

How do you get there? It's not terribly hard, but it takes some time. First, get to Hiroshima Station. Then take the JR Tokaido / Sanyo Shinkansen from Hiroshima Station to Mihara Station. Then take the JR Kure line from Mihara Station to Tadanoumi Station. Once you get to Tadanoumi Station, things get a little tricky. Tadanoumi Station is way off the beaten path, so absolutely nothing is in English there. Luckily, there's a rabbit to welcome you and a map showing where to go.

We completely missed the ferry map even though I took a picture of it. The lack of English was so disorienting I didn't know what I was looking at. Sorry for the bad quality. I took the picture from across the tracks with my finger in front of the lens. Oops.

Basically you exit the train station and just keep turning right until you get to the ferry station. There's a vending machine there that sells tickets, but I can't read Japanese.

Instead just go to the ticket window and say "oh-coo-no-shee-muh round-trip" while holding up your fingers to show how many people are in your group. Japanese people are smart and polite. They'll figure out what you want.

There's also a time-table posted above the ticket booth. Make sure you don't miss the last ferry back. Otherwise you'll be sleeping with the bunnies.

on February 4, 2015 by Kurt Tomlinson

In my line of work as a semiconductor test engineer, pseudo-random binary/bit sequences are very useful. They're random-ish streams of bits that can be easily and reliably reproduced using very simple hardware or software. Any semiconductor that can be used to transmit information can be tested at a functional level with a PRBS. Send a PRBS to the device you're testing, tell the device to repeat it back to you, and compare what you received to what you sent.

A PRBS is preferred over a simple square wave because it stresses the device under test in more ways. It's not uncommon for a device to have no problem transmitting a sequence like "010101" but choke on a sequence with repeated bits like "011101". PRBSs include strings of repeated bits as well as strings of alternating bits.

Some common PRBSs are referred to by the degree of the polynomial that is used to generate them:

These polynomials are elements of GF(2n) (the Galois Field of two elements). These polynomials can also be represented as binary numbers:

First, a seed polynomial is chosen. This seed polynomial can be any non-zero polynomial in the field GF(2n) where n is the degree of the PRBS polynomial. Zero can't be chosen as a seed state because the seed is multiplied by x to produce the next state. If the seed is zero, this product is zero and there is no next state.

The Project Nayuki website has a good description of how to calculate the state of the LSFR at each step:

Note that this method produces the states in reverse order when compared with the code given later in this post. Here's an example of the math worked out by hand:

The javascript below can be used to generate PRBSs from the binary reqresentation of a PRBS polynomial:

var polynomial = "10100"; //"1100000" = x^7+x^6+1 //"10100" = x^5+x^3+1 //"110" = x^3+x^2+1 var start_state = 0x1; /* Any nonzero start state will work. */ var taps = parseInt(polynomial, 2); var lfsr = start_state; var period = 0; var prbs = ""; do { var lsb = lfsr & 1; /* Get LSB (i.e., the output bit). */ prbs = prbs + lsb; lfsr >>= 1; /* Shift register */ if (lsb == 1) { /* Only apply toggle mask if output bit is 1. */ lfsr ^= taps; /* Apply toggle mask, value has 1 at bits corresponding to taps, 0 elsewhere. */ } ++period; } while (lfsr != start_state); console.log("period = " + period); console.log("prbs = " + prbs); if (period == Math.pow(2, polynomial.length)-1) { console.log("polynomial is maximal length"); } else { console.log("polynomial is not maximal length"); }

The script above produced these outputs:

PRBSs produce 2n-1 bits before repeating. See section III. LFSR and Galois Fields in Linear Feedback Shift Registers, Galois Fields, and Stream Ciphers by Mike Thomsen for an overview on how to find PRBS polynomials for a desired repetition length. Additionally, Wikipedia has a list of polynomials for maximal LFSRs and Philip Koopman has provided lists of longer polynomials for maximal LFSRs on his website.

Photo by Vladimer Shioshvili.