E72 Lab 6

Motor control

The laboratory this time requires significant design time, but the write-up is fairly minimal.

Your task  is to design the electronics for a simple device that tracks a light source.

Your strategy for controlling the motor will be simple on-off (or bang-bang)  control -- you will turn the motor in one direction, or the other, at full speed to try to equalize the light falling on the two photo-sensors.   

The rest of this lab handout is devoted to discussing the new devices that you will be using, and giving you some hints on how to proceed. However, the design will be entirely your own.

Link to schematic. Link to Layout.

New devices:

The rotary encoder

A rotary encoder puts out a "quadrature" signal as it rotates (this just means two signals that are 90 degrees out of phase with each other).  You can read about them here (the article even includes some MSP430 code that can help set up and react to the interrupts - but the given code has some flaws).  By my observations, there are two cycles of A and B per shaft revolution; you may want to double check. 

The A/B connections go to ports 2.7 and 2.5.  Make sure to change P2SEL to make P2.7 an input and a GPIO (P2SEL.7 must be set to 0 (note: there seems to be an error in the data sheet which has P2SEL.7 as a don't care for GPIO)).  The output is open drain/collector so you will need to enable the pullup resistors on P2.5 and 2.7.

The motor

The motor is a Cytron SPG30-60k gearhead motor with a 60-1 reduction between the motor shaft (where the encoder is connected) and the output shaft.


N-Channel MOSFET
(w/ flyback diode)

In this lab you will be using N-Channel MOSFETs (Metal Oxide Semiconductor Field Effect Transistors) to drive the motor.

There are several things to notice about these devices. The most important is that there are three terminals: the gate (the input, D), the source (source of charge carriers, S) and the drain (drains charge carriers, D). The voltage between the gate and source determine whether the transistor is on or off.  In the n-channel device when the gate voltage is sufficiently greater than the source voltage the resistance between source and drain becomes small, allowing current to flow between them (for large gate-source voltage this resistance can be very small). There is a diode between the source and drain on these devices, which is important when switching inductive loads (because you can't stop current flow rapidly without a large change in voltage -- the diode prevents this large, and potentially damaging, voltage). We won't worry about the diode, and if you hook up your circuit properly you won't really notice it is there. Subsequent circuit drawings won't include the diode. They are manufactured by Vishay Semiconducto.

For the devices that we will be using the resistance between the drain and source is much less than 1 ohm when the gate voltage is at least 2 to 4 volts above the source voltage for the n-channel device, and the gate voltage is at least 2 to 4 volts below the source voltage for the p-channel device. We will use an IRFD024 (NMOS) that can only handle a little about 2 amps (plenty for our needs).  The pinout for these is shown.

Be very careful when replacing the transistors that they go in the proper drawers.  Double check the numbers.  (You should probably double check them when you remove them from the drawers as well.)

Though these transistors can handle considerable power when in a circuit, they are static sensitive and can be destroyed by being improperly handled. When handling them always ground yourself first (either on the oscilloscope ground, or on the metal case surrounding the outlet box). 


The H-Bridge

To control the motor you will be using a circuit configuration called an H-bridge (it physically looks like the letter H). To get current to flow from left to right through the motor you turn Q1 on (set is gate voltage high) and turn Q4 on (set its gate voltage high). You must make sure that Q2 and Q3 are off (their gates are at a low voltage, i.e., ground).  If either Q2 or Q3 is on there is a direct path for current to go to ground, and something will blow (hopefully the fuse in the power supply). 

To make current flow in the opposite direction (and make the motor turn in the opposite direction) make P1 low, N1 high, P2 high and N2 low. The potential for disaster arises in this case because if you drive P2 low and N1 high simultaneously you have a direct connection between 12 volts and ground, and something will go (hopefully the fuse on your board). 

To turn the motor off simply turn of all 4 transistors (gates set to ground) and the motor will coast.   If you turn Q3 and Q4 on and Q1 and Q2 off (or vice versa), the back emf of the motor will force current through it dissipating electrical power, and the motor will slow more quickly.

The MOSFET Driver

Turning on Q3 and Q4 is relatively easy. You may be able to turn them on with the MSP430, so 3.3 Volts may not be enough to fully turn the device on. However, turning Q1 and Q2 is more problematic. If Q1 is on, we want the left side of the motor to be effectively connected to the 10V source - but that requires that the gate of Q1 be several volts above 10 Volts. This presents a difficulty if the highest voltage available to the circuit is the 10V source. For this purpose we use a high-side MOSFET driver. From a 10V source it can output a signal that is close to 20V. More than enought to fully turn on the high side MOSFET (Q1 and Q2) as well as the low-side MOSFETS (Q3 and Q4).

f you look at the schematic diagram (page 2), you can see the circuit below


Add to your circuit board

Link to schematic. Link to layout.

If you have any questions about any of these connections, please ask.  If you put in an incorrect part, it will be very hard to fix later.

Connections to motor/encoder

Examine the schematic.  Note:

The Lab (Read this thoroughly before starting)

Important:  The black wire from the motor should be connected to M- on the PCB.

Design a system that turns the motor to an angle dictated by the potentiometer (as potentiometer turns, so does motor - you can use code from last week to read the pot).  Keep track of the angle using an interrupt routine using the shaft encoder output as an interrupt source (you should be able to calculate the angle from the count without needing to do an empirical calibration).  (Note: I goofed the design a bit, the potentiometer is on the same pin as the pushbutton on the LaunchPad (P1.3) so you can't use both - If you need both, I can show you a relatively easy fix.)

Demonstrate the finished design for me.

Turn in well documented code.  You may turn in a separate document that helps with documentation if you find that useful.

The task can probably be accomplished using bang-bang control (turning the motor fully on in one direction or the other to turn it).  If you want to get fancy, you can use PWM (between 10 and 20 kHz) to control motor speed (see previous lab).

Some hints: