Skip to content

Commit

Permalink
v20.1C.4-860C-update-3
Browse files Browse the repository at this point in the history
  • Loading branch information
emmebrusa committed Jul 5, 2023
1 parent 4047d27 commit dbe885e
Show file tree
Hide file tree
Showing 17 changed files with 1,058 additions and 223 deletions.
16 changes: 16 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
TSDZ2 Open Source Firmware v20.1C.4 update 3 for 860C display
1 - Anti-tampering measure.
Added password to parameters regarding speed limit, motor power, use of throttle and cruise.
2 - Startup assist. Added speed limit to 6 km/h.
3 - Choice of temperature sensor, LM35 or TMP36.
4 - Choice of brake input, brake sensors or on/off thermostat (NO max 85°C).
5 - Choosing how to use the throttle.
6 - Choosing how to use the cruise.
7 - Added motor overcurrent check (by mspider65), e7 Overcurrent error.
8 - Added throttle input check on power up, e5 Throttle fault.
Changed files
main.h
ebike_app.c
ebike_app.h
motor.c

TSDZ2 Open Source Firmware v20.1C.4 update 2 for 860C display
1 - Improved Walk assist speed adjustment.
2 - Added legal throttle, only works when pedaling, in street mode.
Expand Down
Binary file removed manuals/EN-860C_additional_manual-v20.1C.4-2.pdf
Binary file not shown.
Binary file added manuals/EN-860C_additional_manual-v20.1C.4-3.pdf
Binary file not shown.
Binary file removed manuals/IT-Manuale_integrativo_860C-v20.1C.4-2.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed manuals/odt/EN-860C_additional_manual-v20.1C.4-2.odt
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
793 changes: 793 additions & 0 deletions releases/v20.1C.4-3-860C/TSDZ2-v20.1C.4-3-860C.hex

Large diffs are not rendered by default.

419 changes: 232 additions & 187 deletions src/ebike_app.c

Large diffs are not rendered by default.

15 changes: 4 additions & 11 deletions src/ebike_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,13 @@ extern volatile uint8_t ui8_adc_motor_phase_current_max;
// ADC battery current target
//extern volatile uint8_t ui8_adc_battery_current_target;

// Motor enabled
// Motor
extern uint8_t ui8_motor_inductance_x1048576;
extern volatile uint8_t ui8_motor_enabled;

typedef struct _configuration_variables {
uint16_t ui16_battery_low_voltage_cut_off_x10;
uint16_t ui16_wheel_perimeter;
uint8_t ui8_wheel_speed_max;
uint8_t ui8_motor_inductance_x1048576;
uint8_t ui8_pedal_torque_per_10_bit_ADC_step_x100;
uint8_t ui8_target_battery_max_power_div25;
uint8_t ui8_optional_ADC_function;
} struct_configuration_variables;
// Throttle
extern uint8_t ui8_adc_throttle_assist;

void ebike_app_controller(void);
struct_configuration_variables* get_configuration_variables(void);

#endif /* _EBIKE_APP_H_ */
16 changes: 9 additions & 7 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@
#define PWM_DUTY_CYCLE_RAMP_UP_INVERSE_STEP_CADENCE_OFFSET (uint8_t)(PWM_CYCLES_SECOND/260) // PWM_DUTY_CYCLE_RAMP_UP_INVERSE_STEP offset for cadence assist mode
#define PWM_DUTY_CYCLE_RAMP_UP_INVERSE_STEP_DEFAULT (uint8_t)(PWM_CYCLES_SECOND/98) // (should be less than 255-50->205) 160 -> 160 * 64 us for every duty cycle increment at 15.625KHz
#define PWM_DUTY_CYCLE_RAMP_UP_INVERSE_STEP_MIN (uint8_t)(PWM_CYCLES_SECOND/781) // 20 -> 20 * 64 us for every duty cycle increment at 15.625KHz
#define PWM_DUTY_CYCLE_RAMP_DOWN_INVERSE_STEP_DEFAULT (uint8_t)(PWM_CYCLES_SECOND/390) // 40 -> 40 * 64 us for every duty cycle decrement at 15.625KHz
#define PWM_DUTY_CYCLE_RAMP_DOWN_INVERSE_STEP_DEFAULT (uint8_t)(PWM_CYCLES_SECOND/260) // 60 -> 60 * 64 us for every duty cycle decrement at 15.625KHz
#define PWM_DUTY_CYCLE_RAMP_DOWN_INVERSE_STEP_MIN (uint8_t)(PWM_CYCLES_SECOND/1953) // 8 -> 8 * 64 us for every duty cycle decrement at 15.625KHz
#define CRUISE_DUTY_CYCLE_RAMP_UP_INVERSE_STEP (uint8_t)(PWM_CYCLES_SECOND/195) // 80 at 15.625KHz
#define CRUISE_DUTY_CYCLE_RAMP_UP_INVERSE_STEP (uint8_t)(PWM_CYCLES_SECOND/130) // 120 at 15.625KHz
#define WALK_ASSIST_DUTY_CYCLE_RAMP_UP_INVERSE_STEP (uint8_t)(PWM_CYCLES_SECOND/78) // 200 at 15.625KHz
#define THROTTLE_DUTY_CYCLE_RAMP_UP_INVERSE_STEP_DEFAULT (uint8_t)(PWM_CYCLES_SECOND/195) // 80 at 15.625KHz
#define THROTTLE_DUTY_CYCLE_RAMP_UP_INVERSE_STEP_DEFAULT (uint8_t)(PWM_CYCLES_SECOND/78) // 200 at 15.625KHz
#define THROTTLE_DUTY_CYCLE_RAMP_UP_INVERSE_STEP_MIN (uint8_t)(PWM_CYCLES_SECOND/390) // 40 at 15.625KHz

