能輕鬆控製LCD顯示屏亮度的環境光傳感器(附源代碼)
發布時間:2017-02-23 來源:Ilya Veygman 責任編輯:wenwei
【導讀】本應用筆記主要講述采用MAX44009環境光傳感器控製便攜式設備(譬如智能手機和平板電腦)背bei光guang亮liang度du的de應ying用yong。針zhen對dui背bei光guang亮liang度du調tiao節jie,本ben文wen介jie紹shao了le兩liang種zhong不bu同tong的de控kong製zhi方fang案an。此ci外wai,本ben文wen還hai就jiu如ru何he獲huo得de更geng好hao的de控kong製zhi效xiao果guo提ti供gong了le相xiang關guan建jian議yi,同tong時shi也ye提ti供gong了le實shi現xian本ben文wen所suo述shu算suan法fa的de源yuan代dai碼ma。
引言
環境光傳感器(ALS)集成電路正越來越多地用於各種顯示器和照明設備,以節省電能,改善用戶體驗。借助ALSjiejuefangan,xitongshejishikegenjuhuanjingguangqiangdu,zidongtiaojiexianshipingdeliangdu。yinweibeiguangzhaomingdehaodianliangzaixitongdezonghaodianliangzhongzhanjuhendadebili,shixingdongtaidebeiguangliangdukongzhi,kejieshengdaliangdedianneng。ciwai,tahainenggougaishanyonghutiyan,rangxianshipingliangdugenjuhuanjingguangtiaojianzixingtiaozhengdaozuijiazhuangtai。
係統實現需要三大部分:監測環境光強的光傳感器、數據處理裝置(通常是微控製器)、控製背光輸入電流的執行器。
背光控製:環境光傳感器
圖1是shi實shi施shi背bei光guang控kong製zhi的de係xi統tong示shi範fan框kuang圖tu。在zai這zhe套tao組zu合he中zhong,光guang傳chuan感gan器qi是shi關guan鍵jian的de組zu成cheng部bu分fen,因yin為wei它ta要yao向xiang係xi統tong的de其qi他ta模mo塊kuai提ti供gong環huan境jing光guang強qiang信xin息xi。光guang傳chuan感gan器qi必bi須xu具ju備bei將jiang光guang信xin號hao轉zhuan換huan成cheng電dian信xin號hao的de信xin號hao轉zhuan換huan器qi(譬如光電二極管或CdS光敏電阻)和信號放大和/或調節裝置以及模/數轉換器(ADC)。

圖1. 實施背光控製的係統框圖
圖2所示為分立光電二極管電路,從圖中可以看出,該電路需要一個或多個運算放大器:一yi個ge用yong於yu電dian流liu到dao電dian壓ya的de轉zhuan換huan,可ke能neng還hai需xu要yao一yi級ji放fang大da,提ti供gong附fu加jia增zeng益yi。它ta還hai包bao括kuo一yi些xie分fen支zhi電dian路lu,用yong於yu供gong電dian,確que保bao高gao度du可ke靠kao的de信xin號hao鏈lian。而er在zai空kong間jian極ji其qi寶bao貴gui的de應ying用yong中zhong,所suo需xu元yuan件jian的de數shu量liang過guo多duo可ke能neng導dao致zhi空kong間jian受shou限xian問wen題ti。

圖2. 光電二極管電路分立設計
這裏還存在一個更細微的問題。具體而言,理想情況下,應確保環境光的測量模擬了人眼對光線的響應機製。這通常借助CIE提供的視覺亮度曲線(圖3)。然而,光電二極管很少能夠完全模擬這種響應機製,因為它們通常具有很高的紅外(IR)靈敏度。在IR強度較大的光照條件(譬如白熾燈或日光)下,這種紅外靈敏度會造成錯誤地判斷光線強度。
解決上述問題的方法之一是使用兩個光電二極管:一yi個ge采cai用yong對dui可ke見jian光guang和he紅hong外wai光guang都dou很hen敏min感gan的de元yuan件jian,另ling一yi個ge采cai用yong隻zhi對dui紅hong外wai光guang敏min感gan的de元yuan件jian。最zui終zhong用yong前qian者zhe的de響xiang應ying值zhi減jian去qu後hou者zhe的de響xiang應ying值zhi,將jiang紅hong外wai幹gan擾rao降jiang至zhi最zui小xiao,獲huo得de準zhun確que的de可ke見jian光guang響xiang應ying。
這種解決方案雖然有效,卻增加了分立電路的占用空間。通常還很難、甚至不可能讓兩個分立的光電二極管配合得足夠緊密,以實現消除紅外幹擾的目的。如果不配備精密放大器(譬如對數放大器),動態範圍可能很小。換句話說,很難利用這種組合獲得可重複的結果。

