Friday 28 June 2019

Correcting for non-linear brightness in LEDs when using PWM


When driving an LED with PWM, the brightness (as I perceive it) does not scale linearly with duty cycle. The brightness is slow to ramp up, then increases exponentially with duty cycle.


Can anyone suggest a rule of thumb to use as a correction factor, or other workaround?



Answer



For 16 levels it's easy to do a simple look-up table "by hand" and convert the 4 bit value in an 8 bit value to pass to PWM controller: this is the component i've used in my FPGA led array driver. For an 8 bit level controller, you'll need at least 11-12 bit output from the look-up table.


library IEEE;
use IEEE.Std_logic_1164.all;

entity Linearize is
port ( reqlev : in std_logic_vector (3 downto 0) ;

pwmdrive : out std_logic_vector (7 downto 0) );
end Linearize;

architecture LUT of Linearize is
begin
with reqlev select
pwmdrive <= "00000000" when "0000",
"00000010" when "0001",
"00000100" when "0010",
"00000111" when "0011",

"00001011" when "0100",
"00010010" when "0101",
"00011110" when "0110",
"00101000" when "0111",
"00110010" when "1000",
"01000001" when "1001",
"01010000" when "1010",
"01100100" when "1011",
"01111101" when "1100",
"10100000" when "1101",

"11001000" when "1110",
"11111111" when "1111",
"00000000" when others;
end LUT;

No comments:

Post a Comment

arduino - Can I use TI&#39;s cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...