5
\$\begingroup\$

I'm working on a project involving driving LEDs at a 20kHz PWM frequency with 1024 bit resolution. I've calculated that the minimum pulse time, (1/frequency)/resolution, would result in a minimum pulse time of ~50ns, which means I need rise and fall times of <25ns of all of the components I'm using to turn the LEDs on and off. While there are components that meet this specification, it's pretty demanding and I'd like to use some cheaper, more widely available ICs.

My thought is that while 1024 resolution is useful in adjusting the output of the LEDs in fine increments in my use case, I don't actually need a minimum brightness of 1/1024, but could probably get away with a minimum of 1% of the total brightness, or 1024 x 0.01, which is roughly 10x the minimum pulse width or about 500ns. This results in rise and falls times of 250ns, which greater increases the number of available components.

Is my understanding of the PWM frequency, resolution and duty cycle relationship correct here?

\$\endgroup\$
3
  • \$\begingroup\$ Skip mode or lower frequency a possibility? \$\endgroup\$
    – winny
    Jan 10, 2022 at 18:50
  • 1
    \$\begingroup\$ A pulse time of 50ns needs rise and fall both <= 50ns and approximately equal to each other. The end of the digital logic pulse is the beginning, not the end, of the fall time of the output pulse. \$\endgroup\$
    – Ben Voigt
    Jan 11, 2022 at 16:00
  • \$\begingroup\$ I'm curious - what's your application which needs 20kHz PWM on an LED? \$\endgroup\$
    – Graham
    Jan 11, 2022 at 16:35

3 Answers 3

9
\$\begingroup\$

Your calculations seem correct to me.

However, do you really care about the rise time being >25ns?

If you say you don't need the range below 1% brightness, then you can simply use only values in range 10 to 1023 out of 1023, and you therefore get a rise time of at least 10*50ns = 500ns.

If by mistake (or to simplify code/design) you still use the 0 to 9 out of 1023 range, then you will simply get in one of the following situations :

  1. The LED doesn't turn on at all (you don't have time enough to turn it on at all before starting to turn it off.)
  2. The LED turns on a little little bit (less than if you had instant turn on/off.)
  3. The LED somehow manages to turn on then turns off as quick as possible.

Which of the above will happen depends of the exact components you use for driving the LED (I would guess 1 or 2 are the most likekly.)

Between 0 and 9, you might not get brightness proportionnal to PWM, but you should get:

  • at least the same brightness as for 0
  • at most the same brightness as for 10
  • for any 2 numbers A<B, you will have brighness_A<=brightness_B

If you don't care about what exactly happens below 1% of brighness, either don't use values 1 to 9, or just accept the fact that you will not get perfect linearity for those.

\$\endgroup\$
5
  • \$\begingroup\$ Ok perfect, that was basically what I was trying to ask, (however confusingly) whether I could just skip the lower brightness values. Thanks! \$\endgroup\$
    – flimsy
    Jan 10, 2022 at 22:52
  • \$\begingroup\$ yes, you can (either you never use them in your code (or whatever else provides the PWM), or you use them and just accept that the behaviour is not perfect for thoses values) \$\endgroup\$
    – Sandro
    Jan 10, 2022 at 22:54
  • \$\begingroup\$ There is a significant mistake in the calculations of the OP -- minimum PWM pulse width is not the sum of rise and fall times, it's equal to just rise time. Fall time doesn't begin until the end of the digital pulse. \$\endgroup\$
    – Ben Voigt
    Jan 11, 2022 at 15:58
  • \$\begingroup\$ @BenVoigt that's not the case as far as I understand. Here's an illustration of how to calculate pulse width accounting for rise and fall times: mosaic-industries.com/embedded-systems/instrumentation/… \$\endgroup\$
    – flimsy
    Jan 12, 2022 at 0:30
  • \$\begingroup\$ @flimsy: Look at your reference again... only t_fall happens during the "on" time of the digital pulse (which causes the FET to drive its output low), t_rise happens during the "off" time. \$\endgroup\$
    – Ben Voigt
    Jan 12, 2022 at 18:23
7
\$\begingroup\$

If your driver is slower than 25ns (and I hope to heck it is or you'll likely be jamming RF for miles around unless the pixies are very contained) you'll just get an offset zero and maybe some sensitivity to temperature/supply voltage.

20kHz is a very high PWM frequency for a visible LED. Why not 2kHz?

\$\endgroup\$
2
  • 7
    \$\begingroup\$ 20khz is actually a very common PWM frequency because it's a) fast enough to prevent visible flicker in video and photography applications and b) beyond the auditory frequency range. Pretty much any LED light used for video or photography uses this PWM frequency. \$\endgroup\$
    – flimsy
    Jan 10, 2022 at 19:02
  • \$\begingroup\$ @flimsy: I've observed that some LED strips would in fact whine audibly if driven around a few thousand hertz, which made it necessary to rework the driver code to use a faster rate. \$\endgroup\$
    – supercat
    Jan 11, 2022 at 7:47
2
\$\begingroup\$

High frequency PWM is necessary if you don't want flicker.

However, fast switching is not only unnecessary, it makes things worse by generating more EMI. The good thing is, if you use slow switching, you will gain an extra feature: deeper dimming at the low end.

Since lighting LEDs have quite large capacitance, there will be a turn-on current spike, which increases EMI the faster the FET switches. And due to capacitance, they will turn off slowly anyway no matter how fast the FET switches off.

If you make your MOSFET switch slowly, say about 5-10 PWM ticks to fully turn on, then the very low PWM duty cycles between 1 and 10 become a lot more useful, because they no longer produce light that is proportional to duty cycle. This greatly expands your dynamic range. With a fast switching FET, a PWM duty cycle of 1/1024 will produce a bit more light than 1/1024 relative to fully on. I'm saying a bit more, because due to capacitance, the LED will stay on a little longer ; it will also be colder and more efficient.

But with a slow switching FET, if you use a low duty cycle, it won't have enough time to turn on fully before it turns off, so you get a lot less light.

I had problems because the lowest setting on my PWM was still too bright, and I didn't want to decrease frequency to avoid flickering. So I slowed the FET switching by increasing the gate resistor. Then, the first few PWM values were completely off, but the next 5-10 values did provide a very nice gradation starting from "barely visible".

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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