Do ADC_GetConversionValue read the current ADC value?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-11-22 4:22 PM
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!- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-11-22 5:13 PM
The prescribed method is to start the conversion, and then wait for the EOC (End Of Conversion) status, and then read the value, once.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-11-22 5:44 PM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-11-22 6:26 PM
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.Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-11-22 6:44 PM
Oh yes! That's the one! I wasn't aware of the function of the continuous mode. Thanks a lot! :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-10-27 1:41 PM
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.7vIn my GSM module AT+CBC gives me 4210Then 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 +/- 4This 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- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-10-27 2:06 PM
What part are you using? What is your VDDA/+VREF voltage?
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-10-27 2:14 PM
STMF32072
VREF = 1720VDDA = 2044tks- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-10-27 3:35 PM
1492?
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-10-28 4:36 AM
