@@ -10,12 +10,14 @@ static uint32_t left_val1 = 0;
1010static uint32_t left_val2 = 0 ;
1111static uint8_t left_captured = 0 ;
1212static float left_rpm = 0 ;
13+ static bool pulse_detected_left = false;
1314
1415/* Right Wheel */
1516static uint32_t right_val1 = 0 ;
1617static uint32_t right_val2 = 0 ;
1718static uint8_t right_captured = 0 ;
1819static float right_rpm = 0 ;
20+ static bool pulse_detected_right = false;
1921
2022void wheel_speed_init (TIM_HandleTypeDef * _htim_left , TIM_HandleTypeDef * _htim_right ) {
2123 htim_left = _htim_left ;
@@ -27,6 +29,8 @@ void wheel_speed_init(TIM_HandleTypeDef *_htim_left, TIM_HandleTypeDef *_htim_ri
2729
2830void wheel_speed_capture_callback (TIM_HandleTypeDef * htim ) {
2931 if (htim -> Instance == htim_left -> Instance && htim -> Channel == HAL_TIM_ACTIVE_CHANNEL_1 ) {
32+ pulse_detected_left = true;
33+
3034 if (left_captured == 0 ) {
3135 left_val1 = HAL_TIM_ReadCapturedValue (htim , TIM_CHANNEL_1 );
3236 left_captured = 1 ;
@@ -58,6 +62,8 @@ void wheel_speed_capture_callback(TIM_HandleTypeDef *htim) {
5862 }
5963
6064 if (htim -> Instance == htim_right -> Instance && htim -> Channel == HAL_TIM_ACTIVE_CHANNEL_1 ) {
65+ pulse_detected_right = true;
66+
6167 if (right_captured == 0 ) {
6268 right_val1 = HAL_TIM_ReadCapturedValue (htim , TIM_CHANNEL_1 );
6369 right_captured = 1 ;
@@ -92,6 +98,19 @@ void calculate_wheel_rpm(int frequency, int *rpm) {
9298 * rpm = (frequency * 60.0f ) / PULSES_PER_ROTATION ;
9399}
94100
101+ void wheel_pulse_check () {
102+ if (!pulse_detected_left ) {
103+ left_rpm = 0 ;
104+ }
105+
106+ if (!pulse_detected_right ) {
107+ right_rpm = 0 ;
108+ }
109+
110+ pulse_detected_left = false;
111+ pulse_detected_right = false;
112+ }
113+
95114void send_wheel_speed () {
96115 struct __attribute__((__packed__ )) {
97116 uint16_t right_rpm ;
0 commit comments