7

I have a 5 V embedded circuit where a 10 kΩ pot controls the duty cycle of an LED. I noticed that when the duty cycle is only 0.39% (or 1/255 bits), the LED is still perceptibly bright. I'm looking at the PWM signal on an oscilloscope and can see that the +5V fraction takes up only 65 us of a 16.4 ms period.

  1. What is the expected brightness of a conventional LED at duty cycles less than 1%? Feels like it should be completely off.

  2. Can anyone derive the equation relating brightness to duty cycle in this case?

Also checkout this article which gets close to the answer: https://codeinsecurity.wordpress.com/2023/07/17/the-problem-with-driving-leds-with-pwm/

"However, if you linearly sweep the duty cycle from 0-100%, you won’t see a smooth linear increase in brightness. This is because our eyes are far more sensitive to changes in brightness in the dark than in bright light; the evolutionary reasons for this are fairly obvious. If you graph the PWM duty cycle versus the normalized perceptual brightness, you’ll get a curve that looks something like this [logarithmic curve, no equation given]. At just 5% duty cycle, the perceptual brightness of the LED already exceeds 20% of the maximum."
(this leads to a gamma correction technique)

EDIT: This is a 5 V circuit, typical breadboard LED in series with a 1 kΩ resistor. The 5 V is PWM at variable duty cycle. What happens to the LED over over the full range of an 8 bit duty cycle? At what point is the LED perceptibly off? Apparently not unless the duty cycle is exactly zero.

winny
  • 14,707
  • 6
  • 46
  • 66
t3rrapin
  • 71
  • 4
  • 6
    The relationship of duty cycle to light intensity is quite linear, even down to 1%. The relationship of light intensity to perceptual brightness is complicated and dependent on the viewing environment and not exactly an electronics question :) – hobbs Sep 24 '23 at 22:52
  • @hobbs I see. Did you know that LEDs are not off with <1% PWM? – t3rrapin Sep 24 '23 at 23:15
  • what type of LED? ... maybe it contains a phosphor patch – jsotola Sep 24 '23 at 23:28
  • @jsotola typical breadboard LEDs, PWM frequency is 60 hz. Works on all LEDs I have obtained from arduino starter kits etc. – t3rrapin Sep 24 '23 at 23:49
  • A phosphor won't change linearity. Each pump photon generates something like 0.9 Stokes photons, so mathematically it works like a linear attenuation. – user1850479 Sep 24 '23 at 23:54
  • @t3rrapin Have a look here and here on this site for some details. There's a lot of more recent investigations, as well. Humans perceive color not only by the wavelengths their eyes gather but also by the spatial (nearby) wavelengths they also receive and then use to calibrate the illuminating sources, as well. This was studied by Edwin Land, among others. Brightness (scotopic and photopic) is a log function because our environment is illuminated over many orders of magnitude. – periblepsis Sep 25 '23 at 00:42
  • 1
    @t3rrapin But even that brightness perception isn't simple. For example, an LED in darkness and at a distance away will look brighter if it moves back and forth slightly. It's far more noticeable than the same LED at the same intensity when it isn't moving. It's all a matter of long evolution for what works to help us survive in a complex world and removing aspects that don't matter so much. We are not measurement instrumentation. Not even close. – periblepsis Sep 25 '23 at 00:45
  • 2
    @t3rrapin The *environment* within which the display is to be used means *everything* to answering your question. Everything. It's one thing when discussing a darkened environment, as that relies upon a completely different visual system. It's another thing entirely when discussing open daylight where another visual system is in use and where *contrast* is vital and the elimination of insolation becomes yet another problem element. There is no simple answer. Everything matters. With 8-bit PWM and dim env. only 0% will be off. Orders of mag are needed. So what's the environment? – periblepsis Sep 25 '23 at 04:14
  • 1
    I coded most of my lighting's PWM dimmers with 10 steps of linear-ish brightness, and that means that 9/10 is 50%, while 5/10 is just 6%, and 2/10 is 0.8%, to name a few intercepts. – dandavis Sep 25 '23 at 22:54
  • This is actually a feature that has been used for this project: https://hackaday.io/project/11864-tritiled - a very low duty cycle LED to replace a radioactive-phosphor light, with a battery life of ten years. – pjc50 Sep 26 '23 at 11:54
  • You speak of PWM control but explaining what that means in your case would be "a very good idea". eg Are you PWMing the on time at constant voltage, or the on current or ... ? || If you are PWM ing voltage at constant current then the LED is at full brightness for 1/255th of the time. While the average brightness is 0.4% you are giving the eye-brain a chance to sense full brightness. Given that "the dark adapted eye can sense a single photon" that is certainly not going to be "off". || Saying what LED is used and what the 1/255 drive (and 255/255) looks like will be useful. – Russell McMahon Sep 28 '23 at 02:01

