|
|
@@ -6,9 +6,9 @@
|
|
|
#include "libs/logger.h"
|
|
|
|
|
|
#define MAX_CURRENT_FOR_CHARGER (20*1000) //最大充电电流20A
|
|
|
-#define MIN_VOLTAGE_FOR_DISCHARGER (34 * 1000) //允许能放电的最小电压
|
|
|
-#define MIN_VOLTAGE_FOR_RECOVERY_DISCHARGER (40 * 1000) //恢复放电的最小电压
|
|
|
-#define MIN_VOLTAGE_FOR_POWER_DOWN (32 * 1000)
|
|
|
+#define MIN_VOLTAGE_FOR_DISCHARGER (2.2f * CELLS_NUM * 1000) //允许能放电的最小电压
|
|
|
+#define MIN_VOLTAGE_FOR_RECOVERY_DISCHARGER (2.3f * CELLS_NUM * 1000) //恢复放电的最小电压
|
|
|
+#define MIN_VOLTAGE_FOR_POWER_DOWN (2.1f * CELLS_NUM* 1000)
|
|
|
#define SIGLE_CELL_LOWER_DISCHARGER_VOLTAGE (1820) //最小允许的电芯放电电压 1.8v, 考虑到采样的误差取 1.82
|
|
|
#define SIGLE_CELL_MAX_CHARGER_VOLTAGE (3880)//最大允许充电电压,3.9v,考虑到采样的误差取 3.88
|
|
|
|
|
|
@@ -125,61 +125,69 @@ void check_current_state(void){
|
|
|
}
|
|
|
|
|
|
/* 检测pack电压,cell电压,pack电压过低触发powerdown*/
|
|
|
-static debounce_t _discharger_lower_voltage = {.count = 0, .max_count = 10};
|
|
|
-static debounce_t _discharger_low_normal_voltage = {.count = 0, .max_count = 10};
|
|
|
-static debounce_t _power_down_voltage = {.count = 0, .max_count = 10};
|
|
|
-static debounce_t _sigle_cell_discharger_lower_vol = {.count = 5, .max_count = 10};
|
|
|
-static debounce_t _sigle_cell_charger_max_vol = {.count = 15, .max_count = 30};
|
|
|
+static debounce_t _discharger_lower_voltage = {.count = 10, .max_count = 20, .init_count = 10};
|
|
|
+static debounce_t _power_down_voltage = {.count = 0, .max_count = 10, .init_count = 0};
|
|
|
+static debounce_t _sigle_cell_discharger_lower_vol = {.count = 5, .max_count = 10, .init_count = 5};
|
|
|
+static debounce_t _sigle_cell_charger_max_vol = {.count = 15, .max_count = 30, .init_count = 15};
|
|
|
|
|
|
void check_voltage_state(void) {
|
|
|
- if (bms_state_get()->charging){
|
|
|
- if (bms_state_get()->cell_max_vol>= SIGLE_CELL_MAX_CHARGER_VOLTAGE){
|
|
|
+ if (bms_state_get()->charging){ //check sigle cell's voltage for charger
|
|
|
+ if ((bms_state_get()->cell_max_vol>= SIGLE_CELL_MAX_CHARGER_VOLTAGE) && !_health.sigle_cell_over_voltage){
|
|
|
debounce_inc(_sigle_cell_charger_max_vol);
|
|
|
- }else {
|
|
|
+ if (debounce_reach_max(_sigle_cell_charger_max_vol)){
|
|
|
+ _health.sigle_cell_over_voltage = 1;
|
|
|
+ debounce_reset(_sigle_cell_charger_max_vol);
|
|
|
+ }
|
|
|
+ }else if ((bms_state_get()->cell_max_vol < SIGLE_CELL_MAX_CHARGER_VOLTAGE) && _health.sigle_cell_over_voltage){
|
|
|
debounce_dec(_sigle_cell_charger_max_vol);
|
|
|
+ if (debounce_reach_zero(_sigle_cell_charger_max_vol)){
|
|
|
+ _health.sigle_cell_over_voltage = 0;
|
|
|
+ debounce_reset(_sigle_cell_charger_max_vol);
|
|
|
+ }
|
|
|
}
|
|
|
- if (debounce_reach_max(_sigle_cell_charger_max_vol)){
|
|
|
- _health.sigle_cell_over_voltage = 1;
|
|
|
- }else if (debounce_reach_zero(_sigle_cell_charger_max_vol)){
|
|
|
- _health.sigle_cell_over_voltage = 0;
|
|
|
- }
|
|
|
- }else if (bms_state_get()->discharging){
|
|
|
- if (bms_state_get()->cell_min_vol <= SIGLE_CELL_LOWER_DISCHARGER_VOLTAGE){
|
|
|
+ }else{
|
|
|
+ //check sigle cell's voltage for discharger
|
|
|
+ if ((bms_state_get()->cell_min_vol <= SIGLE_CELL_LOWER_DISCHARGER_VOLTAGE) && !_health.sigle_cell_lower_voltage){
|
|
|
debounce_inc(_sigle_cell_discharger_lower_vol);
|
|
|
- }else {
|
|
|
+ if (debounce_reach_max(_sigle_cell_discharger_lower_vol)){
|
|
|
+ _health.sigle_cell_lower_voltage = 1;
|
|
|
+ debounce_reset(_sigle_cell_discharger_lower_vol);
|
|
|
+ }
|
|
|
+ }else if ((bms_state_get()->cell_min_vol > SIGLE_CELL_LOWER_DISCHARGER_VOLTAGE) && _health.sigle_cell_lower_voltage){
|
|
|
debounce_dec(_sigle_cell_discharger_lower_vol);
|
|
|
+ if (debounce_reach_zero(_sigle_cell_discharger_lower_vol)){
|
|
|
+ _health.sigle_cell_lower_voltage = 0;
|
|
|
+ debounce_reset(_sigle_cell_discharger_lower_vol);
|
|
|
+ }
|
|
|
}
|
|
|
- if (debounce_reach_max(_sigle_cell_discharger_lower_vol)){
|
|
|
- _health.sigle_cell_lower_voltage = 1;
|
|
|
- }else if (debounce_reach_zero(_sigle_cell_discharger_lower_vol)){
|
|
|
- _health.sigle_cell_lower_voltage = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- if (!_health.discharger_lower_voltage){ //check for low pack voltage for close discharger
|
|
|
- if (bms_state_get()->pack_voltage <= MIN_VOLTAGE_FOR_DISCHARGER){
|
|
|
- debounce_inc(_discharger_lower_voltage);
|
|
|
- }else {
|
|
|
- debounce_reset(_discharger_lower_voltage);
|
|
|
- }
|
|
|
- if (debounce_reach_max(_discharger_lower_voltage)){
|
|
|
- _health.discharger_lower_voltage = 1;
|
|
|
- debounce_reset(_discharger_lower_voltage);
|
|
|
- }
|
|
|
+ //check sigle pack's voltage for discharger
|
|
|
+ if (!_health.discharger_lower_voltage){ //check for low pack voltage for close discharger
|
|
|
+ if (bms_state_get()->pack_voltage <= MIN_VOLTAGE_FOR_DISCHARGER){
|
|
|
+ debounce_inc(_discharger_lower_voltage);
|
|
|
+ }else {
|
|
|
+ debounce_reset(_discharger_lower_voltage);
|
|
|
+ }
|
|
|
+ if (debounce_reach_max(_discharger_lower_voltage)){
|
|
|
+ _health.discharger_lower_voltage = 1;
|
|
|
+ debounce_reset(_discharger_lower_voltage);
|
|
|
+ }
|
|
|
|
|
|
- }else { //check for discharger recovery
|
|
|
- if (bms_state_get()->pack_voltage >= MIN_VOLTAGE_FOR_RECOVERY_DISCHARGER){
|
|
|
- debounce_inc(_discharger_low_normal_voltage);
|
|
|
- }else {
|
|
|
- debounce_reset(_discharger_low_normal_voltage);
|
|
|
- }
|
|
|
- if (debounce_reach_max(_discharger_low_normal_voltage)){
|
|
|
- _health.discharger_lower_voltage = 0;
|
|
|
- debounce_reset(_discharger_low_normal_voltage);
|
|
|
+ }else { //check for discharger recovery
|
|
|
+ if (bms_state_get()->pack_voltage >= MIN_VOLTAGE_FOR_RECOVERY_DISCHARGER){
|
|
|
+ debounce_inc(_discharger_lower_voltage);
|
|
|
+ }else {
|
|
|
+ debounce_reset(_discharger_lower_voltage);
|
|
|
+ }
|
|
|
+ if (debounce_reach_max(_discharger_lower_voltage)){
|
|
|
+ _health.discharger_lower_voltage = 0;
|
|
|
+ debounce_reset(_discharger_lower_voltage);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
/* check for power down */
|
|
|
if (!io_state()->charger_detect && !bms_state_get()->charging && !_health.powerdown_lower_voltage){
|
|
|
- if (bms_state_get()->pack_voltage >= MIN_VOLTAGE_FOR_POWER_DOWN){
|
|
|
+ if (bms_state_get()->pack_voltage <= MIN_VOLTAGE_FOR_POWER_DOWN){
|
|
|
debounce_inc(_power_down_voltage);
|
|
|
}else {
|
|
|
debounce_reset(_power_down_voltage);
|
|
|
@@ -198,12 +206,12 @@ void check_voltage_state(void) {
|
|
|
|
|
|
/* 检测温度情况,看是否过高温,或者过低温 */
|
|
|
|
|
|
-static debounce_t _charger_over_temp = {.count = 0, .max_count = 10};
|
|
|
-static debounce_t _charger_lower_temp = {.count = 0, .max_count = 10};
|
|
|
-static debounce_t _charger_normal_temp = {.count = 0, .max_count = 10};
|
|
|
-static debounce_t _discharger_over_temp = {.count = 0, .max_count = 10};
|
|
|
-static debounce_t _discharger_lower_temp = {.count = 0, .max_count = 10};
|
|
|
-static debounce_t _discharger_normal_temp = {.count = 0, .max_count = 10};
|
|
|
+static debounce_t _charger_over_temp = {.count = 0, .max_count = 10, .init_count = 0};
|
|
|
+static debounce_t _charger_lower_temp = {.count = 0, .max_count = 10, .init_count = 0};
|
|
|
+static debounce_t _charger_normal_temp = {.count = 0, .max_count = 10, .init_count = 0};
|
|
|
+static debounce_t _discharger_over_temp = {.count = 0, .max_count = 10, .init_count = 0};
|
|
|
+static debounce_t _discharger_lower_temp = {.count = 0, .max_count = 10, .init_count = 0};
|
|
|
+static debounce_t _discharger_normal_temp = {.count = 0, .max_count = 10, .init_count = 0};
|
|
|
|
|
|
static int _is_over_temp(int8_t *temps){
|
|
|
for (int i = 0; i < PACK_TEMPS_NUM; i++){
|