Convert ultrasonic flight time to distance value

This commit is contained in:
2024-09-25 17:25:07 +08:00
parent b6b6932c08
commit 9cdd0008a5
2 changed files with 15 additions and 0 deletions

View File

@@ -177,3 +177,15 @@ void ultrasonic_echo_timer_config(void)
timer_icinitpara.icfilter = 0x03; // 设置滤波器
timer_input_capture_config(US_ECHO_TIMER, US_ECHO_CH, &timer_icinitpara);
}
uint16_t calculate_distance(uint32_t us_value) {
uint16_t distace = (TIME_CORRECTION_US + us_value) * 17;
/*
* (TIME_CORRECTION_US + us_value) * 340 m/s
* -----------------------------------------
* 1000 000
* ----------------------------------------------
* 2
*/
return distace;
}