Rewrite the M1 command to send the drive signal after receiving the M1 command, and turn on TIMER16 at the same time. Set the measurement completion flag after 240us, and turn off TIMER16 after the maximum TOF timing.

This commit is contained in:
2025-08-20 00:25:03 +08:00
parent 70a6311425
commit 16c5a31a63
4 changed files with 59 additions and 83 deletions

View File

@@ -102,39 +102,30 @@ void SysTick_Handler(void) {
delay_decrement();
}
// /**
// * @brief This function handles TIMER15 interrupt request.
// * @param[in] none
// * @param[out] none
// * @retval None
// */
// void TIMER15_IRQHandler(void) {
// if (timer_interrupt_flag_get(US_TX_DELAY_TIMER, TIMER_INT_FLAG_UP) == SET)
// {
// timer_interrupt_flag_clear(US_TX_DELAY_TIMER, TIMER_INT_FLAG_UP);
// exti_interrupt_enable(US_RX_GPIO_EXTI); // turn on hardware external input interrupt
// timer_counter_value_config(US_ECHO_TIMER, 0);
// timer_enable(US_ECHO_TIMER); // turn on timer to calculate the first ultrasonic echo time
// timer_disable(US_TX_DELAY_TIMER);
// }
// }
void TIMER15_IRQHandler(void) {
if (timer_interrupt_flag_get(TIMER15, TIMER_INT_FLAG_CH1)) {
timer_interrupt_flag_clear(TIMER15, TIMER_INT_FLAG_CH1);
// g_ultrasonic_measure_done = true; // TODO 测距命令发送回报标识位,最终不应在这里
gpio_bit_set(GPIOA, GPIO_PIN_0); // TODO waiting for delete
void TIMER16_IRQHandler(void) {
// 处理通道0比较中断240us时触发
if (timer_interrupt_flag_get(TIMER16, TIMER_INT_FLAG_CH0)) {
timer_interrupt_flag_clear(TIMER16, TIMER_INT_FLAG_CH0);
// 在240us时执行的操作
g_ultrasonic_measure_done = true; // 设置测量完成标志
// TODO: 在这里可以执行其他240us时需要的操作
// 例如启动其他定时器、设置GPIO、记录时间戳等
}
if (timer_interrupt_flag_get(TIMER15, TIMER_INT_FLAG_UP)) {
timer_interrupt_flag_clear(TIMER15, TIMER_INT_FLAG_UP);
timer_disable(TIMER15);
// 处理重装载中断1000us时触发即超时
if (timer_interrupt_flag_get(TIMER16, TIMER_INT_FLAG_UP)) {
timer_interrupt_flag_clear(TIMER16, TIMER_INT_FLAG_UP);
// 达到最大时间1ms自动关闭定时器
timer_disable(TIMER16);
// TODO: 超时处理逻辑
// 如果需要,可以在这里设置超时标志或执行其他清理操作
}
}
/**
* @brief This function handles external lines 0 to 1 interrupt request
* @param[in] none
@@ -165,7 +156,7 @@ void TIMER13_IRQHandler(void)
if(pwm_cycle_count >= (ULTRASONIC_TX_CYCLES)) {
timer_disable(TIMER13);
pwm_cycle_count = 0;
g_ultrasonic_measure_done = true; // TODO 测距命令发送回报标识位,最终不应在这里
// g_ultrasonic_measure_done = true; // 注释掉现在由TIMER16在240us时设置
}
}