Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Commit cfa85f7

Browse files
committed
Added configuration for motor current control as torque mode as also keeping the previous power mode. Changed Walk assist max speed to 6 km/h. Added a few configuration to clock field, like disabling or show battery SOC
1 parent 5300925 commit cfa85f7

6 files changed

Lines changed: 54 additions & 14 deletions

File tree

firmware/common/include/eeprom.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
// 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
1717
// changes bump up EEPROM_MIN_COMPAT_VERSION and the user's EEPROM settings will be discarded.
18-
#define EEPROM_MIN_COMPAT_VERSION 0x39
19-
#define EEPROM_VERSION 0x39
18+
#define EEPROM_MIN_COMPAT_VERSION 0x3A
19+
#define EEPROM_VERSION 0x3A
2020

2121
typedef struct {
2222
graph_auto_max_min_t auto_max_min;
@@ -34,6 +34,7 @@ typedef struct eeprom_data {
3434
uint32_t ui32_wh_x10_offset;
3535
uint32_t ui32_wh_x10_100_percent;
3636
uint8_t ui8_battery_soc_enable;
37+
uint8_t ui8_time_field_enable;
3738
uint8_t ui8_target_max_battery_power_div25;
3839
uint8_t ui8_battery_max_current;
3940
uint8_t ui8_motor_max_current;
@@ -42,6 +43,7 @@ typedef struct eeprom_data {
4243
uint8_t ui8_ramp_up_amps_per_second_x10;
4344
uint16_t ui16_battery_low_voltage_cut_off_x10;
4445
uint8_t ui8_motor_type;
46+
uint8_t ui8_motor_current_control_mode;
4547
uint8_t ui8_motor_assistance_startup_without_pedal_rotation;
4648
uint16_t ui16_assist_level_factor[ASSIST_LEVEL_NUMBER];
4749
uint8_t ui8_number_of_assist_levels;
@@ -170,13 +172,15 @@ void eeprom_init_defaults(void);
170172
#define DEFAULT_VALUE_WH_X10_OFFSET 0
171173
#define DEFAULT_VALUE_HW_X10_100_PERCENT 4000 // default to a battery of 400 Wh
172174
#define DEAFULT_VALUE_SHOW_NUMERIC_BATTERY_SOC 1 // SOC
175+
#define DEAFULT_VALUE_TIME_FIELD 1 // 1 i show clock
173176
#define DEFAULT_VALUE_BATTERY_MAX_CURRENT 16 // 16 amps
174177
#define DEFAULT_VALUE_MOTOR_MAX_CURRENT 16 // 16 amps
175178
#define DEFAULT_VALUE_CURRENT_MIN_ADC 1 // 1 unit, 0.156 A
176179
#define DEFAULT_VALUE_RAMP_UP_AMPS_PER_SECOND_X10 80 // 8.0 amps per second ramp up
177180
#define DEFAULT_VALUE_TARGET_MAX_BATTERY_POWER 60 // e.g. 20 = 20 * 25 = 500, 0 is disabled
178181
#define DEFAULT_VALUE_BATTERY_LOW_VOLTAGE_CUT_OFF_X10 420 // 52v battery, LVC = 42.0 (3.0 * 14)
179-
#define DEFAULT_VALUE_MOTOR_TYPE 0 // ui8_motor_type = 0 = 48V
182+
#define DEFAULT_VALUE_MOTOR_CURRENT_CONTROL_MODE 0 // 0 power; 1 torque
183+
#define DEFAULT_VALUE_MOTOR_TYPE 0 // 0 = 48V
180184
#define DEFAULT_VALUE_MOTOR_ASSISTANCE_WITHOUT_PEDAL_ROTATION 0 // 0 to keep this feature disable
181185
#define DEFAULT_VALUE_ASSIST_LEVEL_FACTOR_1 5 // 0.005 and each next increase +33%
182186
#define DEFAULT_VALUE_ASSIST_LEVEL_FACTOR_2 9

firmware/common/include/state.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ typedef struct rt_vars_struct {
8484
uint8_t ui8_units_type;
8585
uint32_t ui32_wh_x10_offset;
8686
uint32_t ui32_wh_x10_100_percent;
87-
uint8_t ui8_battery_soc_enable;
8887
uint8_t ui8_target_max_battery_power_div25;
8988
uint8_t ui8_battery_max_current;
9089
uint8_t ui8_motor_max_current;
@@ -95,6 +94,7 @@ typedef struct rt_vars_struct {
9594
uint16_t ui16_battery_voltage_reset_wh_counter_x10;
9695
uint16_t ui16_battery_pack_resistance_x1000;
9796
uint8_t ui8_motor_type;
97+
uint8_t ui8_motor_current_control_mode;
9898
uint8_t ui8_motor_assistance_startup_without_pedal_rotation;
9999
uint16_t ui16_assist_level_factor[ASSIST_LEVEL_NUMBER];
100100
uint8_t ui8_walk_assist_feature_enabled;
@@ -198,6 +198,7 @@ typedef struct ui_vars_struct {
198198
uint32_t ui32_wh_x10_offset;
199199
uint32_t ui32_wh_x10_100_percent;
200200
uint8_t ui8_battery_soc_enable;
201+
uint8_t ui8_time_field_enable;
201202
uint8_t ui8_target_max_battery_power_div25;
202203
uint8_t ui8_battery_max_current;
203204
uint8_t ui8_motor_max_current;
@@ -209,6 +210,7 @@ typedef struct ui_vars_struct {
209210
uint16_t ui16_battery_pack_resistance_x1000;
210211
uint16_t ui16_battery_pack_resistance_estimated_x1000;
211212
uint8_t ui8_motor_type;
213+
uint8_t ui8_motor_current_control_mode;
212214
uint8_t ui8_motor_assistance_startup_without_pedal_rotation;
213215
uint16_t ui16_assist_level_factor[ASSIST_LEVEL_NUMBER];
214216
uint8_t ui8_walk_assist_feature_enabled;

firmware/common/src/configscreen.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ static Field motorMenus[] = {
3131
FIELD_EDITABLE_ENUM(_S("Motor voltage", "Motor volt"), &ui_vars.ui8_motor_type, "48V", "36V"),
3232
FIELD_EDITABLE_UINT(_S("Max current", "Max curren"), &ui_vars.ui8_motor_max_current, "amps", 1, 30),
3333
FIELD_EDITABLE_UINT(_S("Current ramp", "Curre ramp"), &ui_vars.ui8_ramp_up_amps_per_second_x10, "amps", 4, 100, .div_digits = 1),
34+
FIELD_EDITABLE_ENUM(_S("Motor control", "Motor ctrl"), &ui_vars.ui8_motor_current_control_mode, "power", "torque"),
3435
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
3536
FIELD_EDITABLE_ENUM(_S("Field weakening", "Field weak"), &ui_vars.ui8_field_weakening, "disable", "enable"),
3637
FIELD_END };
@@ -172,6 +173,7 @@ static Field streetModeMenus[] =
172173
static Field displayMenus[] =
173174
{
174175
#ifndef SW102
176+
FIELD_EDITABLE_ENUM("Clock field", &ui_vars.ui8_time_field_enable, "disable", "clock", "batt SOC %", "batt volts"),
175177
FIELD_EDITABLE_UINT("Clock hours", &ui8_g_configuration_clock_hours, "", 0, 23, .onSetEditable = onSetConfigurationClockHours),
176178
FIELD_EDITABLE_UINT("Clock minutes", &ui8_g_configuration_clock_minutes, "", 0, 59, .onSetEditable = onSetConfigurationClockMinutes),
177179
FIELD_EDITABLE_UINT("Brightness on", &ui_vars.ui8_lcd_backlight_on_brightness, "", 5, 100, .inc_step = 5, .onSetEditable = onSetConfigurationDisplayLcdBacklightOnBrightness),

firmware/common/src/eeprom.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const eeprom_data_t m_eeprom_data_defaults = {
2828
.ui32_wh_x10_offset = DEFAULT_VALUE_WH_X10_OFFSET,
2929
.ui32_wh_x10_100_percent = DEFAULT_VALUE_HW_X10_100_PERCENT,
3030
.ui8_battery_soc_enable = DEAFULT_VALUE_SHOW_NUMERIC_BATTERY_SOC,
31+
.ui8_time_field_enable = DEAFULT_VALUE_TIME_FIELD,
3132
.ui8_battery_max_current = DEFAULT_VALUE_BATTERY_MAX_CURRENT,
3233
.ui8_target_max_battery_power_div25 = DEFAULT_VALUE_TARGET_MAX_BATTERY_POWER,
3334
.ui8_motor_max_current = DEFAULT_VALUE_MOTOR_MAX_CURRENT,
@@ -36,6 +37,7 @@ const eeprom_data_t m_eeprom_data_defaults = {
3637
.ui8_ramp_up_amps_per_second_x10 = DEFAULT_VALUE_RAMP_UP_AMPS_PER_SECOND_X10,
3738
.ui16_battery_low_voltage_cut_off_x10 = DEFAULT_VALUE_BATTERY_LOW_VOLTAGE_CUT_OFF_X10,
3839
.ui8_motor_type = DEFAULT_VALUE_MOTOR_TYPE,
40+
.ui8_motor_current_control_mode = DEFAULT_VALUE_MOTOR_CURRENT_CONTROL_MODE,
3941
.ui8_motor_assistance_startup_without_pedal_rotation = DEFAULT_VALUE_MOTOR_ASSISTANCE_WITHOUT_PEDAL_ROTATION,
4042
.ui16_assist_level_factor = {
4143
DEFAULT_VALUE_ASSIST_LEVEL_FACTOR_1,
@@ -329,6 +331,8 @@ void eeprom_init_variables(void) {
329331
m_eeprom_data.ui32_wh_x10_100_percent;
330332
ui_vars->ui8_battery_soc_enable =
331333
m_eeprom_data.ui8_battery_soc_enable;
334+
ui_vars->ui8_time_field_enable =
335+
m_eeprom_data.ui8_time_field_enable;
332336
ui_vars->ui8_target_max_battery_power_div25 =
333337
m_eeprom_data.ui8_target_max_battery_power_div25;
334338
ui_vars->ui8_battery_max_current =
@@ -344,6 +348,7 @@ void eeprom_init_variables(void) {
344348
ui_vars->ui16_battery_low_voltage_cut_off_x10 =
345349
m_eeprom_data.ui16_battery_low_voltage_cut_off_x10;
346350
ui_vars->ui8_motor_type = m_eeprom_data.ui8_motor_type;
351+
ui_vars->ui8_motor_current_control_mode = m_eeprom_data.ui8_motor_current_control_mode;
347352
ui_vars->ui8_motor_assistance_startup_without_pedal_rotation =
348353
m_eeprom_data.ui8_motor_assistance_startup_without_pedal_rotation;
349354
ui_vars->ui8_temperature_limit_feature_enabled =
@@ -580,6 +585,8 @@ void eeprom_write_variables(void) {
580585
ui_vars->ui32_wh_x10_100_percent;
581586
m_eeprom_data.ui8_battery_soc_enable =
582587
ui_vars->ui8_battery_soc_enable;
588+
m_eeprom_data.ui8_time_field_enable =
589+
ui_vars->ui8_time_field_enable;
583590
m_eeprom_data.ui8_target_max_battery_power_div25 =
584591
ui_vars->ui8_target_max_battery_power_div25;
585592
m_eeprom_data.ui8_motor_max_current =
@@ -593,6 +600,7 @@ void eeprom_write_variables(void) {
593600
m_eeprom_data.ui16_battery_low_voltage_cut_off_x10 =
594601
ui_vars->ui16_battery_low_voltage_cut_off_x10;
595602
m_eeprom_data.ui8_motor_type = ui_vars->ui8_motor_type;
603+
m_eeprom_data.ui8_motor_current_control_mode = ui_vars->ui8_motor_current_control_mode;
596604
m_eeprom_data.ui8_motor_assistance_startup_without_pedal_rotation =
597605
ui_vars->ui8_motor_assistance_startup_without_pedal_rotation;
598606
m_eeprom_data.ui8_temperature_limit_feature_enabled =

firmware/common/src/mainscreen.c

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,17 +1055,39 @@ void battery_soc(void) {
10551055

10561056

10571057
void time(void) {
1058-
rtc_time_t *p_rtc_time = rtc_get_time();
1058+
#ifndef SW102
1059+
rtc_time_t *p_rtc_time = rtc_get_time();
10591060

1060-
// force to be [0 - 12]
1061-
if (ui_vars.ui8_units_type) { // FIXME, should be based on a different eeprom config value, just because someone is using mph doesn't mean they want 12 hr time
1062-
if (p_rtc_time->ui8_hours > 12) {
1063-
p_rtc_time->ui8_hours -= 12;
1064-
}
1065-
}
1061+
switch (ui_vars.ui8_time_field_enable) {
1062+
default:
1063+
case 0:
1064+
// clear the area
1065+
fieldPrintf(&timeField, "");
1066+
break;
1067+
1068+
case 1:
1069+
// force to be [0 - 12]
1070+
if (ui_vars.ui8_units_type) { // FIXME, should be based on a different eeprom config value, just because someone is using mph doesn't mean they want 12 hr time
1071+
if (p_rtc_time->ui8_hours > 12) {
1072+
p_rtc_time->ui8_hours -= 12;
1073+
}
1074+
}
10661075

1067-
fieldPrintf(&timeField, "%d:%02d", p_rtc_time->ui8_hours,
1068-
p_rtc_time->ui8_minutes);
1076+
fieldPrintf(&timeField, "%d:%02d", p_rtc_time->ui8_hours,
1077+
p_rtc_time->ui8_minutes);
1078+
break;
1079+
1080+
case 2:
1081+
fieldPrintf(&timeField, "%3d%%", ui8_g_battery_soc);
1082+
break;
1083+
1084+
case 3:
1085+
fieldPrintf(&timeField, "%u.%1uV",
1086+
ui_vars.ui16_battery_voltage_soc_x10 / 10,
1087+
ui_vars.ui16_battery_voltage_soc_x10 % 10);
1088+
break;
1089+
}
1090+
#endif
10691091
}
10701092

10711093
void walk_assist_state(void) {

firmware/common/src/state.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ void rt_send_tx_package(frame_type_t type) {
295295
ui8_usart1_tx_buffer[79] = rt_vars.ui8_motor_current_min_adc;
296296
ui8_usart1_tx_buffer[80] = (rt_vars.ui8_pedal_cadence_fast_stop |
297297
(rt_vars.ui8_field_weakening << 1) |
298-
(rt_vars.ui8_coast_brake_enable << 2));
298+
(rt_vars.ui8_coast_brake_enable << 2) |
299+
(rt_vars.ui8_motor_current_control_mode << 3));
299300
ui8_usart1_tx_buffer[81] = rt_vars.ui8_coast_brake_adc;
300301
ui8_usart1_tx_buffer[82] = rt_vars.ui8_adc_lights_current_offset;
301302
ui8_usart1_tx_buffer[83] = rt_vars.ui8_torque_sensor_filter;
@@ -672,6 +673,7 @@ void copy_rt_to_ui_vars(void) {
672673
rt_vars.ui16_wheel_perimeter = ui_vars.ui16_wheel_perimeter;
673674
rt_vars.ui8_wheel_max_speed = ui_vars.wheel_max_speed_x10 / 10;
674675
rt_vars.ui8_motor_type = ui_vars.ui8_motor_type;
676+
rt_vars.ui8_motor_current_control_mode = ui_vars.ui8_motor_current_control_mode;
675677
rt_vars.ui8_motor_assistance_startup_without_pedal_rotation =
676678
ui_vars.ui8_motor_assistance_startup_without_pedal_rotation;
677679
rt_vars.ui8_temperature_limit_feature_enabled =

0 commit comments

Comments
 (0)