圖3. CIE曲線和典型的光電二極管
高集成度解決方案不僅能夠獲得比人眼光學係統更真實的光強數據,還能夠節省大量空間MAX44009等環境光傳感器,可將所有信號調節和模/數轉換器集成在一個小封裝(2mm x 2mm UTDFN封裝)內,從而在空間受限應用中有效節省電路板麵積。
圖4提供了MAX44009的功能框圖,采用I²C通tong信xin協xie議yi,使shi其qi與yu微wei控kong製zhi器qi的de連lian接jie方fang式shi更geng簡jian單dan,數shu據ju傳chuan輸shu速su度du更geng快kuai。除chu此ci之zhi外wai,該gai解jie決jue方fang案an的de高gao集ji成cheng特te性xing使shi其qi能neng夠gou置zhi於yu柔rou性xing電dian纜lan,安an裝zhuang在zai離li主zhu電dian路lu板ban距ju離li合he適shi的de位wei置zhi。

圖4. MAX44009功能框圖
背光控製:調節顯示屏亮度
該(gai)控(kong)製(zhi)方(fang)案(an)的(de)第(di)二(er)部(bu)分(fen)是(shi)調(tiao)節(jie)顯(xian)示(shi)屏(ping)的(de)背(bei)光(guang)亮(liang)度(du)。這(zhe)可(ke)通(tong)過(guo)多(duo)種(zhong)方(fang)式(shi)實(shi)現(xian),具(ju)體(ti)取(qu)決(jue)於(yu)設(she)備(bei)中(zhong)的(de)顯(xian)示(shi)屏(ping)模(mo)塊(kuai)。有(you)兩(liang)種(zhong)最(zui)簡(jian)單(dan)的(de)方(fang)式(shi),一(yi)種(zhong)是(shi)借(jie)助(zhu)脈(mai)衝(chong)寬(kuan)度(du)調(tiao)製(zhi)(PWM)方案的直接調節方式,另一種是采用顯示屏控製器的間接調節方式。
許(xu)多(duo)顯(xian)示(shi)屏(ping)模(mo)塊(kuai)如(ru)今(jin)都(dou)配(pei)有(you)一(yi)個(ge)集(ji)成(cheng)控(kong)製(zhi)器(qi),用(yong)戶(hu)可(ke)以(yi)通(tong)過(guo)向(xiang)控(kong)製(zhi)器(qi)發(fa)送(song)串(chuan)行(xing)命(ming)令(ling),直(zhi)接(jie)設(she)置(zhi)背(bei)光(guang)亮(liang)度(du)。如(ru)果(guo)顯(xian)示(shi)屏(ping)模(mo)塊(kuai)未(wei)配(pei)備(bei)集(ji)成(cheng)控(kong)製(zhi)器(qi),還(hai)可(ke)安(an)裝(zhuang)一(yi)個(ge)簡(jian)單(dan)的(de)背(bei)光(guang)控(kong)製(zhi)執(zhi)行(xing)器(qi),控(kong)製(zhi)顯(xian)示(shi)屏(ping)後(hou)麵(mian)用(yong)於(yu)背(bei)光(guang)照(zhao)明(ming)的(de)白(bai)光(guang)LED燈的輸入電流。實現這種控製的一種簡單辦法是:直接給LED串聯一個場效應晶體管(FET),使用PWM信號快速打開、關閉FET (圖5)。然而,也可以利用單一芯片(用於LED控製的MAX1698升壓轉換器)準確、可靠地調節(圖6),請參考應用筆記3866“Low-power PWM output controls LED brightness”,獲取詳細信息。

