MOSFET Audio Amplifier

The questions below are due on Friday October 04, 2024; 05:00:00 PM.
 
You are not logged in.

Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.
Take Your Time

The lab is not a race! Take your time, read all the words, try to answer questions (and ask for help if you get stuck, and make sure you understand things before moving on, rather than just racing through).

There are a lot of words, but most of them are important. Please ready carefully!

Danger, Will Robinson

There are some places in the lab where you can cause harm to yourself or your laptop if you're not careful. Seriously, let's not rush through it.

1) Remembrance of Things Past

In last week's lab, we built a digital-to-analog converter (DAC), which let us take purely digital (only "high" 3.3V or "low" 0V) signals from the Teensy microcontroller and turn them into analog voltages that spanned a wide range of possible values. Today, we're going to build on that, and to try to resolve the issue we found with trying to use our DAC to play a song last week.

Our circuit from last week looked like this:

Go ahead and grab your circuit from last week (it should be right where you left it), and grab yourself a speaker if you need to as well. Then download this week's Teensy code here: https://circuits.mit.edu/_static/F24/labs/audio_amp/audio_amp.zip

Upload this code to your Teensy. If you use the oscilloscope to measure v_{\rm out}, you should see a signal moving around as the DAC attempts to play the song. Then if you also hook up a speaker to the port labeled v_{\rm out}, you'll see the signal change dramatically! You should also hear a real banger of a song playing, but it will be playing pretty quietly (much more quietly than we would expect given the roughly-0V-to-2.2V range of outputs we were seeing from our DAC before connecting the speaker).

Last time, we used some of the theory we've been learning to try to explain this behavior. In particular, we modeled the DAC using a Thévenin equivalent and modeled the speaker as a resistor:

Calculating by hand, what is the Thevenin equivalent resistance of your DAC circuit? Remember that we used R=1{\rm k}\Omega.

R_{\rm TH} =~

Given the R_{\rm TH} value from above, and the measured resistance of the speaker, approximately what fraction of the input voltage (e.g., our song signal) do we expect to see on the output terminal?

\displaystyle{v_{\rm out}\over V_{\rm DAC}} =~

Check Yourself 1:
Use the scope to make some measurements and double-check; is this about the ratio you see when plugging/unplugging the speaker?

Now that we've remembered the problem from last week, let's do something about it. In particular, we'll end up fixing this problem today by using a device that we can model as a voltage-controlled current source, which is really going to let us PUMP UP THE JAMS so everyone on the whole block can hear how cool we are and how great our taste in music is.

This isn't exactly what we'll build, but we can take a look at one kind of circuit that would, in principle, resolve this issue, using a dependent source:

This parameter k has units of 1/\Omega, which is actually called a siemens but is often humorously referred to as a "mho," for "ohm" backwards. The symbols for siemens/mhos is actually a capital S, but it's not uncommon to write it as 1/\Omega or \mho.

In this circuit, we can measure V_{\rm TH} with negligible amounts of current flowing through R_{\rm TH}, and then produce a current elsewhere in the circuit that is proportional to that measurement. By running that current through our speaker, we should be able to get a much bigger voltage drop across our speaker than before (and, thus, a much louder sound).

What we build below won't be exactly this, but it will work by roughly the same principle.

Solve for the voltage drop across the speaker in terms of v_1, R_TH, R_speaker, and/or k, given the circuit layout above.

2) Unplug Your Teensy From Your Computer

Now that we've remembered our problem and thought a bit about how we're going to solve it in a theoretical sense, let's go about doing it for real.

To start, disconnect the Teensy from your computer. We're going to be doing some stuff that could potentially damage your computer if we leave it connected.

REALLY, ONCE IT'S PROGRAMMED, UNPLUG THE TEENSY FROM YOUR COMPUTER.

Did you disconnect the Teensy from your computer? 

3) Our New Friend, the Benchtop Power Supply

But the teensy needs power to work, and it was getting that power from your laptop before, but we'll grab it from a different place for today, the benchtop power supply, which looks something like this:

