|
|
@@ -6,6 +6,7 @@
|
|
|
#include "measure.h"
|
|
|
#include "measure_task.h"
|
|
|
#include "health.h"
|
|
|
+#include "Least_Square.h"
|
|
|
|
|
|
#if 0
|
|
|
#define MIN_VOLTAGE_FOR_DISCHARGER (2.2f * CELLS_NUM * 1000) //允许能放电的最小电压
|
|
|
@@ -41,6 +42,8 @@ static float min_discharger_cell_recovery_vol[] = {2100, 2600};//
|
|
|
static float min_discharger_pdown_vol[] = {28000, 34000}; //power down的最小电压
|
|
|
static float min_discharger_pdown_cell_vol[] = {1900, 2200}; //power down的最小电芯电压
|
|
|
|
|
|
+#define MAX_TRY_FOR_AUX_SHORT 10
|
|
|
+
|
|
|
/* health 模块,只检测状态,不做任何控制,如果有异常情况,控制中心会统一处理 */
|
|
|
static void check_ml5238_state(int event);
|
|
|
static void load_detect_handler(shark_timer_t *timer);
|
|
|
@@ -54,7 +57,6 @@ static bms_health_t _health;
|
|
|
static debounce_timer_t _load_detect_timer = {.max_count = 100, .interval = 10, ._timer.handler = load_detect_handler};
|
|
|
static debounce_timer_t _charger_detect_timer = {.max_count = 500, .interval = 10, ._timer.handler = charger_detect_handler};
|
|
|
static shark_timer_t _clear_short_current_timer = {.handler = clear_short_current_handler};
|
|
|
-
|
|
|
static error_counts_t error_counts;
|
|
|
|
|
|
void health_init(void){
|
|
|
@@ -72,6 +74,7 @@ void health_log(void){
|
|
|
health_debug("soft short:%d\n", error_counts.soft_current_short);
|
|
|
health_debug("hard short:%d\n", error_counts.hard_current_short);
|
|
|
health_debug("work temp: %d\n", _health.is_work_temp_normal);
|
|
|
+ health_debug("aux_short: %d, %d\n", error_counts.aux_short, error_counts.aux_real_short);
|
|
|
}
|
|
|
|
|
|
bms_health_t *bms_health(){
|
|
|
@@ -149,12 +152,7 @@ static debounce_t _charger_over_current = {
|
|
|
.count = 0,
|
|
|
.max_count = 70
|
|
|
};
|
|
|
-#if 0
|
|
|
-static debounce_t _discharger_over_current = {
|
|
|
- .count = 0,
|
|
|
- .max_count = 20
|
|
|
-};
|
|
|
-#endif
|
|
|
+
|
|
|
/* 55 - 100A, 14 - I x I / 750 */
|
|
|
void check_current_state(void){
|
|
|
float current = measure_value()->load_current;
|
|
|
@@ -183,20 +181,7 @@ void check_current_state(void){
|
|
|
ml5238_enable_load_detect(1); //打开负载检测
|
|
|
shark_timer_post(&_load_detect_timer._timer, _load_detect_timer.interval);
|
|
|
soft_current_init();
|
|
|
- }
|
|
|
-#if 0
|
|
|
- if ((abs(current) >= MAX_CURRENT_FOR_DISCHARGER)) {
|
|
|
- _discharger_over_current.count++;
|
|
|
- }else {
|
|
|
- _discharger_over_current.count = 0;
|
|
|
- }
|
|
|
- if (_discharger_over_current.count >= _discharger_over_current.max_count) {
|
|
|
- _health.load_current_short = 1;
|
|
|
- _discharger_over_current.count = 0;
|
|
|
- ml5238_enable_load_detect(1); //打开负载检测
|
|
|
- shark_timer_post(&_load_detect_timer._timer, _load_detect_timer.interval);
|
|
|
- }
|
|
|
-#endif
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -346,19 +331,26 @@ static shark_timer_t _aux_unlock_timer = {.handler = _aux_unlock_timer_handler};
|
|
|
|
|
|
static void _aux_lock_timer_handler(shark_timer_t *t){
|
|
|
AUX_VOL_OPEN(1);
|
|
|
- shark_timer_post( &_aux_unlock_timer, 200);
|
|
|
- health_debug("open aux[re-enable], %lld\n", shark_get_mseconds());
|
|
|
- if (++small_power_detect_count >= 10){
|
|
|
- delay_us(1000);
|
|
|
+ if (++small_power_detect_count >= MAX_TRY_FOR_AUX_SHORT){
|
|
|
//端口电压小于阈值,判断为小电流短路
|
|
|
- if (get_small_current_voltage() < SMALL_CURRENT_MIN_VOLTAGE){//real short
|
|
|
- bms_health()->small_current_short = 1;
|
|
|
+ int short_voltage = get_small_current_voltage()/1000;
|
|
|
+ int pack_voltage = bms_state_get()->pack_voltage/1000;
|
|
|
+ if (short_voltage >= (pack_voltage - AUX_SHORT_DIFF_VOLTAGE)) {
|
|
|
+ _health.small_current_short = 1;
|
|
|
+ error_counts.aux_short ++;
|
|
|
AUX_VOL_OPEN(0);
|
|
|
small_power_detect_count = 0;
|
|
|
shark_timer_post( &_aux_lock_timer, 30 * 1000); //30s后再次尝试打开
|
|
|
shark_timer_cancel(&_aux_unlock_timer);
|
|
|
- health_debug("set aux short current, and retry after 30s\n");
|
|
|
+ if (short_voltage >= (pack_voltage - AUX_SHORT_REAL_DIFF_VOLTAGE)){ //real short
|
|
|
+ error_counts.aux_real_short ++;
|
|
|
+ _health.small_current_real_short = 1;
|
|
|
+ }
|
|
|
+ health_debug("aux short, v:%d, and retry after 30s\n", short_voltage);
|
|
|
}
|
|
|
+ }else {
|
|
|
+ health_debug("open aux[re-enable], %lld\n", shark_get_mseconds());
|
|
|
+ shark_timer_post( &_aux_unlock_timer, 200);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -366,7 +358,8 @@ static void _aux_unlock_timer_handler(shark_timer_t *t){
|
|
|
if (!io_state()->aux_lock_detect){
|
|
|
health_debug("unlock aux detect\n");
|
|
|
small_power_detect_count = 0;
|
|
|
- bms_health()->small_current_short = 0;
|
|
|
+ _health.small_current_short = 0;
|
|
|
+ _health.small_current_real_short = 0;
|
|
|
AUX_VOL_OPEN(1);
|
|
|
}
|
|
|
}
|
|
|
@@ -375,7 +368,8 @@ static void _aux_unlock_timer_handler(shark_timer_t *t){
|
|
|
void health_stop_aux_detect(void){
|
|
|
shark_timer_cancel(&_aux_unlock_timer);
|
|
|
shark_timer_cancel(&_aux_lock_timer);
|
|
|
- bms_health()->small_current_short = 0;
|
|
|
+ _health.small_current_short = 0;
|
|
|
+ _health.small_current_real_short = 0;
|
|
|
}
|
|
|
|
|
|
void health_process_aux_lock(void){
|