高中生
最后登录1970-1-1
在线时间 小时
注册时间2015-10-17
|
因为我采集的频率要大于1.4MHz,所以考虑使用ADC快速交叉模式,不知道可不可行?
如果可行,请帮我看看adc交叉模式的代码对不对
static void ADC12_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable DMA clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
/* Enable ADC1 and GPIOC clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 |RCC_APB2Periph_ADC2 | RCC_APB2Periph_GPIOA, ENABLE);
/*ÅäÖÃADCê±Öó£¬ÎaPCLK2μÄ6·ÖÆ죬¼′12MHz*/
RCC_ADCCLKConfig(RCC_PCLK2_Div6);
/* Configure PA.01 as analog input */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure); // PA1,êäèëê±2»óÃéèÖÃËùÂê
}
/**
* @brief ÅäÖÃADC12μÄ1¤×÷Ä£ê½ÎaMDAÄ£ê½
* @param ÎT
* @retval ÎT
*/
static void ADC12_Mode_Config(void)
{
DMA_InitTypeDef DMA_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
/* DMA channel1 configuration */
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address; //ADCμØÖ·
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_ConvertedValue; //Äú′æμØÖ·
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 1;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //íaéèμØÖ·1춨
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable; //Äú′æμØÖ·1춨
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);
/* Enable DMA channel1 */
DMA_Cmd(DMA1_Channel1, ENABLE);
/* ADC1 configuration ------------------------------------------*/
ADC_InitStructure.ADC_Mode = ADC_Mode_FastInterl ; //ADC1oíADC2 1¤×÷Ôú¿ìËù½»2æÄ£ê½
ADC_InitStructure.ADC_ScanConvMode = DISABLE; ; //½ûÖ1é¨Ãèģ꽣¬é¨ÃèÄ£ê½óÃóú¶àí¨μà2é¼ˉ
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; //¿aÆôá¬Dø×a»»Ä£ê½£¬¼′2»í£μؽøDDADC×a»»
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; //2»ê1óÃía2¿′¥·¢×a»»
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //2é¼ˉêy¾Yóò¶ÔÆë
ADC_InitStructure.ADC_NbrOfChannel = 1; //òa×a»»μÄí¨μàêyÄ¿1
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC1 regular channels configuration */
/*ÅäÖÃADC1μÄí¨μà11Îa55. 5¸ö2éÑùÖüÆú£¬DòáDÎa1 */
ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 1, ADC_SampleTime_1Cycles5);
// ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 2, ADC_SampleTime_55Cycles5);
/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
/* ADC2 configuration ------------------------------------------------------*/
ADC_InitStructure.ADC_Mode = ADC_Mode_FastInterl ; //ADC1oíADC2 1¤×÷Ôú¿ìËù½»2æÄ£ê½
ADC_InitStructure.ADC_ScanConvMode = DISABLE; ; //½ûÖ1é¨Ãèģ꽣¬é¨ÃèÄ£ê½óÃóú¶àí¨μà2é¼ˉ
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; //¿aÆôá¬Dø×a»»Ä£ê½£¬¼′2»í£μؽøDDADC×a»»
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; //2»ê1óÃía2¿′¥·¢×a»»
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //2é¼ˉêy¾Yóò¶ÔÆë
ADC_InitStructure.ADC_NbrOfChannel = 1; //òa×a»»μÄí¨μàêyÄ¿1
ADC_Init(ADC2, &ADC_InitStructure);
/* Enable ADC2 */
ADC_Cmd(ADC2, ENABLE);
/* ADC2 regular channels configuration */
/*ÅäÖÃADC2μÄí¨μà11Îa55. 5¸ö2éÑùÖüÆú£¬DòáDÎa1 */
ADC_RegularChannelConfig(ADC2, ADC_Channel_11, 1, ADC_SampleTime_1Cycles5);
/*¸′λD£×¼¼Ä′æÆ÷ */
ADC_ResetCalibration(ADC1);
/*μè′yD£×¼¼Ä′æÆ÷¸′λíê3é */
while(ADC_GetResetCalibrationStatus(ADC1));
/* ADCD£×¼ */
ADC_StartCalibration(ADC1);
/* μè′yD£×¼íê3é*/
while(ADC_GetCalibrationStatus(ADC1));
/* óéóúûóD2éóÃía2¿′¥·¢£¬ËùòÔê1óÃèí¼t′¥·¢ADC×a»» */
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
/* Enable ADC2 reset calibration register */
ADC_ResetCalibration(ADC2);
/* Check the end of ADC2 reset calibration register */
while(ADC_GetResetCalibrationStatus(ADC2));
/* Start ADC2 calibration */
ADC_StartCalibration(ADC2);
/* Check the end of ADC2 calibration */
while(ADC_GetCalibrationStatus(ADC2));
/* Start ADC1 Software Conversion */
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
/* Test on DMA1 channel1 transfer complete flag */
while(!DMA_GetFlagStatus(DMA1_FLAG_TC1));
/* Clear DMA1 channel1 transfer complete flag */
DMA_ClearFlag(DMA1_FLAG_TC1);
}
|
|