#define MOTOR_OVER_SPEED_ERPS ((PWM_CYCLES_SECOND/29) < 650 ? (PWM_CYCLES_SECOND/29) : 650) // motor max speed | 29 points for the sinewave at max speed (less than PWM_CYCLES_SECOND/29)
Expand Down Expand Up @@ -144,10 +144,12 @@ HALL_COUNTER_OFFSET_UP: 29 -> 44
but a value of 25 may be good.
---------------------------------------------------------*/

#define ADC_10_BIT_BATTERY_CURRENT_MAX 112 // 18 amps
#define ADC_10_BIT_MOTOR_PHASE_CURRENT_MAX 187 // 30 amps
//#define ADC_10_BIT_BATTERY_CURRENT_MAX 106 // 17 amps
//#define ADC_10_BIT_MOTOR_PHASE_CURRENT_MAX 177 // 28 amps
#define ADC_10_BIT_BATTERY_OVERCURRENT 150 // 24 amps
#define ADC_10_BIT_BATTERY_EXTRACURRENT 38 // 6 amps
#define ADC_10_BIT_BATTERY_CURRENT_MAX 112 // 18 amps
#define ADC_10_BIT_MOTOR_PHASE_CURRENT_MAX 187 // 30 amps
//#define ADC_10_BIT_BATTERY_CURRENT_MAX 106 // 17 amps
//#define ADC_10_BIT_MOTOR_PHASE_CURRENT_MAX 177 // 28 amps

/*---------------------------------------------------------
NOTE: regarding ADC battery current max
Expand Down
22 changes: 4 additions & 18 deletions src/motor.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,9 +710,7 @@ void TIM1_CAP_COM_IRQHandler(void) __interrupt(TIM1_CAP_COM_IRQHANDLER)
tnz _ui8_g_duty_cycle+0 // if (ui8_g_duty_cycle > 0)
jreq 00051$
clrw x // ui8_adc_motor_phase_current = (ui8_adc_battery_current_filtered << 6)) / ui8_g_duty_cycle;
ld xh, a
srlw x
srlw x
ld xh, a // ui8_adc_battery_current_filtered
ld a, _ui8_g_duty_cycle+0
div x, a
ld a, xl
Expand Down Expand Up @@ -798,7 +796,8 @@ void TIM1_CAP_COM_IRQHandler(void) __interrupt(TIM1_CAP_COM_IRQHANDLER)
} else if ((ui8_field_weakening_enabled)
&& (ui8_g_duty_cycle == PWM_DUTY_CYCLE_MAX)
&& (ui16_motor_speed_erps > MOTOR_SPEED_FIELD_WEAKEANING_MIN) // do not enable at low motor speed / low cadence
&& (ui8_adc_battery_current_filtered < ui8_controller_adc_battery_current_target)) {
&& (ui8_adc_battery_current_filtered < ui8_controller_adc_battery_current_target)
&& (!ui8_adc_throttle_assist)) {
// reset duty cycle ramp down counter (filter)
ui8_counter_duty_cycle_ramp_down = 0;

Expand Down Expand Up @@ -1020,9 +1019,6 @@ void calc_foc_angle(void) {
uint32_t ui32_w_angular_velocity_x16;
uint16_t ui16_iwl_128;

struct_configuration_variables *p_configuration_variables;
p_configuration_variables = get_configuration_variables();

// FOC implementation by calculating the angle between phase current and rotor magnetic flux (BEMF)
// 1. phase voltage is calculate
// 2. I*w*L is calculated, where I is the phase current. L was a measured value for 48V motor.
Expand All @@ -1047,16 +1043,6 @@ void calc_foc_angle(void) {
// multiplication overflow if ui16_motor_speed_erps > 648 (65535/101) -> cast ui16_motor_speed_erps to uint32_t !!!!
ui32_w_angular_velocity_x16 = (uint32_t)ui16_motor_speed_erps * 101U;

// ---------------------------------------------------------------------------------------------------------------------
// NOTE: EXPERIMENTAL and may not be good for the brushless motor inside TSDZ2
// Original message from jbalat on 28.08.2018, about increasing the limits on 36 V motor -- please see that this seems to go over the recomended values
// The ui32_l_x1048576 = 105 is working well so give that a try if you have a 36 V motor.
// This is the minimum value that gives me 550 W of power when I have asked for 550 W at level 5 assist, > 36 km/hr
//
// Remember also to boost the max motor erps in main.h to get higher cadence
// #define MOTOR_OVER_SPEED_ERPS 700 // motor max speed, protection max value | 30 points for the sinewave at max speed
// ---------------------------------------------------------------------------------------------------------------------

// ---------------------------------------------------------------------------------------------------------------------
// 36 V motor: L = 76uH
// 48 V motor: L = 135uH
Expand All @@ -1066,7 +1052,7 @@ void calc_foc_angle(void) {
// ui32_l_x1048576 = 142 <--- THIS VALUE WAS verified experimentaly on 2018.07 to be near the best value for a 48V motor
// Test done with a fixed mechanical load, duty_cycle = 200 and 100 and measured battery current was 16 and 6 (10 and 4 amps)
// ---------------------------------------------------------------------------------------------------------------------
ui16_l_x1048576 = p_configuration_variables->ui8_motor_inductance_x1048576;
ui16_l_x1048576 = ui8_motor_inductance_x1048576;

// calc IwL
ui16_iwl_128 = ((uint32_t)((uint32_t)ui16_i_phase_current_x2 * ui16_l_x1048576) * ui32_w_angular_velocity_x16 ) >> 18;
Expand Down

0 comments on commit dbe885e

Please sign in to comment.