2015-04-27 10:58 AM
Hi,
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_PuPd = GPIO_PuPd_NOPULL;
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;
ADC_CommonInit(&ADC_CommonInitStruct);
// 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
ADC_SoftwareStartConv(ADC1);
// Wait till done
while(ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC)==RESET);
return ADC_GetConversionValue(ADC1);
}
#adc #stm32f4 #disco2015-04-27 12:24 PM
Check the input impedance of the ADC. Pretty sure the 1M arm of the divider is going to route through the ADC instead
2015-04-27 06:44 PM
When you use an 429 Discovery for analog conversions, you discover either by reading the reference manual or by bitter experience that PA1 is dedicated to LG3D20 interrupt functions on the board. You have 3 choices - PA5, PC3 or PF6.
I wish ST would use a darker shade on the pin allocations table to indicate free I/O. Cheers, Hal2015-04-30 06:12 AM
Thank you very much...I tried more than one pin/channel but to be honest I did not check the wiring...Thanks very very much...