AnsweredAssumed Answered

32F429IDISCOVERY ADC single conversion

Question asked by machala.petr on Apr 27, 2015
Latest reply on Apr 30, 2015 by machala.petr

I am having issue regarding an ADC configuration on 32F429IDISCOVERY board. I have a battery power application where I want to measure the battery voltage. This voltage is above the reference of the board (VCC) so I need to use a voltage divider. The divider is as big as possible to drain as low current as possible in my case combination 1M/330k resistors plus parallel 100n capacitor to the 330k. My idea was to measure voltage with ADC for example once every ten seconds and print id out. I believed that this was enough time to charge the capacitor and then by S&H circuit get the voltage. Problem is that this is not working...

When I connect some voltage for example 2V directly to ADC pin it shows approx. 2V very nicely but when I connect the voltage across the voltage divider the voltage on the divider drops to zero.
So basically the ADC measures good value because there really is zero but why? Why the voltage on the divider drops when I connect it to the ADC pin? I dont know what to do with it...It just must work...Using OPAMP didn't help either...

The code I am using is as follows:

void ADC1_CH1_Init(void){

    GPIO_InitTypeDef GPIO_InitDef;

    ADC_InitTypeDef ADC_InitStruct;

     ADC_CommonInitTypeDef ADC_CommonInitStruct;

     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

     RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);

    // GPIO config

     //                          PA1

     GPIO_InitDef.GPIO_Pin = GPIO_Pin_1;

    GPIO_InitDef.GPIO_Mode = GPIO_Mode_AN;

    GPIO_InitDef.GPIO_OType = GPIO_OType_PP;


    GPIO_InitDef.GPIO_Speed = GPIO_Speed_100MHz;

    GPIO_Init(GPIOA, &GPIO_InitDef);

    // Set common ADC settings

     ADC_CommonInitStruct.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;

     ADC_CommonInitStruct.ADC_Mode = ADC_Mode_Independent;

     ADC_CommonInitStruct.ADC_Prescaler = ADC_Prescaler_Div4;

     ADC_CommonInitStruct.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;


     // Init ADC settings

     ADC_InitStruct.ADC_ContinuousConvMode = DISABLE;

     ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right;

     ADC_InitStruct.ADC_ExternalTrigConv = DISABLE;

     ADC_InitStruct.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;

     ADC_InitStruct.ADC_NbrOfConversion = 1;

     ADC_InitStruct.ADC_ScanConvMode = DISABLE;

     ADC_InitStruct.ADC_Resolution = ADC_Resolution_12b;

    ADC_Init(ADC1, &ADC_InitStruct);

     ADC_Cmd(ADC1, ENABLE);


uint16_t ADC1_CH1_Read(void) {

     ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_3Cycles);

     // Start software conversion


     // Wait till done


     return ADC_GetConversionValue(ADC1);