一、硬件准备
1、主控板子:S32K312 板子
2、BJB 板子:MC33772 BJB 板子
3、硬件连接:
两个板子独立 12V 供电,外部电流接线流经分流器 Shunt ,分流器方向从下往上流向得到正值数据。
4、BJB 测量电流电路注意事项
① 板子上预留的外部电压模拟测试电流采样电路需要去掉,如下图,BJB 板子电路图如示意图一致
二、软件准备
1、S32DS 软件 IDE
2、软件包获取:
① 进入官网下载 ,Go on Package manager webpage.
② 勾选 S32K344 HVBMS ,然后下载
3、环境安装
S32K312 以及 S32 DS 安装环境查看《BMS_SWInstalationGuide_Hvbms_2024.pdf》,在上述官网页面点击下图位置,即可下载用户指导手册,按照手册一步步下载安装即可完成环境的安装
4、软件更改
芯片更换为 S32K312 ,上述已经下载了 S32K344 的 BMS 例程,按照 S32K344 的 EB tresos 配置,在S32K312 的例程上,直接在 EB tresos 更改外设,添加 MC33772 ,MC33665 对应的组件即可,如下图,其他外设配置可以参考 S32K344 例程。(如客户及用户此步骤无法操作,可以联系 我们 WPI ATU ,在允许的情况下可以提供这套移植好的 demo)
三、测量电流软件流程
1、 查看数据手册
《ds633730 - MC33772C Datasheet.pdf》里面有提示:电流采样使能后至少等待 2.7us 后才能进行 ADC 转化。
2、 ADC 采样配置
配置 ADC 采样平均次数,次数越高采样时间越长,在 EB 配置当中,ADC2 的采样分辨率设置为 15bit
3、 查看代码配置,进行修改:先使能 电流采样,再进行 ADC 转换
HVBMS_Errors Bjb_StartMeas(void)
{
Std_ReturnType Status = E_OK;
/* Clear TD */
Status = Bms_TD_Clear(&BmsTDCfg_Tpl2);
/* Start measurements */
Status |= Bcc_772c_CC_ControlMeasurements(BCC_772C_ALL_CHAIN_TPL, BCC_772C_ALL_DEVICE_TPL, BCC_772C_CC_START, &BmsTDCfg_Tpl2);
/* Add 2 ms delay to wait for the device to finish current measurement */
Status |= Bms_TD_InsertPhyEvent(&BmsTDCfg_Tpl2, PHY_TIMER, 2000U);
Status |= Bcc_772c_COM_InsertNop(BS_CHAIN_ADDR, 1, &BmsTDCfg_Tpl2);
/* Call Bcc_772c_Send */
Status |= Bms_TD_Send(&BmsTDCfg_Tpl2, &PhyError);
if(Status != E_OK)
{
return ERROR_BJB_START_MEASUREMENTS_TD_FILL;
}
/* Wait until PHY processes the request */
Td_Wait(&BmsTDCfg_Tpl2);
if(PhyError != PHY_NO_ERROR)
{
return ERROR_BJB_START_MEASUREMENTS_TD_SEND;
}
/* Clear TD */
Status = Bms_TD_Clear(&BmsTDCfg_Tpl2);
Status |= Bcc_772c_MSR_StartConversion(BCC_772C_ALL_CHAIN_TPL, BCC_772C_ALL_DEVICE_TPL, MC33772C_ADC_CFG_AVG_8_SAMPLES_ENUM_VAL, &BmsTDCfg_Tpl2);
/* Add 2 ms delay to wait for the device to finish current measurement */
Status |= Bms_TD_InsertPhyEvent(&BmsTDCfg_Tpl2, PHY_TIMER, 2000U);
Status |= Bcc_772c_COM_InsertNop(BS_CHAIN_ADDR, 1, &BmsTDCfg_Tpl2);
/* Call Bcc_772c_Send */
Status |= Bms_TD_Send(&BmsTDCfg_Tpl2, &PhyError);
if(Status != E_OK)
{
return ERROR_BJB_START_MEASUREMENTS_TD_FILL;
}
/* Wait until PHY processes the request */
Td_Wait(&BmsTDCfg_Tpl2);
if(PhyError != PHY_NO_ERROR)
{
return ERROR_BJB_START_MEASUREMENTS_TD_SEND;
}
/* Clear TD */
Status = Bms_TD_Clear(&BmsTDCfg_Tpl2);
return NO_ERROR;
}
4、 读取数据
HVBMS_Errors Bjb_ReadMeasurementsResults(BjbMeasurementType MeasurementType)
{
volatile Std_ReturnType Status = E_OK;
uint8 BS_Device_Addr;
Bcc_772c_CcISenseValueType CcIsense[BS_DEVICE_CNT];
//Bjb_ReadIsolation();
Status = Bms_TD_Clear(&BmsTDCfg_Tpl2);
uint16 CurrentData[BS_DEVICE_CNT][5] = {0,0};
/* Start measurements */
do
{
/* Read current measurements */
if(MeasurementType == BJB_CURRENT_MEASUREMENT)
{
//delay 10ms
Status |= Bms_TD_InsertPhyEvent(&BmsTDCfg_Tpl2, PHY_TIMER, 5000);
Status |= Bcc_772c_CC_ControlMeasurements(BCC_772C_ALL_CHAIN_TPL, BCC_772C_ALL_DEVICE_TPL, BCC_772C_CC_RESTART, &BmsTDCfg_Tpl2);
/* Add 2 ms delay to wait for the device to finish current measurement */
Status |= Bms_TD_InsertPhyEvent(&BmsTDCfg_Tpl2, PHY_TIMER, 2000U);
Status |= Bcc_772c_COM_InsertNop(BS_CHAIN_ADDR, 1, &BmsTDCfg_Tpl2);
/* Call Bcc_772c_Send */
Status |= Bms_TD_Send(&BmsTDCfg_Tpl2, &PhyError);
if(Status != E_OK)
{
return ERROR_BJB_START_MEASUREMENTS_TD_FILL;
}
/* Wait until PHY processes the request */
Td_Wait(&BmsTDCfg_Tpl2);
if(PhyError != PHY_NO_ERROR)
{
return ERROR_BJB_START_MEASUREMENTS_TD_SEND;
}
/* Clear TD */
Status = Bms_TD_Clear(&BmsTDCfg_Tpl2);
for(BS_Device_Addr = 1; BS_Device_Addr <= BS_DEVICE_CNT; BS_Device_Addr++)
{
Status |= Bcc_772c_CC_GetData(BS_CHAIN_ADDR, BS_Device_Addr, &BmsTDCfg_Tpl2);
}
Status |= Bms_TD_Send(&BmsTDCfg_Tpl2, &PhyError);
if(Status != E_OK)
{
return ERROR_BJB_READ_MEASUREMENTS_CURRENT_TD_FILL;
}
/* Wait until PHY processes the request */
Td_Wait(&BmsTDCfg_Tpl2);
if(PhyError != PHY_NO_ERROR)
{
return ERROR_BJB_READ_MEASUREMENTS_CURRENT_TD_SEND;
}
/* Check DATA_RDY bits for current measurements */
if( ((((BmsTDCfg_Tpl2).PhyTD)->Response).Data[9] & 0x8000)&
((((BmsTDCfg_Tpl2).PhyTD)->Response).Data[12] & 0x8000)&
((((BmsTDCfg_Tpl2).PhyTD)->Response).Data[24] & 0x8000)&
((((BmsTDCfg_Tpl2).PhyTD)->Response).Data[27] & 0x8000) )
{
Status = E_OK;
}
else
Status = E_NOT_OK;
if(Status != E_OK)
{
return ERROR_BJB_READ_MEASUREMENTS_CURRENT_VALUE_EXTRACT;
}
/* Read current measurements */
for(BS_Device_Addr = 1; BS_Device_Addr <= BS_DEVICE_CNT; BS_Device_Addr++)
{
/* RShunt 100 uOhm */
CcIsense[BS_Device_Addr-1].RShunt = RSHUNT;
Status |= Bcc_772c_CC_ExtractISense(BS_CHAIN_ADDR, BS_Device_Addr, &CcIsense[BS_Device_Addr-1], &BmsTDCfg_Tpl2);
PackCurrent[BS_Device_Addr-1] = CcIsense[BS_Device_Addr-1].ISense;//单位 mA
}
break;
}
} while(0);
Status = Bms_TD_Clear(&BmsTDCfg_Tpl2);
return NO_ERROR;
}
四、参考资料
1、MC33772 数据手册
2、BJB 用户参考手册 UM11847
欢迎登录大大通,阅读原文,浏览更多精彩技术内容吧!