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

Commit

Permalink
Added torque sensor startup offset. Motor current control mode defaul…
Browse files Browse the repository at this point in the history
…t to torque mode. Cadence fast stop disabled by default. Corrected auto shutdown timeout
  • Loading branch information
casainho committed May 26, 2020
1 parent 93506d4 commit 125e1ac
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 25 deletions.
8 changes: 4 additions & 4 deletions firmware/common/include/eeprom.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 0x3A
#define EEPROM_VERSION 0x3A
#define EEPROM_MIN_COMPAT_VERSION 0x3B
#define EEPROM_VERSION 0x3B

typedef struct {
graph_auto_max_min_t auto_max_min;
Expand Down Expand Up @@ -180,7 +180,7 @@ void eeprom_init_defaults(void);
#define DEFAULT_VALUE_RAMP_UP_AMPS_PER_SECOND_X10 80 // 8.0 amps per second ramp up
#define DEFAULT_VALUE_TARGET_MAX_BATTERY_POWER 60 // e.g. 20 = 20 * 25 = 500, 0 is disabled
#define DEFAULT_VALUE_BATTERY_LOW_VOLTAGE_CUT_OFF_X10 420 // 52v battery, LVC = 42.0 (3.0 * 14)
#define DEFAULT_VALUE_MOTOR_CURRENT_CONTROL_MODE 0 // 0 power; 1 torque
#define DEFAULT_VALUE_MOTOR_CURRENT_CONTROL_MODE 1 // 0 power; 1 torque
#define DEFAULT_VALUE_MOTOR_TYPE 0 // 0 = 48V
#define DEFAULT_VALUE_MOTOR_ASSISTANCE_WITHOUT_PEDAL_ROTATION 0 // 0 to keep this feature disable
#define DEFAULT_VALUE_ASSIST_LEVEL_FACTOR_1 5 // 0.005 and each next increase +33%
Expand Down Expand Up @@ -275,7 +275,7 @@ 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_PEDAL_CADENCE_FAST_STOP_ENABLE 0 // disabled
#define DEFAULT_COAST_BRAKE_ADC 15 // 15: tested by plpetrov user on 28.04.2020:
#define DEFAULT_FIELD_WEAKENING 1 // 1 enabled
#define DEFAULT_ADC_LIGHTS_CURRENT_OFFSET 1
Expand Down
17 changes: 6 additions & 11 deletions firmware/common/src/configscreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ static Field batteryMenus[] =
FIELD_EDITABLE_UINT(_S("Max current", "Max curren"), &ui_vars.ui8_battery_max_current, "amps", 1, 20),
FIELD_EDITABLE_UINT(_S("Low cut-off", "Lo cut-off"), &ui_vars.ui16_battery_low_voltage_cut_off_x10, "volts", 160, 630, .div_digits = 1),
FIELD_EDITABLE_UINT(_S("Resistance", "Resistance"), &ui_vars.ui16_battery_pack_resistance_x1000, "mohm", 0, 1000),
FIELD_SCROLLABLE("SOC", batterySOCMenus),
FIELD_READONLY_UINT(_S("Voltage est", "Voltag est"), &ui_vars.ui16_battery_voltage_soc_x10, "volts", false, .div_digits = 1),
FIELD_READONLY_UINT(_S("Resistance est", "Resist est"), &ui_vars.ui16_battery_pack_resistance_estimated_x1000, "mohm", 0, 1000),
FIELD_READONLY_UINT(_S("Power loss est", "Power loss"), &ui_vars.ui16_battery_power_loss, "watts", false, .div_digits = 0),
Expand All @@ -37,8 +36,12 @@ static Field motorMenus[] = {
FIELD_EDITABLE_ENUM(_S("Field weakening", "Field weak"), &ui_vars.ui8_field_weakening, "disable", "enable"),
FIELD_END };

static Field torqueSensorCalibrationMenus[] =
static Field torqueSensorMenus[] =
{
FIELD_EDITABLE_UINT(_S("Torque s ADC thresho", "Torq s thr"), &ui_vars.ui8_torque_sensor_adc_threshold, "", 5, 100),
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_ENUM(_S("Coast brake", "Coast brak"), &ui_vars.ui8_coast_brake_enable, "disable", "enable"),
FIELD_EDITABLE_UINT(_S("Coast brake ADC", "Coa bk ADC"), &ui_vars.ui8_coast_brake_adc, "", 5, 255),
FIELD_EDITABLE_ENUM(_S("Calibration", "Calibrat"), &ui_vars.ui8_torque_sensor_calibration_feature_enabled, "disable", "enable"),
FIELD_EDITABLE_UINT(_S("Torque sensor filter", "Torq s fil"), &ui_vars.ui8_torque_sensor_filter, "", 0, 100),
FIELD_EDITABLE_ENUM(_S("Start pedal ground", "Pedal grou"), &ui_vars.ui8_torque_sensor_calibration_pedal_ground, "left", "right"),
Expand Down Expand Up @@ -76,15 +79,6 @@ static Field torqueSensorCalibrationMenus[] =
FIELD_EDITABLE_UINT("Right ADC 8", &ui_vars.ui16_torque_sensor_calibration_table_right[7][1], "", 0, 1023),
FIELD_END };

static Field torqueSensorMenus[] =
{
FIELD_EDITABLE_UINT(_S("Torque sensor ADC threshold", "Torq s thr"), &ui_vars.ui8_torque_sensor_adc_threshold, "", 5, 75),
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_ENUM(_S("Coast brake", "Coast brak"), &ui_vars.ui8_coast_brake_enable, "disable", "enable"),
FIELD_EDITABLE_UINT(_S("Coast brake ADC", "Coa bk ADC"), &ui_vars.ui8_coast_brake_adc, "", 5, 255),
FIELD_SCROLLABLE("Calibration", torqueSensorCalibrationMenus),
FIELD_END };

static Field assistMenus[] =
{
FIELD_EDITABLE_UINT(_S("Num assist levels", "Num Levels"), &ui_vars.ui8_number_of_assist_levels, "", 1, 20),
Expand Down Expand Up @@ -371,6 +365,7 @@ static Field technicalMenus[] = {
static Field topMenus[] = {
FIELD_SCROLLABLE("Wheel", wheelMenus),
FIELD_SCROLLABLE("Battery", batteryMenus),
FIELD_SCROLLABLE("SOC", batterySOCMenus),
FIELD_SCROLLABLE(_S("Motor", "Motor"), motorMenus),
FIELD_SCROLLABLE(_S("Torque sensor", "Torque sen"), torqueSensorMenus),
FIELD_SCROLLABLE(_S("Assist level", "Assist"), assistMenus),
Expand Down
2 changes: 1 addition & 1 deletion firmware/common/src/eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ const eeprom_data_t m_eeprom_data_defaults = {
.ui8_adc_lights_current_offset = DEFAULT_ADC_LIGHTS_CURRENT_OFFSET,
.ui8_throttle_virtual_step = DEFAULT_THROTTLE_VIRTUAL_STEP,
.ui8_torque_sensor_filter = DEFAULT_TORQUE_SENSOR_FILTER,
.ui8_torque_sensor_adc_threshold = DEFAULT_TORQUE_SENSOR_FILTER,
.ui8_torque_sensor_adc_threshold = DEFAULT_TORQUE_SENSOR_ADC_THRESHOLD,
.ui8_coast_brake_enable = DEFAULT_COAST_BRAKE_ENABLE,
};

Expand Down
4 changes: 2 additions & 2 deletions firmware/common/src/mainscreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ void trip_time(void) {
static int oldmin = -1; // used to prevent unneeded updates
char timestr[MAX_TIMESTR_LEN]; // 12:13

if(p_time->ui8_minutes != oldmin) {
if (p_time->ui8_minutes != oldmin) {
oldmin = p_time->ui8_minutes;
sprintf(timestr, "%d:%02d", p_time->ui8_hours, p_time->ui8_minutes);
updateReadOnlyStr(&tripTimeField, timestr);
Expand Down Expand Up @@ -1095,7 +1095,7 @@ void time(void) {

void walk_assist_state(void) {
// kevinh - note on the sw102 we show WALK in the box normally used for BRAKE display - the display code is handled there now
if (ui_vars.ui8_walk_assist_feature_enabled) {
if (ui_vars.ui8_walk_assist_feature_enabled) {
// if down button is still pressed
if (ui_vars.ui8_walk_assist && buttons_get_down_state()) {
ui8_walk_assist_timeout = 2; // 0.2 seconds
Expand Down
13 changes: 6 additions & 7 deletions firmware/common/src/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,13 @@ void rt_low_pass_filter_battery_voltage_current_power(void) {

// low pass filter battery voltage
ui32_battery_voltage_accumulated_x10000 -=
ui32_battery_voltage_accumulated_x10000
>> BATTERY_VOLTAGE_FILTER_COEFFICIENT;
(ui32_battery_voltage_accumulated_x10000 >> BATTERY_VOLTAGE_FILTER_COEFFICIENT);

ui32_battery_voltage_accumulated_x10000 +=
(uint32_t) rt_vars.ui16_adc_battery_voltage
* ADC_BATTERY_VOLTAGE_PER_ADC_STEP_X10000;
((uint32_t) rt_vars.ui16_adc_battery_voltage * ADC_BATTERY_VOLTAGE_PER_ADC_STEP_X10000);

rt_vars.ui16_battery_voltage_filtered_x10 =
((uint32_t) (ui32_battery_voltage_accumulated_x10000
>> BATTERY_VOLTAGE_FILTER_COEFFICIENT)) / 1000;
(((uint32_t) (ui32_battery_voltage_accumulated_x10000 >> BATTERY_VOLTAGE_FILTER_COEFFICIENT)) / 1000);

// low pass filter battery current
ui16_battery_current_accumulated_x5 -= ui16_battery_current_accumulated_x5
Expand Down Expand Up @@ -742,7 +741,7 @@ void automatic_power_off_management(void) {
// check if we should power off the LCD
if (ui16_lcd_power_off_time_counter
>= (ui_vars.ui8_lcd_power_off_time_minutes * 10 * 60)) { // have we passed our timeout?
// lcd_power_off(1);
lcd_power_off(1);
}
}
} else {
Expand Down

0 comments on commit 125e1ac

Please sign in to comment.