Hi @wmtanada,
I am not sure what is the specific issue that you have with the battery.
Please look at the code below to calibrate the temperature sensor, that could help you with the calibration for the battery using the adc.
#include "analog.h"
#include "adc.h"
#include "nvds.h"
volatile uint32_t adc_done = 0;
static void adc_test_cb(void)
{
adc_done = 1;
}
uint32_t temp_buf = 0;
void TEMP_sensor_calibration()
{
adc_read_configuration read_cfg;
temp_sensor_enable(MASK_ENABLE);
int16_t tempv[100];
adc_init(ADC_DIFF_WITH_BUF_DRV, ADC_CLK_1000000, ADC_INT_REF, ADC_12BIT);
adc_done = 0;
read_cfg.trig_src=ADC_TRIG_SOFT;
read_cfg.mode = SINGLE_MOD;
read_cfg.start_ch = TEMP;
read_cfg.end_ch = TEMP;
for(uint8_t i=0;i<100;i++)
{
adc_read(&read_cfg, tempv+i, 1, adc_test_cb);
// printf("tempv:%x\r\n",tempv[i]);
while (adc_done == 0);
}
for(uint8_t j=50;j<60;j++)
{
temp_buf += (tempv[j]&0xFFFF);
}
temp_buf /= 10;
temp_buf |= 0xFFFF0000;
printf("temp_buf:%x\r\n",temp_buf);
nvds_put(NVDS_TAG_TEMPERATURE_OFFSET,NVDS_LEN_TEMPERATURE_OFFSET,(uint8_t *)&temp_buf);
uint32_t temp_offset = 0;
uint16_t nv_len = NVDS_LEN_TEMPERATURE_OFFSET;
nvds_get(NVDS_TAG_TEMPERATURE_OFFSET,&nv_len,(uint8_t *)&temp_offset);
TEMP_OFFSET = temp_offset;
printf("temperature: %0.1f\r\n", (float)(TEMPERATURE_X10(tempv[0])/10.0));
}
Regards,
Mario