当前位置:首页 > 工业控制 > 工业控制
[导读]摘要:这篇应用笔记介绍了如何合理使用MAX9635环境光传感器的中断输出功能,适用于智能手机、平板电脑等便携设备的LCD背光。利用中断功能可以针对多个照明区间设置不同的门限值,无需重复查询光传感器。合理使用中断

摘要:这篇应用笔记介绍了如何合理使用MAX9635环境光传感器的中断输出功能,适用于智能手机、平板电脑等便携设备的LCD背光。利用中断功能可以针对多个照明区间设置不同的门限值,无需重复查询光传感器。合理使用中断功能,可以将系统保持在低功耗休眠状态,或用于执行用户定义的其它任务。中断功能极大地提升了系统能效,改善了系统性能和用户在不同照明条件下的体验。本文还给出了I?C接口的C语言例程,用于中断操作。

概述

MAX9635环境光传感器用于检测环境光的亮度,器件适用于众多应用,其中包括:LCD显示器背光调节,用于便携产品、家电产品以及室内照明等。MAX9635具有超低功耗(工作电流仅为0.65uA),工作电压为1.8V (便于连接微处理器I/O口),这些特性使其成为传感器和加密应用中的理想选择。背光调节和低功耗操作可有效延长电池寿命,提高照明系统的工作效率。

MAX9635最有价值的特性是具有一个便利的中断输出引脚。这个引脚可以使系统处于低功耗待机模式或将有限的资源用于执行其它更重要的任务。

该应用笔记介绍了如何编程中断输出功能,优化系统性能,并给出了几个C语言例程。

寄存器设置

下表列出了MAX9635的寄存器以及上电复位(POR)后的状态。

 

 

可预设的寄存器包括:配置寄存器、中断使能和门限定时器。

配置寄存器(地址0x02)上电时设置为:CONT=0和MANUAL=0,能够满足绝大多数用户的应用。这些设置通知MAX9635根据环境光的强度自动调整其灵敏度。

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

主控制器然后在门限定时器寄存器(地址0x07)写入适当的延时,通常情况下不会更改这个设置。设置门限延时需要遵循两个基本原则。首先,在该寄存器写入一个不为零的数值,以避免照明条件出现闪变或瞬间发生变化时反复触发中断。当用户的姿势发生变化,或者是在设备移动时,都会在光传感器上产生阴影,导致亮度发生闪变。其次,增加响应显示器亮度调整的延时,也可以为所定义的用户接口算法预留时间。例如,在iPad™等移动设备中,当用户穿过一个黑暗的通道时(比如地铁轨道),用户并不希望屏幕的亮度频繁变化。

门限寄存器设置

正常操作情况下,用户会重复设置上限门限寄存器(地址0x05)和下限门限寄存器(地址0x06)。当环境光强超出这些寄存器定义的窗口时,则触发中断(寄存器0x00的INTS位置1,/INT引脚拉低)。该中断的持续时间要比门限定时寄存器(地址0x07)设置的延迟时间长。

设置门限寄存器时,主控制器必须首先从数据寄存器LUX高字节(地址0x03)和LUX低字节(地址0x04)读取流明数值,以确定当前的工作区域。然后,由主控制器设置相应的上限门限寄存器和下限门限寄存器。

背光控制算法举例

人眼对光亮的响应特性为对数函数,类似于人耳对声音的响应特性。因此,需要对背光强度进行特殊设置,使其对环境光呈对数响应。在亮度较低时,背光强度随亮度变化的幅度较大,而在高亮度环境下背光强度变化幅度较小。理想情况下,主处理器还会根据环境光强度信息调整对比度、色彩等参数,支持高级图像处理算法。

典型的亮度控制机制可以包含五级控制门限。多数情况下,屏幕的玻璃和物理尺寸会使光传感器测到的环境光亮度降低5%至10%,设置检测门限时应该考虑这一因素。

下表给出了一个背光强度和上限、下限门限的设置示例。为了把门限的流明值转换成门限计数值,简单地用0.045除目标流明值。

 

 

 

 

