瀏覽代碼

电压采集和电流采集分开,接近电压保护点的时候,需要加快电压采集

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 4 年之前
父節點
當前提交
423fe71c96
共有 3 個文件被更改,包括 66 次插入23 次删除
  1. 3 3
      Application/app/sox/health.c
  2. 61 20
      Application/app/sox/measure_task.c
  3. 2 0
      Application/app/sox/measure_task.h

+ 3 - 3
Application/app/sox/health.c

@@ -202,11 +202,11 @@ void check_current_state(void){
 
 /* 检测pack电压,cell电压,pack电压过低触发powerdown*/
 static debounce_t _discharger_lower_voltage = {.count = 0, .max_count = 200, .init_count = 0};
-static debounce_t _power_down_voltage = {.count = 0, .max_count = 20, .init_count = 0};
+static debounce_t _power_down_voltage = {.count = 0, .max_count = 400, .init_count = 0};
 static debounce_t _sigle_cell_discharger_lower_vol = {.count = 0, .max_count = 200, .init_count = 0};
-static debounce_t _sigle_cell_charger_max_vol = {.count = 0, .max_count = 50, .init_count = 0};
+static debounce_t _sigle_cell_charger_max_vol = {.count = 0, .max_count = 200, .init_count = 0};
 static debounce_t _shut_discharger_lower_voltage = {.count = 0, .max_count = 20,.init_count = 0};
-static debounce_t _shut_discharger_cell_lower_voltage = {.count = 0, .max_count = 400,.init_count = 0};
+static debounce_t _shut_discharger_cell_lower_voltage = {.count = 0, .max_count = 20,.init_count = 0};
 
 static int judge_debounce(int input, debounce_t *d){
 	if (input) {

+ 61 - 20
Application/app/sox/measure_task.c

@@ -19,7 +19,8 @@ struct means_task {
 	u8  index;
 };
 
-static void init_current_voltage_task(void);
+static void init_current_task(void);
+static void init_voltage_task(void);
 static void init_temp_task(void);
 
 void measure_task_init(measure_notify cn, measure_notify vn, measure_notify tn){
@@ -27,7 +28,8 @@ void measure_task_init(measure_notify cn, measure_notify vn, measure_notify tn){
 	_voltage_notify = vn;
 	_temperature_notify = tn;
 	measure_adc_init();
-	init_current_voltage_task();
+	init_current_task();
+	init_voltage_task();
 	init_temp_task();
 	set_log_level(MOD_MEASURE, L_debug);
 }
@@ -46,40 +48,79 @@ void measure_log(void){
 /*
  * 测量电芯电压,计算出总电压, 测量总电流,放电和充电
 */
-static struct means_task _current_voltage_task;
-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 = 25;
-	_current_voltage_task.index = CELLS_NUM;
+static struct means_task _current_task;
+static struct means_task _voltage_task;
+
+static u32 current_task_handler(void);
+static u32 voltage_task_handler(void);
+static void init_current_task(void){
+	_current_task._task.handler = current_task_handler;
+	_current_task.delay = 25;
 	_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);
-	}
-	shark_task_add(&_current_voltage_task._task);
+
+	shark_task_add(&_current_task._task);
 }
 
-static u32 current_voltage_task_handler(void){
+static u32 current_task_handler(void){
 	if (bms_work_is_calibrating()){
-		return _current_voltage_task.delay;
+		return _current_task.delay;
 	}
 	/* 测量电流 */
 	_measure_value.load_current = get_pack_current(&_measure_value.current_5238);
 	_current_notify();//通知bms state 有新的电流数据
 
+	if (abs(_measure_value.load_current) >= MIN_CURRENT_FOR_CS1180) {
+		return 5;
+	}
+	return _current_task.delay;
+}
+
+static void init_voltage_task(void){
+	_voltage_task._task.handler = voltage_task_handler;
+	_voltage_task.delay = 50;
+	_voltage_task.index = CELLS_NUM;
+	_measure_value.min_vol = 10000;
+	_measure_value.max_vol = 0;
+	for (int i = 0; i < CELLS_NUM; i++){
+		_measure_value.cell_vol[i] = get_cell_voltage(i);
+		if (_measure_value.cell_vol[i] > _measure_value.max_vol) {
+			_measure_value.max_vol = _measure_value.cell_vol[i];
+		}
+		if (_measure_value.cell_vol[i] < _measure_value.min_vol) {
+			_measure_value.min_vol = _measure_value.cell_vol[i];
+		}		
+	}
+	shark_task_add(&_voltage_task._task);
+}
+
+static u32 voltage_task_handler(void){
+	if (bms_work_is_calibrating()){
+		return _voltage_task.delay;
+	}
+
 	if (bms_state_get()->pack_balancing){ //if balance, do'nt sample cell voltage
-		return _current_voltage_task.delay;
+		return _voltage_task.delay;
 	}	
 	//用内阻对cell的电压进行补偿,充电减,放电加
-	_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_task.index = (_voltage_task.index + 1) % CELLS_NUM;
+	_measure_value.cell_vol[_voltage_task.index] = get_cell_voltage(_voltage_task.index) - bms_health()->internal_resistance[_voltage_task.index] * _measure_value.load_current/1000;
+	if (_measure_value.cell_vol[_voltage_task.index] > _measure_value.max_vol) {
+		_measure_value.max_vol = _measure_value.cell_vol[_voltage_task.index];
+	}
+	if (_measure_value.cell_vol[_voltage_task.index] < _measure_value.min_vol) {
+		_measure_value.min_vol = _measure_value.cell_vol[_voltage_task.index];
+	}
 	_voltage_notify();//通知bms state 有新的电压数据
-	if (abs(_measure_value.load_current) >= MIN_CURRENT_FOR_CS1180) {
-		return 5;
+	//接近过压或者欠压,加快采集速度
+	if ((_measure_value.min_vol < 2300) || (_measure_value.max_vol > 3600)) {
+		if (abs(_measure_value.load_current) >= MIN_CURRENT_FOR_CS1180){
+			return 5;
+		}
 	}
-	return _current_voltage_task.delay;
+	return _voltage_task.delay;
 }
 
+
 /*
  * 测量4个温度
 */

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

@@ -8,6 +8,8 @@ typedef struct{
 	int current_5238;
 	int      pack_temp[PACK_TEMPS_NUM];
 	uint16_t cell_vol[CELLS_NUM]; //mV
+	uint16_t min_vol;
+	uint16_t max_vol;
 }measure_value_t;
 typedef void (*measure_notify)(void);