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.
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 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.
(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).
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
- P2.1 goes into In1 of the MOSFET driver (U8, LTC1156) and G1 (the corresponding output) goes to the gate of Q1. So setting P2.1 high turns on Q1.
- P2.3 similarly drives Q2,
- P2.2 drives Q3, and
- P2.4 drives Q4.
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.
- Important: Add 8 pin sockets for Q1/Q3 and Q2/Q4. By looking at the layout you can tell where the drain goes because the two pins will be shorted together.If you are unsure whether or not a transistor is functioning, you can test on your blinking board (Lab 1).
- Important: Add a 16 pin IC socket for U8, and then put in the LTC 1156. Polarity is important - check the layout.
- Put a six pin male header for M1.
- Put two pin male headers in for JMOT and J5.
Connections to motor/encoder
Examine the schematic. Note:
- The 6 pin connection for the motor:
- M+ and M- are the connections to the motor.
Important: The black wire from the motor should be connected to M-
- 5V and 0V are connections that power the rotary encoder on the back of the motor.
- The A/B connections go to ports 2.7 and 2.5. Make sure to change P2SEL to make P2.7 an input. The output is open drain/collector so you will need to enable the pullup resistors on P2.5 and 2.7. See note above for rotary encoder.
- The motor is connected in an H-bridge controlled by P2.1, P2.2, P2.3 and P2.4.
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).
__bis_SR_register(GIE); // enable interrupts.