随着外部照明条件的改变调整背光强度

中断处理

以下流程图所示为主机微控制器处理中断的典型流程图。

 

 

门限值算法和环境光测量:计数值与流明值

利用计数值(而不是流明值)进行计算更为简捷,可以省去浮点运算并可采用简单的定点运算程序。

 

 

从上述表格中获得所要求的门限,可以计算门限寄存器字节,以作为每个流明区域的伪码限制。这些门限值可以简单地从上式计算出来,与环境光计数值进行比较。

 

 

需要注意的是,如果光强非常接近所定义的流明区域的边界,背光强度会频繁摆动,使用户感觉很不舒服。考虑到这一因素,可以在一个流明区域的上限与下一流明区域的下限之间建立一个重叠区,从而形成一个滞回空间,屏蔽微弱的亮度波动。必要时,可以扩大该滞回区域。

这里列举的算法仅为背光亮度控制提供一些常规准则,实际应用中已经开发了多种背光控制算法,满足终端用户舒适、透明的背光需求。

 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

本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

凭借深度学习技术和SmartBid产品,百度国际MediaGo获得美国商业奖认可 旧金山2024年5月6日 /美通社/ -- 第22届美国商业奖(American Business Award®)近日发布获奖名...

关键字: MEDIA GO SMART BSP

上海2024年4月17日 /美通社/ -- 在2024 F1中国站即将拉开帷幕之际,高端全合成润滑油品牌美孚1号今日举办了品牌50周年庆祝活动。三届F1年度车手总冠军马克斯•维斯塔潘也亲临现场,共同庆祝这一里程...

关键字: BSP 汽车制造 行业标准 产品系列

北京2024年4月17日 /美通社/ -- 2024年4月13日,由北京康盟慈善基金会主办的"县域诊疗,规范同行"——肿瘤诊疗学术巡讲项目首站在广州隆重召开。本次会议邀请全国多位肺癌领域专家和县域同道...

关键字: AI技术 医疗服务 BSP 互联网

海口2024年4月16日 /美通社/ -- 4月14日,在中法建交60周年之际,科学护肤先锋品牌Galenic法国科兰黎受邀入驻第四届中国国际消费品博览会(以下简称"消博会")法国馆。Galenic法...

关键字: NI IC BSP ACTIVE

上海2024年4月17日 /美通社/ -- 每年4月17日是世界血友病日。今年,世界血友病日以"认识出血性疾病,积极预防和治疗"为主题,呼吁关注所有出血性疾病,提升科学认知,提高规范化诊疗水平,让每一位出血性疾病患者享有...

关键字: VII 动力学 软件 BSP

伦敦2024年4月16日 /美通社/ -- ATFX宣布任命Siju Daniel为首席商务官。Siju在金融服务行业拥有丰富的经验和专业知识,曾在全球各地的高管职位上工作了19年以上。Siju之前担任FXCM首席商务官...

关键字: NI AN SI BSP

全球领先的科技公司默克推出了同类产品中首个经验证的全新一体化遗传稳定性分析。 Aptegra™ CHO遗传稳定性检测利用全基因组测序和生物信息学,显著加快了客户的生物医药安全性测试,从而帮助加快了客户进入商业生产的步伐。...

关键字: 稳定性分析 BSP 人工智能

常州2023年9月25日 /美通社/ -- 9月23日,由江苏省商务厅指导,世界中餐业联合会、常州市人民政府主办的"第三届中华节气菜大会暨首届江南美食节"在江苏常州开幕。文化和旅游部国际交流与合作局一...

关键字: BSP 可持续发展 大赛 质量控制

北京2023年9月25日 /美通社/ -- 9月21日,由中国质量报刊社·中国质量新闻网主办的第六届食品高质量发展交流会在北京举行,会议主题为"高质量,新生活",旨在推动食品行...

关键字: 自动化 BSP ISO9001 NAS
关闭
关闭