AnsweredAssumed Answered

nhs3152 adc problem

Question asked by 向 雪姣 on Oct 15, 2019
Latest reply on Oct 23, 2019 by Dries Moors

dear sir 

   i encounter a question about test the battery voltage with the ADC function .

  1. 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 1Header 1Header 2Header 3Header 4Header 5Header 6Header 7Header 8Header 9
adcInput(mv) 269526772573259625782676259726702630
VCC(mv)296029412826285228322940285329332889

can you give me some advise ?is there anything wrong with my schematic ?

is there anything wrong with my design formula ?

 

Outcomes