Motor Control

The questions below are due on Friday March 08, 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.

A few weeks ago, we built a 6-bit digital-to-analog converter (DAC), which demonstrated a powerful capability of electronic circuits as interfaces between computation and the physical world. In this lab, we'll explore that idea further, using our DAC to control a motor.

We're also going to use this lab as a first practical exposure to operational amplifiers ("op-amps" for short).

Scope Setup

Depending on the scope's current state, things may or may not be well-set-up for this lab. So before we build anything, let's go ahead and turn on the scope (we'll need it later) and reset it to all of its defaults by:

  • Pushing the "Default Setup" button in the upper left, and
  • Under the "Wave Gen" menu (accessible by pushing the button in the bottom right), click the "Settings" button (the bottom one on the screen), then click the "Default Wave Gen" button (the bottom one again) You should get a message on screen saying that things have been reset.

1) Drivin' Through the Night

Before we get to using our DAC to control the motor, let's experiment with the motor itself a little bit. For this part of the lab, we'll again use the benchtop power supply. As a reminder, it looks like this:

Yours may not have connectors coming out of it; if it doesn't, you can unplug the red and black cables from your multimeter and put them in the left-most two plugs (labeled "CH1," make sure you put the red and black in the right places).

When you turn on the supply, 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 "On/Off" button under "CH1" turns that channel on and off (it will be lit up in green when the channel is on).

Here's the experiment we'd like to try:

  • Grab a motor and a breadboard from the cart. If your motor doesn't already have one, use some masking tape to make a little "flag" on the end of the motor so that we'll be able to see how it's moving more easily, something like this:

  • Push the big power button on the bottom left of the power supply to turn it on.

  • Make sure channel 1 is off (the little "on/off" button under CH1 should not be lit up).

  • Click the little "V" button on the right and use the knob to adjust the voltage to 0V (yes, zero).

  • Click the little "A" button on the right and use the knob to adjust the current to 1A (this is a safety measure; it limits the amount of current we can draw from the supply).

  • Connect the two clips from the supply to the two wires from the motor (you could connect them directly, but it might be better to use the breadboard).

  • Click the "On/Off" button to turn on the supply.

  • While it is on, adjust the voltage between 0V and 20V.

Check Yourself 1:
How does the motor's speed relate to voltage? What happens if you flip the leads on the motor?

Turn off the power supply when you're done.

2) DAC to the Future

Now that we've understood something about how the motor works, we're going to combine it with our DAC to be able to control the speed of the motor programmatically. Grab your DAC circuit from before, and download the code from motor_control.zip and flash it to your Teensy.

Hook the output port v_{\rm DAC} up to your oscilloscope and look at the voltage on the output. You should see the voltage change over time (though you may need to zoom in/out on one or both axes to get a good view of it).

Which of the following best describes the shape of the output waveform?

Using the cursors on the scope (or reading directly, but without using the Measure tools), what is the maximum value of the voltage? Enter your answer below, in units of Volts.

Using the cursors on the scope (or reading directly, but without using the Measure tools), what is the frequency of the wave? Enter your answer below, in units of Hz (1/seconds).

3) Current Events

Next, we'd like to hook up our motor so that we can control it using the output from our DAC (hopefully getting a variety of different speeds).

Check Yourself 2:
Huh? The motor isn't turning, even though the voltage should definitely have been sufficient given our earlier calculations/measurements. What is going on?

With your scope still set to measure v_{\rm DAC}, try connecting and disconnecting the motor. What happens?

Check Yourself 3:
Why doesn't the motor turn? How does this relate to what we've seen in labs in the last few weeks?

4) Buffer: The Ampere Slayer

Now let's see what we can do about the problem we noticed in the last section. We've got a nice voltage that we made using our DAC, but as soon as we hook something up to it (the speaker over the past few weeks, the motor this week), the voltage changes dramatically! In this way, circuits are not modular; adding or removing a single component can affect the voltages and currents throughout the circuit. This can make design quite hard; our design depends on knowing exactly what we're connecting to, and if they change (from the speaker to the motor, for example), we might need to change our circuit. It seems like progress would be impossible...

But luckily, we do have ways to modularize our circuits. As we have seen in lecture, one key way we can do this is using devices that act as dependent sources: they measure a value somewhere in the circuit (without changing it much) and set a value elsewhere in the circuit based on that value. An example we've seen throughout the class over the past week is an operational amplifier, which we can model as a voltage-controlled voltage source:

This kind of separation is really nice; it allows us to measure and use values from a circuit we've built without affecting that value too much, which allows us to think more easily about circuits as being comprised of modules (for example, we might like to think about our DAC as a module that always creates a predictable set of voltages, and then separately use those voltages to drive a speaker or a motor or something).

Schematically, we will almost never draw out of the whole dependent-source model of an op-amp; throughout the rest of the lab we'll use the following representation instead:

