Author Topic: Switching a PWM output with a transistor  (Read 8283 times)

0 Members and 1 Guest are viewing this topic.

Offline peperTopic starter

  • Contributor
  • Posts: 16
Switching a PWM output with a transistor
« on: February 28, 2010, 01:47:11 pm »
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.
 

Offline peperTopic starter

  • Contributor
  • Posts: 16
Re: Switching a PWM output with a transistor
« Reply #1 on: February 28, 2010, 09:31:17 pm »
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.
 

Offline jimmc

  • Frequent Contributor
  • **
  • Posts: 304
  • Country: gb
Re: Switching a PWM output with a transistor
« Reply #2 on: February 28, 2010, 10:59:55 pm »
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

 

Offline peperTopic starter

  • Contributor
  • Posts: 16
Re: Switching a PWM output with a transistor
« Reply #3 on: March 01, 2010, 10:09:48 am »
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.
 

Offline jimmc

  • Frequent Contributor
  • **
  • Posts: 304
  • Country: gb
Re: Switching a PWM output with a transistor
« Reply #4 on: March 01, 2010, 11:34:56 pm »
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
 

Offline peperTopic starter

  • Contributor
  • Posts: 16
Re: Switching a PWM output with a transistor
« Reply #5 on: March 02, 2010, 09:39:51 am »
Hi Jim,

No, you haven't confused me too much - I confused myself more :)  I added the diode to a quick sketch I had on a scrap of paper, which didn't include the base resistor.  Yes, obviously with the base resistor, the control current will be limited.

As a side note, how important is it to understand the physics behind a transistor?  Nearly all the tutorials I've found start with a fairly detailed explanation of the physics and every time I try to read through it, my eyes start to glaze over and the information just won't go in.  I understand transistors in general (small current on here causes a larger current here) but can't help feeling that if nearly every tutorial starts with the physics, it must be important.

I wonder whether it's a similar situation in software - you can write a program in C without having to know the underlying assembler (or more importantly the underlying principles of how exactly any given line is actually going to be implemented), but having an idea of how something is going to be implemented can lead to better decisions higher up (and I don't mean you need to know *exactly* which platform-specific assembler instructions the compiler will generate, rather, for example, which constructs are more efficient).

Richard.

p.s. It's just occurred to me that since the 'high' output of the microcontroller is actually Vdd-0.7, I shouldn't actually have any problems anyway.  The maximum reverse bias would be 4.3v not 5v.
 

GeekGirl

  • Guest
Re: Switching a PWM output with a transistor
« Reply #6 on: March 02, 2010, 11:10:16 am »

As a side note, how important is it to understand the physics behind a transistor?  Nearly all the tutorials I've found start with a fairly detailed explanation of the physics and every time I try to read through it, my eyes start to glaze over and the information just won't go in.  I understand transistors in general (small current on here causes a larger current here) but can't help feeling that if nearly every tutorial starts with the physics, it must be important.

Knowing the actual process of how a device works is a great idea. Even as an apprentice electronics technician you are taught electron theory and conventional current, then into semiconductors, where you get to put the current theories into practice. I feel very strongly in knowledge, BUT having said that, if all you want to do is knock up something for home, you can get by with less in depth knowledge, but if it is for production then you need more in depth knowledge so that you can properly calculate values, so that you can then feel confident that every device will roll off the production line and work, without having to worry about component tolerances.

p.s. It's just occurred to me that since the 'high' output of the microcontroller is actually Vdd-0.7, I shouldn't actually have any problems anyway.  The maximum reverse bias would be 4.3v not 5v.

You are making assumptions ;) (which engineering is all about, just you need to know the right ones to make)

Due to temperature the voltage drop will vary in the micro controller, also due to temperature the voltage out of your regulator will vary (as well as current drawn through out the device etc) so you may find it is putting out 5.3V....... When designing a circuit, you need to calculate the extremes (Vin say 4.5 - 5.5V, internal drop of 0.6-0.8V, base resistor +/- say 5% (if you are using 5% resistors) etc)

These days a lot of people use simulators to quicken these calculations, some old timers (like me ;) do them all by hand as it is quick to do on a scrap of paper (or an excel spread sheet).
 

Offline peperTopic starter

  • Contributor
  • Posts: 16
Re: Switching a PWM output with a transistor
« Reply #7 on: March 02, 2010, 01:54:10 pm »
Hi Kat,

Yep, as I thought :)  I've written loads of stuff in assembler for various processors.  I don't do much these days (it's not needed where I work and I've done enough that I don't need to do it as a hobby!) but it's given me a good understanding of how a processor works (at a code level).  It's not necessary - there are plenty of developers who have never written anything in assembler - but at least for my part, I find it helps me write more robust code and debug problems more quickly.

I guess I'm just going to have to grit my teeth and force the physics into my head :)  I get a sense of pride knowing I've written code that doesn't die a horrible death as soon as something slightly out of the ordinary comes along.  I want to be able to do the same in hardware :)

Richard.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf