Skip to content

Commit

Permalink
Update v20.1C.3
Browse files Browse the repository at this point in the history
  • Loading branch information
emmebrusa committed Jun 3, 2021
1 parent 2b7fc0e commit 745d2eb
Show file tree
Hide file tree
Showing 19 changed files with 339 additions and 290 deletions.
Binary file modified CSV-PWM-Table.xlsx
Binary file not shown.
Binary file modified PWMCalculations.xlsx
Binary file not shown.
11 changes: 11 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
TSDZ2 Open Source Firmware v20.1C.3 for 860C display

1 - Updated to v13 version of mspider65 (but with 19KHz PWM frequency)
2 - Improved motor efficiency with high power (by mspider65)
Changed files
main.h
ebike_app.c
ebike_app.h
motor.c
motor.h

TSDZ2 Open Source Firmware v20.1C.2 for 860C display

1 - Updated to v12 version of mspider65 (Hall sensor calibration missing)
Expand Down
Binary file added manuals/EN-860C_additional_manual-v20.1C.3.pdf
Binary file not shown.
Binary file removed manuals/EN-860C_additional_manual-v20.1C.pdf
Binary file not shown.
Binary file added manuals/IT-Manuale_integrativo_860C-v20.1C.3.pdf
Binary file not shown.
Binary file removed manuals/IT-Manuale_integrativo_860C-v20.1C.pdf
Binary file not shown.
Binary file not shown.
Binary file modified manuals/odt/EN-860C_additional_manual-v20.1C.odt
Binary file not shown.
Binary file modified manuals/odt/IT-Manuale_integrativo_860C-v20.1C.odt
Binary file not shown.
Binary file not shown.
Binary file not shown.

Large diffs are not rendered by default.

Binary file not shown.
22 changes: 14 additions & 8 deletions src/ebike_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ volatile struct_configuration_variables m_configuration_variables = {
};

// system
static uint8_t ui8_assist_level = 0;
uint8_t ui8_assist_level = 0;
static uint8_t ui8_riding_mode = OFF_MODE;
static uint8_t ui8_riding_mode_parameter = 0;
static uint8_t ui8_walk_assist_parameter = 0;
Expand All @@ -81,8 +81,9 @@ static uint8_t ui8_motor_enabled = 1;
static uint8_t ui8_assist_without_pedal_rotation_threshold = 0;
static uint8_t ui8_assist_without_pedal_rotation_enabled = 0;
static uint8_t ui8_lights_configuration = 0;
static uint8_t ui8_lights_state = 0;
static uint8_t ui8_assist_whit_error_enabled = 0;
uint8_t ui8_lights_state = 0;
uint8_t ui8_field_weakening_enabled = 0;

// power control
static uint8_t ui8_battery_current_max = DEFAULT_VALUE_BATTERY_CURRENT_MAX;
Expand All @@ -100,7 +101,7 @@ volatile uint8_t ui8_adc_motor_phase_current_max = ADC_10_BIT_MOTOR_PHASE_CURREN
// cadence sensor
uint16_t ui16_cadence_ticks_count_min_speed_adj = CADENCE_SENSOR_CALC_COUNTER_MIN;
static uint8_t ui8_pedal_cadence_RPM = 0;
volatile uint8_t ui8_pedal_cadence_fast_stop = 0;
uint8_t ui8_pedal_cadence_fast_stop = 0;

// torque sensor
static uint16_t ui16_adc_pedal_torque_offset = ADC_TORQUE_SENSOR_OFFSET_DEFAULT;
Expand Down Expand Up @@ -1748,9 +1749,14 @@ void UART2_RX_IRQHandler(void) __interrupt(UART2_RX_IRQHANDLER)
break;

case 1:
ui8_rx_buffer[1] = ui8_byte_received;
ui8_rx_len = ui8_byte_received;
ui8_state_machine = 2;
if(ui8_byte_received > (UART_NUMBER_DATA_BYTES_TO_RECEIVE - 2)) {
ui8_state_machine = 0;
}
else {
ui8_rx_buffer[1] = ui8_byte_received;
ui8_rx_len = ui8_byte_received;
ui8_state_machine = 2;
}
break;

case 2:
Expand Down Expand Up @@ -2073,7 +2079,7 @@ static void communications_process_packages(uint8_t ui8_frame_type)
ui8_assist_without_pedal_rotation_enabled = (ui8_rx_buffer[8] & 32) >> 5;

// motor type
ui8_temp = (ui8_rx_buffer[8] >> 6) & 1;
ui8_temp = (ui8_rx_buffer[8] & 64) >> 6;

//m_configuration_variables.ui8_motor_inductance_x1048576
// motor inductance & cruise pid parameter
Expand Down Expand Up @@ -2151,7 +2157,7 @@ static void communications_process_packages(uint8_t ui8_frame_type)

