音影先锋亚洲天堂网|电影世界尽头的爱完整版播放|国产 熟女 91|高清无码免费观看欧美日韩|韩国一区二区三区黄色录像|美女亚洲加勒比在线|亚洲综合网 开心五月|7x成人在线入口|成人网站免费日韩毛片区|国产黄片?一级?二级?三级

MAX9635環(huán)境光傳感器的接口程序

出處:xyluck1786 發(fā)布于:2011-01-27 11:34:03

     摘要:這篇應(yīng)用筆記介紹了如何合理使用MAX9635環(huán)境光傳感器的中斷輸出功能,適用于智能手機、平板電腦等便攜設(shè)備的LCD背光。利用中斷功能可以針對多個照明區(qū)間設(shè)置不同的門限值,無需重復(fù)查詢光傳感器。合理使用中斷功能,可以將系統(tǒng)保持在低功耗休眠狀態(tài),或用于執(zhí)行用戶定義的其它任務(wù)。中斷功能極大地提升了系統(tǒng)能效,改善了系統(tǒng)性能和用戶在不同照明條件下的體驗。本文還給出了I?C接口的C語言例程,用于中斷操作。

  概述

  MAX9635環(huán)境光傳感器用于檢測環(huán)境光的亮度,器件適用于眾多應(yīng)用,其中包括:LCD顯示器背光調(diào)節(jié),用于便攜產(chǎn)品、家電產(chǎn)品以及室內(nèi)照明等。MAX9635具有超低功耗(工作電流僅為0.65uA),工作電壓為1.8V (便于連接微處理器I/O口),這些特性使其成為傳感器和加密應(yīng)用中的理想選擇。背光調(diào)節(jié)和低功耗操作可有效延長電池壽命,提高照明系統(tǒng)的工作效率。

  MAX9635有價值的特性是具有一個便利的中斷輸出引腳。這個引腳可以使系統(tǒng)處于低功耗待機模式或?qū)⒂邢薜馁Y源用于執(zhí)行其它更重要的任務(wù)。

  該應(yīng)用筆記介紹了如何編程中斷輸出功能,優(yōu)化系統(tǒng)性能,并給出了幾個C語言例程。

  寄存器設(shè)置

  下表列出了MAX9635的寄存器以及上電復(fù)位(POR)后的狀態(tài)。


  可預(yù)設(shè)的寄存器包括:配置寄存器、中斷使能和門限定時器。

  配置寄存器(地址0x02)上電時設(shè)置為:CONT=0和MANUAL=0,能夠滿足絕大多數(shù)用戶的應(yīng)用。這些設(shè)置通知MAX9635根據(jù)環(huán)境光的強度自動調(diào)整其靈敏度。

  為了使能中斷功能,主控制器(如微控制器),首先將中斷使能寄存器(地址0x01)置1。

  主控制器然后在門限定時器寄存器(地址0x07)寫入適當(dāng)?shù)难訒r,通常情況下不會更改這個設(shè)置。設(shè)置門限延時需要遵循兩個基本原則。首先,在該寄存器寫入一個不為零的數(shù)值,以避免照明條件出現(xiàn)閃變或瞬間發(fā)生變化時反復(fù)觸發(fā)中斷。當(dāng)用戶的姿勢發(fā)生變化,或者是在設(shè)備移動時,都會在光傳感器上產(chǎn)生陰影,導(dǎo)致亮度發(fā)生閃變。其次,增加響應(yīng)顯示器亮度調(diào)整的延時,也可以為所定義的用戶接口算法預(yù)留時間。例如,在iPad™等移動設(shè)備中,當(dāng)用戶穿過一個黑暗的通道時(比如地鐵軌道),用戶并不希望屏幕的亮度頻繁變化。

  門限寄存器設(shè)置

  正常操作情況下,用戶會重復(fù)設(shè)置上限門限寄存器(地址0x05)和下限門限寄存器(地址0x06)。當(dāng)環(huán)境光強超出這些寄存器定義的窗口時,則觸發(fā)中斷(寄存器0x00的INTS位置1,/INT引腳拉低)。該中斷的持續(xù)時間要比門限定時寄存器(地址0x07)設(shè)置的延遲時間長。

  設(shè)置門限寄存器時,主控制器必須首先從數(shù)據(jù)寄存器LUX高字節(jié)(地址0x03)和LUX低字節(jié)(地址0x04)讀取流明數(shù)值,以確定當(dāng)前的工作區(qū)域。然后,由主控制器設(shè)置相應(yīng)的上限門限寄存器和下限門限寄存器。

  背光控制算法舉例

  人眼對光亮的響應(yīng)特性為對數(shù)函數(shù),類似于人耳對聲音的響應(yīng)特性。因此,需要對背光強度進行特殊設(shè)置,使其對環(huán)境光呈對數(shù)響應(yīng)。在亮度較低時,背光強度隨亮度變化的幅度較大,而在高亮度環(huán)境下背光強度變化幅度較小。理想情況下,主處理器還會根據(jù)環(huán)境光強度信息調(diào)整對比度、色彩等參數(shù),支持圖像處理算法。

  典型的亮度控制機制可以包含五級控制門限。多數(shù)情況下,屏幕的玻璃和物理尺寸會使光傳感器測到的環(huán)境光亮度降低5%至10%,設(shè)置檢測門應(yīng)該考慮這一因素。

  下表給出了一個背光強度和上限、下限門限的設(shè)置示例。為了把門限的流明值轉(zhuǎn)換成門限計數(shù)值,簡單地用0.045除目標(biāo)流明值。



  中斷處理

  以下流程圖所示為主機微控制器處理中斷的典型流程圖。


  門限值算法和環(huán)境光測量:計數(shù)值與流明值

  利用計數(shù)值(而不是流明值)進行計算更為簡捷,可以省去浮點運算并可采用簡單的定點運算程序。


  從上述表格中獲得所要求的門限,可以計算門限寄存器字節(jié),以作為每個流明區(qū)域的偽碼限制。這些門限值可以簡單地從上式計算出來,與環(huán)境光計數(shù)值進行比較。


  需要注意的是,如果光強非常接近所定義的流明區(qū)域的邊界,背光強度會頻繁擺動,使用戶感覺很不舒服??紤]到這一因素,可以在一個流明區(qū)域的上限與下一流明區(qū)域的下限之間建立一個重疊區(qū),從而形成一個滯回空間,屏蔽微弱的亮度波動。必要時,可以擴大該滯回區(qū)域。

  這里列舉的算法僅為背光亮度控制提供一些常規(guī)準(zhǔn)則,實際應(yīng)用中已經(jīng)開發(fā)了多種背光控制算法,滿足終端用戶舒適、透明的背光需求。

  C語言例程

