Compare commits

...

21 Commits
master ... wk

Author SHA1 Message Date
ahu_gq 83b4133c68 Merge branch 'wk' of http://47.120.14.45:3000/Bluesun/BCU into wk 2025-03-02 15:50:49 +08:00
guzz c2cceee9df bcu function is basiclly ok 2025-03-01 16:55:37 +08:00
guzz da3aca4948 bcu功能基本ok 2025-03-01 16:53:28 +08:00
guzz 6b4089ed1e bcu功能基本ok 2025-03-01 16:33:40 +08:00
guzz a6ddf7f43d 注释了反馈异常中dly加base_time的条件 2025-02-25 15:48:49 +08:00
guzz 25aaac1080 4000modbus 2025-02-25 14:58:14 +08:00
guzz 091a70874e 4000多地址增加连续可写的功能 2025-02-25 10:24:49 +08:00
guzz ed4c22e628 除了分流器部分,soctmp计算少除100,电量计算多除100 2025-02-20 11:17:24 +08:00
guzz b4ce65176d 高压采集问题解决 2025-02-15 19:57:30 +08:00
guzz f02582475f 提交测试 2025-02-15 08:21:45 +08:00
guzz de4f10aaf2 单体温感排线错误故障 2025-02-12 15:02:26 +08:00
guzz 0375e81dd6 更改dido枚举 2025-02-10 16:45:06 +08:00
guzz 75158d3bf3 Merge branch 'gary' into wk 2025-02-10 16:15:54 +08:00
guzz 61a91657bd 1 2025-02-10 16:15:29 +08:00
ahu_gq 7624dbe183 解决ADS1818官方示例错误 2025-02-09 17:04:22 +08:00
ahu_gq 8470d2c41a Merge branch 'master' into gary 2025-02-09 16:34:37 +08:00
ahu_gq a3d5cc58b5 添加忽略 2025-02-09 16:30:51 +08:00
ahu_gq de38f54c76 添加忽略 2025-02-09 16:29:24 +08:00
guzz 9920f30203 提交测试 2025-02-09 10:53:08 +08:00
ahu_gq 1f0cef7f45 Merge branch 'master' into gary 2025-02-09 10:31:55 +08:00
ahu_gq 803b34c34e Merge branch 'master' into gary 2025-02-06 15:26:32 +08:00
28 changed files with 1143817 additions and 427329 deletions

3
.gitignore vendored
View File

@ -5,6 +5,8 @@
*.rpt
*.plg
*.uvgui.*
*.uvprojx
*.uv*
*.crf
*.map
*.hex
@ -12,6 +14,7 @@
*.o
*.s19
*.dbgconf
*.uv*
# 忽略编译器输出目录(如果您有自定义的输出目录)
Objects/
Listings/

View File

@ -102,8 +102,8 @@ void bmu_config_init(void)
drv_gpio_set_pin_status(kGpioType_SP1_Cs_En2, kGpioStatus_Low);
//drv_gpio_set_pin_status(kGpioType_SP1_Cs_En1, kGpioStatus_Low);
//bmu_data.bmu_num = get_eeprom_data(kEep_DevAddr_SlaverNum, kEepromDataType_Low);
bmu_data.bmu_num = 2;
bmu_data.bmu_num = get_eeprom_data(kEep_DevAddr_SlaverNum, kEepromDataType_Low);
//bmu_data.bmu_num = 1;
if (bmu_data.bmu_num > BMU_MAX_NUM || bmu_data.bmu_num == 0)
{
bmu_data.bmu_num = BMU_MAX_NUM;
@ -112,11 +112,11 @@ void bmu_config_init(void)
bmu_data.bmu_ic_num = get_eeprom_data(kEep_AfeNum_CellNum, kEepromDataType_High);
bmu_data.total_ic_num = bmu_data.bmu_num * bmu_data.bmu_ic_num;
bmu_data.ic = bsp_adbms1818_global();
//bmu_data.total_cell_num = get_eeprom_data(kEep_CellNum, kEepromDataType_Full);
//bmu_data.total_temp_num = get_eeprom_data(kEep_TempNum, kEepromDataType_Full);
bmu_data.total_cell_num = get_eeprom_data(kEep_CellNum, kEepromDataType_Full);
bmu_data.total_temp_num = get_eeprom_data(kEep_TempNum, kEepromDataType_Full);
bmu_data.total_cell_num = 32;
bmu_data.total_temp_num = 18;
//bmu_data.total_cell_num = 16;
//bmu_data.total_temp_num = 8;
//set num from hmi =>adapt num for furture
cell_num = bmu_data.total_cell_num / bmu_data.bmu_num;
@ -240,14 +240,21 @@ void bmu_vlot_breakline_check()
}
static int tempJudge_cnt[26][9] = {0};
//static int tempCellErr_cnt = 0;
//@wkun the here can add temp line break or connect
void bmu_temp_breakline_check()
void bmu_temp_breakline_check(int value, int bmuIdx, int tempIdx)
{
//核心逻辑是通过每个bmu中的温度是否大于60000来确定温感排线是否有问题通过for循环然后将故障塞入kFaultCode_TempCable对应的故障中
//bms_get_bmu_fault_bit(kBmuFaultBit_TempCable)将这个接口中的数据如果有则置1否则为0
if (value > 6000)
{
tempJudge_cnt[bmuIdx][tempIdx]++;
}
if(tempJudge_cnt[bmuIdx][tempIdx] > 1)
{
//bms_set_bmu_fault_bit(kBmuFaultBit_TempCable, 1);
}
}
@ -361,7 +368,7 @@ static void bmu_statistic_cell_temp(uint16_t bmuIdx)
void bmu_data_handler(uint32_t base_time)
{
uint8_t bmuIdx = 0,cellIdx = 0,_cellIdx = 0,_bmuIdx = 0,_ntcIdx = 0;
uint16_t current = 0,load = 0;
uint16_t current = 0,load = 0, tempJudge = 0;
//calc cell volt
for(bmuIdx = 0;bmuIdx < bmu_data.total_ic_num;bmuIdx++)
{
@ -388,7 +395,9 @@ void bmu_data_handler(uint32_t base_time)
current = 1;
}
load = (bmu_data.ic[bmuIdx].aux.a_codes[_ntcIdx] / 10) * 1000 / current; //修订索引错误
bmu_data.bmu_unit[bmuIdx].cell_temp_buf[cellIdx] = (bms_get_linear_temp(load, kNtcType_CWFH708_H713) - 500) / 10;
tempJudge = (bms_get_linear_temp(load, kNtcType_CWFH708_H713) - 500) / 10;
bmu_data.bmu_unit[bmuIdx].cell_temp_buf[cellIdx] = tempJudge;
bmu_temp_breakline_check(tempJudge, bmuIdx, _ntcIdx);
}
//统计温度
bmu_statistic_cell_temp(bmuIdx);
@ -396,7 +405,6 @@ void bmu_data_handler(uint32_t base_time)
//alarm monitor
//bmu_comm_offline_check(base_time);
bmu_vlot_breakline_check();
bmu_temp_breakline_check();
}
@ -418,6 +426,8 @@ void bms_bmu_init()
}
void bms_poll_bmu(uint32_t base_time)
{
//Automatic Recognition
@ -435,10 +445,15 @@ void bms_poll_bmu(uint32_t base_time)
run_command(6,bmu_data.bmu_num*bmu_data.bmu_ic_num);
bmu_data_handler(base_time);
//温感检测是否脱落加上了防抖需要两次大于6000才设置温感排线错误温感排线错误显示的有点慢
//温感的值最开始全是大于6000的第二次才是采集值
memset(tempJudge_cnt, 0, sizeof(tempJudge_cnt));
//2-5 @wangk add this line bcu statistic data is show
bms_poll_statistic(0);
//2-6 @wangk
bms_poll_run_status(base_time);
//2-10 @wangk
task_dido_ctrl_handle(1000);
}

View File

