diff --git a/mcconf/mcconf_sten.h b/mcconf/mcconf_sten.h index 97ce4e17..1f5f2160 100644 --- a/mcconf/mcconf_sten.h +++ b/mcconf/mcconf_sten.h @@ -37,7 +37,7 @@ #define MCPWM_MIN_VOLTAGE 20.0 // Minimum input voltage #define MCPWM_MAX_VOLTAGE 50.0 // Maximum input voltage #define MCPWM_CURRENT_STARTUP_BOOST 0.03 // The lowest duty cycle to use in current control mode (has to be > MCPWM_MIN_DUTY_CYCLE) -#define MCPWM_RPM_LIMIT_NEG_TORQUE 0 // Do not brake when going to fast, just stop applying torque +#define MCPWM_RPM_LIMIT_NEG_TORQUE 0 // Use negative torque to limit the RPM #define MCPWM_CURR_MIN_RPM_FBRAKE 900 // Minimum electrical RPM to use full brake at // Sensorless settings diff --git a/mcpwm.c b/mcpwm.c index 17b6cc80..15900059 100644 --- a/mcpwm.c +++ b/mcpwm.c @@ -1520,14 +1520,14 @@ void mcpwm_adc_int_handler(void *p, uint32_t flags) { direction ? MCPWM_MAX_DUTY_CYCLE : -MCPWM_MAX_DUTY_CYCLE, ramp_step_no_lim); limit_delay = 1; } else if (rpm > MCPWM_RPM_MAX) { - if ((MCPWM_RPM_LIMIT_NEG_TORQUE || current > -4.0) && dutycycle_now <= dutycycle_now_tmp) { - utils_step_towards((float*) &dutycycle_now, 0.0, ramp_step); + if ((MCPWM_RPM_LIMIT_NEG_TORQUE || current > -1.0) && dutycycle_now <= dutycycle_now_tmp) { + utils_step_towards((float*) &dutycycle_now, 0.0, MCPWM_RAMP_STEP_RPM_LIMIT); limit_delay = 1; slow_ramping_cycles = 500; } } else if (rpm < MCPWM_RPM_MIN) { - if ((MCPWM_RPM_LIMIT_NEG_TORQUE || current > -4.0) && dutycycle_now >= dutycycle_now_tmp) { - utils_step_towards((float*) &dutycycle_now, 0.0, ramp_step); + if ((MCPWM_RPM_LIMIT_NEG_TORQUE || current > -1.0) && dutycycle_now >= dutycycle_now_tmp) { + utils_step_towards((float*) &dutycycle_now, 0.0, MCPWM_RAMP_STEP_RPM_LIMIT); limit_delay = 1; slow_ramping_cycles = 500; } diff --git a/mcpwm.h b/mcpwm.h index 5d4caecc..979ace00 100644 --- a/mcpwm.h +++ b/mcpwm.h @@ -120,6 +120,7 @@ extern volatile int mcpwm_vzero; #define MCPWM_AVG_COM_RPM 3 // Number of commutations to average RPM over #define MCPWM_RAMP_STEP 0.01 // Ramping step (1000 times/sec) at maximum duty cycle #define MCPWM_RAMP_STEP_CURRENT_MAX 0.04 // Maximum ramping step (1000 times/sec) for the current control +#define MCPWM_RAMP_STEP_RPM_LIMIT 0.0005 // Ramping step when limiting the RPM #define MCPWM_CURRENT_LIMIT_GAIN 0.1 // The error gain of the current limiting algorithm #define MCPWM_FAULT_STOP_TIME 3000 // Ignore commands for this duration in msec when faults occur #define MCPWM_CMD_STOP_TIME 50 // Ignore commands for this duration in msec after a stop has been sent