177 lines
5.5 KiB
C
177 lines
5.5 KiB
C
#include "../main/SystemInclude.h"
|
||
|
||
static s16 GasAnalysisCNT;
|
||
u16 ATypeNode[CURVE_DATA_MAX], ATypeVal[CURVE_DATA_MAX], curveATypeNum;
|
||
bool isCurrentGas;
|
||
|
||
/******************************************************************************/
|
||
void GasAnalysisParameterInit(void)
|
||
{
|
||
airFactor = (u16)ReadShortParameterFromMemory(AIR_FACTOR, AIR_FACTOR_DEFAULT);
|
||
factorVth = (u16)ReadShortParameterFromMemory(FACTOR_VTH, 1000);
|
||
|
||
//------------------------------------------------------------------------------
|
||
#ifndef ENABLE_GAS_RECOGNITION_TABLE
|
||
#pragma message("[undefined] ENABLE_GAS_RECOGNITION_TABLE")
|
||
#elif(ENABLE_GAS_RECOGNITION_TABLE)
|
||
ReadVHHCurveFromMemory();
|
||
#endif
|
||
|
||
//------------------------------------------------------------------------------
|
||
#ifndef ENABLE_DENSITY_DETECT
|
||
#pragma message("[undefined] ENABLE_DENSITY_DETECT")
|
||
#elif(ENABLE_DENSITY_DETECT)
|
||
// densityFSParameter = (u16)ReadParameterFromMemory(DENSITY_FS_PARA, DENSITY_FS_PARA_WIDTH, DENSITY_FS_PARA_DEFAULT);
|
||
#endif
|
||
}
|
||
|
||
/******************************************************************************/
|
||
u16 ComputeZeroVHH(void)
|
||
{
|
||
tmpSLA = (u32)voltageDetected[RRRES];
|
||
tmpSLA -= (u32)RRRoom;
|
||
|
||
tmpSLB = (u32)VHHHigh;
|
||
tmpSLB -= (u32)VHHLow;
|
||
tmpSLA *= tmpSLB;
|
||
|
||
tmpSLB = (u32)RRHigh;
|
||
tmpSLB -= (u32)RRLow;
|
||
tmpSLA /= tmpSLB;
|
||
|
||
tmpSLA += (u32)VHHRoom;
|
||
|
||
return (u16)tmpSLA;
|
||
}
|
||
|
||
/******************************************************************************/
|
||
bool GasAnasisOneTime(void)
|
||
{
|
||
s16 valueTemp;
|
||
|
||
valueTemp = (s16)(voltageDetected[VHPA] - airFactor);
|
||
if(abs(valueTemp) < factorVth) return 1;
|
||
else return 0;
|
||
}
|
||
|
||
/******************************************************************************/
|
||
void GasAnasisCompute(void)//
|
||
{
|
||
//===========================================================================
|
||
voltageDetected[CVHHX] = ComputeZeroVHH();
|
||
voltageDetected[DVHHX] = WordSubFunction(voltageDetected[IVHDX], voltageDetected[CVHHX]);
|
||
|
||
//===========================================================================
|
||
#ifndef ENABLE_GAS_RECOGNITION_TABLE
|
||
#pragma message("[undefined] ENABLE_GAS_RECOGNITION_TABLE")
|
||
#elif(ENABLE_GAS_RECOGNITION_TABLE)
|
||
voltageDetected[VHPA] = FindVHHInCalibCurve(voltageDetected[RGIDX]);
|
||
#else
|
||
voltageDetected[VHPA] = (u16)GetFlowRate(voltageDetected[REG_INDEX], ATYPE_VH);
|
||
#endif
|
||
|
||
voltageDetected[VHPA] = WordSubFunction(voltageDetected[DVHHX], voltageDetected[VHPA]);
|
||
voltageDetected[VHPA] = MovingAverage(voltageDetected[VHPA], 5, VHPA);
|
||
VHHParameter = voltageDetected[VHPA];
|
||
|
||
if((VHHParameter < 32780) & (VHHParameter > 32700)) //32700-32780
|
||
{
|
||
GasAnalysisCNT--;
|
||
return;
|
||
}
|
||
|
||
//===========================================================================
|
||
if(GasAnasisOneTime()) GasAnalysisCNT--;
|
||
else GasAnalysisCNT++;
|
||
|
||
if(GasAnalysisCNT > 3)
|
||
{
|
||
systemAlarm.Bit.GasChange = 1; //<2F><><EFBFBD>ʸı<CAB8>
|
||
GasAnalysisCNT = 0;
|
||
}
|
||
else if(GasAnalysisCNT < -3)
|
||
{
|
||
systemAlarm.Bit.GasChange = 0;
|
||
GasAnalysisCNT = 0;
|
||
}
|
||
}
|
||
|
||
/******************************************************************************/
|
||
void ReadVHHCurveFromMemory(void)
|
||
{
|
||
u16 I;
|
||
|
||
curveATypeNum = ReadShortParameterFromMemory(ATYPECURVE_NUM, ATYPECURVE_NUM_DEFAULT);
|
||
for(I=0; I<curveATypeNum; I++)
|
||
{
|
||
ReadMultiByteFromEEPROM(ATYPECURVE_DATA_BASE + I * ATYPECURVE_DATA_WIDTH, tempDev.Byte, ATYPECURVE_DATA_WIDTH, PARA_EEPROM);
|
||
if(tempDev.Byte[ATYPECURVE_DATA_CRC] == CRC8(tempDev.Byte, ATYPECURVE_DATA_CRC))
|
||
{
|
||
tempDev.Byte[ATYPECURVE_DATA_CRC] = 0;
|
||
ATypeNode[I] = tempDev.Word[1];
|
||
ATypeVal[I] = tempDev.Word[0];
|
||
}
|
||
else
|
||
{
|
||
ATypeVal[I] = 0;
|
||
ATypeVal[I] = 0;
|
||
}
|
||
}
|
||
}
|
||
|
||
/******************************************************************************/
|
||
u16 FindVHHInCalibCurve(u16 calibIndex)
|
||
{
|
||
u16 I;
|
||
|
||
if((curveATypeNum < 3) || (curveATypeNum > CURVE_DATA_MAX))
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
//----------------------------------------------------------------------------
|
||
if(calibIndex > 32767) calibIndex = 0;
|
||
|
||
//----------------------------------------------------------------------------
|
||
for(I = 0; I < curveATypeNum - 1; I++)
|
||
{
|
||
if(ATypeNode[I] > 32767) continue;
|
||
if(ATypeNode[I] > calibIndex) break;
|
||
}
|
||
|
||
//----------------------------------------------------------------------------
|
||
if(I == 0) return ATypeVal[0];
|
||
|
||
//----------------------------------------------------------------------------
|
||
Secondary.NodeX = calibIndex;
|
||
if(ATypeNode[I] > 32767) Secondary.NodeH = 0;
|
||
else Secondary.NodeH = ATypeNode[I];
|
||
|
||
if(ATypeNode[I-1] > 32767) Secondary.NodeL = 0;
|
||
else Secondary.NodeL = ATypeNode[I-1];
|
||
|
||
Secondary.ValueH = ATypeVal[I];
|
||
Secondary.ValueL = ATypeVal[I-1];
|
||
|
||
return SecondaryCompute();
|
||
}
|
||
|
||
/******************************************************************************/
|
||
#ifndef ENABLE_DENSITY_DETECT
|
||
#pragma message("[undefined] ENABLE_DENSITY_DETECT")
|
||
#elif(ENABLE_DENSITY_DETECT)
|
||
void GasDensityCompute(void)
|
||
{
|
||
Secondary.NodeH = densityFSParameter;
|
||
Secondary.NodeL = VHHParameterAir;
|
||
Secondary.NodeX = voltageDetected[VHPA];
|
||
|
||
Secondary.ValueH = DENSITY_FS;
|
||
Secondary.ValueL = DENSITY_ZERO;
|
||
|
||
density = SecondaryCompute();
|
||
if(density > Secondary.ValueH) density = Secondary.ValueH;
|
||
}
|
||
#endif
|
||
|