@ -19,6 +19,10 @@ extern "C" {
//2-6
#include "statistic_manager.h"
#include "run_status.h"
#include "logic_ctrl.h"
#include "bmu_manager.h"
#include "string.h"
#include "stdio.h"
typedef struct
{

View File

@ -195,7 +195,8 @@ void bms_force_crtl_do_status(uint8_t idx, DoCtrlStatus status)
if(status < kDoCtrlStatus_None)
{
do_item.tick[idx] = RELAY_CTRL_NO_DLY;
do_item.ctrl_status[idx] = (DoStatus)(status + 2);
//@wagnk2-17这里原本的status加了2取消了
do_item.ctrl_status[idx] = (DoStatus)(status);
}
else
{
@ -225,7 +226,7 @@ const GpioStatus relay_status_to_ctrl[kDoStatus_End] ={kGpioStatus_Low, kGpioSta
void bms_poll_di_do(uint32_t base_time)
{
uint32_t i;
uint32_t i,j = 0;
DoStatus rly_st;
if(do_item.bmsCircuitCtrl != NULL)
@ -247,6 +248,10 @@ void bms_poll_di_do(uint32_t base_time)
do_item.tick[i] = 0;
rly_st = do_item.ctrl_status[i];
do_item.actual_status[i] = rly_st;
if((relay_status_to_ctrl[rly_st] == kGpioStatus_Low) && (i == 1))
{
j = 1;
}
drv_gpio_set_pin_status(do_item.relay_start_io + i, relay_status_to_ctrl[rly_st]);
}
else

View File

@ -37,9 +37,9 @@ typedef enum
{
kDoType_Start = 0,
kDoType_Unused = kDoType_Start,
kDoType_Chg,
kDoType_Dis,
kDoType_PreChg, //3
kDoType_PreChg,
kDoType_Chg,
kDoType_Dis,//3
kDoType_Positive, //4
kDoType_Negative,//5
kDoType_Cool,
@ -84,6 +84,8 @@ typedef enum
kDiType_Start = 0,
kDiType_Unused= kDiType_Start,
kDiType_FireAlarm1, //消防1
kDiType_FireAlarm2,
kDiType_FireAlarm3,
kDiType_EmergStop1, //急停
kDiType_Do1Feedback,
kDiType_Do2Feedback,

View File

@ -14,7 +14,8 @@
#include "drv_ads8688.h"
#define CUR_FILTER_ENABLE (0u)
#define ADCIC_SAMPLE_CNT (4u)
#define ADCIC_SAMPLE_CNT (20u)
#define MCP3208_SAMPLE_CNT (10u)
ADS8688_STATIC_INIT(ads8688, kSpiDev_2, kGpioType_ADC_Cs);
@ -83,7 +84,7 @@ void bms_init_current(void)
cur_item.shunt_volt = get_eeprom_data(kEep_ChgCurDir_ShuntRatedVolt, kEepromDataType_Low);
cur_item.prop[0].filter = cur_item.prop[1].filter = 0;
// 上位机下发时缩小10倍
// 上位机下发时缩小10倍,分流器量程 乘了 10
cur_item.prop[0].scale = get_eeprom_data(kEep_CurSensor2_1Range, kEepromDataType_Low) * 10;
cur_item.prop[1].scale = get_eeprom_data(kEep_CurSensor2_1Range, kEepromDataType_High) * 10;
@ -191,12 +192,12 @@ int16_t bms_caculate_current(uint32_t base_time)
if (cur_item.channel < kCurChannel_End)
{
prop = &cur_item.prop[cur_item.channel];
switch (prop->type)
switch (prop->type)
{
case kCurSensor_Shunt:
// 分流器 cur_hv_item.cur_volt_avg / cur_prop.shunt_volt * cur_prop.cur_scale;
//current = (int32_t)cur_hv_item.value[kAdIc_Cur] * prop->scale / cur_item.shunt_volt;
current = HighResCurTrans(cur_hv_item.value[kAdIc_Cur]);
current = (int32_t)cur_hv_item.value[kAdIc_Cur] * prop->scale / cur_item.shunt_volt;
//current = HighResCurTrans(cur_hv_item.value[kAdIc_Cur]);
break;
case kCurSensor_SigHall:
// 霍尔电流
@ -229,8 +230,8 @@ int16_t bms_caculate_current(uint32_t base_time)
break;
}
}
//测试用 SFJ 7.30
current = volval * 100 / 10;
//测试用 SFJ 7.30,2-18,注释
//current = volval * 100 / 10;
// 电流方向
current *= prop->dir;
@ -282,26 +283,70 @@ uint32_t HighVolTrans(uint16_t voldata)
AdjustValue adIc_adjust_value[kAdIc_End];
uint16_t adIc_reg_map[kAdIc_End] = {MAN_Ch_0, MAN_Ch_1, MAN_Ch_2, MAN_Ch_3, MAN_Ch_4};
uint16_t zero_calc(uint16_t value)
{
if(value > 32700 && value < 32788)
{
return 0;
}
else if(value < 20)
{
return 0;
}
else
{
return value;
}
}
void get_ad_sample(void)
{
static uint16_t outputdata[16] = {0};
int32_t i =0;
uint16_t ad =0;
int32_t i =0,dir = 1;
//uint16_t ad =0;
uint16_t ad = 0,value = 0;
#if ADC_AUTO_MODE
//auto scan mode
drv_enter_auto_rst_mode_Data(outputdata, 6);
#else
//auto scan mode
drv_enter_auto_rst_mode_Data(outputdata, 6);
outputdata[i] = drv_get_ads8688_ch_data(MAN_Ch_0);
i += 1;
outputdata[i] = drv_get_ads8688_ch_data(MAN_Ch_1);
i += 1;
outputdata[i] = drv_get_ads8688_ch_data(MAN_Ch_2);
i += 1;
outputdata[i] = drv_get_ads8688_ch_data(MAN_Ch_3);
i += 1;
outputdata[i] = drv_get_ads8688_ch_data(MAN_Ch_4);
i += 1;
outputdata[i] = drv_get_ads8688_ch_data(MAN_Ch_5);
i += 1;
#endif
for (i = 0; i < kAdIc_End; i++)
{
//ad = drv_get_ads8688_ch_data(adIc_reg_map[i]);
//0漂处理
if(i == kAdIc_Cur)
{
outputdata[i] = zero_calc(outputdata[i]);
}
cur_hv_item.ad_buf[i][cur_hv_item.ad_buf_pos[i]++] = drv_ads8688_value(outputdata[i]);
ad = cur_hv_item.ad_avg[i] = kit_get_int32_avg_filter_max_min(cur_hv_item.ad_buf[i], ADCIC_SAMPLE_CNT);
cur_hv_item.ad_avg[i] = kit_get_int32_avg_filter_max_min(cur_hv_item.ad_buf[i], ADCIC_SAMPLE_CNT);
if(cur_hv_item.ad_avg[i] < 0)
{
dir = -1;
}
ad = KIT_ABS(cur_hv_item.ad_avg[i]);
if (i == kAdIc_HvIso)
{
//cur_hv_item.value[i] = HighVolTrans2(ad)/100;
bms_set_iso_volt_ad(kIsoVolt_Other, ad);
bms_set_iso_volt_ad(kIsoVolt_Other, dir * ad);
}
if(i == kAdIc_HvIsoNagtive)
{
@ -309,24 +354,26 @@ void get_ad_sample(void)
}
if (i == kAdIc_HvBat)
{
cur_hv_item.value[i] = (ad / 100) * 512 * 10 / (0x01 << 16); //单位是mv
cur_hv_item.value[i] = dir * (376 * ad * 512 * 10 / (0x01 << 15)) / 100; //单位是mv
bms_set_iso_volt_ad(kIsoVolt_TotalVolt, cur_hv_item.value[i]);
}
if(i == kAdIc_Hv1)
{
cur_hv_item.value[i] = (ad / 100) * 512 * 10 / (0x01 << 16); //单位是mv
cur_hv_item.value[i] = dir * (376 * ad * 512 * 10 / (0x01 << 15)) / 100; //单位是mv
}
if(i == kAdIc_Cur)
{
ad = ad - adIc_adjust_value[i].zero;
ad = (10 * ad / 82000) * 512 * 1000/ (0x01 << 16); //单位是mv
//ad = ad - adIc_adjust_value[i].zero;
//ad = (ad * 5120 * 10 / (0x01 << 15)) / 82; //单位是mv
ad = (ad * 2560 * 10 * 100 / (0x01 << 15)) / 82; //单位是0.1 mv
// 防止eeprom中没有设置电压校准系数
if (get_eeprom_data(kEep_Volt1CalFactor, kEepromDataType_Full) <= 900 || get_eeprom_data(kEep_Volt1CalFactor, kEepromDataType_Full) >= 1100)
{
bsp_eeprom_save_data(kEep_Volt1CalFactor, 1000, kEepromDataType_Full);
}
cur_hv_item.value[i] = ad / 1000 * adIc_adjust_value[i].rate *get_eeprom_data(kEep_Volt1CalFactor, kEepromDataType_Full) / 1000;//转为V
cur_hv_item.value[i] = ad * dir;/// 1000 * adIc_adjust_value[i].rate *get_eeprom_data(kEep_Volt1CalFactor, kEepromDataType_Full) / 1000;//转为V
}
if (cur_hv_item.ad_buf_pos[i] >= ADCIC_SAMPLE_CNT)
@ -432,10 +479,12 @@ const uint32_t adIc_default_rate[kAdIc_End] = {1, 1, 1, 1, 1};
//
void bms_init_cur_hv(void)
{
static uint8_t errcnt = 0;
uint32_t i = 0, cnt = 30;
#ifdef ADS_8688_EN
while(drv_ads8688_Init())
while(drv_ads8688_Init() && errcnt < 30)
{
errcnt++;
OSTimeDly(20);
}

View File

@ -13,10 +13,8 @@ extern "C" {
typedef enum
{
kHvType_Iso,
kHvType_Bat,
kHvType_Hv1,
kHvType_Hv2,
kHvType_Bat,
kHvType_End,
}HvType;

View File

@ -17,15 +17,18 @@ DiParamItem di_param_item[kDiType_End];
//辅助触点1
//di_signal->di_item.status, di->di_iteml.type
void ord_di_do_feedback_func(uint32_t base_time, DiStatus di_signal, DiType di)
{
if(di < kDiType_End)
{
if(bms_get_do_status_by_idx(di - kDiType_Do1Feedback) != di_signal)
{
di_param_item[di].dly += base_time;
//I don't know what's the meaning of this line.Whatever I change the 5000 to what , it is always enter the " if " and set the fault level.
//di_param_item[di].dly += base_time;
if(di_param_item[di].dly >= 5000)
{
//这里会写进错误--反馈异常,这里的一级代表三级错误
bms_set_fault_level(kFaultCode_Feedback, kFaultLevel_First, kFaultHandle_AlarmIdx);
}
}
@ -93,8 +96,9 @@ void ord_di_breaker1_fun(uint32_t base_time, DiStatus di_signal, DiType di)
{
if((di < kDiType_End) && (di_signal == kDiStatus_Trigger))
{
//这里会写进错误--反馈异常,这里的三级代表一级错误
di_param_item[di].dly += base_time;
bms_set_fault_level(kFaultCode_Feedback, kFaultLevel_Third, kFaultHandle_CutNoRelIdx);
bms_set_fault_level(kFaultCode_Feedback, kFaultLevel_Third, kFaultHandle_CutNoRelIdx);
}
}

View File

@ -92,7 +92,7 @@ bool logic_adhesion_check(uint32_t base_time, DoType type)
void logic_open_check(uint32_t base_time)
{
uint16_t tv, hv, rate;
DoErrSrc do_err_src = bms_get_do_err_src(kDoType_Positive);
DoErrSrc do_err_src = bms_get_do_err_src(kDoType_Chg);
FaultLevel fault = kFaultLevel_Normal;
static uint16_t dly;
@ -161,8 +161,8 @@ void logic_same_circuit_ctrl(uint32_t base_time)
//kEep_IsSoftReset高低只能清楚一个否则断电下带无法保存0
if(((bms_get_run_status() != kRunStatus_Init) && (bms_get_circuit_cmd_status() == kCircuitStatus_On)) || (dly >= 10000))
{
bms_crtl_do_status(kDoType_Positive, kDoCtrlStatus_On, RELAY_CTRL_NO_DLY);
bms_crtl_do_status(kDoType_Negative, kDoCtrlStatus_On, 100);
bms_crtl_do_status(kDoType_Chg, kDoCtrlStatus_On, RELAY_CTRL_NO_DLY);
bms_crtl_do_status(kDoType_Dis, kDoCtrlStatus_On, 100);
dly = 0;
status = kDoLogicStatus_On;
}
@ -177,7 +177,7 @@ void logic_same_circuit_ctrl(uint32_t base_time)
//增加init状态防止预充中反复检测粘连 建议增加多次检测
//Gary 2024-07-25 连续粘连3秒才报粘连故障
dly += base_time;
if(logic_adhesion_check(base_time, kDoType_Positive) == true)
if(logic_adhesion_check(base_time, kDoType_Chg) == true)
{
dly = 0;
status = kDoLogicStatus_Off;
@ -189,22 +189,22 @@ void logic_same_circuit_ctrl(uint32_t base_time)
if (prechg_max_cnt == 0) //读取配置:不预充
{
status = kDoLogicStatus_On;
bms_crtl_do_status(kDoType_Negative, kDoCtrlStatus_On, RELAY_CTRL_NO_DLY);
bms_crtl_do_status(kDoType_Positive, kDoCtrlStatus_On, 100);
bms_crtl_do_status(kDoType_Dis, kDoCtrlStatus_On, RELAY_CTRL_NO_DLY);
bms_crtl_do_status(kDoType_Chg, kDoCtrlStatus_On, 100);
}
else //读取配置:预充
{
if (prechg_cnt++ < prechg_max_cnt) //判断预充次数
{
status = kDoLogicStatus_Prechg;
//bms_crtl_do_status(kDoType_Positive, kDoCtrlStatus_On, RELAY_CTRL_NO_DLY); //闭合总正继电器
bms_crtl_do_status(kDoType_Negative, kDoCtrlStatus_On, RELAY_CTRL_NO_DLY);
//bms_crtl_do_status(kDoType_Chg, kDoCtrlStatus_On, RELAY_CTRL_NO_DLY); //闭合总正继电器
bms_crtl_do_status(kDoType_Dis, kDoCtrlStatus_On, RELAY_CTRL_NO_DLY);
bms_crtl_do_status(kDoType_PreChg, kDoCtrlStatus_On, 100);
}
else
{
bms_crtl_do_status(kDoType_Negative, kDoCtrlStatus_Off, 100);
bms_crtl_do_status(kDoType_Dis, kDoCtrlStatus_Off, 100);
bms_set_fault_level(kFaultCode_PreChg, kFaultLevel_Third, kFaultHandle_CutNoRelIdx);
}
}
@ -217,7 +217,7 @@ void logic_same_circuit_ctrl(uint32_t base_time)
prechg_cnt = 0;
status = kDoLogicStatus_Off;
bms_crtl_do_status(kDoType_PreChg, kDoCtrlStatus_Off, RELAY_CTRL_NO_DLY);
bms_crtl_do_status(kDoType_Negative, kDoCtrlStatus_Off, 100);
bms_crtl_do_status(kDoType_Dis, kDoCtrlStatus_Off, 100);
}
else if (dly >= prechg_time)//预充超时
{
@ -237,7 +237,7 @@ void logic_same_circuit_ctrl(uint32_t base_time)
dly = 0;
prechg_cnt = 0;
status = kDoLogicStatus_On;
bms_crtl_do_status(kDoType_Positive, kDoCtrlStatus_On, RELAY_CTRL_NO_DLY); //闭合总正继电器
bms_crtl_do_status(kDoType_Chg, kDoCtrlStatus_On, RELAY_CTRL_NO_DLY); //闭合总正继电器
bms_crtl_do_status(kDoType_PreChg, kDoCtrlStatus_Off, 500); //延时500ms断开预充继电器
}
}
@ -271,8 +271,8 @@ void logic_same_circuit_ctrl(uint32_t base_time)
{
dly = 0;
status = kDoLogicStatus_WaitAdhesion;
bms_crtl_do_status(kDoType_Positive, kDoCtrlStatus_Off, RELAY_CTRL_NO_DLY);
bms_crtl_do_status(kDoType_Negative, kDoCtrlStatus_Off, 100);
bms_crtl_do_status(kDoType_Chg, kDoCtrlStatus_Off, RELAY_CTRL_NO_DLY);
bms_crtl_do_status(kDoType_Dis, kDoCtrlStatus_Off, 100);
}
break;
case kDoLogicStatus_WaitAdhesion:
@ -296,8 +296,8 @@ void logic_same_circuit_poll(uint32_t base_time, uint8_t idx)
CircuitStatus circuit_st = kCircuitStatus_On;
logic_same_circuit_ctrl(base_time);
pos_rly_st = bms_get_do_status_by_type(kDoType_Positive);
neg_rly_st = (bms_is_do_config(kDoType_Negative) == true) ? bms_get_do_status_by_type(kDoType_Negative) : kDoStatus_On;
pos_rly_st = bms_get_do_status_by_type(kDoType_Chg);
neg_rly_st = (bms_is_do_config(kDoType_Dis) == true) ? bms_get_do_status_by_type(kDoType_Dis) : kDoStatus_On;
//neg_rly_st = kDoStatus_On;
if(((pos_rly_st != kDoStatus_On) && (pos_rly_st != kDoStatus_ForceOn))

View File

@ -4,6 +4,7 @@
* @brief TaskEntry
* @version V1.0.0
* @remark
* @date 20250209
* @copyright
******************************************************************************/
#include "task_register.h"

View File

@ -149,7 +149,7 @@ bool bms_is_chg_circuit_allow(void)
res = (bms_get_main_ctrl_strategy() == kDoCtrlStrategy_DiffCircuit) ? (run_item.run_status == kRunStatus_Chg) : (run_item.run_status != kRunStatus_Init);
if((res != true) || (bms_get_fault_relay_off_bit_by_status(kRunStatus_Chg) != 0)
|| (bms_get_signal(kSignalIdx_LowVoltSleep) == kSignalStatus_High)|| (bms_get_signal(kSignalIdx_StandbySleep) == kSignalStatus_High))
{
{
res = false;
}
return res;

View File

@ -146,8 +146,8 @@ uint16_t soh_init(uint16_t cycle, uint32_t dis_cap, uint32_t charge_cap)
{
uint16_t soh_loss1 = 0; //充放电次数计算出的SOH损耗百分比
uint16_t soh_loss2 = 0; //累计放电安时计算出的SOH损耗百分比
uint32_t rated_cap = get_eeprom_data(kEep_RatedCapacity, kEepromDataType_Full);
uint16_t cycle_70 = get_eeprom_data(kEep_SOHSeventyCycle, kEepromDataType_Full);
uint32_t rated_cap = get_eeprom_data(kEep_RatedCapacity, kEepromDataType_Full); //2800
uint16_t cycle_70 = get_eeprom_data(kEep_SOHSeventyCycle, kEepromDataType_Full);//3000
if(cycle <= 10)
{
@ -207,7 +207,7 @@ void cap_data_update(uint16_t base_time)
if (run_status == kRunStatus_Chg)
{
chg_dly += KIT_SECOND_CONVERT(1);
if(chg_dly >= KIT_MINUTE_CONVERT(6))
if(chg_dly >= KIT_MINUTE_CONVERT(6))//
{
chg_dly -= KIT_MINUTE_CONVERT(6);
@ -303,7 +303,7 @@ void soc_run_calibrate(int16_t current, uint16_t base_time)
static uint16_t dis_dly = 0;
static uint16_t chg_dly = 0;
uint8_t temp = 0;
//放电
if((current < 0) && (sox_item.dis_adjust_flag == false) &&
(bms_get_statistic_data(kStatisticData_MinVolt) <= 3000) &&
@ -368,11 +368,11 @@ void soc_exterme_calibrate(int16_t current, uint16_t base_time)
{
case kSocAdjustStep_Wait:
avg_volt = bms_get_statistic_data(kStatisticData_AvgVolt);
total_volt = bms_get_statistic_data(kStatisticData_AccVolt) / 100;
total_volt = bms_get_statistic_data(kStatisticData_AccVolt)/ 100;
if (((bms_get_statistic_data(kStatisticData_MinVolt) <= get_eeprom_data(kEep_FullDisVolt, kEepromDataType_Full))
&& (avg_volt <= get_eeprom_data(kEep_FullDisAvgVolt, kEepromDataType_Full))
&& (bms_get_ex_data(kExType_CellVolt) == kExStatus_None))
|| (total_volt <= get_eeprom_data(kEep_FullDisTotalVolt, kEepromDataType_Full))
|| (total_volt <= get_eeprom_data(kEep_FullDisTotalVolt, kEepromDataType_Full)/100)
|| ((sox_item.soc_req_st == kSocStatus_Empty) && (sox_item.is_bsu_adjust == false)))
{
full_dly = 0;
@ -463,15 +463,16 @@ void bms_init_soc(void)
{
uint32_t soc;
uint64_t tmp_64u;
int32_t year, mon, day;
int32_t year, mon, day;
soc = get_eeprom_data(kEep_SOC, kEepromDataType_Full);
//soc = bms_check_pwr_on_ocv(soc);
sox_item.soc_kEep_99 = true;
sox_item.soc_kEep_1 = true;
if (soc == 0)
{
sox_item.soc_kEep_1 = false;
sox_item.soc_kEep_1 = false;
}
else if (soc == SOX_MAX_SOC_VALUE)
{
@ -504,6 +505,7 @@ void bms_init_soc(void)
sox_item.rated_cap = tmp_64u;
sox_item.soc_1_cap = (SOX_DIS_kEep_SOC * tmp_64u) / SOX_MAX_SOC_VALUE;
sox_item.soc_99_cap = (SOX_CHG_kEep_SOC * tmp_64u) / SOX_MAX_SOC_VALUE;
sox_item.calculate_cap = (soc * tmp_64u) / SOX_MAX_SOC_VALUE;
sox_item.cycle = get_eeprom_data(kEep_CycleTimes, kEepromDataType_Full);
@ -553,12 +555,16 @@ void bms_integral_soc(int32_t current, uint16_t base_time)
uint16_t soc = sox_item.soc;
uint16_t integral_time = 0, total_volt;
uint32_t tmp_32u = 0;
cap_data_update(base_time);
soc_exterme_calibrate(current, base_time);
if(sox_item.adjust_step != kSocAdjustStep_Wait)
return;
// /*soc test add 2-19
// current = 168;
// soc_run_calibrate(168, base_time);
// */
tmp_32u = kit_time_get_tick();
integral_time = kit_time_get_interval(sox_item.last_tick, tmp_32u);
sox_item.last_tick = tmp_32u;
@ -586,13 +592,15 @@ void bms_integral_soc(int32_t current, uint16_t base_time)
{
//单位Ams
//公式 (current / 100 * integral_time) * (sox_item.chg_adjust_rate / 100)
tmp_32u = current * integral_time * sox_item.chg_adjust_rate / 10000;
//tmp_32u = current * integral_time * sox_item.chg_adjust_rate / 10000;
tmp_32u = current * integral_time * sox_item.chg_adjust_rate / 100;
if (tmp_32u > SOX_MAX_SIGNAL_INTEGRAL)
tmp_32u = SOX_MAX_SIGNAL_INTEGRAL;
sox_item.tmp_chg_cap += tmp_32u;
//单位 kWms
sox_item.tmp_chg_energy += tmp_32u * total_volt / 10000;
//tmp_32少除了100这里应该多除个100--2.20
sox_item.tmp_chg_energy += tmp_32u * total_volt / 1000000;
if(sox_item.calculate_cap < sox_item.rated_cap)
{
@ -632,13 +640,13 @@ void bms_integral_soc(int32_t current, uint16_t base_time)
//放电积分
if(current < 0)
{
tmp_32u = KIT_ABS(current) * integral_time * sox_item.dis_adjust_rate / 10000;
tmp_32u = KIT_ABS(current) * integral_time * sox_item.dis_adjust_rate / 100;
if (tmp_32u > SOX_MAX_SIGNAL_INTEGRAL)
tmp_32u = SOX_MAX_SIGNAL_INTEGRAL;
sox_item.tmp_dis_cap += tmp_32u;
//单位 kWms
sox_item.tmp_dis_energy += tmp_32u * total_volt / 10000;
sox_item.tmp_dis_energy += tmp_32u * total_volt / 1000000;
if(sox_item.calculate_cap > 0)
{

View File

@ -23,26 +23,26 @@ typedef enum
typedef enum
{
kCumulateData_DayDisTime,
kCumulateData_DayDisTime, //0
kCumulateData_DayChgTime,
kCumulateData_SigDisTime,
kCumulateData_SigDisCap,
kCumulateData_SigDisEnergy,
kCumulateData_SigChgTime,
kCumulateData_SigChgTime, //5
kCumulateData_SigChgCap,
kCumulateData_SigChgEnergy,
kCumulateData_DayDisCap,
kCumulateData_DayDisEnergy,
kCumulateData_DayChgCap,
kCumulateData_DayChgCap, //10
kCumulateData_DayChgEnergy,
kCumulateData_AccDisTime,
kCumulateData_AccDisCap,
kCumulateData_AccDisEnergy,
kCumulateData_AccChgTime,
kCumulateData_AccChgCap,
kCumulateData_AccChgCap, //16
kCumulateData_AccChgEnergy,
kCumulateData_End,
}CumulateData;

View File

@ -53,7 +53,7 @@ typedef enum
void bms_analyse_chg_sop(uint32_t base_time)
{
static uint16_t dly = 0;
bool is_forbid_chg;
bool is_forbid_chg;// 充电禁止标志
uint16_t fault_cur, end_cur, fault_power, end_power, req_volt, total_volt;
uint16_t soc, min_temp, max_temp;
int32_t min_temp_cur, max_temp_cur;
@ -61,7 +61,7 @@ void bms_analyse_chg_sop(uint32_t base_time)
soc = bms_get_soc() / 100;
min_temp = (int32_t)bms_get_statistic_data(kStatisticData_MinTemp) /10 - 50;
max_temp = (int32_t)bms_get_statistic_data(kStatisticData_MaxTemp) /10 - 50;
total_volt = bms_get_statistic_data(kStatisticData_TotalVolt) > 300 ? bms_get_statistic_data(kStatisticData_TotalVolt):300;
total_volt = bms_get_statistic_data(kStatisticData_TotalVolt) > 300 ? bms_get_statistic_data(kStatisticData_TotalVolt):300;//534
if(get_eeprom_data(kEep_ChgDisMode_HighVoltStrategy, kEepromDataType_High) == kChgMode_CP)
{
@ -75,7 +75,7 @@ void bms_analyse_chg_sop(uint32_t base_time)
}
else
{
end_power = sop_item.rate_data[kSopData_ChgPower];
end_power = sop_item.rate_data[kSopData_ChgPower];//50
end_cur = (uint32_t)sop_item.rate_data[kSopData_ChgPower] * 10000/total_volt;
}
}

View File

@ -59,7 +59,8 @@ void task_100ms_handler(uint32_t base_time)
static uint32_t cout100ms = 0;
cout100ms++;
bms_poll_iso(base_time);
//bms_poll_adc(base_time);
//bms_poll_adc(); THis was originally commented.
bms_poll_adc(base_time);
bms_poll_statistic(base_time);
bms_poll_run_status(base_time);
bms_poll_sop(base_time);
@ -68,7 +69,7 @@ void task_100ms_handler(uint32_t base_time)
}
GLOBAL_TASK_VARS_CCM(poll_1ms_task, 4, 10, 5000, 400, poll_1ms_task_init, task_1ms_handler, NULL);
GLOBAL_TASK_VARS_CCM(poll_1ms_task, 4, 100, 5000, 400, poll_1ms_task_init, task_1ms_handler, NULL);
GLOBAL_TASK_VARS_CCM(poll_100ms_task, 1, 100, 2000, 400, NULL, task_100ms_handler, NULL);
GLOBAL_TASK_VARS_CCM(poll_10ms_task, 3, 100, 2000, 400, poll_10ms_task_init, task_10ms_handler, NULL);
@ -99,35 +100,42 @@ void poll_1ms_task_init(void)
bms_init_gpio();
bms_init_eeprom();
//bms_init_adc(); THis was originally commented.
//bms_init_adc();
bms_init_tag();
bms_init_run();
bms_init_comm();
//2-17 new add
//task_dido_ctrl_handle(1000);
bms_init_di_do(bmsCircuitCtrl, kDoCtrlStrategy_End, doLogicArray);
bsp_create_task(&poll_10ms_task, (uint8_t *)"10ms");
KIT_DEBUG_PRINTF("cur_hv init start \r\n");
//KIT_DEBUG_PRINTF("cur_hv init start \r\n");
//debug here is no more run
bms_init_cur_hv();
bms_init_cur_hv();
KIT_DEBUG_PRINTF("cur_hv init ok \r\n");
//KIT_DEBUG_PRINTF("cur_hv init ok \r\n");
while(KIT_GET_BIT_32(is_data_ok, BMU_FINISH_BIT) == 0)
{
bsp_task_delay_ms(10);
}
//耗时初始化 ≈300ms 确保信号正常
KIT_DEBUG_PRINTF("signal init start \r\n");
//KIT_DEBUG_PRINTF("signal init start \r\n");
bms_poll_statistic(0);
bms_init_signal();
//刷新信号策略 确保例如常闭等需要立即闭合do输出
task_dido_ctrl_handle(1000);
KIT_DEBUG_PRINTF("signal init ok \r\n");
//KIT_DEBUG_PRINTF("signal init ok \r\n");
KIT_SET_BIT_MASK_32(is_data_ok, SIGNAL_FINISH_BIT);
bsp_create_task(&ord_ctrl_task, (uint8_t *)"ctrl");
}
void poll_10ms_task_init(void)
@ -146,7 +154,8 @@ void poll_10ms_task_init(void)
drv_misc_cfg_pwr_off_interrupt(APP_CFG_INT_PRIO_PWR_OFF, kPwrOffVolt_2_9, bms_pwr_off_save);
KIT_SET_BIT_MASK_32(is_data_ok, BMU_FINISH_BIT);
//while(KIT_GET_BIT_32(is_data_ok, SIGNAL_FINISH_BIT) == 0)
//next line is originally commented.
while(KIT_GET_BIT_32(is_data_ok, SIGNAL_FINISH_BIT) == 0)
{
bsp_task_delay_ms(10);
}
@ -156,7 +165,8 @@ void poll_10ms_task_init(void)
bms_init_sop();
bms_init_iso();
//bsp_create_task(&poll_100ms_task, (uint8_t *)"100ms");
//bsp_create_task(&poll_100ms_task, (uint8_t *)"100ms");,THis was originally commented.
bsp_create_task(&poll_100ms_task, (uint8_t *)"100ms");
bsp_create_task(&bms_poll_bmu_task, (uint8_t *)"100ms");
bsp_create_task(&ord_comm_can_task, (uint8_t *)"100ms");
bsp_create_task(&modbus_rtu_task1, (uint8_t *)"inter_modbus");

File diff suppressed because one or more lines are too long

View File

@ -17,8 +17,8 @@
<TargetCommonOption>
<Device>STM32F407ZGTx</Device>
<Vendor>STMicroelectronics</Vendor>
<PackID>Keil.STM32F4xx_DFP.3.0.0</PackID>
<PackURL>https://www.keil.com/pack/</PackURL>
<PackID>Keil.STM32F4xx_DFP.2.14.0</PackID>
<PackURL>http://www.keil.com/pack/</PackURL>
<Cpu>IRAM(0x20000000,0x00020000) IRAM2(0x10000000,0x00010000) IROM(0x08000000,0x00100000) CPUTYPE("Cortex-M4") FPU2 CLOCK(12000000) ELITTLE</Cpu>
<FlashUtilSpec></FlashUtilSpec>
<StartupFile></StartupFile>
@ -50,7 +50,7 @@
<InvalidFlash>1</InvalidFlash>
</TargetStatus>
<OutputDirectory>.\Objects\</OutputDirectory>
<OutputName>BCU_APP</OutputName>
<OutputName>BCU_APP2</OutputName>
<CreateExecutable>1</CreateExecutable>
<CreateLib>0</CreateLib>
<CreateHexFile>1</CreateHexFile>
@ -83,7 +83,7 @@
<AfterMake>
<RunUserProg1>1</RunUserProg1>
<RunUserProg2>0</RunUserProg2>
<UserProg1Name>fromelf --m32combined --output=@L.s19 .\Objects\@L.axf</UserProg1Name>
<UserProg1Name>D:\Soft\Setup\Keil\ARM\ARM_Compiler_5.06u7\bin\fromelf.exe --bin -o D:\Code\BMS\BCU\app/BCU_APP2.bin D:\Code\BMS\BCU\app/BCU_APP2.axf"</UserProg1Name>
<UserProg2Name></UserProg2Name>
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
@ -186,8 +186,6 @@
<uocXRam>0</uocXRam>
<RvdsVP>2</RvdsVP>
<RvdsMve>0</RvdsMve>
<RvdsCdeCp>0</RvdsCdeCp>
<nBranchProt>0</nBranchProt>
<hadIRAM2>1</hadIRAM2>
<hadIROM2>0</hadIROM2>
<StupSel>8</StupSel>
@ -354,7 +352,7 @@
<NoWarn>0</NoWarn>
<uSurpInc>0</uSurpInc>
<useXO>0</useXO>
<ClangAsOpt>4</ClangAsOpt>
<uClangAs>0</uClangAs>
<VariousControls>
<MiscControls></MiscControls>
<Define></Define>
@ -473,7 +471,7 @@
<NoWarn>2</NoWarn>
<uSurpInc>2</uSurpInc>
<useXO>2</useXO>
<ClangAsOpt>0</ClangAsOpt>
<uClangAs>2</uClangAs>
<VariousControls>
<MiscControls></MiscControls>
<Define></Define>
@ -786,6 +784,11 @@
<FileType>1</FileType>
<FilePath>..\app\fault_manager.c</FilePath>
</File>
<File>
<FileName>ocv_tables.c</FileName>
<FileType>1</FileType>
<FilePath>..\app\ocv_tables.c</FilePath>
</File>
<File>
<FileName>fault_register.c</FileName>
<FileType>1</FileType>
@ -831,11 +834,6 @@
<FileType>1</FileType>
<FilePath>..\app\logic_same_circuit_ctrl.c</FilePath>
</File>
<File>
<FileName>ocv_tables.c</FileName>
<FileType>1</FileType>
<FilePath>..\app\ocv_tables.c</FilePath>
</File>
<File>
<FileName>run_status.c</FileName>
<FileType>1</FileType>
@ -861,16 +859,16 @@
<FileType>1</FileType>
<FilePath>..\app\statistic_manager.c</FilePath>
</File>
<File>
<FileName>version_manager.c</FileName>
<FileType>1</FileType>
<FilePath>..\app\version_manager.c</FilePath>
</File>
<File>
<FileName>bmu_adbms1818.c</FileName>
<FileType>1</FileType>
<FilePath>..\app\bmu_adbms1818.c</FilePath>
</File>
<File>
<FileName>version_manager.c</FileName>
<FileType>1</FileType>
<FilePath>..\app\version_manager.c</FilePath>
</File>
</Files>
</Group>
<Group>
@ -974,7 +972,7 @@
<NoWarn>2</NoWarn>
<uSurpInc>2</uSurpInc>
<useXO>2</useXO>
<ClangAsOpt>0</ClangAsOpt>
<uClangAs>2</uClangAs>
<VariousControls>
<MiscControls></MiscControls>
<Define></Define>
@ -1314,8 +1312,6 @@
<uocXRam>0</uocXRam>
<RvdsVP>2</RvdsVP>
<RvdsMve>0</RvdsMve>
<RvdsCdeCp>0</RvdsCdeCp>
<nBranchProt>0</nBranchProt>
<hadIRAM2>1</hadIRAM2>
<hadIROM2>0</hadIROM2>
<StupSel>8</StupSel>
@ -1482,7 +1478,7 @@
<NoWarn>0</NoWarn>
<uSurpInc>0</uSurpInc>
<useXO>0</useXO>
<ClangAsOpt>4</ClangAsOpt>
<uClangAs>0</uClangAs>
<VariousControls>
<MiscControls></MiscControls>
<Define></Define>
@ -1743,6 +1739,11 @@
<FileType>1</FileType>
<FilePath>..\app\fault_manager.c</FilePath>
</File>
<File>
<FileName>ocv_tables.c</FileName>
<FileType>1</FileType>
<FilePath>..\app\ocv_tables.c</FilePath>
</File>
<File>
<FileName>fault_register.c</FileName>
<FileType>1</FileType>
@ -1788,11 +1789,6 @@
<FileType>1</FileType>
<FilePath>..\app\logic_same_circuit_ctrl.c</FilePath>
</File>
<File>
<FileName>ocv_tables.c</FileName>
<FileType>1</FileType>
<FilePath>..\app\ocv_tables.c</FilePath>
</File>
<File>
<FileName>run_status.c</FileName>
<FileType>1</FileType>
@ -1818,16 +1814,16 @@
<FileType>1</FileType>
<FilePath>..\app\statistic_manager.c</FilePath>
</File>
<File>
<FileName>version_manager.c</FileName>
<FileType>1</FileType>
<FilePath>..\app\version_manager.c</FilePath>
</File>
<File>
<FileName>bmu_adbms1818.c</FileName>
<FileType>1</FileType>
<FilePath>..\app\bmu_adbms1818.c</FilePath>
</File>
<File>
<FileName>version_manager.c</FileName>
<FileType>1</FileType>
<FilePath>..\app\version_manager.c</FilePath>
</File>
</Files>
</Group>
<Group>

File diff suppressed because it is too large Load Diff

View File

@ -106,7 +106,7 @@ uint16_t bcu_total_msg_fill(uint16_t start_addr, uint8_t reg_num, uint8_t *buf)
//READ_FC03_F04_ITEM(1, test99+=10);
//2 动力电池组总电流
READ_FC03_F04_ITEM(2, bms_get_show_current() + 211);
READ_FC03_F04_ITEM(2, bms_get_show_current());
//3 SOC
//READ_FC03_F04_ITEM(3,get_eeprom_data(kEep_SOC,kEepromDataType_Full) / 100);
READ_FC03_F04_ITEM(3, bms_get_soc() / 100);
@ -117,7 +117,7 @@ uint16_t bcu_total_msg_fill(uint16_t start_addr, uint8_t reg_num, uint8_t *buf)
//6 额定总压
READ_FC03_F04_ITEM(6, get_eeprom_data(kEep_RatedTotalVolt,kEepromDataType_Full));
//7 额定容量
READ_FC03_F04_ITEM(7, get_eeprom_data(kEep_RatedCapacity,kEepromDataType_Full));
READ_FC03_F04_ITEM(7, get_eeprom_data(kEep_RatedCapacity,kEepromDataType_Full) );
//8 剩余容量
READ_FC03_F04_ITEM(8, (uint32_t)bms_get_soc()*get_eeprom_data(kEep_RatedCapacity, kEepromDataType_Full)/10000);
//9 额定电量
@ -714,8 +714,8 @@ uint16_t bcu_total_cfg_fill(uint16_t start_addr, uint8_t reg_num, uint8_t *buf)
case 3146: // 预充超时时间s
data = get_eeprom_data(kEep_PreChgTimeout_Count , (EepromDataType)(1 - (address % 2)));
break;
case 3147: // HV电压比例(%
case 3148: // 预充电压比例(%
case 3147: // 预充电压比例(%
case 3148: // 预充类型
data = get_eeprom_data(kEep_PreChgVoltType_Rate , (EepromDataType)(1 - (address % 2)));
break;
case 3149: // 系统时间s
@ -1271,9 +1271,21 @@ BspMdExCode bcu_modbus_485_0x10_fun(uint16_t start_addr, uint16_t reg_num, uint8
bcu_data_set_0x06_msg(start_addr + i, data);
}
}
//@wangk , 2-25, add 0x10function(4000~4449)
else if((start_addr >= 4000) && (start_addr <= 4449))
{
uint16_t *reg_data = (uint16_t *)buf;
for (uint16_t i = 0; i < reg_num; i++)
{
uint16_t reg_value = (reg_data[i] >> 8) | (reg_data[i] << 8);
uint16_t offset_addr = start_addr - 4000 + i;
hmi_write_modbus_cfg(offset_addr, reg_value);
}
}
else
{
err = kBspMdEx_InvalidAddr;
err = kBspMdEx_InvalidAddr;
}
return err;
}

View File

@ -10,15 +10,15 @@
<TargetName>stm32f407</TargetName>
<ToolsetNumber>0x4</ToolsetNumber>
<ToolsetName>ARM-ADS</ToolsetName>
<pArmCC>5060960::V5.06 update 7 (build 960)::.\ARMCC</pArmCC>
<pCCUsed>5060960::V5.06 update 7 (build 960)::.\ARMCC</pCCUsed>
<pArmCC>5060960::V5.06 update 7 (build 960)::.\ARM_Compiler_5.06u7</pArmCC>
<pCCUsed>5060960::V5.06 update 7 (build 960)::.\ARM_Compiler_5.06u7</pCCUsed>
<uAC6>0</uAC6>
<TargetOption>
<TargetCommonOption>
<Device>STM32F407ZGTx</Device>
<Vendor>STMicroelectronics</Vendor>
<PackID>Keil.STM32F4xx_DFP.2.14.0</PackID>
<PackURL>http://www.keil.com/pack/</PackURL>
<PackID>Keil.STM32F4xx_DFP.3.0.0</PackID>
<PackURL>https://www.keil.com/pack/</PackURL>
<Cpu>IRAM(0x20000000,0x00020000) IRAM2(0x10000000,0x00010000) IROM(0x08000000,0x00100000) CPUTYPE("Cortex-M4") FPU2 CLOCK(12000000) ELITTLE</Cpu>
<FlashUtilSpec></FlashUtilSpec>
<StartupFile></StartupFile>
@ -139,7 +139,7 @@
</Flash1>
<bUseTDR>1</bUseTDR>
<Flash2>BIN\UL2CM3.DLL</Flash2>
<Flash3></Flash3>
<Flash3>"" ()</Flash3>
<Flash4></Flash4>
<pFcarmOut></pFcarmOut>
<pFcarmGrp></pFcarmGrp>
@ -187,6 +187,7 @@
<RvdsVP>2</RvdsVP>
<RvdsMve>0</RvdsMve>
<RvdsCdeCp>0</RvdsCdeCp>
<nBranchProt>0</nBranchProt>
<hadIRAM2>1</hadIRAM2>
<hadIROM2>0</hadIROM2>
<StupSel>8</StupSel>

File diff suppressed because it is too large Load Diff

View File

@ -588,8 +588,8 @@ void SystemInit(void)
/* Configure the System clock source, PLL Multiplier and Divider factors,
AHB/APBx prescalers and Flash settings ----------------------------------*/
SetSysClock();
//SystemClock_Config();
//SetSysClock();
SystemClock_Config();
/* Configure the Vector Table location add offset address ------------------*/
#ifdef VECT_TAB_SRAM
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */

File diff suppressed because one or more lines are too long

View File

@ -86,7 +86,7 @@ typedef struct
uint16_t * data_buf;
const EepromDataFormat * format;
flash_Item_t *flash;
AreaItem static_area;
AreaItem dynamic_area;
}EEpromItem;

View File

@ -519,7 +519,7 @@ void SystemInit(void)
/* Configure the System clock source, PLL Multiplier and Divider factors,
AHB/APBx prescalers and Flash settings ----------------------------------*/
//SetSysClock();
SystemClock_Config();
SystemClock_Config();
/* Configure the Vector Table location add offset address ------------------*/
#ifdef VECT_TAB_SRAM
@ -573,6 +573,7 @@ void SystemCoreClockUpdate(void)
#endif /* STM32F412xG || STM32F413_423xx || STM32F446xx */
/* Get SYSCLK source -------------------------------------------------------*/
tmp = RCC->CFGR & RCC_CFGR_SWS;
//tmp = RCC_CFGR_SWS_HSE;
switch (tmp)
{
@ -711,7 +712,7 @@ void SystemClock_Config(void)
RCC->CFGR |= RCC_CFGR_PPRE2_DIV2;
/* PCLK1 = HCLK / 4 */
RCC->CFGR |= RCC_CFGR_PPRE1_DIV4;
RCC->CFGR |= RCC_CFGR_PPRE1_DIV8;
/* Configure the main PLL for 168 MHz using HSI */
RCC->PLLCFGR = (16 << 0) // PLL_M = 16 (HSI = 16 MHz input for PLL)

View File

@ -611,6 +611,72 @@ int8_t parse_cells(uint8_t current_ic, // Current IC
return (pec_error);
}
/* Helper function that parses voltage measurement registers */
int8_t drv_parse_temp_data(uint8_t current_ic, // Current IC
uint8_t cell_reg, // Type of register
uint8_t cell_data[], // Unparsed data
uint16_t *cell_codes, // Parsed data
uint8_t *ic_pec // PEC error
)
{
uint8_t BYT_IN_REG = 6;
uint8_t CELL_IN_REG = 3;
int8_t pec_error = 0;
uint16_t parsed_cell;
uint16_t received_pec;
uint16_t data_pec;
uint8_t data_counter = current_ic * NUM_RX_BYT; // data counter
for (uint8_t current_cell = 0; current_cell < CELL_IN_REG; current_cell++) // This loop parses the read back data into the register codes, it
{ // loops once for each of the 3 codes in the register
parsed_cell = cell_data[data_counter] + (cell_data[data_counter + 1] << 8); // Each code is received as two bytes and is combined to
// create the parsed code
if(cell_reg == 1)
{
cell_codes[current_cell + ((cell_reg - 1) * CELL_IN_REG)] = parsed_cell;
}
else if(cell_reg == 2)
{
if(current_cell < 2)
{
cell_codes[current_cell + 3] = parsed_cell;
}
}
else if(cell_reg == 3)
{
cell_codes[current_cell + 5] = parsed_cell;
}
else if(cell_reg == 4)
{
if(current_cell < 1)
{
cell_codes[current_cell + 8] = parsed_cell;
}
}
data_counter = data_counter + 2; // Because the codes are two bytes, the data counter
// must increment by two for each parsed code
}
received_pec = (cell_data[data_counter] << 8) | cell_data[data_counter + 1]; // The received PEC for the current_ic is transmitted as the 7th and 8th
// after the 6 cell voltage data bytes
data_pec = pec15_calc(BYT_IN_REG, &cell_data[(current_ic)*NUM_RX_BYT]);
if (received_pec != data_pec)
{
pec_error = 1; // The pec_error variable is simply set negative if any PEC errors
ic_pec[cell_reg - 1] = 1;
}
else
{
ic_pec[cell_reg - 1] = 0;
}
data_counter = data_counter + 2;
return (pec_error);
}
/*Reads and parses the ADBMS181x cell voltage registers.
The function is used to read the parsed Cell voltages codes of the ADBMS181x.
This function will send the requested read commands parse the data
@ -767,7 +833,7 @@ int8_t ADBMS1818_rdaux(uint8_t reg, // Determines which GPIO voltage register
{
c_ic = total_ic - current_ic - 1;
}
pec_error = parse_cells(current_ic, gpio_reg, data,
pec_error = drv_parse_temp_data(current_ic, gpio_reg, data,
&ic[c_ic].aux.a_codes[0],
&ic[c_ic].aux.pec_match[0]);
}
@ -787,7 +853,7 @@ int8_t ADBMS1818_rdaux(uint8_t reg, // Determines which GPIO voltage register
{
c_ic = total_ic - current_ic - 1;
}
pec_error = parse_cells(current_ic, reg, data,
pec_error = drv_parse_temp_data(current_ic, reg, data,
&ic[c_ic].aux.a_codes[0],
&ic[c_ic].aux.pec_match[0]);
}

View File

@ -28,40 +28,67 @@ uint8_t drv_ads8688_spi_send_rev(uint8_t data)
// 返回TURE则说明初始化正常否则错误
bool drv_ads8688_Init(void)
{
uint8_t i = 0;
uint8_t i = 0, value = 0;
drv_spi_init(kSpiDev_2, kSpiFreq_Div256, kSpiMode_C0E1, SpiFrame_MSBFirst, kGpioType_ADC_Clk, kGpioType_ADC_Miso, kGpioType_ADC_Mosi);
//drv_ads8688_Reset();// hardware reset
drv_enter_pwrdn_mode();
OSTimeDly(20);
drv_reset_ads8688();
kit_time_dly_ms(20);
drv_enter_standby_mode();
OSTimeDly(20);
drv_reset_ads8688();
OSTimeDly(20);
drv_set_ch_range(Channel_0_Input_Range,VREF_25_25);
drv_set_ch_range(Channel_1_Input_Range,VREF_25_25);
drv_set_ch_range(Channel_2_Input_Range,VREF_25_25);
drv_set_ch_range(Channel_3_Input_Range,VREF_25_25);
drv_set_ch_range(Channel_4_Input_Range,VREF_25_25);
drv_set_ch_range(Channel_5_Input_Range,VREF_25_25);
kit_time_dly_ms(20);
drv_set_ch_pwrdn(Channel_6_Input_Range);
drv_set_ch_pwrdn(Channel_7_Input_Range);
//drv_enter_pwrdn_mode();
//OSTimeDly(20);
drv_ads8688_write_reg(AUTO_SEQ_EN, 0x3F);
drv_ads8688_write_reg(AUTO_SEQ_EN, 0xFF);
kit_time_dly_ms(10);
i = drv_ads8688_read_reg(AUTO_SEQ_EN);
drv_ads8688_write_reg(Feature_Select, 0x28);
kit_time_dly_ms(20);
if (i != 0x3F)
{
return true;
}
else
{
drv_enter_auto_rst_mode(); // ½øÈë×Ô¶¯É¨Ãèģʽ
OSTimeDly(20);
return false;
}
drv_set_ch_range(Channel_0_Input_Range,VREF_125_125);
drv_set_ch_range(Channel_1_Input_Range,VREF_125_125);
drv_set_ch_range(Channel_2_Input_Range,VREF_0625_0625);
drv_set_ch_range(Channel_3_Input_Range,VREF_125_125);
drv_set_ch_range(Channel_4_Input_Range,VREF_125_125);
drv_set_ch_range(Channel_5_Input_Range,VREF_125_125);
drv_set_ch_range(Channel_6_Input_Range,VREF_125_125);
drv_set_ch_range(Channel_7_Input_Range,VREF_125_125);
//value = drv_ads8688_read_reg(Channel_0_Input_Range);
drv_set_ch_pwrdn(0xC0);
//
#if ADC_AUTO_MODE
{
drv_ads8688_write_reg(AUTO_SEQ_EN, 0x3F);
i = drv_ads8688_read_reg(AUTO_SEQ_EN);
if (i != 0x3F)
{
return true;
}
else
{
drv_enter_auto_rst_mode(); // ½øÈë×Ô¶¯É¨Ãèģʽ
OSTimeDly(20);
return false;
}
}
#else
{
drv_manual_chn_mode(MAN_Ch_0);
drv_manual_chn_mode(MAN_Ch_1);
drv_manual_chn_mode(MAN_Ch_2);
drv_manual_chn_mode(MAN_Ch_3);
drv_manual_chn_mode(MAN_Ch_4);
drv_manual_chn_mode(MAN_Ch_5);
return false;
}
#endif
}
void drv_ads8688_Reset(void) // hardware reset
@ -107,7 +134,8 @@ void drv_reset_ads8688(void) //
// 退出此模式需执行AUTO_RST或者MAN_CH_n命令且需要等待至少20us以保证正常数据的AD转换
void drv_enter_standby_mode(void)
{
drv_ads8688_write_cmd_reg(STDBY);
//drv_ads8688_write_cmd_reg(STDBY);
drv_ads8688_write_cmd_reg(NO_OP);
}
// 进入PWR_DN模式且命令发送后CS立刻置高不读数据帧
@ -156,7 +184,7 @@ uint16_t drv_manual_chn_mode_Data(void)
datah = drv_ads8688_spi_send_rev(0xFF);
datal = drv_ads8688_spi_send_rev(0xFF);
drv_set_ads8688_cs(kGpioStatus_High);
kit_time_dly_ms(10);
return (datah << 8 | datal);
}
@ -177,17 +205,16 @@ void drv_ads8688_write_reg(uint8_t Addr, uint8_t data)
}
// Program Register读操作
uint8_t drv_ads8688_read_reg(uint8_t Addr)
uint16_t drv_ads8688_read_reg(uint8_t Addr)
{
uint8_t data = 0;
uint8_t datah = 0,datal = 0;
drv_set_ads8688_cs(kGpioStatus_Low);
drv_ads8688_spi_send_rev(Addr << 1 | READ);
data = drv_ads8688_spi_send_rev(0xFF);
data = drv_ads8688_spi_send_rev(0xFF);
datah = drv_ads8688_spi_send_rev(0xFF);
datal = drv_ads8688_spi_send_rev(0xFF);
drv_set_ads8688_cs(kGpioStatus_High);
return data;
return datal + (datah << 8);
}
void drv_set_auto_scan_sequence(uint8_t seq) // 设置自动扫描序列通道
@ -198,11 +225,13 @@ void drv_set_auto_scan_sequence(uint8_t seq) //
void drv_set_ch_pwrdn(uint8_t chn) // 设置通道n为Power Down
{
drv_ads8688_write_reg(0X02, chn);
}
void drv_set_ch_range(uint8_t ch, uint8_t range) // 设置各个通道的范围
{
drv_ads8688_write_reg(ch, range);
kit_time_dly_ms(20);
}
int16_t drv_ads8688_value(uint16_t value)

View File

@ -84,7 +84,8 @@ kGpioType_ADC_Cs
#define VREF_0_25 0X05
#define VREF_0_125 0X06
typedef struct
#define ADC_AUTO_MODE 0
typedef struct
{
uint8_t cs;
SpiDev spi;
@ -112,7 +113,7 @@ void drv_enter_auto_rst_mode(void);
void drv_enter_auto_rst_mode_Data(uint16_t* outputdata, uint8_t chnum);
void drv_ads8688_write_reg(uint8_t Addr,uint8_t data);
uint8_t drv_ads8688_read_reg(uint8_t Addr);
uint16_t drv_ads8688_read_reg(uint8_t Addr);
void drv_set_auto_scan_sequence(uint8_t seq);
void drv_set_ch_pwrdn(uint8_t chn);
void drv_set_ch_range(uint8_t ch,uint8_t range);