圖5. 簡單的PMW控製電路

圖6. 基於MAX1698的LED亮度調節器
背光控製:建立連接
最後一步就是在傳感器和執行器之間建立連接,通過微控製器實現。有人可能首先要問:“環境光強如何映射到背光亮度?”事實上,有些文獻專門介紹了相關方案。其中一種映射方式是,Microsoft®針對運行Windows® 7¹操作係統的計算機提出的。圖7所示曲線是由Microsoft提供的,它可以將環境光強度映射到顯示屏亮度(以全部亮度的百分比表示)。

圖7. 將環境光強映射為最佳顯示屏亮度的曲線示例
這種特殊曲線可以用以下函數表示:
如果設備采用的是已集成亮度控製功能的LCD控製芯片,就可通過向芯片發送指令,輕鬆設置背光亮度。如果設備采用的是PWM直接控製亮度,則要考慮如何將比例信號映射至顯示屏亮度。
在MAX1698示例中,根據其產品說明書的介紹,可以將驅動電流映射為電壓。通過這個示例,我們可以假設LED電流強度幾乎與其電流呈線性關係。這樣,我們就可以在上述等式中乘上一個係數,計算出PWM所映射的有效電壓,該電壓再被映射至LED電流,最後轉化成顯示屏亮度。
方案實施
最zui好hao不bu要yao從cong一yi個ge亮liang度du級ji直zhi接jie跳tiao轉zhuan到dao另ling一yi個ge亮liang度du級ji,而er是shi平ping滑hua上shang調tiao和he下xia調tiao背bei光guang亮liang度du,確que保bao不bu同tong亮liang度du等deng級ji之zhi間jian無wu縫feng過guo渡du。為wei了le達da到dao這zhe一yi目mu的de,最zui好hao采cai用yong帶dai有you固gu定ding或huo不bu同tong亮liang度du步bu長chang、可逐步調節亮度的定時中斷,也可采用帶有可控製LED輸入電流的PWM值的定時中斷,或者是能夠發送到顯示屏控製器的串行指令的定時中斷。圖8提供了這種算法的一個示例。

