• AVR Freaks

RGB LED driving using PWM

Page: < 123 > Showing page 2 of 3
Author
OldZ80
Starting Member
  • Total Posts : 51
  • Reward points : 0
  • Joined: 2007/04/29 18:08:35
  • Status: offline
RE: RGB LED driving using PWM 2010/03/03 17:33:08 (permalink)
0
There is another person who has been posting questions on controlling a 3 colour LED. shortly after yours.
 I suggest that you also look at that. If you want more colours then you need to step more slowly  through the range so that you get more intermediate values.  Otherwise replace the sine table with a table containing  sets of 3 fixed values which you have chosen experimentally to give the right effect.   If the colour sequence changes too rapidly, you can re-write the same values several time before it changes

OldZ80
#21
akp25i
New Member
  • Total Posts : 18
  • Reward points : 0
  • Joined: 2009/04/18 03:23:42
  • Location: 0
  • Status: offline
RE: RGB LED driving using PWM 2010/03/07 22:17:40 (permalink)
0
Thanks ,
I have seen those posts ,
instead of sine color table , i am directly incrementing , decrementing , RGB led's duty cycle
, from keyboard , and i can see those values in hexadecimal on LCD , but generation of a
color seems to be more complex , For example , on Windows "paintbrush " program , by choosing
"define custom color " we can give 0-255 , numbers to all three colors , then a custom color will appear for
a certain combination of RGB values ,but if i do that on LED's , by giving those same numbers as
duty cycle of RGB PWM , i will not get same color as i get on paintbrush ,
If a color is 50%Red ,30%Green , 45% Blue , it is ratio of "Brightness " of colors ?
Now brightness ratings of 3 leds in RGB led is not same , there current ratings are also not same ,
if by experiment i adjust the resistors values such that equal current flows through R ,G and B leds ;
even then the brightness of Red led will be more , how to perfectly adjust this "brightness " ;

I can not find any application note on RGB LED manufacturer 's website giving description of color generation ,
In construction of multicolor led display's some "diffuser" is used to mix the output of 3 LED's;

If we increase the bits of duty cycle from 8 to 10 or 12 bits will it increase number of colors.

Amit
#22
DarioG
Allmächtig.
  • Total Posts : 54081
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: Oesterreich
  • Status: offline
RE: RGB LED driving using PWM 2010/03/08 02:06:21 (permalink)
0
Wow Smile this is an old one!
I've done that Paintbrush thing back in 2002.

Yes, the leds will have a different "color per lumen" strength for each of the channel. It was somehow solved using a separate LM317 regulator for each color, hand-trimmed. Now possibly there are better drivers...

Increasing PWM steps surely helps, but the above is needed to make sure that when you do 100% of R, G and B the resulting color is plain white.

A lookup-table to linearize each channel *can* be used later, if needed.

GENOVA :D :D ! GODO
#23
K8LH
Super Member
  • Total Posts : 1887
  • Reward points : 0
  • Joined: 2004/03/26 05:12:34
  • Location: Michigan, USA
  • Status: offline
RE: RGB LED driving using PWM 2010/03/08 04:43:14 (permalink)
0
ORIGINAL: DarioG
........

A lookup-table to linearize each channel *can* be used later, if needed.


Curious if anyone has worked out a good "gamma" correction table, say 64 level to 256 level, for RGB or monocolor LED brightness characteristics?

Mike
#24
DarioG
Allmächtig.
  • Total Posts : 54081
  • Reward points : 0
  • Joined: 2006/02/25 08:58:22
  • Location: Oesterreich
  • Status: offline
RE: RGB LED driving using PWM 2010/03/08 07:03:57 (permalink)
0
I have one, but it does not distinguish among the 3 channels: it's more useful to linearize the steps at lower-levels.

GENOVA :D :D ! GODO
#25
akp25i
New Member
  • Total Posts : 18
  • Reward points : 0
  • Joined: 2009/04/18 03:23:42
  • Location: 0
  • Status: offline
RE: RGB LED driving using PWM 2010/03/08 21:29:30 (permalink)
0
Smile Dario G ,

Thanks for your suggestion , i will try this.

Amit
#26
rshr
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2010/04/06 06:37:51
  • Location: 0
  • Status: offline
RE: RGB LED driving using PWM 2010/04/06 07:24:27 (permalink)
0
Hi,

I would like to adjust the code described in AN1074.

I want to use a potentiometer to adjust colors in the tri-color LED vs automatic sweep function as described in AN1074.

Is there an easy way to do it?

Roman
#27
akp25i
New Member
  • Total Posts : 18
  • Reward points : 0
  • Joined: 2009/04/18 03:23:42
  • Location: 0
  • Status: offline
