Skip to content

Commit

Permalink
Turn off pwm above speed limit.
Browse files Browse the repository at this point in the history
Otherwise it uses pwm from one of the assist function.
  • Loading branch information
dzid26 committed Jul 5, 2024
1 parent 18e8aa8 commit 269ffbf
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/ebike_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down

0 comments on commit 269ffbf

Please sign in to comment.