圖8. 步進式亮度調節的算法示例
另一個問題是,係統響應環境光強變化的速度。我們應盡量避免過快地改變亮度等級。這是因為光強的瞬間變化(譬如一扇窗戶打開或瞬間有一束光掃過)可ke能neng導dao致zhi背bei光guang亮liang度du發fa生sheng不bu必bi要yao的de變bian化hua,這zhe往wang往wang會hui造zao成cheng用yong戶hu感gan覺jiao不bu適shi。並bing且qie,較jiao長chang的de響xiang應ying時shi間jian還hai有you助zhu於yu減jian少shao微wei控kong製zhi器qi對dui光guang傳chuan感gan器qi的de檢jian測ce次ci數shu,從cong而er可ke以yi釋shi放fang一yi定ding的de微wei控kong製zhi器qi資zi源yuan。
最(zui)初(chu)級(ji)的(de)方(fang)法(fa)就(jiu)是(shi)每(mei)隔(ge)一(yi)兩(liang)秒(miao)鍾(zhong)檢(jian)查(zha)一(yi)次(ci)光(guang)傳(chuan)感(gan)器(qi),然(ran)後(hou)相(xiang)應(ying)地(di)調(tiao)整(zheng)背(bei)光(guang)亮(liang)度(du)。更(geng)好(hao)的(de)方(fang)法(fa)是(shi),隻(zhi)有(you)光(guang)線(xian)強(qiang)度(du)偏(pian)離(li)特(te)定(ding)範(fan)圍(wei)一(yi)定(ding)時(shi)間(jian)後(hou),才(cai)對(dui)背(bei)光(guang)亮(liang)度(du)進(jin)行(xing)調(tiao)節(jie)。譬(pi)如(ru),如(ru)果(guo)正(zheng)常(chang)光(guang)強(qiang)是(shi)200lux,我們可能隻會在光強降到180lux以下或升至220lux以上,而且持續時間超過數秒的情況下才調節亮度。幸運的是,MAX44009集成了中斷引腳和閾值寄存器,可輕鬆實現這個目的。
附錄:源代碼
#define MAX44009_ADDR 0x96
// begin definition of slave addresses for MAX44009
#define INT_STATUS 0x00
#define INT_ENABLE 0x01
#define CONFIG_REG 0x02
#define HIGH_BYTE 0x03
#define LOW_BYTE 0x04
#define THRESH_HIGH 0x05
#define THRESH_LOW 0x06
#define THRESH_TIMER 0x07
// end definition of slave addresses for MAX44009
extern float SCALE_FACTOR; // captures scaling factors to map from % brightness to PWM
float currentBright_pct; // the current screen brightness, in % of maximum
float desiredBright_pct; // the desired screen brightness, in % of maximum
float stepSize; // the step size to use to go from the current
// brightness to the desired brightness
uint8 lightReadingCounter;
/**
* Function: SetPWMDutyCycle
*
* Arguments: uint16 dc - desired duty cycle
*
* Returns: none
*
* Description: Sets the duty cycle of a 16-bit PWM, assuming that in this
* architecture, 0x0000 = 0% duty cycle
* 0x7FFF = 50% and 0xFFFF = 100%
**/
extern void SetPWMDutyCycle(uint16 dc);
/**
* Function: I2C_WriteByte
*
* Arguments: uint8 slaveAddr - address of the slave device
* uint8 command - destination register in slave device
* uint8 data - data to write to the register
*
* Returns: ACK bit
*
* Description: Performs necessary functions to send one byte of data to a
* specified register in a specific device on the I2C bus
**/
uint8 2C_WriteByte(uint8 slaveAddr, uint8 command, uint8 data);
/**
* Function: I2C_ReadByte
*
* Arguments: uint8 slaveAddr - address of the slave device
* uint8 command - destination register in slave device
* uint8 *data - pointer data to read from the register
*
* Returns: ACK bit
*
* Description: Performs necessary functions to get one byte of data from a
* specified register in a specific device on the I2C bus
**/
uint8 I2C_ReadByte(uint8 slaveAddr, uint8 command, uint8* data);
/**
* Function: getPctBrightFromLuxReading
*
* Arguments: float lux - the pre-computed ambient light level
*
* Returns: The % of maximum brightness to which the backlight should be set
* given the ambient light (0 to 1.0)
*
* Description: Uses a function to map the ambient light level to a backlight
* brightness by using a predetermined function
**/
float getPctBrightFromLuxReading(float lux);
/**
* Function: mapPctBrighttoPWM
*
* Arguments: float pct
*
* Returns: PWM counts needed to achieve the specified % brightness (as
* determined by some scaling factors)
**/
uint16 mapPctBrighttoPWM(float pct);
/**
* Function: getLightLevel
*
* Arguments: n/a
*
* Returns: the ambient light level, in lux
*
* Description: Reads both the light registers on the device and returns the
* computed light level
**/
float getLightLevel(void);
/**
* Function: stepBrightness
*
* Arguments: n/a
*
* Returns: n/a
*
* Description: This function would be called by an interrupt. It looks at the
* current brightness setting, then the desired brightness setting.
* If there is a difference between the two, the current brightness
* setting is stepped closer to its goal.
**/
void stepBrightness(void);
/**
* Function: timerISR
*
* Arguments: n/a
*
* Returns: n/a
*
* Description: An interrupt service routine which fires every 100ms or so. This
* handles all the ambient light sensor and backlight
* control code.
**/
void timerISR(void);
void main() {
SetupMicro(); // some subroutine which initializes this CPU
I2C_WriteByte(MAX44009_ADDR, CONFIG_REG, 0x80); // set to run continuously
lightReadingCounter = 0;
stepSize = .01;
currentBright_pct = 0.5;
desiredBright_pct = 0.5;
SetPWMDutyCycle(mapPctBrighttoPWM(currentBright_pct));
InitializeTimerInterrupt(); // set this to fire every 100ms
while(1) {
// do whatever else you need here, the LCD control is done in interrupts
Idle();
}
} // main routine
// the point at which the function clips to 100%
#define MAXIMUM_LUX_BREAKPOINT 1254.0
float getPctBrightFromLuxReading(float lux) {
if (lux > MAXIMUM_LUX_BREAKPOINT)
return 1.0;
else
return (9.9323*log(x) + 27.059)/100.0;
} // getPctBrightFromLuxReading
uint16 mapPctBrighttoPWM(float pct) {
return (uint16)(0xFFFF * pct * SCALE_FACTOR);
} // mapPctBrighttoPWM
float getLightLevel(void) {
uint8* lowByte;
uint8* highByte;
uint8 exponent;
uint8 mantissa;
float result;
I2C_ReadByte(MAX44009_ADDR, HIGH_BYTE, highByte);
I2C_ReadByte(MAX44009_ADDR, LOW_BYTE, lowByte);
exponent = (highByte & 0xF0) >> 4;// upper four bits of high byte register
mantissa = (highByte & 0x0F) << 4;// lower four bits of high byte register =
// upper four bits of mantissa
mantissa += lowByte & 0x0F; // lower four bits of low byte register =
// lower four bits of mantissa
result = mantissa * (1 << exponent) * 0.045;
return result;
} //getLightLevel
void stepBrightness(void) {
// if current is at desired, don''t do anything
if (currentBright_pct == desiredBright_pct)
return;
// is the current brightness above the desired brightness?
else if (currentBright_pct > desiredBright_pct) {
// is the difference between the two less than one step?
if ( (currentBright_pct-stepSize) < desiredBright_pct)
currentBright_pct = desiredBright_pct;
else
currentBright_pct -= stepSize;
} // else if
else if (currentBright_pct < desiredBright_pct) {
// is the difference between the two less than one step?
if ( (currentBright_pct+stepSize) > desiredBright_pct)
currentBright_pct = desiredBright_pct;
else
currentBright_pct += stepSize;
} // else if
SetPWMDutyCycle(mapPctBrighttoPWM(currentBright_pct));
return;
} // stepBrightness
void timerISR(void) {
float lux;
float pctDiff;
stepBrightness();
if (lightReadingCounter)
lightReadingCounter--;
else {
lightReadingCounter = 20; // 2 second delay
lux = getLightLevel();
desiredBright_pct = getPctBrightFromLuxReading(lux);
pctDiff = abs(desiredBright_pct - currentBright_pct);
stepSize = (pctDiff <= 0.01) ? 0.01:pctDiff/10;
} // else
ClearInterruptFlag();
} // timerISR
本文來源於Maxim。
推薦閱讀:
特別推薦
- 噪聲中提取真值!瑞盟科技推出MSA2240電流檢測芯片賦能多元高端測量場景
- 10MHz高頻運行!氮矽科技發布集成驅動GaN芯片,助力電源能效再攀新高
- 失真度僅0.002%!力芯微推出超低內阻、超低失真4PST模擬開關
- 一“芯”雙電!聖邦微電子發布雙輸出電源芯片,簡化AFE與音頻設計
- 一機適配萬端:金升陽推出1200W可編程電源,賦能高端裝備製造
技術文章更多>>
- 2026藍牙亞洲大會暨展覽在深啟幕
- 新市場與新場景推動嵌入式係統研發走向統一開發平台
- 維智捷發布中國願景
- 2秒啟動係統 • 資源受限下HMI最優解,米爾RK3506開發板× LVGL Demo演示
- H橋降壓-升壓電路中的交替控製與帶寬優化
技術白皮書下載更多>>
- 車規與基於V2X的車輛協同主動避撞技術展望
- 數字隔離助力新能源汽車安全隔離的新挑戰
- 汽車模塊拋負載的解決方案
- 車用連接器的安全創新應用
- Melexis Actuators Business Unit
- Position / Current Sensors - Triaxis Hall
熱門搜索
Tektronix
Thunderbolt
TI
TOREX
TTI
TVS
UPS電源
USB3.0
USB 3.0主控芯片
USB傳輸速度
usb存儲器
USB連接器
VGA連接器
Vishay
WCDMA功放
WCDMA基帶
Wi-Fi
Wi-Fi芯片
window8
WPG
XILINX
Zigbee
ZigBee Pro
安規電容
按鈕開關
白色家電
保護器件
保險絲管
北鬥定位
北高智

