tim1定时器的配置和中断配置如下,帮忙看看有什么问题
void TIM1_INT_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* TIM1 ʱÖÓʹÄÜ */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 , ENABLE);
/* TIM1 ÖжÏǶÌ×Éè¼Æ*/
NVIC_InitStructure.NVIC_IRQChannel = TIM1_BRK_UP_TRG_COM_IRQn;
NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void TIM1_Toggle_Config(void)
{
/* Time ¶¨Ê±»ù´¡ÉèÖÃ*/
TIM_TimeBaseStructure.TIM_Period = 65535;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
/* Ô¤·ÖƵÆ÷ÅäÖà */
TIM_PrescalerConfig(TIM1, 47, TIM_PSCReloadMode_Immediate);
/* ƵµÀ2µÄ±È½ÏÊä³öģʽÉèÖà */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;//TIM_OCMode_Toggle;//TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
//ʹÄÜƵµÀ2ÅäÖÃ
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 10000;//Puls_Val;
TIM_OC2Init(TIM1, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Disable);
/* TIM ÖжÏʹÄÜ */
TIM_ITConfig(TIM1, TIM_IT_CC2, ENABLE);
/* TIM1 ¼ÆËãÆ÷ʹÄÜ*/
TIM_Cmd(TIM1, ENABLE);
/* TIM1 Ö÷Êä³öʹÄÜ */
TIM_CtrlPWMOutputs(TIM1, ENABLE);
}
此帖出自
小平头技术问答
一周热门 更多>