diff --git a/commands.c b/commands.c index 368f0795..19249453 100644 --- a/commands.c +++ b/commands.c @@ -178,6 +178,7 @@ void commands_process_packet(unsigned char *data, unsigned char len) { mcconf.l_min_erpm = (float)buffer_get_int32(data, &ind) / 1000.0; mcconf.l_max_erpm = (float)buffer_get_int32(data, &ind) / 1000.0; mcconf.l_max_erpm_fbrake = (float)buffer_get_int32(data, &ind) / 1000.0; + mcconf.l_max_erpm_fbrake_cc = (float)buffer_get_int32(data, &ind) / 1000.0; mcconf.l_min_vin = (float)buffer_get_int32(data, &ind) / 1000.0; mcconf.l_max_vin = (float)buffer_get_int32(data, &ind) / 1000.0; mcconf.l_slow_abs_current = data[ind++]; @@ -237,6 +238,7 @@ void commands_process_packet(unsigned char *data, unsigned char len) { buffer_append_int32(send_buffer, (int32_t)(mcconf.l_min_erpm * 1000.0), &ind); buffer_append_int32(send_buffer, (int32_t)(mcconf.l_max_erpm * 1000.0), &ind); buffer_append_int32(send_buffer, (int32_t)(mcconf.l_max_erpm_fbrake * 1000.0), &ind); + buffer_append_int32(send_buffer, (int32_t)(mcconf.l_max_erpm_fbrake_cc * 1000.0), &ind); buffer_append_int32(send_buffer, (int32_t)(mcconf.l_min_vin * 1000.0), &ind); buffer_append_int32(send_buffer, (int32_t)(mcconf.l_max_vin * 1000.0), &ind); send_buffer[ind++] = mcconf.l_slow_abs_current; diff --git a/conf_general.c b/conf_general.c index 1aee5549..f8ac1b6b 100644 --- a/conf_general.c +++ b/conf_general.c @@ -69,6 +69,9 @@ #ifndef MCPWM_CURR_MAX_RPM_FBRAKE #define MCPWM_CURR_MAX_RPM_FBRAKE 1500 // Maximum electrical RPM to use full brake at #endif +#ifndef MCPWM_CURR_MAX_RPM_FBRAKE_CC +#define MCPWM_CURR_MAX_RPM_FBRAKE_CC 1500 // Maximum electrical RPM to use full brake at with current control +#endif #ifndef MCPWM_SLOW_ABS_OVERCURRENT #define MCPWM_SLOW_ABS_OVERCURRENT false // Use the filtered (and hence slower) current for the overcurrent fault detection #endif @@ -239,6 +242,7 @@ void conf_general_read_mc_configuration(mc_configuration *conf) { conf->l_min_erpm = MCPWM_RPM_MIN; conf->l_max_erpm = MCPWM_RPM_MAX; conf->l_max_erpm_fbrake = MCPWM_CURR_MAX_RPM_FBRAKE; + conf->l_max_erpm_fbrake_cc = MCPWM_CURR_MAX_RPM_FBRAKE_CC; conf->l_min_vin = MCPWM_MIN_VOLTAGE; conf->l_max_vin = MCPWM_MAX_VOLTAGE; conf->l_slow_abs_current = MCPWM_SLOW_ABS_OVERCURRENT; diff --git a/datatypes.h b/datatypes.h index 7fc19976..9a2e5229 100644 --- a/datatypes.h +++ b/datatypes.h @@ -86,6 +86,7 @@ typedef struct { float l_min_erpm; float l_max_erpm; float l_max_erpm_fbrake; + float l_max_erpm_fbrake_cc; float l_min_vin; float l_max_vin; bool l_slow_abs_current; diff --git a/led_external.c b/led_external.c index 99fcd964..fb845604 100644 --- a/led_external.c +++ b/led_external.c @@ -111,8 +111,8 @@ static msg_t led_thread(void *arg) { while (state == state_last && !HAS_FAULT()) { if ((chTimeNow() / (CH_FREQUENCY / 2)) % 2) { - ws2811_set_led_color(WS2811_LED_NUM / 2 - 1, COLOR_ORANGE); - ws2811_set_led_color(WS2811_LED_NUM / 2, COLOR_ORANGE); + ws2811_set_led_color(WS2811_LED_NUM / 2 - 1, 0xFF9900); + ws2811_set_led_color(WS2811_LED_NUM / 2, 0xFF9900); } else { ws2811_set_led_color(WS2811_LED_NUM / 2 - 1, COLOR_BLACK); ws2811_set_led_color(WS2811_LED_NUM / 2, COLOR_BLACK); @@ -134,8 +134,8 @@ static msg_t led_thread(void *arg) { while (state == state_last && !HAS_FAULT()) { if ((chTimeNow() / (CH_FREQUENCY / 2)) % 2) { - ws2811_set_led_color(0, COLOR_ORANGE); - ws2811_set_led_color(WS2811_LED_NUM - 1, COLOR_ORANGE); + ws2811_set_led_color(0, 0xFF9900); + ws2811_set_led_color(WS2811_LED_NUM - 1, 0xFF9900); } else { ws2811_set_led_color(0, COLOR_BLACK); ws2811_set_led_color(WS2811_LED_NUM - 1, COLOR_BLACK); diff --git a/mcpwm.c b/mcpwm.c index e1d02463..f1691e7b 100644 --- a/mcpwm.c +++ b/mcpwm.c @@ -1840,8 +1840,13 @@ void mcpwm_adc_int_handler(void *p, uint32_t flags) { // Lower truncation if (fabsf(dutycycle_now_tmp) < MCPWM_MIN_DUTY_CYCLE) { - dutycycle_now_tmp = 0.0; - dutycycle_set = dutycycle_now_tmp; + if (fabsf(rpm_now) < conf.l_max_erpm_fbrake_cc) { + dutycycle_now_tmp = 0.0; + dutycycle_set = dutycycle_now_tmp; + } else { + dutycycle_now_tmp = SIGN(dutycycle_now_tmp) * MCPWM_MIN_DUTY_CYCLE; + dutycycle_set = dutycycle_now_tmp; + } } } else { utils_step_towards((float*)&dutycycle_now_tmp, dutycycle_set, ramp_step);