21ic问答首页 - GD32H759IMK6使用定时器0的多模式通道进行输入捕获要怎么配置
GD32H759IMK6使用定时器0的多模式通道进行输入捕获要怎么配置
fz的Kevin2025-01-08
本帖最后由 fz的Kevin 于 2025-1-8 15:44 编辑
公司的项目是要使用到GD32H759IMK6中TIMER0的8个通道进行输入捕获100Khz的方波。根据官方例程普通通道CH0、CH1、CH2、CH3能够正常捕获到,但是在使用多模式通道MCH0、MCH1、MCH2、MCH3时无论怎么配置,进入输入捕获中断函数的频率并不是由外部输入决定的,而是随着TIMER0规定的计时周期变化而变化,请教各位大佬有没有相关配置资料,或者思路。目前的配置如下:
公司的项目是要使用到GD32H759IMK6中TIMER0的8个通道进行输入捕获100Khz的方波。根据官方例程普通通道CH0、CH1、CH2、CH3能够正常捕获到,但是在使用多模式通道MCH0、MCH1、MCH2、MCH3时无论怎么配置,进入输入捕获中断函数的频率并不是由外部输入决定的,而是随着TIMER0规定的计时周期变化而变化,请教各位大佬有没有相关配置资料,或者思路。目前的配置如下:
void timer0_config(void)
{
timer_ic_parameter_struct timer_icinitpara;
timer_parameter_struct timer_initpara;
rcu_periph_clock_enable(RCU_TIMER0);
rcu_periph_clock_enable(RCU_SYSCFG);
timer_deinit(TIMER0);
/* TIMER0 configuration */
timer_struct_para_init(&timer_initpara);
timer_initpara.prescaler = 299;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 65535;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0;
timer_init(TIMER0, &timer_initpara);
/* TIMER0 configuration */
/* TIMER0 CH1 input capture configuration */
timer_channel_input_struct_para_init(&timer_icinitpara);
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_1, &timer_icinitpara);
timer_input_capture_config(TIMER0, TIMER_CH_2, &timer_icinitpara);
timer_input_capture_config(TIMER0, TIMER_CH_3, &timer_icinitpara);
timer_input_capture_config(TIMER0, TIMER_MCH_0, &timer_icinitpara);
timer_input_capture_config(TIMER0, TIMER_MCH_1, &timer_icinitpara);
timer_input_capture_config(TIMER0, TIMER_MCH_2, &timer_icinitpara);
timer_input_capture_config(TIMER0, TIMER_MCH_3, &timer_icinitpara);
timer_master_slave_mode_config(TIMER0 , TIMER_MASTER_SLAVE_MODE_ENABLE);
timer_multi_mode_channel_mode_config(TIMER0,TIMER_MCH_0,TIMER_MCH_MODE_INDEPENDENTLY);
timer_multi_mode_channel_mode_config(TIMER0,TIMER_MCH_1,TIMER_MCH_MODE_INDEPENDENTLY);
timer_multi_mode_channel_mode_config(TIMER0,TIMER_MCH_2,TIMER_MCH_MODE_INDEPENDENTLY);
timer_multi_mode_channel_mode_config(TIMER0,TIMER_MCH_3,TIMER_MCH_MODE_INDEPENDENTLY);
timer_input_trigger_source_select(TIMER0,TIMER_SMCFG_TRGSEL_MCI0FEM0);
timer_input_trigger_source_select(TIMER0,TIMER_SMCFG_TRGSEL_MCI1FEM1);
timer_input_trigger_source_select(TIMER0,TIMER_SMCFG_TRGSEL_MCI2FEM2);
timer_input_trigger_source_select(TIMER0,TIMER_SMCFG_TRGSEL_MCI3FEM3);
timer_slave_mode_select(TIMER0 , TIMER_SLAVE_MODE_EVENT);
/* auto-reload preload enable */
timer_auto_reload_shadow_enable(TIMER0);
/* clear channel 0 interrupt bit */
timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_CH0);
timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_CH1);
timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_CH2);
timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_CH3);
timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_MCH0);
timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_MCH1);
timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_MCH2);
timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_MCH3);
/* channel 0 interrupt enable */
timer_interrupt_enable(TIMER0, TIMER_INT_CH0);
timer_interrupt_enable(TIMER0, TIMER_INT_CH1);
timer_interrupt_enable(TIMER0, TIMER_INT_CH2);
timer_interrupt_enable(TIMER0, TIMER_INT_CH3);
timer_interrupt_enable(TIMER0, TIMER_INT_MCH0);
timer_interrupt_enable(TIMER0, TIMER_INT_MCH1);
timer_interrupt_enable(TIMER0, TIMER_INT_MCH2);
timer_interrupt_enable(TIMER0, TIMER_INT_MCH3);
/* TIMER0 counter enable */
timer_enable(TIMER0);
}
您需要登录后才可以回复 登录 | 注册