We'll need little plugs in both the port labeled CH1 and the port labeled CH2. Yours may not have all the necessary connectors coming out of it; if it doesn't, you can maybe unplug the red and black cables from your multimeter and put them in the other channel (make sure you put red and black in the right holes and DON'T PUT ANYTHING IN THE LITTLE GREEN HOLE AT THE BOTTOM LABELED GND).

When you turn on the supply (the button on the bottom left), you'll see something like the above on the display. While the green "V" on the right is lit up, turning the big knob will adjust the voltage; clicking the little "A" will change things to that the big knob will adjust the maximum current instead. The channel whose values you're changing can be selected by clicking "CH1" or "CH2".

For now, let's do the following:

  • Make sure all of the little things labeled "On/Off" are off (not lit up)
  • Make sure the "SER" and "PARA" buttons up top are also off (not lit up)
  • Click the "CH1" button if it's not already lit up, and then use the "V" and "A" buttons and the knob to set it to output 5Volts with a current limit of 300mA (0.3 A).

When all is said and done, it should look something like the picture above. If you are having any trouble or just want a staff member to double-check things, let us know!

Then, with your laptop DISCONNECTED (seriously), do the following:

  • connect the red wire from CH1 to the pin labeled "5V" on the far corner of the Teensy, and
  • connect the black wire from CH1 to the pin labeled "G" on the other corner of the Teensy.

When you're confident that you've done that correctly, hit the "ON/OFF" button just under "CH1" on the power supply. That button should then light up and stay lit up, and if you plug your speaker back in, you should hear the song again.

Check Yourself 2:
Do you hear the song? If not, ask a staff member for help.

Check Yourself 3:
Before moving on, turn the power supply back off by clicking the 'ON/OFF' button again. It's a good idea to leave the power supply off when we're building things, and only to turn it back on when we need it.

4) MOSFET? Who's That?

