View previous topic :: View next topic |
Author |
Message |
wordizlife
Joined: 08 Mar 2012 Posts: 38 Location: Canada
|
Transistor Switch or Relay? |
Posted: Tue Apr 17, 2012 11:39 am |
|
|
Hey Guys,
I am designing a circuit that will require a PIC16F877A to comunicate with another pic and the pc through serial communication. I want to be able to control a certain portion of the circuit and be able to cut power to it. I am currently using a 2n3904 as a switch, the base is connected to my microcontroller pin through a 10k resistor and there is a pull down resistor of 100k also. All the negative(ground) connections of that portion of the circuit are connected to the collector of the 2N3904 and the emitter to the circuit ground.
For some reason the transistor is not working, it says it can handle up to 200 ma of current and my circuit is putting out less then 150 ma. Should I be using a relay for this and controlling this relay with the transistor switch?
Thanks
this is my code to initialise the port and set it high.
Code: |
#byte TRISA = 0x85
#byte PORTA = 0x05
#bit A5 = 0x5.5 // User to power secondary circuit
main()
{
TRISA = 0x00; // Set port A as outputs
A5 = 1; // turn secondary circuit on
while(1);
}
|
|
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Tue Apr 17, 2012 12:33 pm |
|
|
For hardware, using a 2N3904 with a 10k base resistor is limiting the current you can deliver. A 1k resistor may improve things a lot. You should be able to go as low as 220 Ohm is you need to. Beware that the 2N3904 may get warm if it is handling high currents for a long time.
My choice for this application would likely be a MOSFET like a 2N7002. It costs a few pennies more but will switch on more completely. A relay may also work but it will likely require a driver transistor between the PIC and the relay.
I am surprised your software is working at all. First you don't need to worry about the TRIS register. The CCS compiler will handle that automatically unless you tell it not to.
The statement a5 = 1: will not set pin A5 high. You should use the BIT_SET() and BIT_CLEAR() functions. _________________ The search for better is endless. Instead simply find very good and get the job done.
Last edited by SherpaDoug on Tue Apr 17, 2012 12:42 pm; edited 1 time in total |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Tue Apr 17, 2012 12:39 pm |
|
|
Quote: |
For some reason the transistor is not working, it says it can handle up to 200 ma of current and my circuit is putting out less then 150 ma. Should I be using a relay for this and controlling this relay with the transistor switch?
|
In what way is it not working?
Does 5V appear at A5 output?
You may have to make port A all digital.
Your drive to the bjt is on the mean side.
What is the guaranteed Hfe for your device?
Your base current is ~0.5mA. Your asking for a Hfe approaching 300.
The quoted Hfe varies with manufacturer and is usually for the most favourable conditions.
I'd reduce both resistors by a factor of 10, or replace the bjt with a MOSFET.
If you go to a relay watch out for inductive fly-back.
Mike |
|
|
wordizlife
Joined: 08 Mar 2012 Posts: 38 Location: Canada
|
|
Posted: Tue Apr 17, 2012 1:02 pm |
|
|
I reduced both resistors by as close to a factor of ten as possible and still no results and yes 5V appears at the output. This is weird because I used this exact configuration not long ago on a similar project and the microcontroller triggered it perfectly fine...
I am not sure how to check my guaranteed Hfe for my device..?
You can check out a picture of the schematic for the circuit, I posted it in another forum since I cannot attach any files here.
http://forum.allaboutcircuits.com/showthread.php?t=68932 |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1354
|
|
Posted: Tue Apr 17, 2012 1:20 pm |
|
|
Most of us don't want to sign up on another forum just to see a picture. Can you not upload it to a image host, like ImageShack and post the link? |
|
|
wordizlife
Joined: 08 Mar 2012 Posts: 38 Location: Canada
|
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Tue Apr 17, 2012 2:33 pm |
|
|
Quote: |
I am not sure how to check my guaranteed Hfe for my device..?
|
The manufacturer's full data sheet for the device you're using SHOULD provide minimum Hfe value for a wide range of collector currents and voltages.
I don't have time to analyse the schematic on the imageshack link.
So you have ~1k0 from A5 to 2N3904 base, 10k across base-emitter and 5V at A5.
Assuming that your 2N3904 is correctly connected you should have ~700mV at the base, the collector should be able to sink 150mA easily.
If it's not working either your 2N3904 is duff or there's a wiring fault.
Mike |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Tue Apr 17, 2012 2:42 pm |
|
|
You need to post it a little larger, and using an image format that doesn't destroy data line data (GIF for example). It is basically impossible to read component values, or even follow what part is really what....
Some odd things though. You talk about a 16F877A, but that is a 40pin device. Nothing on the circuit has this many pins. Then you talk about using pin A5 to drive the transistor, while if this is the 876 (28pin version of the device), the sixth pin down (A5), is connected to A4 and A3 etc...
Best Wishes |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
Manufacturer's data sheet |
Posted: Tue Apr 17, 2012 3:43 pm |
|
|
OK. So I've just checked Fairchild's version of the 2N3904.
Yes maximum current IS quoted as 200mA.
But USEFULL switching current is 100mA!
At 100mA collector current, and 1V Vce, MINIMUM Hfe is only 30!.
At your 150mA load current the gain is falling out of the sky.
It's just possible that you stuffed your device at an early stage when you were not providing enough base current.
Also you've told us very little about the load you're switching.
What is the voltage supplying the load?
Is the load inductive?
Is the load capacitive?
...........
Mike |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue Apr 17, 2012 4:30 pm |
|
|
have you considered using a P-channel power MOSFET as a high side switch and controlling the gate directly from your pic?
if it is 5V you are switching and the PIC is operating at 5v
it is very EZ and really no resistors are required unless you put a safety pull up resistor of about 20K ohms from the gate to +5v prevent a startup
glitch.
simply connect P-fet source to +5v ,, drain to load side.
pull gate DOWN with pic to turn switch ON
very simple VERY hi current capable |
|
|
wordizlife
Joined: 08 Mar 2012 Posts: 38 Location: Canada
|
|
Posted: Tue Apr 17, 2012 5:19 pm |
|
|
The voltage supply is 5V at the resistive load.
I guess I will have no choice to go for a MOSFET. Would you possibly have any schematic examples that you could point out to me? I need to know how to use a mosfet as a switch with a microcontroller.
What P-channel power MOSFET would you recommend for my application? This will be my first time working with MOSFETS.
Here is a link to a clear schematic of what I was attempting to accomplish with the 2n3904.
http://imageshack.us/photo/my-images/801/screenshot20120417at706.png/
EDIT:
I just found this schematic, could i possibly use a 2N7002 N-CHannel mosfet with this circuit?
http://imageshack.us/photo/my-images/10/screenshot20120417at725.png/
What resistiance values would I have to use for Rin and Rgs? |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue Apr 17, 2012 5:36 pm |
|
|
With a clear schematic you need a LOW side switch and it is just as EZ.
A 2n7000 is good for up to 200 ma, 150 ma steady state.
An MTP3055 is good for 10A.
Your example is fine too.
Use 20k to ground
and 100 ohms in series driving the gate from the pic.
The ground shunt resistor keeps it from glitching to the on state during pic power up. |
|
|
wordizlife
Joined: 08 Mar 2012 Posts: 38 Location: Canada
|
|
Posted: Tue Apr 17, 2012 5:50 pm |
|
|
Perfect! Thanks a lot for your help, I will get the components tomorrow and will hope for the best. I'm glad that I don't even have to change my schematics or my PCB at all since the circuit is practically the same. |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Wed Apr 18, 2012 12:41 am |
|
|
SherpaDoug wrote: |
My choice for this application would likely be a MOSFET like a 2N7002. It costs a few pennies more but will switch on more completely. A relay may also work but it will likely require a driver transistor between the PIC and the relay. |
I second the 2N7000/7002 (To-92 vs SOT23-3).
I use 'em all the time.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
languer
Joined: 09 Jan 2004 Posts: 144 Location: USA
|
|
Posted: Wed Apr 18, 2012 1:02 am |
|
|
In addition to the 2N7000 (2N7002), you could also try the SS8050. With a 100-ohm or 200-ohm in series with gate or base. |
|
|
|