2010-08-17 03:30 AM
ADC multichannel (scan mode)
2011-05-17 05:02 AM
Hi, maybe it will be useful.
I am using Ride7 and standard library V3.1.0 06/19/2009. There are program lines from my variuos files. #define ADC1_DR_Address ((uint32_t)0x4001244C) DMA_InitTypeDef DMA_InitStructure; ADC_InitTypeDef ADC_InitStructure; __IO uint16_t ADC_RegularConvertedValueTab[6]; //******************************************** // from void NVIC_Configuration(void): /* Configure and enable ADC interrupt */ NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); //*******************************************************************************/ void MyConfigureADC(void) { /* DMA1 channel1 configuration ----------------------------------------------*/ DMA_DeInit(DMA1_Channel1); DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address; DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ADC_RegularConvertedValueTab; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = 6; 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_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel1, &DMA_InitStructure); /* ADC1 configuration ------------------------------------------------------*/ ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 6; ADC_Init(ADC1, &ADC_InitStructure); /* ADC1 regular channels configuration */ ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_28Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 2, ADC_SampleTime_28Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 3, ADC_SampleTime_28Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 4, ADC_SampleTime_28Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 5, ADC_SampleTime_28Cycles5); // ld current ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 6, ADC_SampleTime_28Cycles5); // laser power /* Regular discontinuous mode channel number configuration */ ADC_DiscModeChannelCountConfig(ADC1, 6); /* Enable regular discontinuous mode */ ADC_DiscModeCmd(ADC1, ENABLE); ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE); /* Enable ADC1 DMA */ ADC_DMACmd(ADC1, ENABLE); /* 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)); /* Start ADC1 calibaration */ ADC_StartCalibration(ADC1); /* Check the end of ADC1 calibration */ while(ADC_GetCalibrationStatus(ADC1)); DMA_Cmd(DMA1_Channel1,ENABLE); } //***************************** //this is line from other sub how start conversion. I do this every 8ms: ADC_SoftwareStartConvCmd(ADC1,ENABLE); // command from standard library //********************* // do not forget to configure pins and clock //******************************************** void ADC1_2_IRQHandler(void) { /* Clear ADC1 EOC pending interrupt bit */ ADC_ClearITPendingBit(ADC1, ADC_IT_EOC); SetWordDataInControllerDataArray(DATA_ENTRY_CODE_TEC1_TEMP_MEAS,ADC_RegularConvertedValueTab[0]); SetWordDataInControllerDataArray(DATA_ENTRY_CODE_TEC2_TEMP_MEAS,ADC_RegularConvertedValueTab[1]); SetWordDataInControllerDataArray(DATA_ENTRY_CODE_TEC3_TEMP_MEAS,ADC_RegularConvertedValueTab[2]); SetWordDataInControllerDataArray(DATA_ENTRY_CODE_TEC4_TEMP_MEAS,ADC_RegularConvertedValueTab[3]); // nuo 2010.07.29: SetWordDataInControllerDataArray(DATA_ENTRY_CODE_LD_CURRENT_MEAS,ADC_RegularConvertedValueTab[4]); SetWordDataInControllerDataArray(DATA_ENTRY_CODE_LASER_POWER_MEAS,ADC_RegularConvertedValueTab[5]); }