Forráskód Böngészése

update

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 5 éve
szülő
commit
f1885f2575

+ 1 - 1
Application/app/protocol_old.c

@@ -69,7 +69,7 @@ static int get_response_data(uint8_t *data, uint8_t operate, uint8_t result){
 	
 	response->health_state = *((uint16_t *)bms_health());
 	response->balance_mask = 0x0;
-	response->misc_status = (ml5238_is_charging() << 1) | (ml5238_is_discharging() << 2) | (AUX_VOL_IS_OPEN() << 3) |(io_state()->aux_lock_detect << 4) | ((get_soc()->capacity==100) << 5) | (((get_soc()->flags & SOC_FLAG_CALIBRATED) == 0) << 6);
+	response->misc_status = (ml5238_is_discharging() << 1) | (ml5238_is_charging() << 2) | (AUX_VOL_IS_OPEN() << 3) |(io_state()->aux_lock_detect << 5) | ((get_soc()->capacity==100) << 4) | (((get_soc()->flags & SOC_FLAG_CALIBRATED) == 0) << 6);
 	response->result = (operate << 4) | result;
 
 	head->size += sizeof(comm_response_t);

+ 8 - 0
Application/app/sox/Least_Square.c

@@ -44,6 +44,14 @@ double get_y_by_x(least_square_t *ls, double x){
 	return ls->Cb * x + ls->Ka;
 }
 
+int get_x_by_y(least_square_t *ls, double y) {
+	if (ls->Cb == 0){
+		return -1; 
+	}
+	int x = (y - ls->Ka)/ls->Cb;
+	return  (x >= 0) ? x : -1;
+}
+
 #if 0
 void Least_square_method(void)
 {

+ 1 - 0
Application/app/sox/Least_Square.h

@@ -16,4 +16,5 @@ typedef struct {
 void least_square_init(least_square_t *ls, int samples);
 int least_square_put(least_square_t *ls, double x, double y);
 double get_y_by_x(least_square_t *ls, double x);
+int get_x_by_y(least_square_t *ls, double y);
 

+ 10 - 0
Application/app/sox/health.c

@@ -67,6 +67,15 @@ bms_health_t *bms_health(){
 	return &_health;
 }
 
+uint32_t bms_health_pack_lower_voltage(void){
+	return min_discharger_vol[_health.is_work_temp_normal];
+}
+
+uint32_t bms_health_cell_lower_voltage(void){
+	return min_discharger_cell_vol[_health.is_work_temp_normal];
+}
+
+
 static void clear_short_current_handler(shark_timer_t *timer){
 	_health.load_current_short = 0; //¸ºÔØÒƳý£¬clear load current short
 	health_warning("clear load current short\n");
@@ -128,6 +137,7 @@ static debounce_t _charger_over_current = {
 	.count = 0,
 	.max_count = 70
 };
+/* 55 - 100A, 14 - I x I / 750 */
 void check_current_state(void){
 	if (bms_state_get()->charging) {
 		if (!_health.charger_over_current) {

+ 2 - 0
Application/app/sox/health.h

@@ -56,6 +56,8 @@ void check_voltage_state(void);
 void check_temp_state(void);
 void health_process_aux_lock(void);
 void health_stop_aux_detect(void);
+uint32_t bms_health_pack_lower_voltage(void);
+uint32_t bms_health_cell_lower_voltage(void);
 
 #endif /* _HEALTH_H__ */
 

+ 2 - 2
Application/app/sox/measure_task.c

@@ -50,7 +50,7 @@ static u32 current_voltage_task_handler(void);
 static void init_current_voltage_task(void){
 	_current_voltage_task._task.handler = current_voltage_task_handler;
 	_current_voltage_task.delay = 15;
-	_current_voltage_task.index = 0;
+	_current_voltage_task.index = CELLS_NUM;
 	_measure_value.load_current = get_pack_current(&_measure_value.current_5238);
 	for (int i = 0; i < CELLS_NUM; i++){
 		_measure_value.cell_vol[i] = get_cell_voltage(i);
@@ -67,8 +67,8 @@ static u32 current_voltage_task_handler(void){
 		return _current_voltage_task.delay;
 	}	
 	//用内阻对cell的电压进行补偿,充电减,放电加
-	_measure_value.cell_vol[_current_voltage_task.index] = get_cell_voltage(_current_voltage_task.index) - bms_health()->internal_resistance[_current_voltage_task.index] * _measure_value.load_current/1000;
 	_current_voltage_task.index = (_current_voltage_task.index + 1) % CELLS_NUM;
+	_measure_value.cell_vol[_current_voltage_task.index] = get_cell_voltage(_current_voltage_task.index) - bms_health()->internal_resistance[_current_voltage_task.index] * _measure_value.load_current/1000;
 	_voltage_notify();//通知bms state 有新的电压数据
 	return _current_voltage_task.delay;
 }

+ 28 - 7
Application/app/sox/soc.c

@@ -31,6 +31,7 @@ static least_square_t discharger_cell_coef;
 static least_square_t discharger_capacity_coef;
 static shark_timer_t least_square_timer = {.handler = _least_square_timer_handler};
 static int least_square_time = 0;
+static int least_square_started = 0;
 #define LEAST_SQUARE_STEP_TIME 1000
 #endif
 void soc_init(void){
@@ -56,23 +57,36 @@ void soc_init(void){
 }
 
 #if LEAST_SQUARE==1
-static void start_least_square(void){
-	least_square_init(&discharger_vol_coef, 10);
-	least_square_init(&discharger_cell_coef, 10);
-	least_square_init(&discharger_capacity_coef, 10);
-	least_square_time = 0;
-	shark_timer_post(&least_square_timer, LEAST_SQUARE_STEP_TIME);
+static void start_least_square(int start){
+	if (start && !least_square_started) {
+		least_square_init(&discharger_vol_coef, 100);
+		least_square_init(&discharger_cell_coef, 100);
+		least_square_init(&discharger_capacity_coef, 100);
+		least_square_time = 0;
+		least_square_started = 1;
+		shark_timer_post(&least_square_timer, LEAST_SQUARE_STEP_TIME);
+	}else if (!start && least_square_started){
+		least_square_time = 0;
+		least_square_started = 0;
+		shark_timer_cancel(&least_square_timer);
+	}
 }
 
 static void _least_square_timer_handler(shark_timer_t *timer){
 	if (least_square_put(&discharger_vol_coef, least_square_time, bms_state_get()->pack_voltage/1000.0f) == 1) {
 		soc_error("voltage: A = %f, B = %f, v: %f\n", discharger_vol_coef.Cb, discharger_vol_coef.Ka, get_y_by_x(&discharger_vol_coef, least_square_time));
+		int delta = get_x_by_y(&discharger_vol_coef, bms_state_get()->pack_voltage/1000.0f) - get_x_by_y(&discharger_vol_coef, bms_health_pack_lower_voltage()/1000.0f);
+		soc_error("remain %d s to reach lower pack voltage\n", delta);
 	}
 	if (least_square_put(&discharger_cell_coef, least_square_time, bms_state_get()->cell_min_vol/1000.0f) == 1) {
 		soc_error("cell: A = %f, B = %f, v: %f\n", discharger_cell_coef.Cb, discharger_cell_coef.Ka, get_y_by_x(&discharger_cell_coef, least_square_time));
+		int delta = get_x_by_y(&discharger_cell_coef, bms_state_get()->cell_min_vol/1000.0f) - get_x_by_y(&discharger_cell_coef, bms_health_cell_lower_voltage()/1000.0f);
+		soc_error("remain %d s to reach lower cell voltage\n", delta);
 	}
 	if (least_square_put(&discharger_capacity_coef, least_square_time, _soc.coulomb_now/3600.0f) == 1) {
 		soc_error("capacity: A = %f, B = %f, c: %f\n", discharger_capacity_coef.Cb, discharger_capacity_coef.Ka, get_y_by_x(&discharger_capacity_coef, least_square_time));
+		int delta = get_x_by_y(&discharger_capacity_coef, _soc.coulomb_now/3600.0f) - get_x_by_y(&discharger_capacity_coef, _soc.coulomb_min/3600.0f);
+		soc_error("remain %d s to reach 0 min AH\n", delta);
 	}
 	least_square_time ++;
 	shark_timer_post(&least_square_timer, LEAST_SQUARE_STEP_TIME);
@@ -278,6 +292,9 @@ void soc_update(void){
 		if (_soc.capacity < 100) {
 			is_force_full = 0;
 		}
+#if LEAST_SQUARE==1		
+		start_least_square(0);
+#endif
 		soc_warning("changed to chargering, current = %d\n", measure_value()->load_current);
 	}else if (chargering && !bms_state_get()->charging){
 		_soc.pre_discharger_coulomb = _soc.dischrger_coulomb;
@@ -289,7 +306,11 @@ void soc_update(void){
 		}
 		soc_warning("changed to dischargering, current = %d\n", measure_value()->load_current);
 	}
-
+#if LEAST_SQUARE==1	
+	if(!chargering && abs(measure_value()->load_current) >= 5000){
+		start_least_square(1);
+	}
+#endif	
 	soc_update_by_current_and_time(measure_value()->load_current, _delta_time(), pre_chargering);
 	soc_update_charger_remain_time();
 }