Saturday, March 12, 2011

Electricity for Synth-DIY'ers: Operational Amplifiers

Now that we've covered the basic semiconductors and passive components, let's begin covering what happens when you put a bunch of them together on a slab of silicon -- the integrated circuit. One of the most basic integrated circuits, used in both analog and digital systems, is the operational amplifier, or op amp for short. Op amps are one of the most useful ICs; they can be used to amplify or attenuate a signal to any extent desired, invert a signal, and solve signal buffering and impedence-matching problems. Further, they can be used to conveniently implement active filters in the audio range, do voltage level comparisons, and a host of other analog signal processing functions.

The development of the operational amplifier actually precedes the advent of the integrated circuit. Op amps were first devised in the 1930s as a means of solving various amplification and impedence-matching problems in long line telephone circuits. At the time, they were obviously constructed using tubes since the transistor had not yet been invented; as the circuits were mass produced, they started being packaged into forms that allowed them to be treated as a single component -- some tube types were packaged such that the entire circuit could be plugged into a socket as if it were a single tube.



Philbrick Labs
K2-W tube-based operational amplifier. Photo from Wikipedia Commons.

Much research in the pre-IC days went into miniaturizing these circuits, and making them work at lower voltages. A few op amps intended for high-end audio applications are still made as "bricks" implemented with discrete transistors, but nearly all other types are made as ICs these days. (An aside: One engineer who played a significant role in the development of the early solid-state op amps was a certain young Alan R. Pearlman, who would later play a much larger role in the development of the music synthesizer.)

The first monolithic IC op amps were developed by Fairchild in the early 1960s. They introduced the first one, the µA702, in 1963; it had some unfortunate characteristics and was not a success. However, in 1965 they followed this up with the µA709, which fixed the 702's problems and went on to see widespread use; it remained in production into the 1980s. Then things picked up; National Semiconductor challenged Fairchild by introducing its LM101/201/301 series in 1967. (The series of numbers represented different ambient operating temperature ranges, with the 3xx being the commercial series and the 1xx being mil-spec; this pattern continues today for most ICs designed by National.) Fairchild said "oh, yeah?" and the next year they introduced what would become the canonical op amp for decades: the µA741. The 741 was the first internally-compensated op amp (we'll get to compensation later). Variants of the 741 are still in production today.

If you are interested in reading a very good and detailed story of the development of the op amp, see this paper published by Analog Devices.

Opamp Basics

A basic opamp has two inputs and one output. The two inputs are known as the inverting and non-inverting inputs; as one might guess, the output will be inversely proportional to the signal at the inverting input, and directly proportional to the signal at the non-inverting input. That's a bit of an over-simplification, though; it often leads beginners to believe that what the opamp does is amplify the difference between the two inputs. There's more to how an opamp works than that, though.

Here, in three short rules, is what an opamp does (or tries to do):
  1. The opamp wants the voltage at its two inputs to be equal.
  2. It assumes that a feedback path exists between the output and the inverting input.
  3. It uses this assumption to vary the output to try to make the two inputs equal.
If no feedback path exists, the opamp will drive its output to its minimum or maximum voltage, which depends on the power supply voltages and the opamp's circuit design. (Some opamps will go "to the rails" and some will stop a volt or two short.) Thus, most useful opamp circuits include a negative feedback path. Another way of putting this is that without any feedback, the opamp has extremely high gain -- almost any non-zero inputs drive it to clipping, in one direction or the other. (The theoretical ideal opamp has infinite open-loop gain. Real opamps of course cannot go to infinity, but most types have open-loop gain factors within the audio range in the tens of thousands.) The feedback path is what controls this gain. From there, it follows that how much feedback is supplied can control the opamp to provide more or less gain, and this is exactly the case.

Symbology

We'll introduce the symbology at this point. The symbol for a basic opamp is:


The two pins show on the left are the two inputs: inverting (indicated by '-') and non-inverting (indicated by '+'). The pin on the right is the output. The power and ground pins are frequently not show, but when they are, they are show sticking out of the top and bottom; any other special-purpose inputs that the op amp has will also be shown at the top or bottom. In isolation, illustrators will usually draw the opamp symbol with the non-inverting input above the inverting input. However, in a schematic, the reverse is often true; conventionally the feedback path is drawn above the opamp symbol, and since it connects to the inverting input, to reduce the number of crossing paths the inverting input frequently gets placed on top. Some schematics will use the '+' symbol to indicate the non-inverting input and the '-' symbol to indicate the inverting. But others will use the pin numbers of the specific IC, in which case you need to know what kind of opamp it is and have access to the pinout. In this article, we will keep the non-inverting input on top throughout, to reduce confusion.

The Basic Amplifier Circuits

There are two basic configurations of amplifier circuits using an opamp, the inverting configuration and the non-inverting configuration. The inverting configuration has the effect of the output being the inverse of the input; with the non-inverting configuration, the output is identical to the input except for gain. Although the inverting configuration is used more, the non-inverting configuration is easier to understand and it does have its uses, so we'll introduce it first. It looks like this:


Note the resistor connected between the output and the inverting input. This is the feedback path. Thinking back to the three rules, picture what happens when a positive voltage comes to the opamp from the external circuitry. It raises the voltage at the non-inverting input. The opamp then wants the inverting input to rise to the same voltage as the non-inverting input. In order to accomplish this, it raises the voltage level at the output.

That voltage goes over to the inverting input, where some of it is bled off to ground by the other resistor. The two resistors form a voltage divider, so the voltage at the inverting input will be some fraction of the voltage at the output. Therefore, the output voltage will have to go up higher than the voltage present at the non-inverting input before the voltages at the two inputs become equal. For instance, if the two resistors have the same value, then they form a divide-by-2 divider, and the output will have to rise to twice the voltage that is present at the non-inverting input before the circuit settles.

All of this happens very fast. The speed at which the opamp is capable of responding to its input determines its maximum response frequency, or bandwidth. Nearly every opamp on the market today has a bandwidth that extends well beyond the audio range, so in an audio application, you will rarely have to worry about it; you can assume that everything happens instantaneously. (If you get into radio, or high-speed data circuits, that assumption is no longer valid.)

The ratio of the two resistors determines the gain of this circuit. The ratio in the middle of a two-resistor voltage divider is the total resistance divided by the resistance of the "bottom" resistor; in this case R2. So the gain of the non-inverting amplifier configuration is (R1+R2)/R2, or (R1/R2)+1. In the simplest case, where R1 is replaced by a straight wire (i.e., zero resistance) and R2 is omitted (infinite resistance), the result is a unity-gain amplifier; the output will be identical to the input. What good is a unity-gain amplifier? Well, one use is for re-driving signals that can't take being loaded down, such as signals from guitar pickups. Many opamps have extremely high input impedance, and a unity gain buffer is perfect for taking signals from high-impedance sources and repeating them with lower output impedance. Note one implication of the gain formula: in the non-inverting configuration, you can't achieve a gain of less than 1.

(By the way, in practical circuits, it's not a good idea to totally omit R2. Opamps often "bleed" a very small amount of current internally back into their inputs. If this bleed current doesn't have a path to ground, it can cause the opamp to go open loop and drive the output to the rail. If the need is for a unity-gain circuit, a 1M resistor can usually be used for R2 without any practical effect on the gain ratio, and it will allow the leakage currents to bleed off.)

The inverting amplifier configuration looks like this:


How does this one work? Per the three rules, when a positive voltage comes from the external circuit, it applies a positive voltage to the inverting input. Because it is the inverting input, the opamp will respond by pushing the output negative, in an attempt to counterbalance the positive voltage and bring it back to the voltage level of the non-inverting input, which is at 0V since it's grounded. The voltage level that the output has to go to in order to accomplish this depends on the ratio of the two resistors. Since the resistors directly determine the proportion of the input signal and the feedback that get combined at the inverting input, the gain equation for the inverting configuration is simply R1/R2. Unlike the non-inverting configuration, the inverting configuration can achieve a gain of less than 1; as you can see from the formula, as R2 gets large, the gain goes towards zero. Thus the inverting configuration can be both an amplifier and an attenuator.

So when do you choose one configuration over the other? Well, for one thing, the inverting configuration obviously inverts the signal, which is useful in its own right sometimes. More importantly, though, is that you will see below that most of the more sophisticated op amp circuits require an inverting configuration -- they don't work the other way. So why not just use the inverting configuration for everything? Well, for one thing, this may result in unintended inversion of the input, which will make you have to add an extra inverting stage to get the signal right side up.

However, a more important reason is in the fact that, in the inverting configuration, the two gain-setting resistors provide a "sneak path" around the op amp between the input and the output. This can cause a problem regarding the input impedance of the circuit. The op amp itself has incredibly high input impedance, which can be a very useful property (in, e.g., a preamp for a mic or guitar). However, if the op amp is driving something else with low input impedance, the path through the resistors will lower the effective input impedance. You could fix that by using high values for both resistors, since the ratio of the resistors and not the values per se is what determines the gain. However, past a certain point (when one of the resistors gets up past about 100K), you will start to have noise and voltage offset problems.

The non-inverting configuration does not have this problem because there is no connection between the input and the feedback path. So what you often see is that, for a given device, non-inverting circuits are often used for the external inputs and outputs, and most everything in between uses inverting circuits.

Stuff You Need to Know at This Point

Now that you understand the basic principles behind the opamp, before we proceed let's go over some of the requirements and practical limits of real opamps. Most opamps require both a positive and a negative power supply, depending on the type, and these must usually be of the same magnitude in order for the opamp to work properly. In other words, if the negative supply is -15V, a positive supply of +5V won't do; you need +15V. The power supply voltages limit how far the output can swing in either direction. They also limit what input voltages are permitted; with most opamp types, the inputs must be kept at least 1-2V away from the supply voltages. If the input limits are exceeded, the opamp may go into a condition called "latchup" where it no longer responds to its inputs. Latchup generally requires that the power be removed to reset the circuit, and it may harm the IC. If there is a possibility of the inputs exceeding the opamp's specified voltage, such as an opamp connected to an external input jack, it is a good idea to protect the inputs. Usually this is done with zener diodes. There are opamps which can accept input voltages all the way to the supply voltages; check the vendor catalogs if you need one of these.

There are some opamps made to work with single supply voltages. These are sometimes useful particularly in battery-powered applications. With these, the input voltages must be kept between the power supply voltage and ground, so if you want to feed in an AC signal, you will need to add DC offset to the input and then remove it from the output.

Most modern opamps are protected against having their outputs short-circuited; if you short the output to ground, nothing bad will happen. However, there is a limit to how much current the output can supply, so if you short it to ground, the output will go to zero and stay there until you remove the short. The output current limits are printed in the specifications. If you are building a circuit to drive a very long cable -- say, an output module for a modular that needs to drive to the house mixer 75 feet away -- an opamp will a high-current output capability will be useful.

One other thing to be aware of: All op amps "leak" very small amount bias currents that occur internally on the inputs. These small currents have to have a path out via the input pins. Here's something to watch out for:


Note the capacitor on the non-inverting input; this would be typical if it was desired to block DC voltages from reaching the input. The problem is: those micro-leakages at the input are "trapped" by the capacitor; they don't have a path out of the circuit! The result is that the circuit will never reach equilibrium and the output will probably go to the minimum or maximum voltage and stay there. Here's how you fix that:


The extra resistor allows the leakage currents to bleed to ground. A 1M resistor will usually be large enough to not have any effect on the input signal.

Analog Arithmetic with Opamps

A frequent problem in synth circuits is the need to add or subtract control voltages. For instance, the control voltage fed to a VCO might need to be the sum of control voltages from the keyboard, the pitch wheel, and an LFO. Here is a circuit that will sum up any number of control voltages:



You can add any number of inputs to the input ladder at the left. To keep things simple, all of the Rx resistors should be of the same value; if you do so, the gain is Ry/Rx. Use Rx values of at least 1K to prevent the input signals from trying to back-drive each other. Note that, because this is based on the inverting-amplifier configuration, the output will be the negative of the sum of the inputs. That's easy to fix; just run it through a second inverting amplifier, with the gain configured as needed. Note that this circuit can also be used as an audio mixer; after all, a mixer is really just an adder. The one thing you might want to do if it is being used for audio mixing is add a DC-blocking capacitor (10 uF or so, non-polarized electrolytic) in series with each input.

You can subtract signals using the configuration above, preceded by an inverting amp that inverts the signal to be subtracted. However, here's a one-op-amp solution for computing the difference of two signals:



Note that this circuit is identical to what is commonly called a "difference amplifier" or "differential amplifier" (the latter is not-so-good terminology, but lots of people use it). The "balanced line" signal connection often used in recording studios consists of two signals, one of which is the negative of the other. You see this commonly in equipment such as microphones which use the 3-pin "Cannon" plugs and jacks; two of the pins carry the signals and the third is connected to the cable shield. You can use the difference amplifier circuit to convert this to a single-wire signal that you can process inside a piece of equipment. The difference amplifier produces an output which is proportional to the difference between its inputs. An interesting implication of this is that if both signals change by the same amount, the output does not change at all, because the difference between the signals didn't change. In the studio environment, this is called "common mode rejection" and is a big help in reducing noise pickup. The basic circuit should have R1 = R3 and R2 = R4; assuming so, then the gain is equal to R1/R2.

(Note that this is not the optimum version of this circuit; the main problem is that it's difficult to make the impedances of the two sides match exactly, which limits the circuit's accuracy. Here is an improved version, if you have a need for it.)

Differentiators and Integrators

Here's a pair of circuits that can be very useful particularly in a modular synth. The first is called a differentiator (not to be confused with a difference amplifier). What it does is produce an output which is proportional to the rate at which the input is changing; you can think of it as sort of a speedometer for the input signal. If the input is increasing, the output will be a positive voltage; if the input is decreasing, the output is negative, and if the input is not changing, the output is zero.



The gain of this circuit is proportional to the frequency of the signal fed into it, but is influenced by the values of R and C. The output voltage Vo = -RC(dV/dt), where R is the resistor value in ohms, C is the capacitor value in farads (not microfarads or nanofarads, but whole farads), and dV/dt is the rate at which the input voltage is rising or falling, in volts per second. (Don't worry about what the individual parts of the dV/dt stand for; just accept that it stands for "change in voltage with respect to time".) Note the minus sign, which is a result of this being an inverting-amp configuration. An easy way to think about this circuit is to assume an R of 1M and a C of 1 uF; this way the product of RC is 1, and then if the input is rising at 1V per second, the output is -1V as long as the input keeps changing.

The integrator is, mathematically, the opposite of the differentiator. To continue with the car analogy, you can think of the input as an accelerator for the output. When the input is positive, the output rises; its rate of rise is determined by the magnitude of the input. Same goes for a negative input; the output goes lower in proportion to the input. When the input is zero, the output remains where it was. Given that an input that remains positive or negative for any length of time will push the output to its power-supply-determined limit, it's useful to have a reset capability. This is shown in the schematic as a switch, but it would be a simple matter to substitute an NPN transistor or a mini relay so it could take a reset trigger signal.



Basic Active Filter Circuits

Consider the following circuit:



Note the capacitor in the feedback path. What is this capacitor doing to the feedback? Well, start by considering a very low frequency: At a low enough frequency, the capacitor is essentially an open circuit, so only the R1 resistor in parallel with it has any effect. This reduces to your basic inverting amplifier with gain determined by the formula for an inverting amplifier: R1/R2. But what happens as the frequency goes up: The capacitor starts to let some current through, in addition to what goes through R1. In effect, the capacitor is reducing the value of R1 by allowing some current to bypass it. This gets more pronounced as the frequency goes up, until the frequency is reached where the capacitor has effectively shorted out R1. At this point, R1's effective resistance is zero, and the full amount of feedback is being applied to the inverting input, which cancels out the input signal at that frequency and reduces the op amp's gain at that frequency.

This circuit is a low-pass filter. It has a certain gain at low frequencies and less gain as the frequency goes up; at a sufficiently high frequency, its gain is zero. Doing the math, we find that, just like any filter, there is a cutoff frequency determined by the capacitor's value and above that value the gain rolls off at 6 dB/octave, making it a single-pole filter. The cutoff frequency is: 1/(6.2832R1C) where R1 is in ohms and C is in whole farads.




This circuit is a high pass filter. From the above discussion, you can probably already guess how it works. At low frequencies, the capacitor is essentially open, so full feedback is applied to the inverting input, and the op amp's gain is zero. As the frequency increases, C starts to conduct and at a high enough frequency it essentially becomes a straight wire. At that frequency, the circuit's gain then is determined by R1/R2. The formula for cutoff frequency is the same as for the low pass filter. Note that this circuit, unlike the low pass filter circuit, is non-inverting with respect to the input. Inverting and non-inverting configurations exist for both low pass and high pass filters.

What if you want more than a one-pole response? Well, an obvious answer is to put several of the above circuits in series. For instance, if you use two, you get a two-pole filter with a 12 dB/octave rolloff. However, using this method for multi-pole filters means using an op amp for each stage, which can make for an expensive circuit. So, electrical engineers have devised all kinds of devious circuits for implementing multi-pole filters that do not need an op amp for each pole. For instance, the Sallen-Key circuit often used in synth filters implements a two-pole low pass or high pass filter with only one op amp.

Sallen-Key filter, from Wikipedia Commons

Op Amp Filter Topologies and Response Types

Here is something that people often get confused about when they read about op amp-based filter circuits. The topology is the logical arrangement of the components in the circuit. There are a bunch of ways of designing filter circuits, particularly multi-pole filter circuits. The Sallen-Key is one such topology; others often found in synths are the biquad and the multiple feedback. The response class refers to the general shape of the response curve. The three types you will hear most often in audio systems are Butterworth, Chebyshev, and Bessel; most synth filters belong to the Butterworth class. The differences between them are in exactly what the frequency response curve looks like; for instance, the Butterworth type is very flat in the passband, while the Chebyshev has some variations ("ripple"). All three of these filter types can be implemented in various topologies, and usually the difference is in the ratios between certain components. There is some pretty complicated math behind these, but you don't have to do the math; there are all kinds of design tools that allow you to plug in the desired characteristics and it will calculate the component values for you. Here is a simple one which will calculate a Sallen-Key (12 dB/octave) low-pass filter of the Butterworth class; all you have to put in is the desired cutoff frequency and one capacitor value. I'll do a future post which explains some of these active-filter types in more detail.

Compensation and Offset Nulling

All op amps require what is called compensation, in order to keep the op amp from going into self-oscillation under certain circuit conditions. The compensation consists of one or more capacitors that are placed into the op amp's internal circuitry. The first op amps were externally compensated -- they required the designer to add capacitors to compensation terminals on the device. However, most op amps today are internally compensated; the compensating capacitors are built into the op amp itself. In terms of ultimate performance, internally compensated op amps are a compromise; using external compensation allows the designer to extend the op amp's bandwidth and/or reduce its power draw, depending on the need. However, in designing synth circuits, these are seldom important factors. Therefore, there is usually no reason not to use internally compensated op amps in synth circuits.

The ideal op amp should, if both of its inputs are grounded, drive its output to exactly 0V. Real op amps will usually have an offset ranging from microvolts to a few millivolts, depending on how the inputs are configured. This is caused by small current leakages in or out of the input pins. Some op amps have inputs to which you can connect a trimmer pot that you can adjust to null out the offset. This can be important in, for instance, a control voltage input to a VCO. If you need this, look for an op amp type that has "balance" or "offset null" inputs.

Op Amp Types and Specifications

These days, nearly all op amps are packaged in the familiar dual-in-line plastic package, in either through-hole or surface mount configuration. (A very few of the oldest types are still available in the metal can that looks like an oversize transistor with more legs.) A single part often contains more than one actual op amp; dual, triple, and quad packages are common. Single types nearly always have 8 pins while types containing more than one per package may have up to 16 pins.

Things that you (maybe) need to be concerned about when you are searching for an op amp for a synth application are:
  • Number of individual op amps in the package
  • Minimum and maximum power supply voltages
  • Input impedances
  • The gain-bandwidth product
  • Whether the op amp can run off of a single supply voltage
  • The voltage range of the output
  • Output drive capacity
We had a lot of fun back in the history writeup at the beginning of this article talking about the 741. However: Unless you are replacing a part in a vintage synth, don't even think about using one today. There are much better types available now. A popular general-purpose type is the TL08x series, originally designed by Texas Instruments but available now from multiple sources. These are available in various packaging containing 1, 2, or 4 individual op amps per unit. The inputs are JFET circuits and have very high input impedance. They can be powered at ±12V or 15V (the voltages used in modern modulars), and the permissible input voltages range to within 2V of the supply voltages. Another useful general-purpose type is the LM358, also available from multiple sources. It has most of the same virtues as the TL081 (single op amp per device); the input impedances aren't quite as high, but still adequate for most synth circuits. And they are inexpensive enough that you can buy a tube of 50 or so, to keep on hand for circuit prototyping or other off-the-cuff uses. Here is a table containing some potentially useful types that I extracted from the Mouser catalog. (The file is a .CSV file, which you can download and import into any spreadsheet application.)

Monday, January 17, 2011

More Shepherd Tones from Youtube

These are not mine... they are things I found while doing various searches for Shepherd tone examples.

First example:



I think the author is using this Reaktor ensemble, from the Native Instruments user-contributed library. It starts out using tones at octave intervals, and I think the cycling is rather obvious. It becomes more convincing when he sets it to narower intervals, starting about 0:55 in.

Second example. This one uses discrete quantized intervals rather than a continuous glissando:



As you can see, the author added a note indicating that he doesn't think it turned out very well. However, I actually find it more convincing than the first example. This is despite the fact that, according to the author, it only uses two tones at a time. I think this may have to do with the chime-like tonality of the tones used; there's a lot of upper overtones and it sounds like some of the overtones are enharmonic. The addition of the drum machine track, while not necessary for demonstrating the principle, adds a nice touch and illustrates a possible use in a musical context. Unfortunately there is nothing in the author's notes about what hardware or software he used to make this.

Third example. I was utterly floored by this one:



Now obviously there's a lot more going on here than just sweeping tones up and down. The author mentions that it uses FM; I don't know if it's using the FM to do some of the tone sweeps and spreading, or just for tonality variations. He apparently did this with a Reaktor ensemble that he built himself. Note the stereo effects. In some places the illusion is very convincing; in other places cycling is somewhat obvious. It seems to hit a place at about 5:10 where the sweep can't go any further, and then at 5:58 it starts back in the other direction. Frequency shifting? The author's notes don't say.

(After you finish listening to this one, go to the author's Youtube page and check out his favorites -- rather interesting list.)

Saturday, January 15, 2011

Shepherd tones

I took a crack at making some Shepherd tones today, for a tune I'm working on. (He's trying to do trance! Run! Hide!) Shepherd tones are a form of audio illusion; they are supposed to give the impression of a tone that rises or falls forever without ever moving out of the audio range. This is often referred to as a "barber pole" effect; Shepherd tones are one mechnism for creating it. I had hunted around for some Shepherd tone samples on the Internet, and until today I had not had much luck; in most of the examples I found, either the "cycling" was obvious (it sounded like they rose/fell to a certain point and then obviously started over), or there was no sensation of moving pitch at all. I tried copying and running the example given in the Csound manual, which employs frequency shifting, but all I got out of it was phase cancellation (sounding like pulse width modulation of a square wave).

So I decided to code up my own algorithm in Csound. I chose to build the tone out of six sine waves, at intervals of an octave. Each time rises six octaves before it is faded out. I wrote the code to gradually increase the frequency exponentially, so that it is constant-time with respect to octaves (in other words, it takes the same amount of time to go from one octave to the next at low and high frequencies). Below is my code -- first, the orchestra code:


sr = 44100
kr = 4410
ksmps = 10
nchnls = 1

1nstr 1

ifreq = 200 ; base freq * 2
idur = p3
iatk = p3 / 5
irel = p3 / 5
ireps = p4 - 1

kruntime init 0
; At the octave break point, start the next one
if kruntime < 1 kgoto keepgoing
schedwhen 1, 1, 0, idur, ireps
keepgoing:

; If repeat count has decremented to 0, do nothing
if p4 > 0 kgoto dontquit
turnoff
dontquit:

; Compute the exponentially rising frequency
; (necessary to make it linear with respect to half-steps per second)
ktime line 0, idur, idur
kruntime line 0, (idur/6), 1
kexp = ktime/(idur/6)-1
kpower = powoftwo(kexp)
kfreq = ifreq * kpower


;Envelope and Oscillator
kenv linen 1, iatk, idur, irel
aout oscil3 6000*kenv, kfreq, 1

; Output it
out aout

endin



And now the score file:


; Sine
f 1 0 16385 9 1 1 0

t 0 60

; inst start duration reps
i 1 0 30 20


Most of this is pretty straightforward to someone with just a bit of experience with Csound. The "powoftwo()" function is a bit weird since it only takes arguments in the range -5 to +5, so a bit of finagling was needed there. The tricky bit is that the score file only plays the first tone. After it has increased in frequency one octave, it uses the "schedwhen" to create a dynamic score event that starts the next tone. The line opcode and the kruntime variable do the timing for when to kick off the next tone. There is a repetition count given in the original score event that is decremented every time a new tone kicks off, and when it decrements to zero, the code quits generating new tones, which eventually brings the whole thing to an orderly end. I originally had the test of kruntime at the end of the code block, and I found that I had timing problems -- with the arguments given, the next tone kicked off a few milliseconds either early or late, depending on what value I used for the kr rate. That created noticable beating between the tones because the intervals between them weren't exact octaves. Once I moved the kruntime test to the start of the block, the timing was dead on after that.

I had Csound render this to a file, which created two minutes' worth of audio. I then loaded it up into two channels in Metro and panned the two hard left and right. I offset the start time of the right channel. Then I ran both through the Expert Sleepers phase shifter plug-in. Then, to give them more presence, I ran them through an ambient (small room reverb) algorithm on my Lexicon MPX500 and re-recorded the result to a stereo channel. Here is a brief sample of the result.

I think the results are pretty decent. The cycling isn't too terribly obvious, once all six tones get kicked off and running. I'm going to experiment with it more Based on some Youtube videos I watched today, I'm not sure there is anything special about the octave interval (contrary to theory); I'm thinking many closely spaced tones would produce a better effect with less noticable cycling. But I'm going to use what I've got for the tune I'm working on.

Wednesday, January 12, 2011

Sysex strings for controlling JD-800 tones

If you've spent time working with sysex on the Roland JD-800, you may have noticed that the tone layer/active buttons don't send sysex. This means, among other things, that if you are trying to turn tones on and off during a performance and record it with a sequencer, these actions will not be recorded.

There is, however, a sysex string that you can send to a JD-800 to turn tones on and off. Here is the string; it's expressed in bytes as two hexadecimal digits per byte (most software sequencers will allow you to copy and paste this into a sysex editing dialog box):

F0 41 10 3D 12 00 00 21 0x 5y F7

The x and y are variables. A byte-by-byte breakdown of the string:
  • F0 The MIDI standard command byte that indicate that a sysex follows.
  • 41 Roland's manufacturer ID.
  • 10 The JD-800's unit number. The value "10" represents the factory default unit number of 17. If you have set your JD-800 to some other unit number, see the note at the end of this post.
  • 3D The model number for the JD-800.
  • 12 The command ID that tells the JD-800 to receive the following data.
  • 00 00 21 The address of the tone layer parameter in the single-mode edit buffer.
  • 0x is the parameter that tells the JD-800 which combination of tones should be on. The table below tells you how to set this value.
  • 5y is a checksum, which the synth uses to check to see that the sysex string was transmitted correctly; if the checksum value is incorrect, the JD-800 will ignore the sysex. The table below tells you how to set this too.
Set the x and y values according to this table:
[apologies for the white space problem below; I haven't been able to fix it]






















































































Tones OnXY
A1E
A, B3C
A, B, C78
A, B, C, DF0
A, B, DB4
A, C5A
A, C, DD2
A, D96
B2D
B, C69
B, C, DE1
B, DA5
C4B
C, DC3
D87


Sending the string turns on and off the selected combination of tones in the currently loaded patch. It only effects the edit buffer; it's exactly the same as pushing the buttons on the panel. The changes are not saved unless you write the patch to memory.

If you've changed your JD-800's unit number, you need to change the unit code in the sysex string. The JD-800 allows its unit number to be set to any value in the range 17-32. For unit number 17, the sysex code is 10, as show above. For unit 18, the code is 11; for unit 19, the code is 12, and so on... up to unit number 26, for which the code is 19. For unit 27, the code is 1A; for unit 28, the code is 1B, and so on... up to unit number 32, for which the code is 1F.


Wednesday, December 8, 2010

Fear and loathing of tantalum capacitors

Why is everyone so afraid of tantalum capacitors? Lately I see posts in various places from people who are anxious to go through all of their synths and rip out any tantalum caps that they find. Completely unnecessary, provided that the person who designed the circuit that the tantalum cap is in was designed by a competent engineer, and that it was installed properly. There's a few rules that you need to be aware if you are going to use a tantalum cap in a synth (or any other kind of circuit), but if you do it right, tantalums have significant advantages over electrolytic types.


Solid tantalum capacitors. The loose capacitors at left are 10 uF; the caps fastened to the tape at right are 1 uF. Note the penny for size comparison.

First, let's talk a bit about how tantalums work. Tantalum capacitors have something in common with electrolytics: in both cases, the capacitor dielectric consists of the oxide of the metal that one of the electrodes is made of. In the case of the electrolytic capacitor, it's a layer of aluminum oxide that forms when the electrolyte reacts with the aluminum anode under an electric charge. The electrolyte is necessary to maintain the oxide layer. When it eventually evaporates or leaks out of the capacitor's container, the oxide layer breaks down and the capacitor loses capacitance.

Most tantalums used to be made the same way; these were called "wet slug" types. The ones that fail inside '70s ARP synths are wet slugs. The problem with these is that, because tantalum is pretty unreactive compared to aluminum, strong acids have to be used as electrolytes. These eventually eat up the seals around where the leads penetrate the body, and the electrolyte gradually leaks out. However, at some point, someone figured out that they could use a process where the tantalum "slug" is dipped in an electrolyte at the factory before the capacitor is assembled, and connected to a voltage to form the tantalum oxide dielectric layer. Then, the slug is removed, dried out, and assembled into a capacitor; the electrolyte is used only at the factory. Because tantalum oxide is more stable under electric charge, the electrolyte isn't necessary to maintain it. These are the "solid tantalum" or "dry slug" types. There are several different designs used in solid tantalums, but they all use the same basic idea -- a tantalum slug forms the anode; a layer of tantalum oxide built up on it is the dielectric, and some material (often manganese dioxide) is bound onto the outside of the oxide layer to form the cathode. Thus there is no electrolyte inside the assembled capacitor; since there is nothing to leak out, the capacitor will not degrade or lose value.



Cutaway drawing of a surface-mount solid tantalum capacitor. From an NEC data sheet.

As it turns out, tantalum oxide has a very high dielectric constant. This means that a tantalum capacitor can use a very thin layer of oxide, only a few microns. The basic rule of capacitors is that the capacitance value is directly proportional to the surface area and inversely proportional to how far apart the electrodes are; since the electrodes in a tantalum cap are separated only by the thin oxide layer, a tantalum cap can pack a lot of capacitance into a small volume.

The problem with having an exceedingly thin dielectric layer is that it can't withstand high voltages; it doesn't have enough insulation value. Thus one of the first rules for dealing with tantalum caps: do not expose them to excessive voltages. Most references I've seen recommend that tantalums be derated to 50% of the rated voltage. Some say to go down to 30% when the tantalum is used in a low-impedence, high-power circuit. Inexpensive tantalums are usually rated for 25-50V, with higher voltage ratings becoming harder to obtain above 10 uF.

The second thing about tantalums is something that they are notorious for: exploding. Why does this happen? Two words: reverse voltage. The polarity of a tantalum cap must be respected. Any reverse voltage breaks down the dielectric layer. It reduces the oxide back to metallic tantalum, which then forms a short-circuit path; if the circuit the capacitor is in can supply a lot of current, the short path heats up rapidly and the capacitor goes boom. The third point is related: ripple current. Large amounts of ripple have a similar effect: they create localized heat spots in the dielectric, which breaks down at those spots and a short circuit results. So it is generally best to avoid using tantalum caps in applications where they will be exposed to high ripple current. (Nonetheless, some power supply makers use tantalums as filter caps in their supplies, and it works. How they get this to work, I don't know.)

So why use tantalums? For one thing, they are small and light, much smaller than electrolytic caps of the same rating. Second, solid tantalums can't leak because they contain no electrolyte. "So what", you might say. In a synthesizer, does it matter if the capacitors are a few grams lighter? Probably not. No electrolyte is an advantage, but many synths are loaded with electrolytic caps and they seldom leak, and even if they do, it's usually not that big a deal.

Well, there's another, very good reason to prefer a tantalum capacitor over an electrolytic. Consider:



This is an interface circuit that I built for a home automation system. It's basically a 7555-based monostable timer circuit that, when activated, holds a relay open for a fixed amount of time. The little yellow blob at bottom center, just above the red connector with the blue and orange wires going to it, is a .68 uF tantalum capacitor. When I prototyped this circuit, I used an electrolytic capacitor of the same rated value. When I fired it up to check it out, the actual value of the cap as determined by the circuit's time constant worked out to about .35 uF -- unsatisfactory, because the timer needed to hold for 600 milliseconds and I was only getting about half of that. Electrolytic capacitors are not noted for being precision devices; the .35 actual that I got from the cap marked at .68 is within the typical tolerance for electrolytic caps, which are often specified as being -50%, +100%. And, electrolytics will lose value over time as the electrolyte evaporates; it isn't unusual to pull one out of a circuit after several years and find that it is only operating at 10% of its marked value.

Standard tantalums, on the other hand, are specified at plus or minus 10%, and you can get tighter tolerances at a somewhat higher price point. And solid tantalums will retain their operating value over a long period of time. (Wet-slug tantalums are still made for special applications, but don't waste your time with them.) The advantages for synthesizer circuits should be obvious: when the calibration of, say, a VCO or a VCF depends on a capacitor circuit, tantalums will make the circuit closer to the center of the calibration range at aseembly, and will retain their value over time, reducing the need for recalibration. That's why I went with a tantalum when I built the board above; the .68 uF marked cap got me as close to the 600 millisecond time value as I could easily measure (50 ms or so) without trimming.

The one other thing about tantalums: there is no such thing as a non-polarized tantalum cap. So keeping in mind that you need to respect the polarity, a bit of care is required in design. Do that right, though, and you'll have a more stable and reliable circuit. After all, tantalums are considered reliable enough by the aerospace industry that they are heavily used in aviation and spacecraft. So don't be afraid of the tantalum.

Friday, October 1, 2010

Electricity for Synth-DIY'ers: Transistors

This is where we start to get into the more complex of the basic electronics components. Transistors are really the basis of modern electronics. It was the transistor, and its subsequent micro-miniaturization into integrated circuits, that really kicked off the electronics revolution in the latter half of the 20th century.

There are a number of different basic types of transistors. In this installment I'm only going to cover the bipolar transistor, which is still the most commonly used type. You are also likely at some point to run across another type, called the field effect transistor (e.g., JFET, MOSFET). Those work on a different physical principle and they have different characteristics. I'll cover them in a future installment.

What Does a Transistor Do?

Basically, a transistor is a device that controls a flow of current. This is the first thing to understand: the bipolar transistor is not a voltage regulating device; it's a current regulating device. A transistor has three terminals: current flows from one terminal to the other, under the influence of the third terminal. A small current flowing into or out of the controlling terminal controls a much larger flowing between the other two terminals. This is what allows the transistor to act as an amplifier: a small current can control a much larger one.

The three pins of a bipolar transistor are referred to as the emitter, the base, and the collector. The base is the control terminal; a small current at the base controls a larger current flowing between the emitter and the collector. Which direction these current flows go in depends on which of the two flavors of bipolar transistor you are dealing with; the two are known as PNP and NPN, based on their construction. If you remember the discussion from the diode installment of this series, a diode is a junction between two types of semiconductor, known as P-type and N-type. Same thing here: the PNP and NPN designations indicate what types of semiconductor material the transistors are made from, and by implication, which direction current can flow through them.

At this point we will introduce the symbology for transistors. The two types are denoted as:


The pin coming out to the left side of the symbol, perpendicular to the little bar, indicates the base terminal. The little arrow indicates the emitter, and of course the remaining pin is the collector. Note that in the symbol for a bipolar transistor, the collector and emitter are always portrayed as meeting the little bar at a 45-degree angle. If they aren't, then the symbol is for some type of FET transistor, not a bipolar.

As you may have figured, the direction of the arrow indicates whether the transistor is a PNP or NPN type. But what does the direction actually mean? This is where we introduce the first principle of the bipolar transistor: the junction between the emitter and the base acts as a diode. And, in accordance with the base pin being the middle pin in the transistor symbol, the middle letter in "PNP" and "NPN" indicates the type of the base; either of the other two letters can be regarded as representing the emitter. So, in a PNP transistor, the emitter is a P-type and the base is an N-type. If you remember from the diode discussion, this indicates that current can only flow from the emitter to the base, not the other way around. Accordingly, the arrow on the PNP symbol is pointing inward, to indicate that current goes in through the emitter. The opposite is true for an NPN transistor; since the base is P-type, current can only flow from the base to the emitter. So the emitter has to be a current exit, and so its arrow points out.

Do not, at this point, start confusing the current-in or current-out state of the emitter with where you actually obtain the amplified output signal! In both the PNP and NPN types, you can tap off of either the emitter or the collector to get the output, depending on the circuit design. We'll cover this further down. The arrow only indicates which direction current is flowing through the transistor.

So what about the base-collector junction? Does it also act as a diode? Well, no. Why not? To be honest, I don't know enough about the physics to give you a complete answer, but here's a simplified explanation: The base region of the transistor is very, very thin compared to the collector and emitter regions. So when the electron is attracted to the base region due to an opposite charge leaving the base, when it hits this region, instead of taking a 90-degree turn and heading laterally towards the base pin, it's easier to just pass through it to the other side. The collector region is "doped" differently so that it has much less of a tendency to pull charges away from the junction area when it is reverse-biased. So, although some electrons or "holes" go get gathered up by the base, most of them just go on through. That's what makes the transistor an amplifier. This is far from being a satisfactory explanation, but for a better answer, I'll have to refer you to someone who knows more about semiconductor physics than I do.

Transistor Circuit Basics

So, let's see what we've got so far. We have three layers of semiconductor material, with two junctions between layers of opposite types, one of which acts like a diode and one of which doesn't. For purpose of discussion, let's assume for a while that we are talking about an NPN diode. Now let's apply some voltages to some of the terminals. We'll start by applying 12 volts to the collector, and grounding the base and the emitter.

What happens? Nothing. Why not? Remember, the P-N junction between the base and the emitter has all of the properties of a diode -- including diode drop. Because of the diode drop, and the fact that we're talking about silicon, no current can flow from the base to the emitter until the base is at least 0.6V higher than the emitter. So now let's apply, say, 3V from a battery to the base.

Now what happens? Probably, the transistor burns up! Why? Because we're not thinking in the transistor's terms. The transistor isn't a voltage controlling device; it's a current controlling device. When we connected the battery to the base, we gave it an almost infinite source of current. The input impedence of the base of a bipolar transistor is very low. So right away a large current went into the base; this in effect threw the transistor "wide open" and a whole bunch of current flowed from the collector to the emitter. Even running wide open, the transistor has a small amount of resistance, and like any resistive device, there is a limit to how much heat it can dissipate.

So, after clearing the smoke and installing another transistor, let's re-think this and try again. The voltage into the base, as long as it's at least 0.6V above the emitter, doesn't really matter. What matters is the current going into the base. So let's put a potentiometer in between the base battery and the transistor base terminal. We'll also put in an ammeter in between the pot and the transistor base, and we'll put another one on the transistor's collector. I've prepared three short videos to illustrate some of thes principles; they use the circuit below:




We turn on the power and start turning the pot slowly clockwise, as in this first video:



What do we see now? At some pretty small value of current going into the base, we'll also see current starting to flow into the collector. As we increase the base current, the collector current will increase in proportion (up to a point, which I'll describe in a moment). The transistor is amplifying the current: as we put a current N into the base, we get a larger current X*N going into the collector. What is the value of X? That is, by definition, the transistor's current gain. When discussing bipolar transistors, the current gain is called the beta. (You may also see the terminology "Hfe".) The beta is a property of the design and construction of the transistor, pertubated somewhat by manufacturing variation. For the typical commodity small-signal transistors that we commonly deal with, the beta will generally be in the 50-250 range depending on the specific type. Fancier transistors, particularly power types, have gains ranging from the hundreds up to about 1000. The transistor used in the demo video has a beta of 200. So, for instance, when we adjust our pot for 50 uA into the base, we see 10 mA going into the collector. What if we used a PNP transistor? Well, we'd have to swap the voltages at the collector and the emitter, and apply a negative voltage so as to draw current out of the base rather than putting current in. But the operating principles are exactly the same. Only the arithmetic signs change.

Question at this point: what is the current coming out of the emitter? Well, all current that goes into the transistor has to come out somewhere. We have current coming in at both the collector and the base, and the only place where current is coming out is at the emitter. So it stands to reason that the emitter current is the collector current plus the base current: 10 mA + 50 uA = 10.05 mA. And if we had a third (accurate) ammeter on the emitter, we would see that this is true. Much of the time, when you are figuring currents through a transistor, you can disregard the base current and figure that the collector current equals the emitter current, since the base current is always a small fraction (according to the transistor's beta). Next question: what is the voltage at the base? Answer: it depends on the voltage at the emitter. As long as the transistor is flowing current, and isn't saturated ( in a moment), it will always maintain the diode-drop relationship between the base and the emitter, so if we are interested in the base voltage, we can always look at the emitter voltage, and the base voltage will be about 0.6V more than that. But the transistor is not really sensitive to the voltage at the base -- it's the current at the base that matters. You will often have to figure out the value of a resistor to put in series with the base.

Which brings up a point: you must always ensure that both the collector-emitter and the base-emitter currents are limited somehow. As we discussed earlier, the transistor will willingly pass enough current to blow up both itself and components connected to it. One way to limit the collector current, as shown by our example circuit, is to put the load (in this case, just a resistor) in series with the collector. However, you can also put the load in series with the emitter -- but the circuit will behave somewhat differently. Check this second video, in which we add resistance to the emitter load; as the resistance goes up, the base voltage goes up. This occurs because the pot plus the current-limiting resistance at the collector effectively puts the transistor in the middle of a voltage divider. As the voltage at the emitter goes up, the base voltage has to go up in order to maintain the diode-drop relationship.





Transistor Performance and Characteristics

Transistor performance is often shown in the form of a characteristic curve which plots collector current vs. collector-emitter voltage, for various values of base current. I don't find these to be terribly useful; the main thing they illustrate is that as long as the collector-emitter voltage is sufficiently large (typically 1-3V), the collector current depends only on the base current -- it doesn't depend on the collector-emitter voltage. But we knew that already. What we really want to see, for educational purposes, is a chart that details base current vs. emitter current. Here's a rough one that I assembled from taking measurements on the transistor I used in the video above. The green area indicates where the transistor is behaving linearly (constant beta), and the red areas indicate where it is non-linear. Bear in mind that the upper red area, in particular, depends considerably on the circuit that the transistor is installed in.




This illustrates a couple of things. The red "corner" at the bottom left is where the transistor is approaching cutoff; as in the case of the diode, this is where the base-emitter junction voltage is less than the diode drop and it is very non-linear. When the base voltage drops to or below the emitter voltage, the transistor will completely stop carrying current, except for a small leakage current which, for smaller transistors, is usually on the order of a few nanoamps. The other interesting red bit is the flattening out of curve as the collector current approaches 20 mA. This occurs as the transistor is approaching saturation -- a condition where it cannot carry any more current because there are no more charge carriers available at the junctions. Why are there no more charge carriers available? Because, in the case of the video above, the circuit that the transistor is in can't source any more current. Note that this is not a limitation of the transistor itself; it's a limitation of the circuit that the transistor is in, and specifically the resistance that I put in series with the collector. The 500 ohms resistance between the battery positive and the collector limits the maximum possible current to about 20 mA.

In between the cutoff and saturation regions is the active region, shown by the green portion of the graph. In the active region, the beta remains nearly constant, and so the transistor's response to base current is nicely linear, as shown in the center portion of the above graph. When you are using the transistor as an amplifier, this is what you want. On the other hand, the cutoff and saturation regions have their uses too.

Transistor Applications: Switching vs. Amplification

The two most common uses for a transistor are switching and amplification. Let's cover the switching case first since it is easier to understand. In a switching application, we want the transistor to, at any given time, be in one of two states. The "off" state obviously corresponds to the transistor's cutoff region: we kill the base current, and the collector current goes to near zero. The "on" state can be a little trickier. It's common to operate a switching transistor in saturation; in this state, it has a very low resistance (provided that the collector current isn't excessive). A common rule of thumb for switching circuit design is to figure out what base current is needed to achieve the necessary collector current, and then double it. However, in doing so, you have to make sure that the transistor's limits for base current and power dissipation aren't exceeded. Here's an example of a common use for a transistor circuit: the transistor is being used to drive a relay. (The relay could, for example, be switching a high-voltage circuit on or off. A typical example in the audio world would be that the relay might be controlling the high-voltage plate supply in a tube amplifier.) Assume the following:
  • The relay coil has an impedence of 250 ohms
  • It takes 20 mA of current through the coil to make the relay close
  • The transistor has a beta of 100
  • The supply voltage is 12V
When the switch is closed, the base resistor feeds current into the base of the transistor. This is where the fun starts: how do you analyze this to know how much base current you need? Start by doing an Ohm's Law calculation: in order to to push 20 mA through the 250-ohm coil, you need to apply at least 5V to it. So we know it's doable, provided that our 12V power supply can source at least 20 mA of current without drooping. Now, in order to pass 20 mA of current through the transistor, how much base current do we need? Dividing that current by the beta gives us 0.2 mA, or 200 µA, of base current. If the switch is also connected to the 12V supply, then in order to put 0.2 mA into the base, we need a 60K ohms resistor in series with the base. (Note in this case that because of the base-emitter diode drop, the voltage at the base will need to be at least 5.6V if the relay coil is in series with the emitter. If we only had 5V being supplied to the switch, that won't work; the transistor will remain cut off. If this is the case, you have two options: (1) supply a higher voltage to the switch, or (2) put the relay coil in series with the collector and ground the emitter.)

Now, the thing about transistors is, the beta of specific units varies a lot from unit to unit across a given part number. So if our transistor is spec'ed for a nominal beta of 100, the beta of the particular unit we have might only be 70 or so. There are two approaches to this. One is that we can test the individual transistor that we put into the circuit and make sure its beta is at least 100. However, if we are manufacturing in quantity, it will take extra time to do the testing, and cost more because we'll have to discard some percentage of the transistors that we buy. The other approach is to provide for the minimum expected beta of a particular unit. In a switching application, this is pretty easy; if we reduce the base resistor to 30K, then the transistor beta can be as low as 50 and it will still work, but the base current is still low enough to not cause damage.

Well, assuming that your transistor is operating in the active region, it's pretty easy: choose the resistor that results in 2 mA of base current, and you'll get 200 mA out. But how do you know what resistor value gets you 2 mA of base current? And how do you know for sure that you are going to be operating in the active region? After all, that depends on the collector-emitter current.

Historically, though, amplification has been the most common use for transistors. This is not quite so true in audio applications today; opamps have taken over most of the functions of amplification within audio devices because they are easier to design with. In audio-frequency applications, discrete transistors remain mostly in power amplifiers. Nonetheless, we'll look at two methods of using transistors as amplifiers.

The first type of circuit uses a single transistor. As you might guess, the first problem that one faces when using a transistor to amplify alternating signals is that the transistor can only flow current in one direction, which means that if you just feed an AC signal into the base, at best only half of the signal will get amplified -- the other half will be absent from the output, because the opposite-polarity voltage applied to the base drives the transistor into cutoff. The way to solve this problem is to bias the input signal -- that is, add an offset current to it so that the transistor stays within the active region throughout the input signal range. This drawing illustrates a common way of doing this:



This is an example of a single-transistor amplifier driving a loudspeaker. The resistors obviously constitute a voltage divider, but it can also be thought of as a current divider. It sets the "operating point" of the transistor: the amount of current that enters the base when the input signal is quiescent, which is proportional to the voltage drop in the middle of the divider. Assuming that the input signal will on average be symmetric, the operating point needs to be at the midpoint of the transistor's active region. The input also needs to be scaled, per the transistor's approximate beta, so that a maximum input signal will not drive the transistor into saturation, and a maximum negative signal won't drive it into cutoff. Since the output will have a DC offset, the usual practice is to couple it into the following circuit via a DC-blocking capacitor (not shown here).

This single-transistor circuit is pretty common in circuits which handle small currents, but for large-current circuits, there are better methods. The two-transistor "totem pole" is a commonly used circuit; it is nearly universal in audio power amplifiers. In this configuration, a PNP and an NPN transistor are used together, with either their collectors or their emitters tied together, and the output taken from that node point between the two. One transistor amplifies the positive half of the signal; the other transistor amplifies the negative half. In Class A operation, the transistors have their operating points set so that neither of them ever goes into cutoff. A given level of input signal causes one transistor to conduct more current while the the other one conducts less; the difference is what appears as the output signal. When the input signal is quiescent, an equal current flows through both transistors. Well designed Class A amps are noted for their low-distortion operation, but they are very inefficient at low signal levels because a lot of "wasted" current is passing through the two transistors.

In Class B operation, the transistors have their operating points set so that they both enter the cutoff region precisely at the point where the input signal is zero. Note that some bias is still required in order to overcome the base-emitter diode drop; otherwise, there would be a "hole" in the response at very low input levels. It's harder to design a Class B amplifier for low distortion due to the fact that the transistors are approaching the non-linear cutoff region, but a Class B amp is far more efficient than a Class A -- at a zero input level, the Class B amp draws little current. There exist designs that are hybrid of these two concepts, known as "Class AB"; they set the operating points so that one transistor cuts off when the other is well into its active region. These are a compromise between distortion and efficiency.

Emitter vs. Collector Output

There are two basic ways of obtaining the output signal from the transistor, which we've already touched on, but they need to be described more explicitly. One is the common emitter configuration; in this configuration the emitter is connected to ground or to a power supply, and the output signal is obtained at the collector. If the output signal is something that requires a lot of current and has some resistance, such as a relay coil, the easiest way to do this is to put the load in series with the collector.

However, this configuration can also be used to derive a voltage signal from the input, provided that the load doesn't draw much current. The way to do this is to put a resistor in series with the collector (which you often will do anyway, to limit the maximum current) and then tap a point between the resistor and the collector. This effectively makes the transistor behave as a variable resistor in a voltage divider, and the output comes from the middle of the divider, as such:



Note a couple of things about this. The first is that the signal output is inverted from the input; the output voltage will be at its maximum when the base current is zero, and vice versa. The second thing to note is that the swing of the output voltage is determined by the maximum collector-emitter voltage, and so it can be of higher voltage than the input to the base. So in this mode, the transistor is capable of voltage gain in addition to current gain. This is illustrated by the video below:



The other configuration is usually called the emitter follower. In this configuration, the signal is taken from the emitter:


You can, if you are careful, design an emitter follower circuit with no current-limiting resistors. This configuration provides the maximum possible power within the limits of the transistor, which is why it is frequently used in power amplifiers.

Darlington Pair

You can use a pair (or more) of transistors to obtain higher gain, by driving the base of a second transmitter from the emitter of the first one, like so:


This is known as a Darlington pair. Where the name comes from, I don't know; I've often wondered if it has anything to do with the notorious speedway in South Carolina. The total beta for the Darlington pair is B1 x B2, where B1 and B1 are the betas of the individual transistors. As you can see, you can obtain quite high gain levels this way. Darlington pairs can be purchased as pre-made parts, or you can of course make your own from individual transitors.

Other Useful Transistor Circuits

You may recall that back in the diodes chapter, we presented a simple regulated power supply circuit controlled by a zener diode. The problem with that circuit is that the zener itself has to dissipate all of the power not drawn by the load at any moment. Here's an improved version:


In this circuit, the zener only has to dissipate the very small base current. The regulated voltage will always be 0.6V less then the zener's voltage rating, thanks to the B-E diode drop. The transistor has to pass all of the power supply current, but you can get power transistors that can handle substantial current.

The next circuit is called a current mirror, and it has a number of uses:


The way it works is that the resistor on the left allows a specific amount of collector current to flow through the transistor on the left, and its connection to both of the bases will cause the same amount of current to flow through the transistor on the right. This means that a fixed amount of current will flow through the load (within the limts of the power supply). The two transistors must be of the same part number and be matched -- that is, tested to make sure they have the same beta value. The circuit is useful for any situation where a constant-current supply is needed. Replacing the resistor on the left with a varying load will cause the two loads to always see the same amount of current.

A similar-looking circuit is the differential amplifier:


This circuit amplifies the difference between the inverting and the non-inverting input. If both inputs change by the same amount, the output does not change. This is frequently used in pro audio applications where "balanced" lines are used, e.g., to send microphone signals long distances to a mixing console. Noise that tries to enter the line will enter both inputs in equal amounts (called "common mode" noise) and the amp will reject it. It is also frequently used in sophisticated amplifier circuits where negative feedback is used to stabilize the circuit.

Transistor Numbering, and Packaging

Three main packaging styles are used for transistors these days. "Small signal" transistors are generally found in what is know as a "TO-92" package:



It's a small cylindrical plastic package, nearly always black. One side is flat for orientation, and circuit board designers often use a flat-sided circle on the board silkscreen to indicate which way the transistor is to be inserted. Generally, as you look at the flat side, the order of the pins is emitter/base/collector, but not always. So be sure to check the data sheet for the specific type that you have. Usually, the part number will be printed on the flat side. Not pictured is the TO-18 metal can, which is the same size as the TO-92 but does not have the flat side. A small piece of metal sticks out from the edge of the can to identify the emitter pin. The TO-18 version is not much used anymore, but very common in electronic devices made prior to 1985 or so.

Somewhat higher-power transistors will usually be found in a "TO-220" package:


Photo courtesy of the University of Michigan Smartsurfaces Project

As in the case of the TO-92 package, the order of the pins may vary. The metal tab is intended to be mechanically fastened to a heat sink, to increase the current carrying capacity of the transistor. The tab is often electrically connected to one of the pins, usually the collector, so electrical insulation may be required between the tab and whatever it is fastened to. As usual, check the data sheet.

Serious power transistors come in a "TO-3" case:


Photo from Wikipedia Commons

These are most commonly found as output transistors in audio and RF power amplifiers, and switching transistors in solid-state power controls. Not visible in the photo are two pins that stick out from the bottom side, which are the base and emitter pins; the case itself is the collector. These are made to be inserted into a special socket, and they are usually in contact with a live heat sink (insulated from ground) which is also part of the collector circuit. Transitors this large have a number of non-ideal properties, such as high leakage current and parasitic capacitance.

There are three main systems for part numbering of transistors. As in the case of diodes, there is a JEDEC system for transistor numbering. While diode JEDEC numbers all start with "1N", transistors start with "2N". This will be followed a a three- or four-digit number, and possibly additional letters to identify variants. In general, higher numbers are more recent designs.

Many transistors made in the Far East use the Japanese Industrial Standard (JIS) system. In this system, numbers for PNP types start with "2SA" or "2SB", and NPN types start with "2SC" or "2SD". A European system called Pro-Electron also exists. In this system, the first character is "B" to indicate a silicon-based device. A second letter of "C" or "D" indicates an audio-frequency transistor; "F" or "L" indicates a radio-frequency transistor, and "U" indicates a power switching transistor. Here is a good Web page that summarizes these systems.

Transistor Conventions and Standard Parts

You may have noticed that all of the circuits I've presented in this post have all used NPN type transistors. There is some history for that: in the 1960s when transistors first came into use, for reasons not clear to me, NPN types were a lot easier to make -- and therefore a lot cheaper -- than PNP types with equivalent characteristics. For that reason, designers figured out how to build many common circuits using only NPN types. This persists somewhat in electrical engineering; in situations when the choice between designing a circuit to use NPN or PNP transistors is an arbitrary choice, designers will usually go the NPN route. A side effect of this is that when engineers discuss the characteristics of various transistors, they will generally talk about the NPN type as being the standard, and then just note whether or not an equivalent PNP type exists. PNP types aren't often discussed for their own sake.

In synthesis circuits, we don't typically deal with large currents, so we usually stick to small-signal transistors. (This will change if you get into building amplifiers.) Doing a quick survey of small-signal transistors used in the most common published synth-DIY circuits, I note these three commonly used part numbers:

* BC547. A very useful and inexpensive NPN small-signal transistor, with a maximum collector-emitter voltage of 45V and maximum collector current of 100 mA. A Fairchild data sheet specifies beta as being in the range 110-220 for the "A" version; there are "B" and "C" versions with higher beta ranges at somewhat higher prices. As of this writing, Mouser has the "A" version listed for a whopping five cents USD apiece, quantity 10. They come in the TO-92 plastic package. The BC557 is a complementary PNP type.
* 2N3904. A similar part to the BC547, with max collector-emitter voltage of 40V and a maximum collector current of 100-200 mA depending on which version you get. Beta is in the 100-300 range; here's a Fairchild data sheet. It comes in a TO-92 package and a variety of surface-mount packages. It's a little faster than the BC547, which generally won't matter in synth applications. The main thing you have to watch is the max emitter-base reverse breakdown voltage of 6V. Mouser is quoting them at five cents USD apiece, quantity 25. The 2N3906 is a complementary PNP type.
* 2N2222. The easy-to-remember "all twos" NPN transistor has some virtues over the above, mainly that it can handle more collector current: 500-600 mA for most versions. It is still available in the TO-18 metal can as well as the TO-92 package; the former is good for applications where you need to thermally couple it to something (e.g., the expo converter circuit in a VCO/VCF), and some people claim that the extra parasitic capacitance of the TO-18 can makes it sound a bit better in audio applications. Here's an ST Microelectronics data sheet; collector-emitter voltage is 40V and beta is in the 100-300 range. As in the case of the 2N3904, you have to watch the 6V base-emitter reverse breakdown voltage. Main disadvantages are the somewhat higher cost (cheapest one I see at Mouser is $0.54 USD, quantity 25), and the fact that there is no exactly complementary PNP type.

On To the Next

As you can see from the date of my last post, it's taken me a long time to get this one together, for various reasons. This is the end of the series on discrete parts; next, we'll swing into integrated circuits with a discussion of operational amplifiers -- op amps.