cancel
Showing results for 
Search instead for 
Did you mean: 

ADC shows wrong output

sarang
Associate II
Posted on September 03, 2009 at 22:37

ADC shows wrong output

13 REPLIES 13
sarang
Associate II
Posted on May 17, 2011 at 13:22

I am working on ARM Cortex for the first time and trying to get ADC running with GPIOC pins 0,1,2 as input for ADC1,2,3 respectively.

Below is my code:

//After GPIOC is set to Analog input

// ADC Clock

RCC_ADCCLKConfig(RCC_PCLK2_Div4);

RCC_GetClocksFreq(&RCC_Clocks);

// Enable peripherals clock

RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOC, ENABLE);

/* ADC1 configuration ------------------------------------------------------*/

ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;

ADC_InitStructure.ADC_ScanConvMode = ENABLE;

ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;

ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;

ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

ADC_InitStructure.ADC_NbrOfChannel = 1;

ADC_Init(ADC1, &ADC_InitStructure);

/* ADC1 regular channels configuration */

ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_71Cycles5);

/* Enable ADC1 */

ADC_Cmd(ADC1, ENABLE);

/* Enable ADC1 reset calibaration register */

ADC_ResetCalibration(ADC1);

/* Check the end of ADC1 reset calibration register */

while(ADC_GetResetCalibrationStatus(ADC1));

sprintf(tempStr,''\r\nreset cal= %d'',ADC1->DR);

User_Print(tempStr);

/* Start ADC1 calibaration */

ADC_StartCalibration(ADC1);

/* Check the end of ADC1 calibration */

while(ADC_GetCalibrationStatus(ADC1));

sprintf(tempStr,''\r\nBefore Conv= %d'',ADC1->DR);

User_Print(tempStr);

/* Start ADC1 Software Conversion */

ADC_SoftwareStartConvCmd(ADC1, ENABLE);

// Wait until conversion completion

while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET) ;

// Get the conversion value

sprintf(tempStr,''\r\nOutput= 0x%04X'',ADC_GetConversionValue(ADC1));

User_Print(tempStr);

The ADC DR shows 16 bit output which is not as per expectation.

Also, the output remains more or less constant even if there is no input voltage of GPIOC Pins 0/1/2.

Please help. I am stuck!!!

guyvo67
Associate II
Posted on May 17, 2011 at 13:22

Be aware that PC0/1/2 are dedicated to ADC10/11/12. You must take PA0/1/2 to match ADC0/1/2. Also put your GPIO pins to GPIO_Mode_AIN mode.

Guy

sarang
Associate II
Posted on May 17, 2011 at 13:22

//GPIO Port C

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;

GPIO_Init(GPIOC, &GPIO_InitStructure);

I did initialize Port C Pins 0,1,2 to Analog Input Mode. Still the output is incorrect. Also, it shows an output irrespective of input or NO input :

[ This message was edited by: sarang.mandke on 31-08-2009 16:20 ]

ngaylard
Associate II
Posted on May 17, 2011 at 13:22

Are you using your own hardware? If so make sure that your voltage reference is properly connected and configured.

I only mention this because we had garbage from our ADC and found that we had not connected Vref-neg to ground.

guyvo67
Associate II
Posted on May 17, 2011 at 13:22

Quote:

I did initialize Port C Pins 0,1,2 to Analog Input Mode.

Are those not related to ADC_Channel_10 / 11 / 12 ?

Never tried those pins I work with PA1/ADC1/ADC_Channel_1 and that works. Of course you must following the hardware specs with respect to Vref and also providing a stable analogue signal using a capacitor of 10nF on the input to reduce noise.

-G

sarang
Associate II
Posted on May 17, 2011 at 13:22

On my board, PC0,1,2 are connected to ADC inputs.

sarang
Associate II
Posted on May 17, 2011 at 13:22

I was not grounding the variable power supply, so the pins were kinda floating. Realized it today!

Thanks everyone for putting in comments!!

sarang
Associate II
Posted on May 17, 2011 at 13:22

I have issues now with ADC2, ADC1 and ADC3 are working fine. ADC2 shows output irrespective of input. I did check the ground etc for the ADC input to ADC2, and found nothing amiss.

Help!

jj
Associate II
Posted on May 17, 2011 at 13:22

Have you a 2nd board? Always helpful to verify/check-out 2 or more boards to speed debug.

Be absolutely certain you have not error in ''cut/paste'' hoop-jumping (set-up) of ADC. If you haven't damaged (via over-voltage) ADC2 I bet you this is your problem... Let us know