大学生
最后登录1970-1-1
在线时间 小时
注册时间2014-4-1
|
本帖最后由 啄木鸟 于 2016-3-22 23:01 编辑
我想做一个四轴的飞控板,现在想实现遥控器信号的捕捉,利用STM32F103来捕捉PWM。有一个帖子讲得挺好的,http://blog.sina.com.cn/s/blog_63d525fd0100u9o3.html。但是我按那个来不能实现功能。仿真发现当通道2捕捉到上升沿时,能进入中断,但是通道1和通道2 捕捉寄存器的值一直为0,得到的占空比和频率一直为0。手册上的PWM输入模式相应描述。
我的部分程序
static void TIM4_Mode_Config(void)
{
TIM_ICInitTypeDef TIM4_ICInitStructure;
TIM4_ICInitStructure.TIM_Channel = TIM_Channel_2;
TIM4_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM4_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM4_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM4_ICInitStructure.TIM_ICFilter = 0x0;
TIM_PWMIConfig(TIM4, &TIM4_ICInitStructure); //¸ù¾Y2ÎêyÅäÖÃTIMíaéèDÅÏ¢
TIM_SelectInputTrigger(TIM4, TIM_TS_TI2FP2); //Ñ¡ÔñIC2Îaê±Öó′¥·¢Ô′
TIM_SelectSlaveMode(TIM4, TIM_SlaveMode_Reset); //TIM′óģ꽣o′¥·¢DÅoÅμÄéÏéyÑØÖØDÂ3õê¼»ˉ¼ÆêyÆ÷oí′¥·¢¼Ä
TIM_SelectMasterSlaveMode(TIM4, TIM_MasterSlaveMode_Enable); //Æô¶ˉ¶¨ê±Æ÷μı»¶ˉ′¥·¢
TIM_Cmd(TIM4, ENABLE); //Æô¶ˉTIM2
TIM_ITConfig(TIM4, TIM_IT_CC2, ENABLE); //′ò¿aÖD¶Ï
}
void TIM4_IRQHandler(void)
{
TIM_ClearITPendingBit(TIM4, TIM_IT_CC2); //Çå3yTIMÖD¶Ï′y′|àíλ
IC2Value = TIM_GetCapture2(TIM4); //¶áè¡IC22¶»ñ¼Ä′æÆ÷μÄÖ죬¼′PWMÖüÆúμļÆêyÖμ
IC1Value = TIM_GetCapture1(TIM4);
if (IC2Value != 0)
{
DutyCycle = (IC1Value * 100) / IC2Value; //¶áè¡IC12¶»ñ¼Ä′æÆ÷μÄÖ죬2¢¼ÆËãÕ¼¿Õ±è
Frequency = 72000000 / IC2Value; //¼ÆËãÆμÂê
}
else
{
DutyCycle = 0;
Frequency = 0;
}
}
|
|