Files
CHJ/user/Compute/ATypeFlowRate.c
2026-03-20 21:16:58 +08:00

137 lines
5.5 KiB
C
Executable File

#include "../main/SystemInclude.h"
unsigned short P0RhLow, P0RhHigh;
float PHeater, P0Heater, A0Heater, B0Heater;
unsigned short switchFIndex, ATypeIndexGain, GDCFactorAType;
/******************************************************************************/
void ComputeABParameter(void)
{
float tempH, tempL;
// compute A0 AND b
// P0_L = A*(1 + B*T0_L)*(TH_L - T0_L) --> 100 * P0_L = A*(10 + B*T0_L)*(TH_L - T0_L)
// P0_H = A*(1 + B*T0_H)*(TH_H - T0_H)
//---------------------------------------------------------------------------
// ¡÷H = TH_H - T0_H,
// ¡÷L = TH_L - T0_L
// B = (P0_H * ¡÷L - P0_L * ¡÷H)/(P0_L * ¡÷H * T0_H - P0_H * ¡÷L * T0_L)
//---------------------------------------------------------------------------
// A = P0_L/( (1 + B * TO_L) * (TH_L - TO_L))
//---------------------------------------------------------------------------
// compute B
// P0_H * ¡÷L
tmpSLA = (unsigned long int)ComputeRHTemperature(NRHLow);
tmpSLA -= (unsigned long int)staticLowTemperature;
tmpSLB = tmpSLA;
tempH = (float)P0RhHigh;
tempH *= (float)tmpSLA;
// P0_L * ¡÷H
tmpSLA = (unsigned long int)ComputeRHTemperature(NRHHigh);
tmpSLA -= (unsigned long int)staticHighTemperature;
tempL = (float)P0RhLow;
tempL *= (float)tmpSLA;
// (P0_H * ¡÷L - P0_L * ¡÷H)
B0Heater = tempH - tempL;
// P0_L * ¡÷H * T0_H
tmpSLA = (unsigned long int)staticHighTemperature;
tmpSLA -= (unsigned long int)TEMPRETURE_OFFSET;
tempL *= (float)tmpSLA;
// P0_H * ¡÷L * T0_L
tmpSLA = (unsigned long int)staticLowTemperature;
tmpSLA -= (unsigned long int)TEMPRETURE_OFFSET;
tempH *= (float)tmpSLA;
// B = (P0_H * ¡÷L - P0_L * ¡÷H)/(P0_L * ¡÷H * T0_H - P0_H * ¡÷L * T0_L)
tempL -= tempH;
B0Heater /= tempL;
B0Heater *= 100;
//---------------------------------------------------------------------------
// compute A
// P0_L = A*(1 + B*T0_L)*(TH_L - T0_L)
// 10000 * P0_L = A*(1 + B*T0_L)*(TH_L - T0_L)*100*100 // Tempreture 2 bit dot
// 10000 * P0_L = A*(100 + B*T0_L)*(TH_L - T0_L)
// 1 + B * TO_L
tmpSLA = (unsigned long int)staticLowTemperature;
tmpSLA -= (unsigned long int)TEMPRETURE_OFFSET;
tempH = B0Heater * (float)tmpSLA;
tempH += 100;
// (100 + B*T0_L)*(TH_L - T0_L)
tempH *= (float)tmpSLB;
// A = P0_L*10000/( (10 + B * TO_L) * (TH_L - TO_L) )
A0Heater = (float)P0RhLow;
//A0Heater *= 100;
A0Heater /= (float)tempH;
}
/******************************************************************************/
void ATypeFlowRateInit(void)
{
P0RhLow = ReadShortParameterFromEEPROM(P0_0_RH, P0_0_RH_WIDTH, 32768);
P0RhHigh = ReadShortParameterFromEEPROM(P0_50_RH, P0_50_RH_WIDTH, 32768);
offsetGasA = ReadShortParameterFromEEPROM(OFFSET_A, OFFSET_A_WIDTH, SDT_ZERO_OFFSET);
switchFIndex = ReadShortParameterFromEEPROM(SWITCH_FR, SWITCH_FR_WIDTH, SWITCH_FR_DEFAULT);
ATypeIndexGain = ReadShortParameterFromEEPROM(ATYPE_INDEX_GAIN, ATYPE_INDEX_GAIN_WIDTH, ATYPE_INDEX_GAIN_DEFAULT);
GDCFactorAType = ReadShortParameterFromEEPROM(GCF_ATYPE, GCF_ATYPE_WIDTH, GCF_ATYPE_DEFAULT);
ComputeABParameter();
}
/******************************************************************************/
void ComputeATypeIndex(void)
{
voltageDetected[TRH] = MovingAverage(voltageDetected[TRH], 30, TRH);
voltageDetected[TGAS] = MovingAverage(voltageDetected[TGAS], 30, TGAS);
//---------------------------------------------------------------------------
// compute P0Heater
// P0Heater = A0Heater * (1 + B0Heater * T0) * (TH - T0)
// 10000 * P0_L = A*(100 + B*T0_L)*(TH_L - T0_L)
tmpSLA = (unsigned long int)voltageDetected[TGAS];
tmpSLA -= (unsigned long int)TEMPRETURE_OFFSET;
P0Heater = (float)tmpSLA;
P0Heater *= B0Heater; // B0Heater * T0
P0Heater += 100; // 100 + B0Heater*T0
P0Heater *= A0Heater; // A*(100 + 100 + B0Heater*T0)
// (TH - T0)
tmpSLA = (signed long int)voltageDetected[TRH];
tmpSLA -= (signed long int)voltageDetected[TGAS];
P0Heater *= (float)tmpSLA; // P0Heater = A0Heater * (1 + B0Heater * T0) * (TH - T0)
//P0Heater /= 100;
voltageDetected[PORH] = (unsigned short)P0Heater; // ÈÈÍ·¾²Ì¬¹¦ÂÊ
//---------------------------------------------------------------------------
tmpSLB = (unsigned long int)voltageDetected[PDRH];
tmpSLB -= (unsigned long int)voltageDetected[PORH];
tmpSLB *= (unsigned long int)100;
tmpSLB *= (unsigned long int)ATypeIndexGain;
tmpSLB /= tmpSLA;
tmpSLB += (unsigned long int)SDT_ZERO_OFFSET;
voltageDetected[SDT] = (unsigned short)tmpSLB;
//voltageDetected[SDT] = MovingAverage(voltageDetected[SDT], 10, SDT);
if(voltageDetected[SDT] > offsetGasA) flowRateIndex[ATYPE_FR] = voltageDetected[SDT] - offsetGasA;
else flowRateIndex[ATYPE_FR] = 0;
// if(isCalibMode) return;
//
// // auto calibration VHH offset
// if(voltageDetected[NVHH] > VHHRoom + (unsigned short)AUTO_OFFSET_NVHH) return;
// if(voltageDetected[NIDX] > offsetGas + (unsigned short)AUTO_OFFSET_NIDX) return;
// if(voltageDetected[NIDX] < offsetGas - (unsigned short)AUTO_OFFSET_NIDX) return;
//
// offsetA = voltageDetected[SDT];
}