From 269ffbfb46f0d1261cafb62ac5a18df6c73ee231 Mon Sep 17 00:00:00 2001 From: dzid26 Date: Fri, 5 Jul 2024 01:15:21 +0100 Subject: [PATCH] Turn off pwm above speed limit. Otherwise it uses pwm from one of the assist function. --- src/ebike_app.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/ebike_app.c b/src/ebike_app.c index e7144a9c..c7bf984d 100644 --- a/src/ebike_app.c +++ b/src/ebike_app.c @@ -1438,15 +1438,20 @@ static void apply_temperature_limiting(void) } -static void apply_speed_limit(void) -{ - if (m_configuration_variables.ui8_wheel_speed_max) { - // set battery current target - ui8_adc_battery_current_target = map_ui16((uint16_t) ui16_wheel_speed_x10, - (uint16_t) (((uint8_t)(m_configuration_variables.ui8_wheel_speed_max) * (uint8_t)10U) - (uint8_t)20U), - (uint16_t) (((uint8_t)(m_configuration_variables.ui8_wheel_speed_max) * (uint8_t)10U) + (uint8_t)20U), +static void apply_speed_limit(void) { + if (m_configuration_variables.ui8_wheel_speed_max > 0U) { + uint16_t speed_limit_low = (uint16_t)(m_configuration_variables.ui8_wheel_speed_max * (uint8_t)10U) - 20U; // casting literal to uint8_t ensures usage of MUL X,A + uint16_t speed_limit_high = (uint16_t)(m_configuration_variables.ui8_wheel_speed_max * (uint8_t)10U) + 20U; + + ui8_adc_battery_current_target = map_ui16(ui16_wheel_speed_x10, + speed_limit_low, + speed_limit_high, ui8_adc_battery_current_target, - 0); + 0U); + + if (ui16_wheel_speed_x10 > speed_limit_high) { + ui8_duty_cycle_target = 0; + } } }