volatile unsigned int After_filter[16]; //ÓÃÀ´´æ·ÅÇóƽ¾ùÖµÖ®ºóµÄ½á¹û
- void ADC1_GPIO_Config(void);
- void ADC1_Mode_Config(void);
- void ADC1_DMA_Init(void);
- void ADC1_Init(void)
- {
- ADC1_DMA_Init();
- ADC1_GPIO_Config();
- ADC1_Mode_Config();
- }
- //Ñ¡ÓÃADCµÄͨµÀ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
- //·Ö±ð¶ÔÓ¦¹Ü½Å PA0 PA1 PA2 PA3 PA4 PA5 PA6 PA7 PB0 PB1 PC0 PC1 PC2 PC3 PC4 PC5
- //¶ÔÓ¦¹¦ÄÜ OCE OCF OCG OCH OVA OVB OVC OVD OVG OVH OCA OCB OCC OCD OVE OVF
- void ADC1_GPIO_Config(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
- RCC_APB2Periph_GPIOC |RCC_APB2Periph_AFIO ,ENABLE);//¹¦Äܸ´ÓÃIOʱÖÓ
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AIN;//Ä£ÄâÊäÈë
- GPIO_Init(GPIOA, GPIO_InitStructure);//PA0 1 2 3 4 5 6 7
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0 | GPIO_Pin_1;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AIN;//Ä£ÄâÊäÈë
- GPIO_Init(GPIOB, GPIO_InitStructure);//PB0 1
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 ;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AIN;//Ä£ÄâÊäÈë
- GPIO_Init(GPIOC, GPIO_InitStructure);//PC0 1 2 3 4 5
- }
- void ADC1_DMA_Init(void)
- {
- DMA_InitTypeDef DMA_InitStructure;
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);//ʹÄÜDMAʱÖÓ
- ///**************************DMAͨµÀ1ÅäÖÃ****************************/////
- DMA_DeInit(DMA1_Channel1);//DMAͨµÀ1³õʼ»¯
- DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;//ADCµØÖ·
- DMA_InitStructure.DMA_MemoryBaseAddr = (u32) After_filter;//ÄÚ´æµØÖ·
- DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;//ÍâÉèΪÊý¾ÝÔ´
- DMA_InitStructure.DMA_BufferSize = 16;//MAX_ADC_CH*GET_ADC_NMB;
- 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;//Ñ shy;»·´«Êä
- DMA_InitStructure.DMA_Priority = DMA_Priority_High;
- DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
- DMA_Init(DMA1_Channel1, DMA_InitStructure);
- DMA_Cmd(DMA1_Channel1,ENABLE);
- }
- void ADC1_Mode_Config(void)
- {
- ADC_InitTypeDef ADC_InitStructure;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 ,ENABLE);//ʹÄÜADC1ʱÖÓ
- //*******************************ADC1ÅäÖÃ**********************///
- ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;//¶ÀÁ¢ADCģʽ
- ADC_InitStructure.ADC_ScanConvMode = ENABLE;//½ûֹɨÃèģʽ£¬É¨ÃèģʽÓÃÓÚ¶àͨµÀ²É¼¯
- ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;//¿ªÆôÁ¬Ðøģʽ£¬¼´²»Í£µÄ½øÐÐADCת»»
- ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;//²»Ê¹ÓÃÍⲿ´¥·¢×ª»»
- ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;//²É¼¯Êý¾ÝÓÒ¶ÔÆë
- ADC_InitStructure.ADC_NbrOfChannel = 8;//Ҫת»»µÄͨµÀÊýÄ¿
- ADC_Init(ADC1, ADC_InitStructure);
- RCC_ADCCLKConfig(RCC_PCLK2_Div8);//ÅäÖÃADCʱÖÓ£¬ÎªPCLK2µÄ8·ÖƵ£¬¼´9MHz
- ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_55Cycles5); //ADC4 PC0 µçÁ÷1
- ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 2, ADC_SampleTime_55Cycles5); //ADC5 PC1 µçÁ÷2
- ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 3, ADC_SampleTime_55Cycles5); //ADC2 PC2 µçÁ÷3
- ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 4, ADC_SampleTime_55Cycles5); //ADC3 PC3 µçÁ÷4
- ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 5, ADC_SampleTime_55Cycles5); //ADC12 PA0 µçÁ÷5
- ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 6, ADC_SampleTime_55Cycles5); //ADC13 PA1 µçÁ÷6
- ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 7, ADC_SampleTime_55Cycles5); //ADC11 PA2 µçÁ÷7
- ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 8, ADC_SampleTime_55Cycles5); //ADC10 PA3 µçÁ÷8
- ADC_DMACmd(ADC1,ENABLE);
- ADC_Cmd(ADC1,ENABLE);
- ADC_ResetCalibration(ADC1);//¸´Î»Ð£×¼¼Ä´æÆ÷
- while(ADC_GetResetCalibrationStatus(ADC1));//µÈ´ýУ׼¼Ä´æÆ÷¸´Î»Íê³É
- ADC_StartCalibration(ADC1);//ADCУ׼
- while(ADC_GetCalibrationStatus(ADC1));//µÈ´ýУ׼Íê³É
- ADC_SoftwareStartConvCmd(ADC1,ENABLE);//ÓÉÓÚûÓвÉÓÃÍⲿ´¥·¢£¬ËùÒÔʹÓÃÈí¼þ´¥·¢ADCת»»
- }
- void pid_task(void *pdata)
- {
- float temp=0;
- pdata = pdata;
- ADC1_Init(); //ADC³õʼ»¯
- OSTimeDlyHMSM(0, 0, 0, 100);//ÑÓʱ0.1Ãë
- for(;;)
- {
- OSTimeDlyHMSM(0, 0, 0, 10);//ÑÓʱ1Ãë
- TIM_SetCompare1(TIM1, After_filter[0]);
- TIM_SetCompare2(TIM1, After_filter[1]);
- TIM_SetCompare3(TIM1, After_filter[2]);
- TIM_SetCompare4(TIM1, After_filter[3]);
- TIM_SetCompare3(TIM2, After_filter[4]);
- TIM_SetCompare4(TIM2, After_filter[5]);
- TIM_SetCompare1(TIM4, After_filter[6]);
- TIM_SetCompare2(TIM4, After_filter[7]);
- }
- }
更多回帖