高中生
最后登录1970-1-1
在线时间 小时
注册时间2015-11-5
|
定时器2通道1和2能工作,为什么通道3不能。。。。- void TIM2_Config_task(void *pdata)
- {
- while(1)
- {
-
- GPIO_InitTypeDef GPIO_InitStructure;
-
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- TIM_OCInitTypeDef TIM_OCInitStructure;
-
- /*******************TIM2_GPIO_ConfigèÎÎñ******************/
-
- /* GPIOB clock enable */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
-
- if(clas=='a')
- {
- GPIOA->CRL &=0X00000000;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; /*ÅäÖÃPWMμ½PA0éÏ*/
- }
- else if (clas=='b')
- {
- GPIOA->CRL &=0X00000000;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ; /*ÅäÖÃPWMμ½PA1éÏ*/
- }
- else if (clas=='c')
- {
- GPIOA->CRL &=0X00000000;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 ; /*ÅäÖÃPWMμ½PA2éÏ*/
- }
- else if (clas=='0')
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2;
- clas=1;
-
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; // ¸′óÃíÆíìêä3ö
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-
-
- /*******************TIM2_Mode_ConfigèÎÎñ*****************/
-
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); //ê1ÄüTIM2ê±Öó
- /* »ù±¾¶¨ê±Æ÷ÅäÖà */
- TIM_TimeBaseStructure.TIM_Period = 255; //챶¨ê±Æ÷′ó0¼Æêyμ½255£¬¼′Îa266′Σ¬Îaò»¸ö¶¨ê±ÖüÆú589
- TIM_TimeBaseStructure.TIM_Prescaler = 493; //éèÖÃÔ¤·ÖÆμ£o
- TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1 ; //éèÖÃê±Öó·ÖÆμÏμêy£o2»·ÖÆμ(ÕaàïóÃ2»μ½)
- TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //ÏòéϼÆêyÄ£ê½
- TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
- /* PWMÄ£ê½ÅäÖà */
- TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //ÅäÖÃÎaPWMÄ£ê½1
- TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //ê1Äüêä3ö
- TIM_OCInitStructure.TIM_Pulse = 0; //éèÖÃ3õê¼PWMÂö3å¿í¶èÎa0
- TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //챶¨ê±Æ÷¼ÆêyÖμD¡óúCCR1_Valê±Îaμíμçƽ
- TIM_OC1Init(TIM2, &TIM_OCInitStructure); //ê1Äüí¨μà1
- TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Enable); //ê1ÄüԤװÔØ
-
- TIM_OC2Init(TIM2, &TIM_OCInitStructure); //ê1Äüí¨μà2
- TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Enable); //ê1ÄüԤװÔØ
- TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;
- TIM_OCInitStructure.TIM_Pulse=500;
- TIM_OC3Init(TIM2, &TIM_OCInitStructure); //ê1Äüí¨μà3
- TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Enable); //ê1ÄüԤװÔØ
-
- // TIM_OC4Init(TIM2, &TIM_OCInitStructure); //ê1Äüí¨μà4
- // TIM_OC4PreloadConfig(TIM2, TIM_OCPreload_Enable); //ê1ÄüԤװÔØ
- TIM_ARRPreloadConfig(TIM2, ENABLE); //ê1ÄüTIM2ÖØÔؼÄ′æÆ÷ARR
- /* TIM2 enable counter */
- TIM_Cmd(TIM2, ENABLE); //ê1Äü¶¨ê±Æ÷2
-
- TIM_ITConfig(TIM2,TIM_IT_Update, ENABLE); //ê1ÄüupdateÖD¶Ï
-
- OSTaskCreate(NVIC_Config_PWM_task,(void*)0,
- (OS_STK*)&NVIC_Config_PWM_TASK_STK
- [NVIC_Config_PWM_STK_SIZE-1],
- NVIC_Config_PWM_TASK_PRIO); //ÅäÖÃÖD¶ÏóÅÏ輶
- OSTaskDel(OS_PRIO_SELF);
- // OSTimeDly(1);
- }
- }
复制代码
|
|