diff --git a/Firmware/Board/v3/Inc/main.h b/Firmware/Board/v3/Inc/main.h index ac9bd857..4292821d 100644 --- a/Firmware/Board/v3/Inc/main.h +++ b/Firmware/Board/v3/Inc/main.h @@ -170,8 +170,10 @@ #if HW_VERSION_VOLTAGE == 48 #define VBUS_S_DIVIDER_RATIO 19.0f +#define VBUS_OVERVOLTAGE_LEVEL 52.0f #elif HW_VERSION_VOLTAGE == 24 #define VBUS_S_DIVIDER_RATIO 11.0f +#define VBUS_OVERVOLTAGE_LEVEL 26.0f #else #error "unknown board voltage" #endif diff --git a/Firmware/MotorControl/low_level.c b/Firmware/MotorControl/low_level.c index c1e99742..45c7529c 100644 --- a/Firmware/MotorControl/low_level.c +++ b/Firmware/MotorControl/low_level.c @@ -68,7 +68,8 @@ Motor_t motors[] = { .current_setpoint = 0.0f, // [A] .calibration_current = 10.0f, // [A] .resistance_calib_max_voltage = 1.0f, // [V] - You may need to increase this if this voltage isn't sufficient to drive calibration_current through the motor. - .dc_bus_brownout_trip_level = 8.0f, // [V] + .dc_bus_undervoltage_trip_level = 8.0f, // [V] + .dc_bus_overvoltage_trip_level = VBUS_OVERVOLTAGE_LEVEL, // [V] .phase_inductance = 0.0f, // to be set by measure_phase_inductance .phase_resistance = 0.0f, // to be set by measure_phase_resistance .motor_thread = 0, @@ -176,7 +177,8 @@ Motor_t motors[] = { .current_setpoint = 0.0f, // [A] .calibration_current = 10.0f, // [A] .resistance_calib_max_voltage = 1.0f, // [V] - You may need to increase this if this voltage isn't sufficient to drive calibration_current through the motor. - .dc_bus_brownout_trip_level = 8.0f, // [V] + .dc_bus_undervoltage_trip_level = 8.0f, // [V] + .dc_bus_overvoltage_trip_level = VBUS_OVERVOLTAGE_LEVEL, // [V] .phase_inductance = 0.0f, // to be set by measure_phase_inductance .phase_resistance = 0.0f, // to be set by measure_phase_resistance .motor_thread = 0, @@ -1320,8 +1322,16 @@ bool check_DRV_fault(Motor_t* motor) { } //Returns true if everything is OK (no fault) -bool check_PSU_brownout(Motor_t* motor) { - if(vbus_voltage < motor->dc_bus_brownout_trip_level) +bool check_vbus_undervoltage(Motor_t* motor) { + if(vbus_voltage < motor->dc_bus_undervoltage_trip_level) + return false; + return true; +} + +//Returns true if everything is OK (no fault) +// TODO This will be less repetitive with the refactoring +bool check_vbus_overvoltage(Motor_t* motor) { + if(vbus_voltage > motor->dc_bus_overvoltage_trip_level) return false; return true; } @@ -1338,8 +1348,12 @@ bool do_checks(Motor_t* motor) { DRV8301_readData(&motor->gate_driver, local_regs); return false; } - if (!check_PSU_brownout(motor)) { - motor->error = ERROR_DC_BUS_BROWNOUT; + if (!check_vbus_undervoltage(motor)) { + motor->error = ERROR_DC_BUS_UNDERVOLTAGE; + return false; + } + if (!check_vbus_overvoltage(motor)) { + motor->error = ERROR_DC_BUS_OVERVOLTAGE; return false; } return true; diff --git a/Firmware/MotorControl/low_level.h b/Firmware/MotorControl/low_level.h index e92774e4..1ed956db 100644 --- a/Firmware/MotorControl/low_level.h +++ b/Firmware/MotorControl/low_level.h @@ -51,7 +51,8 @@ typedef enum { ERROR_DRV_FAULT, ERROR_NOT_IMPLEMENTED_MOTOR_TYPE, ERROR_ENCODER_CPR_OUT_OF_RANGE, - ERROR_DC_BUS_BROWNOUT, + ERROR_DC_BUS_UNDERVOLTAGE, + ERROR_DC_BUS_OVERVOLTAGE, } Error_t; // Note: these should be sorted from lowest level of control to @@ -151,7 +152,8 @@ typedef struct { float current_setpoint; float calibration_current; float resistance_calib_max_voltage; - float dc_bus_brownout_trip_level; + float dc_bus_undervoltage_trip_level; + float dc_bus_overvoltage_trip_level; float phase_inductance; float phase_resistance; osThreadId motor_thread;