ui8_temp = ui8_rx_buffer[80];
ui8_pedal_cadence_fast_stop = ui8_temp & 1;
ui8_g_field_weakening_enable = (ui8_temp & 2) >> 1;
ui8_field_weakening_enabled = (ui8_temp & 2) >> 1;
ui8_coaster_brake_enabled = (ui8_temp & 4) >> 2;
//m_config_vars.ui8_motor_current_control_mode = (ui8_temp & 8) >> 3;
// (ui8_temp & 16) >> 4; available
Expand Down
9 changes: 7 additions & 2 deletions src/ebike_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@

// cadence sensor
extern uint16_t ui16_cadence_ticks_count_min_speed_adj;
extern volatile uint8_t ui8_pedal_cadence_fast_stop;
extern volatile uint8_t ui8_adc_motor_phase_current_max;
extern uint8_t ui8_pedal_cadence_fast_stop;
extern uint8_t ui8_lights_state;
extern uint8_t ui8_field_weakening_enabled;
extern uint8_t ui8_assist_level;

// Torque sensor coaster brake engaged threshold value
extern uint16_t ui16_adc_coaster_brake_threshold;

// ADC motor phase current max
extern volatile uint8_t ui8_adc_motor_phase_current_max;

typedef struct _configuration_variables {
uint16_t ui16_battery_low_voltage_cut_off_x10;
uint16_t ui16_wheel_perimeter;
Expand Down
14 changes: 10 additions & 4 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
// PWM related values

// motor
#define PWM_COUNTER_MAX 444 // 16MHz / 888 = 18,018 KHz
//#define PWM_COUNTER_MAX 444 // 16MHz / 888 = 18,018 KHz
#define PWM_COUNTER_MAX 420 // 16MHz / 840 = 19,047 KHz
#define PWM_CYCLES_SECOND (16000000/(PWM_COUNTER_MAX*2)) // 55.5us (PWM period)

/*---------------------------------------------------------
Expand Down Expand Up @@ -75,9 +76,14 @@
#define WHEEL_SPEED_SENSOR_TICKS_COUNTER_MAX (uint16_t)((uint32_t)PWM_CYCLES_SECOND*10U/1157U) // (135 at 15,625KHz) something like 200 m/h with a 6'' wheel
#define WHEEL_SPEED_SENSOR_TICKS_COUNTER_MIN (uint16_t)((uint32_t)PWM_CYCLES_SECOND*1000U/477U) // 32767@15625KHz could be a bigger number but will make for a slow detection of stopped wheel speed


#define MIDDLE_SVM_TABLE 107
#define MIDDLE_PWM_COUNTER 107
// svm table 19 Khz
#define MIDDLE_SVM_TABLE 107
#define MIDDLE_PWM_COUNTER 107
/*
// svm table 18 Khz
#define MIDDLE_SVM_TABLE 110
#define MIDDLE_PWM_COUNTER 110
*/

#define PWM_DUTY_CYCLE_MAX 254
#define PWM_DUTY_CYCLE_STARTUP 30 // Initial PWM Duty Cycle at motor startup
Expand Down
29 changes: 25 additions & 4 deletions src/motor.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define SVM_TABLE_LEN 256
#define ASIN_TABLE_MAX 127

// svm table 19 Khz
static const uint8_t ui8_svm_table[SVM_TABLE_LEN] = { 202, 203, 205, 206, 207, 208, 209, 210, 211, 211, 212, 213, 213,
214, 214, 214, 215, 215, 215, 215, 215, 215, 215, 215, 214, 214, 214, 213, 213, 212, 211, 211, 210, 209, 208,
208, 207, 206, 205, 204, 202, 201, 199, 195, 191, 187, 183, 178, 174, 170, 165, 161, 157, 152, 148, 143, 139,
Expand All @@ -36,6 +37,21 @@ static const uint8_t ui8_svm_table[SVM_TABLE_LEN] = { 202, 203, 205, 206, 207, 2
214, 214, 215, 215, 215, 215, 215, 215, 215, 215, 214, 214, 214, 213, 213, 212, 211, 211, 210, 209, 208, 207,
206, 205, 203, 202, 201 };

/*
// svm table 18 Khz
static const uint8_t ui8_svm_table[SVM_TABLE_LEN] = { 208, 209, 210, 212, 213, 214, 215, 216, 217, 217, 218, 219, 219,
220, 220, 220, 221, 221, 221, 221, 221, 221, 221, 221, 220, 220, 220, 219, 219, 218, 217, 217, 216, 215, 214,
213, 212, 211, 210, 209, 208, 207, 205, 201, 196, 192, 188, 183, 179, 174, 170, 165, 161, 156, 152, 147, 143,
138, 134, 129, 124, 120, 115, 111, 106, 101, 97, 92, 87, 83, 78, 74, 69, 65, 60, 56, 51, 47, 42, 38, 33, 29, 25,
20, 16, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 4, 3, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 4,
4, 5, 6, 7, 8, 9, 11, 12, 13, 15, 13, 12, 11, 9, 8, 7, 6, 5, 4, 4, 3, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 1, 2, 2, 3, 4, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 20, 25, 29, 33, 38, 42, 47, 51, 56, 60, 65, 69, 74,
78, 83, 87, 92, 97, 101, 106, 111, 115, 120, 124, 129, 134, 138, 143, 147, 152, 156, 161, 165, 170, 174, 179,
183, 188, 192, 196, 201, 205, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 217, 218, 219, 219, 220,
220, 220, 221, 221, 221, 221, 221, 221, 221, 221, 220, 220, 220, 219, 219, 218, 217, 217, 216, 215, 214, 213,
212, 210, 209, 208, 206 };
*/

static const uint8_t ui8_asin_table[128] = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7,
8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 15, 16, 16, 16, 17, 17,
18, 18, 18, 19, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 23, 24, 24, 25, 25, 25, 26, 26, 27, 27, 27, 28,
Expand Down Expand Up @@ -64,7 +80,6 @@ volatile uint8_t ui8_controller_duty_cycle_target = 0;
volatile uint8_t ui8_g_foc_angle = 0;
// Field Weakening Hall offset (added during interpolation)
volatile uint8_t ui8_fw_hall_counter_offset = 0;
volatile uint8_t ui8_g_field_weakening_enable = 0;

static uint8_t ui8_counter_duty_cycle_ramp_up = 0;
static uint8_t ui8_counter_duty_cycle_ramp_down = 0;
Expand Down Expand Up @@ -707,7 +722,7 @@ void TIM1_CAP_COM_IRQHandler(void) __interrupt(TIM1_CAP_COM_IRQHANDLER)
// - check if brakes are engaged

// check if coaster brake is engaged
if (ui16_adc_torque < ui16_adc_coaster_brake_threshold) {
if(ui16_adc_torque < ui16_adc_coaster_brake_threshold) {
// set brake state
ui8_brake_state = 1;
} else {
Expand All @@ -730,7 +745,8 @@ void TIM1_CAP_COM_IRQHandler(void) __interrupt(TIM1_CAP_COM_IRQHANDLER)
|| (ui8_adc_motor_phase_current > ui8_adc_motor_phase_current_max)
|| (ui16_hall_counter_total < (HALL_COUNTER_FREQ / MOTOR_OVER_SPEED_ERPS))
|| (ui16_adc_voltage < ui16_adc_voltage_cut_off)
|| (ui8_brake_state)) {
|| (ui8_brake_state)
|| (!ui8_assist_level)) {
// reset duty cycle ramp up counter (filter)
ui8_counter_duty_cycle_ramp_up = 0;

Expand Down Expand Up @@ -761,7 +777,7 @@ void TIM1_CAP_COM_IRQHandler(void) __interrupt(TIM1_CAP_COM_IRQHANDLER)
ui8_g_duty_cycle++;
}
}
} else if ((ui8_g_duty_cycle == PWM_DUTY_CYCLE_MAX) && (ui8_g_field_weakening_enable)
} else if ((ui8_g_duty_cycle == PWM_DUTY_CYCLE_MAX) && (ui8_field_weakening_enabled)
&& (ui8_adc_battery_current_filtered < ui8_controller_adc_battery_current_target)) {
// reset duty cycle ramp down counter (filter)
ui8_counter_duty_cycle_ramp_down = 0;
Expand Down Expand Up @@ -1039,6 +1055,11 @@ void calc_foc_angle(void) {
// calc FOC angle
ui8_g_foc_angle = asin_table(ui16_iwl_128 / ui16_e_phase_voltage);

uint8_t ui8_tmp = ui8_adc_battery_current_filtered / (uint8_t)13U;
if (ui8_tmp > 5)
ui8_tmp = 5;
ui8_g_foc_angle += ui8_tmp;

skip_foc:
// low pass filter FOC angle
ui16_foc_angle_accumulated -= ui16_foc_angle_accumulated >> 4;
Expand Down
2 changes: 0 additions & 2 deletions src/motor.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ extern volatile uint8_t ui8_hall_ref_angles[6];
extern volatile uint8_t ui8_hall_counter_offsets[6];
extern volatile uint8_t ui8_hall_sensors_state;

extern volatile uint8_t ui8_g_field_weakening_enable;

// motor erps
extern volatile uint16_t ui16_motor_speed_erps;

Expand Down

0 comments on commit 745d2eb

Please sign in to comment.