Load overvoltage detection corrected and error flag comments added
This commit is contained in:
+91
-20
@@ -31,28 +31,99 @@
|
||||
#include <stdint.h>
|
||||
|
||||
/** Error Flags
|
||||
*
|
||||
*
|
||||
* When adding new flags, please make sure to use only up to 32 errors
|
||||
* Each enum must represent a unique power of 2 number
|
||||
*/
|
||||
enum ErrorFlag {
|
||||
ERR_BAT_UNDERVOLTAGE = 1U << 0 , ///< Battery voltage too low
|
||||
ERR_BAT_OVERVOLTAGE = 1U << 1, ///< Battery voltage too high
|
||||
ERR_BAT_DIS_OVERCURRENT = 1U << 2, ///< Battery discharge overcurrent
|
||||
ERR_BAT_CHG_OVERCURRENT = 1U << 3, ///< Battery charge overcurrent
|
||||
ERR_BAT_DIS_UNDERTEMP = 1U << 4, ///< Temperature below discharge minimum limit
|
||||
ERR_BAT_DIS_OVERTEMP = 1U << 5, ///< Temperature above discharge maximum limit
|
||||
ERR_BAT_CHG_UNDERTEMP = 1U << 6, ///< Temperature below charge minimum limit
|
||||
ERR_BAT_CHG_OVERTEMP = 1U << 7, ///< Temperature above charge maximum limit
|
||||
ERR_LOAD_OVERVOLTAGE = 1U << 8, ///< To high voltage for load so that it was switched off
|
||||
ERR_LOAD_OVERCURRENT = 1U << 9, ///< Long-term overcurrent of load port
|
||||
ERR_LOAD_SHORT_CIRCUIT = 1U << 10, ///< Short circuit detected at load port
|
||||
ERR_LOAD_VOLTAGE_DIP = 1U << 11, ///< Overcurrent identified via voltage dip (may be because of
|
||||
///< too small battery)
|
||||
ERR_INT_OVERTEMP = 1U << 12, ///< Charge controller internal temperature too high
|
||||
ERR_DCDC_HS_MOSFET_SHORT = 1U << 13, ///< Short-circuit in HS MOSFET
|
||||
/** Battery voltage too low
|
||||
*
|
||||
* Set directly in ISR after ADC conversion finished, cleared in Charger::discharge_control()
|
||||
*/
|
||||
ERR_BAT_UNDERVOLTAGE = 1U << 0,
|
||||
|
||||
// we use this as mask to catch all error flags (up to 32 errors)
|
||||
/** Battery voltage too high
|
||||
*
|
||||
* Set directly in ISR after ADC conversion finished, cleared in Charger::charge_control()
|
||||
*/
|
||||
ERR_BAT_OVERVOLTAGE = 1U << 1,
|
||||
|
||||
/** Battery discharge overcurrent
|
||||
*
|
||||
* Not used yet
|
||||
*/
|
||||
ERR_BAT_DIS_OVERCURRENT = 1U << 2,
|
||||
|
||||
/** Battery charge overcurrent
|
||||
*
|
||||
* Not used yet
|
||||
*/
|
||||
ERR_BAT_CHG_OVERCURRENT = 1U << 3,
|
||||
|
||||
/** Temperature below discharge minimum limit
|
||||
*
|
||||
* Set and cleared in Charger::discharge_control
|
||||
*/
|
||||
ERR_BAT_DIS_UNDERTEMP = 1U << 4,
|
||||
|
||||
/** Temperature above discharge maximum limit
|
||||
*
|
||||
* Set and cleared in Charger::discharge_control
|
||||
*/
|
||||
ERR_BAT_DIS_OVERTEMP = 1U << 5,
|
||||
|
||||
/** Temperature below charge minimum limit
|
||||
*
|
||||
* Set and cleared in Charger::discharge_control
|
||||
*/
|
||||
ERR_BAT_CHG_UNDERTEMP = 1U << 6,
|
||||
|
||||
/** Temperature above charge maximum limit
|
||||
*
|
||||
* Set and cleared in Charger::discharge_control
|
||||
*/
|
||||
ERR_BAT_CHG_OVERTEMP = 1U << 7,
|
||||
|
||||
/** To high voltage for load so that it was switched off
|
||||
*
|
||||
* Set in LoadOutput::control() and cleared in LoadOutput::state_machine()
|
||||
*/
|
||||
ERR_LOAD_OVERVOLTAGE = 1U << 8,
|
||||
|
||||
/** Long-term overcurrent of load port
|
||||
*
|
||||
* Set in LoadOutput::control() and cleared in LoadOutput::state_machine()
|
||||
*/
|
||||
ERR_LOAD_OVERCURRENT = 1U << 9,
|
||||
|
||||
/** Short circuit detected at load port
|
||||
*
|
||||
* Set by LoadOutput::control() after overcurrent comparator triggered, cleared in
|
||||
* LoadOutput::state_machine()
|
||||
*/
|
||||
ERR_LOAD_SHORT_CIRCUIT = 1U << 10,
|
||||
|
||||
/** Overcurrent identified via voltage dip (may be caused by too small battery)
|
||||
*
|
||||
* Set in LoadOutput::control() and cleared in LoadOutput::state_machine(). Reported as
|
||||
* overcurrent in load state machine.
|
||||
*/
|
||||
ERR_LOAD_VOLTAGE_DIP = 1U << 11,
|
||||
|
||||
/** Charge controller internal temperature too high
|
||||
*
|
||||
* Set and cleared by ADC update_measurements()
|
||||
*/
|
||||
ERR_INT_OVERTEMP = 1U << 12,
|
||||
|
||||
/** Short-circuit in HS MOSFET
|
||||
*
|
||||
* Set in Dcdc::control() and never cleared
|
||||
*/
|
||||
ERR_DCDC_HS_MOSFET_SHORT = 1U << 13,
|
||||
|
||||
/** Mask to catch all error flags (up to 32 errors)
|
||||
*/
|
||||
ERR_ANY_ERROR = UINT32_MAX,
|
||||
};
|
||||
|
||||
@@ -100,20 +171,20 @@ public:
|
||||
/**
|
||||
* @brief sets one or more error flags in device state
|
||||
* @param e a single ErrorFlag or "bitwise ORed" ERR_XXX | ERR_YYY
|
||||
*/
|
||||
*/
|
||||
void set_error(uint32_t e) { error_flags |= e; }
|
||||
|
||||
/**
|
||||
* @brief clears one or more error flags in device state
|
||||
* @param e a single ErrorFlag or "bitwise ORed" ERR_XXX | ERR_YYY
|
||||
*/
|
||||
*/
|
||||
void clear_error(uint32_t e) { error_flags &= ~e; }
|
||||
|
||||
/**
|
||||
* @brief queries one or more error flags in device state
|
||||
* @param e a single ErrorFlag or "bitwise ORed" ERR_XXX | ERR_YYY
|
||||
* @return true if any of the error flags given in e are set in device state
|
||||
*/
|
||||
*/
|
||||
bool has_error(uint32_t e) { return (error_flags & e) != 0; }
|
||||
};
|
||||
|
||||
|
||||
+23
-7
@@ -261,7 +261,8 @@ void LoadOutput::state_machine()
|
||||
case LOAD_STATE_DISABLED:
|
||||
if (enable == true) {
|
||||
if (port->pos_current_limit > 0 &&
|
||||
!dev_stat.has_error(ERR_BAT_UNDERVOLTAGE | ERR_BAT_OVERVOLTAGE))
|
||||
!dev_stat.has_error(ERR_BAT_UNDERVOLTAGE | ERR_BAT_OVERVOLTAGE
|
||||
| ERR_INT_OVERTEMP | ERR_BAT_DIS_OVERTEMP | ERR_BAT_DIS_UNDERTEMP))
|
||||
{
|
||||
switch_set(true);
|
||||
state = LOAD_STATE_ON;
|
||||
@@ -270,8 +271,13 @@ void LoadOutput::state_machine()
|
||||
if (dev_stat.has_error(ERR_BAT_UNDERVOLTAGE)) {
|
||||
state = LOAD_STATE_OFF_LOW_SOC;
|
||||
}
|
||||
else {
|
||||
// must be battery over/under temperature then
|
||||
else if (dev_stat.has_error(ERR_BAT_OVERVOLTAGE)) {
|
||||
state = LOAD_STATE_OFF_OVERVOLTAGE;
|
||||
}
|
||||
else if (dev_stat.has_error(ERR_INT_OVERTEMP)
|
||||
|| dev_stat.has_error(ERR_BAT_DIS_OVERTEMP)
|
||||
|| dev_stat.has_error(ERR_BAT_DIS_UNDERTEMP))
|
||||
{
|
||||
state = LOAD_STATE_OFF_TEMPERATURE;
|
||||
}
|
||||
}
|
||||
@@ -289,10 +295,19 @@ void LoadOutput::state_machine()
|
||||
lvd_timestamp = time(NULL);
|
||||
state = LOAD_STATE_OFF_LOW_SOC;
|
||||
}
|
||||
else {
|
||||
// must be battery over/under temperature then
|
||||
else if (dev_stat.has_error(ERR_BAT_OVERVOLTAGE)) {
|
||||
state = LOAD_STATE_OFF_OVERVOLTAGE;
|
||||
}
|
||||
else if (dev_stat.has_error(ERR_INT_OVERTEMP)
|
||||
|| dev_stat.has_error(ERR_BAT_DIS_OVERTEMP)
|
||||
|| dev_stat.has_error(ERR_BAT_DIS_UNDERTEMP))
|
||||
{
|
||||
state = LOAD_STATE_OFF_TEMPERATURE;
|
||||
}
|
||||
else {
|
||||
// for safety reasons if other error flags are added in the future
|
||||
state = LOAD_STATE_DISABLED;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LOAD_STATE_OFF_LOW_SOC:
|
||||
@@ -328,8 +343,9 @@ void LoadOutput::state_machine()
|
||||
}
|
||||
break;
|
||||
case LOAD_STATE_OFF_TEMPERATURE:
|
||||
if (!(dev_stat.has_error(ERR_INT_OVERTEMP)) &&
|
||||
port->pos_current_limit > 0)
|
||||
if (!(dev_stat.has_error(ERR_INT_OVERTEMP)
|
||||
|| dev_stat.has_error(ERR_BAT_DIS_OVERTEMP)
|
||||
|| dev_stat.has_error(ERR_BAT_DIS_UNDERTEMP)))
|
||||
{
|
||||
state = LOAD_STATE_DISABLED;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user