static uint8_t battMeasure(void) {uint32_t percent;// Call measurement setup callbackif (battServiceSetupCB != NULL){battServiceSetupCB();}// Read the battery voltage (V), only the first 12 bitspercent = AONBatMonBatteryVoltageGet();// Convert to from V to mV to avoid fractions.// Fractional part is in the lower 8 bits thus converting is done as follows:// (1/256)/(1/1000) = 1000/256 = 125/32// This is done most effectively by multiplying by 125 and then shifting// 5 bits to the right.percent = (percent * 125) >> 5;// Convert to percentage of maximum voltage.percent = ((percent* 100) / battMaxLevel);// Call measurement teardown callbackif (battServiceTeardownCB != NULL){battServiceTeardownCB();}return percent; }
代码如上,
AONBatMonBatteryVoltageGet 这个函数接口是怎样获取到电池电压的?
Viki Shi:
//***************************************************************************** // //! \brief Get the battery monitor measurement. //! //! This function will return the current battery monitor measurement. //! The battery voltage measurements are updated every cycle. //! //! \note The returned value is NOT sign-extended! //! //! \note Use the function \ref AONBatMonNewBatteryMeasureReady() to test for //! a change in measurement. //! //! \return Returns the current battery monitor value of the battery voltage //! measurement in a <int.frac> format size <3.8> in units of volt. //! //! \sa AONBatMonNewBatteryMeasureReady() // //***************************************************************************** __STATIC_INLINE uint32_t AONBatMonBatteryVoltageGet(void) {uint32_t ui32CurrentBattery;ui32CurrentBattery = HWREG(AON_BATMON_BASE + AON_BATMON_O_BAT);//// Return the current battery voltage measurement.//return (ui32CurrentBattery >> AON_BATMON_BAT_FRAC_S); }
Viki Shi:
回复 Viki Shi:
这里涉及到的寄存器操作请看:software-dl.ti.com/…/AON_BATMON.html
user1388075:
回复 Viki Shi:
硬件上任何处理都不做就可以读出电池电压么?