21ic问答首页 - GD32F305VG timer0输入捕获无反应
GD32F305VG timer0输入捕获无反应
CapSean2021-04-25
各位大佬好! 我按照GD32F30x的标准库配置了GD32F305VG 的timer0定时器并开启了输入捕获功能,配置代码如下:
void timer_config(void)
{
/* -----------------------------------------------------------------------
timer_parameter_struct timer_initpara;
timer_ic_parameter_struct timer_icinitpara;
rcu_periph_clock_enable(RCU_TIMER0);
timer_deinit(TIMER0);
/*NVIC config*/
nvic_irq_enable(TIMER0_UP_TIMER9_IRQn, 1, 1);
nvic_irq_enable(TIMER0_Channel_IRQn, 1, 0);
/* TIMER0 configuration */
timer_initpara.prescaler = 119;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 999;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0;
timer_init(TIMER0, &timer_initpara);
timer_icinitpara.icpolarity = TIMER_IC_POLARITY_RISING;
timer_icinitpara.icselection = TIMER_IC_SELECTION_DIRECTTI;
timer_icinitpara.icprescaler = TIMER_IC_PSC_DIV1;
timer_icinitpara.icfilter = 0x0;
timer_input_capture_config(TIMER0, TIMER_CH_0, &timer_icinitpara);
timer_input_capture_config(TIMER0, TIMER_CH_3, &timer_icinitpara);
/* auto-reload preload enable */
timer_auto_reload_shadow_enable(TIMER0);
timer_interrupt_flag_clear(TIMER0,TIMER_INT_FLAG_CH0);
timer_interrupt_flag_clear(TIMER0,TIMER_INT_FLAG_CH3);
timer_interrupt_enable(TIMER0,TIMER_INT_CH0);
timer_interrupt_enable(TIMER0,TIMER_INT_CH3);
timer_interrupt_enable(TIMER0,TIMER_INT_UP);
timer_enable(TIMER0);
}
/*中断服务程序*/
void TIMER0_UP_TIMER9_IRQHandler(void) {
if ( timer_interrupt_flag_get(TIMER0, TIMER_INT_FLAG_UP) != RESET ) {
timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_UP);
timer0tick++;
}
}
void TIMER0_Channel_IRQHandler() {
if ( timer_interrupt_flag_get(TIMER0, TIMER_INT_FLAG_CH0) != RESET) {
timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_CH0);
}
else if (timer_interrupt_flag_get(TIMER0, TIMER_INT_FLAG_CH3) != RESET){
timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_CH3);
rcvcnt++;
}
}
TIMER0 CH0和CH3的GPIO口确定可以正常检测到高低电平,然而软件在运行中,只有更新中断是正常的,输入捕获中断一直触发不了,不知道各位大佬们是否有遇到过此类问题,恳请指点一二,感谢!
void timer_config(void)
{
/* -----------------------------------------------------------------------
timer_parameter_struct timer_initpara;
timer_ic_parameter_struct timer_icinitpara;
rcu_periph_clock_enable(RCU_TIMER0);
timer_deinit(TIMER0);
/*NVIC config*/
nvic_irq_enable(TIMER0_UP_TIMER9_IRQn, 1, 1);
nvic_irq_enable(TIMER0_Channel_IRQn, 1, 0);
/* TIMER0 configuration */
timer_initpara.prescaler = 119;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 999;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0;
timer_init(TIMER0, &timer_initpara);
timer_icinitpara.icpolarity = TIMER_IC_POLARITY_RISING;
timer_icinitpara.icselection = TIMER_IC_SELECTION_DIRECTTI;
timer_icinitpara.icprescaler = TIMER_IC_PSC_DIV1;
timer_icinitpara.icfilter = 0x0;
timer_input_capture_config(TIMER0, TIMER_CH_0, &timer_icinitpara);
timer_input_capture_config(TIMER0, TIMER_CH_3, &timer_icinitpara);
/* auto-reload preload enable */
timer_auto_reload_shadow_enable(TIMER0);
timer_interrupt_flag_clear(TIMER0,TIMER_INT_FLAG_CH0);
timer_interrupt_flag_clear(TIMER0,TIMER_INT_FLAG_CH3);
timer_interrupt_enable(TIMER0,TIMER_INT_CH0);
timer_interrupt_enable(TIMER0,TIMER_INT_CH3);
timer_interrupt_enable(TIMER0,TIMER_INT_UP);
timer_enable(TIMER0);
}
/*中断服务程序*/
void TIMER0_UP_TIMER9_IRQHandler(void) {
if ( timer_interrupt_flag_get(TIMER0, TIMER_INT_FLAG_UP) != RESET ) {
timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_UP);
timer0tick++;
}
}
void TIMER0_Channel_IRQHandler() {
if ( timer_interrupt_flag_get(TIMER0, TIMER_INT_FLAG_CH0) != RESET) {
timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_CH0);
}
else if (timer_interrupt_flag_get(TIMER0, TIMER_INT_FLAG_CH3) != RESET){
timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_CH3);
rcvcnt++;
}
}
TIMER0 CH0和CH3的GPIO口确定可以正常检测到高低电平,然而软件在运行中,只有更新中断是正常的,输入捕获中断一直触发不了,不知道各位大佬们是否有遇到过此类问题,恳请指点一二,感谢!
赞0
评论
2024-07-03
赞0
评论
2024-07-03
赞0
评论
2024-07-03
赞0
评论
2024-07-03
赞0
评论
2024-07-03
赞0
评论
2024-07-03
赞0
评论
2024-06-30
赞0
评论
2024-04-29
赞0
评论
2024-04-29
您需要登录后才可以回复 登录 | 注册