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

Commit

Permalink
Increased PWM frequency and changed UART speed to be twice to get pro…
Browse files Browse the repository at this point in the history
…cessor speed for the increased PWM frequency. Added coast brake ADC sensitivity, fast stop configuration, Wh/km and field weakening
  • Loading branch information
casainho committed Apr 25, 2020
1 parent e82fa0f commit 268350c
Show file tree
Hide file tree
Showing 12 changed files with 250 additions and 63 deletions.
2 changes: 1 addition & 1 deletion firmware/860C_850C/src/usart1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions firmware/common/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -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)\"
55 changes: 33 additions & 22 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 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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions firmware/common/include/mainscreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern Field
cadenceField,
humanPowerField,
batteryPowerField,
batteryPowerUsageField,
motorMaxPowerField,
batteryVoltageField,
batteryCurrentField,
Expand Down Expand Up @@ -48,6 +49,8 @@ extern Field
cadenceGraph,
humanPowerGraph,
batteryPowerGraph,
batteryPowerUsageGraph,
batteryPowerUsageFieldGraph,
batteryVoltageGraph,
batteryCurrentGraph,
motorCurrentGraph,
Expand Down
5 changes: 4 additions & 1 deletion firmware/common/include/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ typedef enum {
VarsCadence,
VarsHumanPower,
VarsBatteryPower,
VarsBatteryPowerUsage,
VarsBatteryVoltage,
VarsBatteryCurrent,
VarsMotorCurrent,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
19 changes: 18 additions & 1 deletion firmware/common/include/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion firmware/common/include/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

15 changes: 15 additions & 0 deletions firmware/common/src/configscreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] =
Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 268350c

Please sign in to comment.