void TIM5_CH1_Cap_Init(u32 arr,u16 psc)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5,ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource1,GPIO_AF_TIM5);
TIM_TimeBaseStructure.TIM_Prescaler=psc;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period=arr;
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM5,&TIM_TimeBaseStructure);
TIM5_ICInitStructure.TIM_Channel = TIM_Channel_2;
TIM5_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM5_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM5_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM5_ICInitStructure.TIM_ICFilter = 0x00;
TIM_ICInit(TIM5, &TIM5_ICInitStructure);
TIM_ITConfig(TIM5,TIM_IT_Update|TIM_IT_CC1,ENABLE);
TIM_Cmd(TIM5,ENABLE );
NVIC_InitStructure.NVIC_IRQChannel = TIM5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority =0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void TIM5_IRQHandler(void)
{
if((TIM5CH2_CAPTURE_STA&0X80)==0)//»1Î′3é1|2¶»ñ
{
if(TIM_GetITStatus(TIM5, TIM_IT_Update) != RESET)//òç3ö
{
if(TIM5CH2_CAPTURE_STA&0X40)//òѾ-2¶»ñμ½¸ßμçƽáË
{
if((TIM5CH2_CAPTURE_STA&0X3F)==0X3F)//¸ßμçƽì«3¤áË
{
TIM5CH2_CAPTURE_STA|=0X80; //±ê¼Ç3é1|2¶»ñáËò»′Î
TIM5CH2_CAPTURE_VAL=0XFFFFFFFF;
}else TIM5CH2_CAPTURE_STA++;
}
}
if(TIM_GetITStatus(TIM5, TIM_IT_CC1) != RESET)//2¶»ñ1·¢éú2¶»ñê¼t
{
if(TIM5CH2_CAPTURE_STA&0X40) //2¶»ñμ½ò»¸öϽμÑØ
{
TIM5CH2_CAPTURE_STA|=0X80; //±ê¼Ç3é1|2¶»ñμ½ò»′θßμçƽÂö¿í
TIM5CH2_CAPTURE_VAL=TIM_GetCapture2(TIM5);//»ñè¡μ±Ç°μÄ2¶»ñÖμ.
TIM_OC2PolarityConfig(TIM5,TIM_ICPolarity_Rising); //CC1P=0 éèÖÃÎaéÏéyÑØ2¶»ñ
}else //»1Î′¿aê¼,μúò»′Î2¶»ñéÏéyÑØ
{
TIM5CH2_CAPTURE_STA=0; //Çå¿Õ
TIM5CH2_CAPTURE_VAL=0;
TIM5CH2_CAPTURE_STA|=0X40; //±ê¼Ç2¶»ñμ½áËéÏéyÑØ
TIM_Cmd(TIM5,DISABLE ); //1رն¨ê±Æ÷5
TIM_SetCounter(TIM5,0);
TIM_OC2PolarityConfig(TIM5,TIM_ICPolarity_Falling); //CC1P=1 éèÖÃÎaϽμÑØ2¶»ñ
TIM_Cmd(TIM5,ENABLE ); //ê1Äü¶¨ê±Æ÷5
}
}
}
TIM_ClearITPendingBit(TIM5, TIM_IT_CC1|TIM_IT_Update); //Çå3yÖD¶Ï±ê־λ
}
求助各位大神看看 我按照原子哥的历程 自己配置的TIM4_CH2输入捕获配置, 但是配置完后,无法捕获脉冲。
TIM_ITConfig(TIM5,TIM_IT_Update|TIM_IT_CC1,ENABLE); 这句话 我把TIM_IT_CC1 改成 CC2 之后 示波器上连PWM都看不到了
求助!!!!!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
PWM用TIM3_CH3
一周热门 更多>