Sunday, May 31, 2009

Electricity for Synth-DIY'ers: Inductors and Coils

I'm not going to write extensively about inductors, because they aren't used much in synthesizer circuits. The main reason I am writing about them is because they are, in a mathematical and engineering sense, complementary to capacitors. It is necessary to know a bit about in inductors in order to fully understand reactance, which is the over-arching principle that determines how AC circuits behave in the presence of both inductance and capacitance. Also, we need to describe inductance in order to understand how transformers and relays work.

An inductor is basically a coil of wire, which might or might not be wrapped around a metal bar or rod, or some other cylindrical object. You often see inductors in a circuit as coils of what appear to be bare copper wire, wrapped around a cardboard or plastic core. The copper is not actually bare; it is coated with a thin enamel insulation, similar to enamel paint. The reason enamel-insulated wire is often used for inductors is because it is thinner and allows the coils to be placked tighter, and also because it tolerates higher temperatures than most PVC-based wire insulation. The most frequently seen enamels are either clear, or have a reddish tinge that makes the copper look especially gold or red in color. Unlike nearly every other basic electrical component, inductors can be home-made fairly easily, and electronic supply houses sell prefabricated cores of certain lengths, diamaters, and materials for wrapping copper coils around to make inductors.



Inductors (image from Wikipedia Commons)



Inductors in DC Circuits

So what does an inductor do? The idea is simple: it fights any change in the current flowing through it. If a constant DC current is applied to an inductor, the inductor will, in theory, have little or no effect (the resistance of the wire may act like a low-value resistor). However, if anything causes the amount of current that is flowing to change, the inductor will fight that change. If the current tries to increase, the inductor will limit the rate at which the current can increase. Here's where it gets interesting: It will also limit the rate at which the current can decrease -- if the current tries to decrease, the inductor will actually "suck" current through in an attempt to keep it constant! The inductor does this by developing a voltage across it, from one end to the other, that tries to keep the current constant.

Here's a thought experiment. DO NOT ACTUALLY TRY THIS! Imagine a circuit with a battery connected to a switch and a large-value inductor, all in series. Initially, the switch is off, so no current is flowing. Then, we turn the switch on. What happens? The inductor does not allow the current to go to maximum immediately. Instead, the current ramps up gradually. Eventually, it reaches the maximum current that the battery is capable of supplying, but if we have a really large value inductor, it will take some number of seconds. If we had an ammeter or a scope with a current probe monitoring this, we could see it going up slowly at first, and then faster as it approaches the maximum value.


What happens when we turn the switch off? The current tries to go to zero immediately -- and the inductor doesn't like it one bit! It will develop a LARGE voltage in an attempt to "suck the current through", and very likely it will draw an arc across the switch contacts! This is why I said in the previous paragraph not to try this (unless you have a well-equipped lab and your fire insurance is paid up).

Inductors in AC Circuits

So in a DC circuit, an inductor can do drastic things when large step changes occur in the current, but as long as the current is in a steady state, nothing interesting happens; the current simply flows through. But what about an AC circuit? After all, a fundemental characteristic of AC is that the voltage, and hence the current, is changing all the time. Well, the obvious answer is that the inductor will resist all of the changes in the current, and it will do so in a manner that tends to keep the average current at a midpoint value. If we assume that the waveform is symmetrical, then the average current will be at the midpoint between the top and bottom peaks. If we further assume that the waveform has no DC offset, then that midpoint value is zero. Which means that, in effect, the inductor is acting like a resistor to the AC current.
At this point, we note something about AC. As we know from the Fourier theorem, all alternating signals are made up of sums of component sines. Let's consider two sine waves, both of the same peak-to-peak magnitude, but one of a low frequency and one of a higher frequency:



Low-frequency sine (green) and high frequency (red).
The dashed lines show the maximum slopes.

Note the slopes of the two sine waves where they cross the axis. You can see that the high-frequency one is rising and falling at a greater slope, and hence a faster rate, than the low-frequency one. So if we run both of them through an inductor, what happens? Per our discussion above, the inductor will resist both of them, but it will resist the higher-frequency one more. The inductor is acting like a frequency-dependent resistor, whose value increases with frequency -- which makes it a low-pass filter. You may recall seeing the previous sentence in the capacitors discussion. In fact, in an AC circuit, the inductor does the opposite of what the capacitor does; the capacitor is a high-pass filter; the inductor is a low-pass filter. And you can do, in theory, most of the same things with inductor-based filters that you can do with capacitor-based filters.

