想在20ms的定时周期内利用翻转功能在2-4ms之内输出高电平,希望大神能帮我看看哪里不对
void COM_Init(void)
{
TIM_TimeBaseInitTypeDef TIM_Base_Init;
TIM_OCInitTypeDef TIM_OC_Init;
NVIC_InitTypeDef COM_NVIC_Init;
GPIO_InitTypeDef COM_GPIO_Init;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5 , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO , ENABLE);
COM_GPIO_Init.GPIO_Mode = GPIO_Mode_AF_PP;
COM_GPIO_Init.GPIO_Pin = GPIO_Pin_1;
COM_GPIO_Init.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &COM_GPIO_Init);
TIM_Base_Init.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_Base_Init.TIM_Period = 1199;
TIM_Base_Init.TIM_Prescaler = 0;
TIM_Base_Init.TIM_CounterMode = TIM_CounterMode_Down;
TIM_TimeBaseInit(TIM5 , &TIM_Base_Init);
TIM_PrescalerConfig(TIM5,1199,TIM_PSCReloadMode_Immediate);
TIM_OC_Init.TIM_OCMode = TIM_OCMode_Timing;
TIM_OC_Init.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OC_Init.TIM_OutputState = TIM_OutputState_Enable;
TIM_OC_Init.TIM_Pulse = 120;
TIM_OC2Init(TIM5 ,&TIM_OC_Init);
TIM_OC2PreloadConfig(TIM5 , TIM_OCPreload_Disable);
TIM_ARRPreloadConfig(TIM5 , DISABLE);
COM_NVIC_Init.NVIC_IRQChannel = TIM5_IRQn;
COM_NVIC_Init.NVIC_IRQChannelCmd = ENABLE;
COM_NVIC_Init.NVIC_IRQChannelPreemptionPriority = 0;
COM_NVIC_Init.NVIC_IRQChannelSubPriority = 3;
NVIC_Init(&COM_NVIC_Init);
TIM_ITConfig(TIM5, TIM_IT_CC2, ENABLE);
GPIO_SetBits(GPIOA , GPIO_Pin_1);
TIM_Cmd(TIM5, ENABLE);
}
void TIM5_IRQHandler(void)
{
if(TIM_GetITStatus(TIM5, TIM_IT_CC2) != RESET)
{
TIM_ClearITPendingBit(TIM5, TIM_IT_CC2);
TIM_SetCompare2(TIM5,240);
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>