大学生
最后登录1970-1-1
在线时间 小时
注册时间2016-7-21
|
请各位帮我看看哪里有问题,我这是用例程改的
- static void ADCx_GPIO_Config(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- // ′ò¿a ADC IO¶Ë¿úê±Öó
- macADC_GPIO_APBxClock_FUN ( macADC_GPIO_CLK, ENABLE );
-
- // ÅäÖà ADC IO òy½ÅÄ£ê½
- GPIO_InitStructure.GPIO_Pin = macADC_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
-
- // 3õê¼»ˉ ADC IO
- GPIO_Init(macADC_PORT, &GPIO_InitStructure);
- }
复制代码- static void ADCx_Mode_Config(void)
- {
- ADC_InitTypeDef ADC_InitStructure;
- // ′ò¿aADCê±Öó
- macADC_APBxClock_FUN ( macADC_CLK, ENABLE );
-
- // ADC Ä£ê½ÅäÖÃ
- // Ö»ê1óÃò»¸öADC£¬êôóúμ¥Ä£ê½
- ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
-
- // ½ûÖ1é¨Ãèģ꽣¬¶àí¨μà2Åòa£¬μ¥í¨μà2»Dèòa
- ADC_InitStructure.ADC_ScanConvMode = DISABLE ;
- // á¬Dø×a»»Ä£ê½
- ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
- // óö¨ê±Æ÷¶tCC2′¥·¢
- ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_CC2 ;
- // ×a»»½á1ûóò¶ÔÆë
- ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
-
- // ×a»»í¨μà1¸ö
- ADC_InitStructure.ADC_NbrOfChannel = 1;
-
- // 3õê¼»ˉADC
- ADC_Init(macADCx, &ADC_InitStructure);
-
- // ÅäÖÃADCê±Öó£ÎaPCLK2μÄ8·ÖÆ죬¼′9MHz
- RCC_ADCCLKConfig(RCC_PCLK2_Div8);
-
- // ÅäÖà ADC í¨μà×a»»Ë3DòÎa1£¬μúò»¸ö×a»»£¬2éÑùê±¼äÎa1¸öê±ÖóÖüÆú
- ADC_RegularChannelConfig(macADCx, macADC_CHANNEL, 1, ADC_SampleTime_1Cycles5);
-
- // ADC ×a»»½áêø2úéúÖD¶Ï£¬ÔúÖD¶Ï·tÎñ3ìDòÖD¶áè¡×a»»Öμ
- ADC_ITConfig(macADCx, ADC_IT_EOC, ENABLE);
-
- // ¿aÆôADC £¬2¢¿aê¼×a»»
- ADC_Cmd(macADCx, ENABLE);
-
- // 3õê¼»ˉADC D£×¼¼Ä′æÆ÷
- ADC_ResetCalibration(macADCx);
- // μè′yD£×¼¼Ä′æÆ÷3õê¼»ˉíê3é
- while(ADC_GetResetCalibrationStatus(macADCx));
-
- // ADC¿aê¼D£×¼
- ADC_StartCalibration(macADCx);
- // μè′yD£×¼íê3é
- while(ADC_GetCalibrationStatus(macADCx));
-
- // óö¨ê±Æ÷2′¥·¢
- ADC_ExternalTrigConvCmd(macADCx, ENABLE);
- }[code]static void ADC_NVIC_Config(void)
- {
- NVIC_InitTypeDef NVIC_InitStructure;
- // ÅäÖÃÖD¶ÏóÅÏ輶
- NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- }
- static void TIM2_Configuration(void)
- {
-
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- TIM_OCInitTypeDef TIM_OCInitStructure;
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
-
-
- TIM_TimeBaseStructure.TIM_Period = 1000-1;
- TIM_TimeBaseStructure.TIM_Prescaler = 71;
- TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
- TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
- TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
- TIM_TimeBaseInit(TIM2, & TIM_TimeBaseStructure);
-
- TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;//ÏÂÃæÏêϸËμÃ÷
- TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;//TIM_OutputState_Disable;
- TIM_OCInitStructure.TIM_Pulse = 500;
- TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;//èç1ûPWM1ÎaLow,PWM2òaÎaHigh
- TIM_OC1Init(TIM2, & TIM_OCInitStructure);
-
- TIM_CtrlPWMOutputs(TIM2, ENABLE);
- TIM_Cmd(TIM2, DISABLE);
-
-
- }
- /**
- * @brief ADC3õê¼»ˉ
- * @param ÎT
- * @retval ÎT
- */
- void ADCx_Init(void)
- {
- ADCx_GPIO_Config();
- ADCx_Mode_Config();
- ADC_NVIC_Config();
- TIM2_Configuration();
- }
复制代码 [/code] |
|