Shop OBEX P1 Docs P2 Docs Learn Events
Need formula to "linearize" LED PWM duty cycle — Parallax Forums

Need formula to "linearize" LED PWM duty cycle

BeanBean Posts: 8,129
edited 2006-06-10 03:25 in General Discussion
Is there a standard formula that is used to convert from PWM duty cycle to apparent light output for a white LED ?

I have a PWM value that can go from 0 to 127, and I would like to have 32·equally spaced brightness levels.

Bean.


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap 4-digit LED display with driver IC·www.hc4led.com

Low power SD Data Logger www.sddatalogger.com

"I reject your reality, and substitute my own." Mythbusters


Post Edited (Bean (Hitt Consulting)) : 6/7/2006 2:46:42 PM GMT

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-06-07 15:47
    This is what I found here:
    Jonathan Kirwan said...

    On 5 Oct 2004 13:31:38 -0700, wrongaddress([noparse][[/noparse]at]att.net (Bill Bowden) wrote:

    |LEDs are more efficient at lower currents, so you might consider using
    |2 or 3 of them at lower current rather than just one at higher current.
    |Hook up your LED at 5 mA to see how much dimmer the light is compared
    |to 20mA. I think you will get a lot more light from 4 LEDs at 5 mA as
    |opposed to one LED at 20mA.


    Assuming no empirical information on LEDs generally, accepting your statement as
    true in some context, and then carrying it to the end, I'd deduce that a million
    LEDs operating at 20nA each would produce more candelas than one at 20mA. Yet,
    I'd tend to argue instead that there is an optimizing parabola associated with
    all this, with an optimum point that is neither too far one way nor too far the
    other.

    But according to an HP document I'm reading here, the relative efficiency for a
    given LED and type "__increases__ with forward current," it does not
    __decrease__. That is, prior to the junction reaching saturation.

    For example, they say that with high-efficiency red LEDs and using 1.0 as the
    standard efficiency at 5mA, it reaches a relative efficiency of about 1.59 at
    about 43mA. This means that if you maintained an average current of 5mA but
    pulsed it at 43mA while maintaining that average (holding mean die temperature
    roughly constant) and compared it against a continuous 5mA, the photons produced
    in both cases would be 1.59 times greater when pulsing but maintaining the 5mA
    average. (Their chart is a relative guide that can be used to estimate
    millicandelas for different driving methods against some reference condition.)

    The efficiency factor does take into account die temperature changes. But
    ambient temperature does impact things. For the high efficiency red LED:

    ratio = I(Tambient)/I(Tcal) = e^(-.0131*(Tambient - Tcal))

    (Temperature affects other LEDs, of course, but the -.0131 factor varies with
    their type.) So, for example, when comparing a temperature of 60C with some
    spec given at a calibration point of 25C, the equivalent flux ratio will be
    e^(-.0131*(60-25)) or about 63.2% of what was specified for 25C.

    For example, they suggest the following calculation. If we already know that
    the LED is supposed to provide 5 millicandelas at 10mA and 25C, and we expect to
    pulse it at 50mA with a duty cycle of 50%, and the ambient temperature will be
    55C, then:

    result = 5 mcd * (50mA*50% / 10mA) * (1.61 / 1.24) * e^(-.0131*(55-25))

    or about an 11 mcd equivalent output. (The 1.61 comes from the table for 50mA
    and the 1.24 comes from the table at 10mA.)

    I've not made the measurements here, but it appears they disagree with your
    comments. For example, using their calculations, and assuming the same ambient
    temperature in all cases:

    relative performance = (5mA / 20mA) * (1.00 / 1.43) = about 17.5%

    In other words, driving at 1/4th the current (for high-eff red LED) doesn't
    provide 25% of the brightness, but instead 17.5%. Now, this does NOT consider
    human logarithmic responses. But if you now use four of these 5mA LEDs, then
    the total is 4*17.5% or 70%. One doesn't need to understand details about human
    logarithmic responses to "see" that 70% will appear to be less bright than 100%.

    But then, I'm taking this from empirical HP studies I have at hand and I'm not
    making measurements, myself. So I'd like to see the basis for arguing that (4)
    LEDs operating at 25% of the current are brighter than (1) LED operating at
    100%. (Unless saturation takes place, of course.)

    Jon



    Though Im not sure how much use that will be since its non-emperical.

    Here is a very insightful document: http://www.lumex.com/MstrCatalog/2_operating_curves.pdf

    Where lumex has provided the operating curves for all of thier LEDs, the luminousity vs current is the one of interest.
    For the first few you'll see its a negative curavture where efficiency of·luminosity vs current·decreases with increased current, and each has varying degrees of curvature (super blue suffering the worst loss of efficiency). But then you get down to 555nm green, and its the opposite where a positive curvature exists at low currents, then become essentially linear at higher currents. Then when you think you can express the luminosity of an LED with a single constant value for a specific LED (using the e^(K Tratio)), you hit the 565nm green,·590nm super yellow and·635nm high intesity red which exhibit a positive curvature at low currents and a negative curvature at high currents, meaning the formula isn't exact and must include another exponential term.

    So the conclusion is,·there is no standard equation to equate current with luminosity for all LEDs, each LED has its own constant(s). So to be able to provide a linear luminosity you must either purchase an LED whose luminosity has already been characterized, or you must use a luminousity meter and do empirical anaysis on the LED you will be using.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Life is one giant teacup ride.

    Post Edited (Paul Baker) : 6/7/2006 3:50:32 PM GMT
  • BeanBean Posts: 8,129
    edited 2006-06-07 16:29
    Paul,

    Thanks for that info. I'm not looking for anything accuate. I would just like the LED to APPEAR to increase in intensity linearly.

    In other words "Factor in" the human non-linear response to light.

    Rather than appear to increase quickly at low PWM values, then increase much more slowly at the higher PWM value.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com

    "I reject your reality, and substitute my own." Mythbusters
    ·
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-06-07 16:42
    Ah gotcha, ok this is a little more up my alley (researched alot of perception studies in grad school), Ill see what I can scare up as far as info on my lunch break.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Life is one giant teacup ride.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-06-07 17:15
    Ok from http://www.edgesensor.com/feast/color.html·:
    Physical Presentation of Light and Mental Color-Image

    A sensitivity of the eye sensor's substance to light is measured by a degree of substance reaction to light of given intensity.

    If this sensitivity is ri for a light component i, and si is an intensity of component i, then a cumulative reaction of the substance is a sum of si*ri by all light components:

    s1*r1+ ...+sn*rn.

    There is a general pattern, how a body (including brain) reacts on stimuli. Reaction on light follows this pattern.

    A relation between a physical stimulus and corresponding perception follows a rule: a small change in the level of stimulus leads to a proportional small change in a level of perception; it is inversely proportional to a current level of stimulus. When a change of the level of perception y is dy, and a change in the level of stimulus x is dx and coefficient of proportionality is a, we can write this rule in a following formula

    dy=a*dx/x.Hence

    y=a*ln(x)+c,where ln() - natural logarithm, and c - constant.

    The constant c in this formula, we can find from a following fact. When the level of stimulus is below x0 there is no reaction (there is a threshold of sensitivity). Hence:

    0=a*ln(x0)+c, or

    c=-a*ln(x0).It means:

    y = a*ln(x/x0), when x ³ x0,

    y = 0, when x < x0When we know a level y, a corresponding level x is:

    x = x0*exp(y/a), y ³ 0.We apply this reasoning to an eye sensor. In this case, the stimulus is the reaction of the eye sensor's substance:

    x = s1*r1+ ...+sn*rn.

    Values a, x0 and ri depend on the sensor. Hence, we need to know values aj, x0j, and

    r1j, ..., rnj

    for each sensor j=1,2,3,4.

    As soon we have this information, we can compute reactions of eye sensors to the light of any spectrum.



    Here x0 would be the minimum detectible PWM value of an observable illuminated LED. http://hyperphysics.phy-astr.gsu.edu/hbase/vision/bright.html·provides a rough estimation of a by stating a doubling of intensity results in a 1.5 (50% increase) in perceived brightness.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Life is one giant teacup ride.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-06-09 19:29
    Bean, so did you figure it out? The formula for equi-brightness is something like x = e(0.462*y)-0.58 . So the list of illuminations (1x brightness, 2x brightness, 3x brightness,...):


    1, 1.94, 3.42, 5.77, 9.50, 15.42, 24.82, 40.32, ... and rounded to the nearest integer would be
    1, 2, 3, 6, 10, 15, 25, 40, ...

    the - 0.58 factor is the offset to yeild the lowest visible PWM value, which I made the assumption was 1 (result of·e0.462 is 1.58), if the actual lowest visible PWM value were 2 the constant would be + 0.42, and would similarly be calculated for another value.

    Given the range of 128·PWM levels, 10 equi bright values can be obtained (e4.62-0.58 = 100.9, with the next brightness value at 160.7), if hyperphysic's claim that a double of intensity equals a 50% increase in brightness is correct, you'd need a 12 bit value for PWM in order to achieve 32 equi bright values.

    You might be able to squeeze a few more values out by doing a regional linear approximation of the curve by sacrificing accuracy near the boundry points, but you wont be able to squeeze anywhere close to 3x as many points into a 7 bit space.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Life is one giant teacup ride.

    Post Edited (Paul Baker) : 6/9/2006 7:35:10 PM GMT
  • BeanBean Posts: 8,129
    edited 2006-06-09 20:32
    I simplied it and just used excel and used value = brightness (0-31) ^ 1.75 then I normalize the values to fit 0-127.
    It's not perfect, but it's alot better than linear.
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com

    "I reject your reality, and substitute my own." Mythbusters
    ·
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-06-09 21:03
    Cool, after doing some research to verify what I derived, I stumbled across the guiding principle of perception called Weber's law of just noticible differences (JND), which is what I was studying as part of my thesis in college (though in the audio realm). It states that the noticable change in value with respect to the intensity of the value is constant or di/i = k, for vision intensity the constant is 0.08. For the first part of the line this is obviously going to be linear because you cant use a non integer value. But when you get to higher values the delta will increase.

    You may or may not want to try to adapt this algorithm, I tried a bit but it didnt want to fit nicely into 32 slots, but you can use it as a sanity check for the values you used, instead of using the 0.08, just plot the log of the change in value verses the value. The resultant slope should come close to a straight line. This wont hold for the small intesities due to the lack of precision from integer numbers, but the right hand of the graph should be a straight line.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Life is one giant teacup ride.
  • BeanBean Posts: 8,129
    edited 2006-06-10 02:17
    Paul,
    When you say di/i = k = 0.08 are you saying that you need an 8% increase in power (from the present value) to get a noticeable change ?
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com

    "I reject your reality, and substitute my own." Mythbusters
    ·
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-06-10 03:25
    Thats my understanding, the formula is related to the exponential I quoted before, but it yeild more than 32 increments over the span of 128.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Life is one giant teacup ride.
Sign In or Register to comment.