Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 16, 2024, 07:38:54 07:38


Login with username, password and session length


Pages: [1]
Print
Author Topic: pic linear dimming curve  (Read 6939 times)
0 Members and 1 Guest are viewing this topic.
jamen
Junior Member
**
Offline Offline

Posts: 41

Thank You
-Given: 31
-Receive: 7


« on: May 01, 2014, 11:20:17 11:20 »

hi:friend
i have a led project ,need linear dimming, use pic ADC to control PWM dimming.
the ADC is 0.5V-5V, pwm ratio 2% to 100%. step need greater than 200.
if me use read table , the curve is not linear .
have one tell me ,how can i to do ,
Logged
hate
Hero Member
*****
 Warned
Offline Offline

Posts: 555

Thank You
-Given: 156
-Receive: 355


« Reply #1 on: May 01, 2014, 01:52:36 13:52 »

There is a discussion about your problem in the thread below with some proposed solutions.
http://electronics.stackexchange.com/questions/1983/correcting-for-non-linear-brightness-in-leds-when-using-pwm
Logged

Regards...
jamen
Junior Member
**
Offline Offline

Posts: 41

Thank You
-Given: 31
-Receive: 7


« Reply #2 on: May 01, 2014, 02:56:45 14:56 »

There is a discussion about your problem in the thread below with some proposed solutions.
http://electronics.stackexchange.com/questions/1983/correcting-for-non-linear-brightness-in-leds-when-using-pwm


yes this solution is ok, but take up too much memory.
Is there a formula for calculating curve, only for add ADC value,
Logged
hate
Hero Member
*****
 Warned
Offline Offline

Posts: 555

Thank You
-Given: 156
-Receive: 355


« Reply #3 on: May 01, 2014, 07:24:20 19:24 »

Did you actually read the whole thread?
Quote
The Excel formula I used was this:
Code:
=1/(1+EXP(((A2/21)-6)*-1))*255
where A2 is the first value in column A, which increases A3, A4, ..., A256 for each value.
By the way I wouldn't rely much on formulas in case of code space. Usually a simple look-up table will take less space than a complex formula code.

