FRDM-K20D50M - ADC Voltage Measurement with processor expert

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

FRDM-K20D50M - ADC Voltage Measurement with processor expert

跳至解决方案
1,416 次查看
srividhyaumasha
Contributor I

I am trying to connect an external battery for some voltage calculation. Have enabled ADC0_SE14 (P0)  as my input pin.

When i am not connected to the battery in the A0 pin, should i expect a 0 value  when calling AD1_GetMeasuredValues() ?

But i am getting a value ranging between 17000 -  30000 everytime. Why is that. All the examples provided match the configuration and code that i have done.


Please help.



Here is my AD1_LDD Configuration in processor expert

adc_setting.png

Here is the code in my main.c for reading the single voltage value.

  /* Write your code here */

  /* For example: for(;;) { } */

  AD1_SelectSampleGroup(adcDevData, 0U);

  AD1_StartSingleMeasurement(adcDevData);

 

  uint16_t value;

    printf("----Checking Status...... --------\n");

   

    while (!AD1_GetMeasurementCompleteStatus(adcDevData))

     {

         printf("---running...\n");

     }

    AD1_GetMeasuredValues(adcDevData, &value);

    printf("----Final Data... -----%d---\n", value);

The output show a value ranging from 17000 ~ 25000   without connecting anything to the board..

----Checking Status...... --------                                             

----Final Data... -----21526---                                                

标签 (1)
0 项奖励
回复
1 解答
1,169 次查看
chris_brown
NXP Employee
NXP Employee

Hi Srividhya,

I must first ask this:  Have you called the appropriate calibration routines for the ADC?

Also know that by simply not connecting that pin at all, you have a floating pin.  So it may not necessarily be 0V.  I would recommend not testing your code in this manner.  Generally it is a better practice to put some non-zero and non-full scale voltage on the pin and see that your readings are what you expect.  In this case, you could try grounding the pin in question and see if you start reading zero. 

Hope this helps,

Chris

在原帖中查看解决方案

0 项奖励
回复
2 回复数
1,170 次查看
chris_brown
NXP Employee
NXP Employee

Hi Srividhya,

I must first ask this:  Have you called the appropriate calibration routines for the ADC?

Also know that by simply not connecting that pin at all, you have a floating pin.  So it may not necessarily be 0V.  I would recommend not testing your code in this manner.  Generally it is a better practice to put some non-zero and non-full scale voltage on the pin and see that your readings are what you expect.  In this case, you could try grounding the pin in question and see if you start reading zero. 

Hope this helps,

Chris

0 项奖励
回复
1,169 次查看
srividhyaumasha
Contributor I

Thanks Chris ! Grounding worked

The output of  AD1_GetMeasuredValues(adcDevData, &value); seems to be a count

i had to calculate the voltage with this formula

(3.3/65535)*(value)  3.3 -> ref voltage .

0 项奖励
回复