This man doesn't need Nomex undies - he's on the right track, but a little circuit revision wouldn't hurt :-). Reading the following min-tutorial will be useful to those who really want to understand what's going on here (now I'll need Nomex undies :-)) This is a simple subject but legitimately misunderstood. There are some subtle things to catch you out (eg how many people expect LED voltage drops of around 2 volts?). The LED current/voltage table will probably be scrambled by email mix&match and may need to be pasted into you favourite word processor and realigned if you have any interest. This should reward any beginner wanting to see what really happens here. >From: Michael J. Ghormley ORIGINAL PROBLEM: *************************** >Skybyte wrote: >> SIGNAL from PIC--> 1k --> LED --> LED in opto opto comparable with cny17. >> opto: collector 1k to 13.8V >> emitter: to Base of DB139 >> BD139: C = 13.8V >> E = Relay >> B = emitter of opto. >> >> When the PIC signal is '1', the relay does nothing. >> I tried this before with a simple BC547b (same scheme as the above but a >> bc547 in stead of bd139), it worked fine but this type of transistor can't >> provide enough current for the stepper motor. A relay on it, however, works >> fine. >> Why doesn't this work with a BD139? > PONDERINGS: ****************** >It is probably a Beta problem. The BD139 probably has a much lower Beta than the >BC547 is my guess. Beta = current gain of transistor ~ ratio of collector current that can flow for a given amount of base current. This is probably the "main" problem - provided that you have got the BD139 pinout correct. If you swap C & E in error it will still work as a transistor but with VERY low beta. >Here's my ideas FWIW: > >1) Try replacing the 1K resistor in series with the LED of the opto-iso with a 220 >ohm. The 1K was giving you about 3.3mA of current, a 220 ohm will pump that up to >around 15mA. In practice, the situation is worse than this. The average LED will probably drop around 1.7 to over 2 volts for currents from 1 to 10 milliamps. The opto will probably drop 1.0 to 1.3 volts. Combined this is a voltage drop of 1.7 + 1.1 = 2.8 volts. With a 5.0 volt PIC supply this leaves 2.2 volts to drop across the resistor. With 1K you get about 2.2ma With 330r you get about 7ma With 220r you get about 9+ ma This will depend on the LED used. Here are some measurements using. R older style red LED Y older style Yellow LED G older style Green LED BR newer "high intensity" red LED O Opto coupler i I haven't specified actual types - this is indicative. ii I have staed voltages to 0.01 volt accuracy to show subtle but real differences. This does not mean to suggest that readings to this accuracy are generally useful in this application Method: Place all components in series from supply to ground in this order (any order will do :-) 1K resistor, R LED, Y LED, G LED, BR LED, Opto LED. Adjust supply voltage to supply desired current. Measure LED drops plus overall supply voltage. Readings in order are Ima VR VY VR VG VBR VO Vsupply 0.01ma 1.69 1.58 1.71 1.49 .85 7.31 ie - at 10uA you need 7.3 volts just to wake up The best LED needs 1.5v! 0.1ma 1.75 1.65 1.77 1.57 .94 7.77 not much change at 100uA 1 1.84 1.78 1.87 1.66 1.05 9.5 2 1.87 1.82 1.89 1.67 1.07 10.45 4 1.92 1.90 1.94 1.71 1.09 12.8 6 1.95 1.94 1.97 1.73 1.10 14.6 8 2.00 2.00 2.01 1.75 1.12 17.1 2 volts across some LEDs !!! 10 2.02 2.02 2.04 1.76 1.13 18.9 To work out what R you need for a given current for a given string of components. - Choose line starting with desired current. - Add Vs fro desired components. - Subtract total from PIC supply V (eg 5V) - Divide this voltage by current to give Resistor in Kohm (R = V/I) eg 6ma Bright RED LED plus Opto Vbr = 1.73 Vo = 1.10 sum = 2.83 say 2.8 5-2.8 = 2.2v R = 2.8 / 6ma = 0.46 Kohn = 460 ohm Use, say, 390 ohm to be safe. In practice PIC output voltage will drop as load current increases. Look at PIC data sheets to see by how much. Use this figure for available voltage rather than 5 volts. NOTE - From the above it can be sen that, using a 3 volt supply a PIC could only just drive the opto plus a series LED - the result would be ill defined. A better method to the above , if an external indication of drive on is required, is to drive the LED in PARALLEL with the opto WITH ITS OWN RESISTOR. As may be seen from the above, if the LED is placed in hard parallel with the LED, the LED will not light all. s may be deduced from the above table, here are some results using just a series resistor, a LED and an Opto all in series (as in the original example). 10ma with iK series R: 10ma Vbr=1/77 Vopto=1.13 Vsupply=13v Rser=1K Obviously beyond a PIC! 5 volt supply with variable series R: 2ma Vbr=1.67 Vopto=1.06 Vsupply=5volt Rser=1K 7.2ma Vbr = 1.74 Vo = 1.13 Vsupply = 5v Rseries = 330r 9.5ma Vbr = 1.76 Vo = 1.13 Vsupply = 5V Rseries = 220r Which is the original arrangement with 1K, 330r and 220r resistors. > At 3.3mA you might not be driving the optp's T into saturation. It's not so much a matter of saturation (probably) as CTR ("current transfer ratio"). (similar to beta but for quite different reasons. An opto will allow a given amount of output current per unit of input current. This ratio varies with design. A CTR of say 0.5 menas that for say 1ma input it will give 0.5ma output subject to various other specified conditions. For a LED to photo-transistor type opto the CTR is usually around 0.5 to 1 but may be much less and will not be much more unless specially designed otherwise. Some optos have darlington outputs with CTRs of >>1. >2) Placing the 1K resistor between the C of the opto and +V isn't the best idea. >The C of a transistor is (more or less) a current source. If you want to limit the >current through the opto's T, place the 1K between the E of the opto and the B of >the power T. Actually, the power transistor can't tell where the resistor is in this case - either position will have the same result . >3) Place the relay between the C of the power T and +V, as has been discussed in >the other relay problem. This is good advice and makes a major change to what the circuit is doing but in this case shouldn't make toop much difference to the result. With the load in the emmitter the circuit is an "emitter follower" and the relat drive voltage will be about 0.6 to 1 volt less than the voltage at the bottom (emitter) of the opto output. The circuit has current gain (the beta of the output transistor) but essentially unity voltage gain. Placing the load in the collector gives the circuit voltage gain (about 500) (I hear the experts mumbling). The difference is small as we are driving the "amplifier" hard on or hard off so the transistor "tries" to swing rail to rail and can now saturate if there is enough drive current through the opto. Which is the next important point. The BD139 has a "current gain"/"beta" of between 40 and 150 depending on current (mainly), voltage and manufacturing spread. Say 40 to be safe. If we use the original 1K series resistor, a series LD and an opto we will get about 2.2ma INTO the opto's LED. Assume a CTR of 0.5 (look up the data sheet to see what it really is for your opto). This gives us 1.1ma, say 1ma output. The BD139 worst case has a beta of 40 so 40*1ma = 40ma. Your relay can have most of the supply voltage dropped across it PROVIDED that it needs less than 40ma (eg >= 3K coil). If the coild is less than 3000 ohms the transistor will refuse to provide the more than 40ma required and will come out of saturation. It won't die as 40ma x 13v odd is about 1/2 a watt. A small transistor with higher beta will possibly switch the relay if it needs marginally more than this. If you use a 220r in the original circuit you will/should get 9ma into the opto, 4.5ma out and 180ma BD139 output. All these figures will vary in practice subject to actual specs. Hope all this helps towards a better underatsnding of whats really happening. In this sort of simple but puzzling circuit, a bit of time with a volt meter and milliameter and a variable power supply (or changing resistors) will give you a good idea of what's really happening. The 1.5v+ drop across the seried LED can be quite an eye opener. Unless cost and spece was at a real premium it would be wise not to do it this way (see above for alternative) so that you have better control over the opto current. regards Russell McMahon