As our first foray here, we're going to use an op-amp to act as a buffer that isolates our DAC from the motor. For today, we'll use an L272AM op-amp, which is packaged so that two op-amps fit in one package, as shown below:

The spacing of the pins is such that the package can be conveniently inserted into the breadboard across the gap in the middle without bending the pins too much, as shown above. Notice that the pins all have distinct meanings, and a dot on the package marks pin 1.

A small "buffer" circuit is shown below. As we have seen in class, there are many different ways to model op-amps; but for today, we will make the ideal op-amp assumption described in class:

  • the currents into / out of the + and - inputs (called the "non-inverting" and "inverting" inputs, respectively) are small enough that they are essentially zero, and

  • the high gain of the op-amp will drive the potentials at the two input terminals to be roughly equal to each other (close enough that we will assume they are the same).

Here is a slightly larger drawing showing how we'll use this idea in today's lab (note that the port labeled v_{\rm DAC} represents the output of your DAC):

Let's go ahead and build it, but let's be careful. Follow these steps:

  • With the power supply off set the power supply voltage to 20V, and leave the current limit at 1A.

  • Connect the 20V supply across one set of red/blue rails (the red lead from the power supply should go to the red rail, and the black lead should go to the blue rail).

  • Connect the red and blue rails up to pins 2 and 4 of the op-amp, respectively, to provide power to the op-amp (this will provide V_{\rm CC} and V_{\rm EE} as discussed in class). You should be able to orient the op-amp so that short wires can be used to make these connections, like so (and we have the little pre-cut wires in the cabinet with the resistors so that you don't need to cut them yourself):

    Pay close attention to the little "dot" on the op-amp package. It marks pin 1, so in order to make sure that your connections are going to 2 and 4, it needs to be oriented correctly (it's in the lower-left corner in the photo above).

  • Connect the Teensy's ground (pin G) to the 20V power supply's ground (the black cable/pin), but for the love of all that is holy, do not connect the +20V (red) side of the power supply to the Teensy anywhere.

Double-check: Is the red side of your 20V power supply connected to the Teensy?

  • With the power still off, wire up the op-amp as shown below, using one of the op-amps in the L272AM package (the pinout for the L272AM has been reproduced here so you don't need to scroll back up). Note that v_{\rm DAC} represents the output of your DAC, and we won't connect anything up to v_o for now (just measure it). You'll need to connect the + and - sides of the power supply to V_{\rm CC} and V_{\rm EE}, respectively, to provide power to the op-amp.

Another Consideration

When connected as a buffer rather than an amplifier, this particular kind of op-amp (L272AM) generates a lot of high-frequency oscillations that won't matter for our application today (turning the motor) but that we would like to ignore. To make those go away for purposes of our analysis, connect a 2.2\mu {\rm F} capacitor between the output pin of the op-amp and ground:

You can grab capacitors from the same cabinet where you get resistors; look for a drawer labeled 2.2uF

We won't include this capacitor in our analysis of the circuit; it will just let us get a clearer view of the output signal we're expecting, without the additional noise from the op-amp on top of it.

These oscillations also mean that the op-amps can get quite hot even when they're operating as expected, so be careful when touching them.

  • If you want a staff member to take a look at your circuit before powering it on, just ask!

  • Once you're confident that everything is wired up correctly, go ahead and turn on channel 1 of the power supply.

Check Yourself 4:
Use your oscilloscope to measure v_o. How does it compare to v_{\rm DAC}?

Does this behave like you would expect, given the way we've hooked up the op-amp here?

Now try hooking up the motor not to v_{\rm DAC}, but between the op-amp's output pin and ground (as shown here, but don't remove the 2.2\mu{\rm F} capacitor; connect the motor in parallel with it):

Check Yourself 5:
It might be pretty wimpy for now, but your motor should turn. If not, talk with a staff member.

Check Yourself 6:
With your oscilloscope measuring v_o, connect and disconnect the motor. How does this voltage change as you do so? Why is this result different from when we did the same experiment earlier with the motor on v_{\rm DAC}? What features of the op-amp cause that difference?

Checkoff 1:

Discuss the results of your experiment so far with a staff member, including:

  • How does the motor's speed relate to the voltage drop across it?
  • Why did the motor not turn when connected directly to v_{\rm DAC}?
  • How does the version with the op-amp "buffer" fix this problem?

5) Mad Gainz

The buffer above lets us use the signal from our DAC to control the speed of the motor; how exciting! But, unfortunately, the motor doesn't turn very fast here, at least not compared to how fast it was going in our experiments near the start of the lab. Let's see what we can do about that.

Consider the following op-amp topology:
Making the ideal op-amp assumption again, we have the same constraints as above:
  • approximately no current flows into or out of the input terminals, and
  • the op-amp will work to set the potentials at the two input pins (labeled + and -) equal to each other.

Let's set the amplifier to have a gain of 10, i.e., so that v_{\rm out} = 10v_{\rm in} under our ideal op-amp assumption. To accomplish this, what values of R_1 and R_2 should you use so that the gain is approximately 10?

You have some freedom of what particular resistances to choose, but we probably want both R_1 and R_2 to be in the 1{\rm k\Omega}-to-100{\rm k\Omega} range. The checker will accept any combination that results in a gain that's off by up to 5% of the desired value.

R_1 =~

R_2 =~

Go ahead and replace the buffer on your breadboard with this topology, using the output from your DAC as v_\text{in} (you may need to construct or approximate those two resistor values, but we want something close to the amplification factor from the question above). The cabinet may not have exactly the resistor values you want; just try to grab some that are close.

Set up your scope to measure v_{\rm DAC} and v_{\rm out}. Use 2V/div for the scales on both channels, and arrange them on the scope so that their reference points (indicated by the little "ground" symbol on the left side) are right on top of each other and near the bottom of the display.

Compare and contrast the two waveforms. What is the same, and what is different? Use the scope to verify that you're getting the amplification factor that we expect.

Try cranking up the gain further, to 20 or 30 or so. What happens to your output? How can we explain this?

Now put the gain back to 10, like it was before, and hook up the motor. It should be turning faster than before!

Checkoff 2:
Show your working motor to a staff member and discuss your design and the results of your experiment.

6) Take It Back Now, Y'all

