generated from hulk/gd32e23x_template_cmake_vscode
Simplify the use of timers, timer13 sends ultrasonic waves, timer16 counts (debounce time and flight time)
The ultrasonic transducer is driven only after each command is issued.
This commit is contained in:
@@ -102,27 +102,18 @@ void SysTick_Handler(void) {
|
||||
delay_decrement();
|
||||
}
|
||||
|
||||
void TIMER16_IRQHandler(void) {
|
||||
// 处理通道0比较中断(240us时触发)
|
||||
if (timer_interrupt_flag_get(TIMER16, TIMER_INT_FLAG_CH0)) {
|
||||
void TIMER16_IRQHandler(void)
|
||||
{
|
||||
// CH0比较中断 (ULTRASONIC_TX_RINGDOWN_RELOAD)
|
||||
if(timer_interrupt_flag_get(TIMER16, TIMER_INT_FLAG_CH0) != RESET) {
|
||||
timer_interrupt_flag_clear(TIMER16, TIMER_INT_FLAG_CH0);
|
||||
|
||||
// 在240us时执行的操作
|
||||
g_ultrasonic_measure_done = true; // 设置测量完成标志
|
||||
|
||||
// TODO: 在这里可以执行其他240us时需要的操作
|
||||
// 例如:启动其他定时器、设置GPIO、记录时间戳等
|
||||
exti_interrupt_enable(US_RX_GPIO_EXTI);
|
||||
}
|
||||
|
||||
// 处理重装载中断(1000us时触发,即超时)
|
||||
if (timer_interrupt_flag_get(TIMER16, TIMER_INT_FLAG_UP)) {
|
||||
|
||||
// UP更新中断 (ULTRASONIC_MAX_TOF_RELOAD)
|
||||
if(timer_interrupt_flag_get(TIMER16, TIMER_INT_FLAG_UP) != RESET) {
|
||||
timer_interrupt_flag_clear(TIMER16, TIMER_INT_FLAG_UP);
|
||||
|
||||
// 达到最大时间(1ms),自动关闭定时器
|
||||
timer_disable(TIMER16);
|
||||
|
||||
// TODO: 超时处理逻辑
|
||||
// 如果需要,可以在这里设置超时标志或执行其他清理操作
|
||||
timer_disable(US_ECHO_TIMER);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,14 +127,12 @@ void EXTI0_1_IRQHandler(void) {
|
||||
if (exti_interrupt_flag_get(US_RX_GPIO_EXTI) == SET)
|
||||
{
|
||||
exti_interrupt_flag_clear(US_RX_GPIO_EXTI);
|
||||
// g_capture_value = timer_channel_capture_value_register_read(US_ECHO_TIMER, US_ECHO_CH);
|
||||
|
||||
timer_disable(US_ECHO_TIMER);
|
||||
g_ultrasonic_measure_done = true; // 超声转换完成,置位flag后有命令处理部分回包
|
||||
exti_interrupt_disable(US_RX_GPIO_EXTI);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* PWM周期计数器 - 使用ULTRASONIC_TX_CYCLES宏 */
|
||||
volatile uint8_t pwm_cycle_count = 0;
|
||||
|
||||
@@ -156,7 +145,6 @@ void TIMER13_IRQHandler(void)
|
||||
if(pwm_cycle_count >= (ULTRASONIC_TX_CYCLES)) {
|
||||
timer_disable(TIMER13);
|
||||
pwm_cycle_count = 0;
|
||||
// g_ultrasonic_measure_done = true; // 注释掉,现在由TIMER16在240us时设置
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user