ADC result alignment
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-15 07:05 PM
Posted on May 16, 2014 at 04:05
Hello,
I have problem to get the ADC alignment feature working. config: STM32F407 on discovery board, Adjustable voltage (0 to 3V) connected to PA3 ADC resolution set to 12b Whatever alignment setting I use (ADC_DataAlign_Right orADC_DataAlign_Lef), the 4 LSb are always 0 and the result range from 0x0000 to 0xFFF0 for 0 to 3V. The conversion value is right, it just seems that the alignment setting does not have any effect... Does any one has similar issue? Here is my code:uint32_t ConvResult;
// Initialize ADC
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);
ADCInitStruct.ADC_Resolution = ADC_Resolution_12b;
ADCInitStruct.ADC_ScanConvMode = DISABLE;
ADCInitStruct.ADC_ContinuousConvMode = DISABLE;
ADCInitStruct.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADCInitStruct.ADC_DataAlign = ADC_DataAlign_Right; // ADC Val max = 4095 @12b resolution
ADCInitStruct.ADC_NbrOfConversion = 1;
ADC_Init(ADC1, &ADCInitStruct);
ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 1, ADC_SampleTime_480Cycles);
ADC_Cmd(ADC1,ENABLE);
// ADC Read
ADC_SoftwareStartConv(ADC1);
while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) != SET);
ConvResult = ADC_GetConversionValue(ADC1);
printf(''%lu: %lx\n'', ConvResult, ConvResult);
4 REPLIES 4
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-15 07:31 PM
Posted on May 16, 2014 at 04:31
Does any one has similar issue?
The right alignment gives me 0x000..0xFFF
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Up vote any posts that you find helpful, it shows what's working..
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-15 07:51 PM
Posted on May 16, 2014 at 04:51
Hi Clive,
It's what I was hoping to get, but I get 0x0000 to 0xFFF0 :(...Do you see anything wrong on my ADC init code?F.Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-15 08:01 PM
Posted on May 16, 2014 at 05:01
I would hazard that you are not initializing the structure completely, and a side effect of having junk in there is that the ADC gets misconfigured.
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ScanConvMode = DISABLE; // Single Channel
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; // Manual Trigger
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; // NONE
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1; // VALID BUT NOT USED
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion = 1;
ADC_Init(ADC1, &ADC_InitStructure);
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Up vote any posts that you find helpful, it shows what's working..
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-05-15 08:12 PM
Posted on May 16, 2014 at 05:12
Thanks Clive,
You are right,I did not set the theADC_ExternalTrigConv, and even thought I don't use external trigger, it killed the ADC init. The right alignment works fine now. Here is the corrected code:uint32_t ConvResult;
// Initialize ADC
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);
ADCInitStruct.ADC_Resolution = ADC_Resolution_12b;
ADCInitStruct.ADC_ScanConvMode = DISABLE;
ADCInitStruct.ADC_ContinuousConvMode = DISABLE;
ADCInitStruct.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADCInitStruct.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1; // Not used but needed for valid init
ADCInitStruct.ADC_DataAlign = ADC_DataAlign_Right; // ADC Val max = 4095 @12b resolution
ADCInitStruct.ADC_NbrOfConversion = 1;
ADC_Init(ADC1, &ADCInitStruct);
ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 1, ADC_SampleTime_480Cycles);
ADC_Cmd(ADC1,ENABLE);
// Conversion
while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) != SET);
ConvResult = ADC_GetConversionValue(ADC1);
printf(''%lu: %lx
'', ConvResult, ConvResult);
Thanks again,
F.