Motor Control

The questions below are due on Friday October 25, 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 as another opportunity to get some experience working with op-amps, in particular running them in negative feedback (instead of in positive feedback like we saw last week).

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?

Set the power supply voltage back to 0 before continuing on.

Check Yourself 2:
Set the power supply back to 0, then start slowly clicking the voltage up until the motor starts to turn. What is the minimum voltage required for it to start to turn?

Then speed it up a little bit before slowly clicking the voltage back down. At what voltage does the motor stop turning?

It's likely that you'll get two different numbers for those results; why would they be different?

Turn off the power supply when you're done with this experiment.

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.

Leave the Teensy plugged in (it'll derive power from the USB connection), and then 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).

PCB Workshop People

If you're doing the extra PCB workshop stuff, feel free to use your PCB version of the DAC here (we have some alligator clips you can use to grab on to the test points to hook them up to a breadboard). After you've put it on the scope for a little while, change the DAC_RESOLUTION variable from 6 to 8, then reflash the code and see what happens; you should get a much smoother curve after making that change (those extra 2 bits mean we get 256 discrete voltage levels instead of 64).

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). Go ahead and plug a motor in so that v_{\rm DAC} is dropping across it.

Check Yourself 3:
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 4:
Why doesn't the motor turn? How does this relate to what we've seen in labs in the last few weeks?

Check Yourself 5:
From those measurements, can you approximate the effective resistance of the motor? You can also measure it with a meter and compare.

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, as we've seen in lecture/recitation recently, we do have ways to modularize our circuits, using our recent new best friends, op-amps. As we've seen throughout the class over the past week, we can model an op-amp, as a voltage-controlled voltage source, which, among other things, has the effect of isolating parts of a circuit from each other:

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).

As we've seen in class, we can accomplish this using operational amplifiers, and there are a bunch of ways we can hook them up to perform different operations. We're going to start today by using our op-amp as buffer that isolates our DAC from the motor. For today, we'll use our same L272AM op-amp from last week; as a reminder, it's 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). NOTE that depending on the way your breadboard is oriented, the red and blue rails might be swapped from what is shown in the picture; but pin 2 of the L272 should go to the red rail, and pin 4 to the blue.

    The op-amp package has a marker that indicates which side of the op-amp is pin 1. Some of the L272's have a little dot right on pin 1; some have a little groove in the center of the pin 1 side of the board; and some have both. But regardless of what kind of indicator your op-amp package has, it'll always be on the side with pin 1.

  • 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 in any way?

  • 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 They're big and chunky, but don't worry about that; they're just normal capacitors, just with a slightly weird form factor.

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 6:
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 7:
It might be pretty wimpy for now, but your motor should turn. If not, talk with a staff member.

Check Yourself 8:
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 (and pretty fast). You should do this uing only the single 20V channel we've already set up on the power supply.

We're going to leave the design of the circuit largely up to you (but feel free to ask for help if you get stuck!). By the time of the checkoff, we're going to expect to see both a working circuit and a schematic drawing of that circuit.

We shouldn't need to design a whole new circuit completely from scratch here; it should be possible to make this happen with some small changes / additions to the circuit we built in the last section.

As you're thinking about your design, think back to our experiments from earlier in the lab. In particular:

  • How did the voltage drop across the motor affect the speed/direction of its rotation?
  • As v_{\rm DAC} moved through its pattern in this last experiment, how did the voltage at the output of the op-amp change? What are the minimum and maximum possible voltages at the output of the op-amp?
  • How does the voltage at the output of the op-amp relate to the drop across the motor with how things are currently hooked up?
  • What are the minimum and maximum possible voltage drops across the motor with how things are currently hooked up? What would need to be true about the minimum and maximum drops across the motor in order to get it to turn both ways?

We're more than happy to help, but please do try to give it a good think on your own before asking us over.

Checkoff 3:

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

When you are done, clean up by:

  • putting your DAC back wherever you stored it before
  • taking the little "flag" off of your motor and returning your motor to the front of the room
  • returning the op-amp to the front of the room
  • throwing away any spare resistors / clipped wires not related to your DAC
  • 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)