I'm a hobbyist (well, less than a hobbyist really) trying to layout my first PCB design. I'm somewhat familiar with the concept of decoupling capacitors. I'm fading 3 LEDs in and out (really, it's an RGB LED and I'm trying to create blended colors). I'm using ATTiny's PWM pins to accomplish this.

I'm planning to add a 100nF ceramic disk capacitor between the VCC and GND on the IC, but I'm not sure if I also need to decouple the LED signals. If so, do I put them close to the LED or close to the IC? What size caps do I use?

  • 2
    \$\begingroup\$ I don't think it is necessary. I haven't seen it in any other led circuit. \$\endgroup\$ – Sean87 Nov 26 '18 at 1:13
  • 1
    \$\begingroup\$ Capacitors may have undesired low-pass filtering effects on your pwm signal, but ya also totally unnecessary. \$\endgroup\$ – vicatcu Nov 26 '18 at 1:22
  • \$\begingroup\$ What is the RGB LED that uses PWM pins but also has a Vcc pin? That seems unusual. In any case, do not put caps on the PWM pins. That will only damage the Attiny output pins over time. \$\endgroup\$ – CrossRoads Nov 26 '18 at 1:49
  • \$\begingroup\$ @CrossRoads, the LED doesn’t have VCC, the ATTiny does. Sorry for the confusion. \$\endgroup\$ – D. Patrick Nov 26 '18 at 1:51

Just a warning about putting large capacitors on MCU output pins.

Modern FETs can be laid out very compactly while providing 100mA output pin drives, and the thermal time constant is very fast (about 10 nanoseconds) because of shallow channels. The 3_D silicon size (volume) provides little ability to store heat, to the point of over 1,000 degree Centigrade heating per microsecond of short-circuit (driving a large capacitors) operation.

Large capacitors will be way too slow to charge and discharge, causing the FETs to operating in HIGH_CURRENT and HIGH_VOLTAGE modes simultaneously, melting the FETs.

How large a capacitor is dangerous? If the capacitor cannot be charged to 90% of final value (2 timeconstants) in 100 nanoseconds, then rethink your values or circuits.

1uF and 1 amp will charge the capacitor voltage by 1 volt per 1 microsecond.

0.1uF and 0.1 amp will charge the capacitor voltage by 1 volt per 1uS.

0.01uF and 0.1 amp will charge the capacitor voltage by 1 volt in 0.1uS. This begins to be safe.

Thus I suggest you not use more than 1,000pF (1nF) on MCU outputs.


You can connect the LEDs directly to the output pins - you do not even need current limiting resistors. (wait for the flames on this - but I PROMISE it is true and no problem!)

When the PWM pin is high then the LED will be on, when the PWM pin is low then the LED will be off. Adding a capacitor in parallel with the LED would "smooth" out this on/off flashing, but as long as the PWM frequency that you are driving the LED with is higher than your eye can see (like >100Hz), then it will visually just look like the LED is dimmed based on the duty cycle of the PWM.

  • 1
    \$\begingroup\$ Wait!? I don’t need a current limiting resistor!? Why not? \$\endgroup\$ – D. Patrick Nov 26 '18 at 3:36
  • 1
    \$\begingroup\$ bugjosh apparently thinks the output impedance of the Attiny output transistors is high enough to limit the LED current. I would suggest that is poor design practice and that the 25-40mA output will either make the LED overly bright and fail early from overheating, or the Attiny will. At 20mA, the output is guaranteed to be 4.2V, while the LED is typically expecting 20mA max at it's Vf, somewhere in the 2.5V to 3.7V range. Stick with 150 to 330 ohm resistors, that will keep things from burning up, until you can determine the Vf of the LEDs and make a smarter resistor choice. \$\endgroup\$ – CrossRoads Nov 26 '18 at 15:39
  • 1
    \$\begingroup\$ There are several factors that make eliminating the resistor ok - too many to fit in a comment - but just keeping in the average LED current below the rated current using the duty cycle of the PWM is enough to insure no problems as long as frequency is > ~1KHz and the chip Vcc is lower than rated ~6V. But even if you mess up the PWM and leave the output pin dead on for, say, A DECADE, I promise nothing will burn up. Try it! If anything bad happens I will happily replace the destroyed chip and/or LED! Please do report back in this thread in 2028 with the results! :) \$\endgroup\$ – bigjosh Nov 26 '18 at 17:08
  • 1
    \$\begingroup\$ @D.Patrick TIP: Set up your R,G,B PWM timers to all run out of phase with each other. This way only one LED is actually one at given moment. This avoids problems where visually making one LED brighter makes another dimmer because they are both pulling current at the same time. To coordinate phases, you can use inverting and non-inverting output on the same timer, and 180 out of phase start time (or direct TCNT assignment) between timers. \$\endgroup\$ – bigjosh Nov 26 '18 at 17:12
  • 1
    \$\begingroup\$ TIP: If you want to run directly off 3V batteries (i.e. 2XAA or 2032 coin cell), you will loose blue as soon as the battery gets below the forward voltage of the blue LED, which is much sooner than the battery is actually deal. You can very cheaply and easily boost the blue with this technique. \$\endgroup\$ – bigjosh Nov 26 '18 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.