PWM through a transistor

Discussion in 'The Projects Forum' started by KansaiRobot, Apr 30, 2015.

  1. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5
    Hello and thanks always for your help. It is greatly appreciated.

    I would like to ask some questions related to a project I have been given all of a sudden.

    Say I have a LED like the following:
    http://www.aglare.com/pdf/120-piece...SF1210W120_asia-manufacturer-and-supplier.pdf

    As you can see it is powered with 12V. If you connect each terminal to a 12V battery it lights up, no need of resistors.
    I have to regulate the brightness with a PIC so I am planning on doing the following:

    schemeit-LED1.png

    I dont know yet the value of R1 and if R2 is necessary at all.
    I have already written a program that uses the PWM module of a PIC. It works without problems. Say you connect a LED (and a resistor) to the CCP1 port, you can regulate the brightness of that LED.

    Do this PWM signal pass through a transistor so as to regulate the brightness of the big LED???

    ------------------------------------------------------------------------------------

    Also related with this, any comments on the above circuit. In the past I worked with a valve of 12V that has EMF (?) so I was afraid to mix the voltages. I tried to separate them using a opto isolator as you can see in the following schematic

    valve.png

    my question is, now with this 12V LED, is this all necessary? I dont think the valve presents a problem so I took of the optoisolator and the diodes, and just plan to use a transistor (now which transistor I dont know...) Do you see a problem in this??

    Thanks always very much for the help
     
  2. #12

    Expert

    Nov 30, 2010
    16,270
    6,786
    First drawing: R2 is not necessary. I would tell you what size R1 is, but you did not tell the PIC voltage. Try 220 ohms if you have a 5 volt supply. Use a 2N3904 transistor.

    Second drawing, D1 and D2 are not necessary. Everything else should work.
     
  3. pwdixon

    Member

    Oct 11, 2012
    488
    56
    Would D1 not be required to limit the turn off spike from the coil?
     
  4. Søren

    Senior Member

    Sep 2, 2006
    472
    28
    A 2N3904 won't cut it - it's a strip light of unknown length.

    What coil?
     
    KansaiRobot likes this.
  5. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,802
    832
    The load is "a valve that has EMF (?)". This needs to be clarified; it sounds like a solenoid valve, but it is not described sufficiently to tell. @KansaiRobot ?
     
  6. AnalogKid

    Distinguished Member

    Aug 1, 2013
    4,530
    1,248
    For the second question, no. You do not need optical isolation of the LED from the PIC. And LED is not inductive and does not kick up the voltage spikes that a motor or solenoid valve can. To choose the transistor, determine the current through the LED at 12 V. Use a transistor with a continuous collector current rating that is at least twice the LED value. Also, the transistor Vce should be at least 30 V. If the PIC is running on 5V, you have the option of using a logic-level MOSFET instead of a bipolar transistor. This might be more efficient, and need a smaller heatsink (or no heatsink at all depending on the environment around the transistor).

    ak
     
  7. #12

    Expert

    Nov 30, 2010
    16,270
    6,786
    I thought he just bought a lot of LEDS. Didn't look at the pdf.:oops:
     
  8. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5
    Thanks everybody for the replies. they are greatly appreciated

    Yes, it was a solenoid valve. That is why I used optoisolators (I was afraid of the spikes) and diodes.
    But in this case as it is written below, it is only a chain of LEDs that use 12V. I am thinking this does not kick up spikes so I need only a transitor in place. and no diodes at all. am I right?


    That is one of my problems... I was given this strip light (the length is known but is that important?) but no datasheet at all. I searched in the internet and only could find the pdf I put in the first post. I think it is that one. I know it uses 12V but not how much current. Reading that datasheet it says 20 mA?? not really sure.

    Why the Vce should be 30V??

    I was thinking that if I have the current necessary thorugh the LEDs that is the current collector emiter so with that I can calculate the current in the base (using beta of the transistor) and with that I can determine R1 since the voltage in the PIC pin is 5V.

    Now the original question was: if I have a PWM signal in the base, will I get a PWM signal in the collector?? (ergo in the LEDs) to regulate the brightness??

    Thanks a lot for any advice
     
  9. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Getting back to the first circuit I disagree with R2 not being necessary. It is R1 that is unnecessary. That way it forms a basic constant current sink.

    The current flowing into the LED is simple (V(RC2) – Vbe) / R2. So if your device is outputting a nominal 5V and the transistor has a typical B-E drop of .7V and your brightest LED current is 10mA you would need a 430 ohm resistor.

    Do note that both Q1 and R2 share the burden of burning off excessive voltage (the difference between 12V and what the LED is actually using) as heat.

    I have done this exact curcuit in a commercial LED dimmer product where the LED intensity needed to match an incandescent bulb over a wide (10-28V) range.
     
  10. AnalogKid

    Distinguished Member

    Aug 1, 2013
    4,530
    1,248
    R2 is unnecessary because the LEDs already are current-limited. The strip should be driven by a constant-voltage device like a switched NPN as in the first schematic. R1 is necessary to limit the base current. However, it looks like the required current will be greater than a PIC can provide, so you might need a power darlington transistor.

    For long-term reliability, transistors should not be run at more than 50% of their ratings.

    For best performance, a power transistor in this type of application should have a base current that is approx. 10% of the collector current. For example, a strip of 100 LEDs would require 2 A of collector current, or about 200 mA of base current. A PIC can not supply this. An alternative is a power darlington transistor with a minimum gain of 1000. Now you need a base current that is only 1% of the collector current, or 10 mA.

    Yes, a PWM signal on the base will show up as a PWM signal at the collector.

    Page three is very clear about how to determine how much current you need to supply. It is 20 mA *per LED*, no matter how many LEDs there are. The length is VERY important. Count the LEDs and multiply.

    ak
     
    KansaiRobot likes this.
  11. #12

    Expert

    Nov 30, 2010
    16,270
    6,786
    Sorry about the flub.
    I thought TS was calling a transistor a valve, like the Brits call vacuum tubes, and the valve isn't labeled in the drawing. Note to self: Don't post in public after a 21 hour day. :oops:
     
  12. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5
    Thank you very much for your reply. Excuse me to ask this but which part of page 3? I looked and couldnt find it. However my supervisor suggested the same.
    Now, I have 18 LEDs (with what I think are 6 resistors) so I guess I need 20mA x 18 = 360mA

    How much current can a PIC supply?
    EDIT: I read 20 mA is the max

    EDIT: Mine! now I ve realized this is not the datasheet of the thing I have... cause here I have 3 LEDs per 5cm and the datasheet has 6LEDs per 5 cm.

    Btw, you mentioned that in page 3 it says 20 mA per LED, where? reading the datasheet I read in page 1 720mA/m and each meter has 120 pieces so I guess each LED should use only 6mA, am I wrong???

    EDIT:
    One question though. If I need 12 V to pass through my LED, does that mean that the VCE should be near 0? (saturated transistor) . Because if not and if VCE is different than 0 that means that the maximum voltage passing through the LED would be less right??? Already confused :confused:
     
    Last edited: Apr 30, 2015
  13. AnalogKid

    Distinguished Member

    Aug 1, 2013
    4,530
    1,248
    "Up to 1600 mA" plus "From 40 to 80 sections" = 1600 / 80 = 20 mA per LED
    "Up to 3200 mA" plus "From 80 to 160 sections" = 3200 / 160 = 20 mA per LED

    Count the LEDs.

    ak
     
    KansaiRobot likes this.
  14. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5
    Thank you very much. :)

    I didnt understand the 50% ratings thing. Sorry.

    About the rest, I understand, you are talking about the current gain β right? for example 10% of the collector current would give a β of 10. Now a 1% would give a β of 100, not 1000, no???

    Anyway, for my problem, I have 18 LEDs (I counted them! :) ) so I will need Ic= 360 mA.
    So Ib= 360mA/β

    so for a transistor with β=100 I would need 3.6 mA which I think is quite possible for a PIC

    however for a transistor with β= 10 I would need 36mA which surpasses the limits of the PIC.

    Is my analysis correct??

    -------------------
    Also my voltage drop Base -emitter would be 0.7V so the voltage drop across R1 would be 5V-0.7V= 4.3 V
    Now all I need is to calculate the R1 with Ohm's law being careful not to surpass the current limits of the PIC (20mA I think???)
     
  15. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5
    continuing with the analysis above I ve come to the conclusion that I need a β of at least > 18 to ensure that the PIC can provide the current.

    Looking for transistors that can do this I found only the 2N2222, which has Ic of 800 mA and a current gain between 30~100 (I dont understand why β is different , in my book it says it was constant... :( )

    I looked for other transistors 2N3904, 2SC1815, C237, BC372 and A1015 and no one satisfy the requirements. The BC372 seemed near
    http://pdf.datasheetcatalog.com/datasheet/motorola/BC372.pdf

    but the current gain is only 8 or 10 I read. ( I dont understand why there are Mins and Maxs for these values either)

    Any comment or advice will be greatly appreciated
     
  16. pwdixon

    Member

    Oct 11, 2012
    488
    56
    As you have already discarded the emitter resistor if you swap out the NPN for a MOSFET you don't need to worry about the base resistor and there are loads of high current devices around that will easily satisfy this requirement and they are cheap.
     
  17. Søren

    Senior Member

    Sep 2, 2006
    472
    28
    Usually it's per 3 serially connected LEDs - have been in all the LED strings I've worked with.
    12V to each 3 LEDs (plus resistor).


    So 18 LEDs will take 120mA in my book and a BC337 would be a good choice. ~2.5mA to the base (you need to saturate the transistor to get the C-E drop low).
    (5-0.7)/0.0025 = ~1k8 and that's the base resistor, no further resistors needed.

    I thought it was a long string, a couple of meters at least and in that case, I'd have suggested a MOSFET like this
    https://www.sparkfun.com/products/10213
    with a gate resistor of 22..47 Ohm.
     
    KansaiRobot likes this.
  18. AnalogKid

    Distinguished Member

    Aug 1, 2013
    4,530
    1,248
    I wondered why the datasheet said "per section" instead of "per LED". Makes sense at 12 V; you get more bang for your mA's and lower resistor power. I yield to Soren.

    ak
     
  19. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5
    I thought I had all figure it out, but now with the answers in other thread I m more confused...

    Do I need my transistor to be in saturation??

    Do I need another resistor to ground??

    Will PWM work here(be trasmitted to the lamp)?

    Today I will study-again- my textbook on transistors.. I hope I can understand it this time :oops:
     
  20. Søren

    Senior Member

    Sep 2, 2006
    472
    28
    Hi,

    You don't need the transistor to be in saturation, but it gives the lowest voltage drop (and hence the transistor has to dissipate less power as heat). An argument against driving it into saturation is, that it will be slower to switch (and hence has to dissipate some power as heat in its linear region), but with a lower voltage drop when on.

    Since a suitable PWM frequency will be anything down to a few hundred Hertz, the transition time between ON and OFF will be a very small percentage of the full period and hence the most important is to keep the ON-losses low. An unsaturated transistor will have a higher total loss in your application.

    You don't need a resistor to ground! Neither on the base, nor the emitter, the former is governed by the PIC driving actively both high and low, but it would be another thing if you were to set the pin to input at some time, or have 12V on the LED string while the PIC was powered down - in that case, eg. 4k7 (or whatever) to ground/Vss directly from the base would be a good idea, to keep noise from turning the transistor on.

    A resistor on the emitter will just give a voltage drop = less max. light from the LEDs - the string is built for 12V.

    As you were told already, yes, the transistor will switch the PWM through to your LEDs - Put a transistor in a sim with a 1k8 base resistor. Set a signal generator to eg. 1kHz square wave (5V amplitude) and feed to the other end of the resistor. put 3 white (or blue) LED's and a 82 Ohm resistor from +12V to the collector and let it rip - change the duty cycle to see it replicated on the collector (oh yeah, add a scope to the collector to see it) - Happy studying :)
     
Loading...