| Electronics > Beginners |
| Switching a PWM output with a transistor |
| (1/2) > >> |
| peper:
Hi, My problem is transistor-related but first some background: I'm designing a 'relatively' simple microcontroller circuit. I want to be able vary the brightness of a couple of LEDs but also to be able to turn either LED on or off independently. As I only have one PWM output available on the microcontroller, I'm using that as a common-anode and the cathode of each LED is connected to a separate output pin. This works fine on the breadboard (minor problem with the total amount of current available through the microcontroller pins but that's a different problem). My problem is that at one of the LEDs will be on a separate daughterboard with other components and I don't want to have to have two signals going to the daughterboard just to light one LED. For one thing (most important reason), I would need 1 pin more than I have on the connector and for another I want to be able to disable the whole daughterboard electronically if a second daughtboard is connected. I could do that fairly easily by just turning off Vdd (assuming the LED signal but if I have two separate signals for the LED, I'd have to turn off Vdd for the other components and then one of the LED signals. Ok, so my problem is how to use the LED control pin (that's connected to the cathode on the LED) to work as a trigger to let the PWM signal through? This is what I came up with originally: But on reflection, I don't think that's going to work because whenever the PWM pin is low and the PWM_CONTROL pin is high, the base voltage will 5v higher than the emitter, which as I understand it will probably fry the PNP transistor (this is presumably the base-emitter voltage specified in the data sheets isn't it?). I thought about using an NPN transistor instead but I think I'd hit other problems with that. The LED is only on momentarily so I could really do with a 'normally off' solution to avoid drawing current to keep the LED off. What's the best solution here? The theoretical behaviour of my original idea would be perfect so I'd love to find a way to get the behaviour without releasing any magic smoke. Would a logic-level FET be any better? I'm a software engineer by trade and that doesn't faze me, but although I'm enjoying learning, electronics still confuses the heck out of me at times (unfortunately I've still not mastered the art of reading and thoroughly understanding datasheets). Any help would be greatly appeciated! Richard. |
| peper:
Replying to myself... Sometimes I suppose it just takes a while until you get a 'duh' moment. With a common anode configuration, basically what I want to do is to get a a 'high' output when the PWM signal is high *and* the output should be enabled. So I actually want an AND gate (and change the PWM control output to be active high instead of active low). However, since I said I want to be able to turn off the Vdd supply to the daughterboard, the LED signal should be sinking current rather than sourcing it, so I should use a NAND gate. Something like a 74HC00 has a maximum quiescent current of 2uA at normal temperatures so that looks ideal (quiescent current for the 74HCT series is also low but still a little higher but may be easier to interface to the microcontroller - another area to research :) ) An alternative would be to invert the lot and use a common cathode configuration and an OR gate, which I think could be done with a couple of diodes but I'd still have the problem of the microcontroller not being able to sink enough current, so the first solution seems to be better. Anyone have any better ideas? Richard. |
| jimmc:
Your first idea is OK, almost all general purpose PNP transistors will stand 5v reverse bias B-E. Look for VEBO in the data sheet. If you are really worried about it either 1/ connect a diode anode to base of Q1 cathode to emitter Q1 to clamp the reverse voltage to 0.7v or 2/ connect a diode between 'PWM' and emitter of Q1, reverse voltage blocked by diode. 1/ loses no drive voltage, 2/ loses 0.7v but there's still plenty left from 5v drive. Almost any small signal diode will be suitable. eg 1N4148 Jim |
| peper:
Hi Jim, Thanks for the reply. According to the datasheet of the transistor I was looking to use (BC558), it has an absolute maximum of 5v reverse bias, which was why I was wary of driving it to that level since it will spend most of its time like that (I only enable the PWM output when necessary so it'll spend most of the time shut off, and even if it is turned on, I think the duty cycle will usually be below 50% so it'll still spend most of the time low). I just had a look at the datasheets of some of the other transistors I have to hand and they all have the same maximum. I certainly understand solution number 2. I sort of get solution number 1 but won't that cause a large(ish) current flow in the 'off' state (i.e. PWM pin low, Control pin high)? The microcontroller will limit the total current but it will still be drawing a fair bit. Or have I understood that wrong? Richard. |
| jimmc:
Hi Richard, The 'off' control current in option 1/ will be the same as the 'on' current (5v -0.7v)/R1 Your not going to need more than a couple of hundred uA to turn Q1 hard on so the currents involved are quite small. Option 2/ will work just as well but you now have the VF of the diode forward voltage, the VCEsat of Q1 and the VBE of Q2 all subtracting from the voltage across R3. (approximately 5v - 0.7v - 0.2v - 0.7v = 3.4v) As I said still plenty left with 5v drive but would be difficult to tolerance if you were to reduce the drive to say 2v. Practically the the reverse B-E breakdown of a transistor is not catastrophic, the junction behaves as a Zener diode. There is some degradation in noise performance and small drop in current gain; neither of which would affect your circuit significantly. (It's not like the gate breakdown of a FET which is fatal.) I hope I haven't confused you. Straight answer is... use a diode in the emitter (2/) if you want to be ultra cautious, but your original circuit will work well. Jim |
| Navigation |
| Message Index |
| Next page |