GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC ,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* EXTI line(PC0) mode config */
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, GPIO_PinSource0);
EXTI_InitStructure.EXTI_Line = EXTI_Line0;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //ÖD¶ÏÄ£ê½
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; //¿aÆôéÏéyoíϽμÑØÖD¶Ï
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //ê1ÄüÖD¶Ï
EXTI_Init(&EXTI_InitStructure);
void EXTI0_IRQHandler(void)
{
uint32_t pwmin_temp;
if( GPIOC->IDR & 0x0001){
CH6.RisingTime = micros();
}else{
CH6.FallingTime = micros();
if(CH6.FallingTime < CH6.RisingTime){
return ;
} else{
pwmin_temp = CH6.FallingTime - CH6.RisingTime;//T2-T1
}
// if((pwmin_temp>(uint32_t)PWM_Input_MIN) && (pwmin_temp<(uint32_t)PWM_Input_MAX))
{
PWM_Input_CH6 = pwmin_temp;
RC_data[5] = PWM_Input_CH6;
}
}
EXTI->PR=1<<0;
}
用PC0为中断输入引脚,测量结果并不是PWM脉宽,而是PWM周期,测量的PWM周期为20ms,脉宽为2ms,但是调试发现,1S时间上升沿进入中断发生了50次(这个是正常的),而下降沿进入中断发生了100次(很纳闷)。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>