CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

electronic switch using PIC

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
maddy
Guest







electronic switch using PIC
PostPosted: Sun Dec 01, 2002 5:22 am     Reply with quote

Hi,
I am planning to use a transistor (say 2N2222) as a switch that can be turned ON and OFF using the control signal 'high or low' by feeding a I/0 pin of PIC to the base of the transistor. I have grounded the emitter and connected the collector to the supply voltage.

Now if i turn ON the transistor, all the supply voltage goes to ground and if i turn OFF the transistor, the supply voltage passes to the next stage. This works good in theory.

But when implemented, i got a fluctuation in the supply voltage when the transistor was OFF..and more fluctuation when the transistor was ON..i don't know why the transistor couldn't behave like a perfect switch connecting the supply voltage to ground when ON and passing it to the next stage when OFF..

I had a 10k resistor connected between the PIC I/0 and the base of the transistor.

Can anyone explain this?

Advance thanks for your views!!!!!!!!!
___________________________
This message was ported from CCS's old forum
Original Post ID: 9647
Jos
Guest







Re: electronic switch using PIC
PostPosted: Sun Dec 01, 2002 8:12 am     Reply with quote

Are you using the transitor as a switch or a amplifier? If you want to use the transistor as a switch you must be sure that the current through the base is high enough! Example:

collector current = 100mA
output PIC I/0 = 5V
Beta (worst case) = 50

base current x beta = collector current
base current = 100mA/50 = 2mA
5 - 0,6 (base voltage) = 4,3V
4,3V / 2mA = 2,15kOhm

In this example the resistor must be 2,15 kOhms or less!!!

I hope this solves your problem.


:=Hi,
:=I am planning to use a transistor (say 2N2222) as a switch that can be turned ON and OFF using the control signal 'high or low' by feeding a I/0 pin of PIC to the base of the transistor. I have grounded the emitter and connected the collector to the supply voltage.
:=
:=Now if i turn ON the transistor, all the supply voltage goes to ground and if i turn OFF the transistor, the supply voltage passes to the next stage. This works good in theory.
:=
:=But when implemented, i got a fluctuation in the supply voltage when the transistor was OFF..and more fluctuation when the transistor was ON..i don't know why the transistor couldn't behave like a perfect switch connecting the supply voltage to ground when ON and passing it to the next stage when OFF..
:=
:=I had a 10k resistor connected between the PIC I/0 and the base of the transistor.
:=
:=Can anyone explain this?
:=
:=Advance thanks for your views!!!!!!!!!
___________________________
This message was ported from CCS's old forum
Original Post ID: 9649
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

Re: electronic switch using PIC
PostPosted: Sun Dec 01, 2002 9:36 am     Reply with quote

If you have connected the emitter to ground and the collector to the supply voltage with no resistor on either side, when you get the transitor to turn on, you will short out your supply voltage and eventually burn up the transitor if your supply can source enough current.


:=Are you using the transitor as a switch or a amplifier? If you want to use the transistor as a switch you must be sure that the current through the base is high enough! Example:
:=
:=collector current = 100mA
:=output PIC I/0 = 5V
:=Beta (worst case) = 50
:=
:=base current x beta = collector current
:=base current = 100mA/50 = 2mA
:=5 - 0,6 (base voltage) = 4,3V
:=4,3V / 2mA = 2,15kOhm
:=
:=In this example the resistor must be 2,15 kOhms or less!!!
:=
:=I hope this solves your problem.
:=
:=
:=:=Hi,
:=:=I am planning to use a transistor (say 2N2222) as a switch that can be turned ON and OFF using the control signal 'high or low' by feeding a I/0 pin of PIC to the base of the transistor. I have grounded the emitter and connected the collector to the supply voltage.
:=:=
:=:=Now if i turn ON the transistor, all the supply voltage goes to ground and if i turn OFF the transistor, the supply voltage passes to the next stage. This works good in theory.
:=:=
:=:=But when implemented, i got a fluctuation in the supply voltage when the transistor was OFF..and more fluctuation when the transistor was ON..i don't know why the transistor couldn't behave like a perfect switch connecting the supply voltage to ground when ON and passing it to the next stage when OFF..
:=:=
:=:=I had a 10k resistor connected between the PIC I/0 and the base of the transistor.
:=:=
:=:=Can anyone explain this?
:=:=
:=:=Advance thanks for your views!!!!!!!!!
___________________________
This message was ported from CCS's old forum
Original Post ID: 9650
maddy
Guest







electronic switch using PIC - can RELAYS be used????
PostPosted: Sun Dec 01, 2002 5:52 pm     Reply with quote

the explanation on transistor as switch was nice!! thank you!

i will try to use your logic. i found out that the beta (worst case) for 2N2222 to be 75 and the collector current in my application ranges from 150 mA to 185 mA..so i should be using approx 2K ohms ..let me check out and discuss further.

can I used reed relay or ultra miniature relays capable of handling upto 500 mA to do the above function??

your comments please!
___________________________
This message was ported from CCS's old forum
Original Post ID: 9664
Dave Yeatman
Guest







Re: electronic switch using PIC - can RELAYS be used????
PostPosted: Sun Dec 01, 2002 7:01 pm     Reply with quote

I use the ULN2003 Darlington gate array. It interfaces 7 outputs directly from the PIC with no resisters and drives up to 50VDC at 500ma. I use it to driver relays, solenoids, lights etc required.
In 16 pin DIP form they are 84 cents each from Digikey. Much cheaper than individual transistors.

Dave
___________________________
This message was ported from CCS's old forum
Original Post ID: 9665
R.J.Hamlett
Guest







Re: electronic switch using PIC - can RELAYS be used????
PostPosted: Mon Dec 02, 2002 3:08 am     Reply with quote

:=the explanation on transistor as switch was nice!! thank you!
:=
:=i will try to use your logic. i found out that the beta (worst case) for 2N2222 to be 75 and the collector current in my application ranges from 150 mA to 185 mA..so i should be using approx 2K ohms ..let me check out and discuss further.
:=
:=can I used reed relay or ultra miniature relays capable of handling upto 500 mA to do the above function??
:=
:=your comments please!
Yes you can use relays, but these bring their own problems (noise, contact bounce etc.). There are a number of solutions:
1) Use a darlington pair. This makes the switching time slightly worse, but gives far higher gain than the single transistor, reducing the problems you have noticed. This is the approach commonly used to actually drive relays.
2) Use a 'solid state relay'. These are normally power MOSFETs, driven by an opto-coupler, and give relatively fast switching, without the bounce problems, with the advantage of isolation (so noise doesn't get back into the PIC), and also allowing operation at high voltage if required. The 'downside', is they tend to be expensive.
3) Consider using a FET. These have the advantage of being a voltage controlled device (rather than a current controlled device like the bipolar transistor). The resistor used to drive the gate, controls the slew rate, rather than the final 'on' behaviour.
Worth adding, that with both the FET, and the transistor, it is worth adding another resistor of a high value (100k say), between the base/gate, and the 0v rail (assuming NPN or N channel devices), to _ensure_ the transistor is switched off before you drive it. Otherwise when the PIC wakes up, when it's pins are all set as inputs, the base/gate will be floating, which can lead to unexpected current being drawn...

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 9671
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group