Преглед изворни кода

单mos打开的情况下,通过判断电流大小来决定隔多久开另外一个mos

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui пре 5 година
родитељ
комит
e18be5ab68
1 измењених фајлова са 20 додато и 7 уклоњено
  1. 20 7
      Application/app/sox/state.c

+ 20 - 7
Application/app/sox/state.c

@@ -465,8 +465,18 @@ static void check_charging(){
    we must judage the current: if current is large than 10A(-10A), 
    we must open the closed mos to avoid the closed mos to be destroyed
 */
-#define MIN_CURRENT_FOR_BOTH_MOS_OPEN (300)
+#define MIN_CURRENT_FOR_BOTH_MOS_OPEN (1000)
 static int _min_current_for_both_mos_count = 0;
+static u32 _check_mos_time = 0;
+static __INLINE u32 _open_all_mos_time(void){
+	if (abs(measure_value()->load_current) >= MIN_CURRENT_FOR_BOTH_MOS_OPEN * 2){
+		return 0;
+	}
+	if (abs(measure_value()->load_current) >= MIN_CURRENT_FOR_BOTH_MOS_OPEN) {
+		return 10;
+	}
+	return 30;
+}
 static void _check_mos_stat(void){
 	if (abs(measure_value()->load_current) >= MIN_CURRENT_FOR_BOTH_MOS_OPEN){
 		_min_current_for_both_mos_count ++;
@@ -480,13 +490,16 @@ static void _check_mos_stat(void){
 			if (dmos == 1 && cmos == 1){
 				return;
 			}
-			uint32_t request = USER_REQUEST_PENDING;
-			if (!dmos) {
-				request |= USER_REQUEST_DISCHARGER_ON;
-			}else {
-				request |= USER_REQUEST_CHARGER_ON;
+			if (shark_get_seconds() >= (_check_mos_time + _open_all_mos_time())) {
+				uint32_t request = USER_REQUEST_PENDING;
+				if (!dmos) {
+					request |= USER_REQUEST_DISCHARGER_ON;
+				}else {
+					request |= USER_REQUEST_CHARGER_ON;
+				}
+				_bms_state.user_request = request;
+				_check_mos_time = shark_get_seconds();
 			}
-			_bms_state.user_request = request;
 		}
 	}else {
 		_min_current_for_both_mos_count = 0;