Also the last post (if you've read) suggest an 'anti-log' drive. You might consider googling 'anti-log' and try to implement one.
Logged

Regards...
Gallymimu
Hero Member
*****
Offline Offline

Posts: 704

Thank You
-Given: 151
-Receive: 214


« Reply #4 on: May 14, 2014, 09:43:27 21:43 »

yeah I'd use a 128 or 256 point lookup table.  If that consumes too much memory then use a 16 pt lookup table and piecewise linear approximation between the points.  You want to bunch the points towards the low end of the brightness curve as your eyes are much more sensitive to incremental changes at the low brightness end.

What you are dealing with here is a psychophysical power law.  It's been well researched and published for all of the human sensory mechanisms.
http://www.telescope-optics.net/eye_intensity_response.htm
http://en.wikipedia.org/wiki/Stevens'_power_law
Logged
CocaCola
Senior Member
****
Offline Offline

Posts: 482

Thank You
-Given: 169
-Receive: 232



« Reply #5 on: May 14, 2014, 10:28:12 22:28 »

Personally I have found that if you want it to really fade in and out nice it's easier and cost effective to simply use a dedicated LED driver IC as most use 1024 bit resolution and have highly refined fade curves already built in...   This also leaves your micro pretty much free to do whatever else it needs to do...  I was never really happy with fade of the 128/256 look up tables I experimented with...
Logged
Gallymimu
Hero Member
*****
Offline Offline

Posts: 704

Thank You
-Given: 151
-Receive: 214


« Reply #6 on: May 17, 2014, 09:38:27 21:38 »

we use a 256 point visual perceptual power curve lookup table for a variety of public art sculptures and it works quite nicely.  Though if you can go 1024 bit it's nice because the eye is very sensitive to small intensity changes at the low end.
Logged
Crackn
Active Member
***
Offline Offline

Posts: 130

Thank You
-Given: 118
-Receive: 565



« Reply #7 on: September 09, 2014, 06:42:30 06:42 »

we use a 256 point visual perceptual power curve lookup table for a variety of public art sculptures and it works quite nicely.  Though if you can go 1024 bit it's nice because the eye is very sensitive to small intensity changes at the low end.

hello, do you mind to share those linearity lookup tables?

im working on a mosfet led dimmer circuit and I need to create some tables to control the linearity of the curves. I will have 2 or 3 diferent selectable curves to play with.

thanks.
Logged
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2420

Thank You
-Given: 862
-Receive: 678


Top Topic Starter


« Reply #8 on: September 09, 2014, 12:13:10 12:13 »

file attached is not for dummies, things are very simple, read the explanation inside the file below the graph and you will understand how to modify it, whether it is LOG, AntiLOG or even Linear and also you can change DAC_MAX as well as step values, you can also treat DAC_MAX as the PWM or timer value, it is a math thing!


This sheet can be used to create the required lookup table for 64 steps. I assumed that I have a 8-bit DAC or a 256-step digital POT. Hence, in order to be able to achieve a LOG or Anti-LOG response curve with a 8-bit DAC or a 256-step digital POT, I opted to reduce the actual resolution to 64 steps.

Humans would not notice the difference between step 100 and 101 while you have 256 steps. Inserting gamma to Anti-LOG formula allows you to control how steep your dimmer works, you better go with gamma thing when it comes to dimmers, even with LEDs. Bear in mind that actual consumer appliances use 16~32 steps!

Hope this is of help. I used this for an AC dimmer and it works a treat.

BTW, I can write you a perl script that can generate files for your required values.

you better use a lookup table, using the formula to calculate the current value takes lomg time on 8-bit MCUs.
« Last Edit: September 09, 2014, 12:16:52 12:16 by metal » Logged
towlerg
Senior Member
****
Offline Offline

Posts: 263

Thank You
-Given: 474
-Receive: 104

What is this for?


« Reply #9 on: September 10, 2014, 01:38:07 01:38 »

I don't know if this is interesting but on http://jared.geek.nz/2013/feb/linear-led-pwm the guy implements the CIE 1931 lightness formula ( what ever that is)

George 
Logged

Win 7 Ult x64 SP1 on HP2570p
Crackn
Active Member
***
Offline Offline

Posts: 130

Thank You
-Given: 118
-Receive: 565



« Reply #10 on: September 11, 2014, 03:31:03 03:31 »

This sheet can be used to create the required lookup table for 64 steps. I assumed that I have a 8-bit DAC or a 256-step digital POT. Hence, in order to be able to achieve a LOG or Anti-LOG response curve with a 8-bit DAC or a 256-step digital POT, I opted to reduce the actual resolution to 64 steps.

Hi,

this table is what im looking for long time... really thanks for the precious information.
now its time to do a lot of tests.

i will check the site too, seems to be interesting material.
Logged
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2420

Thank You
-Given: 862
-Receive: 678


Top Topic Starter


« Reply #11 on: September 11, 2014, 07:52:09 07:52 »

to be honest with you, you better try both techniques. I did lots of reading yesterday, and it appears that the antilog suites audio volume control, while people - including me - used to think that the antilog when combined with gamma will work OK for dimmer applications, seems I was wrong; I should try both now as well. I thought that because when I first started with this stuff, I found a guy who made 8 channel dimmer and used the gamma thing, also I found today a perl script from diamond RTOS that implements gamma as well, thanks to towlerg who pointed out that we are wrong.

 I will plot it today on excel and get back with a graph comparison.

Logged
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2420

Thank You
-Given: 862
-Receive: 678


Top Topic Starter


« Reply #12 on: September 11, 2014, 09:12:12 09:12 »

Interesting to read: https://home.comcast.net/~NikonD70/GeneralTopics/Exposure/Psychometric_Lightness_and_Gamma.htm
Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #13 on: September 12, 2014, 04:52:52 16:52 »

Microchip now have PIC12F1572 a 8 pin mcu with 3x 16 bit PWM - ideal for 3 channel led dimming.

Look at the demo board, it is much more than dimming - implement the CIE 1931 too (yes, whatever it is)

-ichan
Logged

There is Gray, not only Black or White.
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2420

Thank You
-Given: 862
-Receive: 678


Top Topic Starter


« Reply #14 on: September 13, 2014, 12:23:52 00:23 »

turns out that log is for our ears, CIE 1931 is for our eyes.
Logged
Gallymimu
Hero Member
*****
Offline Offline

Posts: 704

Thank You
-Given: 151
-Receive: 214


« Reply #15 on: October 20, 2014, 04:01:58 04:01 »


Sorry for the late response on this, here are tables we use in sculptures.  Exponential Beta value for these was 2.

For a given desired intensity index, the output of the lookup table would be your duty ratio (out of a max of 256)

Code:
#ifndef LOOKUP_H
#define LOOKUP_H

/*
//beta = 2
const rom unsigned char INTENSITY[64] =
{
0   ,0   ,0   ,0   ,0   ,0   ,0   ,1   ,
1   ,1   ,1   ,2   ,2   ,2   ,3   ,3   ,
4   ,4   ,5   ,5   ,6   ,6   ,7   ,8   ,
8   ,9   ,10  ,11  ,11  ,12  ,13  ,14  ,
15  ,16  ,17  ,18  ,19  ,20  ,22  ,23  ,
24  ,25  ,27  ,28  ,29  ,31  ,32  ,34  ,
35  ,37  ,38  ,40  ,42  ,43  ,45  ,47  ,
49  ,50  ,52  ,54  ,56  ,58  ,60  ,62  };
*/
/*
const unsigned char INTENSITY[256] =
{
0 ,0 ,0 ,0 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,256
};
*/

//beta = 2
/*
const unsigned char INTENSITY[128] ={
0 ,0 ,
0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,1 ,1 ,1 ,2 ,2 ,2 ,
2 ,3 ,3 ,3 ,3 ,4 ,4 ,4 ,5 ,5 ,6 ,6 ,7 ,7 ,
7 ,8 ,8 ,9 ,10 ,10 ,11 ,11 ,12 ,12 ,13 ,14 ,14 ,15 ,
16 ,17 ,17 ,18 ,19 ,20 ,20 ,21 ,22 ,23 ,24 ,24 ,25 ,26 ,
27 ,28 ,29 ,30 ,31 ,32 ,33 ,34 ,35 ,36 ,37 ,38 ,39 ,40 ,
42 ,43 ,44 ,45 ,46 ,47 ,49 ,50 ,51 ,52 ,54 ,55 ,56 ,58 ,
59 ,60 ,62 ,63 ,65 ,66 ,67 ,69 ,70 ,72 ,73 ,75 ,76 ,78 ,
80 ,81 ,83 ,84 ,86 ,88 ,89 ,91 ,93 ,94 ,96 ,98 ,100 ,101 ,
103 ,105 ,107 ,109 ,110 ,112 ,114 ,116 ,118 ,120 ,122 ,124 ,126 ,128 ,
};
*/

// adjusted intensity for offset needed for AP8800 drivers
// beta = 2
const unsigned char INTENSITY[128] ={
0,0,0,1,1,1,2,2,2,2,3,3,3,4,4,5,5,6,6,7,7,8,9,9,10,11,12,13,13,14,15,16,17,18,19,20,22,23,24,25,26,28,29,30,32,33,35,36,38,39,41,42,44,46,47,49,51,53,54,56,58,60,62,64,66,68,70,72,74,77,79,81,83,86,88,90,93,95,98,100,103,105,108,110,113,116,118,121,124,127,130,132,135,138,141,144,147,150,153,157,160,163,166,169,173,176,179,183,186,190,193,197,200,204,207,211,215,218,222,226,230,233,237,241,245,249,253,255
};





#endif //LOOKUP_H
Logged
flo0319
Junior Member
**
Offline Offline

Posts: 81

Thank You
-Given: 7
-Receive: 17


« Reply #16 on: October 20, 2014, 10:29:53 22:29 »

The LED intensity is function of current integrated in time and it's temperature.
 Dimming the same led color will have the same curve but if you will combine them, you need to be careful. A RGB LED has different forward voltage for Red Green and Blue colors, which means different currents + temperatures -> different curves.
 A LUT is useful when is needed speed and is not time for software mul/div (audio, motors control) and the ROM/RAM is not a problem . But the LEDs need around 200Hz PWM (a lower frequency can affect the photosensitive epileptic people) and the duty cycle I suppose that will be updated with a lower frequency, which means enough time to calculate "any" approximation function for a dimming curve.
Logged
Gallymimu
Hero Member
*****
Offline Offline

Posts: 704

Thank You
-Given: 151
-Receive: 214


« Reply #17 on: October 23, 2014, 07:17:46 19:17 »

The LED intensity is function of current integrated in time and it's temperature.
 Dimming the same led color will have the same curve but if you will combine them, you need to be careful. A RGB LED has different forward voltage for Red Green and Blue colors, which means different currents + temperatures -> different curves.
 A LUT is useful when is needed speed and is not time for software mul/div (audio, motors control) and the ROM/RAM is not a problem . But the LEDs need around 200Hz PWM (a lower frequency can affect the photosensitive epileptic people) and the duty cycle I suppose that will be updated with a lower frequency, which means enough time to calculate "any" approximation function for a dimming curve.

I don't agree.  If you get a decent RGB LED and drive it with equal currents to each diode you are going to get a very consistent white over a broad temperature range.  I think you've unnecessarily over-complicated things.

Where did you get your information about epilepsy?
http://www.epilepsy.com/learn/triggers-seizures/photosensitivity-and-seizures

30-60Hz is just fine for LED PWM unless you have the light rapidly moving through the field of vision, in which case higher frequencies will be better.  We get very good results even with motion at around 100Hz.
Logged
vern
V.I.P
Active Member
*****
Offline Offline

Posts: 144

Thank You
-Given: 7
-Receive: 41


« Reply #18 on: October 23, 2014, 09:17:55 21:17 »

Quote
30-60Hz is just fine for LED PWM
I don't agree with that. Even if the LED is not moving, your eyes are constantly moving and a LED with such a low PWM freqency is very annoying.
If you look directly it seems fine, but if it is on the periphery of your vision you can see it strobe.
If you ever follwed a car with PWM'd tail lights you'll know what I mean.
Logged
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2420

Thank You
-Given: 862
-Receive: 678


Top Topic Starter


« Reply #19 on: October 23, 2014, 10:00:43 22:00 »

may be this is a bit off topic, but to my experience with 7 segment displays, I was comfortable with 250Hz for 3 digits, which gives ~83HZ per digit.. I was not comfortable with 50/60HZ values, while I was walking I looked at the display and I could see it was clearly flickering.. Now compare my speed to the car's speed, I think you are right.
Logged
CocaCola
Senior Member
****
Offline Offline

Posts: 482

Thank You
-Given: 169
-Receive: 232



« Reply #20 on: October 23, 2014, 10:56:31 22:56 »

IMO you should do less then 100HZ better to do 200HZ or more, even though the human has a hard time seeing/detecting much beyond 60HZ, there are studies that suggest that flash rates even up to about 120HZ can induce migraines, headaches and even eye strain, so even though you might not be 'seeing' it, it is most likely still being detected by the brain as flashing...  We live in a day and age where higher flash rates are not that hard to do, IMO really no reason beyond being cheap (or it's for some cheap product where smoothness isn't required) to not do a higher rate...
Logged
flo0319
Junior Member
**
Offline Offline

Posts: 81

Thank You
-Given: 7
-Receive: 17


« Reply #21 on: October 24, 2014, 11:58:34 23:58 »

I don't agree.  If you get a decent RGB LED and drive it with equal currents to each diode you are going to get a very consistent white over a broad temperature range.  I think you've unnecessarily over-complicated things.

The discussion was about a simple voltage PWM dimming and not about a constant current source controlled by a PWM. Because I don't want to complicate things I will say just this: a series resistor is connected to an LED and 5V (for a current limitation), at 100% duty the LED will have a temperature and a forward voltage, that means a current in resistor; at 10%  duty the LED will have a low temperature which means a higher forward voltage, that means  a smaller voltage for the series resistor and a smaller current.

I found this link useful for me and maybe will be for others: http://www.digikey.de/de/articles/techzone/2014/feb/led-color-shift-under-pwm-dimming

About photosensitive epilepsy I think this is a good article: http://www.xinelam.com/pdf/IEEE%20Standard%20PAR1789%20Update.pdf
Quote
Measurements of the electroretinogram have indicated that
modulation of light in the frequency range 100-160Hz and
even up to 200 Hz is resolved by the human retina although
the flicker is too rapid to be seen (Burns et al. 1992, Berman
et al., 1991)
Logged
jellybean442
Newbie
*
Offline Offline

Posts: 22

Thank You
-Given: 128
-Receive: 47


« Reply #22 on: November 16, 2014, 09:45:59 21:45 »

30-60Hz is just fine for LED PWM unless you have the light rapidly moving through the field of vision, in which case higher frequencies will be better.  We get very good results even with motion at around 100Hz.

I can easily spot the difference between 30Hz and 60Hz LED lighting while driving around at night. A lot of LED taillights use PWM to provide dimming for brake lights, but some of them use annoyingly low PWM frequencies. Too low and it can actually nauseate people... The downside to high PWM frequencies is an increase in switching losses, but I understand that these losses are negligible until you hit frequencies in the 10kHz+ range.

Back to the original question, TI has a nice article (and Excel spreadsheet) for plotting LED colors using CIE 1931. You can pull values from that for lookup tables. There's also an EDN article that you can reference for using the spreadsheet.
« Last Edit: November 16, 2014, 09:48:38 21:48 by jellybean442 » Logged
Gallymimu
Hero Member
*****
Offline Offline

Posts: 704

Thank You
-Given: 151
-Receive: 214


« Reply #23 on: November 18, 2014, 03:56:57 03:56 »

I don't agree with that. Even if the LED is not moving, your eyes are constantly moving and a LED with such a low PWM freqency is very annoying.
If you look directly it seems fine, but if it is on the periphery of your vision you can see it strobe.
If you ever follwed a car with PWM'd tail lights you'll know what I mean.


whatever man, I've been doing LED lighting systems for years.... and if you read what I said, I said "if you are not moving the LED through your field of vision" which is a completely different issue which does require very high frequencies such that the LED is not in different states as it passes rapidly through the field of vision.

Posted on: November 18, 2014, 04:44:00 04:44 - Automerged

The discussion was about a simple voltage PWM dimming and not about a constant current source controlled by a PWM. Because I don't want to complicate things I will say just this: a series resistor is connected to an LED and 5V (for a current limitation), at 100% duty the LED will have a temperature and a forward voltage, that means a current in resistor; at 10%  duty the LED will have a low temperature which means a higher forward voltage, that means  a smaller voltage for the series resistor and a smaller current.

I found this link useful for me and maybe will be for others: http://www.digikey.de/de/articles/techzone/2014/feb/led-color-shift-under-pwm-dimming

About photosensitive epilepsy I think this is a good article: http://www.xinelam.com/pdf/IEEE%20Standard%20PAR1789%20Update.pdf

OK fine, sure, if you are trying to use a resistor as a constant current source then no, you are never going to be able to get consistent color matching.  Why anyone who cares about their light output and color would design such an oversimplified approach is odd to me though.

That's why if you want good color, you use a current source and minimize the temperature effects.

Posted on: November 18, 2014, 04:51:18 04:51 - Automerged

I don't agree with that. Even if the LED is not moving, your eyes are constantly moving and a LED with such a low PWM freqency is very annoying.
If you look directly it seems fine, but if it is on the periphery of your vision you can see it strobe.
If you ever follwed a car with PWM'd tail lights you'll know what I mean.


you are talking about saccades and are misunderstanding their purpose and impact on vision.  The reason saccades improve visual spatial resolution is because they move FASTER than the integration time of the visual system.  Therefore, they would NOT have an impact or interaction with any PWM frequencies selected.

You are correct though that the photoreceptors on the periphery of your vision are more temporally sensitive than those in the fovia (center of vision)
Logged
jellybean442
Newbie
*
Offline Offline

Posts: 22

Thank You
-Given: 128
-Receive: 47


« Reply #24 on: November 19, 2014, 11:44:15 23:44 »

you are talking about saccades and are misunderstanding their purpose and impact on vision.  The reason saccades improve visual spatial resolution is because they move FASTER than the integration time of the visual system.  Therefore, they would NOT have an impact or interaction with any PWM frequencies selected.

You are correct though that the photoreceptors on the periphery of your vision are more temporally sensitive than those in the fovia (center of vision)

So saccades allow us to obtain a wider angle of view, but our brains don't sample visual data fast enough to capture images in as much detail as we would during a fixed stare? This is interesting; I don't believe I've ever seen the word "saccades" before, but now that I have, it's quite interesting. Looks like I have some reading to do!
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC