Skip to content

Commit

Permalink
Merge pull request #98 from leon927/bug-fixes
Browse files Browse the repository at this point in the history
Improvements and bug fixes
  • Loading branch information
casainho authored Jun 8, 2019
2 parents 25af00d + f89ba3a commit b727f5c
Show file tree
Hide file tree
Showing 14 changed files with 601 additions and 771 deletions.
22 changes: 12 additions & 10 deletions src/controller/ebike_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,18 +446,12 @@ static void uart_receive_package(void)

case 3:
// type of motor (36 volt, 48 volt or some experimental type)
m_configuration_variables.ui8_motor_type = (ui8_rx_buffer [5] & 3);
m_configuration_variables.ui8_motor_type = ui8_rx_buffer [5];

// motor assistance without pedal rotation enable/disable when startup
m_configuration_variables.ui8_motor_assistance_startup_without_pedal_rotation = (ui8_rx_buffer [5] & 4) >> 2;

// motor temperature limit function enable/disable
m_configuration_variables.ui8_temperature_limit_feature_enabled = (ui8_rx_buffer [5] & 8) >> 3;

// startup motor boost state
// startup motor power boost state
m_configuration_variables.ui8_startup_motor_power_boost_state = (ui8_rx_buffer [6] & 1);

// startup power boost max power limit
// startup power boost max power limit enabled
m_configuration_variables.ui8_startup_motor_power_boost_limit_to_max_power = (ui8_rx_buffer [6] & 2) >> 1;
break;

Expand All @@ -474,7 +468,7 @@ static void uart_receive_package(void)
m_configuration_variables.ui8_startup_motor_power_boost_fade_time = ui8_rx_buffer [5];

// startup motor boost enabled
m_configuration_variables.ui8_startup_motor_power_boost_feature_enabled = (ui8_rx_buffer [6] & 1);
m_configuration_variables.ui8_startup_motor_power_boost_feature_enabled = ui8_rx_buffer [6];
break;

case 6:
Expand Down Expand Up @@ -521,6 +515,14 @@ static void uart_receive_package(void)
ui16_received_target_wheel_speed_x10 = (uint16_t) (ui8_rx_buffer [6] * 10);
break;

case 8:
// motor temperature limit function or throttle
m_configuration_variables.ui8_temperature_limit_feature_enabled = ui8_rx_buffer [5];

// motor assistance without pedal rotation enable/disable when startup
m_configuration_variables.ui8_motor_assistance_startup_without_pedal_rotation = ui8_rx_buffer [6];
break;

default:
// nothing, should display error code
break;
Expand Down
7 changes: 0 additions & 7 deletions src/controller/ebike_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ typedef struct _configuration_variables
uint16_t ui16_wheel_perimeter;
uint8_t ui8_lights;
uint8_t ui8_walk_assist;
uint8_t ui8_offroad_mode;
uint8_t ui8_wheel_max_speed;
uint8_t ui8_motor_type;
uint8_t ui8_motor_assistance_startup_without_pedal_rotation;
Expand All @@ -46,18 +45,12 @@ typedef struct _configuration_variables
uint8_t ui8_temperature_current_limiting_value;
uint16_t ui16_motor_temperature_x2;
uint8_t ui8_motor_temperature;
uint8_t ui8_offroad_feature_enabled;
uint8_t ui8_offroad_enabled_on_startup;
uint8_t ui8_offroad_speed_limit;
uint8_t ui8_offroad_power_limit_enabled;
uint8_t ui8_offroad_power_limit_div25;
uint8_t ui8_ramp_up_amps_per_second_x10;
} struct_configuration_variables;



extern volatile uint16_t ui16_current_ramp_up_inverse_step;

extern volatile uint8_t ui8_g_adc_torque_sensor_min_value;
extern volatile uint8_t ui8_g_adc_torque_sensor_max_value;
extern volatile uint8_t ui8_adc_battery_current_offset;
Expand Down
26 changes: 4 additions & 22 deletions src/controller/eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ static uint8_t array_default_values [EEPROM_BYTES_STORED] = {
DEFAULT_VALUE_WHEEL_PERIMETER_1, // 8 + EEPROM_BASE_ADDRESS
DEFAULT_VALUE_WHEEL_MAX_SPEED, // 9 + EEPROM_BASE_ADDRESS
DEFAULT_VALUE_CONFIG_1, // 10 + EEPROM_BASE_ADDRESS
DEFAULT_VALUE_OFFROAD_CONFIG, // 11 + EEPROM_BASE_ADDRESS
DEFAULT_VALUE_OFFROAD_SPEED_LIMIT, // 12 + EEPROM_BASE_ADDRESS
DEFAULT_VALUE_OFFROAD_POWER_LIMIT_DIV25, // 13 + EEPROM_BASE_ADDRESS
DEFAULT_VALUE_RAMP_UP_AMPS_PER_SECOND_X10 // 14 + EEPROM_BASE_ADDRESS
DEFAULT_VALUE_RAMP_UP_AMPS_PER_SECOND_X10 // 11 + EEPROM_BASE_ADDRESS
};


Expand Down Expand Up @@ -91,7 +88,6 @@ static void eeprom_read_values_to_variables (void)
ui8_temp = FLASH_ReadByte (ADDRESS_CONFIG_0);
p_configuration_variables->ui8_lights = ui8_temp & 1 ? 1 : 0;
p_configuration_variables->ui8_walk_assist = ui8_temp & (1 << 1) ? 1 : 0;
p_configuration_variables->ui8_offroad_mode = ui8_temp & (1 << 2) ? 1 : 0;

