ZDBMS/code_drv/PorSelfTest.c

205 lines
4.9 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/********************************************************************************
Copyright (C), Sinowealth Electronic. Ltd.
Author: Sino
Version: V0.0
Date: 2020/04/26
History:
V2.0 2020/04/26 Preliminary
********************************************************************************/
#include "Main.H"
BOOL bPorSelfTestFlg;
U8 ucPorSelfTestDelayCnt;
/*************************************************************************************************
* 函数名: PorProtectOV
* 参 数: 无
* 返回值: 无
* 描 述: 单节电池过压保护检测过压后置位bOV为1
*************************************************************************************************/
void PorProtectOV(void)
{
if(!bOV)
{
if(uiCellVmax > E2uiOVvol)
{
if(++uiOVDelayCnt >= TIME_50mS_50mS)
{
bOV = 1;
uiOVDelayCnt = 0;
}
}
else if(uiCellVmax < E2uiOVRvol)
{
uiOVDelayCnt = 0;
}
}
}
/*************************************************************************************************
* 函数名: PorProtectUV
* 参 数: 无
* 返回值: 无
* 描 述: 单节电芯欠压保护检测保护后置位bUV为1
*************************************************************************************************/
void PorProtectUV(void)
{
if(!bUV)
{
if(uiCellVmin < E2uiUVvol)
{
if(++uiUVDelayCnt >= TIME_50mS_50mS)
{
bUV = 1;
uiUVDelayCnt = 0;
}
}
else if(uiCellVmin > E2uiUVRvol)
{
uiUVDelayCnt = 0;
}
}
}
/*************************************************************************************************
* 函数名: PorProtectOTC
* 参 数: 无
* 返回值: 无
* 描 述: 充电高温保护检测保护后置位bOTC为1
*************************************************************************************************/
void PorProtectOTC(void)
{
if(!bOTC)
{
if(uiTempeMax > E2uiTempOTC)
{
if(++uiOTCDelayCnt >= TIME_50mS_50mS)
{
bOTC = 1;
uiOTCDelayCnt = 0;
}
}
else if(uiTempeMax < E2uiTempOTCR)
{
uiOTCDelayCnt = 0;
}
}
}
/*************************************************************************************************
* 函数名: PorProtectUTC
* 参 数: 无
* 返回值: 无
* 描 述: 充电低温保护检测保护后置位bUTC为1
*************************************************************************************************/
void PorProtectUTC(void)
{
if(!bUTC)
{
if(uiTempeMin < E2uiTempUTC)
{
if(++uiUTCDelayCnt >= TIME_50mS_50mS)
{
bUTC = 1;
uiUTCDelayCnt = 0;
}
}
else if(uiTempeMin > E2uiTempUTCR)
{
uiUTCDelayCnt = 0;
}
}
}
/*************************************************************************************************
* 函数名: PorProtectOTD
* 参 数: 无
* 返回值: 无
* 描 述: 放电高温保护检测保护后置位bOTD为1
*************************************************************************************************/
void PorProtectOTD(void)
{
if(!bOTD)
{
if(uiTempeMax > E2uiTempOTD)
{
if(++uiOTDDelayCnt >= TIME_50mS_50mS)
{
bOTD = 1;
uiOTDDelayCnt = 0;
}
}
else if(uiTempeMax < E2uiTempOTDR)
{
uiOTDDelayCnt = 0;
}
}
}
/*************************************************************************************************
* 函数名: PorProtectUTD
* 参 数: 无
* 返回值: 无
* 描 述: 放电低温保护检测保护后置位bUTD为1
*************************************************************************************************/
void PorProtectUTD(void)
{
if(!bUTD)
{
if(uiTempeMin < E2uiTempUTD)
{
if(++uiUTDDelayCnt >= TIME_50mS_50mS)
{
bUTD = 1;
uiUTDDelayCnt = 0;
}
}
else if(uiTempeMin > E2uiTempUTDR)
{
uiUTDDelayCnt = 0;
}
}
}
/*************************************************************************************************
* 函数名: ProtectProcess
* 参 数: 无
* 返回值: 无
* 描 述: 第一次上电时的自检持续100mS上电自检最快完成时间为50mS
*************************************************************************************************/
void PorSelfTest(void)
{
if(bPorSelfTestFlg)
{
AfeCalcuVol(); //第一次上电50mS后自动读取电压数据和温度数据
AfeCalcuTempe();
PorProtectOV(); //检测过压保护及其释放
PorProtectUV(); //检测欠压保护及其释放
PorProtectOTC(); //检测充电高温保护及其释放
PorProtectUTC(); //检测充电低温保护及其释放
PorProtectOTD(); //检测放电高温保护及其释放
PorProtectUTD(); //检测放电低温保护及其释放
if(++ucPorSelfTestDelayCnt >= TIME_50mS_100mS) //如果需要最快自检完成则将TIME_50mS_100mS修改为TIME_50mS_50mS
{
bPorSelfTestFlg = 0; //1S自检结束后根据当前状态确定是否进入PD或者是否开关MOS
if(bAfeErr || bE2PRErr || bRTCErr || bMcuFlashErr)
{
bPDFlg = 1;
}
else
{
GasGaugeInit(); //计算电量值
}
}
}
}