However, in reality, inductors are rarely used as filters in modern audio equipment. The reason is that small inductors are only effective in the RF range; an inductor-based filter for audio requires a huge inductor. There are practical problems with large inductors; besides the physical size, weight, and cost in copper, they also have the unfortunate habit of acting like radio antennas. A large inductor will pick up electromagnetic noise from other circuit components and the surrounding environment. (This is actually how a guitar pickup works. The magnet in the pickup sets up a field that is interfered with by the vibration of the guitar's strings. The pickup coil senses this interference and converts it into a signal. And as any guitar player who has played a guitar with non-humbucking pickups will tell you, the pickup coil also senses any other interference in the room and converts that into a signal too.) This is why you don't find many inductors in synths or other audio equipment.

Inductors, Electromagnets, and Applications

One other thing that an inductor does is create a magnetic field. This field is inside the coil and extends from one ends of the coil to the other, and slightly outside at each end. If you put an iron bar inside the coil, then when current is flowing, the bar becomes a magnet. This is precisely what an electromagnet is. If you mount the bar so it can slide in and out of the coil, then when current is flowing the magnetic field will pull the bar into the coil. If you then connect a spring to pull it back when the coil is not energized, you have a solenoid. If you connect a switch to the piece of iron, you have a relay. Relays are useful for allowing high voltage circuits to switch low-voltages ones on and off, or to allow DC circuits to switch AC circuits, or vice versa.

Transformers

If you run AC through the coil, you will obviously create an alternating magnetic field. One thing that an alternating magnetic field can do is induce a current into another coil that happens to be wound around the same core. This is precisely what a transformer is. A transformer is a power-converting device.

Recall that power, measured in watts, is calculated as:
watts = EI
where E is the voltage and I is the current. Now, in the transformer world, they don't use the term watts; they call them "volt-amps", or VA, instead. There's a reason for this that I won't get into; if you've ever heard the term "power factor", it has to do with that. The two coils of a transformer maintain a constant VA; VA in equals VA out. However, the voltage is not constant; it is determined by the ratio of the number of turns in the coils. If the primary coil (the one the power is applied to) has 100 turns, and the secondary coil (the one the current is being induced in) has 50 turns, the ratio is 2:1, and the voltage across the secondary coil will be half that applied to the primary coil. Since the VA is constant, that means the secondary coil will supply twice the current applied to the primary coil. That's how the power supply in a synth steps down the high mains voltage to the low voltages used by the synth circuitry. It's also how the output transformer in a tube amplifier converts the high-voltage signal from the output tube into the lower-voltage, higher-current signal needed to drive the loudspeaker. (And it should be noted that the loudspeaker itself contains an inductor, which creates the magnetic field that moves the speaker cone.)

Specifying Inductors and Transformers

The basic unit of inductance is the henry (no kidding), abbreviated H. As it turns out, one H is a larger amount of inductance than what is generally needed for the purposes for which inductors are used in electronics, so most inductors you will see in electronics parts catalogs will be specified in millihenries, or mH. Inductors will also be rated according to their maximum current capacity.

Transformers are rated in terms of the volt-amp (VA) capacity, and the turns ratio. There is usually also a maximum current rating (which is a function of how the transformer is constructed) and a maximum operating temperature. The turns ratio tells you what output voltage you can achieve for a given input voltage, and from that you can figure the maximum output current achievable, and compare to the transformer's maximum current rating. Transformers often have a multi-tapped coil on one or both sides; some of the taps allow some of the turns on that coil to be bypassed, which effectively changes the transformer's turns ratio. This is common in transformers intended to be used in power supplies; there will usually be taps on the primary side to accommodate both U.S. 120V mains and European 240V mains, and there may be a third one for Japanese 100V mains. If the device containing the power supply is taken to a different part of the world, it can be adapted to a new mains voltage by moving the power input lead to a different tap, or perhaps through a switch arrangement which accomplishes the same thing. Some transformers also have multiple taps on the secondary side, that allows the transformer to supply two or more secondary voltages in one unit. Remember that transformer depend on an alternating magnetic field being set up by the primary coil, and so they only work with AC voltages.

Summary

That's as far as I'm going to into this topic. There's a lot about inductors that I've ony hinted on, because the topics are more relevant to power engineering than they are to electronics. But if you are interested, do some Internet searches on the terms "reactance" and "power factor". As it turns out, when you get into these topics, you will discover that capacitance and inductance are two sides of the same coin, and there is some hairy but interesting math that arises.

Saturday, May 9, 2009

Electricity for Synth-DIYers: Capacitors

The next electrical component we're going to talk about is the capacitor. A capacitor is basically a storage device for electric charge. It's somewhat similar to a battery, although the analogy only goes so far: a battery stores electrical energy by converting it to and from chemical energy. A capacitor does not do that; it simply collects and stores charge.

A capacitor consists of two metal plates, each attached to a conductor, and separated by some type of insulator which is referred to as the dielectric. When the two plates of a capacitor are connected to the two poles of a battery or some other source of DC current, current flows in. At this point we have to talk about electrons, since they are the charge-carrying particles at the atomic level. Recall that the charge of the electron is negative, and that the flow of electrons in a circuit is in the opposite direction of "conventional current" (that is, conventional current flows from positive to negative, but electrons actually flow from negative to positive).



So electrons flow from the negative pole of the battery into one plate of the capacitor. They can't flow over to the other side of the capacitor because of the insulating dielectric. The dielectric won't permit a flow of current through it, but it will allow electrons to collect on its surface. The electrons on the negative side of the capacitor develop an electric field, which repels like charges in the same way that a magnet pole repels the like pole of another magnet. So what happens is that as electrons build up on one side of the dielectric, the electric field shoves electrons off the opposite side to the other plate and then out of the capacitor. That side of the capacitor then develops a positive electric field (absence of electrons). This process causes a voltage to develop between the two sides of the capacitor. This voltage opposes the voltage of the battery, which causes the flow of current into the capacitor to slow down. Eventually the voltage across the capacitor equals the battery voltage, at which point the flow of current into the capacitor stops. The system is now in a stasis condition. No matter how much longer you let the circuit sit there, nothing else is going to happen

Now, remove the battery from the circuit. What we have left is a charged capacitor -- essentially, another battery (although it holds a lot less energy, unless it's a really huge capacitor). If you then have a switch that you can use to collect the two sides of the capacitor together, the electrons will flow back out of the negative (excess electrons) side, through the circuit, and back around to the positive (deficient in electrons) side. As this occurs, the voltage across the capacitor drops. Eventually, the number of electrons on each side equals out; at this point the voltage across the capacitor is zero, and the current stops.

Controlling the Charge and Discharge Time

With a typical capacitor, if there is nothing external to restrict the current flow, the charging and discharging processes will both happen extremely fast. Putting a resistor in series with the cap slows down the charge and discharge rate, which leads to one of the main uses for capacitors in DC circuits: timing. This is commonly referred to as an RC circuit. Here is an RC circuit used to implement a crude form of AR envelope generator:


When the pushbutton switch (the symbol to the right of the battery) is pressed, the top half closes and the bottom half opens.  The battery is connected to the capacitor through the resistor, and the battery charges the capacitor.  As it does so, the voltage at the output goes up gradually.  Releasing the button opens the top half and closes the bottom half.  This disconnects the battery, and it completes a circuit from one side of the capacitor to the other, through the resistor.  The capacitor discharges through the resistor, and the voltage at the output gradually goes to zero.  A variable resistor or potentiometer could be used to vary the charge and discharge rate.  

The amount of time it takes for the capacitor to reach a given level of charge, at a given supply voltage, is determined by the capacitance of the capacitor and the resistance of the resistor; this is called the time constant. For a given resistance, the charge/discharge time is very repeatable, and the voltage to which the capacitor is charged will also be very repeatable provided that the supply voltage is stable. By convention, the time constant is given as the amount of time it takes to charge the capacitor to about 63% of its full capacity, which also means that the voltage across it will be 63% of the supply voltage. The calculation is simple:

time = RC

where R is the resistance in ohms, and C is the capacitance in farads (which we'll discuss further down).  It should be noted that the charge rate is not linear; as the capacitor charges, the opposing voltage begins to push back against the inflow of current, and the charging rate slows down.  As a rule of thumb, it takes 5x the time constant for the capacitor to reach full charge.

Capacitors and Alternating Currents

So far, we've talked about capacitors and direct currents. How does a capacitor behave with an alternating current? Well, let's think about it, based on what we've discussed so far. The distinguising characteristic of an alternating current is that it switches back and forth from current flow in one direction to current flow in the other, and hence the voltage switches between positive and negative. If we place a capacitor between the two poles of an AC source, and assume that we start with the positive-going half, then the capacitor behaves as described previously: it charges until its voltage equals the source voltage, and then current stops. However, when the AC switches direction, it is no longer opposing the capacitor voltage; rather, it is reinforcing it. So the capacitor first discharges, and then charges in the opposite direction. Again, its voltage eventually equals the source voltage, at which point the current stops until the AC changes direction again.

But what if we use a high enough AC frequency that the cap doesn't have time to fully charge before the direction reverses? We find that the AC current never fully stops, except for the actual moments when the AC waveform itself is crossing through zero volts, on the way to the other side. In fact, if the AC frequency is high enough, we find that the current flows in and out of the cap the same as it would if that part of the circuit were bypassed with a wire. It looks like the AC current is going through the capacitor! We know it actually isn't; the electrons can't pass through the dielectric. But the alternating flows in and out behave exactly the same as if they did.

And the higher the frequency of the AC current, the less impedence the capacitor poses to it. Impedence is just a fancy word for resistance in the AC context. The capacitor is behaving like a frequency-dependent resistor -- which is exactly what a filter is. The cap is a simple high-pass filter; it blocks low frequencies (and DC, which has a frequency of zero), and lets high freqencies pass. Nearly all filters used in synthesizers are based on the frequency-dependent behavior of the capacitor. Note that a simple capacitor is a long way from a practical VCF, but it's still the basis of one.

If the capacitor is placed in series with the circuit, it acts as a high-pass filter:


If the capacitor is connected between the circuit and ground (e.g., the negative side of the battery), then it "shorts out" the high frequencies. The low frequencies that can't pass through the capacitor go past it as if the capacitor wasn't there. So, in this configuration, the capacitor acts as a low-pass filter.

When using a capacitor as a filter, it would be nice to know what the cutoff frequency is. The problem with the circuits as shown above is that the exact cutoff frequency is highly sensitive to the small resistances in the wiring of the circuit, the internal resistance of the capacitor (no capacitor has absolutely zero internal resistance), and so forth. We solve the problem by putting a resistor into the circuit. Even a relatively low-value resistor of, say, 500 ohms, will probably be much greater than the parasitic resistances in the circuit, and it will overwhelm their effects. By doing this, we can now use the time constant that we discussed above to calculate the cutoff frequency. Remembering that the time constant is equal to R * C, we have:

Fc = 1 / (2 * pi * R * C)

where R is the resistance in ohms, C is the capacitance in farads, Fc is the cutoff frequency in Hertz (cycles per second), and pi is the familar circle ratio constant, roughly equal to 3.1416. (If you spend time looking at filter formulas and calculations, you will see the constant pi pop up frequently. There are mathematical reasons for this that are too complex to go into here.) Note that RC filters are single-pole filters, with a cutoff slope of 6 dB/octave. Most filters used in synth circuits are either two-pole or four-pole types.

However, there are two important applications for capacitors where we often don't care exactly where the cutoff frequency is: DC blocking and power supply bypassing. All capacitors have the property that, if you have a mixed signal with both DC and AC components, the capacitor can separate the DC from the AC. One place where we often want to do this is in the inputs and outputs of various audio circuits. For example, at the input of an audio amplifer, we would like to be able to remove any DC present in the signal. Amplifying the DC serves no purpose; you can't hear it, and large DC offsets in the output can damage the amp or the speakers. Running the input signal through a suitably large-value (a few millifarads) capacitor will block the DC while allowing all of the AC components in the audio frequency range to pass through. On the other hand, in almost any electronic device there are certain circuit components, such as certain ICs, which are connected to the power supply and vary hugely from moment to moment in how much current they draw from the supply. When they do that, they introduce noise into the power supply. This noise can be picked up by other circuit components, and can introduce noise or extraneous signals into the circuit's output, or even cause the circuit to malfunction. Bypass capacitors are frequently placed on a circuit board to take care of this problem. A capacitor, connected between the power supply and the ground (and usually placed near the power pin of the noise-creating IC) will shunt the noise components to ground and get them out of the DC supply.


Capacitors in Series and Parallel

If you remember the discussion of resistors in series and in parallel from that post, you might recall that when two resistors are in series, their values simply add; when resistors are in parallel, they follow the "reciprocal sums" rule. Interestingly, capacitors behave in exactly the opposite way; caps in parallel add, while caps in series follow the reciprocal-sums rule. So if we have three caps C1, C2, and C3:

In parallel: C total = C1 + C2 + C3

In series: C total = 1 / (1/C1 + 1/C2 + 1/C3)

Types of Capacitors

Capacitors may use different types of contstruction and different dielectric materials, which effects the secondary characteristics of the capacitor, such as working voltage and the physical size of the capacitor.  Often the choice of dielectric is a tradeoff between those two factors.  for example, a capacitor that uses air as a dielectric can tolerate high voltages, but a large-value air cap will be physically huge.  A "better" dielectric can accommodate a higher charge density and make a smaller cap, but these dielectrics often cannot tolerate high working voltages.  The types you are most likely to see in electronics are:

  • Ceramic. These use a disc of ceramic as the dielectric. They are fairly stable, tolerate physical abuse, can take high voltages, and are inexpensive. You will see a lot of these used as bypass caps. Main disadvantage: because the dielectric constant of the ceramic isn't very large, they can't be made in high capacitance values; they'd be too large.

A batch of ceramic capacitors, of various values.

  • Metal-film: polypropylene, polystryene, polycarbonate. These are made of a sandwich of the dielectric material, which is a plastic film, with the plates consisting of either thin foil layers or a metal layer vapor-deposited on the dielectric. The whole thing is wound up in a roll, like paper towels, which makes for large-value capacitors that are very small. Polystyrene types are the most temperature-stable, but they don't take high voltages and are hard to find for some reason nowdays. Use these for applications where the exact capacitance value is critical, such as timing and VCO circuits. Polycarbonate is supposed to be second-best in stability, and it takes higher voltages.

A metal-film "box" capacitor, installed in an MOTM module.

  • Aluminum electrolytic. These offer high capacitance value in a given space. They use a paste or gel electrolyte that "forms" the dielectric when a voltage is applied to the capacitor. Most types are polar; they can only take charge in one direction. They appear mostly in power supplies, and in places in circuits where a very high capacitance value is needed and the exact value isn't critical. They lose capacitance value over time, declining to as little as 10% of the original value after 5-10 years. The electrolyte can overheat and leak, or burst the case, if the capacitor is used in the design improperly or if a circuit malfunction apples current to it outside of its design specs, or if the ambient temperature gets too hot. There are "bipolar" types which appear mostly in amplifier circuits as DC-blocking capacitors, and in loudspeaker crossover circuits.


Electrolytic capacitors. The gray ones are polarized; note the back stripe and the shorter leads which indicate the negative terminal. The black one is bipolar.




A large electrolytic that was used as a filter in an amplifier power supply. The gray stripe, just visible at the right, indicates the negative terminal.  Also note that the cap is marked with its maximum working temperature; these types are often used in applications where they get hot.
  • Tantalum. These offer the absolute highest capacitance value in a given space. They have tighter tolerances than the aluminum electrolytic types, and are less sensitive to environmental conditions. They cannot take high voltages, but the main reason they aren't used much in synth DIY is that they are polar, more expensive than electrolytics, and they have a rather distressing tendency to explode if a reverse voltage is accidentally applied.

  • Paper and mica. These aren't used much any more, but you will run across them in antique electronics. The paper types use an oil-soaked paper as the dielectric. They weren't very good. The mica types (mica is a mineral, a sort of natural glass) were very good, but ceramic types have similar specs these days, and mica is expensive. Few paper caps are in production any more; some mica types still are, but there is no compelling reason to use them in synth circuits.

Units of Measurement

The cpaacitance of capacitors is rated in farads, abbreviated F. As it turns out, because of the way the unit is defined, one farad is a huge amount of capacitance. Unless you work in power distribution, you're unlikely to ever come across a capacitor that large. Capacitors used in electronics are usually rated in microfarads (1/1,000,000 of a farad, abbreviated uF), nanofarads (abbreviated nF, 1000 nF = 1 uF), or even picofarads (abbreviated pF, often pronounced "puff", 1000 pF = 1 nF). North American usage tends to avoid nanofarads; caps in that range are usually expressed as a fraction of a microfarad or as thousands of picofarads. Europeans are more sensible and simply use nanofarads when called for. In most synth circuits, you will see caps ranging rrom a few pF up to about 100 uF. Power supplies will use larger ones for filtering, up into the tens of thousands of uF. Note: many mathematical formulas involving capacitors, including the ones in this post, require the capacitance to be stated in farads, not any of the smaller units. It can all be hard to keep track of.

How Capacitors are Specified

The capacitance value is specified in some sub-unit of farads, as described above.  Unfortunately, unlike the case for resistors, there is no really standard way of marking values on capacitors.  Some caps do use a RETMA-like color coding, but most are marked in text.  One system often used on smaller-value (and physically smaller) caps is a three-digit code, where the first two digits are the first two digits of the value in picofarads, and the last digit is a number of zeros to add to the first two digits.  So, for example, a cap marked "102" would be 1000 pF, or 1 nF.  Electrolytics, particularly larger ones, are usually marked with the actual value.  

There is far more variation in capacitor tolerance values then for resistors.  Most ceramic and film types are sold at 10% tolerance; 1% or better are available but are expensive.  Tolerance is often not marked; you have to look at the packaging to know.  Most electrolytics have terrible tolerance specs; +100%, -50% is not uncommon.  (Also keep in mind that electrolytics usually lose value as they age.  These are good reasons to use some other type in applications where the exact value is important.)

Secondary characteristics that are important in capacitors include whether or not the capacitor is polarized, the working peak voltage, the temperature coefficient (how the capacitance varies with temperature), the tolerance, and the equivalent series resistance or ESR. As we have discussed, most electrolytic and tantalum types are polarized; they can be charged in only one direction, and will be damaged if voltage is applied in the opposite direction (dramatically, in the case of tantalums).  The negative lead is usually indicated by a stripe on the body of the cap, or the lead being shorter, or both.

Working voltage is a function of the dielectric and the capacitor's construction. Some types of dielectric have better ability to withstand high voltage than others do. If an excessive voltage is applied to the capacitor, the dielectric breaks down, and then the capacitor shorts out or does something worse, such as burst or catch fire. When considering voltage ratings, you need to consider the peak voltage that the capacitor will be exposed to, and then allow some margin. Rule of thumb is to specify the cap for at least double the expected peak operating voltage. This is frequently fudged down to 50% or less when specifying large electrolytics, due to physical size and cost.

Most types of capacitors vary with temperature. For electrolytics in particular, this can be considerable, to the extent that manufacturers don't always publish data on it. For other types, there are usually several types or grades of variation with temperature. The Electronics Industries Association has a complicated system for designating these. Just know that if you are buying ceramic caps for an application that requires the least available variation with temperature, look for a type designated "NPO or C0G".

Equivalent series resistance, or ESR, can be caused by both resistance and inductance within the capacitor. ESR becomes a factor in circuits where the cap is expected to handle either large currents or high frequencies (1 MHz or above). In synths, you will usually not run into these situations except when dealing with power supplies. In a power-supply filtering application, it pays to get low-ESR types, since these will not get as hot and therefore will last longer. If you are working with digital circuits having high-frequency clock signals, say for a CPU, you may have to think about capacitor inductance, which causes higher ESR at high frequencies. The easiest way to avoid this problem is to stick to ceramic types whenever possible in high-frequency circuits; ceramics nearly always have very low inductance. (In power-supply filtering and decoupling applications, it is often recommended to use two caps in parallel: a film or electrolytic type to handle the higher currents and lower frequencies, and a ceramic to bypass the high frequencies.)  ESR may vary by frequency, and electrolytics often have high ESR at higher frequencies.  For that reason, it is not uncommon to find, in bypass applications, an electrolytic and a ceramic in parallel.  The electrolytic bypasses the lower frequencies, and the ceramic handles the higher frequencies where the electrolytic's ESR is too high.

Summary

Capacitors are fundamental to today's electronics.  It is important to understand them, since they in effect open the door to AC circuits and signal processing the treats different frequencies differently.