cancel
Showing results for 
Search instead for 
Did you mean: 

3 ADC simultaneous mode HELP

zobi000
Associate
Posted on June 04, 2014 at 17:18

Hi,

I am actually working on a project and I need 3 ADC in simultaneous mode.

However, I don't know why, but my programme don't work.

someone can help me?

thank you in advance

this is my code:

/**

 * @file    Adc.c

 * @brief   manages 3 ADC simultaneous  with  DMA

 * @author AUBER Romain

 * @date 1/06/2014

 */

/* INCLUDES DEPENDENCIES ***************/

&sharpinclude ''Adc.h''

/**

 * @fn void ADC_Configuration(void)

 * @brief Configures ADCs

 */

void ADC_configuration(void){

/* Deinitializes the ADC peripheral registers */

ADC_DeInit();

ADC_CommonInitTypeDef ADC_CommonInitStructure;

ADC_InitTypeDef ADC_InitStructure;

/* ADC Common Init */

ADC_CommonInitStructure.ADC_Mode = ADC_TripleMode_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);

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

ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;

ADC_InitStructure.ADC_ScanConvMode = DISABLE;

ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;

ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;

ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

ADC_InitStructure.ADC_NbrOfConversion = 1;

ADC_Init(ADC1, &ADC_InitStructure);

/* ADC1 regular channels configuration */

ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_3Cycles );

/* ADC2 configuration ------------------------------------------------------*/

ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;

ADC_InitStructure.ADC_ScanConvMode = DISABLE;

ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;

ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;

ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

ADC_InitStructure.ADC_NbrOfConversion = 1;

ADC_Init(ADC2, &ADC_InitStructure);

/* ADC2 regular channels configuration */

ADC_RegularChannelConfig(ADC2, ADC_Channel_1, 1, ADC_SampleTime_3Cycles );

/* ADC3 configuration ------------------------------------------------------*/

ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;

ADC_InitStructure.ADC_ScanConvMode = DISABLE;

ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;

ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;

ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

ADC_InitStructure.ADC_NbrOfConversion = 1;

ADC_Init(ADC3, &ADC_InitStructure);

/* ADC2 regular channels configuration */

ADC_RegularChannelConfig(ADC3, ADC_Channel_2, 1, ADC_SampleTime_3Cycles );

/* Enable ADC1, ADC2 et ADC3 */

ADC_Cmd(ADC1, ENABLE);

ADC_Cmd(ADC2, ENABLE);

ADC_Cmd(ADC3, ENABLE);

/* Enable ADC1 DMA */

ADC_DMACmd(ADC1, ENABLE);

/* Start ADC1, ADC2 and ADC3 Software Conversion */

ADC_SoftwareStartConv(ADC1);

//ADC_SoftwareStartConv(ADC2);

//ADC_SoftwareStartConv(ADC3);

}

/**

 * @fn void DMA_Configuration(void)

 * @brief Configures DMAs

 */

void DMA_configuration(void){

DMA_InitTypeDef DMA_InitStructure;

DMA_InitStructure.DMA_Channel = DMA_Channel_0;

DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)ADC_TripleConvertedValueTab;

DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC_CDR_ADDRESS;

DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;

DMA_InitStructure.DMA_BufferSize = 3;

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);

/* Enable DMA1 Channel1 */

DMA_Cmd(DMA2_Stream0, ENABLE);

}

/**

  * GPIO_Configuration

  * @brief  Configures the different GPIO ports.

  */

void GPIO_Configuration(void) {

    GPIO_InitTypeDef GPIO_InitStructure;

    /* Configure  PC.00, PC.01 and PC.02 (ADC Channel10, ADC Channel11 and

    ADC Channel12) as analog inputs */

    GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;

    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

}

/**

  * @fn void RCC_Configuration(void)

  * @brief  Configures the different system clocks.

  */

void RCC_Configuration(void){

/* Enable peripheral clocks ------------------------------------------------*/

/* Enable DMA1 and DMA2 clocks */

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2 , ENABLE);

/* Enable ADC1, ADC2 clocks */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2 | RCC_APB2Periph_ADC3, ENABLE);

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1 , ENABLE);

/* enable TIM2 and TIM 3 clock */

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM3, ENABLE);

/* enable GPIO clock */

RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA |

RCC_AHB1Periph_GPIOB |

RCC_AHB1Periph_GPIOC |

RCC_AHB1Periph_GPIOD , ENABLE);

/* enable peripheral clock for USART2 */

RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

}

#3-adc-simultaneous-mode-help
0 REPLIES 0