p_configuration_variables->ui8_battery_max_current = FLASH_ReadByte (ADDRESS_BATTERY_MAX_CURRENT);
p_configuration_variables->ui8_motor_power_x10 = FLASH_ReadByte (ADDRESS_MOTOR_POWER_X10);
Expand All @@ -113,14 +109,6 @@ static void eeprom_read_values_to_variables (void)
ui8_temp = FLASH_ReadByte (ADDRESS_CONFIG_1);
p_configuration_variables->ui8_motor_type = ui8_temp & 3;
p_configuration_variables->ui8_motor_assistance_startup_without_pedal_rotation = (ui8_temp & 4) >> 2;

ui8_temp = FLASH_ReadByte (ADDRESS_OFFROAD_CONFIG);
p_configuration_variables->ui8_offroad_feature_enabled = ui8_temp & 1;
p_configuration_variables->ui8_offroad_enabled_on_startup = ui8_temp & (1 << 1);
p_configuration_variables->ui8_offroad_power_limit_enabled = ui8_temp & (1 << 2);

p_configuration_variables->ui8_offroad_speed_limit = FLASH_ReadByte (ADDRESS_OFFROAD_SPEED_LIMIT);
p_configuration_variables->ui8_offroad_power_limit_div25 = FLASH_ReadByte (ADDRESS_OFFROAD_POWER_LIMIT_DIV25);

// ramp up, amps per second
p_configuration_variables->ui8_ramp_up_amps_per_second_x10 = FLASH_ReadByte (ADDRESS_RAMP_UP_AMPS_PER_SECOND_X10);
Expand All @@ -142,9 +130,8 @@ static void variables_to_array (uint8_t *ui8_array)

ui8_array [0] = KEY;
ui8_array [1] = p_configuration_variables->ui8_assist_level_factor_x10;
ui8_array [2] = (p_configuration_variables->ui8_lights & 1) |
((p_configuration_variables->ui8_walk_assist & 1) << 1) |
((p_configuration_variables->ui8_offroad_mode & 1) << 2);
ui8_array [2] = (p_configuration_variables->ui8_lights & 1) |
((p_configuration_variables->ui8_walk_assist & 1) << 1);
ui8_array [3] = p_configuration_variables->ui8_battery_max_current;
ui8_array [4] = p_configuration_variables->ui8_motor_power_x10;
ui8_array [5] = p_configuration_variables->ui16_battery_low_voltage_cut_off_x10 & 255;
Expand All @@ -154,12 +141,7 @@ static void variables_to_array (uint8_t *ui8_array)
ui8_array [9] = p_configuration_variables->ui8_wheel_max_speed;
ui8_array [10] = (p_configuration_variables->ui8_motor_type & 3) |
((p_configuration_variables->ui8_motor_assistance_startup_without_pedal_rotation & 1) << 2);
ui8_array [11] = (p_configuration_variables->ui8_offroad_feature_enabled & 1) |
((p_configuration_variables->ui8_offroad_enabled_on_startup & 1) << 1) |
((p_configuration_variables->ui8_offroad_power_limit_enabled & 1) << 2);
ui8_array [12] = p_configuration_variables->ui8_offroad_speed_limit;
ui8_array [13] = p_configuration_variables->ui8_offroad_power_limit_div25;
ui8_array [14] = p_configuration_variables->ui8_ramp_up_amps_per_second_x10;
ui8_array [11] = p_configuration_variables->ui8_ramp_up_amps_per_second_x10;
}


Expand Down
7 changes: 2 additions & 5 deletions src/controller/eeprom.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@
#define ADDRESS_WHEEL_PERIMETER_1 8 + EEPROM_BASE_ADDRESS
#define ADDRESS_WHEEL_MAX_SPEED 9 + EEPROM_BASE_ADDRESS
#define ADDRESS_CONFIG_1 10 + EEPROM_BASE_ADDRESS
#define ADDRESS_OFFROAD_CONFIG 11 + EEPROM_BASE_ADDRESS
#define ADDRESS_OFFROAD_SPEED_LIMIT 12 + EEPROM_BASE_ADDRESS
#define ADDRESS_OFFROAD_POWER_LIMIT_DIV25 13 + EEPROM_BASE_ADDRESS
#define ADDRESS_RAMP_UP_AMPS_PER_SECOND_X10 14 + EEPROM_BASE_ADDRESS
#define EEPROM_BYTES_STORED 15
#define ADDRESS_RAMP_UP_AMPS_PER_SECOND_X10 11 + EEPROM_BASE_ADDRESS
#define EEPROM_BYTES_STORED 12



Expand Down
3 changes: 0 additions & 3 deletions src/controller/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@
#define DEFAULT_VALUE_WHEEL_PERIMETER_1 8
#define DEFAULT_VALUE_WHEEL_MAX_SPEED 50 // 50 km/h
#define DEFAULT_VALUE_CONFIG_1 0
#define DEFAULT_VALUE_OFFROAD_CONFIG 0
#define DEFAULT_VALUE_OFFROAD_SPEED_LIMIT 25 // 25 km/h
#define DEFAULT_VALUE_OFFROAD_POWER_LIMIT_DIV25 10 // 10 * 25 = 250 W



Expand Down
Loading

0 comments on commit b727f5c

Please sign in to comment.