Skip to content

Commit

Permalink
Removed erps lower limit.
Browse files Browse the repository at this point in the history
Fixes small jerk during Smooth Startup.
  • Loading branch information
dzid26 committed Apr 29, 2024
1 parent 68f23fc commit 3f6a8d3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/controller/ebike_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ static void ebike_control_motor(void)

//voltage based control assumes the winding resistance is constant for simplicity
uint32_t smooth_start_voltage_target_x100 = (uint32_t)(uint16_t)(smooth_start_voltage_limit_x100 + smooth_start_voltage_limit_blend_x100);
smooth_start_voltage_target_x100 += (uint32_t)(uint16_t)(ui16_motor_bemf_voltage_x1000 / (10U + SMOOTH_START_BEMF_REDUCE_FACTOR));
smooth_start_voltage_target_x100 += (uint32_t)(uint16_t)(ui16_motor_bemf_voltage_x1000 / (10U + SMOOTH_START_BEMF_REDUCE_FACTOR));//due to resolution of the pwm duty cycle, BEMF starts to increase the duty only above about 3erps
if (smooth_start_voltage_target_x100 > UINT16_MAX){
smooth_start_voltage_target_x100 = UINT16_MAX;
}
Expand Down
8 changes: 5 additions & 3 deletions src/controller/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

// PWM related values
// motor
#define PWM_CYCLES_SECOND 19047U // 52us (PWM period)
#define PWM_CYCLES_COUNTER_MAX 3800U // 5 erps minimum speed -> 1/5 = 200 ms; 200 ms / 50 us = 4000 (3125 at 15.625KHz)
#define DOUBLE_PWM_CYCLES_SECOND 38094 // 25us (2 irq x PWM period)
#define PWM_PERIOD 420U
#define PWM_DOUBLE_PERIOD (2U*PWM_PERIOD) //PWM center aligned mode: counts from 0 to PWM_PERIOD and then down from PWM_PERIOD to 0
#define PWM_CYCLES_SECOND ((uint16_t)(HSE_VALUE / PWM_DOUBLE_PERIOD)) // 19047Hz - 52us (PWM period) - !! has to be less than 21845
#define DOUBLE_PWM_CYCLES_SECOND ((uint16_t)(HSE_VALUE / PWM_PERIOD)) // 25us (2 irq x PWM period)
#define PWM_CYCLES_COUNTER_MAX (DOUBLE_PWM_CYCLES_SECOND + 1U) // +1U ensures ui16_motor_speed_erps is 0 when counter is max
// ramp up/down PWM cycles count
#define PWM_DUTY_CYCLE_RAMP_UP_INVERSE_STEP_CADENCE_OFFSET 60 // PWM_DUTY_CYCLE_RAMP_UP_INVERSE_STEP offset for cadence assist mode
//#define PWM_DUTY_CYCLE_RAMP_UP_INVERSE_STEP_DEFAULT 195 // 160 -> 160 * 64 us for every duty cycle increment at 15.625KHz
Expand Down
4 changes: 2 additions & 2 deletions src/controller/motor.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ uint16_t ui16_PWM_cycles_counter_a = 3;
uint8_t ui8_pwm_counter_valid_b = 0;
uint16_t ui16_PWM_cycles_counter_b = 3;
uint16_t ui16_PWM_cycles_counter_6 = 3;
uint16_t ui16_PWM_cycles_counter_total = 0xffff;
uint16_t ui16_PWM_cycles_counter_total = PWM_CYCLES_COUNTER_MAX;
uint8_t ui8_motor_commutation_type = BLOCK_COMMUTATION;
volatile uint16_t ui16_motor_speed_erps = 0;
static uint8_t ui8_motor_rotor_absolute_angle;
Expand Down Expand Up @@ -539,7 +539,7 @@ void TIM1_CAP_COM_IRQHandler(void) __interrupt(TIM1_CAP_COM_IRQHANDLER)
ui16_PWM_cycles_counter_6 = 2;
ui8_pwm_counter_valid_a = 0;
ui8_pwm_counter_valid_b = 0;
ui16_PWM_cycles_counter_total = 0xffff;
ui16_PWM_cycles_counter_total = PWM_CYCLES_COUNTER_MAX;
ui8_g_foc_angle = 0;
ui8_motor_commutation_type = BLOCK_COMMUTATION;
ui8_hall_sensors_state_last = 0; // this way we force execution of hall sensors code next time
Expand Down
2 changes: 1 addition & 1 deletion src/controller/pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void pwm_init_bipolar_4q(void) {
TIM1_TimeBaseInit(0, // TIM1_Prescaler = 0
TIM1_COUNTERMODE_CENTERALIGNED3,
// clock = 16MHz; counter period = 840; PWM freq = 16MHz / 840 = 19,047kHz;
420, // PWM center aligned mode: counts from 0 to 420 and then down from 420 to 0
PWM_PERIOD, // PWM center aligned mode: counts from 0 to PWM_PERIOD and then down from PWM_PERIOD to 0
1);// will fire the TIM1_IT_UPDATE at every PWM period cycle

//#define DISABLE_PWM_CHANNELS_1_3
Expand Down

0 comments on commit 3f6a8d3

Please sign in to comment.