From df2e58303e482ce176c141f62d834b18a4aef895 Mon Sep 17 00:00:00 2001 From: Benjamin Vedder Date: Wed, 6 Aug 2014 18:44:15 +0200 Subject: [PATCH] Current control and current limit updates --- comm.c | 4 ++++ mcconf/mcconf_outrunner1.h | 3 ++- mcconf/mcconf_outrunner2.h | 5 +++-- mcconf/mcconf_rccar1.h | 3 ++- mcconf/mcconf_sten.h | 3 ++- mcpwm.c | 8 ++++++-- mcpwm.h | 5 +++-- 7 files changed, 22 insertions(+), 9 deletions(-) diff --git a/comm.c b/comm.c index bd42a69b..1861a250 100644 --- a/comm.c +++ b/comm.c @@ -287,6 +287,10 @@ void comm_print_fault_code(mc_fault_code fault_code) { comm_print("FAULT_CODE_DRV8302\n"); break; + case FAULT_CODE_ABS_OVER_CURRENT: + comm_print("FAULT_CODE_ABS_OVER_CURRENT\n"); + break; + default: break; } diff --git a/mcconf/mcconf_outrunner1.h b/mcconf/mcconf_outrunner1.h index b22bb022..92d65b72 100644 --- a/mcconf/mcconf_outrunner1.h +++ b/mcconf/mcconf_outrunner1.h @@ -35,6 +35,7 @@ #define MCPWM_CURRENT_MIN -60.0 // Current limit in Amperes (Lower) #define MCPWM_IN_CURRENT_MAX 60.0 // Input current limit in Amperes (Upper) #define MCPWM_IN_CURRENT_MIN -20.0 // Input current limit in Amperes (Lower) +#define MCPWM_MAX_ABS_CURRENT 90.0 // The maximum absolute current above which a fault is generated // Sensorless settings #define MCPWM_IS_SENSORLESS 1 // Use sensorless commutation @@ -51,7 +52,7 @@ #define MCPWM_PID_MIN_RPM 1200.0 // Minimum allowed RPM // Current control parameters -#define MCPWM_CURRENT_CONTROL_GAIN 0.0016 // Current controller error gain +#define MCPWM_CURRENT_CONTROL_GAIN 0.0036 // Current controller error gain #define MCPWM_CURRENT_CONTROL_MIN 1.0 // Minimum allowed current // Hall sensor diff --git a/mcconf/mcconf_outrunner2.h b/mcconf/mcconf_outrunner2.h index 0d5e94ff..ba496ba8 100644 --- a/mcconf/mcconf_outrunner2.h +++ b/mcconf/mcconf_outrunner2.h @@ -34,6 +34,7 @@ #define MCPWM_CURRENT_MIN -60.0 // Current limit in Amperes (Lower) #define MCPWM_IN_CURRENT_MAX 60.0 // Input current limit in Amperes (Upper) #define MCPWM_IN_CURRENT_MIN -20.0 // Input current limit in Amperes (Lower) +#define MCPWM_MAX_ABS_CURRENT 90.0 // The maximum absolute current above which a fault is generated // Sensorless settings #define MCPWM_IS_SENSORLESS 1 // Use sensorless commutation @@ -47,10 +48,10 @@ #define MCPWM_PID_KP 0.0001 // Proportional gain #define MCPWM_PID_KI 0.002 // Integral gain #define MCPWM_PID_KD 0.0 // Derivative gain -#define MCPWM_PID_MIN_RPM 1200.0 // Minimum allowed RPM +#define MCPWM_PID_MIN_RPM 900.0 // Minimum allowed RPM // Current control parameters -#define MCPWM_CURRENT_CONTROL_GAIN 0.0016 // Current controller error gain +#define MCPWM_CURRENT_CONTROL_GAIN 0.0036 // Current controller error gain #define MCPWM_CURRENT_CONTROL_MIN 1.0 // Minimum allowed current #endif /* MCCONF_OUTRUNNER2_H_ */ diff --git a/mcconf/mcconf_rccar1.h b/mcconf/mcconf_rccar1.h index d70fa609..70b2ea2a 100644 --- a/mcconf/mcconf_rccar1.h +++ b/mcconf/mcconf_rccar1.h @@ -32,6 +32,7 @@ #define MCPWM_CURRENT_MIN -80.0 // Current limit in Amperes (Lower) #define MCPWM_IN_CURRENT_MAX 80.0 // Input current limit in Amperes (Upper) #define MCPWM_IN_CURRENT_MIN -25.0 // Input current limit in Amperes (Lower) +#define MCPWM_MAX_ABS_CURRENT 110.0 // The maximum absolute current above which a fault is generated #define MCPWM_CURRENT_STARTUP_BOOST 0.08 // The lowest duty cycle to use in current control mode @ 20V. #define MCPWM_CURRENT_CONTROL_NO_REV 0 // Do not reverse the direction in current control mode, brake only #define MCPWM_RPM_MAX 100000.0 // The motor speed limit (Upper) @@ -57,7 +58,7 @@ #define MCPWM_PID_MIN_RPM 950.0 // Minimum allowed RPM // Current control parameters -#define MCPWM_CURRENT_CONTROL_GAIN 0.0016 // Current controller error gain +#define MCPWM_CURRENT_CONTROL_GAIN 0.0036 // Current controller error gain #define MCPWM_CURRENT_CONTROL_MIN 1.0 // Minimum allowed current #endif /* MCCONF_RCCAR1_H_ */ diff --git a/mcconf/mcconf_sten.h b/mcconf/mcconf_sten.h index fb7d184b..2bd50c51 100644 --- a/mcconf/mcconf_sten.h +++ b/mcconf/mcconf_sten.h @@ -30,6 +30,7 @@ */ #define MCPWM_CURRENT_MAX 40.0 // Current limit in Amperes (Upper) #define MCPWM_CURRENT_MIN -30.0 // Current limit in Amperes (Lower) +#define MCPWM_MAX_ABS_CURRENT 90.0 // The maximum absolute current above which a fault is generated #define MCPWM_IN_CURRENT_MAX 25.0 // Input current limit in Amperes (Upper) #define MCPWM_IN_CURRENT_MIN -20.0 // Input current limit in Amperes (Lower) #define MCPWM_RPM_MAX 50000.0 // The motor speed limit (Upper) @@ -55,7 +56,7 @@ #define MCPWM_PID_MIN_RPM 1200.0 // Minimum allowed RPM // Current control parameters -#define MCPWM_CURRENT_CONTROL_GAIN 0.0016 // Current controller error gain +#define MCPWM_CURRENT_CONTROL_GAIN 0.0036 // Current controller error gain #define MCPWM_CURRENT_CONTROL_MIN 0.05 // Minimum allowed current #endif /* MCCONF_STEN_H_ */ diff --git a/mcpwm.c b/mcpwm.c index 6b4cd178..435fd6a8 100644 --- a/mcpwm.c +++ b/mcpwm.c @@ -1468,6 +1468,10 @@ void mcpwm_adc_int_handler(void *p, uint32_t flags) { motor_current_iterations++; input_current_iterations++; + if (fabsf(current_nofilter) > MCPWM_MAX_ABS_CURRENT) { + fault_stop(FAULT_CODE_ABS_OVER_CURRENT); + } + if (state == MC_STATE_RUNNING && has_commutated) { // Compensation for supply voltage variations const float voltage_scale = 20.0 / input_voltage; @@ -1484,7 +1488,7 @@ void mcpwm_adc_int_handler(void *p, uint32_t flags) { if (control_mode == CONTROL_MODE_CURRENT) { // Compute error - const float error = current_set - (direction ? current : -current); + const float error = current_set - (direction ? current_nofilter : -current_nofilter); float step = error * MCPWM_CURRENT_CONTROL_GAIN * voltage_scale; const float start_boost = MCPWM_CURRENT_STARTUP_BOOST / voltage_scale; @@ -1527,7 +1531,7 @@ void mcpwm_adc_int_handler(void *p, uint32_t flags) { dutycycle_set = dutycycle_now_tmp >= 0.0 ? MCPWM_MIN_DUTY_CYCLE : -MCPWM_MIN_DUTY_CYCLE; } else if (control_mode == CONTROL_MODE_CURRENT_BRAKE) { // Compute error - const float error = -fabsf(current_set) - current; + const float error = -fabsf(current_set) - current_nofilter; float step = error * MCPWM_CURRENT_CONTROL_GAIN * voltage_scale; // Do not ramp too much diff --git a/mcpwm.h b/mcpwm.h index 2d7ce3e2..6e19fc7e 100644 --- a/mcpwm.h +++ b/mcpwm.h @@ -44,7 +44,8 @@ typedef enum { FAULT_CODE_NONE = 0, FAULT_CODE_OVER_VOLTAGE, FAULT_CODE_UNDER_VOLTAGE, - FAULT_CODE_DRV8302 + FAULT_CODE_DRV8302, + FAULT_CODE_ABS_OVER_CURRENT } mc_fault_code; typedef enum { @@ -122,7 +123,7 @@ extern volatile int mcpwm_vzero; #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_CURRENT_LIMIT_GAIN 1.0 // 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 0 // Ignore commands for this duration in msec after a stop has been sent #define MCPWM_DETECT_STOP_TIME 500 // Ignore commands for this duration in msec after a detect command