cancel
Showing results for 
Search instead for 
Did you mean: 

Do ADC_GetConversionValue read the current ADC value?

vicki19880929
Associate III
Posted on November 23, 2013 at 01:22

Hi all,

I'm recently building an application which asks for the current analog input at each poll.  It only reads the ADC value when it receives the request, which means that my STM32L will not read the ADC value all the time.  

And here's my question,  I found out that the ADC value I read at the current request is always the value read in the previous request.

So I did a simple test like this: I wrote a for loop that will read the ADC value for ten times.  In the meanwhile, I tuned my power supply which gives the analog input. (e.x. 0V-3V-0V-3V-0V-3V...)  And then I found out the same thing that it only prints out the previous ADC value instead of the current one. (e.x. 0-0-4096-0-4096-0...)  

 

for (i = 0; i < 10; i++) {

    /* Read ADC conversion result */

    ADCdata = ADC_GetConversionValue(ADC1);

    printf(''%4u\n'', ADCdata);

    printf(''change value now\n'');

    Delay(0xfffff);

    Delay(0xfffff);

    Delay(0xfffff);

    Delay(0xfffff);

    Delay(0xfffff);

    Delay(0xfffff);

  }

Does anyone know how I could read the current ADC value?

Thanks a lot!

#use-your-head!
10 REPLIES 10
Posted on November 23, 2013 at 02:13

The prescribed method is to start the conversion, and then wait for the EOC (End Of Conversion) status, and then read the value, once.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
vicki19880929
Associate III
Posted on November 23, 2013 at 02:44

hi clive,

I followed what you said but it still gets the same result.

This is my modified code:

for (i = 0; i < 10; i++) {

    /* Start ADC1 Software Conversion */

    ADC_SoftwareStartConv(ADC1);

    /* Wait until ADC end of conversion */

    while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET) {}

    /* Read ADC conversion result */

    ADCdata = ADC_GetConversionValue(ADC1);

    printf(''%4u\n'', ADCdata);

    printf(''change value now\n'');

    Delay(0xfffff);

    Delay(0xfffff);

    Delay(0xfffff);

    Delay(0xfffff);

    Delay(0xfffff);

    Delay(0xfffff);

  }

Posted on November 23, 2013 at 03:26

Then may be you should focus on the initialization code I can't see, and make sure you're not in a continuous conversion mode?

  ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;

And perhaps wait on a key stroke before initiating the next conversion.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
vicki19880929
Associate III
Posted on November 23, 2013 at 03:44

Oh yes!  That's the one!  I wasn't aware of the function of the continuous mode.  Thanks a lot! 🙂

giulio
Associate II
Posted on October 27, 2016 at 22:41

Hi there

To avoid opening almost same question I'm using this space.

I have a similar issue, but instead of having same value, I'm having a strange value on my adc.

I have full battery charge. 3.7v

In my GSM module AT+CBC gives me 4210

Then I execute this function every each 2 seconds:

/* Start ADC1 Software Conversion */

ADC_StartOfConversion(ADC1);

/* Wait until ADC end of conversion */

while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET) {}

/* Read ADC conversion result */

V_Value = ADC_GetConversionValue(ADC1);

I'm getting the value 2072 +/- 4

This is my init:

  ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;

  ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;

  ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;

  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

  ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Upward;

  ADC_Init(ADC1, &ADC_InitStructure);

///// other stuffs ///

ADC_AutoPowerOffCmd(ADC1, ENABLE);//Enables or disables the ADC Power Off.

ADC_VbatCmd(ENABLE);

Can you help me understand this value and how can I get the battery level ?

Thanks

Posted on October 27, 2016 at 23:06

What part are you using? What is your VDDA/+VREF voltage?

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
giulio
Associate II
Posted on October 27, 2016 at 23:14

STMF32072

VREF = 1720

VDDA = 2044

tks

Posted on October 28, 2016 at 00:35

1492?

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
giulio
Associate II
Posted on October 28, 2016 at 13:36

sorry.. this value should be where ?

V_Value = ADC_GetConversionValue(ADC1);

= 2045