RE: RGB LED driving using PWM 2010/04/06 20:56:00 (permalink)
0
AN 1074 uses a potentiometer to control color sweep speed for RGB leds, in the same way you can connect 3 potentiometers to 3 ADC input pins of PIC and sample them , AN1074 uses a lookup table to get PWM duty cycle for RGB leds , you can calculate the duty cycle from the ADC sample value for potentiometers , this will be similar to directly controlling the base current of LED driving transistor via potentiometer , the microcontroller used in AN1071 PIC12HV615 has 4 ADC inputs , but those pins are being used for driving RGB LED's transistor , so you will have to choose some other PIC with more I/O pins.


Amit
#28
lbodnar
Super Member
  • Total Posts : 1148
  • Reward points : 0
  • Joined: 2005/12/18 06:06:09
  • Location: UK
  • Status: offline
RE: RGB LED driving using PWM 2010/04/23 03:34:23 (permalink)
+2 (1)
ORIGINAL: K8LH
Curious if anyone has worked out a good "gamma" correction table, say 64 level to 256 level, for RGB or monocolor LED brightness characteristics?

I use 256 entries antilogarithmic table to translate 8 bit perceived brightness into 10 bit PWM value in this display. It has 27 independent brightness channels for all LEDs and displays at very high refresh rate - when you swing it around in the darks LEDs look like incandescent bulbs if you know what I mean. Works beautifully http://www.youtube.com/watch?v=fGyAK-VkBAo . :)

Just use two columns in Excel and then paste the second one into your code. E.g. for 64 -> 256 try this one
   db .0
db .1
db .1
db .1
db .1
db .2
db .2
db .2
db .2
db .2
db .2
db .3
db .3
db .3
db .3
db .4
db .4
db .4
db .5
db .5
db .6
db .6
db .7
db .8
db .8
db .9
db .10
db .11
db .12
db .13
db .14
db .15
db .17
db .18
db .20
db .22
db .24
db .26
db .28
db .31
db .34
db .37
db .40
db .44
db .48
db .52
db .57
db .62
db .68
db .74
db .81
db .89
db .97
db .106
db .116
db .126
db .138
db .150
db .164
db .179
db .196
db .214
db .234
db .255
post edited by lbodnar - 2010/04/23 03:45:32

Leo
#29
K8LH
Super Member
  • Total Posts : 1887
  • Reward points : 0
  • Joined: 2004/03/26 05:12:34
  • Location: Michigan, USA
  • Status: offline
RE: RGB LED driving using PWM 2010/04/23 04:00:31 (permalink)
0
Hi Leo,

Very nice display.  What are all those ICs on the PCB?

Your "gamma" table looks great and now I see what I am doing wrong on mine.  Thank you...

Regards, Mike
post edited by K8LH - 2010/04/23 04:31:32
#30
lbodnar
Super Member
  • Total Posts : 1148
  • Reward points : 0
  • Joined: 2005/12/18 06:06:09
  • Location: UK
  • Status: offline
RE: RGB LED driving using PWM 2010/04/23 04:39:28 (permalink)
+2 (1)
I meant, use 2^x formula in Excel and paste the result in the code.
Exact formula used above is =" db ." & INT(255^(x/64)+.5) and first entry was manually replaced with zero.


These ICs are simple SPI LED drivers - each segment has independent driver output. Brightness is still controlled via software PWM. I did not want displays multiplexing because it is extremely irritating. Especially in the dark environment with lots of movement (both display and eyes.) I am a bit of a perfectionist :)


Cheers
Leo
post edited by lbodnar - 2010/04/23 09:31:42
#31
Stefan Uhlemayr
Super Member
  • Total Posts : 4292
  • Reward points : 0
  • Joined: 2005/05/12 12:25:46
  • Location: Germany
  • Status: offline
RE: RGB LED driving using PWM 2010/04/23 04:43:15 (permalink)
0
ORIGINAL: lbodnar

I meant, use 2^x formula in Excel and paste the result in the code.
Exact formula used above is =" db ." & INT(255^(x/64)+.5) and first antry manually replaced with zero. ...
Hi Leo,

thanks for posting both the table and the formula behind. Have added a link to this info to the "software-gallery". wink

Greetings,
Stefan
#32
K8LH
Super Member
  • Total Posts : 1887
  • Reward points : 0
  • Joined: 2004/03/26 05:12:34
  • Location: Michigan, USA
  • Status: offline
RE: RGB LED driving using PWM 2010/04/23 15:12:25 (permalink)
0
ORIGINAL: lbodnar

These ICs are simple SPI LED drivers - each segment has independent driver output. Brightness is still controlled via software PWM.....


Software PWM per segment via SPI command to driver IC?  Or, software pwm per digit via PIC PWM signal to driver IC output enable pin?  Or, software pwm for entire display, discrete and 7-segment, sort of like dashboard dimmer?

