dear sir
i encounter a question about test the battery voltage with the ADC function .
- my schematic diagram is below

2 my source about test the vcc voltage code is below
static uint16_t Get_current_adc(void)
{
//int adc_max=0xfff;
int adcInput=0;
int total_adc=0;
//! [adcdac_nss_example_3]
Chip_IOCON_SetPinConfig(NSS_IOCON, IOCON_ANA0_4, IOCON_FUNC_1);
Chip_ADCDAC_Init(NSS_ADCDAC0);
Chip_ADCDAC_SetMuxADC(NSS_ADCDAC0, ADCDAC_IO_ANA0_4);
Chip_ADCDAC_SetInputRangeADC(NSS_ADCDAC0, ADCDAC_INPUTRANGE_WIDE);
Chip_ADCDAC_SetModeADC(NSS_ADCDAC0, ADCDAC_CONTINUOUS);
Chip_ADCDAC_StartADC(NSS_ADCDAC0);
int max,min;
total_adc=max=min=0;
for(int i=0;i<10;i++)
{
adcInput = Chip_ADCDAC_GetValueADC(NSS_ADCDAC0);
total_adc+=adcInput;
if(max<adcInput)
max=adcInput;
else if(min>adcInput)
min=adcInput;
}
Chip_ADCDAC_StopADC(NSS_ADCDAC0);
total_adc=total_adc-max-min;
//get the average value
total_adc=total_adc/8;
//get the caculate from https://community.nxp.com/message/1119718#comment-1120963
//output in mV = ((native value - native offset) * internal operating voltage / steps per uV) + offset
//native offset=2048,internal voltage = 1.2V,gain (steps per uV) = 2730,offset = 0.9V
adcInput=(total_adc-2048)*1200/2730+900;// get the test point voltage ,unit is mv
//convert the test point voltage to VCC voltage
adcInput=adcInput*5/2;
return (uint16_t)adcInput;
/* Further handling of the threshold breach. */
}
my question is :
- how can i get these value ?i get from this value in another question ,but i do not no why ?i can not find it in spec ...native offset=2048,internal voltage = 1.2V,gain (steps per uV) = 2730,offset = 0.9V
- my ADC value adcInput change rapidly,it is not a stable value ,
for example ,i get the voltage VCC by multimeter is 3.0V
but ,i tried 10 times test the value ,and get the adcInput = Chip_ADCDAC_GetValueADC(NSS_ADCDAC0);read from the register is below .
| Header 1 | Header 1 | Header 2 | Header 3 | Header 4 | Header 5 | Header 6 | Header 7 | Header 8 | Header 9 |
|---|
| adcInput(mv) | 2695 | 2677 | 2573 | 2596 | 2578 | 2676 | 2597 | 2670 | 2630 |
| VCC(mv) | 2960 | 2941 | 2826 | 2852 | 2832 | 2940 | 2853 | 2933 | 2889 |
can you give me some advise ?is there anything wrong with my schematic ?
is there anything wrong with my design formula ?