For the rest of the day, we're going to be trying to fix the issue from last week. We're going to do so by using a new kind of device called a MOSFET ("metal-oxide-semiconductor field-effect transistor" if you're feeling fancy). These devices are everywhere, and they're versatile. They can be used as switches (in digital circuits) or as amplifiers (in analog circuits, which we'll see today).

Compared to other components we've seen so far in the labs, the MOSFET is somewhat complicated. But, lucky for us, engineering is all about selectively ignoring complexity, so we're mostly just going to focus in on the parts that we need for the lab today (though if you're interested to learn more, you should definitely take 6.208 and 6.209 at some point in the future!). For now, don't worry if you don't understand every detail of the MOSFET; the conclusion and the way we're going to model the MOSFET is the most important thing for our purposes today.

Here is a photo of the MOSFET we'll be using today:

And schematically, we'll represent these things like so:

One thing you might notice about this device is that it has three terminals, referred to as the SOURCE (S), the GATE (G), and the DRAIN (D). Let's take a moment to look at the datasheet for this MOSFET to learn a little more about it. There is a lot of information there that you might need if you're working with this device in the future, but for today we'll help you focus in on the relevant parts. Let's start by looking just at the first page of the datasheet. Right at the top, there is a picture showing the device and labeling each of the pins.

What order are the terminals in, looking from the front of the MOSFET like above? Enter your answer as a sequence of letters in the box below, for example dgs would indicate that the Drain is on the left, the Gate is in the middle, and the Source is on the right.

On page 3 of the datasheet there are also some interesting curves shown, which help us characterize the behavior of this device. But oh, no! The curves are all horribly nonlinear and gross, for example, here's the one we're really going to be caring about today, which shows how the voltage drop between the Gate terminal and the Source terminal (v_{\rm gs}) and the voltage drop between the Drain and the Source (v_{\rm ds}) relate to the current flowing from the Drain terminal to the Source terminal (i_{\rm d}):

Oof. Life would be hard if we needed to work with things on that level. But let's not worry too much; engineering is all about selectively ignoring gross details of things. So we don't need to be too worried. We're going to invent a better world for ourselves, where everything is approximately linear. Each of the curves in that picture represents the relationship between v_{\rm ds} and i_{\rm d} for one particular value of v_{\rm gs}. Let's look closely at the second curve from the bottom, just as an example. Note that there is a little region of that curve where it looks almost like a horizontal line:

Let's imagine that that horizontal line continued forever in both directions rather than curving off as it does. What that means is that in that region, the current flowing through this device is constant, regardless of the voltage drop across it. What kind of component does that sound like?

OK, cool! Now let's notice that each one of the curves in the graph has a little region over which this relationship seems to be linear:

So what this is saying is that (under a certain range of values), this device behaves almost like a current source. For a fixed value of v_{\rm gs}, the value of this current source is roughly fixed; but as we change v_{\rm gs} (which moves us from one curve to another in the graph), that value changes as well.

This is not exactly what's going on, but it's a reasonable approximation under certain conditions. So what we're going to do for today is to try to keep ourselves operating in those regions of the graph, so that we can squint our eyes and ignore all the horrible nonlinearities:


 

OK, so let's focus our attention on that little region of the graph. To reiterate: if we're ignoring the blurred out regions, then for each of the curves, i_{\rm d} is roughly constant no matter how we change v_{\rm ds}. That sounds like a current source! And, what's more, the specific value of i_{\rm d} depends on the value of v_{\rm gs}, so it sounds like a dependent current source.

There's a lot of detail in the paragraphs above, but the ultimate takeaway is that, under certain conditions, we can model the MOSFET as a voltage-controlled current source: the current flowing between pins D and S is a function of the voltage between G and S.

So if we hook it up so that we're providing a voltage between G and S, the current flowing from D to S will change as we vary that input voltage, which means we can model the MOSFET like this:

4.1) Focusing Our Attention

Unfortunately, even the dependence of i_{\rm d} on v_{\rm gs} is nonlinear; but we can work around that limitation as well1. To attempt to think about this nonlinear device in a linear way, it will be helpful to assume that our input signal v_{\rm gs} is the sum of two pieces: a constant ("DC") offset, and a time-varying ("AC") component, something like this:

If the wiggly part, v_{\rm gs,AC}, is small, then we can approximate the function that governs the VCCS model of the MOSFET as something like:

\underbrace{i_d(t)}_\text{the output current} \approx \underbrace{f\left(v_{gs, DC}\right)}_\text{a constant that depends on the DC offset} + \underbrace{g_m\times v_{\rm gs, AC}(t)}_\text{the AC part of the input scaled by some value}

Hooray, so here's where we're at: if we ignore the DC offsets of both the input and the output signals, and if the AC part of the input is small, then the MOSFET looks something like a linear VCCS (the AC part of the output signal i_{\rm d} is approximately a scaled version of the AC part of the input signal v_{\rm gs})!

5) We Walk The Line

It's important to note that the model discussed in the last section isn't actually what is going on inside the transistor. We live in a horrible nonlinear world, and we've already seen that the actual curves the transistor lives on are nonlinear even beyond the ways we've mentioned above (not to mention that they vary with other external parameters like temperature, etc). But that doesn't mean we can't make productive use of it!

This idea is not at all specific to this lab; our love of linearity is one of the things that make us EE's as opposed to other kinds of engineers. When confronted with nonlinearities in the world, EE's will often make assumptions or limit our attention to cases where things look linear because the tools that we have for thinking about linear systems are so powerful! So for today, we'll assume that the MOSFET is actually working like that voltage-controlled current source, as seen above, and see how far that gets us (if we need to, we can always back up and build a more-complicated model).

Of course, though, we can't just make this assumption blindly; we need to be careful about how we're using the MOSFET to help make sure we're staying within those regions of the graph where things look mostly linear.

So as a place to start, let's experiment with the MOSFET a little bit to try to find a safe region to operate in, where the MOSFET is more-or-less operating linearly.

For this experiment, we're going to use both the benchtop power supply and the oscilloscope's wave generator. Let's go ahead and do the following:

  • On the benchtop power supply:
    • Make sure that CH1 is off.
    • Set CH1's voltage to 7.5V.
    • Set CH1's current limit to 300mA (0.3A).
  • On the wave gen, choose:
    • Waveform: Sine
    • Frequency: 1kHz
    • Amplitude: 150mVpp
    • Offset: 0

Then go ahead and lay out the following circuit on a breadboard (if there is room on the breadboard containing your DAC circuit from last week, you can build it there; if not, feel free to use a second breadboard; we can always connect them together later).

DO NOT USE THE 33 OHM RESISTORS FROM THE CABINET; COME GRAB A PINK-ISH ONE FROM THE FRONT OF THE ROOM INSTEAD.

Try not to bend the pins of the MOSFET as you put it in the breadboard! The usual trick is to push down gently while wiggling it side-to-side, like so:

Note that, for this experiment, we're using the wave generator to provide our input signal v_{\rm gs}, and we'd like to measure i_d to see how the two compare. Unfortunately, measuring i_d directly with the scope is difficult; but we can get at it by measuring the drop across the 33\Omega resistor and then dividing through by its resistance.

And, even more unfortunately, measuring the drop across that resistor is a little tricky, too; we can't just hook one of the channels across R_{\rm speaker}, since all of the little alligator sides of the scope probes are all connected together internally.

But, fortunately, these scopes give us a way to make that measurement regardless. Note that, as we currently have the probes connected, the drop across the speaker is the difference between the voltages we're measuring on channels 2 and 3. If you click the "Math" button in the bottom left of the scope, you can choose to have it subtract two signals and show that output. That's what we want to do here. So let's subtract channel 3 (on the bottom of the resistor) from channel 2 (on the top of the resistor), we should get the drop across the resistor.

Check Yourself 4:
Double-check that your circuit is laid out correctly. If you need help here, and/or if you want us to take a look with you, feel free to ask!

Warning

Be careful; during this experiment, your resistor will get HOT. Like, hot enough that touching it will be painful. Be careful when touching it. Don't leave the power on for too long, and let things cool down before touching them.

Once you're confident you've got your board laid out correctly, go ahead and turn on CH1 on the benchtop power supply by hitting the little "On/Off" button beneath it (the button should light up to indicate that it's on). Use the knobs on the scope to zoom in and out so that you have a good clear view of all of the channels (1, 2, 3, and the math function).

Note that, if the MOSFET is behaving according to our model from above, the Math curve (representing the drop across the resistor, which is proportional to i_d) should have approximately the same shape as our input signal (it should be a sinusoid). As we've currently set up the wave gen, though, things are definitely not linear. But by adjusting the wave gen's "Offset" parameter (which represents a DC offset), we should be able to find a place where things are roughly linear.

Check Yourself 5:
Go ahead and adjust the knob until you find a spot where the MOSFET is behaving roughly linearly. As a hint, the right offset is probably somewhere between 1 and 5 Volts.

In order to find a nice value, you will likely also need to switch to adjusting "Offset Fine" instead of just "Offset" mode so that the knob makes smaller adjustments to the offset voltage. The output will never look exactly like a pure sinusoid, but it should be possible to get close.

Once you have that value, write it down somewhere; we'll need it later.

Once you have that, turn the power supply off for a little bit and let things cool down a bit. Then turn the power back on, make any final adjustments you need to that you can see the Math curve clearly on the screen. Then hit "Run/Stop" to freeze the display in place, and turn the power back off.

Use the cursors to find the peak-to-peak voltage drop across the resistor, and use that to estimate g_m (remember that the peak-to-peak amplitude of i_d, the current flowing through the resistor, will be approximately g_m times the input voltage's peak-to-peak amplitude).
 
g_m~(\text{in}~\mho)\approx~

Checkoff 1:
Show the results of your experiments so far to a staff member, and explain how you found an appropriate offset voltage and estimated g_m.

6) Fixing Last Week's Issue

Now that we've gotten to know the MOSFET a little bit, let's make use of it in a real circuit. Ultimately, our goal will be to use the MOSFET to fix the issue from last week's lab.

What we found in the last section is that:

  • If the total voltage drop across the whole system is around 7.5V, and
  • the peak-to-peak amplitude of the wave on v_{\rm gs} is around 150mV, and
  • the DC offset is around the value you found in the previous section,
  • then the AC part of the current through the resistor (as well as the voltage drop across it) is roughly proportional to the AC part of the voltage on the gate of the MOSFET.

In this part, we're going to hook up our DAC from last week so that it's providing v_{\rm gs}, and we'll also replace the 33\Omega resistor from the last part with our speaker from last week.

In order to do this, we're going to need to keep in mind the constraints above as they relate to our Teensy, and we'll need to adjust our DAC a little bit to make things work.

6.1) Adjusting the DAC's Output Range

From last week, recall (or, hey, measure it again right now if you want) that the DAC's output voltages (with no speaker attached) were roughly in the range from 0 to 2.2 Volts. However, if we're trying to treat that signal as the input to our MOSFET amplifier, we're going to need it to be around 150mV peak-to-peak instead of 2.2V peak-to-peak.

We can do this by putting a resistor at the output port, which should scale those voltages down:

If we want to scale the voltages down as shown above, what value of resistance should we use?
 
R =~

We won't have exactly that resistance in the cabinet, but we should have some that are close. Go ahead and grab one; we'll need it in a bit.

6.2) Setting the Offset Voltage