Regards, Mike
post edited by K8LH - 2010/04/23 15:18:59
#33
lbodnar
Super Member
  • Total Posts : 1148
  • Reward points : 0
  • Joined: 2005/12/18 06:06:09
  • Location: UK
  • Status: offline
RE: RGB LED driving using PWM 2010/04/23 15:17:01 (permalink)
0
ORIGINAL: K8LH
Software PWM per segment via SPI command to driver IC?  Or, software pwm per digit via PIC PWM signal to driver IC output enable pin?
Regards, Mike
Software PWM per segment via SPI command to driver ICs. I don't have individual brightness for each of display segments! Only for left side, central display and right side + all 24 LEDs individually.
Oh, I forgot! There is an independent global brightness control via hardware PWM -> enable pin as well but it acts on all drivers at the same time [8D]

Leo
#34
K8LH
Super Member
  • Total Posts : 1887
  • Reward points : 0
  • Joined: 2004/03/26 05:12:34
  • Location: Michigan, USA
  • Status: offline
RE: RGB LED driving using PWM 2010/04/23 15:32:21 (permalink)
0
Thank you Leo.  I think I see what you're doin' on that product now.  Looks like eight 16-bit drivers for 128 LEDs with PWM brightness control in the drivers and from your mcu.

Congrats' on a very nice product.

Thank you for straightening me out on how to build a decent "gamma" table...

Regards, Mike
post edited by K8LH - 2010/04/23 15:33:30
#35
K8LH
Super Member
  • Total Posts : 1887
  • Reward points : 0
  • Joined: 2004/03/26 05:12:34
  • Location: Michigan, USA
  • Status: offline
RE: RGB LED driving using PWM 2010/04/23 15:49:40 (permalink)
0
Just tested that "gamma" table on a 20-LED Charlieplexed display with a 790-Hz refresh rate and 8-bit BAM (Bit Angle Modulation) 256 step soft' PWM driver and it looks pretty nice.  Here's the circuit I'm using;
[image]local://22956/988BAB479E0A4F6AB17FBB517CD4644E.JPG[/image]

You don't have to build that entire circuit to check out the fading effect.  The demo' program is only fading LED #0 through 64 "gamma" steps so just breadboard up a 12F683 to VDD and ground (don't forget the bypass cap') and connect a single LED with anode to VDD and cathode to GP5.  The program source code (assembler) is in one of the attachments below.

Regards, Mike, K8LH
post edited by K8LH - 2010/04/27 08:30:36

Attached Image(s)

#36
K8LH
Super Member
  • Total Posts : 1887
  • Reward points : 0
  • Joined: 2004/03/26 05:12:34
  • Location: Michigan, USA
  • Status: offline
RE: RGB LED driving using PWM 2010/04/23 17:31:43 (permalink)
0
Just threw this together quickly using free JustBASIC interpreter;

'  Leo Bodnar's 'antilogarithmic'
'  gamma correction algorithm
'
'  JustBASIC (free) interpreter
'
Input "Gamma steps: "; steps
Input "  PWM steps: "; range

PRINT
FOR i = 0 TO steps-1                    '
  x = INT(range^((i+1)/steps)+.3)       '
  if(i=0) then x = 0                    '
  PRINT "  gamma ";                     '
  if(steps > 100) then                  '
    if(i<100) then PRINT " ";           '
  end if                                '
  if(i<10) then PRINT " ";              '
  PRINT i;                              '
  PRINT " = duty cycle ";               '
  if(x < 100) then PRINT "0";           '
  if(x <  10) then PRINT "0";           '
  PRINT x                               '
NEXT i                                  '

REM CLOSE


Here's the output.  Probably should be formatted in a more friendly "array" or "table" format suitable for "copy and paste" but.....