Now, set your gain back to 10 and, for the rest of the lab, our goal is to make it so that as v_{\rm DAC} moves through its pattern, the motors spins in both directions, with its peak speed in either direction being approximately the same.

We would like to devise a circuit such that, without changing the voltage levels emerging from this op-amp, will turn the motor in either direction. You can do this by connecting one pin of the motor to the amplified DAC output (just like we did before) and the other to a different voltage:

The goal is to make a voltage V_\text{offset} such that when the DAC is outputting its max value, the current will flow in one direction through the motor; but when it is outputting its min value, the current will flow in the other direction. We would like those two speeds to be roughly the same.

Check Yourself 7:
Given these design constraints, what value should V_\text{offset} be?

6.1) Gateway Circuits

Now let's make that voltage. We'll start by building the following familiar circuit using a potentiometer but not connecting it to your motor yet:

Do Not Bend The Pins!

The pot's terminals are spaced out just right so that they fit into the breadboard. Please leave them at that spacing rather than bending the terminals. The pots fit nicely into one side of the breadboard (without jumping the gap in the middle), so plug your pot in on one side of the breadboard and use wires to connect the terminals elsewhere if you want.

Again, we have some little wires in the cabinet under the resistors, which are pre-cut to be just the right length to jump across the gaps in the breadboard. These can be a really useful way to keep things from getting too messy when building these circuits. For example, here is one way we could hook up the pot:

Check Yourself 8:
This circuit generates a branch voltage that is proportional to \alpha. Where is that voltage in the schematic above? Where would it be on the breadboard version?

Hook your scope up to measure that voltage and verify that the voltage is indeed proportional to \alpha.

We would like to use this divider to make the V_\text{offset} value we drew up above (a nonzero voltage on the - side of the motor to allow the motor to spin in both directions). What value of \alpha would produce the desired V_\text{offset} you found above? Turn the knob until you are producing approximately this voltage.

Now, with the scope still connected, hook the wiper up to the other side of the motor (as shown in the schematic above). Unfortunately, the motor does not turn for most (or maybe all) values of \alpha.

To prepare for your checkoff, have channel 1 on your scope measuring the output from your DAC, channel 2 measuring the output from your amplifier, and channel 3 measuring V_{\rm offset}. Set things up so that all three signals are on the same vertical scale and their references are all in the same spot.

Check Yourself 9:
Draw a schematic diagram for the circuit and use it to explain why the motor does not turn when hooked up this way (except when \alpha is at the extreme values). YOU WILL NEED TO BE PREPARED TO DISCUSS THIS DRAWING IN YOUR CHECKOFF.

You should be able to fix this with an op-amp. Go ahead and do that (and feel free to ask for help if you get stuck!), and when you've got your motor able to turn in both directions equally fast, go ahead and ask for the checkoff. NOTE that each L272AM package contains two op-amps, so you shouldn't need to grab a second one.

Checkoff 3:

Show your working motor to a staff member and discuss your design.

When you are done, clean up by:

  • shedding a single tear for the last time we'll use the DAC this semester
    (goodbye and thanks for all the memories, DAC! sob emoji)
  • taking the little "flag" off of your motor and returning your motor to the front of the room
  • returning the potentiometer and op-amp to the front of the room
  • throwing away any spare resistors / clipped wires (including those that were formerly in your DAC)
  • LEAVING YOUR TEENSY IN THE BREADBOARD (seriously, don't try to remove it from the breadboard) and returning it to the labeled bin near the cart at the front of the room
  • turning off your scope, multimeter, and bench power supply
  • otherwise cleaning up and throwing away any garbage that's around (generally being a respectful citizen of the lab)