Question
Problem with ADC: channel affected by another and trouble with type conversion
Posted on June 24, 2012 at 14:58
Hello,
I'm using IAR embedded Workbench for ARM 6.30 kickstart to program a STM32F4 DISCOVERY microcontroler. I have two problem with ADCs: - I use two ADC channels (12 & 14) based on the same ADC (ADC2) to 8-bits digitizing two potentiometers output voltages. The trouble is, when I change the first potentiometer value, it's affects the second potentiometer digital value. - The strangest problem: sometimes when I run my project on the STM32 with the ''Make and Restart Debugger'' button, with NO CHANGES in my code, the ADC behavior can change: instead of being digitized on 8-bit (0 to 255), potentiometers values will be digitized on 6-bits (0 to 63) or on 16-bits (0 to 65535), I can see it on the watch !! What is the problem with IAR ? Thanks for your help ! I work on this problem for 2 weeks... Jean// ADC ADRESS #define ADC_CCR_ADDRESS ((uint32_t)0x40012308) // Table to store digitized ADC values extern
__IO uint16_t TabADC[2];
//////////////////////////////////////////////////////////////////// //////// ADC configuration /////////// //////////////////////////////////////////////////////////////////// voidADC_Config(
void)
{ // ADC initialisation ADC_CommonInitTypeDef ADC_CommonInitStructure; // CLOCK set for DMA2 + GPIOC2 + ADC1 + ADC2 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2 | RCC_AHB1Periph_GPIOC, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2, ENABLE); // DMA2 config (direct access memory) Stream0 channel0 DMA_InitTypeDef DMA_InitStructure; DMA_InitStructure.DMA_Channel = DMA_Channel_0; // USE CHANNEL 0DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&TabADC; // Store in my table the digitized values
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC_CCR_ADDRESS; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; DMA_InitStructure.DMA_BufferSize = 2; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; DMA_Init(DMA2_Stream0, &DMA_InitStructure); DMA_Cmd(DMA2_Stream0, ENABLE); // DMA2_Stream0 enable
// ADCs configuration: ADC Channel 12 & 14 // POT2: ADC Channel 12 -> PIN PC2 // POT3: ADC Channel 14 -> PIN PC4 GPIO_InitTypeDef GPIO_InitStructure; // GPIOC
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN ; GPIO_Init(GPIOC, &GPIO_InitStructure); // 'ADC ''Common'' ADC_CommonInitStructure.ADC_Mode = ADC_DualMode_RegSimult; ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2; ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_1; ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles; ADC_CommonInit(&ADC_CommonInitStructure); // Initialisation ADC ''2'' channels 12 & 14 ADC_InitStructure.ADC_Resolution = ADC_Resolution_8b; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfConversion = 2; ADC_Init(ADC2, &ADC_InitStructure); // ADC2 regular channels 12, 14 ADC_RegularChannelConfig(ADC2, ADC_Channel_12, 1, ADC_SampleTime_3Cycles); ADC_RegularChannelConfig(ADC2, ADC_Channel_14, 2, ADC_SampleTime_3Cycles); // Enable DMA request after last transfer (Multi-ADC mode) ADC_MultiModeDMARequestAfterLastTransferCmd(ENABLE); // Start ADC2 ADC_Cmd(ADC1, ENABLE); ADC_Cmd(ADC2, ENABLE); // Start ADC1 Software Conversion ADC_SoftwareStartConv(ADC1); } #adc