Gamma steps: 64
  PWM steps: 255

  gamma  0 = duty cycle 000
  gamma  1 = duty cycle 001
  gamma  2 = duty cycle 001
  gamma  3 = duty cycle 001
  gamma  4 = duty cycle 001
  gamma  5 = duty cycle 001
  gamma  6 = duty cycle 002
  gamma  7 = duty cycle 002
  gamma  8 = duty cycle 002
  gamma  9 = duty cycle 002
  gamma 10 = duty cycle 002
  gamma 11 = duty cycle 003
  gamma 12 = duty cycle 003
  gamma 13 = duty cycle 003
  gamma 14 = duty cycle 003
  gamma 15 = duty cycle 004
  gamma 16 = duty cycle 004
  gamma 17 = duty cycle 005
  gamma 18 = duty cycle 005
  gamma 19 = duty cycle 005
  gamma 20 = duty cycle 006
  gamma 21 = duty cycle 007
  gamma 22 = duty cycle 007
  gamma 23 = duty cycle 008
  gamma 24 = duty cycle 009
  gamma 25 = duty cycle 009
  gamma 26 = duty cycle 010
  gamma 27 = duty cycle 011
  gamma 28 = duty cycle 012
  gamma 29 = duty cycle 013
  gamma 30 = duty cycle 014
  gamma 31 = duty cycle 016
  gamma 32 = duty cycle 017
  gamma 33 = duty cycle 019
  gamma 34 = duty cycle 021
  gamma 35 = duty cycle 022
  gamma 36 = duty cycle 024
  gamma 37 = duty cycle 027
  gamma 38 = duty cycle 029
  gamma 39 = duty cycle 032
  gamma 40 = duty cycle 035
  gamma 41 = duty cycle 038
  gamma 42 = duty cycle 041
  gamma 43 = duty cycle 045
  gamma 44 = duty cycle 049
  gamma 45 = duty cycle 053
  gamma 46 = duty cycle 058
  gamma 47 = duty cycle 064
  gamma 48 = duty cycle 069
  gamma 49 = duty cycle 076
  gamma 50 = duty cycle 083
  gamma 51 = duty cycle 090
  gamma 52 = duty cycle 098
  gamma 53 = duty cycle 107
  gamma 54 = duty cycle 117
  gamma 55 = duty cycle 127
  gamma 56 = duty cycle 139
  gamma 57 = duty cycle 151
  gamma 58 = duty cycle 165
  gamma 59 = duty cycle 180
  gamma 60 = duty cycle 196
  gamma 61 = duty cycle 214
  gamma 62 = duty cycle 234
  gamma 63 = duty cycle 255

#37
K8LH
Super Member
  • Total Posts : 1887
  • Reward points : 0
  • Joined: 2004/03/26 05:12:34
  • Location: Michigan, USA
  • Status: offline
RE: RGB LED driving using PWM 2010/04/24 08:29:08 (permalink)
0
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)

#38
lbodnar
Super Member
  • Total Posts : 1148
  • Reward points : 0
  • Joined: 2005/12/18 06:06:09
  • Location: UK
  • Status: offline
RE: RGB LED driving using PWM 2010/04/24 09:00:24 (permalink)
0
Interesting find! Now this may get very confusing! Especially since Maxim have no idea of what they are talking about Smile Quote: Gamma correction is used to correct for the nonlinear relationship between luminance and brightness. Wrong.

Gamma correction is a process of linearising response of a non-linear imaging device, namely CRTs. http://en.wikipedia.org/wiki/Gamma_correction
It has nothing to do with human perception! The output of a CRT is light=voltage^2.5 therefore CRT display images need to be artificially gamma-corrected to counter-balance this non-linearity.
All JPG images as a result have this correction embedded! Analogue TV signal has gamma-correction applied in the studio, etc.
If you were to display JPG on a display made of LEDs you will get very washed-out image because JPG coding assumes that display is non-linear (CRT) while it is highly linear (LEDs.)
Therefore LED RGB display needs to counter-correct image gamma correction by applying reverse POWER function x=y^a


On the other hand human perception of brightness is logarithmic as established by Webber
If you want to make linear light source (e.g an LED) progressively brighter you need to apply luminance levels 1 2 4 8 16 32, etc. This is exponential (antilogarithmic) law.
x = a^y

Combining these two together:
if you want to make LED progressively brighter you need to apply current (or duty ratio)... 1 2 4 8 16 32
if you want to make TV or CRT screen progressively brighter you need to apply voltages 1.0 1.3 1.7 2.3 3.0 4.0

I hope this makes sense now! [8D]

The Maxim app note makes sense for someone developing an RGB LED display for images or TV pictures. I.e. the graphics decoder produces gamma-corrected image that needs "un-correcting"
post edited by lbodnar - 2010/04/24 09:23:45

Leo
#39
K8LH
Super Member
  • Total Posts : 1887
  • Reward points : 0
  • Joined: 2004/03/26 05:12:34
  • Location: Michigan, USA
  • Status: offline
RE: RGB LED driving using PWM 2010/04/24 09:47:47 (permalink)
0
Hi Leo,

That is very interesting and informative.  Thank you.

Yesterday when I tested the duty cycle array from your algorithm I was delighted at the improvement in perceived linearity but I also noticed that brightness seemed a little "hot" at the high end.

When I came across the Maxim article and compared the duty cycle array output in graphs I was kind of tickled to see that I could "bend" that duty cycle arc and I thought that maybe that's what I needed for the LED fading demo' to smooth out the "hot" high end by perhaps pumping up the duty cycle arc in the middle a little bit.

So I guess I'm not sure why you're dismissing the Maxim algorithm so quickly.  I should mention that you can adjust the "gamma correction factor" in the Maxim algorithm to produce almost the same duty cycle array output as your algorithm.

Kind regards, Mike




#40
Page: < 123 > Showing page 2 of 3
Jump to:
© 2021 APG vNext Commercial Version 4.5