4 Answers4

12

I'll try to give a helpful answer instead of telling you that this is a question of human perception and very difficult to answer correctly.

Gamma correction is exactly what you need and want. Basically, your LED PWM output sets the light intensity, but what you actually want to set is perceived brightness ("luma").

These follow a power law; but the actual exponent is somewhat subjective (see https://en.wikipedia.org/wiki/Gamma_correction#Power_law_for_video_display).

The good thing is you can just keep things simple and use 2 as gamma factor, which is in the right ballpark and makes everything easy to calculate, so:

led_PWM = brightness ^ 2 = brightness * brightness

Answering your question with this:

  1. A PWM value of 1% will still give you 10% perceived brightness! (1% = 10% * 10%)

  2. If you want to do this well, decent PWM resolution is required (e.g. 16bit). Because if you have only 8bit PWM resolution, your very smallest "not-off" value is already going to be ~6% "bright" (with 16bit PWM, you get a ~0.4% first increment, which is MUCH better). Here is how to calculate a 16bit PWM output from a 8bit brightness value using integer arithmetic (in C):

    uint16_t gammaCorrectU8ToU16(uint8_t desiredBrightness)
    {
        // 66051 is (0xffff / (0xff * 0xff) << 16), rounded up
        return (uint32_t)desiredBrightness * (uint32_t)desiredBrightness * 66051 >> 16;
    }
    
radioflash
  • 221
  • 1
  • 4
6

You will have no trouble seeing that LED going at 0.01% duty cycle in a dark-ish room. To turn the LED off, the PWM setting must be zero. That’s all there’s to it.

Many LEDs, if pulsed at say 50% of continuous current rating, will be visible with pulses as short as 50ns. Microcontrollers don’t normally have enough resolution to go that low :)

The LED itself is quite linear. Our eyes on the other hand have a dynamic range of what. 6 orders of magnitude or more? So yeah, 8-bit PWM is not gonna make a LED appear dark. Maybe in sunlight :)

3

Human vision has a logarithmic response, and will be more sensitive to low intensities. PWM type drive also triggers another vision path: persistence. So the eye will see the LED pulses and stretch them out, making the perceived light brighter.

hacktastical
  • 53,912
  • 2
  • 49
  • 152
  • The biggest reason why human vision is logarithmic is the iris adjusting. If you have only one LED as the only light source you see, this holds true. If you have one LED at very low intensity among many other brighter ones which your iris will adopt to, it's far more linear. – winny Sep 25 '23 at 14:03
  • That’s not entirely true. Gamma response over an image would not see changes due to pupil size. – hacktastical Sep 25 '23 at 14:13
  • That is what I tried to say but didn't make well. When teachers explain to the pupils that the eyes are logarithmic, the example is going from say 100 lux classroom to 100,000 lux sunlight outside without issues, that's iris response, not gamma curve. There are two response curves, the gamma curve on an image that you mention and on top of that the global iris regulation. – winny Sep 25 '23 at 14:19
2

LEDs are linear with duty cycle so long as your on time is relatively long relative to the rise time of the driver/LED combination. This will depend to some extent on how you switch it, but probably you will get good linearity down to tens of microseconds, perhaps further.

At very low duty cycles you will find that it starts to deviate from linear because the diode will take time to turn on each cycle.

user1850479
  • 16,883
  • 1
  • 21
  • 46
  • 4
    The LED might be linear, but not the human eye that's observing the LED. The on time and off time and persistence of vision certainly affect how you perceive a PWMed LED. It is of course somewhat subjective too, some people have higher flicker fusion threshold than others. – Justme Sep 25 '23 at 00:02
  • Yes that's true that vision will not appear linear, although since the diode is linear, you can apply a gamma curve to to the PWM to make it appear linear by eye. – user1850479 Sep 25 '23 at 00:13
  • The temporal response of the diode is not a significant factor in the average. It may take awhile for a pulse of injected charge carriers to make photons, but it's the amount of injected charge per second that matters. Of course, if the driver's temporal response is such that it injects less instantaneous current for a short pulse, there will be nonlinearity. – John Doty Sep 26 '23 at 15:09
  • @JohnDoty I don't think that is right. A diode junction is a capacitor, so at high frequencies, most of the current is reactive and real power dissipated in the junction drops. Essentially you'll just charge/discharge the diode capacitance over and over while spending less and less time sufficiently forward biased for current to flow. – user1850479 Sep 26 '23 at 19:44
  • @user1850479 Usually when I drive a LED, I use a transistor that only conducts in one direction. It can't discharge the diode. – John Doty Sep 26 '23 at 21:06