|
@@ -480,22 +480,30 @@ static u32 _bms_main_task_handler(void){
|
|
|
extern void show_leds_for_charging(uint8_t charging);
|
|
extern void show_leds_for_charging(uint8_t charging);
|
|
|
static debounce_t _charging_detect = {.count = 0, .max_count = 10, .init_count = 0};
|
|
static debounce_t _charging_detect = {.count = 0, .max_count = 10, .init_count = 0};
|
|
|
static int cs1180_may_error_count = 0;
|
|
static int cs1180_may_error_count = 0;
|
|
|
|
|
+static bool _cs1180_may_error(void) {
|
|
|
|
|
+ //cs1180 not working
|
|
|
|
|
+ if (measure_value()->load_current == measure_value()->current_5238) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ //cs1180检测到充电电流,5238检测到负电流
|
|
|
|
|
+ if ((measure_value()->load_current >= MIN_START_CHARGER_CURRENT) && (measure_value()->current_5238 <= 0)) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ //cs1180 和 5238的测量电流差超过阈值
|
|
|
|
|
+ if (abs(measure_value()->load_current - measure_value()->current_5238) >= MIN_DIFF_BT_5238_1180) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+}
|
|
|
static void check_charging(){
|
|
static void check_charging(){
|
|
|
/* 解决cs1180可能出错,导致误判充电,离仓后无法休眠 */
|
|
/* 解决cs1180可能出错,导致误判充电,离仓后无法休眠 */
|
|
|
- int may_error = 0;
|
|
|
|
|
- if (measure_value()->load_current >= MIN_START_CHARGER_CURRENT) {
|
|
|
|
|
- if (measure_value()->load_current != measure_value()->current_5238) {
|
|
|
|
|
- if (measure_value()->current_5238 <= 0) { //cs1180检测到充电电流,5238检测到负电流
|
|
|
|
|
- if (++cs1180_may_error_count >= _charging_detect.max_count/2) {
|
|
|
|
|
- measure_value()->load_current = measure_value()->current_5238;
|
|
|
|
|
- cs1180_adc_shutdown();
|
|
|
|
|
- cs1180_may_error_count = 0;
|
|
|
|
|
- }
|
|
|
|
|
- may_error = 1;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (_cs1180_may_error()) {
|
|
|
|
|
+ if (++cs1180_may_error_count >= _charging_detect.max_count/2) {
|
|
|
|
|
+ measure_value()->load_current = measure_value()->current_5238;
|
|
|
|
|
+ cs1180_adc_shutdown();
|
|
|
|
|
+ cs1180_may_error_count = 0;
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- if (may_error == 0) {
|
|
|
|
|
|
|
+ }else {
|
|
|
cs1180_may_error_count = 0;
|
|
cs1180_may_error_count = 0;
|
|
|
}
|
|
}
|
|
|
if ((measure_value()->load_current >= MIN_START_CHARGER_CURRENT)) {
|
|
if ((measure_value()->load_current >= MIN_START_CHARGER_CURRENT)) {
|