[mw_shl_code=applescript,true]void TIM5_IRQHandler(void)
{
if(TIM_GetITStatus(TIM5,TIM_IT_Update)==SET)
{
TIM2->CR1=TIM_CR1_URS;
TIM2->CR1&=(~0X1);
TIM2->EGR|=0X1;
}
TIM_ClearITPendingBit(TIM5,TIM_IT_Update);
}
//TIM14 PWM2¿·Ö3õê¼»ˉ
//PWMêä3ö3õê¼»ˉ
//arr£o×Ô¶ˉÖØ×°Öμ
//psc£oê±ÖóÔ¤·ÖÆμêy
void TIM_PWM_Init(void)
{
//′Ë2¿·ÖDèêÖ¶ˉDT¸ÄIO¿úéèÖÃ
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE); //TIM14ê±Öóê1Äü
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); //ê1ÄüPORTFê±Öó
GPIO_PinAFConfig(GPIOA,GPIO_PinSource5,GPIO_AF_TIM2); //GPIOF9¸′óÃÎa¶¨ê±Æ÷14
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //¸′óÃ1|Äü
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //Ëù¶è100MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //íÆíì¸′óÃêä3ö
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //éÏà-
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //GPIOF9
GPIO_Init(GPIOA,&GPIO_InitStructure);
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; //ÏòéϼÆêyÄ£ê½
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM2->CR1=TIM_CR1_URS;
TIM_TimeBaseStructure.TIM_Prescaler=41; //¶¨ê±Æ÷·ÖÆμ
TIM_TimeBaseStructure.TIM_Period=1; //×Ô¶ˉÖØ×°ÔØÖμ
TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure);//3õê¼»ˉ¶¨ê±Æ÷14
//3õê¼»ˉTIM14 Channel1 PWMÄ£ê½
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //Ñ¡Ôñ¶¨ê±Æ÷Ä£ê½:TIMÂö3å¿í¶èμ÷ÖÆÄ£ê½2
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //±è½Ïêä3öê1Äü
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; //êä3ö¼«DÔ:TIMêä3ö±è½Ï¼«DÔμí
TIM_OC1Init(TIM2, &TIM_OCInitStructure); //¸ù¾YTÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèTIM1 4OC1
TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Enable); //ê1ÄüTIM14ÔúCCR1éÏμÄԤװÔؼÄ′æÆ÷
TIM_ARRPreloadConfig(TIM2,ENABLE);//ARPEê1Äü
TIM_SelectOutputTrigger(TIM2,TIM_TRGOSource_OC1Ref);
TIM_SelectMasterSlaveMode(TIM2,TIM_MasterSlaveMode_Enable);
TIM_ARRPreloadConfig(TIM2,ENABLE);
TIM_Cmd(TIM2, ENABLE); //ê1ÄüTIM14
TIM_CtrlPWMOutputs(TIM2, ENABLE);
TIM2->BDTR=0X8000;
}
void TIM5_Int_Init(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_DeInit(TIM5);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5,ENABLE);
//RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); //ê1ÄüPORTFê±Öó
TIM5->CR1=TIM_CR1_URS;
// NVIC_Configuration(8);
TIM_TimeBaseStructure.TIM_Period= 2; //×Ô¶ˉÖØ×°Öμ
TIM_TimeBaseStructure.TIM_Prescaler= 0; //??????
TIM_TimeBaseStructure.TIM_ClockDivision=0; //????
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;//????
TIM_TimeBaseInit(TIM5,&TIM_TimeBaseStructure);
TIM_SelectInputTrigger(TIM5,TIM_TS_ITR0);//??TIM2?????? ????3 TIM4
TIM_InternalClockConfig(TIM5);
TIM5->SMCR |= 0x0007;//??????????,??????1 ???????
TIM5->CR1=TIM_CR1_OPM;
TIM2->DIER=TIM_DIER_UIE;
//TIM_UpdateDisableConfig(TIM4,ENABLE);
TIM_ARRPreloadConfig(TIM5, ENABLE);
TIM_ClearFlag(TIM5,TIM_FLAG_Update); //????????
TIM_ITConfig(TIM5,TIM_IT_Update,ENABLE);
// TIM_Cmd(TIM5,ENABLE);//??????(??????????,?????)
NVIC_InitStructure.NVIC_IRQChannel =TIM5_IRQn;//ía2¿ÖD¶Ï0
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;//ÇàÕ¼óÅÏ輶0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x03;//×óóÅÏ輶2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//ê1Äüía2¿ÖD¶Ïí¨μà
NVIC_Init(&NVIC_InitStructure);//ÅäÖ
}
[/mw_shl_code]
为什么进不了中断那,好像TIM5的计数根本没启动
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>