mirror of https://github.com/rusefi/bldc.git
Current control and current limit updates
This commit is contained in:
parent
567dd12e36
commit
df2e58303e
4
comm.c
4
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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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_ */
|
||||
|
|
|
@ -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_ */
|
||||
|
|
|
@ -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_ */
|
||||
|
|
8
mcpwm.c
8
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
|
||||
|
|
5
mcpwm.h
5
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
|
||||
|
|
Loading…
Reference in New Issue