LED PWM from an atmega32

Thread Starter

MrSmoke

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



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
 

wayneh

Joined Sep 9, 2010
17,498
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.
 

Thread Starter

MrSmoke

Joined Jun 23, 2012
6
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)
 

hgmjr

Joined Jan 28, 2005
9,027
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
 

wayneh

Joined Sep 9, 2010
17,498
are there any benefits of using a cap vs a resistor?
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
 

Thread Starter

MrSmoke

Joined Jun 23, 2012
6
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
 

Thread Starter

MrSmoke

Joined Jun 23, 2012
6
Rich (BB code):
    tccr1a |= 1<<wgm11 | 1<<com1a1 | 1<<com1b1;
    tccr1b |= 1<<wgm12 | 1<<wgm13 | 1<<cs10;
    tccr2 = (0<<foc2)|(1<<wgm21)|(1<<wgm20)|(1<<com21)|(0<<com20)|(0<<cs20)|(1<<cs21)|(0<<cs22); 

    icr1 = 255;
 

wayneh

Joined Sep 9, 2010
17,498
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
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)?
 

Thread Starter

MrSmoke

Joined Jun 23, 2012
6
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)?
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.
 

wayneh

Joined Sep 9, 2010
17,498
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.
 
Top