下面先贴出程序 void TIM4_Configuration(void)//TIM4初始化函数 { //TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; //TIM_OCInitTypeDef TIM_OCInitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_ICInitTypeDef TIM_ICInitStructure; TIM_DeInit(TIM4); TIM_TimeBaseStructure.TIM_Period =7199; TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); TIM_ICInitStructure.TIM_Channel = TIM_Channel_2; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; TIM_ICInitStructure.TIM_ICFilter = 0x0; TIM_PWMIConfig(TIM4, &TIM_ICInitStructure); TIM_SelectInputTrigger(TIM4, TIM_TS_TI2FP2); /* Select the TIM2 Input Trigger: TI2FP2 */ TIM_SelectSlaveMode(TIM4, TIM_SlaveMode_Reset); /* Select the slave Mode: Reset Mode */ TIM_SelectMasterSlaveMode(TIM4, TIM_MasterSlaveMode_Enable); /* Enable the Master/Slave Mode */ TIM_Cmd(TIM4, ENABLE); /* TIM enable counter */ TIM_ITConfig(TIM4, TIM_IT_CC2, ENABLE); /* Enable the CC2 Interrupt Request */ /* void TIM4_IRQHandler(void) { if(TIM_GetITStatus(TIM4, TIM_IT_CC2) == SET) { TIM_ClearITPendingBit(TIM4, TIM_IT_CC2); IC1_Value = TIM_GetCapture1(TIM4); IC2_Value = TIM_GetCapture2(TIM4); IC3_Value=180*IC1_Value*100/7200; } 测得的PWM的脉宽比周期正常。按照道理来说可以测量脉宽啊。 |
RE:香版:STM32捕捉PWM周期和脉宽时间程序分享及疑问
回复:香版:STM32捕捉PWM周期和脉宽时间程序分享及疑问
void EXTI9_5_IRQHandler(void)
{
IC3_Value=0;
if(EXTI_GetITStatus(EXTI_Line8) != RESET)
{
while(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_8))
{IC3_Value++;}
IC3_Value=(int)IC3_Value*0.13515;
/* 清除EXTI line8 中断挂起位 */
EXTI_ClearITPendingBit(EXTI_Line8);
}
}
可以实现功能,不过哪里可以精简?
RE:香版:STM32捕捉PWM周期和脉宽时间程序分享及疑问