Opto Coupler Circuit Help.

Discussion in 'General Electronics Chat' started by rainyday101, May 10, 2010.

  1. rainyday101

    Thread Starter Member

    Sep 24, 2009
    50
    0
    I am building an I/O board for my Arduino controller. The I/O board is flexible to let you use the Arduino I/O as either an input or output via a 4N25 opto coupler. My external I/O are all 24 vdc. The load for an output could vary from 20-350ma. My schematic is posted below. To use the Arduino I/O as an input, the output jumpers are removed and the input jumper is installed. Just the opposite case to use the Arduino I/O as an ouput. Can you look this over and make suggestions or possible corrections. Right now this works on my proto board, but I have a few concerns. My first concern is the base resistor sizing on Q1. I would like approx. 10ma input current to the 4N25 opto. I am not sure I have the sizing right, even though it works. This Base resistor is giving me slightly less than 5 vdc on the base of Q1. My input voltage to pin 1 of the 4N25 opto is 3.8vdc. This I don't understand. Why am I dropping so much of my 24vdc across Q1? Is it not fully on? Any help thoughts or comments would be greatly appreciated.
     
  2. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    You have Q1 wired as an emitter follower. If the Arduino I/O pin is at 5v when high, then the emitter of Q1 will be around 4.3v. R1's value is really only important in case Q1 develops a short from collector to base; then your Arduino will be subjected to 24v. 8.2k will keep the current acceptable. You could go as low as 1k and still be all right.

    Power dissipation in Q1 will be (24v-4.3v)*10mA = 197mW. Package max is 625mW. Consider using a heat sink.
    [eta]
    As an alternative, use a 2k resistor from the collector of Q1 to your 24v input, see (*) below.

    At 10mA, D1 the 1N4148 diode will drop another 0.7v, for 3.6v remaining.
    The 4N25 IR emitter has a nominal Vf of 1.15v @ 10v, leaving 2.45v remaining.
    Therefore, the cathode resistor for the 4N25 should be 2.45/10mA = 245 Ohms instead of 2.2k Ohms.

    However, you also have another input from 24v to D2.
    (*) 24v-4.3v=19.7v; 19.7v/10mA = 1,970 Ohms needed between D2's anode and your 24v in. 2K is the closest standard resistor; that will work fine. Use a 1/2 Watt resistor.


    The 820 Ohm base resistor on the right MPS2222 transistor (which I'll refer to as Q2) will limit the collector current.
    Rb = (Vin-Vbe)/(Ic/10)
    Vbe ~= 0.7v.
    Vin = your Arduino high out; about 5v.
    Ic = desired collector current.
    Vin-Vbe ~= 4.3v
    4.3v/820 Ohms = 5.24mA base current
    Your maximum collector current for saturated operation will be around 52.4mA. Much more than that, and you'll burn up Q2. You might luck out and get up to 100mA before it bursts into flame, but you're only guaranteed to work up to 52.4mA.

    You're limited as to how low you can go with the base resistor. Check your uC's I/O specifications. Keep in mind total package limits, as well.

    You would likely be better off to use power MOSFETs to switch load currents.

    [eta] For your load flywheel diodes, 1N4148/1N914 diodes are fast, but anemic. Consider using larger fast recovery diodes, like FR303's or something similar. You could also use 1N5819 Schottky diodes; they're rated for 1A average @ 40v peak.
     
    Last edited: May 10, 2010
  3. rainyday101

    Thread Starter Member

    Sep 24, 2009
    50
    0
    Thanks Sgt. Wookie

    Would I be better off not using Q1 as a emitter follower? Also can you recommend a MOSFET for switching the load currents. I am going to start trying things now.
     
  4. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    It's fine. If you use a 2k 1/2W resistor between the collector and your 24v supply, you will be peachy-keen hunky-dory. ;)

    IRLD014PBF or IRLD024PBF.
    These are really spiffy 1.7A and 2.5A (respectively) logic-level 60v N-ch power MOSFETs in a 4-pin DIP package.
    Digikey and Mouser stock them, amongst other suppliers.

    Use a 270 Ohm resistor from the gate to your Arduino I/O (close to the gate) and a 10k resistor from the gate to the source terminal.
     
  5. rainyday101

    Thread Starter Member

    Sep 24, 2009
    50
    0
    Back to Q1, what I was originally trying to do was to have both input sources to pin 1 of the 4N25 opto be 24vdc so that the 2.2k resistor on pin 2 would limit the current correctly for both. I did this because my external input will always be 24 vdc and the ouput of the Arduino (input to the 4N25) will be 5vdc. Is this wrong because I have the emitter follower circuit? I am going to brush up on transistor basics, it's been awhile!
     
  6. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    1,015
    69
    You can drive the LED in an opto isolator directly from an I/O pin (with a resistor, of course).

    Normally, the aim of opto-isolated inputs or outputs is to enable connection to systems with completely different power and ground. For that, you can not have any connections in common between the micro side and the I/O side.

    If you have any connections common to both (as the 5V on pin 5 of the opto, used for both input and output), then you have no isolation so the opto part is pointless.

    If you draw your input & output configs seperately to start with, you should be able to draw a line straight up & down through the center of the opto and have no connections crossing that line.
     
  7. rainyday101

    Thread Starter Member

    Sep 24, 2009
    50
    0
    Thank you and I understand that, but I am setting this up to use the same opto to provide isolation either as an input or an output. Isolation is maintained by the input/output jumpers I have shown in the schematic. In one direction the opto isolates the 24 vdc from the arduino input, and in the other configuration the opto isolates the 5vdc output of the arduino to my 24vdc output devices. I am doing this for the flexibility of being able to use my board for any of the applications I may have.

    Brushing up a bit on transistors, would I be better off having Q1 be a common emitter config.?
     
  8. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Changing Q1 to a common emitter configuration could work.

    See the attached.

    The 620 Ohm resistor on the collector of the 4N25 limits the output to 8mA; safe enough. The 10k resistor makes sure the emitter of the output is not floating.
     
  9. rainyday101

    Thread Starter Member

    Sep 24, 2009
    50
    0
    Thanks Sgt. Wookie, that is what I was trying to figure out and struggling with. I am going to prototype that and test it. My other question is on Q2 the mps2222a on the right of my schematic. I am going to try the mosfet but still am confused about the transistor. It has a CE rating of 600ma. If I saturate the transistor at the base shouldn't I be able to draw any current under the spec, which would be dependent on the load off the collector? I know you said that with the 820 ohm resistor on the base I would be able safely put about 54ma through there, but I have a 300ma load on it and it works fine. I varied the load on this from 20-300ma without a problem. The transistor is not getting hot. I know I need to brush up on my transistor theory a little, but I thought if the transistor was used as a switch, when saturated, the collector to emitter current was load dependent?
     
  10. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Have you been keeping an eye on your Q2's Vce?

    "Saturation" means that a certain base current has been reached where increasing the current through the base does not result in additional current flow through the collector. This is because Vce is as low as it can get.

    Saturation current for that transistor is defined in the datasheet as Ib=Ic/10. Out of a random batch of 1000 transistors, 100% of them will work using the forced beta of 10. If you don't use the forced beta of 10, you would find that the less base current you supplied, the more failures per 1000 you would have. In a production environment, you want as few failures as possible.

    Now, you could use a Darlington configuration. However, that would mean you would have a Vce of 0.7v to perhaps 1.2v

    You could increase base current by lowering the base resistor. However, your Arduino can only source so much current before it starts getting "that warm feeling" - which is not good.

    There's another option - since you have 5v available, rather than using a Darlington or MOSFET, you could use an emitter follower to source current to the base of Q2.

    Have a look at the attached. The plot is a comparison of the transistor power dissipation between the two configurations. The green trace (your Q2) is showing about twice the power dissipation as the yellow trace (Q3). This is with ideal 2N2222 transistors.
     
  11. rainyday101

    Thread Starter Member

    Sep 24, 2009
    50
    0
    Thanks Sgt., in the current configuration I have with the 820 ohm base resistor and 300ma load my Vce is .34. The 5v supplied to the base of Q2 is from a 5vdc power supply and not the arduino so current to the base should not be a problem; therefore I am looking at lowering the base resistor value. Calculated as follows:

    Ib=Ic/Hfe(min)
    =.400 (400ma)/40
    =10ma
    Ib x 2 (safety factor to ensure turn on)
    =20ma

    Rb=V/Ib
    = (5-.7)/20ma
    =4.3/.020
    =215 or a 220 ohm resistor.

    I am getting my specs off of the Motorola MPS2222A spec sheet. I have looked at the circuit you attached but need to keep this as simple/yet effective as possible because I have to replicate this circuit at least 24 times on the board I am going to make. This why I am using each opto to be configureable via jumpers to be either used for the input to the arduino ro the output from. This way I do not need 48 optos!

    When I did the above with a 220 ohm base resistor I get a Vce of .197 vdc with the 300ma load.

    Whats your opinion on this?
     
  12. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    You will have to carefully read the specifications on your Arduino, and it's current source/sink limitations per pin and for the entire package.

    For example, a given uC might have a limit of 20mA source/sink per I/O pin, and a 100mA limit per package. If you have five I/O pins sourcing/sinking 20mA each, that is the limit the uC can provide without burning up.

    You are better off if you can minimize the I/O current that the uC has to sink or source.

    Also, at higher Ib, you will find that Vbe will increase significantly. With Ic=150mA, Ib=15mA, Vbe may be as high as 1.3v.

    If you want to save on board space, consider using ULN2803 IC's. Eight Darlington channels with built-in diodes. Practical current limit is 350mA per output.

    If you want higher sink current, consider something like a ULN2068; 1.5A per channel, 4 channels. You will need to use a copper pour area on the board to keep them cool.
     
  13. rainyday101

    Thread Starter Member

    Sep 24, 2009
    50
    0
    Thanks, I am just finishing up the input side to the opto you suggested earlier to test. I will take a look at the current capabilities of the arduino,(actually this is Sanquino). I am going to take a look at the suggested output IC. I think with a 350ma limit that would be fine. The only way I can approach that current is if a 24vdc contactor coil is connected to the output, them I'm at 300ma.
     
  14. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Keep in mind that even the ULN2803 has package power dissipation limits, too.

    It's rated for 500mA sink current, but the practical limit is 350mA. After that, power dissipation gets to be too high. There's more to it than that.

    Have a look at this graph:

    [​IMG]

    Note that if you are using all 8 outputs at 100% duty cycle with the IC held at 50°C, maximum safe current per channel is about 180mA.

    Wide traces (as wide as you can make 'em) on your PCB will help a great deal to dissipate the heat. Orienting the PCB vertical during operation will help even more, as air convection will improve quite a bit. If you are planning on putting the board in an enclosure, make certain that there is plenty of room and air holes for good ventilation, or provide fans for cooling.
     
  15. rainyday101

    Thread Starter Member

    Sep 24, 2009
    50
    0
    Thanks, I am gonna have to put the thinking cap on and work through the current ratings. The input circuit for the 4N25 you suggested works like a top in both LTspice and on the proto board. I have a lot of things to consider here before I finalize anything. It's not as easy of a task as one first thinks, but if it were easy everyone would do it! You sure gave a lot of insight into things that I overlooked and hadn't considered. Most of all I learned/refereshed a lot of info by looking things up, trying things, and doing the math. I am working on doing more test on this circuit and trying to consider all things to make this layout bullet proof. I am sure I will be asking more questions as get further along. Thanks for the help!
     
  16. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    The more time you spend up-front in considering ALL of the implications, the fewer problems you will have with the end design. You may very well miss a few things at the end, and wind up having to cut traces and splice other stuff in. It's not pretty when that happens, but hopefully you learn to not repeat such mistakes.

    Everything is a compromise; cost, space, performance, etc. You may have to go through a number of permutations before you arrive at a sound conclusion.

    Simulations are good to get to a starting place for testing. The more complete the simulation model, the more closely the results will resemble the finished circuit.

    Trouble is, most people don't include all of the parasitics - and those will "get you" particularly in high speed circuits.

    Forgetting about power dissipation will result in smoking/flaming blobs of plastic populating your board.

    You can get power dissipation plots in LTSpice. During the simulation, hold down the ALT key while hovering over a part, and you will see a thermometer. Left-click, and a plot will appear showing the power dissipation.

    If you then Ctrl+Leftclick on the formula for the plot, you will get the average, RMS, and joules.
     
Loading...