# Transistors and MCUs (LaunchPad)

Discussion in 'General Electronics Chat' started by jproject, Jun 9, 2011.

1. ### jproject Thread Starter New Member

May 12, 2011
17
0
Hello everyone,

I am currently using the MSP430 and I'm trying to get a transistor attached to one of the pins to act as a switch. The switch is to activate a motor with a battery attached to it along with the transistor in series. The pin that will be attached to the base of the transistor will provide around 60 mA to 66 mA when activated by the microcontroller and back to 0 mA when stopped. I'm assuming I'll be needing a NPN bipolar transistor. I've only read up on the basics of the transistor so a specific model number of the transistor would be great.

Thank you!

2. ### SgtWookie Expert

Jul 17, 2007
22,194
1,761
You didn't say how much current the motor requires; that will determine what kind of transistor or MOSFET that you will need.

Are you running on 5v?

Are you certain about the I/O capabilities of the uC's pin? 60mA sounds rather high. Many uC's are limited to 20-25mA source/sink current; you want to stay below the maximum rating.

But generally, the 2N2222/PN2222 transistor is pretty popular in the States; they're available at any Radio Shack store in the 15 NPN transistor assortment (you usually get five of them in the assortment). They're good for up to about 500mA collector current as a practical limit. But, in order to sink that much current, you need to feed 1/10th that much current to the base of the transistor. The 1/10th figure is a standard amount of current for operating a transistor in the saturated region ("saturated" means more base current won't make the transistor conduct any better; Vce is as low as it will go).

You calculate the base resistor (Rb) as:
Rb = (Vin - Vbe) / (Ic / 10)
where:
Vin = the voltage on the opposite side of the base resistor from the transistor; if you're using 5v for your uC supply, then use 5v.
Vbe = typically 0.7v
Ic = desired collector current
So, if you need 300mA collector current, then:
Rb = (5v - 0.7v) / (300mA/10)
Rb = 4.3 / 0.03
Rb = 143 Ohms

Here is a table of standard resistance values:
http://www.logwell.com/tech/components/resistor_values.html
Use the green columns.
The closest values are 130 and 150 Ohms.
4.3v/150 Ohms = 28.6mA, which is better than 95% of what is needed. However, you would need to make certain that your uC can source that much current without getting too close to maximum ratings.

Last edited: Jun 9, 2011
3. ### Potato Pudding Well-Known Member

Jun 11, 2010
684
92
I believe that current output is a main limiting condition of the MSP430.

I believe they are only good for about 1mA per pin.

A small darlington transistor will provide plenty of gain so that 1mA of drive would allow running a small motor or to clamp the base drive of higher power transistor off or otherwise control another transistor if your 60mA is meant to drive a larger transistor that runs a big motor.

4. ### jproject Thread Starter New Member

May 12, 2011
17
0
Thanks for the replies!

Yes, I have measured the current using my multimeter and the motor will actually be for a set of tracked wheels (trying to build a very small mobile tank).

5. ### Potato Pudding Well-Known Member

Jun 11, 2010
684
92
A 2N6426 should do fine for 9Volt 60 MA switching.

Collector of the Darlington connects to the motor, and the Emitter to Ground.

A 3.3k resistor between the Darlington Transistor's base pin and the signal pin of the MSP430.

With the flat side of the TO-92 facing you pins 1-2-3 from left to right are Emitter Base Collector for the ON Semiconductor version if you check the datasheet I linked to before.

If you use anything else including a 2N6426 from another make, please try to check the data sheet to make certain it is the same.

6. ### jproject Thread Starter New Member

May 12, 2011
17
0
The motor will be powered by 2 AA batteries in series so 3V and the base will have to switch ON the circuit with 66 mA. So, 2N6426 will work fine?

EDIT:

I Just realized I need to split the source into 2 (meaning it will be 33mA instead of 66mA) because I need to move it forward and backward. Here is a quick circuit I drew (sorry if it sucks but I did not learn how to properly draw circuits yet other than voltage/current sources and resistances along with capacitors). The P1.4 and P1.5 will provide the currents from the MCU (not at the same time of course). When one of them is providing amps, the other will not. This will allow the motor to go forward and backward right?

Please do tell if there are any mistakes and as always, thank you!

Link to Photo:

http://imageshack.us/photo/my-images/834/circuith.jpg/

Last edited: Jun 10, 2011
7. ### Potato Pudding Well-Known Member

Jun 11, 2010
684
92
That Darlington will work for two of the transistors.

Collector to motor is the way to go for your bridge so that the topside transistors would need to be PNP types. That means you have to cross wire the base drives.

There is some confusion about the base current.

The control current goes through the base of the transistor. A control current of even half a mA will be more than enough to allow your transistors to switch every milliAmp that you can get out of 2 AA batteries. AA are only good for around 100mA continuous. You might draw 1 amp from them for something like a digital camera but that is a short draw to charge the flash. Even then, those high currents will cut the available mAmp hours to around 20% of rated capacity.

You would never get much more than a milliamp from the pins of an MSP430.

You need 2 PNP and 2 NPN darlington transistors. You should be able to use just about anything of these types you find, and only need TO-92 types or SMD styles.

Here is a simple version of the circuit you need. Remember that the PNP and NPN work different from each other so that the signals that will turn them on and off are reversed. You don't want to tie the two bases together that need the same signal because with PNP and NPN that creates a short circuit. Use separate pins of the MSP430 to drive each of the 4 transistors, even though Aa and AA are the same signal form, and Bb and BB are also the same signal form as each other but the opposite phase of the Aa/AA signals.

I did not add it here because I wanted to keep the drawing simple but make certain you have a Ceramic capacitor wired across the motor terminals.

jproject likes this.
8. ### jproject Thread Starter New Member

May 12, 2011
17
0
I just checked again with my multimeter and it's giving me 47 mA. I must've been really hyped off coffee when I was measuring it before.

This is what I'm doing. I programmed the pin to output (P1.7) and I made sure that it was outputting by testing with an LED. The P1.7 pin is connected to the LED and the LED is connected to the ground of the LaunchPad and surely enough, it lights up. I remove the LED and use my multimeter to measure the current for 10 seconds and it gives me a steady 47mA.

EDIT: Alright I found it... It says here in theory, I could connect the LED or any other load directly to the pin but it is NOT recommended since max output should be below 12 mA. But it also says it should not exceed 48 mA? K I'm going to read this over.

Here is where I got the info:

http://processors.wiki.ti.com/index.php/MSP430_LaunchPad_Drive_LED

EDIT2: I just realized... I found my transistor that I need to buy from this link! LOL

Just wondering, what is the difference between PN2369 and PN2369a? Looks like they are the same from the datasheet.
Also, will this be able to handle around 220 mA when I connect it to the motor and the 2 AA batteries in series?

Last edited: Jun 11, 2011
9. ### Potato Pudding Well-Known Member

Jun 11, 2010
684
92
Edit: Correction. I thought that the outputs were rated at 1 or 2 milliAmps but page 19 of the data sheet says they are good for 6milliAmps. Another rating that does specify 2milliAmp was where I misread.

Yes I have seen that project article before.

Have you looked at the MPS430 datasheet?

So if you say that you ran 47mA current through yours at pin 1.7, I would be very suspicious of the reliability you can expect from that chip in the future. I don't know if there is a failsafe built into the chip but this makes me wonder.

The chips are easy to replace in the Launchpad and only cost about \$2 so no big deal.

The PN2369 is rated for only 200mA according to the datasheets.

I suggested darlingtons for two reasons. They will easily saturate and switch even with the low drive from the MSP430.

NPN
http://www.fairchildsemi.com/ds/2N/2N6426.pdf
PNP
http://www.fairchildsemi.com/ds/MP/MPSA63.pdf

Last edited: Jun 11, 2011
jproject likes this.
10. ### jproject Thread Starter New Member

May 12, 2011
17
0
Haha, I can't believe I missed the max current value but then again I didn't sleep for over 22 hours now. Well, thank you for everything! Off to the store I go to buy some stuff.

Oh yes, btw, so I'm assuming I'll be needing a good 1.5k to 2k ohm resistor for a 12 mA output but how can I control the output amp of the pin? It seems like mine likes to stay at 47 mA and I do not feel like frying my MCU.

Last edited: Jun 11, 2011
11. ### Potato Pudding Well-Known Member

Jun 11, 2010
684
92
3.3kOhms was what I recommend.

You don't need much drive for the Darlingtons.

12. ### Potato Pudding Well-Known Member

Jun 11, 2010
684
92
I would have been better off sleeping too.

I forgot the second reason that I was suggesting the Darlingtons.

They will handle over an Amp of current.

13. ### jproject Thread Starter New Member

May 12, 2011
17
0
So I'm just wondering about your circuit. How come I can't just use 2 pins (one for both Aa/AA and one for both Bb/BB) instead of using 4 pins for each transistor? If I output for both Aa/AA and ground Bb/BB or vise versa, it seems like it would work fine.

14. ### Potato Pudding Well-Known Member

Jun 11, 2010
684
92
You need to isolate those transistor's bases from each other.

What happens if you tie those bases together to use a single pin for signalling?

The transistors line up their base emitter junctions like two diodes between the power rail and ground so that they bias each other, which locks them in an on state and makes the transistors into a short circuit instead of a bridge.

Last edited: Jun 12, 2011
15. ### Potato Pudding Well-Known Member

Jun 11, 2010
684
92
Well, like 4 diodes between the power rail and ground when they are darlingtons.

Beware of unintended bias paths.

It should be nothing to code turning on another pin on the microcontroller so use the micro and you only need two more resistors.

16. ### jproject Thread Starter New Member

May 12, 2011
17
0
Alright... I decided to order the transistors online from digikey meaning I have to wait a bit for them to come after the weekends =(

But, while that's happening, I've been reading up a bit on transistors and I'm wondering if these transistors have diodes in them. I never knew DC motors had inductors that can increase the voltage enough to damage the components. Will my 1.5-3V motors require diodes if the transistors don't have them?

EDIT: Alright! it moves! and the h bridge works. I did your first suggestion and decided to try out using 2 pins for one motor instead of 4 and it also works well! I thought the transistors would burn up or something but it was very cool and no problems for over 3 minutes of running.

Now, would it be a bad idea to use a 9V battery for my motor which originally used 3V?
This is the exact motor I am using atm:

http://www.earthshineelectronics.com/46-101-large/3v-dc-motor.jpg

Last edited: Jun 15, 2011
17. ### Potato Pudding Well-Known Member

Jun 11, 2010
684
92
Regarding 9V. Would you mind if the motor was toasted? Or do you have a replacement motor? Also keep in mind that you need to convert the drive signals from the Launchpad. 3V drive won't switch a 9V bridge directly.

I doubt 9V will really hurt the motor but I can't tell from a small picture.

For the motor noise and back emf.
You want a .1uF ceramic disc capacitor across the motor terminals to absorb spiking.
You would do well to put in parallel bridge of reverse bias clamping diodes.

I am not surprised that it seems to work to use only 2 pins instead of 4 from the microcontroller. 3Volts only leaves a little room between the bases for the resistor drop and shorting will close that up. It will actually be a half short circuit which for AA batteries is not very spectacular. The batteries will just go dead.

While the circuit is live and signal on the microcontroller should be able to override that natural bias so that it all works well.

A couple more pins to control the other bases is still what I recommend.

18. ### SgtWookie Expert

Jul 17, 2007
22,194
1,761
Gosh, I hate to rain on the parade at such a late date, but Darlington transistors just won't work very well with the low supply voltage.

The reason for that is the relatively high Vce (voltage on the collector referenced to the emitter when in saturation) for the Darlingtons; even under a light load you'll get about 0.7v per transistor. As the load increases, so will the Vce. So, if you have one PNP and one NPN darlington in the motors' current path, you will have a maximum of 3v-2*0.7v = 3v-1.4v = 1.6v across the motor; you'll lose about half of your supply voltage even with a light load. That's just not going to work very well at all.

What one might do instead is to use two discrete BJTs per "leg" of the H-bridge, one acting as an emitter follower to amplify the current to the base of the 2nd transistor, and the 2nd transistor used as a saturated switch. That way, the saturation voltage of the 2nd transistor of the pair can be quite low.

I can't draw a schematic now as I'm on a public computer at the moment.

However, rather than using 8 transistors for an H-bridge, have a look at Steve Bolts' H-bridge here:
http://library.solarbotics.net/circuits/driver_4varHbridge.html
The 74HC14 is a hex inverting Schmitt trigger. Its' inputs will present a high impedance to your uC's outputs, but will drive the transistors with enough current to keep the transistors pretty well saturated for up to ~300mA load.
Datasheet for the NXP 74HC14: http://www.nxp.com/documents/data_sheet/74HC_HCT14.pdf
Use 2N2907's for the PNP's and 2N2222's for the NPN's - don't use the 2N3904 or 2N3906 as they will limit you to around 100mA. PN2907 and PN2222's are plastic packaged counterparts for the metal-packaged 2N parts; they will work just fine.

Last edited: Jun 15, 2011
19. ### Potato Pudding Well-Known Member

Jun 11, 2010
684
92
The 0.7x2 Volts is seen on the base but typically the Collector Emitter Voltage will drop near enough to nothing with a common emitter circuit. Typical voltages I have seen collector to emitter are 0.06 to 0.5 Volts.

You do need to take the 0.7x2 Volts into account if the circuit used is an Emitter Follower.

EDIT: Now I am not sure. I might be thinking of Darlingtons with an internal resistor. Darlingtons (basic types) are Emitter followers for the top driver of the pair. EDIT2: Looking at the Data Sheets for the transistors I suggested I see that they both look like they will be very bad choices. Sarge is exactly right that they will steal all the voltage. My apologies and thank you Sarge for catching my mistake.

The Darlingtons might not be needed compared to regular BJT but they should help unload the MSP430.
Even better would be some logic level MOSFETS.

Edit2: Use the NPN Darlingtons to translate and you could drive some Mosfets and use a 9Volt or more power source. Yes I am trying to save the parts that I was suggesting and make them useful again. They could still be used for providing the MSP430 with a light pin load.

The Hysteresis locked circuit so that you only need two pins would be as easily done with two pins of the Launchpad for this purpose. You are relying on the drive signal to lock one of the transistors in the off state. I would say that using 4 pins has some added possibilities and not all of those possibilities are good, but some are.

The worst case scenario which would be impossible with only two pins in use is to send drive signals to both of one sides transistors causing smoke.

Adding the logic gate as an intermediary would be an idea of how to run with 9V power in which case the launchpad is the brains and a transistor driving a CMOS gate would drive the bridge transistors.

Last edited: Jun 15, 2011
20. ### SgtWookie Expert

Jul 17, 2007
22,194
1,761
Did you look at the Vce(sat) specifications for the 2N6426 Darlington?
With Ic=50mA, Ib=0.5mA, it's 1.2v max. I'll assert that around Ic=50mA, it'll be around 0.7v or slightly more.
With Ic=500mA, Ib=0.5mA, it's 1.5v max.

Take a look at the Vce(sat) curves for the MPSA63 shown in figure 2, page 2 of the datasheet you linked to. Vce(sat) starts at ~0.7v @ 25°C @ Ic=1mA; at Ic=100mA, Vce >0.8v, and it increases from there.

The big reason for this, is that the collectors for the Darlington pair are connected together. As the output transistor's Vce drops near 0.7v, there is no more collector current available for the input transistor, as there are two be junctions between the input transistor's base and the output transistors' emitter; basically two forward-biased diodes in series.

That's if both the upper and lower transistors are NPN's. You have PNP's on top and NPN's on the bottom.

Actually, with emitter followers, you have a minimum 1.3v dropout even at very low current; since you have two be junctions to contend with. The bjt 555 timer output (pin 3) has a Darlington emitter follower on its' output that does the same thing.

If the MSP430 is limited to 1mA source or sink current, that's not enough to saturate a typical standard transistor if Ic exceeds 10mA.

Now you're talking. However, with only 3v available, you would need some ultra-low threshold MOSFETs; and most of those are in tiny SMT packages that are very difficult for hobbyists to work with.

As long as 2 pins will source/sink enough current to turn the lower side OFF while the upper side gets turned ON, and vice versa, that will be enough.

If 4 pins are used, there are more possibilities to goof up in programming and have the high and low transistors on one half of the H-bridge on simultaneously - until smoke occurs.

If the uC cannot go high enough or low enough to turn one transistor OFF while the other is being turned ON, there will be shoot-through and smoke.

A level translator would be required if the uC is running at 3v and the motor at a different voltage. Just a standard logic gate would not cut the mustard.