微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > TI蓝牙设计交流 > CC2541电源管理

CC2541电源管理

时间:10-02 整理:3721RD 点击:

CC2541 这个芯片检测电源是否的电量多少,需要外用一个IO才能实现嘛?  

你是说电源监测吗?不需要,它内部可以监测VDD/3

代码参考协议栈里的Battservice.c, 如下:

/*********************************************************************
 * @fn      battMeasure
 *
 * @brief   Measure the battery level with the ADC and return
 *          it as a percentage 0-100%.
 *
 * @return  Battery level.
 */
static uint8 battMeasure( void )
{
  uint16 adc;
  uint8 percent;

  /**
   * Battery level conversion from ADC to a percentage:
   *
   * The maximum ADC value for the battery voltage level is 511 for a
   * 10-bit conversion.  The ADC value is references vs. 1.25v and
   * this maximum value corresponds to a voltage of 3.75v.
   *
   * For a coin cell battery 3.0v = 100%.  The minimum operating
   * voltage of the CC2540 is 2.0v so 2.0v = 0%.
   *
   * To convert a voltage to an ADC value use:
   *
   *   (v/3)/1.25 * 511 = adc
   *
   * 3.0v = 409 ADC
   * 2.0v = 273 ADC
   *
   * We need to map ADC values from 409-273 to 100%-0%.
   *
   * Normalize the ADC values to zero:
   *
   * 409 - 273 = 136
   *
   * And convert ADC range to percentage range:
   *
   * percent/adc = 100/136 = 25/34
   *
   * Resulting in the final equation, with round:
   *
   * percent = ((adc - 273) * 25) + 33 / 34
   */

  // Call measurement setup callback
  if (battServiceSetupCB != NULL)
  {
    battServiceSetupCB();
  }

  // Configure ADC and perform a read
  HalAdcSetReference( HAL_ADC_REF_125V );
  adc = HalAdcRead( battServiceAdcCh, HAL_ADC_RESOLUTION_10 );

  // Call measurement teardown callback
  if (battServiceTeardownCB != NULL)
  {
    battServiceTeardownCB();
  }

  if (adc >= battMaxLevel)
  {
    percent = 100;
  }
  else if (adc <= battMinLevel)
  {
    percent = 0;
  }
  else
  {
    if (battServiceCalcCB != NULL)
    {
      percent = battServiceCalcCB(adc);
    }
    else
    {
      uint16 range =  battMaxLevel - battMinLevel + 1;

      // optional if you want to keep it even, otherwise just take floor of divide
      // range += (range & 1);
      range >>= 2; // divide by 4

      percent = (uint8) ((((adc - battMinLevel) * 25) + (range - 1)) / range);
    }
  }

  return percent;
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top