设为首页 帮助中心   收藏本页
会员登录  |  注册新用户
首页>封装技术>用查找表实现对LED的亮度等级修正 (Maxim / 英)

用查找表实现对LED的亮度等级修正 (Maxim / 英)


添加时间:2012-05-30 | 返回首页
更多

Using Lookup Tables to Perform Gamma Correction on
Gamma correction is used to correct for the nonlinear relationship between luminance and brightness. This application note presents an assembly program written for the MAXQ2000 microcontroller (µC) that uses gamma correction with a fixed-frequency PWM signal to linearly increase and decrease the brightness of an LED. The PWM duty cycles, stored in a Lookup Table (LUT) located in Utility ROM memory, are gamma corrected to produce linear brightness changes. The software compiles using the free MAX-IDE development tool and runs on the MAXQ2000 evaluation kit.

Background

When an LED emits light, gamma correction is used to account for the power-law relationship between luminance and brightness. Although often used interchangeably, luminance and brightness are not synonyms.

Luminance: The emitted light, projected per unit area measured in cd/m2 (candela/ meter2).

Brightness: The perceived luminance attributed by the human eye.

The power-law relationship can be approximated by:

In this discussion, is equal to 2.5.

Controlling the LED Intensity

Appendix A is an assembly program that linearly ramps-up and ramps-down the brightness of an LED. The intensity values have been gamma corrected to approximate a linear change in brightness.

The LED is controlled using PWM. Timer 0 generates the PWM signal on P0.0 (visible on LED3 of U11 on the MAX2000 evaluation kit) and is set for 16-bit reload/compare timer mode. In this mode, Timer 0 generates two interrupt requests (IRQs): one on timer overflow, and one when the timer is equal to the compared value in T2C0. Figure 1 illustrates how this process creates a PWM signal. Note that the Overflow IRQ controls the PWM period, while the Compare IRQ controls the PWM duty cycle.


Figure 1. Using Timer 0 to generate a PWM signal.

Timer 1 is used to change Timer 0's PWM duty cycle, and, therefore, change the intensity of the LED. Every 50 milliseconds, Timer 1 generates an overflow IRQ that loads a new value from a lookup table (LUT) into the T2C0 register.

Calculating the gamma-corrected PWM duty cycles was done using equation 2, where:

  • T2C0 = gamma-corrected compare value for Timer 0
  • T2C0 = non-gamma-corrected compare value for Timer 0
  • = gamma-correcting factor (i.e., 2.5)
  • counts is the number of timer steps between reloads on Timer 0 (i.e., 10000h-0C000h = 04000h)
  • offset is the Timer 0 reload value (i.e., 0C000h)

With a Timer 0 reload value of 0C000h, for example, 04000h timer steps occur between each reload. Assuming that 32 PWM duty cycles were used to increase the intensity of the LED and based on the LUT, the non-gamma-corrected compare values for Timer 0 (T2C0) would be:

0C000h
0C200h
0C400h
...
0FA00h
0FC00h
0FE00h
The difference between each value is 0200h, or 04000h divided by 32. Using equation 2 to apply gamma correction to the values above, yields the following values for T2C0 (Figure 2):
0C000h
0C002h
0C010h
...
0F209h
0F676h
0FB1Dh
The source code in Appendix A adjusted these values slightly to eliminate timer problems. Timer 0, for example, does not stop when an IRQ occurs. Care must be taken, therefore, to ensure that the reload value is not close to the compare value (i.e., T2C0 - T2R0 > some minimum positive value).


Figure 2. Gamma corrected T2C0.

Using Lookup Tables (LUTs)

The PWM duty-cycle values mentioned previously are stored in a LUT in the MAXQ2000 microcontroller's program memory. While using program memory for constants and LUTs frees data memory, it does require longer access time.

The Utility ROM function, moveDP1, is used to retrieve data from program memory (see MAXQ Family User's Guide: MAXQ2000 Supplement). Note that because future revisions of the Utility ROM may not be at the same location in the MAXQ2000's ROM, the user should load the address of each function from the Utility ROM function table stored at address 0800Dh. Fortunately, this can be done during program initialization and the function addresses can be saved for use later in the program.

The source code in Appendix A loads the address of the moveDP1 Utility ROM function into the A[4] register, and uses this saved address to call the function.

Conclusion

Using LUTs to save the results of precomputed calculations can significantly increase firmware execution speed. If the LUT is saved in program memory, the MAXQ2000 Utility ROM functions quickly access the data. To further increase firmware execution speed, the MAXQ2000 can load the LUT data from program memory into SRAM at program initialization.

Download: Firmware and project files (ZIP, 18kB)

Appendix A. Assembly Source Code

Download Appendix A
(PDF, 29.92kB)


站内导航

注册帮助 | 国际LED网 | 关于我们 | 联系方式 | 网站地图 | 广告服务 | 意见建议 | LED网 | 中国LED网 | LED照明 | LED显示屏 | LED灯 | LED路灯
服务热线:(0755)36527366,(0755)36527388  | ©2006-2022  All Rights Reserved.
中国互联网
协会网络诚
信推进联盟
深圳网络警
察报警平台盟
公共信息安
全网络监察
不良信息
举报中心
中国文明
网传播文明
网站版权所有:深圳鼎盛创媒 | 粤ICP备07055621号
免责声明:本站所载内容,凡注明署名的,其版权属于署名者所有,转载请注明署名。
本站未注明来源ledwang.com之稿件均为转载稿,如本网转载涉及版权等问题,请作者速来电或发邮件与ledwang.com联系,我们将在第一时间删除。
请遵守《互联网电子公告服务管理规定》及中华人民共和国其他各项有关法律法规。
严禁发表危害国家安全、损害国家利益、破坏民族团结、破坏国家宗教政策、破坏社会稳定、侮辱、诽谤、教唆、淫秽等内容。