LED PWM from an atmega32

Discussion in 'The Projects Forum' started by MrSmoke, Jun 23, 2012.

  1. MrSmoke

    Thread Starter New Member

    Jun 23, 2012
    6
    0
    Hey all,
    im building a small circuit with an ATmega32a to control a 1amp 12v LED with PWM. This is my current circuit:

    [​IMG]

    Does it look ok? I added the capacitor from the BC547 base to ground since i was getting a little bit of voltage though the emitter when the micro-controller was off, making the LED slightly dim instead of off. Should I be doing that?

    The circuit does work fine, just want to make sure it wont die soon or if there's a better way to do it.

    Cheers
     
  2. wayneh

    Expert

    Sep 9, 2010
    12,094
    3,033
    You could eliminate the 5V supply if you supplied Q2 with 12v also.

    I believe C1 is taking some noise to ground for you. Reducing R1 would probably eliminate the noise also, unless it's coming from the ATmega.

    Oh, I see you have the noise only when the ATmega is off. You could consider a 1M resistor or such to replace C1, to act as a pull-down when the controller is off.
     
  3. MrSmoke

    Thread Starter New Member

    Jun 23, 2012
    6
    0
    are there any benefits of using a cap vs a resistor?

    Im only using 5v into the first transistor because when im writing the code for the microcontroller, everything is being run off 5v (from usb, not using the high current LED's yet)
     
  4. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    A resistor from the base of the TIP31 to ground would aid in turning off the LED drive transistor. A 10K would do the trick, I think.

    hgmjr
     
  5. Wendy

    Moderator

    Mar 24, 2008
    20,765
    2,535
  6. wayneh

    Expert

    Sep 9, 2010
    12,094
    3,033
    Using a pulldown resistor to turn off the output when a signal is absent is a standard approach, something you should always have in your mind and look for ways to apply. Your cap may be working in this case, and that's fine, but it's specific to pulling down very high frequency noise. Any low frequency or DC float would still be there. A resistor will pull everything down. Be sure to note Bill's comment above. If not, bye bye LED
     
  7. MrSmoke

    Thread Starter New Member

    Jun 23, 2012
    6
    0
    I replaced C1 with a 1M resistor but now the LED lights up when it should be off. Put C1 back in, LED is now off
     
  8. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Are you sure that the ATMEGA output being used to drive the transistor is configured as an output?

    hgmjr
     
  9. MrSmoke

    Thread Starter New Member

    Jun 23, 2012
    6
    0
    Code ( (Unknown Language)):
    1.     tccr1a |= 1<<wgm11 | 1<<com1a1 | 1<<com1b1;
    2.     tccr1b |= 1<<wgm12 | 1<<wgm13 | 1<<cs10;
    3.     tccr2 = (0<<foc2)|(1<<wgm21)|(1<<wgm20)|(1<<com21)|(0<<com20)|(0<<cs20)|(1<<cs21)|(0<<cs22);
    4.  
    5.     icr1 = 255;
     
  10. wayneh

    Expert

    Sep 9, 2010
    12,094
    3,033
    Something's wrong. Are the two grounds really the same? And I assume the LED goes off if the ATmega is disconnected (with the 1M resistor still in place)?
     
  11. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    It would help to have a schematic posted.

    hgmjr
     
  12. MrSmoke

    Thread Starter New Member

    Jun 23, 2012
    6
    0
    Ground is the same one all off the USB programmer. Also still the same result if I use a different power source.

    If i remove the connection from the atmega pin the LED turns off.

    When the pin should be off, its reading 0.22v at the atmega pin. At the BC547 base pin its reading 0.09v with the 1M ohm resistor in.
     
  13. wayneh

    Expert

    Sep 9, 2010
    12,094
    3,033
    Hmmm, maybe you need to pull down the ATmega output directly, not after the 100k resistor. Try moving the 1M to the other side of the 100K.
     
  14. MrSmoke

    Thread Starter New Member

    Jun 23, 2012
    6
    0
    No difference :/
     
  15. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    You can attach the full schematic and the source code here.

    hgmjr
     
Loading...