FRDM-K20D50M - ADC Voltage Measurement with processor expert

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FRDM-K20D50M - ADC Voltage Measurement with processor expert

Jump to solution
1,008 Views
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---                                                

Labels (1)
0 Kudos
Reply
1 Solution
761 Views
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

View solution in original post

0 Kudos
Reply
2 Replies
762 Views
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 Kudos
Reply
761 Views
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 Kudos
Reply