大家好,
我用GD32F150的定时器来计数,72MHZ时钟,采用SPM单脉冲模式,
预期的功能是,通过CEN使能计数器以后,开始计数到一个值,然后停止计数。设置UPDATE FLAG标志。
然后我去读这个标志,关闭定时器。算是一个延时功能。
但我按官方例子配置后,发现并不如预期(末尾描述)。
我的配置是:
timer_oc_parameter_struct timer_ocinitpara;
timer_parameter_struct timer_initpara;
timer_ic_parameter_struct timer_icinitpara;
rcu_periph_clock_enable(RCU_TIMER2);
timer_deinit(TIMER2);
timer_initpara.prescaler = 71;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 49999; //car
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0;
timer_init(TIMER2, &timer_initpara);
timer_update_event_enable(TIMER2);
timer_ocinitpara.ocpolarity = TIMER_OC_POLARITY_HIGH;
timer_ocinitpara.outputstate = TIMER_CCX_DISABLE;
timer_ocinitpara.ocidlestate = TIMER_OC_IDLE_STATE_LOW;
timer_channel_output_config(TIMER2, TIMER_CH_1, &timer_ocinitpara);
timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_1, 19999); //cv
timer_channel_output_mode_config(TIMER2, TIMER_CH_1, TIMER_OC_MODE_TIMING);
timer_channel_output_shadow_config(TIMER2, TIMER_CH_1, TIMER_OC_SHADOW_DISABLE);
timer_single_pulse_mode_config(TIMER2, TIMER_SP_MODE_SINGLE);
timer_update_event_enable(TIMER2); //updis
timer_update_source_config(TIMER2, TIMER_UPDATE_SRC_REGULAR);
timer_enable(TIMER2);
配置后,循环读取标志位,发现标志位一直位0,
同时,计数器值也一直在变,并没有停下来,和单脉冲模式表达的不同。
f0 = timer_flag_get(TIMER2, TIMER_FLAG_UP);
N0 = timer_counter_read(TIMER2);
请问各位高手,单脉冲模式怎么用呢?怎么配置?官方例子是外部脚信号,
我改成软件触发,
timer_event_software_generate(TIMER1, TIMER_EVENT_SRC_TRGG);
或者内部时钟也没用。没有使用SLAVE |