完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
static void ADC1_GPIO_Config(void)
{ GPIO_InitTypeDef GPIO_InitStructure; /* Enable DMA clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_5|GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; GPIO_Init(GPIOA, &GPIO_InitStructure); } static void ADC1_Mode_Config(void) { ADC_InitTypeDef ADC_InitStructure; ADC_CommonInitTypeDef ADC_CommonInitStructure; DMA_InitTypeDef DMA_InitStructure; //GPIO_InitTypeDef GPIO_InitStructure; /* ¨º1?¨¹¨ªa¨¦¨¨¨º¡À?¨® */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2 , ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); /* DMA2 Stream0 channel0 ????-------------------------------------------------- */ DMA_InitStructure.DMA_Channel = DMA_Channel_0; DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_ADDRESS; DMA_InitStructure.DMA_Memory0BaseAddr =(uint32_t)&AD_Value[0][0];// (uint32_t)&uhADCConvertedValue;; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; DMA_InitStructure.DMA_BufferSize = M*N; 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_Disable; 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); /* DMA2_Stream0 enable */ DMA_Cmd(DMA2_Stream0, ENABLE); /**************************************************************************** PCLK2 = HCLK / 2 ????????¦Ì?¨º?2¡¤??¦Ì ADCCLK = PCLK2 /8 = HCLK / 8 = 168 / 8 = 21M ADC2¨¦?¨´?¦Ì?¨º¡êo Sampling Time + Conversion Time = 480 + 12 cycles = 492cyc Conversion Time = 21MHz / 492cyc = 42.6ksps. *****************************************************************************/ /* ADC Common ???? ----------------------------------------------------------*/ ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent; ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2; ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles; ADC_CommonInit(&ADC_CommonInitStructure); /* ADC1 regular channel 12 configuration ************************************/ ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; 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 = M; ADC_Init(ADC1, &ADC_InitStructure); /* Enable ADC1 DMA */ ADC_DMACmd(ADC1, ENABLE); /* ADC1 regular channel18 (VBAT) configuration ******************************/ ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_480Cycles); ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 2, ADC_SampleTime_480Cycles); ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 3, ADC_SampleTime_480Cycles); /* Enable VBAT channel */ ADC_VBATCmd(ENABLE); ADC_TempSensorVrefintCmd(ENABLE); /* Enable DMA request after last transfer (Single-ADC mode) */ ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE); /* Enable ADC1 **************************************************************/ ADC_Cmd(ADC1, ENABLE); /* Start ADC1 Software Conversion */ ADC_SoftwareStartConv(ADC1); } void ADC1_Init(void) { ADC1_GPIO_Config(); ADC1_Mode_Config(); } u16 MultiDMAGetAdcTest(u8 ch) { u8 i; u16 AdcMax,AdcMin,AdcSum,AdcResult,Adc_temp; volatile u16 ADC_Data; ADC_Data=0; AdcMax=0; AdcMin=~0; AdcSum = 0; Adc_temp = 0; //taskDISABLE_INTERRUPTS(); /* ¿ªÆôµ÷¶ÈËø */ // taskENTER_CRITICAL(); for(i=0;i<34;i++) { Adc_temp =AD_Value[ch]&0XFFF; if(Adc_temp>AdcMax) { AdcMax=Adc_temp; } if(Adc_temp AdcMin=Adc_temp; } AdcSum+=Adc_temp; } AdcResult=(AdcSum-AdcMax-AdcMin)>>5; After_filter[ch]=(u16)AdcResult; //taskENABLE_INTERRUPTS(); // taskEXIT_CRITICAL(); /* Í˳öÁÙ½çÇø */ return(After_filter[ch]); } |
|
|
|
#define M 3 //Ϊ4¸öͨµÀ
#define N 34 //ÿͨµÀ²É34´Î extern u16 AD_Value[N][M]; //ÓÃÀ´´æ·ÅADCת»»½á¹û£¬Ò²ÊÇDMAµÄÄ¿±êµØÖ· extern u16 After_filter[M]; //ÓÃÀ´´æ·ÅÇóƽ¾ùÖµÖ®ºóµÄ½á¹û |
|
|
|
只有小组成员才能发言,加入小组>>
820 浏览 0 评论
1162 浏览 1 评论
2537 浏览 5 评论
2872 浏览 9 评论
移植了freeRTOS到STMf103之后显示没有定义的原因?
2722 浏览 6 评论
keil5中manage run-time environment怎么是灰色,不可以操作吗?
1125浏览 3评论
199浏览 2评论
465浏览 2评论
382浏览 2评论
M0518 PWM的电压输出只有2V左右,没有3.3V是怎么回事?
463浏览 1评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-30 20:18 , Processed in 0.945074 second(s), Total 79, Slave 60 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号