Forgive me guys and gals but I just found a "
Using Lookup Tables to Perform Gamma Correction on LEDs" document from Maxim that that I thought some of you might find interesting.
I modified the Maxim algorithm to work in a spreadsheet and compared its duty cycle array output to Leo's algorithm output and noticed quite a bit of difference in the duty cycle arc (1st chart below).
The Maxim algorithm uses a "gamma correction factor" variable which allows you to change the shape of the arc and so I added a similar variable to Leo's algorithm. A value of "1" in the new "GCF" variable produces the same output as Leo's original algorithm. Through experimentation I found that a "GCF" value of 0.52 produced an arc similar to that of the Maxim algorithm (2nd chart below). The two algorithms produce slightly different duty cycle values along the arc especially at the low end of the duty cycle range.
Anyway the modified program allows us to change the amount of gamma correction in the duty cycle array output (the shape of the duty cycle arc) to perhaps more closely match the characteristics of the LEDs we're using.
' Leo Bodnar's 'antilogarithmic'
' gamma correction algorithm
'
' JustBASIC (free) interpreter
'
Input "Gamma array size: "; arraysize
Input " Total PWM steps: "; width
Input "Gamma correction: "; gamma ' try 0.5 to 1.0
FOR index = 0 to arraysize-1
dcyval = INT(width^(((index+1)/arraysize)^gamma)+.3)
if(index = 0) then
dcyval = 0
PRINT
else
if(index MOD 10 = 0) then
PRINT ","
else
PRINT ",";
end if
end if
if(dcyval < 100) then print " ";
if(dcyval < 10) then print " ";
PRINT dcyval;
NEXT index
PRINT
PRINT
REM CLOSE
Gamma array size: 64
Total PWM steps: 256
Gamma correction: 1
0, 1, 1, 1, 1, 1, 2, 2, 2, 2,
2, 3, 3, 3, 3, 4, 4, 5, 5, 5,
6, 7, 7, 8, 9, 9, 10, 11, 12, 13,
14, 16, 17, 19, 21, 22, 24, 27, 29, 32,
35, 38, 41, 45, 49, 54, 58, 64, 70, 76,
83, 90, 99,107,117,128,139,152,166,181,
197,215,235,256
Gamma array size: 64
Total PWM steps: 256
Gamma correction: .52
0, 2, 3, 4, 4, 5, 6, 6, 7, 8,
9, 10, 11, 12, 13, 15, 16, 17, 19, 20,
22, 24, 26, 28, 30, 32, 34, 37, 39, 42,
45, 48, 51, 54, 57, 61, 65, 68, 72, 77,
81, 86, 91, 96,101,107,112,118,125,131,
138,145,152,160,168,176,185,194,203,213,
223,234,244,256
I also wrote a Just BASIC program for the Maxim algorithm. If anyone wants me to post it, just ask.
Regards, Mike
post edited by K8LH - 2010/04/24 09:14:32
Attached Image(s)