We're also going to need to add a DC offset to our DAC's output voltage (the same offset you added to the sine wave earlier in the lab).

We're going to need to use both CH1 and CH2 on the benchtop power supply to make this work. The Teensy needs a 5V drop across it in order to work, and we also need to make sure that we're offsetting the Teensy's output voltage by roughly the amount you found in the first part of the lab. We can do this by connecting the two channels up end-to-end like so:

Here, V_{\rm offset} is the value you found in the last part of the lab. Go ahead and adjust CH2 to have that voltage (and a current limit of 0.3A). Note that you can hit the "Fine" button to make the knob click more slowly through the voltages.

Then we can connect the red side of CH2 (V_{\rm offset}) to the black side of CH1, and then connect the black side of CH2 elswhere on the board.

6.3) Build It

Let's go ahead and fill out the circuit a little bit more. Ultimately, this is what we want to build, where the V_{\rm TH} and R_{\rm TH} represent our DAC from last week and R represents the resistance from the previous section. You can go ahead and hook everything up now if you want, but DON'T TURN ON THE POWER YET!:

Check Yourself 6:
How will this circuit solve the issue we saw from last week?

Check Yourself 7:
Before turning the power on, double and triple check both your circuit and the settings on your scope and power supply. Don't turn the power on unless you're absolutely certain everything is connected properly.

