Skip to content

Commit

Permalink
avoid div25 battery power defines
Browse files Browse the repository at this point in the history
 reduces complexity, increases precision
  • Loading branch information
dzid26 committed Jul 7, 2024
1 parent c7ae390 commit a116737
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
6 changes: 2 additions & 4 deletions src/ebike_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,16 +369,14 @@ void ebike_app_init(void)
/ (uint16_t)BATTERY_CURRENT_PER_10_BIT_ADC_STEP_X100;

// calculate max adc battery current from the received power limit in offroad mode
ui32_battery_current_max_x100 = (TARGET_MAX_BATTERY_POWER_DIV25 * 2500000)
/ ui16_battery_voltage_filtered_x1000;
ui32_battery_current_max_x100 = (uint32_t)TARGET_MAX_BATTERY_POWER * 100 * 1000 / ui16_battery_voltage_filtered_x1000;
ui8_adc_battery_current_max_temp_2 = ui32_battery_current_max_x100 / BATTERY_CURRENT_PER_10_BIT_ADC_STEP_X100;

// set max battery current in offroad mode
ui8_adc_battery_current_max_array[OFFROAD_MODE] = ui8_min(ui8_adc_battery_current_max_temp_1, ui8_adc_battery_current_max_temp_2);

// calculate max adc battery current from the received power limit in street mode
ui32_battery_current_max_x100 = (STREET_MODE_POWER_LIMIT_DIV25 * 2500000)
/ ui16_battery_voltage_filtered_x1000;
ui32_battery_current_max_x100 = (uint32_t)STREET_MODE_POWER_LIMIT * 100 * 1000 / ui16_battery_voltage_filtered_x1000;
ui8_adc_battery_current_max_temp_2 = ui32_battery_current_max_x100 / BATTERY_CURRENT_PER_10_BIT_ADC_STEP_X100;

// set max battery current in street mode
Expand Down
6 changes: 1 addition & 5 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,7 @@ HALL_COUNTER_OFFSET_UP: 29 -> 44
#define DIFFERENCE_CUT_OFF_SHUTDOWN_8_BIT 26
// battery voltage for saving battery capacity at shutdown
#define BATTERY_VOLTAGE_SHUTDOWN_8_BIT (uint8_t) ((uint16_t)(BATTERY_LOW_VOLTAGE_CUT_OFF * 250 / BATTERY_VOLTAGE_PER_10_BIT_ADC_STEP_X1000)) - ((uint16_t) DIFFERENCE_CUT_OFF_SHUTDOWN_8_BIT)
#define BATTERY_VOLTAGE_SHUTDOWN_10_BIT (uint16_t) (BATTERY_VOLTAGE_SHUTDOWN_8_BIT << 2)
// max battery power div25
#define TARGET_MAX_BATTERY_POWER_DIV25 (uint8_t)(TARGET_MAX_BATTERY_POWER / 25)
// power street limit value div25
#define STREET_MODE_POWER_LIMIT_DIV25 (uint8_t)(STREET_MODE_POWER_LIMIT / 25)
#define BATTERY_VOLTAGE_SHUTDOWN_10_BIT (uint16_t) (BATTERY_VOLTAGE_SHUTDOWN_8_BIT << 2)
// battery voltage reset SOC percentage
#define BATTERY_VOLTAGE_RESET_SOC_PERCENT_X10 (uint16_t)((float)LI_ION_CELL_RESET_SOC_PERCENT * (float)(BATTERY_CELLS_NUMBER * 10))
// battery SOC eeprom value saved (8 bit)
Expand Down

0 comments on commit a116737

Please sign in to comment.