// begin definition of slave device address
#define MAX9635_WR_ADDR		0x96
#define MAX9635_RD_ADDR		0x97

// begin definition of slave register addresses for MAX9635
#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 MAX9635

// define some lookup tables for the upper and lower thresholds as well as the
// brightness. All tables values are taken from text of application notes
#define NUM_REGI*		5
uint8 upperThresholds[NUM_REGI*] = {0x01, 0x06, 0x29, 0x48, 0xEF};
uint8 lowerThresholds[NUM_REGI*] = {0x00, 0x01, 0x06, 0x29, 0x48};
uint8 backlightBrightness[NUM_REGI*] = {0x40, 0x73, 0xA6, 0xD9, 0xFF};

/**
	Function:	SetPWMDutyCycle

	Arguments:	uint8 dc - desired duty cycle

	Returns:	none

	Description:	sets the duty cycle of a 8-bit PWM, assuming that in this
			architecture, 0x00 = 0% duty cycle 0x7F = 50% and 0xFF = 100%
**/
extern void SetPWMDutyCycle(uint8 dc);
extern void SetupMicro(void);
extern void Idle(void);

/**
	Function:	I2C_WriteByte

	Arguments:	uint8 slaveAddr - address of the slave device
			uint8 regAddr - 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 I²C bus
**/
extern uint8 I2C_WriteByte(uint8 slaveAddr, uint8 regAddr, uint8 data);

/**
	Function:	I2C_ReadByte

	Arguments:	uint8 slaveAddr - address of the slave device
			uint8 regAddr - 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 I²C bus
**/
extern uint8 I2C_ReadByte(uint8 slaveAddr, uint8 regAddr, uint8* data);

/**
	Function:	findNewThresholdsAndBrightness

	Arguments:	uint8 luxCounts - light counts High Byte
			uint8 *highThresh - pointer to memory storing upper threshold byte
			uint8 *lowThresh - pointer to memory storing lower threshold byte

	Returns:	none

	Description:	Based on what the lux reading was (in counts), this routine
			determines the current operating illumination zone. The zones
			are defined by upper and lower bounds in a lookup table. After
			knowing the operating zone, this function may set new interrupt
			thresholds and a backlight brightness. Since the interrupt only
			fires when the lux reading is outside the defined region, these
			threshold and brightness settings are not overwritten with the
			same data repeatedly.
**/
void findNewThresholdsAndBrightness(uint8 luxCounts, uint8 *highThresh,
  				    uint8 *lowThresh);

void main() {

	uint8 *highThresholdByte;	// upper and lower threshold bytes
	uint8 *lowThresholdByte;
	uint8 *timerByte;
	uint8 max9635Interrupt = 0;	// status of MAX9635 interrupt register
	uint8 luxCounts;		// computed as shown below

	SetupMicro();			// some subroutine which initializes this CPU
	*highByte = 0;
	*lowByte = 0;
	*highThresholdByte = 0xEF;	// upper threshold counts
					// initially = POR setting (maximum possible = 0xEF)
	*lowThresholdByte = 0x00;	// lower threshold counts
					// initially POR setting (minimum possible = 0x00)
	*timerByte = 0x14;		// initial timer delay for thresholds:
					// 0x14 * 100ms = 2 seconds

					// initialize MAX9635 threshold and timer registers
	I2C_WriteByte(MAX9635_WR_ADDR, THRESH_HIGH, *highThresholdByte);
	I2C_WriteByte(MAX9635_WR_ADDR, THRESH_LOW, *lowThresholdByte);
	I2C_WriteByte(MAX9635_WR_ADDR, THRESH_TIMER, *timerByte);
	I2C_WriteByte(MAX9635_WR_ADDR, INT_ENABLE, 0x01);// enable sensor interrupts

	while(1) {

		// do other tasks until an interrupt fires
		// assume that this function waits for the status of a GPIO-type pin to
		// change states
		while (! GPIO_StatusChanged() ) {
			// some idling subroutine, shown with polling a port for
			// simplicity - but alternate interrupt-based routines are more
			// efficient
			Idle();
		} // loop until an interrupt occurs

		// ok... an interrupt fired! was it from the MAX9635?
		I2C_ReadByte(MAX9635_RD_ADDR, INT_STATUS, max9635Interrupt);

		/**
			Place code to check other devices here, if desired
		**/

		if (max9635Interrupt) {
			// get the current lux reading from the MAX9635
			I2C_ReadByte(MAX9635_RD_ADDR, HIGH_BYTE, luxCounts);
			findNewThresholdsAndBrightness(luxCounts, highThresholdByte,
     							lowThresholdByte);

			// write to the threshold and timer registers with new data
			I2C_WriteByte(MAX9635_WR_ADDR, THRESH_HIGH, *highThresholdByte);
			I2C_WriteByte(MAX9635_WR_ADDR, THRESH_LOW, *lowThresholdByte);

			max9635Interrupt = 0;	// interrupt serviced, clear the bits
		} // only executes if the MAX9635's interrupt fired

		// perform. other tasks which are only done after change of a GPIO pin
	} // loop forever

} // main routine

void findNewThresholdsAndBrightness(uint8 luxCounts, uint8 *highThresh, uint8 *lowThresh) {

	uint8 i;

	for (i=0; i < NUM_REGI*; ++i) {
		if ((luxCounts >= lowerThresholds[i]) && (luxCounts <= upperThresholds[i])){
			*highThresh = upperThresholds[i];
			*lowThresh = lowerThresholds[i];
			// PWM duty cycle sets the brightness of the backlight
			SetPWMDutyCycle(backlightBrightness[i]);
			return;  // found the region -- no point in continuing the loop
		} // found the right region
	} // check where the lux reading lies in terms of threshold regions

} // findNewThresholdsAndBrightness

  
關(guān)鍵詞:MAX9635環(huán)境光傳感器的接口程序環(huán)境光傳感器

版權(quán)與免責(zé)聲明

凡本網(wǎng)注明“出處:維庫電子市場網(wǎng)”的所有作品,版權(quán)均屬于維庫電子市場網(wǎng),轉(zhuǎn)載請必須注明維庫電子市場網(wǎng),http://m.58mhw.cn,違反者本網(wǎng)將追究相關(guān)法律責(zé)任。

本網(wǎng)轉(zhuǎn)載并注明自其它出處的作品,目的在于傳遞更多信息,并不代表本網(wǎng)贊同其觀點或證實其內(nèi)容的真實性,不承擔(dān)此類作品侵權(quán)行為的直接責(zé)任及連帶責(zé)任。其他媒體、網(wǎng)站或個人從本網(wǎng)轉(zhuǎn)載時,必須保留本網(wǎng)注明的作品出處,并自負(fù)版權(quán)等法律責(zé)任。

如涉及作品內(nèi)容、版權(quán)等問題,請在作品發(fā)表之日起一周內(nèi)與本網(wǎng)聯(lián)系,否則視為放棄相關(guān)權(quán)利。

kingbright OSRAM系列 環(huán)境光傳感器
廣告
OEM清單文件: OEM清單文件
*公司名:
*聯(lián)系人:
*手機號碼:
QQ:
有效期:

掃碼下載APP,
一鍵連接廣大的電子世界。

在線人工客服

買家服務(wù):
賣家服務(wù):
技術(shù)客服:

0571-85317607

網(wǎng)站技術(shù)支持

13606545031

客服在線時間周一至周五
9:00-17:30

關(guān)注官方微信號,
第一時間獲取資訊。

建議反饋

聯(lián)系人:

聯(lián)系方式:

按住滑塊,拖拽到最右邊
>>
感謝您向阿庫提出的寶貴意見,您的參與是維庫提升服務(wù)的動力!意見一經(jīng)采納,將有感恩紅包奉上哦!