专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
STM32
小白请教给位大神一个关于输入捕获功能的问题
2019-10-15 03:39
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
STM32/STM8
9629
3
1134
小白今天用原子哥输入捕获例程改了下,用于计数4个编码器的脉冲数并打印打串口,用的是time3通道1234,但是遇到个很奇怪的问题,通道4可以正常工作,但是通道123却出了问题,我没有将对应的io口接任何地方,却不断的在计数脉冲,对应的4个io口没有用于其他地方,配置也是一样的,为什么会出现这种问题呢
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
3条回答
素月墨羽
2019-10-15 08:16
我以前也用过输入捕获功能,也没用遇见这种问题。然后下面把代码贴一下,各位大神走过看一眼,谢谢啦
TIM_ICInitTypeDef TIM3_ICInitStructure;
void TIM3_Cap_Init(u16 arr,u16 psc)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //ê1ÄüTIM5ê±Öó
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB, ENABLE); //ê1ÄüGPIOAê±Öó
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7; //PA67 Çå3y֮ǰéèÖÃ
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //PA67êäèë
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_ResetBits(GPIOA,GPIO_Pin_6|GPIO_Pin_7); //PA67 ÏÂà-
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1; //PB01Çå3y֮ǰéèÖÃ
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //PB01êäèë
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_ResetBits(GPIOB,GPIO_Pin_0|GPIO_Pin_1); //PB01 ÏÂà-
//3õê¼»ˉ¶¨ê±Æ÷3 TIM3
TIM_TimeBaseStructure.TIM_Period = arr; //é趨¼ÆêyÆ÷×Ô¶ˉÖØ×°Öμ
TIM_TimeBaseStructure.TIM_Prescaler =psc; //Ô¤·ÖÆμÆ÷
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //éèÖÃê±Öó·Ö¸î:TDTS = Tck_tim
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIMÏòéϼÆêyÄ£ê½
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); //¸ù¾YTIM_TimeBaseInitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉTIMxμÄê±¼ä»ùêyμ¥λ
//3õê¼»ˉTIM3êäèë2¶»ñ2Îêy
TIM3_ICInitStructure.TIM_Channel = TIM_Channel_1|TIM_Channel_2|TIM_Channel_3|TIM_Channel_4; //CC1S=01 Ñ¡Ôñêäèë¶Ë IC1ó3éäμ½TI1éÏ
TIM3_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //éÏéyÑØ2¶»ñ
TIM3_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; //ó3éäμ½TI2éÏ
TIM3_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //ÅäÖÃêäèë·ÖÆμ,2»·ÖÆμ
TIM3_ICInitStructure.TIM_ICFilter = 0x00;//IC1F=0000 ÅäÖÃêäèëÂË2¨Æ÷ 2»ÂË2¨
TIM_ICInit(TIM3, &TIM3_ICInitStructure);
//ÖD¶Ï·Ö×é3õê¼»ˉ
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; //TIM3ÖD¶Ï
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; //ÏèÕ¼óÅÏ輶2¼¶
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //′óóÅÏ輶0¼¶
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQí¨μà±»ê1Äü
NVIC_Init(&NVIC_InitStructure); //¸ù¾YNVIC_InitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèNVIC¼Ä′æÆ÷
TIM_ITConfig(TIM3,TIM_IT_Update|TIM_IT_CC1|TIM_IT_CC2|TIM_IT_CC3|TIM_IT_CC4,ENABLE);//ÔêDí¸üDÂÖD¶Ï ,ÔêDíCC1IE2¶»ñÖD¶Ï
TIM_Cmd(TIM3,ENABLE ); //ê1Äü¶¨ê±Æ÷3
}
u8 TIM3CH3_CAPTURE_STA=0; //êäèë2¶»ñ×′ì¬
u16 back1;
//¶¨ê±Æ÷5ÖD¶Ï·tÎñ3ìDò
void TIM3_IRQHandler(void)
{
if (TIM_GetITStatus(TIM3, TIM_IT_CC3) != RESET)//2¶»ñ1·¢éú2¶»ñê¼t
{
if(TIM3CH3_CAPTURE_STA&0X40) //2¶»ñμ½ò»¸öϽμÑØ
{
//TIM3CH1_CAPTURE_STA|=0X80; //±ê¼Ç3é1|2¶»ñμ½ò»′θßμçƽÂö¿í
back1++;
printf("%d ",back1);
TIM_OC3PolarityConfig(TIM3,TIM_ICPolarity_Rising); //CC1P=0 éèÖÃÎaéÏéyÑØ2¶»ñ
TIM3CH3_CAPTURE_STA=0; //Çå¿Õ
}else //»1Î′¿aê¼,μúò»′Î2¶»ñéÏéyÑØ
{
TIM3CH3_CAPTURE_STA|=0X40; //±ê¼Ç2¶»ñμ½áËéÏéyÑØ
TIM_OC3PolarityConfig(TIM3,TIM_ICPolarity_Falling); //CC1P=1 éèÖÃÎaϽμÑØ2¶»ñ
}
}
TIM_ClearITPendingBit(TIM3, TIM_IT_CC3|TIM_IT_Update); //Çå3yÖD¶Ï±ê־λ
}
加载中...
查看其它3个回答
一周热门
更多
>
相关问题
STM32F4上I2C(在PROTEUS中模拟)调试不通的问题
6 个回答
芯片供应紧张,准备换个MCU,MM32L系列替换STM32L系列的怎么样?
7 个回答
STM32同时使用两个串口进行数据收发时数据丢包的问题
5 个回答
STM32F103串口通信死机问题
4 个回答
STM32WLE5CC连接SX1268在LoRa模式下能与 SX1278互通吗?
2 个回答
相关文章
ST公司第一款无线低功耗单片机模块有效提高物联网设计生产效率
0个评论
如何实现对单片机寄存器的访问
0个评论
通过USB用STM32片内自带Bootloader下载程序及注意事项
0个评论
欲练此功必先自宫之STM32汇编启动,放慢是为了更好的前行
0个评论
×
关闭
采纳回答
向帮助了您的知道网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
STM32
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
×
付费偷看金额在0.1-10元之间
确定
×
关闭
您已邀请
0
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
TIM_ICInitTypeDef TIM3_ICInitStructure;
void TIM3_Cap_Init(u16 arr,u16 psc)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //ê1ÄüTIM5ê±Öó
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB, ENABLE); //ê1ÄüGPIOAê±Öó
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7; //PA67 Çå3y֮ǰéèÖÃ
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //PA67êäèë
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_ResetBits(GPIOA,GPIO_Pin_6|GPIO_Pin_7); //PA67 ÏÂà-
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1; //PB01Çå3y֮ǰéèÖÃ
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //PB01êäèë
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_ResetBits(GPIOB,GPIO_Pin_0|GPIO_Pin_1); //PB01 ÏÂà-
//3õê¼»ˉ¶¨ê±Æ÷3 TIM3
TIM_TimeBaseStructure.TIM_Period = arr; //é趨¼ÆêyÆ÷×Ô¶ˉÖØ×°Öμ
TIM_TimeBaseStructure.TIM_Prescaler =psc; //Ô¤·ÖÆμÆ÷
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //éèÖÃê±Öó·Ö¸î:TDTS = Tck_tim
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIMÏòéϼÆêyÄ£ê½
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); //¸ù¾YTIM_TimeBaseInitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉTIMxμÄê±¼ä»ùêyμ¥λ
//3õê¼»ˉTIM3êäèë2¶»ñ2Îêy
TIM3_ICInitStructure.TIM_Channel = TIM_Channel_1|TIM_Channel_2|TIM_Channel_3|TIM_Channel_4; //CC1S=01 Ñ¡Ôñêäèë¶Ë IC1ó3éäμ½TI1éÏ
TIM3_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //éÏéyÑØ2¶»ñ
TIM3_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; //ó3éäμ½TI2éÏ
TIM3_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //ÅäÖÃêäèë·ÖÆμ,2»·ÖÆμ
TIM3_ICInitStructure.TIM_ICFilter = 0x00;//IC1F=0000 ÅäÖÃêäèëÂË2¨Æ÷ 2»ÂË2¨
TIM_ICInit(TIM3, &TIM3_ICInitStructure);
//ÖD¶Ï·Ö×é3õê¼»ˉ
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; //TIM3ÖD¶Ï
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; //ÏèÕ¼óÅÏ輶2¼¶
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //′óóÅÏ輶0¼¶
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQí¨μà±»ê1Äü
NVIC_Init(&NVIC_InitStructure); //¸ù¾YNVIC_InitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèNVIC¼Ä′æÆ÷
TIM_ITConfig(TIM3,TIM_IT_Update|TIM_IT_CC1|TIM_IT_CC2|TIM_IT_CC3|TIM_IT_CC4,ENABLE);//ÔêDí¸üDÂÖD¶Ï ,ÔêDíCC1IE2¶»ñÖD¶Ï
TIM_Cmd(TIM3,ENABLE ); //ê1Äü¶¨ê±Æ÷3
}
u8 TIM3CH3_CAPTURE_STA=0; //êäèë2¶»ñ×′ì¬
u16 back1;
//¶¨ê±Æ÷5ÖD¶Ï·tÎñ3ìDò
void TIM3_IRQHandler(void)
{
if (TIM_GetITStatus(TIM3, TIM_IT_CC3) != RESET)//2¶»ñ1·¢éú2¶»ñê¼t
{
if(TIM3CH3_CAPTURE_STA&0X40) //2¶»ñμ½ò»¸öϽμÑØ
{
//TIM3CH1_CAPTURE_STA|=0X80; //±ê¼Ç3é1|2¶»ñμ½ò»′θßμçƽÂö¿í
back1++;
printf("%d ",back1);
TIM_OC3PolarityConfig(TIM3,TIM_ICPolarity_Rising); //CC1P=0 éèÖÃÎaéÏéyÑØ2¶»ñ
TIM3CH3_CAPTURE_STA=0; //Çå¿Õ
}else //»1Î′¿aê¼,μúò»′Î2¶»ñéÏéyÑØ
{
TIM3CH3_CAPTURE_STA|=0X40; //±ê¼Ç2¶»ñμ½áËéÏéyÑØ
TIM_OC3PolarityConfig(TIM3,TIM_ICPolarity_Falling); //CC1P=1 éèÖÃÎaϽμÑØ2¶»ñ
}
}
TIM_ClearITPendingBit(TIM3, TIM_IT_CC3|TIM_IT_Update); //Çå3yÖD¶Ï±ê־λ
}
一周热门 更多>