Also make sure your Teensy is still disconnected.

If you want us to take a look, let us know.

7) Party Time

Alright, here we go! If you turn the power supply on (hit "ALL ON/OFF"), you should see the output of your DAC on channel 1, and you should hear the song, but now played at a nice volume that doesn't make us hold the little speaker right up against our ear to be able to hear it!

Check Yourself 8:
You may need to adjust your offset voltage slightly downward (by maybe about .05V or so) in order for things to sound nice. Can you think of why this might be the case?

Be a little careful, though. If you leave the thing running for too long, the speaker will get really hot and eventually break. We're not being particularly nice to the speakers, and there is more we could do to improve that; but we'll have to save that for later in the semester. For now, just don't leave the thing running for multiple minutes at a time; enjoy the song a couple times through, then turn it off and let things cool down, and you can turn it back on after a little while if you just can't get enough.

Check Yourself 9:
At this point, the song should be substantially louder than when we started. But let's imagine we wanted to make it even louder. We can easily do that with this circuit if we're willing to accept some nonlinearity in our output.

So let's try it. Instead of using that resistor R to scale things down, try removing it so we're putting the full 0-to-2.2-Volt output voltage of our DAC directly on the gate of the MOSFET.

Note that you'll need to change your offset voltage (somewhat substantially) to make this sound good. But when that's set properly, it should sound pretty acceptable (and also substantially louder than the version where we scaled the input voltage down to 150mV peak-to-peak).

Checkoff 2:

Discuss your results with a staff member. How is this circuit, as a whole, working? How does it fix the issue we saw with the DAC/speaker combo from last week?

When you're all done, clean up! For today:

  • Keep your DAC (we're still not done with it yet), but remove the extra resistor we added to bring the peak-to-peak amplitude down to 150mV.
  • Return the MOSFET, power resistor, and speaker to the cart at the front of the room
  • If you borrowed a USB cable and/or an adapter, we want those back, too

Then also reset the lab equipment:

  • On the scope, hit "Default Setup"
  • On the scope under "Wave Gen," hit "Settings" and then "Default Wave Gen"
  • Set all voltages and currents on your power supply to zero

8) (Optional) Choose Your Own Tunes

IF YOU'RE GOING TO DO THIS, COMPLETELY DISCONNECT THE OSCILLOSCOPE FROM YOUR CIRCUIT BOARD AND TURN OFF THE POWER BEFORE RECONNECTING YOUR TEENSY. YOU MAY ALSO WISH TO UNPLUG YOUR LAPTOP IF YOU HAVE THE BATTERY TO DO SO.

If you want to, we also have a way for you to load your own tunes onto the Teensy. You can use this site to convert a portion of a youtube video to the right format for this lab, which you can download and then reflash to the Teensy!

Then once you've done that, unplug the Teensy from your computer before turning the power back on.


 
Footnotes

1We won't go into too much detail about the method here, but you can take 6.208 and 6.209 if you want to know more, or the Wikipedia page for the technique we talked about here (small-signal analysis) is pretty good, too! (click to return to text)