From 268350cf704960be95fe1c122efc49464cd36380 Mon Sep 17 00:00:00 2001 From: casainho Date: Sat, 25 Apr 2020 09:44:46 +0100 Subject: [PATCH] Increased PWM frequency and changed UART speed to be twice to get processor speed for the increased PWM frequency. Added coast brake ADC sensitivity, fast stop configuration, Wh/km and field weakening --- firmware/860C_850C/src/usart1.c | 2 +- firmware/common/Makefile.common | 6 +-- firmware/common/include/eeprom.h | 55 +++++++++++++++---------- firmware/common/include/mainscreen.h | 3 ++ firmware/common/include/screen.h | 5 ++- firmware/common/include/state.h | 19 ++++++++- firmware/common/include/uart.h | 2 +- firmware/common/src/configscreen.c | 15 +++++++ firmware/common/src/eeprom.c | 41 +++++++++++++++++-- firmware/common/src/mainscreen.c | 56 ++++++++++++++++++++++---- firmware/common/src/screen.c | 49 +++++++++++++++++++---- firmware/common/src/state.c | 60 ++++++++++++++++++++-------- 12 files changed, 250 insertions(+), 63 deletions(-) diff --git a/firmware/860C_850C/src/usart1.c b/firmware/860C_850C/src/usart1.c index 92e6fc41..612cf846 100755 --- a/firmware/860C_850C/src/usart1.c +++ b/firmware/860C_850C/src/usart1.c @@ -58,7 +58,7 @@ void usart1_init(void) GPIO_Init(USART1__PORT, &GPIO_InitStructure); USART_DeInit(USART1); - USART_InitStructure.USART_BaudRate = 9600; + USART_InitStructure.USART_BaudRate = 19200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; diff --git a/firmware/common/Makefile.common b/firmware/common/Makefile.common index c996393e..bab1ccf1 100755 --- a/firmware/common/Makefile.common +++ b/firmware/common/Makefile.common @@ -8,10 +8,10 @@ VERSION_NUM := 25 # This is the user visible string for the version -VERSION_STRING := 0.8.0 +VERSION_STRING := 1.0.0 # This is the expected version of the motor firmware. Display will stop to work with correct TSDZ2 firmware version -TSDZ2_FIRMWARE_MAJOR := 0 -TSDZ2_FIRMWARE_MINOR := 57 +TSDZ2_FIRMWARE_MAJOR := 1 +TSDZ2_FIRMWARE_MINOR := 0 CFLAGS += -DVERSION_STRING=\"$(VERSION_STRING)\" -DTSDZ2_FIRMWARE_MAJOR=\"$(TSDZ2_FIRMWARE_MAJOR)\" -DTSDZ2_FIRMWARE_MINOR=\"$(TSDZ2_FIRMWARE_MINOR)\" diff --git a/firmware/common/include/eeprom.h b/firmware/common/include/eeprom.h index 1c656662..281b96e6 100755 --- a/firmware/common/include/eeprom.h +++ b/firmware/common/include/eeprom.h @@ -15,8 +15,8 @@ // For compatible changes, just add new fields at the end of the table (they will be inited to 0xff for old eeprom images). For incompatible // changes bump up EEPROM_MIN_COMPAT_VERSION and the user's EEPROM settings will be discarded. -#define EEPROM_MIN_COMPAT_VERSION 0x31 -#define EEPROM_VERSION 0x31 +#define EEPROM_MIN_COMPAT_VERSION 0x35 +#define EEPROM_VERSION 0x35 typedef struct { graph_auto_max_min_t auto_max_min; @@ -38,6 +38,7 @@ typedef struct eeprom_data { uint8_t ui8_battery_max_current; uint8_t ui8_motor_max_current; uint8_t ui8_motor_current_min_adc; + uint8_t ui8_field_weakening; uint8_t ui8_ramp_up_amps_per_second_x10; uint16_t ui16_battery_low_voltage_cut_off_x10; uint8_t ui8_motor_type; @@ -106,6 +107,10 @@ typedef struct eeprom_data { int32_t batteryPowerField_config_error_threshold; int32_t batteryPowerField_config_warn_threshold; uint8_t batteryPowerField_x_axis_scale_config; + field_threshold_t batteryPowerUsageField_auto_thresholds; + int32_t batteryPowerUsageField_config_error_threshold; + int32_t batteryPowerUsageField_config_warn_threshold; + uint8_t batteryPowerUsageField_x_axis_scale_config; field_threshold_t batteryVoltageField_auto_thresholds; int32_t batteryVoltageField_config_error_threshold; int32_t batteryVoltageField_config_warn_threshold; @@ -140,6 +145,9 @@ typedef struct eeprom_data { uint8_t motorFOCField_x_axis_scale_config; #endif + uint8_t ui8_pedal_cadence_fast_stop; + uint8_t ui8_coast_brake_adc; + // FIXME align to 32 bit value by end of structure and pack other fields } eeprom_data_t; @@ -258,6 +266,9 @@ void eeprom_init_defaults(void); #define DEFAULT_STREET_MODE_SPEED_LIMIT 25 // 25 km/h #define DEFAULT_STREET_MODE_POWER_LIMIT 10 // 250W --> 250 / 25 = 10 #define DEFAULT_STREET_MODE_THROTTLE_ENABLE 0 // disabled +#define DEFAULT_PEDAL_CADENCE_FAST_STOP_ENABLE 1 // enabled +#define DEFAULT_COAST_BRAKE_ADC 15 // 15: tested by plpetrov user on 28.04.2020: +#define DEFAULT_FIELD_WEAKENING 1 // 1 enabled #define BICYCLE_1 //#define BICYCLE_2 @@ -266,37 +277,37 @@ void eeprom_init_defaults(void); #define DEFAULT_TORQUE_SENSOR_CALIBRATION_FEATURE_ENABLE 0 // disabled #define DEFAULT_TORQUE_SENSOR_CALIBRATION_PEDAL_GROUND 0 // left pedal #define DEFAULT_TORQUE_SENSOR_CALIBRATION_LEFT_WEIGHT_1 0 -#define DEFAULT_TORQUE_SENSOR_CALIBRATION_LEFT_ADC_1 196 +#define DEFAULT_TORQUE_SENSOR_CALIBRATION_LEFT_ADC_1 203 #define DEFAULT_TORQUE_SENSOR_CALIBRATION_LEFT_WEIGHT_2 5 -#define DEFAULT_TORQUE_SENSOR_CALIBRATION_LEFT_ADC_2 222 +#define DEFAULT_TORQUE_SENSOR_CALIBRATION_LEFT_ADC_2 225 #define DEFAULT_TORQUE_SENSOR_CALIBRATION_LEFT_WEIGHT_3 10 -#define DEFAULT_TORQUE_SENSOR_CALIBRATION_LEFT_ADC_3 245 +#define DEFAULT_TORQUE_SENSOR_CALIBRATION_LEFT_ADC_3 235 #define DEFAULT_TORQUE_SENSOR_CALIBRATION_LEFT_WEIGHT_4 15 -#define DEFAULT_TORQUE_SENSOR_CALIBRATION_LEFT_ADC_4 258 +#define DEFAULT_TORQUE_SENSOR_CALIBRATION_LEFT_ADC_4 240 #define DEFAULT_TORQUE_SENSOR_CALIBRATION_LEFT_WEIGHT_5 19 -#define DEFAULT_TORQUE_SENSOR_CALIBRATION_LEFT_ADC_5 262 -#define DEFAULT_TORQUE_SENSOR_CALIBRATION_LEFT_WEIGHT_6 30 -#define DEFAULT_TORQUE_SENSOR_CALIBRATION_LEFT_ADC_6 269 -#define DEFAULT_TORQUE_SENSOR_CALIBRATION_LEFT_WEIGHT_7 40 -#define DEFAULT_TORQUE_SENSOR_CALIBRATION_LEFT_ADC_7 273 +#define DEFAULT_TORQUE_SENSOR_CALIBRATION_LEFT_ADC_5 243 +#define DEFAULT_TORQUE_SENSOR_CALIBRATION_LEFT_WEIGHT_6 40 +#define DEFAULT_TORQUE_SENSOR_CALIBRATION_LEFT_ADC_6 254 +#define DEFAULT_TORQUE_SENSOR_CALIBRATION_LEFT_WEIGHT_7 54 +#define DEFAULT_TORQUE_SENSOR_CALIBRATION_LEFT_ADC_7 259 #define DEFAULT_TORQUE_SENSOR_CALIBRATION_LEFT_WEIGHT_8 100 -#define DEFAULT_TORQUE_SENSOR_CALIBRATION_LEFT_ADC_8 291 +#define DEFAULT_TORQUE_SENSOR_CALIBRATION_LEFT_ADC_8 273 #define DEFAULT_TORQUE_SENSOR_CALIBRATION_RIGHT_WEIGHT_1 0 -#define DEFAULT_TORQUE_SENSOR_CALIBRATION_RIGHT_ADC_1 190 +#define DEFAULT_TORQUE_SENSOR_CALIBRATION_RIGHT_ADC_1 209 #define DEFAULT_TORQUE_SENSOR_CALIBRATION_RIGHT_WEIGHT_2 5 -#define DEFAULT_TORQUE_SENSOR_CALIBRATION_RIGHT_ADC_2 217 +#define DEFAULT_TORQUE_SENSOR_CALIBRATION_RIGHT_ADC_2 236 #define DEFAULT_TORQUE_SENSOR_CALIBRATION_RIGHT_WEIGHT_3 10 -#define DEFAULT_TORQUE_SENSOR_CALIBRATION_RIGHT_ADC_3 232 +#define DEFAULT_TORQUE_SENSOR_CALIBRATION_RIGHT_ADC_3 247 #define DEFAULT_TORQUE_SENSOR_CALIBRATION_RIGHT_WEIGHT_4 15 -#define DEFAULT_TORQUE_SENSOR_CALIBRATION_RIGHT_ADC_4 238 +#define DEFAULT_TORQUE_SENSOR_CALIBRATION_RIGHT_ADC_4 254 #define DEFAULT_TORQUE_SENSOR_CALIBRATION_RIGHT_WEIGHT_5 19 -#define DEFAULT_TORQUE_SENSOR_CALIBRATION_RIGHT_ADC_5 241 -#define DEFAULT_TORQUE_SENSOR_CALIBRATION_RIGHT_WEIGHT_6 30 -#define DEFAULT_TORQUE_SENSOR_CALIBRATION_RIGHT_ADC_6 246 -#define DEFAULT_TORQUE_SENSOR_CALIBRATION_RIGHT_WEIGHT_7 40 -#define DEFAULT_TORQUE_SENSOR_CALIBRATION_RIGHT_ADC_7 249 +#define DEFAULT_TORQUE_SENSOR_CALIBRATION_RIGHT_ADC_5 258 +#define DEFAULT_TORQUE_SENSOR_CALIBRATION_RIGHT_WEIGHT_6 40 +#define DEFAULT_TORQUE_SENSOR_CALIBRATION_RIGHT_ADC_6 272 +#define DEFAULT_TORQUE_SENSOR_CALIBRATION_RIGHT_WEIGHT_7 54 +#define DEFAULT_TORQUE_SENSOR_CALIBRATION_RIGHT_ADC_7 278 #define DEFAULT_TORQUE_SENSOR_CALIBRATION_RIGHT_WEIGHT_8 100 -#define DEFAULT_TORQUE_SENSOR_CALIBRATION_RIGHT_ADC_8 263 +#define DEFAULT_TORQUE_SENSOR_CALIBRATION_RIGHT_ADC_8 288 #endif #ifdef BICYCLE_2 diff --git a/firmware/common/include/mainscreen.h b/firmware/common/include/mainscreen.h index e850d551..b19af4e9 100755 --- a/firmware/common/include/mainscreen.h +++ b/firmware/common/include/mainscreen.h @@ -17,6 +17,7 @@ extern Field cadenceField, humanPowerField, batteryPowerField, + batteryPowerUsageField, motorMaxPowerField, batteryVoltageField, batteryCurrentField, @@ -48,6 +49,8 @@ extern Field cadenceGraph, humanPowerGraph, batteryPowerGraph, + batteryPowerUsageGraph, + batteryPowerUsageFieldGraph, batteryVoltageGraph, batteryCurrentGraph, motorCurrentGraph, diff --git a/firmware/common/include/screen.h b/firmware/common/include/screen.h index cd5bee70..ed0501a0 100755 --- a/firmware/common/include/screen.h +++ b/firmware/common/include/screen.h @@ -194,6 +194,7 @@ typedef enum { VarsCadence, VarsHumanPower, VarsBatteryPower, + VarsBatteryPowerUsage, VarsBatteryVoltage, VarsBatteryCurrent, VarsMotorCurrent, @@ -325,7 +326,7 @@ typedef const struct Field { } customizable; struct { - const char *label; // the label shown in theauto_thresholds GUI for this item + char *label; // the label shown in theauto_thresholds GUI for this item void *target; // the data we are showing/manipulating const EditableType typ : 2; const uint8_t size :3; // sizeof for the specified target - we support 1 or 2 or 4 @@ -545,6 +546,8 @@ void rt_graph_process(void); int32_t convertUnits(int32_t val, ConvertUnitsType type); +void update_battery_power_usage_label(void); + extern const UG_FONT *editable_label_font; extern const UG_FONT *editable_value_font; extern const UG_FONT *editable_units_font; diff --git a/firmware/common/include/state.h b/firmware/common/include/state.h index 7b7edf74..a46bfcde 100755 --- a/firmware/common/include/state.h +++ b/firmware/common/include/state.h @@ -37,6 +37,12 @@ typedef enum { extern volatile motor_init_state_t g_motor_init_state; +typedef struct battery_energy_h_km_struct { + uint32_t ui32_sum_x50; + uint32_t ui32_value_x100; + uint32_t ui32_value_x10; +} battery_energy_h_km_t; + typedef struct rt_vars_struct { uint16_t ui16_adc_battery_voltage; uint8_t ui8_battery_current_x5; @@ -82,7 +88,8 @@ typedef struct rt_vars_struct { uint8_t ui8_target_max_battery_power_div25; uint8_t ui8_battery_max_current; uint8_t ui8_motor_max_current; - uint8_t ui8_battery_current_min_adc; + uint8_t ui8_motor_current_min_adc; + uint8_t ui8_field_weakening; uint8_t ui8_ramp_up_amps_per_second_x10; uint16_t ui16_battery_low_voltage_cut_off_x10; uint16_t ui16_battery_voltage_reset_wh_counter_x10; @@ -125,6 +132,11 @@ typedef struct rt_vars_struct { uint8_t ui8_street_mode_speed_limit; uint8_t ui8_street_mode_power_limit_div25; uint8_t ui8_street_mode_throttle_enabled; + + uint8_t ui8_pedal_cadence_fast_stop; + uint8_t ui8_coast_brake_adc; + + battery_energy_h_km_t battery_energy_h_km; } rt_vars_t; /* Selector positions for customizable fields @@ -185,6 +197,7 @@ typedef struct ui_vars_struct { uint8_t ui8_battery_max_current; uint8_t ui8_motor_max_current; uint8_t ui8_motor_current_min_adc; + uint8_t ui8_field_weakening; uint8_t ui8_ramp_up_amps_per_second_x10; uint16_t ui16_battery_low_voltage_cut_off_x10; uint16_t ui16_battery_voltage_reset_wh_counter_x10; @@ -214,6 +227,7 @@ typedef struct ui_vars_struct { uint8_t ui8_offroad_power_limit_div25; uint32_t ui32_odometer_x10; uint32_t ui32_trip_x10; + uint32_t battery_energy_km_value_x100; uint8_t ui8_lights; uint8_t ui8_braking; @@ -321,6 +335,9 @@ typedef struct ui_vars_struct { uint8_t var_motor_foc_auto_thresholds; uint8_t var_motor_foc_threshold_max; uint8_t var_motor_foc_threshold_min; + + uint8_t ui8_pedal_cadence_fast_stop; + uint8_t ui8_coast_brake_adc; } ui_vars_t; ui_vars_t* get_ui_vars(void); diff --git a/firmware/common/include/uart.h b/firmware/common/include/uart.h index 0adc06df..1ef60be9 100755 --- a/firmware/common/include/uart.h +++ b/firmware/common/include/uart.h @@ -8,5 +8,5 @@ uint8_t* uart_get_tx_buffer(void); void uart_send_tx_buffer(uint8_t *tx_buffer, uint8_t ui8_len); #define UART_NUMBER_DATA_BYTES_TO_RECEIVE 28 -#define UART_NUMBER_DATA_BYTES_TO_SEND 83 +#define UART_NUMBER_DATA_BYTES_TO_SEND 85 diff --git a/firmware/common/src/configscreen.c b/firmware/common/src/configscreen.c index ddd37a2b..cace6558 100755 --- a/firmware/common/src/configscreen.c +++ b/firmware/common/src/configscreen.c @@ -32,6 +32,7 @@ static Field motorMenus[] = { FIELD_EDITABLE_UINT(_S("Max current", "Max curren"), &ui_vars.ui8_motor_max_current, "amps", 1, 30), FIELD_EDITABLE_UINT(_S("Current ramp", "Curre ramp"), &ui_vars.ui8_ramp_up_amps_per_second_x10, "amps", 4, 100, .div_digits = 1), FIELD_EDITABLE_UINT(_S("Min current ADC step", "Min ADC st"), &ui_vars.ui8_motor_current_min_adc, "amps", 0, 13), // 13 ADC steps = 2 amps + FIELD_EDITABLE_ENUM(_S("Field weakening", "Field weak"), &ui_vars.ui8_torque_sensor_calibration_feature_enabled, "disable", "enable"), FIELD_END }; static Field torqueSensorMenus[] = @@ -187,6 +188,8 @@ static Field displayMenus[] = FIELD_END }; static Field variousMenus[] = { + FIELD_EDITABLE_ENUM(_S("Cadence fast stop", "Cadenc stp"), &ui_vars.ui8_pedal_cadence_fast_stop, "no", "yes"), + FIELD_EDITABLE_UINT(_S("Coast brake ADC", "Coa bk ADC"), &ui_vars.ui8_coast_brake_adc, "", 5, 255), FIELD_EDITABLE_ENUM(_S("Assist w/o pedal rot", "A w/o ped"), &ui_vars.ui8_motor_assistance_startup_without_pedal_rotation, "disable", "enable"), // FIXME, share one array of disable/enable strings FIELD_EDITABLE_UINT("Odometer", &ui_vars.ui32_odometer_x10, "km", 0, UINT32_MAX, .div_digits = 1, .inc_step = 100, .onSetEditable = onSetConfigurationWheelOdometer), FIELD_END }; @@ -238,6 +241,15 @@ static Field varBatteryPowerMenus[] = { FIELD_EDITABLE_UINT(_S("Min threshold", "Min thresh"), &g_vars[VarsBatteryPower].config_warn_threshold, "", 0, 2000, .div_digits = 0, .inc_step = 10), FIELD_END }; +static Field varBatteryPowerUsageMenus[] = { + FIELD_EDITABLE_ENUM(_S("Graph auto max min", "G auto m n"), &g_graphVars[VarsBatteryPowerUsage].auto_max_min, "auto", "man"), + FIELD_EDITABLE_UINT("Graph max", &g_graphVars[VarsBatteryPowerUsage].max, "", 0, 5000, .inc_step = 10), + FIELD_EDITABLE_UINT("Graph min", &g_graphVars[VarsBatteryPowerUsage].min, "", 0, 5000, .inc_step = 10), + FIELD_EDITABLE_ENUM("Thresholds", &g_vars[VarsBatteryPowerUsage].auto_thresholds, "disabled", "manual"), + FIELD_EDITABLE_UINT(_S("Max threshold", "Max thresh"), &g_vars[VarsBatteryPowerUsage].config_error_threshold, "", 0, 2000, .div_digits = 0, .inc_step = 10), + FIELD_EDITABLE_UINT(_S("Min threshold", "Min thresh"), &g_vars[VarsBatteryPowerUsage].config_warn_threshold, "", 0, 2000, .div_digits = 0, .inc_step = 10), + FIELD_END }; + static Field varBatteryVoltageMenus[] = { FIELD_EDITABLE_ENUM(_S("Graph auto max min", "G auto m n"), &g_graphVars[VarsBatteryVoltage].auto_max_min, "auto", "man", "semi"), FIELD_EDITABLE_UINT("Graph max", &g_graphVars[VarsBatteryVoltage].max, "", 0, 1000, .div_digits = 1, .inc_step = 1), @@ -316,6 +328,7 @@ static Field variablesMenus[] = { FIELD_SCROLLABLE("Cadence", varCadenceMenus), FIELD_SCROLLABLE(_S("human power", "human powr"), varHumanPowerMenus), FIELD_SCROLLABLE(_S("motor power", "motor powr"), varBatteryPowerMenus), + FIELD_SCROLLABLE(_S("Watts/km", "Watts/km"), varBatteryPowerUsageMenus), FIELD_SCROLLABLE(_S("batt voltage", "bat volts"), varBatteryVoltageMenus), FIELD_SCROLLABLE(_S("batt current", "bat curren"), varBatteryCurrentMenus), FIELD_SCROLLABLE(_S("battery SOC", "bat SOC"), varBatterySOCMenus), @@ -380,6 +393,8 @@ static void configExit() { eeprom_write_variables(); set_conversions(); // we just changed units + update_battery_power_usage_label(); + // send the configurations to TSDZ2 if (g_motor_init_state == MOTOR_INIT_READY) g_motor_init_state = MOTOR_INIT_SET_CONFIGURATIONS; diff --git a/firmware/common/src/eeprom.c b/firmware/common/src/eeprom.c index ba40b529..0e5caa02 100755 --- a/firmware/common/src/eeprom.c +++ b/firmware/common/src/eeprom.c @@ -32,6 +32,7 @@ const eeprom_data_t m_eeprom_data_defaults = { .ui8_target_max_battery_power_div25 = DEFAULT_VALUE_TARGET_MAX_BATTERY_POWER, .ui8_motor_max_current = DEFAULT_VALUE_MOTOR_MAX_CURRENT, .ui8_motor_current_min_adc = DEFAULT_VALUE_CURRENT_MIN_ADC, + .ui8_field_weakening = DEFAULT_FIELD_WEAKENING, .ui8_ramp_up_amps_per_second_x10 = DEFAULT_VALUE_RAMP_UP_AMPS_PER_SECOND_X10, .ui16_battery_low_voltage_cut_off_x10 = DEFAULT_VALUE_BATTERY_LOW_VOLTAGE_CUT_OFF_X10, .ui8_motor_type = DEFAULT_VALUE_MOTOR_TYPE, @@ -188,9 +189,10 @@ const eeprom_data_t m_eeprom_data_defaults = { .graph_eeprom[VarsCadence].auto_max_min = GRAPH_AUTO_MAX_MIN_AUTO, .graph_eeprom[VarsHumanPower].auto_max_min = GRAPH_AUTO_MAX_MIN_AUTO, .graph_eeprom[VarsBatteryPower].auto_max_min = GRAPH_AUTO_MAX_MIN_AUTO, - .graph_eeprom[VarsBatteryVoltage].auto_max_min = GRAPH_AUTO_MAX_MIN_SEMI_AUTO, - .graph_eeprom[VarsBatteryCurrent].auto_max_min = GRAPH_AUTO_MAX_MIN_SEMI_AUTO, - .graph_eeprom[VarsMotorCurrent].auto_max_min = GRAPH_AUTO_MAX_MIN_SEMI_AUTO, + .graph_eeprom[VarsBatteryPowerUsage].auto_max_min = GRAPH_AUTO_MAX_MIN_AUTO, + .graph_eeprom[VarsBatteryVoltage].auto_max_min = GRAPH_AUTO_MAX_MIN_AUTO, + .graph_eeprom[VarsBatteryCurrent].auto_max_min = GRAPH_AUTO_MAX_MIN_AUTO, + .graph_eeprom[VarsMotorCurrent].auto_max_min = GRAPH_AUTO_MAX_MIN_AUTO, .graph_eeprom[VarsBatterySOC].auto_max_min = GRAPH_AUTO_MAX_MIN_AUTO, .graph_eeprom[VarsMotorTemp].auto_max_min = GRAPH_AUTO_MAX_MIN_SEMI_AUTO, .graph_eeprom[VarsMotorERPS].auto_max_min = GRAPH_AUTO_MAX_MIN_AUTO, @@ -208,6 +210,8 @@ const eeprom_data_t m_eeprom_data_defaults = { .cadenceField_x_axis_scale_config = GRAPH_X_AXIS_SCALE_AUTO, .batteryPowerField_auto_thresholds = FIELD_THRESHOLD_AUTO, .batteryPowerField_x_axis_scale_config = GRAPH_X_AXIS_SCALE_AUTO, + .batteryPowerUsageField_auto_thresholds = FIELD_THRESHOLD_AUTO, + .batteryPowerUsageField_x_axis_scale_config = GRAPH_X_AXIS_SCALE_15M, .batteryVoltageField_auto_thresholds = FIELD_THRESHOLD_AUTO, .batteryVoltageField_x_axis_scale_config = GRAPH_X_AXIS_SCALE_AUTO, .batteryCurrentField_auto_thresholds = FIELD_THRESHOLD_AUTO, @@ -264,6 +268,8 @@ const eeprom_data_t m_eeprom_data_defaults = { .ui8_street_mode_speed_limit = DEFAULT_STREET_MODE_SPEED_LIMIT, .ui8_street_mode_power_limit_div25 = DEFAULT_STREET_MODE_POWER_LIMIT, .ui8_street_mode_throttle_enabled = DEFAULT_STREET_MODE_THROTTLE_ENABLE, + .ui8_pedal_cadence_fast_stop = DEFAULT_PEDAL_CADENCE_FAST_STOP_ENABLE, + .ui8_coast_brake_adc = DEFAULT_COAST_BRAKE_ADC, }; void eeprom_init() { @@ -327,6 +333,8 @@ void eeprom_init_variables(void) { m_eeprom_data.ui8_motor_max_current; ui_vars->ui8_motor_current_min_adc = m_eeprom_data.ui8_motor_current_min_adc; + ui_vars->ui8_field_weakening = + m_eeprom_data.ui8_field_weakening; ui_vars->ui8_ramp_up_amps_per_second_x10 = m_eeprom_data.ui8_ramp_up_amps_per_second_x10; ui_vars->ui16_battery_low_voltage_cut_off_x10 = @@ -437,6 +445,16 @@ void eeprom_init_variables(void) { } batteryPowerGraph.rw->graph.x_axis_scale = temp; + g_vars[VarsBatteryPowerUsage].auto_thresholds = m_eeprom_data.batteryPowerUsageField_auto_thresholds; + g_vars[VarsBatteryPowerUsage].config_error_threshold = m_eeprom_data.batteryPowerUsageField_config_error_threshold; + g_vars[VarsBatteryPowerUsage].config_warn_threshold = m_eeprom_data.batteryPowerUsageField_config_warn_threshold; + batteryPowerGraph.rw->graph.x_axis_scale_config = m_eeprom_data.batteryPowerUsageField_x_axis_scale_config; + temp = GRAPH_X_AXIS_SCALE_15M; + if (batteryPowerUsageGraph.rw->graph.x_axis_scale_config != GRAPH_X_AXIS_SCALE_AUTO) { + temp = batteryPowerUsageGraph.rw->graph.x_axis_scale_config; + } + batteryPowerUsageGraph.rw->graph.x_axis_scale = temp; + g_vars[VarsBatteryVoltage].auto_thresholds = m_eeprom_data.batteryVoltageField_auto_thresholds; g_vars[VarsBatteryVoltage].config_error_threshold = m_eeprom_data.batteryVoltageField_config_error_threshold; g_vars[VarsBatteryVoltage].config_warn_threshold = m_eeprom_data.batteryVoltageField_config_warn_threshold; @@ -531,6 +549,11 @@ void eeprom_init_variables(void) { m_eeprom_data.ui8_street_mode_power_limit_div25; ui_vars->ui8_street_mode_throttle_enabled = m_eeprom_data.ui8_street_mode_throttle_enabled; + + ui_vars->ui8_pedal_cadence_fast_stop = + m_eeprom_data.ui8_pedal_cadence_fast_stop; + ui_vars->ui8_coast_brake_adc = + m_eeprom_data.ui8_coast_brake_adc; } void eeprom_write_variables(void) { @@ -551,6 +574,8 @@ void eeprom_write_variables(void) { ui_vars->ui8_motor_max_current; m_eeprom_data.ui8_motor_current_min_adc = ui_vars->ui8_motor_current_min_adc; + m_eeprom_data.ui8_field_weakening = + ui_vars->ui8_field_weakening; m_eeprom_data.ui8_ramp_up_amps_per_second_x10 = ui_vars->ui8_ramp_up_amps_per_second_x10; m_eeprom_data.ui16_battery_low_voltage_cut_off_x10 = @@ -642,6 +667,11 @@ void eeprom_write_variables(void) { m_eeprom_data.batteryPowerField_config_warn_threshold = g_vars[VarsBatteryPower].config_warn_threshold; m_eeprom_data.batteryPowerField_x_axis_scale_config = batteryPowerGraph.rw->graph.x_axis_scale_config; + m_eeprom_data.batteryPowerUsageField_auto_thresholds = g_vars[VarsBatteryPowerUsage].auto_thresholds; + m_eeprom_data.batteryPowerUsageField_config_error_threshold = g_vars[VarsBatteryPowerUsage].config_error_threshold; + m_eeprom_data.batteryPowerUsageField_config_warn_threshold = g_vars[VarsBatteryPowerUsage].config_warn_threshold; + m_eeprom_data.batteryPowerUsageField_x_axis_scale_config = batteryPowerUsageGraph.rw->graph.x_axis_scale_config; + m_eeprom_data.batteryVoltageField_auto_thresholds = g_vars[VarsBatteryVoltage].auto_thresholds; m_eeprom_data.batteryVoltageField_config_error_threshold = g_vars[VarsBatteryVoltage].config_error_threshold; m_eeprom_data.batteryVoltageField_config_warn_threshold = g_vars[VarsBatteryVoltage].config_warn_threshold; @@ -693,6 +723,11 @@ void eeprom_write_variables(void) { m_eeprom_data.ui8_street_mode_throttle_enabled = ui_vars->ui8_street_mode_throttle_enabled; + m_eeprom_data.ui8_pedal_cadence_fast_stop = + ui_vars->ui8_pedal_cadence_fast_stop; + m_eeprom_data.ui8_coast_brake_adc = + ui_vars->ui8_coast_brake_adc; + flash_write_words(&m_eeprom_data, sizeof(m_eeprom_data) / sizeof(uint32_t)); } diff --git a/firmware/common/src/mainscreen.c b/firmware/common/src/mainscreen.c index d691b1fa..e05eae90 100755 --- a/firmware/common/src/mainscreen.c +++ b/firmware/common/src/mainscreen.c @@ -68,6 +68,7 @@ void thresholds(void); bool wd_failure_detected; #define MAX_TIMESTR_LEN 8 // including nul terminator +#define MAX_BATTERY_POWER_USAGE_STR_LEN 6 // Wh/km or Wh/mi , including nul terminator // // Fields - these might be shared my multiple screens @@ -97,6 +98,10 @@ Field motorErpsField = FIELD_READONLY_UINT(_S("motor speed", "mot speed"), &ui_v Field pwmDutyField = FIELD_READONLY_UINT(_S("motor pwm", "mot pwm"), &ui_vars.ui8_duty_cycle, "", true, .div_digits = 0); Field motorFOCField = FIELD_READONLY_UINT(_S("motor foc", "mot foc"), &ui_vars.ui8_foc_angle, "", true, .div_digits = 0); +// Note: this field label is special, the string it is pointing to must be in RAM so we can change it later +Field batteryPowerUsageField = FIELD_READONLY_UINT((char [MAX_BATTERY_POWER_USAGE_STR_LEN]){ 0 }, &ui_vars.battery_energy_km_value_x100, "kph", true, .div_digits = 2); + + Field warnField = FIELD_CUSTOM(renderWarning); /** @@ -119,6 +124,7 @@ Field *customizables[] = { &motorErpsField, // 12 &pwmDutyField, // 13 &motorFOCField, // 14 + &batteryPowerUsageField, // 15 NULL }; @@ -141,12 +147,16 @@ Field motorErpsFieldGraph = FIELD_READONLY_UINT("motor speed", &rt_vars.ui16_mot Field pwmDutyFieldGraph = FIELD_READONLY_UINT("pwm duty-cycle", &rt_vars.ui8_duty_cycle, "", false); Field motorFOCFieldGraph = FIELD_READONLY_UINT("motor foc", &rt_vars.ui8_foc_angle, "", false); +// Note: this field label is special, the string it is pointing to must be in RAM so we can change it later +Field batteryPowerUsageFieldGraph = FIELD_READONLY_UINT((char [MAX_BATTERY_POWER_USAGE_STR_LEN]){ 0 }, &rt_vars.battery_energy_h_km.ui32_value_x10, "kph", false, .div_digits = 1); + #ifndef SW102 // we don't have any graphs yet on SW102, possibly move this into mainscreen_850.c Field wheelSpeedGraph = FIELD_GRAPH(&wheelSpeedFieldGraph, .min_threshold = -1, .graph_vars = &g_graphVars[VarsWheelSpeed]); Field tripDistanceGraph = FIELD_GRAPH(&tripDistanceFieldGraph, .min_threshold = -1, .graph_vars = &g_graphVars[VarsTripDistance]); Field cadenceGraph = FIELD_GRAPH(&cadenceFieldGraph, .min_threshold = -1, .graph_vars = &g_graphVars[VarsCadence]); Field humanPowerGraph = FIELD_GRAPH(&humanPowerFieldGraph, .min_threshold = -1, .graph_vars = &g_graphVars[VarsHumanPower]); Field batteryPowerGraph = FIELD_GRAPH(&batteryPowerFieldGraph, .min_threshold = -1, .graph_vars = &g_graphVars[VarsBatteryPower]); +Field batteryPowerUsageGraph = FIELD_GRAPH(&batteryPowerUsageFieldGraph, .min_threshold = -1, .graph_vars = &g_graphVars[VarsBatteryPowerUsage]); Field batteryVoltageGraph = FIELD_GRAPH(&batteryVoltageFieldGraph, .min_threshold = -1, .graph_vars = &g_graphVars[VarsBatteryVoltage]); Field batteryCurrentGraph = FIELD_GRAPH(&batteryCurrentFieldGraph, .filter = FilterSquare, .min_threshold = -1, .graph_vars = &g_graphVars[VarsBatteryCurrent]); Field motorCurrentGraph = FIELD_GRAPH(&motorCurrentFieldGraph, .min_threshold = -1, .graph_vars = &g_graphVars[VarsMotorCurrent]); @@ -165,6 +175,7 @@ Field graph1 = FIELD_CUSTOMIZABLE(&ui_vars.graphs_field_selectors[0], &cadenceGraph, &humanPowerGraph, &batteryPowerGraph, + &batteryPowerUsageGraph, &batteryVoltageGraph, &batteryCurrentGraph, &motorCurrentGraph, @@ -180,6 +191,7 @@ Field graph2 = FIELD_CUSTOMIZABLE(&ui_vars.graphs_field_selectors[1], &cadenceGraph, &humanPowerGraph, &batteryPowerGraph, + &batteryPowerUsageGraph, &batteryVoltageGraph, &batteryCurrentGraph, &motorCurrentGraph, @@ -195,6 +207,7 @@ Field graph3 = FIELD_CUSTOMIZABLE(&ui_vars.graphs_field_selectors[2], &cadenceGraph, &humanPowerGraph, &batteryPowerGraph, + &batteryPowerUsageGraph, &batteryVoltageGraph, &batteryCurrentGraph, &motorCurrentGraph, @@ -602,6 +615,14 @@ void screen_clock(void) { void thresholds(void) { #ifndef SW102 + + odoField.rw->editable.number.auto_thresholds = FIELD_THRESHOLD_DISABLED; + odoFieldGraph.rw->editable.number.auto_thresholds = FIELD_THRESHOLD_DISABLED; + tripDistanceField.rw->editable.number.auto_thresholds = FIELD_THRESHOLD_DISABLED; + tripDistanceFieldGraph.rw->editable.number.auto_thresholds = FIELD_THRESHOLD_DISABLED; + batteryPowerUsageField.rw->editable.number.auto_thresholds = FIELD_THRESHOLD_DISABLED; + batteryPowerUsageFieldGraph.rw->editable.number.auto_thresholds = FIELD_THRESHOLD_DISABLED; + if (*wheelSpeedField.rw->editable.number.auto_thresholds == FIELD_THRESHOLD_AUTO) { wheelSpeedField.rw->editable.number.error_threshold = wheelSpeedFieldGraph.rw->editable.number.error_threshold = ui_vars.wheel_max_speed_x10; @@ -621,10 +642,17 @@ void thresholds(void) { } if (*cadenceField.rw->editable.number.auto_thresholds == FIELD_THRESHOLD_AUTO) { - cadenceField.rw->editable.number.error_threshold = + if (ui_vars.ui8_torque_sensor_calibration_feature_enabled) { + cadenceField.rw->editable.number.error_threshold = + cadenceFieldGraph.rw->editable.number.error_threshold = 120; // max value for motor assistance + cadenceField.rw->editable.number.warn_threshold = + cadenceFieldGraph.rw->editable.number.warn_threshold = 100; + } else { + cadenceField.rw->editable.number.error_threshold = cadenceFieldGraph.rw->editable.number.error_threshold = 92; - cadenceField.rw->editable.number.warn_threshold = + cadenceField.rw->editable.number.warn_threshold = cadenceFieldGraph.rw->editable.number.warn_threshold = 83; // -10% + } } else if (*cadenceField.rw->editable.number.auto_thresholds == FIELD_THRESHOLD_MANUAL) { cadenceField.rw->editable.number.error_threshold = cadenceFieldGraph.rw->editable.number.error_threshold = *cadenceField.rw->editable.number.config_error_threshold; @@ -746,10 +774,17 @@ void thresholds(void) { } if (*pwmDutyField.rw->editable.number.auto_thresholds == FIELD_THRESHOLD_AUTO) { - pwmDutyField.rw->editable.number.error_threshold = - pwmDutyFieldGraph.rw->editable.number.error_threshold = 100; - pwmDutyField.rw->editable.number.warn_threshold = - pwmDutyFieldGraph.rw->editable.number.warn_threshold = 85; + if (ui_vars.ui8_torque_sensor_calibration_feature_enabled) { + pwmDutyField.rw->editable.number.error_threshold = + pwmDutyFieldGraph.rw->editable.number.error_threshold = 111; + pwmDutyField.rw->editable.number.warn_threshold = + pwmDutyFieldGraph.rw->editable.number.warn_threshold = 99; + } else { + pwmDutyField.rw->editable.number.error_threshold = + pwmDutyFieldGraph.rw->editable.number.error_threshold = 100; + pwmDutyField.rw->editable.number.warn_threshold = + pwmDutyFieldGraph.rw->editable.number.warn_threshold = 90; + } } else if (*pwmDutyField.rw->editable.number.auto_thresholds == FIELD_THRESHOLD_MANUAL) { pwmDutyField.rw->editable.number.error_threshold = pwmDutyFieldGraph.rw->editable.number.error_threshold = *pwmDutyField.rw->editable.number.config_error_threshold; @@ -758,8 +793,13 @@ void thresholds(void) { } if (g_graphVars[VarsMotorPWM].auto_max_min == GRAPH_AUTO_MAX_MIN_SEMI_AUTO) { - g_graphVars[VarsMotorPWM].max = 100; - g_graphVars[VarsMotorPWM].min = 0; + if (ui_vars.ui8_torque_sensor_calibration_feature_enabled) { + g_graphVars[VarsMotorPWM].max = 111; + g_graphVars[VarsMotorPWM].min = 0; + } else { + g_graphVars[VarsMotorPWM].max = 100; + g_graphVars[VarsMotorPWM].min = 0; + } } if (*motorFOCField.rw->editable.number.auto_thresholds == FIELD_THRESHOLD_AUTO) { diff --git a/firmware/common/src/screen.c b/firmware/common/src/screen.c index 0d5f38f9..b9d7f55b 100755 --- a/firmware/common/src/screen.c +++ b/firmware/common/src/screen.c @@ -70,6 +70,8 @@ static bool blinkOn; static uint32_t screenUpdateCounter; +void update_battery_power_usage_label(void); + /** * Used to map from FieldVariant enums to rendering functions */ @@ -936,20 +938,27 @@ static void putAligned(FieldLayout *layout, AlignmentX alignx, /// Update this readonly editable with a string value. Important: the original field target must be pointing to a WRITABLE array, not a const string. void updateReadOnlyStr(Field *field, const char *str) { assert(field->editable.typ == ReadOnlyStr); // Make sure the field is being used as provisioned - strcpy(field->editable.target, str); - field->rw->dirty = true; } +void updateReadOnlyLabelStr(Field *field, const char *str) { + strcpy(field->editable.label, str); + field->rw->dirty = true; +} + UG_COLOR getEditableColor(Field *f, int32_t val) { - int32_t warn_threshold = convertToImperialIfNeeded(f, f->rw->editable.number.warn_threshold); - int32_t error_threshold = convertToImperialIfNeeded(f, f->rw->editable.number.error_threshold); + int32_t warn_threshold = f->rw->editable.number.warn_threshold; + int32_t error_threshold = f->rw->editable.number.error_threshold; UG_COLOR color = C_WHITE; // in the case of invalid thresholds - if (warn_threshold == -1 || error_threshold == -1) + if (warn_threshold == -1 || error_threshold == -1) { return C_WHITE; + } else { + warn_threshold = convertToImperialIfNeeded(f, warn_threshold); + error_threshold = convertToImperialIfNeeded(f, error_threshold); + } // find if thresholds are inverted, like in the case of battery voltage bool threshold_inverted = false; @@ -1479,7 +1488,8 @@ static void graphLabelAxis(Field *field) { max_val_pre = graph->max_val; if (graph->max_val != INT32_MIN) { - getEditableString(source, graph->max_val, valstr); + int32_t i32_value = convertToImperialIfNeeded(source, graph->max_val); + getEditableString(source, i32_value, valstr); putStringRight((GRAPH_MAXVAL_FONT.char_width * 4) + 4, graphYmax, &GRAPH_MAXVAL_FONT, valstr); } @@ -1492,7 +1502,8 @@ static void graphLabelAxis(Field *field) { min_val_pre = graph->min_val; if (graph->min_val != INT32_MAX) { - getEditableString(source, graph->min_val, valstr); + int32_t i32_value = convertToImperialIfNeeded(source, graph->min_val); + getEditableString(source, i32_value, valstr); putStringRight((GRAPH_MAXVAL_FONT.char_width * 4) + 4, graphYmin - GRAPH_MAXVAL_FONT.char_height, &GRAPH_MAXVAL_FONT, valstr); @@ -2405,9 +2416,29 @@ void graph_init(void) { #endif } +void update_battery_power_usage_label(void) { + static char str_km[] = "Wh/km"; + static char str_mi[] = "Wh/mi"; + + if(ui_vars.ui8_units_type == 0) { + updateReadOnlyLabelStr(&batteryPowerUsageField, str_km); +#ifndef SW102 + updateReadOnlyLabelStr(&batteryPowerUsageFieldGraph, str_km); +#endif + } + else { + updateReadOnlyLabelStr(&batteryPowerUsageField, str_mi); +#ifndef SW102 + updateReadOnlyLabelStr(&batteryPowerUsageFieldGraph, str_mi); +#endif + } +} + void screen_init(void) { graph_init(); + update_battery_power_usage_label(); + #ifndef SW102 assistLevelField.rw->visibility = FieldVisible; #else @@ -2451,6 +2482,10 @@ void screen_init(void) { batteryPowerField.rw->editable.number.config_warn_threshold = &g_vars[VarsBatteryPower].config_warn_threshold; batteryPowerField.rw->editable.number.config_error_threshold = &g_vars[VarsBatteryPower].config_error_threshold; + batteryPowerField.rw->editable.number.auto_thresholds = &g_vars[VarsBatteryPowerUsage].auto_thresholds; + batteryPowerField.rw->editable.number.config_warn_threshold = &g_vars[VarsBatteryPowerUsage].config_warn_threshold; + batteryPowerField.rw->editable.number.config_error_threshold = &g_vars[VarsBatteryPowerUsage].config_error_threshold; + batteryVoltageField.rw->editable.number.auto_thresholds = &g_vars[VarsBatteryVoltage].auto_thresholds; batteryVoltageField.rw->editable.number.config_warn_threshold = &g_vars[VarsBatteryVoltage].config_warn_threshold; batteryVoltageField.rw->editable.number.config_error_threshold = &g_vars[VarsBatteryVoltage].config_error_threshold; diff --git a/firmware/common/src/state.c b/firmware/common/src/state.c index 84852a18..a2120f43 100755 --- a/firmware/common/src/state.c +++ b/firmware/common/src/state.c @@ -46,9 +46,7 @@ tsdz2_firmware_version_t g_tsdz2_firmware_version = { 0xff, 0, 0 }; static void motor_init(void); -// kevinh: I don't think volatile is probably needed here rt_vars_t rt_vars; - ui_vars_t ui_vars; volatile bool m_reset_wh_flag = false; @@ -246,12 +244,12 @@ void rt_send_tx_package(frame_type_t type) { // battery max current ui8_usart1_tx_buffer[7] = rt_vars.ui8_battery_max_current; - ui8_usart1_tx_buffer[8] = (rt_vars.ui8_startup_motor_power_boost_feature_enabled ? 1 : 0) | - (rt_vars.ui8_startup_motor_power_boost_always ? 2 : 0) | - (rt_vars.ui8_startup_motor_power_boost_limit_power ? 4 : 0) | - (rt_vars.ui8_torque_sensor_calibration_feature_enabled ? 8 : 0) | - (rt_vars.ui8_torque_sensor_calibration_pedal_ground ? 16 : 0) | - (rt_vars.ui8_motor_assistance_startup_without_pedal_rotation ? 32 : 0) | + ui8_usart1_tx_buffer[8] = rt_vars.ui8_startup_motor_power_boost_feature_enabled | + (rt_vars.ui8_startup_motor_power_boost_always << 1) | + (rt_vars.ui8_startup_motor_power_boost_limit_power << 2) | + (rt_vars.ui8_torque_sensor_calibration_feature_enabled << 3) | + (rt_vars.ui8_torque_sensor_calibration_pedal_ground << 4) | + (rt_vars.ui8_motor_assistance_startup_without_pedal_rotation << 5) | ((rt_vars.ui8_motor_type & 0x3) << 6); // motor max current @@ -288,9 +286,13 @@ void rt_send_tx_package(frame_type_t type) { } // battery current min ADC - ui8_usart1_tx_buffer[79] = rt_vars.ui8_battery_current_min_adc; + ui8_usart1_tx_buffer[79] = rt_vars.ui8_motor_current_min_adc; + + ui8_usart1_tx_buffer[80] = rt_vars.ui8_pedal_cadence_fast_stop | (rt_vars.ui8_field_weakening << 1); + + ui8_usart1_tx_buffer[81] = rt_vars.ui8_coast_brake_adc; - crc_len = 81; + crc_len = 83; ui8_usart1_tx_buffer[1] = crc_len; break; @@ -433,6 +435,7 @@ void reset_wh(void) { static void rt_calc_odometer(void) { static uint8_t ui8_1s_timer_counter; uint32_t uint32_temp; + uint8_t ui8_01km_flag = 0; // calc at 1s rate if (++ui8_1s_timer_counter >= 10) { @@ -463,12 +466,36 @@ static void rt_calc_odometer(void) { // ui_vars.ui16_distance_since_power_on_x10 += 1; rt_vars.ui32_odometer_x10 += 1; rt_vars.ui32_trip_x10 += 1; + ui8_01km_flag = 1; // reset the always incrementing value (up to motor controller power reset) by setting the offset to current value rt_vars.ui32_wheel_speed_sensor_tick_counter_offset = rt_vars.ui32_wheel_speed_sensor_tick_counter; } } + + // calc battery energy per km +#define BATTERY_ENERGY_H_KM_FACTOR_X2 1800 // (60 * 60) / 2, each step at fixed interval of 100ms and apply 1 / 2 for have value from _x50 to _x100 + + // keep accumulating the energy + rt_vars.battery_energy_h_km.ui32_sum_x50 += rt_vars.ui16_full_battery_power_filtered_x50; + + static uint16_t ui16_one_km_timeout_counter = 0; + + // reset value if riding at very low speed or being stopped for 2 minutes + if (++ui16_one_km_timeout_counter >= 600) { // 600 equals min of average 2km/h for 2 minutes, at least + ui16_one_km_timeout_counter = 600; // keep on this state... + rt_vars.battery_energy_h_km.ui32_value_x100 = 0; + rt_vars.battery_energy_h_km.ui32_value_x10 = 0; + rt_vars.battery_energy_h_km.ui32_sum_x50 = 0; + } + + if (ui8_01km_flag) { + ui16_one_km_timeout_counter = 0; + rt_vars.battery_energy_h_km.ui32_value_x100 = rt_vars.battery_energy_h_km.ui32_sum_x50 / BATTERY_ENERGY_H_KM_FACTOR_X2; + rt_vars.battery_energy_h_km.ui32_value_x10 = rt_vars.battery_energy_h_km.ui32_value_x100 / 10; + rt_vars.battery_energy_h_km.ui32_sum_x50 = 0; + } } static void rt_low_pass_filter_pedal_cadence(void) { @@ -609,6 +636,7 @@ void copy_rt_to_ui_vars(void) { ui_vars.ui8_foc_angle = (((uint16_t) rt_vars.ui8_foc_angle) * 14) / 10; // each units is equal to 1.4 degrees ((360 degrees / 256) = 1.4) ui_vars.ui32_trip_x10 = rt_vars.ui32_trip_x10; ui_vars.ui32_odometer_x10 = rt_vars.ui32_odometer_x10; + ui_vars.battery_energy_km_value_x100 = rt_vars.battery_energy_h_km.ui32_value_x100; rt_vars.ui32_wh_x10_100_percent = ui_vars.ui32_wh_x10_100_percent; rt_vars.ui32_wh_x10_offset = ui_vars.ui32_wh_x10_offset; @@ -625,7 +653,8 @@ void copy_rt_to_ui_vars(void) { rt_vars.ui8_offroad_mode = ui_vars.ui8_offroad_mode; rt_vars.ui8_battery_max_current = ui_vars.ui8_battery_max_current; rt_vars.ui8_motor_max_current = ui_vars.ui8_motor_max_current; - rt_vars.ui8_battery_current_min_adc = ui_vars.ui8_motor_current_min_adc; + rt_vars.ui8_motor_current_min_adc = ui_vars.ui8_motor_current_min_adc; + rt_vars.ui8_field_weakening = ui_vars.ui8_field_weakening; rt_vars.ui8_ramp_up_amps_per_second_x10 = ui_vars.ui8_ramp_up_amps_per_second_x10; rt_vars.ui8_target_max_battery_power_div25 = ui_vars.ui8_target_max_battery_power_div25; @@ -673,6 +702,9 @@ void copy_rt_to_ui_vars(void) { rt_vars.ui8_street_mode_speed_limit = ui_vars.ui8_street_mode_speed_limit; rt_vars.ui8_street_mode_power_limit_div25 = ui_vars.ui8_street_mode_power_limit_div25; rt_vars.ui8_street_mode_throttle_enabled = ui_vars.ui8_street_mode_throttle_enabled; + + rt_vars.ui8_pedal_cadence_fast_stop = ui_vars.ui8_pedal_cadence_fast_stop; + rt_vars.ui8_pedal_cadence_fast_stop = ui_vars.ui8_coast_brake_adc; } /// must be called from main() idle loop @@ -704,7 +736,6 @@ void automatic_power_off_management(void) { void communications(void) { frame_type_t ui8_frame; uint8_t process_frame = 0; - uint16_t ui16_temp; const uint8_t *p_rx_buffer = uart_get_rx_buffer_rdy(); @@ -771,10 +802,7 @@ void communications(void) { rt_vars.ui8_pedal_cadence = p_rx_buffer[14]; - // convert duty-cycle to 0 - 100 % - ui16_temp = (uint16_t) p_rx_buffer[15]; - ui16_temp = (ui16_temp * 100) / 254; - rt_vars.ui8_duty_cycle = (uint8_t) ui16_temp; + rt_vars.ui8_duty_cycle = p_rx_buffer[15]; rt_vars.ui16_motor_speed_erps = ((uint16_t) p_rx_buffer[16]) | ((uint16_t) p_rx_buffer[17] << 8); rt_vars.ui8_foc_angle = p_rx_buffer[18];