NULL
This commit is contained in:
136
user/Compute/ATypeFlowRate.c
Executable file
136
user/Compute/ATypeFlowRate.c
Executable file
@@ -0,0 +1,136 @@
|
||||
#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)
|
||||
//---------------------------------------------------------------------------
|
||||
// <20><>H = TH_H - T0_H,
|
||||
// <20><>L = TH_L - T0_L
|
||||
// B = (P0_H * <20><>L - P0_L * <20><>H)/(P0_L * <20><>H * T0_H - P0_H * <20><>L * T0_L)
|
||||
//---------------------------------------------------------------------------
|
||||
// A = P0_L/( (1 + B * TO_L) * (TH_L - TO_L))
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// compute B
|
||||
// P0_H * <20><>L
|
||||
tmpSLA = (unsigned long int)ComputeRHTemperature(NRHLow);
|
||||
tmpSLA -= (unsigned long int)staticLowTemperature;
|
||||
tmpSLB = tmpSLA;
|
||||
tempH = (float)P0RhHigh;
|
||||
tempH *= (float)tmpSLA;
|
||||
|
||||
// P0_L * <20><>H
|
||||
tmpSLA = (unsigned long int)ComputeRHTemperature(NRHHigh);
|
||||
tmpSLA -= (unsigned long int)staticHighTemperature;
|
||||
tempL = (float)P0RhLow;
|
||||
tempL *= (float)tmpSLA;
|
||||
|
||||
// (P0_H * <20><>L - P0_L * <20><>H)
|
||||
B0Heater = tempH - tempL;
|
||||
|
||||
// P0_L * <20><>H * T0_H
|
||||
tmpSLA = (unsigned long int)staticHighTemperature;
|
||||
tmpSLA -= (unsigned long int)TEMPRETURE_OFFSET;
|
||||
tempL *= (float)tmpSLA;
|
||||
|
||||
// P0_H * <20><>L * T0_L
|
||||
tmpSLA = (unsigned long int)staticLowTemperature;
|
||||
tmpSLA -= (unsigned long int)TEMPRETURE_OFFSET;
|
||||
tempH *= (float)tmpSLA;
|
||||
|
||||
// B = (P0_H * <20><>L - P0_L * <20><>H)/(P0_L * <20><>H * T0_H - P0_H * <20><>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; // <20><>ͷ<EFBFBD><CDB7>̬<EFBFBD><CCAC><EFBFBD><EFBFBD>
|
||||
//---------------------------------------------------------------------------
|
||||
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];
|
||||
}
|
||||
39
user/Compute/ATypeFlowRate.h
Executable file
39
user/Compute/ATypeFlowRate.h
Executable file
@@ -0,0 +1,39 @@
|
||||
/********************************************************************************************************
|
||||
** HY3106<30><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>
|
||||
**
|
||||
** Copyright (c) Siargo, Ltd. 2011
|
||||
** All Rights Reserved.
|
||||
**
|
||||
********************************************************************************************************/
|
||||
#ifndef __ATypeFlowRate_h__
|
||||
#define __ATypeFlowRate_h__
|
||||
|
||||
//******************************************************************************
|
||||
// for memory WIDTH
|
||||
#define P0_0_RH_WIDTH 3
|
||||
#define P0_50_RH_WIDTH 3
|
||||
#define RH_0_WIDTH 3
|
||||
#define RH_50_WIDTH 3
|
||||
#define ATYPE_FR_BASE_WIDTH 12
|
||||
//******************************************************************************
|
||||
// for memory CRC
|
||||
#define P0_0_RH_CRC (P0_0_RH_WIDTH-1)
|
||||
#define P0_50_RH_CRC (P0_50_RH_WIDTH-1)
|
||||
#define RH_0_CRC (RH_0_WIDTH-1)
|
||||
#define RH_50_CRC (RH_50_WIDTH-1)
|
||||
//******************************************************************************
|
||||
// for memory address
|
||||
#define P0_0_RH ATYPE_FR_BASE
|
||||
#define P0_50_RH (P0_0_RH + P0_0_RH_WIDTH)
|
||||
#define RH_0 (P0_50_RH + P0_50_RH_WIDTH)
|
||||
#define RH_50 (RH_0 + RH_0_WIDTH)
|
||||
/******************************************************************************/
|
||||
extern unsigned short P0RhLow, P0RhHigh;
|
||||
extern float PHeater, P0Heater, A0Heater, B0Heater;
|
||||
extern unsigned short switchFIndex, ATypeIndexGain, GDCFactorAType;
|
||||
/******************************************************************************/
|
||||
void ComputeABParameter(void);
|
||||
void ATypeFlowRateInit(void);
|
||||
void ComputeATypeIndex(void);
|
||||
|
||||
#endif
|
||||
560
user/Compute/AccCompute.c
Executable file
560
user/Compute/AccCompute.c
Executable file
@@ -0,0 +1,560 @@
|
||||
#include "../main/SystemInclude.h"
|
||||
//==============================================================================
|
||||
u8 Total[ACC_MAX],Dis2[20];
|
||||
u64 flowTotalBuffer;
|
||||
u32 lastRemaining, AccComputeTimeBase;
|
||||
u16 totalPulse;
|
||||
u8 MemoryPointer;
|
||||
u16 flowAccCumulationRemaining, samplingIntervalForTotal;
|
||||
|
||||
//#define REC_PULSE_REMAINING
|
||||
//#define PULSE_COUNTER
|
||||
|
||||
/******************************************************************************/
|
||||
void ReleaseTotalToDisArray(void)
|
||||
{
|
||||
Dis2[0] = Total[0] >> 4;
|
||||
Dis2[1] = Total[0] & 0x0f;
|
||||
Dis2[2] = Total[1] >> 4;
|
||||
Dis2[3] = Total[1] & 0x0f;
|
||||
Dis2[4] = Total[2] >> 4;
|
||||
Dis2[5] = Total[2] & 0x0f;
|
||||
Dis2[6] = Total[3] >> 4;
|
||||
Dis2[7] = Total[3] & 0x0f;
|
||||
Dis2[8] = Total[4] >> 4;
|
||||
Dis2[9] = Total[4] & 0x0f;
|
||||
Dis2[10] = Total[5] >> 4;
|
||||
Dis2[11] = Total[5] & 0x0f;
|
||||
|
||||
Dis2[12] = Total[MIN_BIT] >> 4;
|
||||
Dis2[13] = Total[MIN_BIT] & 0x0f;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void ReleaseToIntAndDecimalBuf(void)
|
||||
{
|
||||
u16 I;
|
||||
|
||||
flowTotalBuffer = 0;
|
||||
|
||||
for(I=0; I<=ACC_DOT6; I++)
|
||||
{
|
||||
flowTotalBuffer *= 10;
|
||||
flowTotalBuffer += Dis2[I];
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void ReleaseToIntAndDecimalBufForUart(void)
|
||||
{
|
||||
u16 I;
|
||||
u16 DotStartBit;
|
||||
|
||||
flowAccumulationInteger = 0;
|
||||
flowAccumulationDecimal = 0;
|
||||
|
||||
// Update V2006
|
||||
DotStartBit = ACC_DOT1;
|
||||
switch(AccComUnit)
|
||||
{
|
||||
case ML: DotStartBit = ACC_DOT4; break;
|
||||
case SL:
|
||||
if(FR_STD_UNIT == SCCM) DotStartBit = ACC_DOT1;
|
||||
else DotStartBit = ACC_DOT4;
|
||||
break;
|
||||
|
||||
//case NM3: DotStartBit = ACC_DOT1; break;
|
||||
//case SCF: DotStartBit = ACC_DOT1; break;
|
||||
//case PPM: lastUnit = (float)ONE_PPM_TO_STD_ACC; break;
|
||||
//case KG: DotStartBit = ACC_DOT1; break;
|
||||
default: ;
|
||||
}
|
||||
|
||||
#ifndef ACC_INT_7BIT
|
||||
#pragma message("[undefined] ACC_INT_7BIT")
|
||||
#elif(ACC_INT_7BIT)
|
||||
I = DotStartBit - 7;
|
||||
#endif
|
||||
|
||||
#ifndef ACC_INT_6BIT
|
||||
#pragma message("[undefined] ACC_INT_6BIT")
|
||||
#elif(ACC_INT_6BIT)
|
||||
I = DotStartBit - 6;
|
||||
#endif
|
||||
|
||||
#ifndef ACC_INT_8BIT
|
||||
#pragma message("[undefined] ACC_INT_8BIT")
|
||||
#elif(ACC_INT_8BIT)
|
||||
I = DotStartBit - 8;
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
for(; I<DotStartBit; I++)
|
||||
{
|
||||
flowAccumulationInteger *= 10;
|
||||
flowAccumulationInteger += Dis2[I];
|
||||
}
|
||||
|
||||
for(I=DotStartBit; I<DotStartBit+3; I++)
|
||||
{
|
||||
flowAccumulationDecimal *= 10;
|
||||
flowAccumulationDecimal += Dis2[I];
|
||||
}
|
||||
|
||||
flowAccumulationHex = ( signed long long int)flowAccumulationInteger;
|
||||
flowAccumulationHex *= (unsigned long long int)1000;
|
||||
flowAccumulationHex += (unsigned long long int)flowAccumulationDecimal;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
#ifndef ENABLE_ACC_DEC_COMPUTE
|
||||
#pragma message("[undefined] ENABLE_ACC_DEC_COMPUTE")
|
||||
#elif(ENABLE_ACC_DEC_COMPUTE)
|
||||
if(Dis2[0] != 0)
|
||||
{
|
||||
flowAccumulationInteger *= -1;
|
||||
flowAccumulationHex *= -1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void SendToTotalArray(void)
|
||||
{
|
||||
Total[0] = Dis2[0];
|
||||
Total[0] <<= 4;
|
||||
Total[0] += Dis2[1];
|
||||
|
||||
Total[1] = Dis2[2];
|
||||
Total[1] <<= 4;
|
||||
Total[1] += Dis2[3];
|
||||
|
||||
Total[2] = Dis2[4];
|
||||
Total[2] <<= 4;
|
||||
Total[2] += Dis2[5];
|
||||
|
||||
Total[3] = Dis2[6];
|
||||
Total[3] <<= 4;
|
||||
Total[3] += Dis2[7];
|
||||
|
||||
Total[4] = Dis2[8];
|
||||
Total[4] <<= 4;
|
||||
Total[4] += Dis2[9];
|
||||
|
||||
Total[5] = Dis2[10];
|
||||
Total[5] <<= 4;
|
||||
Total[5] += Dis2[11];
|
||||
|
||||
Total[CRC_CHK] = CRC8(Total, 6); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
Total[MIN_BIT] = Dis2[12];
|
||||
Total[MIN_BIT] <<= 4;
|
||||
Total[MIN_BIT] += Dis2[13];
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
// save ACC FlowRate to memeroy
|
||||
u16 FRAMWriteTotal(void)
|
||||
{
|
||||
// write to first bank and second bank and update EPROMPointer
|
||||
// input: voltAcc, voltAcc0, EPROMPointer
|
||||
// output: EPROMPointer
|
||||
u16 blockAddr, I;
|
||||
u8 temp[7], WriteCounter=0;
|
||||
|
||||
FRAMWriteRepeat:
|
||||
MemoryPointer++;
|
||||
WriteCounter++;
|
||||
if (MemoryPointer > REC_ACC_DEPTH) MemoryPointer = 0;
|
||||
if (WriteCounter > REC_ACC_DEPTH) return 1;
|
||||
|
||||
blockAddr = REC_ACC_BASE + MemoryPointer * REC_ACC_WIDTH;
|
||||
WriteMultiByteToFRAM(blockAddr,Total,7);
|
||||
ReadMultiByteFromFRAM(blockAddr,temp,7);
|
||||
|
||||
for(I=0; I < (u16)ACC_BLOCK_WIDTH; I++)
|
||||
{
|
||||
if(temp[I] != Total[I]) goto FRAMWriteRepeat;
|
||||
}
|
||||
|
||||
blockAddr += ACC_BLOCK2_START;
|
||||
WriteMultiByteToFRAM(blockAddr,Total,7);
|
||||
ReadMultiByteFromFRAM(blockAddr,temp,7);
|
||||
for(I=0; I<ACC_BLOCK_WIDTH; I++)
|
||||
{
|
||||
if(temp[I] != Total[I]) goto FRAMWriteRepeat;
|
||||
}
|
||||
|
||||
// blockAddr = REC_PULSE_REMAINING + MemoryPointer * PULSE_REMAINING_WIDTH;
|
||||
// tempDev.DWord[0] = lastRemaining;
|
||||
// tempDev.Byte[PULSE_REMAINING_CRC] = CRC8(tempDev.Byte, PULSE_REMAINING_CRC);
|
||||
// WriteMultiByteToFRAM(blockAddr,tempDev.Byte,PULSE_REMAINING_WIDTH);
|
||||
|
||||
//tempDev.DWord[0] = pulseCounter;
|
||||
//tempDev.Byte[PULSE_COUNTER_CRC] = CRC8(tempDev.Byte, PULSE_COUNTER_CRC);
|
||||
//WriteMultiByteToFRAM(PULSE_COUNTER,tempDev.Byte, PULSE_COUNTER_WIDTH);
|
||||
//ReadMultiByteFromFRAM(PULSE_COUNTER,temp, PULSE_COUNTER_WIDTH);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
// Routines for FRAM <20><><EFBFBD><EFBFBD>ʵʱ<CAB5><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>洢<EFBFBD><E6B4A2>¼ <20><><EFBFBD><EFBFBD> <20><>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD>1 <20><><EFBFBD><EFBFBD>0
|
||||
u16 FRAMCheckSaveTotalFlow(u8 Pointer)
|
||||
{
|
||||
u8 block1[7], block2[7];
|
||||
u16 blockAddr, I;
|
||||
|
||||
blockAddr = REC_ACC_BASE + Pointer * REC_ACC_WIDTH;
|
||||
ReadMultiByteFromFRAM(blockAddr, block1, 7);
|
||||
blockAddr += ACC_BLOCK2_START;
|
||||
ReadMultiByteFromFRAM(blockAddr, block2, 7);
|
||||
|
||||
if(block1[CRC_CHK] != CRC8(block1, 6)) return false;
|
||||
if(block1[CRC_CHK] != block2[CRC_CHK]) return false;
|
||||
for(I=0; I<6; I++)
|
||||
{
|
||||
if(block1[I] != block2[I]) return false;
|
||||
|
||||
block1[I] &= 0x0f;
|
||||
if(block1[I] > 0x09) return false;
|
||||
|
||||
block1[I] &= 0xf0;
|
||||
if(block1[I] > 0x90) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
// Routines for flow calculations
|
||||
u16 RetrieveLastAccumulationFromFRAM(void)
|
||||
{
|
||||
u32 voltPartA, tempPartA;
|
||||
u16 voltPartB, tempPartB;
|
||||
u8 I, max_g;
|
||||
u8 good_ind[REC_ACC_DEPTH+1];
|
||||
|
||||
// if(ReadFRAMDeviceID()) return 0;
|
||||
|
||||
//find EPROMPointer with good data
|
||||
max_g = 0;
|
||||
for(I = 0; I <= REC_ACC_DEPTH; I++) {
|
||||
if(FRAMCheckSaveTotalFlow(I)) { good_ind[max_g] = I; max_g++; }
|
||||
}
|
||||
if(max_g == 0) return 0;
|
||||
|
||||
// among all the valid data, get the largest one
|
||||
voltPartA = 0;
|
||||
voltPartB = 0;
|
||||
MemoryPointer = 0;
|
||||
for(I = 0; I < max_g; I++) {
|
||||
ReadMultiByteFromFRAM(REC_ACC_BASE + (u16)good_ind[I]* REC_ACC_WIDTH, Total, 7);
|
||||
tempL.Byte[3] = Total[0];
|
||||
tempL.Byte[2] = Total[1];
|
||||
tempL.Byte[1] = Total[2];
|
||||
tempL.Byte[0] = Total[3];
|
||||
tempPartA = tempL.DWord;
|
||||
|
||||
tempL.Byte[1] = Total[4];
|
||||
tempL.Byte[0] = Total[5];
|
||||
tempPartB = tempL.Word[0];
|
||||
|
||||
if(voltPartA > tempPartA) continue;
|
||||
else if(voltPartA == tempPartA)
|
||||
{
|
||||
if(voltPartB > tempPartB) continue;
|
||||
}
|
||||
|
||||
voltPartA = tempPartA;
|
||||
voltPartB = tempPartB;
|
||||
MemoryPointer = good_ind[I];
|
||||
}
|
||||
|
||||
ReadMultiByteFromFRAM(REC_ACC_BASE + (u16)MemoryPointer* REC_ACC_WIDTH, Total, 7);
|
||||
ReleaseTotalToDisArray();
|
||||
|
||||
// ReadMultiByteFromFRAM(REC_PULSE_REMAINING+ MemoryPointer * PULSE_REMAINING_WIDTH, tempDev.Byte, PULSE_REMAINING_WIDTH);
|
||||
// if(tempDev.Byte[PULSE_REMAINING_CRC] != CRC8(tempDev.Byte, PULSE_REMAINING_CRC)) lastRemaining = 0;
|
||||
// else lastRemaining = tempDev.DWord[0];
|
||||
|
||||
//ReadMultiByteFromFRAM(PULSE_COUNTER, tempDev.Byte, PULSE_COUNTER_WIDTH);
|
||||
//if(tempDev.Byte[PULSE_COUNTER_CRC] != CRC8(tempDev.Byte, PULSE_COUNTER_CRC)) pulseCounter = 0;
|
||||
//else pulseCounter = tempDev.DWord[0];
|
||||
|
||||
flowAccCumulationRemaining = 0;
|
||||
//lastRemaining = 0;
|
||||
Total[MIN_BIT] = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
// Routines for flow calculations
|
||||
void RetrieveLastAccumulation(void)
|
||||
{
|
||||
u16 I;
|
||||
u8 temp[HISTORY_WIDTH];
|
||||
|
||||
if(RetrieveLastAccumulationFromFRAM()) return;
|
||||
|
||||
flowAccCumulationRemaining = 0;
|
||||
//pulseCounter = 0;
|
||||
lastRemaining = 0;
|
||||
|
||||
//===========================================================================
|
||||
#ifndef REC_HISTORY_DATA
|
||||
#pragma message("[undefined] REC_HISTORY_DATA")
|
||||
#elif(REC_HISTORY_DATA)
|
||||
if(ReadRecentHistoryData(temp))
|
||||
{
|
||||
Total[0] = temp[5];
|
||||
Total[1] = temp[6];
|
||||
Total[2] = temp[7];
|
||||
Total[3] = temp[8];
|
||||
Total[4] = temp[9];
|
||||
Total[5] = temp[10];
|
||||
Total[CRC_CHK] = CRC8(Total, 6);
|
||||
ReleaseTotalToDisArray();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
//===========================================================================
|
||||
#ifndef REC_DATE_DATA
|
||||
#pragma message("[undefined] REC_DATE_DATA")
|
||||
#elif(REC_DATE_DATA)
|
||||
if(ReadRecentDateAccData(temp))
|
||||
{
|
||||
Total[0] = temp[5];
|
||||
Total[1] = temp[6];
|
||||
Total[2] = temp[7];
|
||||
Total[3] = temp[8];
|
||||
Total[4] = temp[9];
|
||||
Total[5] = temp[10];
|
||||
Total[CRC_CHK] = CRC8(Total, 6);
|
||||
ReleaseTotalToDisArray();
|
||||
}
|
||||
#endif
|
||||
|
||||
for (I = 0; I < CRC_CHK; I++) Total[I] = 0;
|
||||
Total[CRC_CHK] = CRC8(Total, CRC_CHK);
|
||||
ReleaseTotalToDisArray();
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void BcdIncOperate(u8 *addendA, u8 *addendB)
|
||||
{
|
||||
u16 Symbol = 0;
|
||||
|
||||
for(u16 I = 13; ; I--)
|
||||
{
|
||||
addendA[I] += addendB[I];
|
||||
addendA[I] += Symbol;
|
||||
if(addendA[I] >= 10) { Symbol = 1; addendA[I] -= 10; }
|
||||
else Symbol = 0;
|
||||
|
||||
if(I==0) break;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void BcdDecOperate(u8 *minuend, u8 *subtrahend)
|
||||
{
|
||||
for(u16 I=13; I>0 ; I--){
|
||||
if(minuend[I] >= subtrahend[I]) minuend[I] -= subtrahend[I];
|
||||
else {
|
||||
minuend[I] += 10;
|
||||
minuend[I] -= subtrahend[I];
|
||||
subtrahend[I-1]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
/******************************************************************************/
|
||||
// compute acc flowrate
|
||||
//void ComputeFlowRateToTotal(void)
|
||||
void ComputeFlowRateToTotal(void)
|
||||
{
|
||||
u32 tempInt;
|
||||
u8 tempF[14];
|
||||
// V2004
|
||||
// FRUnitForHour: <20>Ŵ<EFBFBD>1000<30><30>
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><><EFBFBD>궨<EFBFBD><EAB6A8>λ<EFBFBD><CEBB>SLPM, NCMH
|
||||
// [8λ<38><CEBB><EFBFBD><EFBFBD>ģʽ]<5D>ܹ<EFBFBD><DCB9><EFBFBD><EFBFBD><EFBFBD>14λ: 12345678.123456<EFBFBD><EFBFBD><EFBFBD>ܹ<EFBFBD>6λС<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŵ<EFBFBD>1000<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 12345678.1234 4λС<CEBB><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2λ56<35><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>鼰<EFBFBD><E9BCB0><EFBFBD><EFBFBD>
|
||||
// [8λ<38><CEBB><EFBFBD><EFBFBD>ģʽ]<5D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λΪSLPM<50><4D>NCMHʱ<48><CAB1><EFBFBD><EFBFBD>С<EFBFBD><D0A1>λ 1mL
|
||||
// [8λ<38><CEBB><EFBFBD><EFBFBD>ģʽ]Flow Unit = SLPM: (((Flow*60)/1000)*1000)/TimeBase
|
||||
// [8λ<38><CEBB><EFBFBD><EFBFBD>ģʽ]Flow Unit = NCMH: (Flow*1000)/TimeBase
|
||||
// [6λ<36><CEBB><EFBFBD><EFBFBD>ģʽ]<5D>ܹ<EFBFBD><DCB9><EFBFBD><EFBFBD><EFBFBD>14λ: 123456.78123456<EFBFBD><EFBFBD><EFBFBD>ܹ<EFBFBD>8λС<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŵ<EFBFBD>100000<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 123456.781234 6λС<CEBB><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2λ56<35><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>鼰<EFBFBD><E9BCB0><EFBFBD><EFBFBD>
|
||||
// if FR_STD_UNIT = SCCM, ACC_UNIT = SL, 12345678.123456 SL
|
||||
// if FR_STD_UNIT = SLPM, ACC_UNIT = NM3, 12345678.123456 NM3
|
||||
// if FR_STD_UNIT = NCMH, ACC_UNIT = NM3, 12345678.123456 NM3
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>ͬһ<CDAC><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>ϣ<EFBFBD><CFA3><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>Ŵ<EFBFBD>1000
|
||||
|
||||
/****************************************************************************/
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϣ<D0B6>
|
||||
/****************************************************************************/
|
||||
// <20><>֤λ<D6A4><CEBB><EFBFBD><EFBFBD><EFBFBD>㲻<EFBFBD><E3B2BB><EFBFBD><EFBFBD>
|
||||
// Step 1: A = Flow / (time <20><><EFBFBD><EFBFBD>)
|
||||
// Step 2: B = Flow - A * (time <20><><EFBFBD><EFBFBD>)
|
||||
// Step 3: B *= 1000; A *= 1000; // <20><><EFBFBD><EFBFBD><EFBFBD>Ŵ<EFBFBD>
|
||||
// Step 4: B += flowAccCumulationRemaining; // <20>ϴμ<CFB4><CEBC><EFBFBD>ʣ<EFBFBD><CAA3>
|
||||
// Step 5: C = B/(time <20><><EFBFBD><EFBFBD>)
|
||||
// Step 6: A += C (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)<29><>flowAccCumulationRemaining = B-C*(time <20><><EFBFBD><EFBFBD>)
|
||||
tmpIA = ConvertTimeBaseAndUnit(flowComUnit, samplingIntervalForTotal);
|
||||
//------------------------------------------------------------------------------
|
||||
#ifndef ENABLE_FLOW_GAIN
|
||||
#pragma message("[undefined] ENABLE_FLOW_GAIN")
|
||||
#elif(ENABLE_FLOW_GAIN)
|
||||
if(tmpIA < calibFlowGain) AccComputeTimeBase *= (u32)calibFlowGain;
|
||||
else tmpIA /= calibFlowGain;
|
||||
#endif
|
||||
//------------------------------------------------------------------------------
|
||||
tempInt = (u32)flowRate/(u32)AccComputeTimeBase;
|
||||
tmpLB = flowRate - tempInt*AccComputeTimeBase;
|
||||
tempInt *= (u32)tmpIA;
|
||||
|
||||
tmpLB = tmpLB*(u32)tmpIA + flowAccCumulationRemaining;
|
||||
tmpLA = tmpLB/(u32)AccComputeTimeBase;
|
||||
tempInt += tmpLA;
|
||||
flowAccCumulationRemaining = tmpLB - tmpLA*(u32)AccComputeTimeBase;
|
||||
|
||||
// ȷ<><C8B7><EFBFBD>ѱ<EFBFBD><D1B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// Determine the total flow
|
||||
if(Total[CRC_CHK] != CRC8(Total, 6)) RetrieveLastAccumulation();
|
||||
ReleaseTotalToDisArray();
|
||||
tempF[0] = 0;
|
||||
tempF[1] = 0;
|
||||
tempF[2] = 0;
|
||||
tempF[3] = 0;
|
||||
//------------------------------------------------------------------------------
|
||||
#ifndef ENABLE_ACC_GAIN
|
||||
#pragma message("[undefined] ENABLE_ACC_GAIN")
|
||||
#elif(ENABLE_ACC_GAIN)
|
||||
if(currentMode.Bit.CalibMode) ConvertHEXToBCDArray(tempInt, &tempF[4], 10, HIGH_FIRST);
|
||||
else ConvertHEXToBCDArray(tempInt*102/100), &tempF[4], 10, HIGH_FIRST);
|
||||
#else
|
||||
ConvertHEXToBCDArray(tempInt, &tempF[4], 10, HIGH_FIRST);
|
||||
#endif
|
||||
//------------------------------------------------------------------------------
|
||||
// V2004
|
||||
#ifndef ENABLE_ACC_DEC_COMPUTE
|
||||
#pragma message("[undefined] ENABLE_ACC_DEC_COMPUTE")
|
||||
#elif(ENABLE_ACC_DEC_COMPUTE)
|
||||
u16 Symbol, I;
|
||||
|
||||
if(Dis2[0] != 0) BcdIncOperate(Dis2, tempF);
|
||||
else {
|
||||
if(CompareAcc(Dis2, tempF)) {
|
||||
BcdDecOperate(tempF, Dis2);
|
||||
Dis2[0] = 1;
|
||||
}
|
||||
else BcdDecOperate(Dis2, tempF);
|
||||
}
|
||||
tempF[0] = 0;
|
||||
tempF[1] = 0;
|
||||
tempF[2] = 0;
|
||||
tempF[3] = 0;
|
||||
ConvertHEXToBCDArray(alarmAcc, &tempF[4], 10, HIGH_FIRST); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
isAlarmAcc = CompareAcc(Dis2, tempF)
|
||||
#else
|
||||
BcdIncOperate(Dis2, tempF);
|
||||
#endif
|
||||
//------------------------------------------------------------------------------
|
||||
SendToTotalArray();
|
||||
Total[CRC_CHK] = CRC8(Total, 6);
|
||||
//------------------------------------------------------------------------------
|
||||
#ifndef ENABLE_ACCPULSE
|
||||
#pragma message("[undefined] ENABLE_ACCPULSE")
|
||||
#elif(ENABLE_ACCPULSE)
|
||||
// lastRemaining += (u32)tempInt;
|
||||
// totalPulse = (u16)(lastRemaining / unitPerPulse);
|
||||
// lastRemaining -= (u32)totalPulse * (u32)unitPerPulse;
|
||||
// if(totalPulse > MaxPulseOutput[samplingIntervalForTotal]) totalPulse = MaxPulseOutput[samplingIntervalForTotal];
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#ifndef REC_ACC_PER
|
||||
#pragma message("[undefined] REC_ACC_PER")
|
||||
#elif(REC_ACC_PER)
|
||||
FRAMWriteTotal();
|
||||
#endif
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void ReadACCFRByCom(void)
|
||||
{
|
||||
u16 I;
|
||||
|
||||
for(I=0; I<12; I++) MBBuf.RxPointer[MBBuf.Index++] = Dis2[I]+0x30;
|
||||
MBBuf.DataByte = 12;
|
||||
ModbusVariablePointerDec();
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void SetupACCArray(void)
|
||||
{
|
||||
u16 I;
|
||||
|
||||
lastRemaining = 0;
|
||||
//pulseCounter = 0;
|
||||
flowAccCumulationRemaining = 0;
|
||||
|
||||
SendToTotalArray();
|
||||
ReleaseToIntAndDecimalBufForUart();
|
||||
|
||||
#ifndef REC_ACC_PER
|
||||
#pragma message("[undefined] REC_ACC_PER")
|
||||
#elif(REC_ACC_PER)
|
||||
for(I=0; I <= REC_ACC_DEPTH; I++) FRAMWriteTotal();
|
||||
#endif
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void WriteACCFRByCom(void)
|
||||
{
|
||||
MBBuf.DataByte = 12;
|
||||
if(MBBuf.ByteNumber < 12)
|
||||
{
|
||||
MBBuf.ByteNumber = 0;
|
||||
MBBuf.BusError = ILLEGAL_DATA_VALUE;
|
||||
return;
|
||||
}
|
||||
|
||||
u8 I, K;
|
||||
|
||||
for(I=0; I<12; I++)
|
||||
{
|
||||
K = MBBuf.RxPointer[MBBuf.Index++];
|
||||
|
||||
if(K == 0x20) Dis2[I] = 0;
|
||||
else if((K < 0x30) || (K > 0x39))
|
||||
{
|
||||
MBBuf.BusError = ILLEGAL_DATA_VALUE;
|
||||
MBBuf.ByteNumber = 0;
|
||||
return;
|
||||
}
|
||||
else Dis2[I] = K & 0x0f;
|
||||
}
|
||||
|
||||
Dis2[12] = 0;
|
||||
Dis2[13] = 0;
|
||||
SetupACCArray();
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void ClearACC(void)
|
||||
{
|
||||
u8 I;
|
||||
|
||||
for(I=0; I<14; I++) Dis2[I] = 0;
|
||||
SetupACCArray();
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
u16 CompareAcc(u8 *compaerA, u8 *compaerB)
|
||||
{
|
||||
if(compaerA[0] != 0) return 1;
|
||||
for(u16 I=1; I<14; I++)
|
||||
{
|
||||
if(compaerA[I] > compaerB[I]) return 0;
|
||||
else if(compaerA[I] < compaerB[I]) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
98
user/Compute/AccCompute.h
Executable file
98
user/Compute/AccCompute.h
Executable file
@@ -0,0 +1,98 @@
|
||||
/********************************************************************************************************
|
||||
**-------------------------------------------------------------------------------------------------------
|
||||
********************************************************************************************************/
|
||||
#ifndef __AccCompute_h__
|
||||
#define __AccCompute_h__
|
||||
|
||||
//for Accumulation Flowrate define
|
||||
#define HIGHEST_INTEGER 0
|
||||
#define LOWEST_DECIMAL 5
|
||||
#define CRC_CHK 6
|
||||
#define MIN_BIT 7 // <20><><EFBFBD><EFBFBD>С<EFBFBD><D0A1>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뱣<EFBFBD><EBB1A3><EFBFBD><EFBFBD>CRCЧ<43><D0A7>
|
||||
#define ACC_MAX 8
|
||||
|
||||
//#define ACC_INT1 0
|
||||
//#define ACC_INT2 1
|
||||
//#define ACC_INT3 2
|
||||
//#define ACC_INT4 3
|
||||
//#define ACC_INT5 4
|
||||
//#define ACC_INT6 5
|
||||
//#define ACC_INT7 6
|
||||
//#define ACC_INT8 7
|
||||
//#define ACC_INT9 8
|
||||
//#define ACC_INT10 9
|
||||
//#define ACC_INT11 10
|
||||
//#define ACC_INT12 11
|
||||
//#define ACC_INT13 12
|
||||
//#define ACC_INT14 13
|
||||
|
||||
#define ACC_INT1 0
|
||||
#define ACC_INT2 1
|
||||
#define ACC_INT3 2
|
||||
#define ACC_INT4 3
|
||||
#define ACC_INT5 4
|
||||
#define ACC_INT6 5
|
||||
#define ACC_INT7 6
|
||||
#define ACC_INT8 7
|
||||
#define ACC_DOT1 8 //total:12, 4Decimal
|
||||
#define ACC_DOT2 9 //total:12, 4Decimal
|
||||
#define ACC_DOT3 10 //total:12, 4Decimal
|
||||
#define ACC_DOT4 11 //total:12, 4Decimal
|
||||
#define ACC_DOT5 12 //total:12, 4Decimal
|
||||
#define ACC_DOT6 13 //total:12, 4Decimal
|
||||
#define ACC_END 14 //total:12, 4Decimal
|
||||
|
||||
#define ACC_DOT ACC_INT9 //total:12, 4Decimal
|
||||
#define ACC_DOT_END 12 //total:11, 4Decimal
|
||||
#define ACC_DOT_BIT4 12
|
||||
|
||||
#define UART_ACC_DOT ACC_INT9 //total:11, 3Decimal
|
||||
#define UART_ACC_DOT_END 11 //total:11, 3Decimal
|
||||
#define ACC_DOT_BIT3 11
|
||||
|
||||
//******************************************************************************
|
||||
// ACC Data save
|
||||
// For FRAM(< 0x0800)
|
||||
// For EEPROM(< 0x0200)
|
||||
//#define REC_BASE 0x0100 // the start EEPROM address of acc data
|
||||
//#define REC_WIDTH 14
|
||||
//#define BLOCK_WIDTH 7 // 0x100(256) + 14*4 = 0x138(312)
|
||||
//#define BLOCK2_START 0x140 // 0x180(256) + 14*4 = 0x1B8
|
||||
//#define REC_DEPTH 4
|
||||
|
||||
//#define REC_PULSE_REMAINING 0x01D0 // 0x1D0(256) + 20 = 0x1E4
|
||||
//#define PULSE_REMAINING_WIDTH 5
|
||||
//#define PULSE_REMAINING_CRC (PULSE_REMAINING_WIDTH-1)
|
||||
|
||||
//#define PULSE_COUNTER 0x01F0 // 0x1D0(256) + 20 = 0x1E4
|
||||
//#define PULSE_COUNTER_WIDTH 5
|
||||
//#define PULSE_COUNTER_CRC (PULSE_COUNTER_WIDTH-1)
|
||||
//------------------------------------------------------------------------------
|
||||
//#define REC_BASE_WIDTH ()
|
||||
|
||||
//******************************************************************************
|
||||
extern u8 Total[], Dis2[];
|
||||
extern u8 MemoryPointer;
|
||||
extern u64 flowTotalBuffer;
|
||||
extern u32 lastRemaining, AccComputeTimeBase;
|
||||
extern u16 totalPulse;
|
||||
//extern float flowAccCumulationRemaining;
|
||||
extern u16 flowAccCumulationRemaining, samplingIntervalForTotal;
|
||||
//******************************************************************************
|
||||
void ReleaseTotalToDisArray(void);
|
||||
void ReleaseToIntAndDecimalBuf(void);
|
||||
void ReleaseToIntAndDecimalBufForUart(void);
|
||||
void SendToTotalArray(void);
|
||||
u16 FRAMWriteTotal(void);
|
||||
u16 FRAMCheckSaveTotalFlow(u8 Pointer);
|
||||
u16 RetrieveLastAccumulationFromFRAM(void);
|
||||
void RetrieveLastAccumulation(void);
|
||||
void ComputeFlowRateToTotal(void);
|
||||
void ReadACCFRByCom(void);
|
||||
void SetupACCArray(void);
|
||||
void WriteACCFRByCom(void);
|
||||
void ClearACC(void);
|
||||
u16 CompareAcc(u8 *compaerA, u8 *compaerB);
|
||||
//******************************************************************************
|
||||
#endif
|
||||
//******************************************************************************
|
||||
230
user/Compute/AdjustOffset.c
Executable file
230
user/Compute/AdjustOffset.c
Executable file
@@ -0,0 +1,230 @@
|
||||
#include "../main/SystemInclude.h"
|
||||
|
||||
u16 ATypeWiper, CTypeWiper, MaxCTypeWiper, MinCTypeWiper, ATypeRC, actualRC, RRRHRatio;
|
||||
u16 OffsetHigh, OffsetLow, MEMSRatio;
|
||||
u16 MaxCTypeWiper, MinCTypeWiper;
|
||||
u16 actualRC, RRRHRatio;
|
||||
|
||||
//==============================================================================
|
||||
void ComputRRRHRatio(void)
|
||||
{
|
||||
float TempF;
|
||||
|
||||
//==============================================================================
|
||||
#ifndef ENABLE_RATIO_HIGH
|
||||
#pragma message("[undefined] ENABLE_RATIO_HIGH")
|
||||
#elif(ENABLE_RATIO_HIGH)
|
||||
|
||||
TempF = (float)ATYPE_PER_POT;
|
||||
TempF *= (float)ATypeWiper;
|
||||
|
||||
tmpLA = (unsigned long int)TempF;
|
||||
tmpLA += (unsigned long int)ATYPE_RA;
|
||||
tmpLA *= 10;
|
||||
tmpLA /= (unsigned long int)VHH_R56;
|
||||
RRRHRatio = (unsigned int)tmpLA;
|
||||
|
||||
actualRC = ATypeRC*10;
|
||||
#else
|
||||
|
||||
TempF = (float)ATYPE_PER_POT;
|
||||
TempF *= (float)ATypeWiper;
|
||||
|
||||
actualRC = (unsigned int)TempF;
|
||||
RRRHRatio = ATYPE_ADJUST_RES - actualRC;
|
||||
actualRC += ATypeRC*10;
|
||||
|
||||
RRRHRatio += ATYPE_RA;
|
||||
tmpLA = (unsigned long int)RRRHRatio;
|
||||
tmpLA *= 10;
|
||||
tmpLA /= (unsigned long int)VHH_R56;
|
||||
RRRHRatio = (unsigned int)tmpLA;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void AutoComputeATypeRC(void)
|
||||
{
|
||||
#ifndef ENABLE_USE_ATYPE_DCP
|
||||
#pragma message("[undefined] ENABLE_USE_ATYPE_DCP")
|
||||
#elif(ENABLE_USE_ATYPE_DCP)
|
||||
unsigned int lastWiper;
|
||||
currentMode.Bit.DigitOutput = 0;
|
||||
|
||||
lastWiper = ATypeWiper;
|
||||
if(voltageDetected[NVOL] < 1600)
|
||||
{
|
||||
MaxCTypeWiper = ATypeWiper;
|
||||
ATypeWiper = (ATypeWiper + MinCTypeWiper)>>1;
|
||||
}
|
||||
else if(voltageDetected[NVOL] > 1620)
|
||||
{
|
||||
MinCTypeWiper = ATypeWiper;
|
||||
ATypeWiper = (ATypeWiper + MaxCTypeWiper)>>1;
|
||||
}
|
||||
|
||||
if(lastWiper == ATypeWiper)
|
||||
{
|
||||
ComputRRRHRatio();
|
||||
tmpLA = (unsigned long int)voltageDetected[NRH];
|
||||
tmpLA *= (unsigned long int)RRRHRatio;
|
||||
tmpLA -= (unsigned long int)actualRC*100;
|
||||
tmpLA /= voltageDetected[LRH];
|
||||
voltageDetected[RATO] = (unsigned int)tmpLA;
|
||||
|
||||
// compute Wiper step 1
|
||||
tmpLA *= VHH_R56_X10; // RATO*112
|
||||
tmpLA -= (unsigned long int)ATYPE_RA; // RATO*112 - 510
|
||||
tmpLA = (unsigned long int)ATYPE_ADJUST_RES - tmpLA; // 100-(RATO*112 - 510)
|
||||
|
||||
// compute NEW RC
|
||||
actualRC = (unsigned int)(ATYPE_ADJUST_RES - tmpLA);
|
||||
tmpLB = voltageDetected[NRH] - voltageDetected[LRH];
|
||||
tmpLB *= voltageDetected[RATO];
|
||||
actualRC = (unsigned long int)(tmpLB - (unsigned int)actualRC);
|
||||
|
||||
// compute Wiper step 2
|
||||
tmpLA *= 256;
|
||||
tmpLA /= (unsigned long int)ATYPE_ADJUST_RES;
|
||||
ATypeWiper = (unsigned int)tmpLA;
|
||||
|
||||
//tempL.Word[0] = ATypeWiper;
|
||||
//ATypeWiper = (unsigned int)WriteShortParameterToEEPROM(ATYPE_WIPER, CTYPE_WIPER_WIDTH);
|
||||
|
||||
printf("RO= %5lu\n", (unsigned long int)voltageDetected[RATO]); //
|
||||
printf("RC= %5lu\n", (unsigned long int)actualRC);
|
||||
printf("WP= %5lu\n", (unsigned long int)ATypeWiper);
|
||||
printf("\n\n");
|
||||
|
||||
StartDMAForTxdData();
|
||||
|
||||
calibType = 0;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void AdjustOffsetInit(void)
|
||||
{
|
||||
//=====================================================================
|
||||
#ifndef ENABLE_USE_CTYPE_DCP
|
||||
#pragma message("[undefined] ENABLE_USE_CTYPE_DCP")
|
||||
#elif(ENABLE_USE_CTYPE_DCP)
|
||||
CTypeWiper = (u16)ReadParameterFromMemory(CTYPE_WIPER, CTYPE_WIPER_WIDTH, CTYPE_WIPER_DEFAULT);
|
||||
#endif
|
||||
|
||||
//=====================================================================
|
||||
#ifndef ENABLE_USE_ATYPE_DCP
|
||||
#pragma message("[undefined] ENABLE_USE_ATYPE_DCP")
|
||||
#elif(ENABLE_USE_ATYPE_DCP)
|
||||
ATypeWiper = (u16)ReadParameterFromMemory(ATYPE_WIPER, ATYPE_WIPER_WIDTH, ATYPE_WIPER_DEFAULT);
|
||||
ATypeRC = (u16)ReadParameterFromMemory(ATYPE_RC, ATYPE_RC_WIDTH, ATYPE_RC_DEFAULT);
|
||||
MEMSRatio = (u16)ReadParameterFromMemory(MEMS_RATIO, MEMS_RATIO_WIDTH, 0);
|
||||
ComputRRRHRatio();
|
||||
#endif
|
||||
|
||||
OffsetLow = (u16)ReadParameterFromMemory(OFFSET_00, OFFSET_00_WIDTH, 32768);
|
||||
OffsetHigh = (u16)ReadParameterFromMemory(OFFSET_50, OFFSET_50_WIDTH, 32768);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
signed int ComputeOffsetDrift(void)
|
||||
{
|
||||
tmpSLA = (unsigned long int)voltageDetected[TGAS];
|
||||
tmpSLA -= (unsigned long int)calibTemperature;
|
||||
|
||||
tmpSLB = (unsigned long int)OffsetHigh;
|
||||
tmpSLB -= (unsigned long int)OffsetLow;
|
||||
tmpSLA *= tmpSLB;
|
||||
|
||||
tmpSLB = (unsigned long int)staticHighTemperature;
|
||||
tmpSLB -= (unsigned long int)staticLowTemperature;
|
||||
tmpSLA /= tmpSLB;
|
||||
|
||||
return (signed int)tmpSLA;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
signed int ComputeOffsetCorrectValue(unsigned int offsetHigh, unsigned int offsetLow)
|
||||
{
|
||||
tmpSLA = (unsigned long int)voltageDetected[TGAS];
|
||||
tmpSLA -= (unsigned long int)calibTemperature;
|
||||
|
||||
tmpSLB = (unsigned long int)offsetHigh;
|
||||
tmpSLB -= (unsigned long int)offsetLow;
|
||||
tmpSLA *= tmpSLB;
|
||||
|
||||
tmpSLB = (unsigned long int)staticHighTemperature;
|
||||
tmpSLB -= (unsigned long int)staticLowTemperature;
|
||||
tmpSLA /= tmpSLB;
|
||||
|
||||
return (signed int)tmpSLA;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void ComputeOffsetDriftInit(void)
|
||||
{
|
||||
voltageDetected[TGAS] = calibTemperature;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void AutoAdjustCTypeWiper(void)
|
||||
{
|
||||
unsigned int lastWiper;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#ifndef POT_INC_AND_VALUE_DEC
|
||||
#pragma message("[undefined] POT_INC_AND_VALUE_DEC")
|
||||
#elif(POT_INC_AND_VALUE_DEC)
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
lastWiper = CTypeWiper;
|
||||
if(voltageDetected[NVDU] > 32788)
|
||||
{
|
||||
MinCTypeWiper = CTypeWiper;
|
||||
CTypeWiper = (CTypeWiper + MaxCTypeWiper)>>1;
|
||||
}
|
||||
else if(voltageDetected[NVDU] < 32748)
|
||||
{
|
||||
MaxCTypeWiper = CTypeWiper;
|
||||
CTypeWiper = (CTypeWiper + MinCTypeWiper)>>1;
|
||||
}
|
||||
|
||||
if(lastWiper == CTypeWiper)
|
||||
{
|
||||
tempL.Word[0] = CTypeWiper;
|
||||
CTypeWiper = (unsigned int)WriteShortParameterToEEPROM(CTYPE_WIPER, CTYPE_WIPER_WIDTH);
|
||||
calibType = 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#else
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
lastWiper = CTypeWiper;
|
||||
if(voltageDetected[VDUX] > 32788)
|
||||
{
|
||||
MaxCTypeWiper = CTypeWiper;
|
||||
CTypeWiper = (CTypeWiper + MinCTypeWiper)>>1;
|
||||
}
|
||||
else if(voltageDetected[VDUX] < 32748)
|
||||
{
|
||||
MinCTypeWiper = CTypeWiper;
|
||||
CTypeWiper = (CTypeWiper + MaxCTypeWiper)>>1;
|
||||
}
|
||||
|
||||
if(lastWiper == CTypeWiper)
|
||||
{
|
||||
tempL.Word[0] = CTypeWiper;
|
||||
CTypeWiper = (unsigned int)WriteShortParameterToEEPROM(CTYPE_WIPER, CTYPE_WIPER_WIDTH);
|
||||
calibType = 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#endif
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
40
user/Compute/AdjustOffset.h
Executable file
40
user/Compute/AdjustOffset.h
Executable file
@@ -0,0 +1,40 @@
|
||||
/********************************************************************************************************
|
||||
**-------------------------------------------------------------------------------------------------------
|
||||
********************************************************************************************************/
|
||||
#ifndef __AdjustOffset_h__
|
||||
#define __AdjustOffset_h__
|
||||
|
||||
//******************************************************************************
|
||||
// parameter limit
|
||||
#define ATYPE_WIPER_MIN 0
|
||||
#define ATYPE_WIPER_MAX POT_MAX
|
||||
#define ATYPE_WIPER_DEFAULT POT_DEFAULT
|
||||
|
||||
#define CTYPE_WIPER_MIN 0
|
||||
#define CTYPE_WIPER_MAX POT_MAX
|
||||
#define CTYPE_WIPER_DEFAULT POT_DEFAULT
|
||||
|
||||
#define ATYPE_RC_MIN 0
|
||||
#define ATYPE_RC_MAX 1000
|
||||
#define ATYPE_RC_DEFAULT 430
|
||||
|
||||
#define ATYPE_RA 5100 //(5100-510.0)
|
||||
#define ATYPE_RB VHH_R56
|
||||
#define ATYPE_ADJUST_RES 1000 //(100.0)
|
||||
#define ATYPE_PER_POT (float)((float)ATYPE_ADJUST_RES/(float)256)
|
||||
//******************************************************************************
|
||||
|
||||
extern u16 ATypeWiper, CTypeWiper, MaxCTypeWiper, MinCTypeWiper, ATypeRC, actualRC, RRRHRatio;
|
||||
extern u16 OffsetHigh, OffsetLow, MEMSRatio;
|
||||
//------------------------------------------------------------------------------
|
||||
void ComputRRRHRatio(void);
|
||||
void AdjustOffsetInit(void);
|
||||
signed int ComputeOffsetDrift(void);
|
||||
signed int ComputeOffsetCorrectValue(unsigned int offsetHigh, unsigned int offsetLow);
|
||||
void ComputeOffsetDriftInit(void);
|
||||
void AutoAdjustCTypeWiper(void);
|
||||
void AutoComputeATypeRC(void);
|
||||
|
||||
//******************************************************************************
|
||||
#endif
|
||||
//******************************************************************************
|
||||
144
user/Compute/CheckSystemVoltage.c
Executable file
144
user/Compute/CheckSystemVoltage.c
Executable file
@@ -0,0 +1,144 @@
|
||||
#include "../main/SystemInclude.h"
|
||||
//==============================================================================
|
||||
|
||||
u16 batteryTestPeriod, batteryTestPeriodSet;
|
||||
|
||||
//******************************************************************************
|
||||
void CheckSystemVoltageInit(void)
|
||||
{
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
void CheckBatteryVoltageInit(void)
|
||||
{
|
||||
//BATOP_POWER_OUTPUT();
|
||||
//TURN_ON_BATOP_POWER();
|
||||
|
||||
//==============================================================================
|
||||
#ifndef ENABLE_BAT_SEL_PIN
|
||||
#pragma message("[undefined] ENABLE_BAT_SEL_PIN")
|
||||
#elif(ENABLE_BAT_SEL_PIN)
|
||||
BATOP_SEL_OUTPUT();
|
||||
SELECT_MAIN_BAT();
|
||||
#endif
|
||||
//==============================================================================
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
u16 ComputeVoltage(u16 codeVol)
|
||||
{
|
||||
tmpLA = (u32)codeVol;
|
||||
tmpLA *= 400; //for vref=2.0V
|
||||
tmpLA >>= 10;
|
||||
|
||||
return (u16)tmpLA;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
u16 ReadAndComputeVoltage(void)
|
||||
{
|
||||
return ComputeVoltage(1);
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
void CheckEndIntoLowPower(void)
|
||||
{
|
||||
//TURN_OFF_BATOP_POWER();
|
||||
|
||||
//============================================================================
|
||||
#ifndef ENABLE_BAT_SEL_PIN
|
||||
#pragma message("[undefined] ENABLE_BAT_SEL_PIN")
|
||||
#elif(ENABLE_BAT_SEL_PIN)
|
||||
BATOP_SEL_OUTPUT();
|
||||
SELECT_RF_BAT();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
void JudgeSystemVolState(void)
|
||||
{
|
||||
// systemVoltage = 271; //FY
|
||||
// batteryVoltage = 278;
|
||||
|
||||
|
||||
#ifndef DISABLE_BAT_ALARM
|
||||
#pragma message("[undefined] DISABLE_BAT_ALARM")
|
||||
#elif(DISABLE_BAT_ALARM)
|
||||
systemAlarm.Bit.BatteryAlarm = 0;
|
||||
systemAlarm.Bit.BatteryOff = 0;
|
||||
#else
|
||||
//<2F>жϸ<D0B6><CFB8><EFBFBD><EFBFBD><EFBFBD>״̬
|
||||
systemAlarm.Bit.BatteryAlarm = 0;
|
||||
systemAlarm.Bit.BatteryOff = 0;
|
||||
|
||||
batteryGrid = 0;
|
||||
if(batteryVoltage >= VOLTAGE_315) batteryGrid = 4;
|
||||
else if(batteryVoltage >= VOLTAGE_310) batteryGrid = 3;
|
||||
else if(batteryVoltage >= VOLTAGE_305) batteryGrid = 2;
|
||||
else if(batteryVoltage >= VOLTAGE_300) batteryGrid = 1;
|
||||
|
||||
if(batteryGrid > 0) return;
|
||||
batteryGrid = 0;
|
||||
systemAlarm.Bit.BatteryAlarm = 1;
|
||||
HWState.EnableCheck = 1;
|
||||
sampleState.EnableRoughTest = 0;
|
||||
roughTestCounter = 0;
|
||||
|
||||
// if(batteryVoltage < systemVoltage )
|
||||
// {
|
||||
// HWState.EnableCheck = 1;
|
||||
// sampleState.EnableRoughTest = 0;
|
||||
// roughTestCounter = 0;
|
||||
// }
|
||||
|
||||
currentMode.Bit.TurnOffSystem = 0;
|
||||
if(systemVoltage < TURN_OFF_SYSTEM)
|
||||
{
|
||||
SysVolErrorCount++;
|
||||
if(SysVolErrorCount < 16) return;
|
||||
|
||||
SysVolErrorCount = 16;
|
||||
currentMode.Bit.TurnOffSystem = 1;
|
||||
systemAlarm.Bit.BatteryAlarm = 1;
|
||||
systemAlarm.Bit.BatteryOff = 1;
|
||||
HWState.EnableCheck = 0;
|
||||
}
|
||||
else SysVolErrorCount = 0;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
void CheckSystemAndBatteryVoltage(void)
|
||||
{
|
||||
batteryTestPeriodSet = 0;
|
||||
batteryTestPeriod = (u16)ReadParameterFromMemory(BATTEST_PERIOD, BATTEST_PERIOD_WIDTH, BATTEST_PERIOD_DEFAULT);
|
||||
|
||||
//BATOP_POWER_OUTPUT();
|
||||
//TURN_ON_BATOP_POWER();
|
||||
|
||||
//==============================================================================
|
||||
#ifndef ENABLE_BAT_SEL_PIN
|
||||
#pragma message("[undefined] ENABLE_BAT_SEL_PIN")
|
||||
#elif(ENABLE_BAT_SEL_PIN)
|
||||
BATOP_SEL_OUTPUT();
|
||||
SELECT_MAIN_BAT();
|
||||
#endif
|
||||
//==============================================================================
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ 3V
|
||||
CheckSystemVoltageInit();
|
||||
systemVoltage = ReadAndComputeVoltage();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ع<EFBFBD><D8B9><EFBFBD><EFBFBD><EFBFBD>ѹ
|
||||
CheckBatteryVoltageInit();
|
||||
batteryVoltage = ReadAndComputeVoltage();
|
||||
//batteryVoltage = MovingAverage(batteryVoltage, 100, BATT);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͻ<EFBFBD><CFBD><EFBFBD><EFBFBD><EFBFBD><CDB9><EFBFBD>ģʽ
|
||||
CheckEndIntoLowPower();
|
||||
|
||||
//<2F>жϵ<D0B6><CFB5>ع<EFBFBD><D8B9><EFBFBD>״̬
|
||||
JudgeSystemVolState();
|
||||
}
|
||||
24
user/Compute/CheckSystemVoltage.h
Executable file
24
user/Compute/CheckSystemVoltage.h
Executable file
@@ -0,0 +1,24 @@
|
||||
/********************************************************************************************************
|
||||
**-------------------------------------------------------------------------------------------------------
|
||||
********************************************************************************************************/
|
||||
#ifndef __CheckSystemVoltage_h__
|
||||
#define __CheckSystemVoltage_h__
|
||||
|
||||
#define BATTEST_PERIOD_MAX 1440
|
||||
#define BATTEST_PERIOD_MIN 1
|
||||
|
||||
|
||||
void CheckSystemVoltageInit(void);
|
||||
void CheckBatteryVoltageInit(void);
|
||||
u16 ComputeVoltage(u16 codeVol);
|
||||
u16 ReadAndComputeVoltage(void);
|
||||
void CheckEndIntoLowPower(void);
|
||||
|
||||
void CheckSystemAndBatteryVoltage(void);
|
||||
void JudgeSystemVolState(void);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
extern u16 batteryTestPeriod, batteryTestPeriodSet;
|
||||
//******************************************************************************
|
||||
#endif
|
||||
//******************************************************************************
|
||||
284
user/Compute/Correct.c
Executable file
284
user/Compute/Correct.c
Executable file
@@ -0,0 +1,284 @@
|
||||
#include "../main/SystemInclude.h"
|
||||
//==============================================================================
|
||||
u32 dcoefNode[DCOEF_MAX];
|
||||
u16 dcoef, dcoefVal[DCOEF_MAX];
|
||||
float GCFParaA, GCFParaB, GCFParaC;
|
||||
u16 GCFCoefB;
|
||||
s32 GCFCoefA, GCFCoefC;
|
||||
float GCFParaA, GCFParaB, GCFParaC;
|
||||
//u16 dcoefNum;
|
||||
//******************************************************************************
|
||||
// Routines for device coefficients
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߽ڵ<DFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>
|
||||
void StoreDevCoefNodeAndValue(unsigned char I)
|
||||
{
|
||||
tempL.DWord= dcoefNode[I];
|
||||
tempDev.Word[2] = tempL.Word[1];
|
||||
tempDev.Word[1] = tempL.Word[0];
|
||||
tempDev.Word[0] = dcoefVal[I];
|
||||
|
||||
WriteMultiByteToMemory(DCOEF_BASE+I*DCOEF_WIDTH, tempDev.Byte, DCOEF_WIDTH);
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߽ڵ<DFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>
|
||||
bool ReadDevCoefNodeAndValue(unsigned char I)
|
||||
{
|
||||
ReadMultiByteFromMemory(DCOEF_BASE + I * DCOEF_WIDTH, tempDev.Byte, DCOEF_WIDTH);
|
||||
if(tempDev.Byte[DCOEF_CRC] == CRC8(tempDev.Byte, DCOEF_CRC))
|
||||
{
|
||||
tempDev.Byte[DCOEF_CRC] = 0;
|
||||
|
||||
dcoefVal[I] = tempDev.Word[0];
|
||||
tempL.Word[0] = tempDev.Word[1];
|
||||
tempL.Word[1] = tempDev.Word[2];
|
||||
dcoefNode[I] = tempL.DWord;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
dcoefNode[I] = 0;
|
||||
dcoefVal[I] = 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
//******************************************************************************
|
||||
//Ĭ<>ϵĶ<CFB5><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߲<EFBFBD><DFB2><EFBFBD>
|
||||
void DefaultDevCoef(void)
|
||||
{
|
||||
unsigned char I;
|
||||
//u32 flowRateMax;
|
||||
|
||||
dcoefNode[0] = (maxFlowRate * 1) / 100; // 1% 1028
|
||||
dcoefNode[1] = 1000;
|
||||
dcoefNode[2] = (maxFlowRate * 10) / 100; // 10%
|
||||
//dcoefNode[3] = (maxFlowRate * 20) / 100;
|
||||
//dcoefNode[4] = (maxFlowRate * 40) / 100;
|
||||
dcoefNode[3] = maxFlowRate >> 1; // 50%
|
||||
dcoefNode[4] = maxFlowRate; // 100%
|
||||
|
||||
if(dcoefNode[0] < 500) dcoefNode[0] = 500;
|
||||
if(dcoefNode[1] <= dcoefNode[0]) dcoefNode[1] = (maxFlowRate * 5) / 100; //dcoefNode[1] = (dcoefNode[0] + dcoefNode[2])>>1;
|
||||
if(dcoefNode[2] <= dcoefNode[1]) dcoefNode[2] = (dcoefNode[1] + dcoefNode[3]) >> 1;
|
||||
if(dcoefNode[3] <= dcoefNode[2]) dcoefNode[3] = (dcoefNode[2] + dcoefNode[4]) >> 1;
|
||||
|
||||
dcoefNum = 5;
|
||||
tempL.Byte[0] = dcoefNum;
|
||||
// WriteShortParameterToEEPROM(DCOEF_NUM, DCOEF_NUM_WIDTH);
|
||||
WriteShortParameterToEEPROM(DCOEF_NUM);
|
||||
|
||||
for (I = 0; I < dcoefNum; I++)
|
||||
{
|
||||
dcoefVal[I] = METER_PARAMETER_DEFAULT;
|
||||
//dcoefNode[I] = ConvertFlowrate(dcoefNode[I]);
|
||||
|
||||
StoreDevCoefNodeAndValue(I);
|
||||
}
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߲<EFBFBD><DFB2><EFBFBD>
|
||||
void RetriveDevCoef(void)
|
||||
{
|
||||
u32 I;
|
||||
// u32 flowRateMax;
|
||||
|
||||
ReadShortParameterFromMemory(DCOEF_NUM, PARA_EEPROM);
|
||||
// if(tempL.Byte[1] != CRC8(tempL.Byte, 1)) goto RetResetDevCoef;
|
||||
|
||||
dcoefNum = tempL.Byte[0];
|
||||
if((dcoefNum > DCOEF_MAX)||(dcoefNum < 3)) goto RetResetDevCoef;
|
||||
|
||||
if(ReadDevCoefNodeAndValue(0)) goto RetResetDevCoef;
|
||||
for (I = 1; I < dcoefNum; I++)
|
||||
{
|
||||
if(ReadDevCoefNodeAndValue(I)) goto RetResetDevCoef;
|
||||
if(dcoefNode[I] <= dcoefNode[I-1]) goto RetResetDevCoef;
|
||||
// if(dcoefNode[I] > flowRateMax) goto RetResetDevCoef;
|
||||
}
|
||||
return;
|
||||
|
||||
RetResetDevCoef:
|
||||
DefaultDevCoef();
|
||||
return;
|
||||
}
|
||||
//******************************************************************************
|
||||
void JudgeDevCoef(void)
|
||||
{
|
||||
u16 I;
|
||||
|
||||
for (I = 1; I < dcoefNum; I++)
|
||||
{
|
||||
if(dcoefNode[I] <= dcoefNode[I-1]) { RetriveDevCoef(); return; }
|
||||
}
|
||||
}
|
||||
//******************************************************************************
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
u16 GetDevCoefFactor(u32 dcoefFlowRate)
|
||||
{
|
||||
// u32 tmp;
|
||||
u16 nodeVal = METER_PARAMETER_DEFAULT;
|
||||
u32 nodeFR = 0;
|
||||
unsigned char I;
|
||||
|
||||
for(I = 0; I < dcoefNum; I++)
|
||||
{
|
||||
if(dcoefNode[I] < dcoefFlowRate) continue;
|
||||
if(I != 0)
|
||||
{
|
||||
nodeVal = dcoefVal[I-1];
|
||||
nodeFR = dcoefNode[I-1];
|
||||
}
|
||||
|
||||
tmpSLA = (u32)dcoefVal[I];
|
||||
tmpSLA -= (u32)nodeVal;
|
||||
|
||||
tmpSLB = (u32)dcoefFlowRate;
|
||||
tmpSLB -= (u32)nodeFR;
|
||||
tmpSLA *= tmpSLB;
|
||||
|
||||
tmpSLB = (u32)dcoefNode[I];
|
||||
tmpSLB -= (u32)nodeFR;
|
||||
tmpSLA /= tmpSLB;
|
||||
|
||||
tmpSLA += (u32)nodeVal;
|
||||
|
||||
return (u16)tmpSLA;
|
||||
}
|
||||
|
||||
return dcoefVal[dcoefNum-1];
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
// Routines for calculating the following expression without overflow:
|
||||
u32 CorrectionExpression(u32 target, u16 factor, u16 base)
|
||||
{
|
||||
float tempF;
|
||||
|
||||
tempF = (float)target;
|
||||
|
||||
#ifndef CORRECT_METHOD
|
||||
#pragma message("[undefined] CORRECT_METHOD")
|
||||
#elif(CORRECT_METHOD)
|
||||
|
||||
tempF *= (float)base;
|
||||
tempF /= (float)factor;
|
||||
|
||||
#else
|
||||
|
||||
tempF /= (float)base;
|
||||
tempF *= (float)factor;
|
||||
|
||||
#endif
|
||||
|
||||
return (u32)tempF;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
void GCFCorrection(void)
|
||||
{
|
||||
if(currentMode.Bit.CalibMode) return;
|
||||
//----------------------------------------------------------------------------
|
||||
#ifndef ENABLE_GAS_RECOGNITION
|
||||
#pragma message("[undefined] ENABLE_GAS_RECOGNITION")
|
||||
#elif(ENABLE_GAS_RECOGNITION)
|
||||
//FY if(!isCurrentGas) return;
|
||||
#endif
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
float floatA, floatB;
|
||||
//----------------------------------------------------------------------------
|
||||
#ifndef ENABLE_A_TYPE_FLOWRATE
|
||||
#pragma message("[undefined] ENABLE_A_TYPE_FLOWRATE")
|
||||
#elif(ENABLE_A_TYPE_FLOWRATE)
|
||||
if(FRType == ATYPE_FR)
|
||||
{
|
||||
floatA = (float)GDCFactorAType;
|
||||
floatA *= (float)currentFlowRate;
|
||||
floatA /= (float)GCF_PARAMETER_STD;
|
||||
currentFlowRate = (u32)floatA;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
#ifndef ENABLE_GCF_POWER_CORR
|
||||
#pragma message("[undefined] ENABLE_GCF_POWER_CORR")
|
||||
#elif(ENABLE_GCF_POWER_CORR)
|
||||
// Power function correction
|
||||
// GCF
|
||||
if(GCFCoefC == 0)
|
||||
{
|
||||
floatB = (float)currentFlowRate;
|
||||
floatB = (float)GCFParaB;
|
||||
}
|
||||
else
|
||||
{
|
||||
floatA = GCFParaC; // GCFParaC : area m2
|
||||
floatB = (float)currentFlowRate;
|
||||
if(FR_STD_UNIT == SL) floatA *= 60000000; // 0000SLPM - 0.000 m3/s (3bit): (FR/1000)
|
||||
else floatA *= 3600000; // 0000m3/H - 0.000 m3/s (3bit): (FR/1000)
|
||||
floatA = floatB/floatA; // 0.000 m/s
|
||||
floatA = pow(floatA, GCFParaA); // compute GCF
|
||||
floatA *= GCFParaB;
|
||||
floatB *= floatA;
|
||||
}
|
||||
currentFlowRate = (u32)floatB;
|
||||
|
||||
#else
|
||||
|
||||
// Quadratic correction coefficient
|
||||
// GCF
|
||||
floatB = (float)currentFlowRate;
|
||||
floatA = floatB * floatB;
|
||||
floatA *= (float)GCFParaA;
|
||||
floatB *= (float)GCFParaB;
|
||||
floatA += floatB;
|
||||
floatA += (float)GCFParaC;
|
||||
currentFlowRate = (u32)floatA;
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
void FlowRateSecondaryCorrection(void)
|
||||
{
|
||||
// retrieve the GDCF factor & device coefficients
|
||||
// account in the GDCF factor & device coefficients
|
||||
#ifndef ENABLE_DCOEF
|
||||
#pragma message("[undefined] ENABLE_DCOEF")
|
||||
#elif(ENABLE_DCOEF)
|
||||
if(HWState.EnableCheckCorr) JudgeDevCoef();
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
#ifndef ENABLE_FLOW_GAIN
|
||||
#pragma message("[undefined] ENABLE_FLOW_GAIN")
|
||||
#elif(ENABLE_FLOW_GAIN)
|
||||
dcoef = GetDevCoefFactor(currentFlowRate/(u32)calibFlowGain);
|
||||
#else
|
||||
dcoef = GetDevCoefFactor(currentFlowRate);
|
||||
#endif
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
currentFlowRate = CorrectionExpression(currentFlowRate, dcoef, METER_PARAMETER_STD);
|
||||
#endif
|
||||
|
||||
currentFlowRate = CorrectionExpression(currentFlowRate, MeterFactor, METER_PARAMETER_STD);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void ComputeGCFFactor(void)
|
||||
{
|
||||
// Quadratic correction coefficient
|
||||
// GCF
|
||||
GCFParaA = (float)GCFCoefA;
|
||||
GCFParaA /= (float)GCF_A_DOT;
|
||||
|
||||
GCFCoefB = GDCFactor;
|
||||
GCFParaB = (float)GCFCoefB;
|
||||
GCFParaB /= (float)GCF_B_DOT;
|
||||
|
||||
GCFParaC = (float)GCFCoefC;
|
||||
GCFParaC /= (float)GCF_C_DOT;
|
||||
}
|
||||
35
user/Compute/Correct.h
Executable file
35
user/Compute/Correct.h
Executable file
@@ -0,0 +1,35 @@
|
||||
/********************************************************************************************************
|
||||
** HY3106<30><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>
|
||||
**
|
||||
** Copyright (c) Siargo, Ltd. 2011
|
||||
** All Rights Reserved.
|
||||
**
|
||||
**-------------------------------------------------------------------------------------------------------
|
||||
********************************************************************************************************/
|
||||
#ifndef __Correct_h__
|
||||
#define __Correct_h__
|
||||
|
||||
//******************************************************************************
|
||||
extern u32 dcoefNode[];
|
||||
extern u16 dcoef, dcoefVal[];
|
||||
extern u16 GCFCoefB;
|
||||
extern s32 GCFCoefA, GCFCoefC;
|
||||
//extern u16 dcoefNum ;
|
||||
|
||||
//******************************************************************************
|
||||
void StoreDevCoefNodeAndValue(u8 I);
|
||||
bool ReadDevCoefNodeAndValue(u8 I);
|
||||
void DefaultDevCoef(void);
|
||||
void RetriveDevCoef(void);
|
||||
void JudgeDevCoef(void);
|
||||
u16 GetDevCoefFactor(u32 dcoefFlowRate);
|
||||
u32 CorrectionExpression(u32 target, u16 factor, u16 base);
|
||||
void FlowRateSecondaryCorrection(void);
|
||||
//void ReadCorrectByCom(void);
|
||||
//void WriteCorrectByCom(void);
|
||||
|
||||
void ReadCorrectNodeByCom(void);
|
||||
void ReadCorrectValueByCom(void);
|
||||
void GCFCorrection(void);
|
||||
void ComputeGCFFactor(void);
|
||||
#endif
|
||||
363
user/Compute/FlowRateCompute.c
Executable file
363
user/Compute/FlowRateCompute.c
Executable file
@@ -0,0 +1,363 @@
|
||||
#include "../main/SystemInclude.h"
|
||||
//==============================================================================
|
||||
#define FR_FILTER_MAX 8
|
||||
#define FR_FILTER_SHIFT 3
|
||||
#define FR_FILTER_MASK (FR_FILTER_MAX-1)
|
||||
|
||||
u32 flowSample[8], DisSample[8];
|
||||
u16 FIndexSample[8];
|
||||
u16 DisIndex, FRIndex, FIndex, filterShift, dataMask, filterDepth;
|
||||
u32 maxAlarmFlowRate;
|
||||
|
||||
#ifndef ENABLE_LEAK_DETECT
|
||||
#pragma message("[undefined] ENABLE_LEAK_DETECT")
|
||||
#elif(ENABLE_LEAK_DETECT)
|
||||
u16 leakDetectLowCounter, leakDetectHighCounter, leakDetectCounter;
|
||||
#endif
|
||||
|
||||
/******************************************************************************/
|
||||
u32 GetFlowRate(u16 flowIndex, u16 curveType)
|
||||
{
|
||||
u16 indexL, dataCompFac;
|
||||
u8 temp[12];
|
||||
switch(curveType)
|
||||
{
|
||||
case CURVE_1ST:
|
||||
if(flowIndex > 32767) return 0;
|
||||
else if(flowIndex < zeroSuppression) return 0;
|
||||
else if(flowIndex >= CALIB_MAX_INDEX) flowIndex = CALIB_MAX_INDEX;
|
||||
dataCompFac = CALIB_COMP_FAC;
|
||||
indexL = CALI_DATA_ADDR;
|
||||
break;
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
#ifndef ENABLE_2ND_CURVE
|
||||
#pragma message("[undefined] ENABLE_2ND_CURVE")
|
||||
#elif(ENABLE_2ND_CURVE)
|
||||
case CURVE_2ND:
|
||||
dataCompFac = CALIB_COMP_FAC2;
|
||||
indexL = CALI_DATA2_ADDR;
|
||||
break;
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
#ifndef ENABLE_3RD_CURVE
|
||||
#pragma message("[undefined] ENABLE_3RD_CURVE")
|
||||
#elif(ENABLE_3RD_CURVE)
|
||||
case CURVE_3RD:
|
||||
if(flowIndex > 32767) return 0;
|
||||
else if(flowIndex < zeroSuppression) return 0;
|
||||
else if(flowIndex >= CALIB_MAX_INDEX3) flowIndex = CALIB_MAX_INDEX;
|
||||
dataCompFac = CALIB_COMP_FAC3;
|
||||
indexL = CALI_DATA3_ADDR;
|
||||
break;
|
||||
#endif
|
||||
|
||||
default: return 0;
|
||||
}
|
||||
|
||||
//240000-3*4 2*4096*6=48828-6*4
|
||||
if(flowIndex > (CALIB_MAX_INDEX - dataCompFac*4)) {
|
||||
indexL += (CALIB_MAX_INDEX / dataCompFac - 1)*3;
|
||||
ReadCalbrationDataFromMemory(indexL, &tempDev.Byte[0], 3);
|
||||
|
||||
tempDev.Byte[3] = 0;
|
||||
return tempDev.DWord[0];
|
||||
}
|
||||
|
||||
u16 index0, indexD, IndexA, IndexB, J=0, K;
|
||||
u32 tempFR[4];
|
||||
//u32
|
||||
|
||||
index0 = flowIndex / dataCompFac;
|
||||
indexL += index0*3;
|
||||
|
||||
ReadCalbrationDataFromMemory(indexL-3, temp, 12);
|
||||
|
||||
tmpLA = 0;
|
||||
tmpLB = 0xffffffff;
|
||||
for(K=0, J=0; K<4; K++) {
|
||||
tempL.Byte[0] = temp[J++];
|
||||
tempL.Byte[1] = temp[J++];
|
||||
tempL.Byte[2] = temp[J++];
|
||||
tempL.Byte[3] = 0;
|
||||
tempFR[K] = tempL.DWord;
|
||||
|
||||
if(tempL.DWord > tmpLA) {
|
||||
tmpLA = tempL.DWord;
|
||||
IndexA = K;
|
||||
}
|
||||
|
||||
if(tempL.DWord < tmpLB) {
|
||||
tmpLB = tempL.DWord;
|
||||
IndexB = K;
|
||||
}
|
||||
}
|
||||
|
||||
for(K=0, J=0; K<4; K++) {
|
||||
if(K == IndexA) continue;
|
||||
if(K == IndexB) continue;
|
||||
temp[J] = K;
|
||||
J++;
|
||||
}
|
||||
|
||||
IndexA = temp[0];
|
||||
IndexB = temp[1];
|
||||
|
||||
tmpSLA = (u32)tempFR[IndexA];
|
||||
tmpSLB = (u32)tempFR[IndexB];
|
||||
IndexB = (IndexB - IndexA)*dataCompFac;
|
||||
IndexA *= dataCompFac;
|
||||
|
||||
// (tmpLB-tmpLA)*indexD/dataCompFac + tmpLA
|
||||
indexD = flowIndex - index0 * dataCompFac;
|
||||
indexD += dataCompFac;
|
||||
|
||||
tmpSLB -= tmpSLA;
|
||||
if(indexD > IndexA) {
|
||||
tmpSLB *= (u32)(indexD-IndexA);
|
||||
tmpSLB /= (u32)IndexB;
|
||||
tmpSLA += tmpSLB;
|
||||
}
|
||||
else {
|
||||
tmpSLB *= (u32)(IndexA-indexD);
|
||||
tmpSLB /= (u32)IndexB;
|
||||
tmpSLA -= tmpSLB;
|
||||
}
|
||||
|
||||
if(tmpSLA < 0) return 0;
|
||||
else return (u32)tmpSLA;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
u16 HalfWordMovingAverage(u16 *TPFilter, u16 shiftCompare, u16 updateScale)
|
||||
{
|
||||
u16 I, tempDelta;
|
||||
|
||||
//for(I=0; I<sumLen; I++) tempSum += (u32)*TPFilter++;
|
||||
//return tempSum >> shiftBit;
|
||||
|
||||
tmpLA = 0;
|
||||
for(I=0; I<filterDepth; I++) tmpLA += (u32)*(TPFilter+I);
|
||||
tmpIA = (u16)(tmpLA >> filterShift);
|
||||
|
||||
if(shiftCompare > tmpIA) tempDelta = shiftCompare - tmpIA;
|
||||
else tempDelta = tmpIA - shiftCompare;
|
||||
|
||||
tmpLA = (u32)tmpIA;
|
||||
tmpLA *= (u32)updateScale;
|
||||
tmpLA >>= 10;
|
||||
|
||||
if(tempDelta < (u16)tmpLA) return tmpIA;
|
||||
for(I=0; I<filterDepth; I++) *TPFilter++ = shiftCompare;
|
||||
|
||||
return shiftCompare;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
u32 WordMovingAverage(u32 *TPFilter, u32 shiftCompare, u16 updateScale)
|
||||
{
|
||||
u16 I;
|
||||
u32 tempDelta;
|
||||
|
||||
tmpLA = 0;
|
||||
for(I=0; I<filterDepth; I++) tmpLA += (u32)*(TPFilter+I);
|
||||
tmpLA >>= filterShift;
|
||||
|
||||
if(shiftCompare > tmpLA) tempDelta = shiftCompare - tmpLA;
|
||||
else tempDelta = tmpLA - shiftCompare;
|
||||
|
||||
tmpLB = (u32)tmpLA;
|
||||
tmpLB *= (u32)updateScale;
|
||||
tmpLB >>= 10;
|
||||
|
||||
if(tempDelta < (u16)tmpLB) return tmpLA;
|
||||
for(I=0; I<filterDepth; I++) *TPFilter++ = shiftCompare;
|
||||
|
||||
return shiftCompare;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
void GetFilterDepth(u16 timeIndex)
|
||||
{
|
||||
filterDepth = FilterMax[timeIndex] / FilterMax[samplingInterval];
|
||||
switch(filterDepth)
|
||||
{
|
||||
case 1: filterShift = 0; break;
|
||||
case 2: filterShift = 1; break;
|
||||
case 4: filterShift = 2; break;
|
||||
case 8: filterShift = 3; break;
|
||||
case 16: filterShift = 4; break;
|
||||
case 32: filterShift = 5; break;
|
||||
default:
|
||||
filterDepth = 1;
|
||||
filterShift = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
dataMask = filterDepth-1;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
u16 FlowRateIndexFilter(u16 filterANX, u16 updateScale)
|
||||
{
|
||||
FIndex++;
|
||||
FIndex &= dataMask;
|
||||
FIndexSample[FIndex] = voltageDetected[filterANX];
|
||||
|
||||
return HalfWordMovingAverage(&FIndexSample[0], voltageDetected[filterANX], updateScale);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void FlowRateMoving(void)
|
||||
{
|
||||
FRIndex++;
|
||||
FRIndex &= dataMask;
|
||||
flowSample[FRIndex] = flowRate;
|
||||
flowRate = WordMovingAverage(&flowSample[0], flowRate, FLOWRATE_UPDATE_SCALE); // 1.5%
|
||||
|
||||
#ifndef ENABLE_LCD_DISPLAY
|
||||
#pragma message("[undefined] ENABLE_LCD_DISPLAY")
|
||||
#elif(ENABLE_LCD_DISPLAY)
|
||||
GetFilterDepth(DISPLAY_FILTER_DEFAULT);
|
||||
DisIndex++;
|
||||
DisIndex &= dataMask;
|
||||
DisSample[DisIndex] = displayUpdate;
|
||||
displayUpdate = WordMovingAverage(&DisSample[0], displayUpdate, FLOWRATE_UPDATE_SCALE);
|
||||
#endif
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void CurrentFlowRateMoving(void)
|
||||
{
|
||||
FRIndex++;
|
||||
FRIndex &= dataMask;
|
||||
flowSample[FRIndex] = currentFlowRate;
|
||||
currentFlowRate = WordMovingAverage(&flowSample[0], currentFlowRate, FLOWRATE_UPDATE_SCALE); // 1.5%
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void DisplayFlowRateMoving(void)
|
||||
{
|
||||
GetFilterDepth(DISPLAY_FILTER_DEFAULT);
|
||||
DisIndex++;
|
||||
DisIndex &= dataMask;
|
||||
DisSample[DisIndex] = displayUpdate;
|
||||
displayUpdate = WordMovingAverage(&DisSample[0], displayUpdate, FLOWRATE_UPDATE_SCALE);
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
void FlowRateAlarmJudgment(void)
|
||||
{
|
||||
u32 minAlarmFlowRate;
|
||||
unsigned long long int alarmFlowRate;
|
||||
|
||||
// float tempFlow;
|
||||
//maxFlowRate = 3500000;
|
||||
// tempFlow = (float)maxFlowRate;
|
||||
// tempFlow *= (float)MAX_ALRAM_FR_DEFAULT;
|
||||
// maxAlarmFlowRate = (u32)tempFlow;
|
||||
|
||||
|
||||
|
||||
//===========================================================================
|
||||
// <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Уʱ<D7BC><CAB1><EFBFBD><EFBFBD><EFBFBD>ķŴ<C4B7><C5B4><EFBFBD><EFBFBD><EFBFBD>
|
||||
//maxAlarmFlowRate = maxFlowRate;
|
||||
//maxAlarmFlowRate *= (u32)MAX_ALRAM_FR_DEFAULT; // 1.25*128 = 160;
|
||||
//maxAlarmFlowRate >>= 7;
|
||||
|
||||
alarmFlowRate = (unsigned long long int)maxFlowRate;
|
||||
alarmFlowRate *= (unsigned long long int)MAX_ALRAM_FR_DEFAULT;
|
||||
alarmFlowRate >>= 7;
|
||||
maxAlarmFlowRate = (u32)alarmFlowRate;
|
||||
minAlarmFlowRate = minFlowRate;
|
||||
|
||||
//===========================================================================
|
||||
#ifndef ENABLE_FLOW_GAIN
|
||||
#pragma message("[undefined] ENABLE_FLOW_GAIN")
|
||||
#elif(ENABLE_FLOW_GAIN)
|
||||
maxAlarmFlowRate *= calibFlowGain;
|
||||
minAlarmFlowRate *= calibFlowGain;
|
||||
#endif
|
||||
|
||||
//===========================================================================
|
||||
systemAlarm.Bit.FRAlarm = 0;
|
||||
if(currentFlowRate > maxAlarmFlowRate) //1.25Qmax
|
||||
{
|
||||
systemAlarm.Bit.FRAlarm = 1;
|
||||
currentFlowRate = maxAlarmFlowRate;
|
||||
}
|
||||
else if(currentFlowRate < minAlarmFlowRate) currentFlowRate = 0; // V2004
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
#ifndef ENABLE_LEAK_DETECT
|
||||
#pragma message("[undefined] ENABLE_LEAK_DETECT")
|
||||
#elif(ENABLE_LEAK_DETECT)
|
||||
void FlowRateLeakDetect(void)
|
||||
{
|
||||
if((alarmState1 & LEAK_ALARM)== LEAK_ALARM)
|
||||
{
|
||||
leakDetectCounter = 0;
|
||||
leakDetectHighCounter = 0;
|
||||
leakDetectLowCounter = 0;
|
||||
#ifndef ENABLE_ERROR_PIN_FOR_VALVE_CONTROL
|
||||
#pragma message("[undefined] ENABLE_ERROR_PIN_FOR_VALVE_CONTROL")
|
||||
#elif(ENABLE_ERROR_PIN_FOR_VALVE_CONTROL)
|
||||
ERROR_PIN_OUTPUT();
|
||||
TURN_OFF_VALVE();
|
||||
alarmState1 |= VALVE_OFF_ALARM;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
// if((leakDetectTime == 0) || (sampleState.EnableRoughTest))
|
||||
// {
|
||||
// leakDetectCounter = 0;
|
||||
// leakDetectHighCounter = 0;
|
||||
// leakDetectLowCounter = 0;
|
||||
// return;
|
||||
// }
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
if(flowRate < minLeakFlowRate)
|
||||
{
|
||||
leakDetectLowCounter++;
|
||||
leakDetectHighCounter = 0;
|
||||
if(leakDetectLowCounter > 4)
|
||||
{
|
||||
leakDetectLowCounter = 0;
|
||||
leakDetectCounter = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if(flowRate > maxLeakFlowRate)
|
||||
{
|
||||
leakDetectHighCounter++;
|
||||
leakDetectLowCounter = 0;
|
||||
if(leakDetectHighCounter > 4)
|
||||
{
|
||||
leakDetectHighCounter = 0;
|
||||
leakDetectCounter = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
leakDetectHighCounter = 0;
|
||||
leakDetectLowCounter = 0;
|
||||
if(leakDetectCounter > leakDetectTime)
|
||||
{
|
||||
leakDetectCounter = leakDetectTime;
|
||||
alarmState1 |= LEAK_ALARM;
|
||||
|
||||
#ifndef ENABLE_ERROR_PIN_FOR_VALVE_CONTROL
|
||||
#pragma message("[undefined] ENABLE_ERROR_PIN_FOR_VALVE_CONTROL")
|
||||
#elif(ENABLE_ERROR_PIN_FOR_VALVE_CONTROL)
|
||||
ERROR_PIN_OUTPUT();
|
||||
TURN_OFF_VALVE();
|
||||
alarmState1 |= VALVE_OFF_ALARM;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
50
user/Compute/FlowRateCompute.h
Executable file
50
user/Compute/FlowRateCompute.h
Executable file
@@ -0,0 +1,50 @@
|
||||
/********************************************************************************************************
|
||||
** HY3106<30><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>
|
||||
**
|
||||
** Copyright (c) Siargo, Ltd. 2011
|
||||
** All Rights Reserved.
|
||||
**
|
||||
**-------------------------------------------------------------------------------------------------------
|
||||
********************************************************************************************************/
|
||||
#ifndef __FlowRateCompute_h__
|
||||
#define __FlowRateCompute_h__
|
||||
|
||||
#define CURVE_1ST 0
|
||||
#define CURVE_2ND 1
|
||||
#define CURVE_3RD 2
|
||||
|
||||
extern u16 FIndexSample[], filterShift, dataMask, filterDepth;
|
||||
extern u32 maxAlarmFlowRate;
|
||||
extern u32 flowSample[], DisSample[];
|
||||
//==============================================================================
|
||||
u32 GetFlowRate(u16 flowIndex, u16 curveType);
|
||||
//void FlowRateAlarmJudgment(void);
|
||||
void FlowRateAlarmJudgment(void);
|
||||
u8 FlowRateModeDetect(void);
|
||||
|
||||
u16 HalfWordMovingAverage(u16 *TPFilter, u16 shiftCompare, u16 updateScale);
|
||||
u32 WordMovingAverage(u32 *TPFilter, u32 shiftCompare, u16 updateScale);
|
||||
void GetFilterDepth(u16 timeIndex);
|
||||
u16 FlowRateIndexFilter(u16 filterANX, u16 updateScale);
|
||||
void FlowRateMoving(void);
|
||||
void CurrentFlowRateMoving(void);
|
||||
void DisplayFlowRateMoving(void);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#ifndef ENABLE_LEAK_DETECT
|
||||
#pragma message("[undefined] ENABLE_LEAK_DETECT")
|
||||
#elif(ENABLE_LEAK_DETECT)
|
||||
extern u16 leakDetectLowCounter, leakDetectHighCounter, leakDetectCounter;
|
||||
void FlowRateLeakDetect(void);
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#ifndef ENABLE_FLOW_GAIN
|
||||
#pragma message("[undefined] ENABLE_FLOW_GAIN")
|
||||
#elif(ENABLE_FLOW_GAIN)
|
||||
u16 JudgeFlowRateGain(u16 flowGain);
|
||||
#endif
|
||||
|
||||
//******************************************************************************
|
||||
#endif
|
||||
//******************************************************************************
|
||||
176
user/Compute/GasAnalysis.c
Executable file
176
user/Compute/GasAnalysis.c
Executable file
@@ -0,0 +1,176 @@
|
||||
#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
|
||||
|
||||
39
user/Compute/GasAnalysis.h
Executable file
39
user/Compute/GasAnalysis.h
Executable file
@@ -0,0 +1,39 @@
|
||||
/********************************************************************************************************
|
||||
** HY3106<30><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>
|
||||
**
|
||||
** Copyright (c) Siargo, Ltd. 2011
|
||||
** All Rights Reserved.
|
||||
**
|
||||
********************************************************************************************************/
|
||||
#ifndef __GasAnalysis_h__
|
||||
#define __GasAnalysis_h__
|
||||
|
||||
#define RH_PARA_DEFAULT 32768
|
||||
|
||||
//******************************************************************************
|
||||
extern u16 ATypeNode[CURVE_DATA_MAX], ATypeVal[CURVE_DATA_MAX], curveATypeNum;
|
||||
//******************************************************************************
|
||||
void GasAnalysisParameterInit(void);
|
||||
u16 ComputeZeroVHH(void);
|
||||
u32 GetVHHFactor(u16 flowIndex);
|
||||
void GasAnasisCompute(void);
|
||||
bool GasAnasisOneTime(void);
|
||||
void ReadVHHCurveFromMemory(void);
|
||||
u16 FindVHHInCalibCurve(u16 calibIndex);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
#ifndef ENABLE_DENSITY_DETECT
|
||||
#pragma message("[undefined] ENABLE_DENSITY_DETECT")
|
||||
#elif(ENABLE_DENSITY_DETECT)
|
||||
#ifndef DENSITY_FS
|
||||
#define DENSITY_FS 1000
|
||||
#define DENSITY_ZERO 0
|
||||
#endif
|
||||
|
||||
void GasDensityCompute(void);
|
||||
#endif
|
||||
|
||||
|
||||
//******************************************************************************
|
||||
#endif
|
||||
//******************************************************************************
|
||||
23
user/Compute/PipeFlowRate.c
Executable file
23
user/Compute/PipeFlowRate.c
Executable file
@@ -0,0 +1,23 @@
|
||||
#include "../main/SystemInclude.h"
|
||||
|
||||
unsigned short calibDiameter, workDiameter;
|
||||
|
||||
//******************************************************************************
|
||||
unsigned long int CorrectTubeFlowrate(unsigned long int correctFlowRate)
|
||||
{
|
||||
float tempF;
|
||||
|
||||
tempF = (float)workDiameter;
|
||||
tempF /= (float)calibDiameter;
|
||||
tempF *= tempF;
|
||||
tempF *= correctFlowRate;
|
||||
|
||||
return (unsigned long int)tempF;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
void PipeFlowRateComputeInit(void)
|
||||
{
|
||||
calibDiameter = ReadShortParameterFromEEPROM(CALIB_DIAMETER, CALIB_DIAMETER_WIDTH, CALIB_DIAMETER_DEFAULT);
|
||||
workDiameter = ReadShortParameterFromEEPROM(WORK_DIAMETER, WORK_DIAMETER_WIDTH, CALIB_DIAMETER_DEFAULT);
|
||||
}
|
||||
33
user/Compute/PipeFlowRate.h
Executable file
33
user/Compute/PipeFlowRate.h
Executable file
@@ -0,0 +1,33 @@
|
||||
/********************************************************************************************************
|
||||
** HY3106<30><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>
|
||||
**
|
||||
** Copyright (c) Siargo, Ltd. 2011
|
||||
** All Rights Reserved.
|
||||
**
|
||||
**-------------------------------------------------------------------------------------------------------
|
||||
********************************************************************************************************/
|
||||
#ifndef __PipeFlowRate_h__
|
||||
#define __PipeFlowRate_h__
|
||||
|
||||
//******************************************************************************
|
||||
// for memory WIDTH
|
||||
#define CALIB_DIAMETER_WIDTH 3
|
||||
#define WORK_DIAMETER_WIDTH 3
|
||||
#define PIPE_BASE_WIDTH 6
|
||||
//******************************************************************************
|
||||
// for memory CRC
|
||||
#define CALIB_DIAMETER_CRC (CALIB_DIAMETER_WIDTH-1)
|
||||
#define WORK_DIAMETER_CRC (WORK_DIAMETER_WIDTH-1)
|
||||
//******************************************************************************
|
||||
// for memory address
|
||||
#define CALIB_DIAMETER PIPE_BASE
|
||||
#define WORK_DIAMETER (PIPE_BASE + CALIB_DIAMETER_WIDTH)
|
||||
//******************************************************************************
|
||||
#define CALIB_DIAMETER_DEFAULT 100
|
||||
#define WORK_DIAMETER_DEFAULT 100
|
||||
//******************************************************************************
|
||||
extern unsigned short calibDiameter, workDiameter;
|
||||
//******************************************************************************
|
||||
unsigned long int CorrectTubeFlowrate(unsigned long int correctFlowRate);
|
||||
void PipeFlowRateComputeInit(void);
|
||||
#endif
|
||||
426
user/Compute/SavingData.c
Executable file
426
user/Compute/SavingData.c
Executable file
@@ -0,0 +1,426 @@
|
||||
#include "../main/SystemInclude.h"
|
||||
/******************************************************************************
|
||||
recordTime must be define
|
||||
*******************************************************************************/
|
||||
// for save data
|
||||
u16 historyPeriodSet;
|
||||
static u16 lastState;
|
||||
u16 saveTimeCounter;
|
||||
|
||||
/******************************************************************************/
|
||||
void SaveParameterInit(void)
|
||||
{
|
||||
// history record period
|
||||
recordTime = (u16)ReadShortParameterFromMemory(RECORD_TIME, RECORD_TIME_DEFAULT);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void CopyTimeToBackUpArray(u8 *backups)
|
||||
{
|
||||
backups[0] = timer[YEAR];
|
||||
backups[1] = timer[MONTH];
|
||||
backups[2] = timer[DATE];
|
||||
backups[3] = timer[HOUR];
|
||||
backups[4] = timer[MINUTE];
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void CopyAccToBackUpArray(u8 *backups)
|
||||
{
|
||||
backups[5] = Total[0];
|
||||
backups[6] = Total[1];
|
||||
backups[7] = Total[2];
|
||||
backups[8] = Total[3];
|
||||
backups[9] = Total[4];
|
||||
backups[10] = Total[5];
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
u16 WriteaAnAlarmData(u16 pointer)
|
||||
{
|
||||
u8 temp[ALARM_WIDTH];
|
||||
|
||||
pointer = ALARM_BASE + pointer * ALARM_WIDTH;
|
||||
|
||||
CopyTimeToBackUpArray(temp);
|
||||
CopyAccToBackUpArray(&temp[5]); // 6 Byte
|
||||
//------------------------------------------------------------------------------
|
||||
tempL.Word[0] = alarmState;
|
||||
temp[11] = tempL.Byte[1];
|
||||
temp[12] = tempL.Byte[0];
|
||||
|
||||
tempL.Word[0] = voltageDetected[NIDX];
|
||||
temp[13] = tempL.Byte[1];
|
||||
temp[14] = tempL.Byte[0];
|
||||
|
||||
tempL.Word[0] = voltageDetected[RHRES];
|
||||
temp[15] = tempL.Byte[1];
|
||||
temp[16] = tempL.Byte[0];
|
||||
|
||||
tempL.Word[0] = voltageDetected[RHVOL];
|
||||
temp[17] = tempL.Byte[1];
|
||||
temp[18] = tempL.Byte[0];
|
||||
|
||||
tempL.Word[0] = voltageDetected[VHPA];
|
||||
temp[19] = tempL.Byte[1];
|
||||
temp[20] = tempL.Byte[0];
|
||||
|
||||
tempL.Word[0] = voltageDetected[IVHDX];
|
||||
temp[21] = tempL.Byte[1];
|
||||
temp[22] = tempL.Byte[0];
|
||||
|
||||
tempL.Word[0] = voltageDetected[BATT];
|
||||
temp[23] = tempL.Byte[1];
|
||||
temp[24] = tempL.Byte[0];
|
||||
//------------------------------------------------------------------------------
|
||||
temp[ALARM_WIDTH_CRC] = CRC8(temp, ALARM_WIDTH_CRC);
|
||||
|
||||
WriteMultiByteToEEPROM(pointer, temp, ALARM_WIDTH, DATA_EEPROM);
|
||||
//ReadMultiByteFromEEPROM(pointer, buffer, ALARM_WIDTH, DATA_EEPROM);
|
||||
|
||||
//for(pointer=0; pointer<ALARM_WIDTH; pointer++)
|
||||
//{
|
||||
// if(buffer[pointer] != temp[pointer]) return 1;
|
||||
//}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/******************************************************************************/
|
||||
// write alarm data state
|
||||
u16 AlarmWrite(void)
|
||||
{
|
||||
|
||||
// write alarm information into external EEPROM
|
||||
// input: date, alarmState, VL, VH, AlarmPointer
|
||||
// output: AlarmPointer
|
||||
|
||||
#ifndef REC_ALARM_DATA
|
||||
#pragma message("[undefined] REC_ALARM_DATA")
|
||||
#elif(REC_ALARM_DATA)
|
||||
|
||||
// The Zero record: Factory initial state
|
||||
ReadMultiByteFromEEPROM(ALARM_POINTER, tempL.Byte, ALARM_POINTER_WIDTH, DATA_EEPROM);
|
||||
if(tempL.Byte[ALARM_POINTER_CRC] != CRC8(tempL.Byte, ALARM_POINTER_CRC)) tempL.Word[0] = 1;
|
||||
else if(tempL.Word[0] >= ALARM_DEPTH) tempL.Word[0] = 1;
|
||||
else if(tempL.Word[0] == 0) tempL.Word[0] = 1;
|
||||
else tempL.Word[0]++;
|
||||
|
||||
tempL.Byte[ALARM_POINTER_CRC] = CRC8(tempL.Byte, ALARM_POINTER_CRC);
|
||||
WriteMultiByteToEEPROM(ALARM_POINTER, tempL.Byte, ALARM_POINTER_WIDTH, DATA_EEPROM);
|
||||
|
||||
if(WriteaAnAlarmData(tempL.Word[0])) return 1;
|
||||
else return 0;
|
||||
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
/******************************************************************************/
|
||||
void SetHistoryRecordTime(void)
|
||||
{
|
||||
/*
|
||||
u16 wrt_base, pointer;
|
||||
|
||||
ReadMultiByteFromEEPROM(HISTORY_POINTER_H, temp, 2, DATA_EEPROM);
|
||||
pointer = make16(temp[0], temp[1]);
|
||||
|
||||
historyPeriodSet = (unsigned int)RTCHOUR;
|
||||
historyPeriodSet *= 60;
|
||||
historyPeriodSet += (unsigned int)RTCMIN;
|
||||
if(pointer >= HISTORY_DEPTH) { historyPeriodSet++; return; }
|
||||
|
||||
wrt_base = HISTORY_BASE + pointer * HISTORY_WIDTH;
|
||||
ReadMultiByteFromEEPROM(wrt_base, timer, 5, DATA_EEPROM);
|
||||
|
||||
wrt_base = (unsigned int)timer[HOUR];
|
||||
wrt_base *= 60;
|
||||
wrt_base += (unsigned int)timer[MINUTE];
|
||||
wrt_base += historyPeriod;
|
||||
if(wrt_base >= 1440) { historyPeriodSet = 0; return;}
|
||||
if(historyPeriodSet < wrt_base) historyPeriodSet = wrt_base;
|
||||
*/
|
||||
historyPeriodSet = 0xffff;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
u16 WriteAnHistoryData(u16 pointer)
|
||||
{
|
||||
u8 temp[HISTORY_WIDTH];
|
||||
|
||||
pointer = HISTORY_BASE + tempL.Word[0] * HISTORY_WIDTH;
|
||||
|
||||
CopyTimeToBackUpArray(temp); // 5 Byte
|
||||
CopyAccToBackUpArray(&temp[5]); // 6 Byte
|
||||
|
||||
tempL.Word[0] = alarmState;
|
||||
temp[11] = tempL.Byte[1];
|
||||
temp[12] = tempL.Byte[0];
|
||||
|
||||
tempL.DWord = flowRate;
|
||||
temp[13] = tempL.Byte[2];
|
||||
temp[14] = tempL.Byte[1];
|
||||
temp[15] = tempL.Byte[0];
|
||||
|
||||
temp[HISTORY_WIDTH_CRC] = CRC8(temp, HISTORY_WIDTH_CRC);
|
||||
|
||||
WriteMultiByteToEEPROM(pointer, temp, HISTORY_WIDTH, DATA_EEPROM);
|
||||
// ReadMultiByteFromEEPROM(pointer, buffer, HISTORY_WIDTH, DATA_EEPROM);
|
||||
//
|
||||
// for(pointer=0; pointer<HISTORY_WIDTH; pointer++)
|
||||
// {
|
||||
// if(buffer[pointer] != temp[pointer]) return 1;
|
||||
// }
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
u16 HistoryRecordWrite(void)
|
||||
{
|
||||
#ifndef REC_HISTORY_DATA
|
||||
#pragma message("[undefined] REC_HISTORY_DATA")
|
||||
#elif(REC_HISTORY_DATA)
|
||||
|
||||
ReadMultiByteFromEEPROM(HISTORY_POINTER, tempL.Byte, HISTORY_POINTER_WIDTH, DATA_EEPROM);
|
||||
if(tempL.Byte[HISTORY_POINTER_CRC] != CRC8(tempL.Byte, HISTORY_POINTER_CRC)) tempL.Word[0] = 1;
|
||||
else if(tempL.Word[0] >= HISTORY_DEPTH) tempL.Word[0] = 1;
|
||||
else if(tempL.Word[0] == 0) tempL.Word[0] = 1;
|
||||
else tempL.Word[0]++;
|
||||
|
||||
tempL.Byte[HISTORY_POINTER_CRC] = CRC8(tempL.Byte, HISTORY_POINTER_CRC);
|
||||
WriteMultiByteToEEPROM(HISTORY_POINTER, tempL.Byte, HISTORY_POINTER_WIDTH, DATA_EEPROM);
|
||||
if(WriteAnHistoryData(tempL.Word[0])) return 1;
|
||||
else return 0;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
u16 ReadRecentHistoryData(u8 *recent)
|
||||
{
|
||||
ReadMultiByteFromEEPROM(HISTORY_POINTER, tempL.Byte, HISTORY_POINTER_WIDTH, DATA_EEPROM);
|
||||
if(tempL.Byte[HISTORY_POINTER_CRC] != CRC8(tempL.Byte, HISTORY_POINTER_CRC)) return 0;
|
||||
|
||||
tempL.Word[0] = HISTORY_BASE + tempL.Word[0] * HISTORY_WIDTH;
|
||||
ReadMultiByteFromEEPROM(tempL.Word[0], recent, HISTORY_WIDTH, DATA_EEPROM);
|
||||
|
||||
if(recent[HISTORY_WIDTH_CRC] != CRC8(recent, HISTORY_WIDTH_CRC)) return 0;
|
||||
else return 1;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
// write history record
|
||||
// record: 2000
|
||||
// format: year-month-date-hour-min-second-ACC-FLOW-STATE
|
||||
/******************************************************************************/
|
||||
void WriteRecordTimeData(void)
|
||||
{
|
||||
u8 temp[RECORD_TIME_WIDTH];
|
||||
|
||||
CopyTimeToBackUpArray(temp);
|
||||
temp[RECORD_TIME_CRC] = CRC8(temp, RECORD_TIME_CRC);
|
||||
WriteMultiByteToEEPROM(HISTORY_BASE, temp, RECORD_TIME_WIDTH, DATA_EEPROM);
|
||||
|
||||
saveTimeCounter = 0;
|
||||
HWState.EnableSaveData = 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
// write date acc every day
|
||||
/******************************************************************************/
|
||||
u16 ReadRecentDateAccData(u8 *recent)
|
||||
{
|
||||
ReadMultiByteFromEEPROM(DATE_POINTER, tempL.Byte, DATE_POINTER_WIDTH, DATA_EEPROM);
|
||||
if(tempL.Byte[DATE_POINTER_CRC] != CRC8(tempL.Byte, DATE_POINTER_CRC)) return 0;
|
||||
if(tempL.Word[0] >= DATE_DEPTH) return 0;
|
||||
|
||||
tempL.Word[0] = DATE_BASE + tempL.Word[0] * DATE_WIDTH;
|
||||
ReadMultiByteFromEEPROM(tempL.Word[0], recent, DATE_WIDTH, DATA_EEPROM);
|
||||
|
||||
if(recent[DATE_WIDTH_CRC] != CRC8(recent, DATE_WIDTH_CRC)) return 0;
|
||||
else return 1;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
u16 DateAccWrite(void)
|
||||
{
|
||||
u8 temp[DATE_WIDTH];
|
||||
|
||||
// write date and accumulation into external EEPROM and update dateAccPointer
|
||||
// input: date, flowAcc, dateAccPointer
|
||||
// output: dateAccPointer
|
||||
|
||||
#ifndef REC_DATE_DATA
|
||||
#pragma message("[undefined] REC_DATE_DATA")
|
||||
#elif(REC_DATE_DATA)
|
||||
u16 wrt_base;
|
||||
unsigned char buffer[DATE_WIDTH];
|
||||
|
||||
ReadMultiByteFromEEPROM(DATE_POINTER, tempL.Byte, DATE_POINTER_WIDTH, DATA_EEPROM);
|
||||
if(tempL.Byte[DATE_POINTER_CRC] != CRC8(tempL.Byte, DATE_POINTER_CRC)) tempL.Word[0] = 1;
|
||||
if(tempL.Word[0] >= DATE_DEPTH) tempL.Word[0] = 1;
|
||||
else if(tempL.Word[0] >= DATE_DEPTH) tempL.Word[0] = 1;
|
||||
else tempL.Word[0]++;
|
||||
|
||||
tempL.Byte[DATE_POINTER_CRC] = CRC8(tempL.Byte, DATE_POINTER_CRC);
|
||||
WriteMultiByteToEEPROM(DATE_POINTER, tempL.Byte, DATE_POINTER_WIDTH, DATA_EEPROM);
|
||||
|
||||
wrt_base = DATE_BASE + tempL.Word[0] * DATE_WIDTH;
|
||||
|
||||
CopyTimeToBackUpArray(temp);
|
||||
CopyAccToBackUpArray(&temp[5]); // 6 Byte
|
||||
temp[DATE_WIDTH_CRC] = CRC8(temp, DATE_WIDTH_CRC);
|
||||
|
||||
WriteMultiByteToEEPROM(wrt_base, temp, DATE_WIDTH, DATA_EEPROM);
|
||||
ReadMultiByteFromEEPROM(wrt_base, buffer, DATE_WIDTH, DATA_EEPROM);
|
||||
for(wrt_base=0; wrt_base<DATE_WIDTH; wrt_base++)
|
||||
{
|
||||
if(buffer[wrt_base] != temp[wrt_base]) return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void ClearAlarmRecord(void)
|
||||
{
|
||||
u16 I, wrtBase;
|
||||
|
||||
wrtBase = ALARM_BASE + ALARM_DEPTH*ALARM_WIDTH;
|
||||
I = ALARM_BASE + ALARM_WIDTH;
|
||||
while(1)
|
||||
{
|
||||
if(wrtBase > I+100)
|
||||
{
|
||||
ClearMultiByteToEEPROM(I, 100, DATA_EEPROM);
|
||||
I += 100;
|
||||
}
|
||||
else
|
||||
{
|
||||
wrtBase -= I;
|
||||
ClearMultiByteToEEPROM(I, wrtBase, DATA_EEPROM);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
tempL.Word[0] = 0;
|
||||
tempL.Byte[ALARM_POINTER_CRC] = CRC8(tempL.Byte, ALARM_POINTER_CRC);
|
||||
WriteMultiByteToEEPROM(ALARM_POINTER, tempL.Byte, ALARM_POINTER_WIDTH, DATA_EEPROM);
|
||||
|
||||
}
|
||||
/******************************************************************************/
|
||||
void ClearHistoryRecord(void)
|
||||
{
|
||||
u16 I, wrtBase;
|
||||
|
||||
wrtBase = HISTORY_BASE + HISTORY_DEPTH*HISTORY_WIDTH;
|
||||
I = HISTORY_BASE + HISTORY_WIDTH;
|
||||
while(1)
|
||||
{
|
||||
if(wrtBase > I+100)
|
||||
{
|
||||
ClearMultiByteToEEPROM(I, 100, DATA_EEPROM);
|
||||
I += 100;
|
||||
}
|
||||
else
|
||||
{
|
||||
wrtBase -= I;
|
||||
ClearMultiByteToEEPROM(I, wrtBase, DATA_EEPROM);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
tempL.Word[0] = 0;
|
||||
tempL.Byte[HISTORY_POINTER_CRC] = CRC8(tempL.Byte, HISTORY_POINTER_CRC);
|
||||
WriteMultiByteToEEPROM(HISTORY_POINTER, tempL.Byte, HISTORY_POINTER_WIDTH, DATA_EEPROM);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void ClearDateRecord(void)
|
||||
{
|
||||
u16 I, wrtBase;
|
||||
|
||||
wrtBase = DATE_BASE + DATE_DEPTH*DATE_WIDTH;
|
||||
I = DATE_BASE + DATE_WIDTH;
|
||||
|
||||
while(1)
|
||||
{
|
||||
if(wrtBase > I+100)
|
||||
{
|
||||
ClearMultiByteToEEPROM(I, 100, DATA_EEPROM);
|
||||
I += 100;
|
||||
}
|
||||
else
|
||||
{
|
||||
wrtBase -= I;
|
||||
ClearMultiByteToEEPROM(I, wrtBase, DATA_EEPROM);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
tempL.Word[0] = 0;
|
||||
tempL.Byte[DATE_POINTER_CRC] = CRC8(tempL.Byte, DATE_POINTER_CRC);
|
||||
WriteMultiByteToEEPROM(DATE_POINTER, tempL.Byte, DATE_POINTER_WIDTH, DATA_EEPROM);
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void DataStorageManagement(void)
|
||||
{
|
||||
systemProcessing.Bit.SaveHandle = 0;
|
||||
|
||||
if(alarmState != lastState)
|
||||
{
|
||||
lastState = alarmState;
|
||||
disable_interrupts();
|
||||
if(AlarmWrite()) systemAlarm.Bit.EEPROMAlarm = 1;
|
||||
else systemAlarm.Bit.EEPROMAlarm = 0;
|
||||
enable_interrupts();
|
||||
}
|
||||
|
||||
// save history data
|
||||
if(HWState.EnableSaveHistoryData)
|
||||
{
|
||||
disable_interrupts();
|
||||
if(HistoryRecordWrite()) systemAlarm.Bit.EEPROMAlarm = 1;
|
||||
else systemAlarm.Bit.EEPROMAlarm = 0;
|
||||
historyPeriodSet = 0;
|
||||
HWState.EnableSaveHistoryData = 0;
|
||||
enable_interrupts();
|
||||
}
|
||||
|
||||
// save acc data
|
||||
if(HWState.EnableSaveDateAcc)
|
||||
{
|
||||
disable_interrupts();
|
||||
if(DateAccWrite()) systemAlarm.Bit.EEPROMAlarm = 1;
|
||||
else systemAlarm.Bit.EEPROMAlarm = 0;
|
||||
HWState.EnableSaveDateAcc = 0;
|
||||
enable_interrupts();
|
||||
}
|
||||
|
||||
if(HWState.EnableSaveRTC)
|
||||
{
|
||||
disable_interrupts();
|
||||
WriteRecordTimeData();
|
||||
enable_interrupts();
|
||||
}
|
||||
|
||||
HWState.EnableSaveData = 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void ReadRecordToComBuf(void)
|
||||
{
|
||||
disable_interrupts();
|
||||
ReadMultiByteFromEEPROM(MBBuf.StartAddr, &MBBuf.RxPointer[3], MBBuf.ByteNumber, DATA_EEPROM);
|
||||
MBBuf.ByteNumber -= 1;
|
||||
|
||||
if(MBBuf.RxPointer[3+MBBuf.ByteNumber] == CRC8(&MBBuf.RxPointer[3], MBBuf.ByteNumber)) MBBuf.RxPointer[3+MBBuf.ByteNumber] = 0xaa;
|
||||
enable_interrupts();
|
||||
}
|
||||
|
||||
83
user/Compute/SavingData.h
Executable file
83
user/Compute/SavingData.h
Executable file
@@ -0,0 +1,83 @@
|
||||
/********************************************************************************************************
|
||||
** HY3106<30><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>
|
||||
**
|
||||
** Copyright (c) Siargo, Ltd. 2011
|
||||
** All Rights Reserved.
|
||||
**
|
||||
**-------------------------------------------------------------------------------------------------------
|
||||
********************************************************************************************************/
|
||||
#ifndef __SavingData_h__
|
||||
#define __SavingData_h__
|
||||
|
||||
//******************************************************************************
|
||||
// for memory WIDTH
|
||||
|
||||
//******************************************************************************
|
||||
//******************************************************************************
|
||||
// for data eeprom ---[For 24c512]----------------------------------------------
|
||||
// DATE REC DATA
|
||||
// NO.0 ([YEAR] [MONTH] [DATE] [HOUR] [MINUTE] + <20><><EFBFBD><EFBFBD>1Сʱ<D0A1><CAB1><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
// Max addr: 0x300+12*1000 (0x2ee0) = 0x31e0
|
||||
#define DATE_POINTER (unsigned int)0x300 // DATE record start ponit addr
|
||||
#define DATE_POINTER_WIDTH (unsigned int)3
|
||||
#define DATE_POINTER_CRC (unsigned int)(DATE_POINTER_WIDTH-1)
|
||||
#define DATE_BASE (unsigned int)(DATE_POINTER+DATE_POINTER_WIDTH)
|
||||
#define DATE_WIDTH (unsigned int)12 // DATE record start eeprom addr
|
||||
#define DATE_WIDTH_CRC (unsigned int)(DATE_WIDTH-1)
|
||||
#define DATE_DEPTH (unsigned int)1000
|
||||
|
||||
// ALARM DATA
|
||||
// NO.0 <20><><EFBFBD><EFBFBD>ǰMEMS<4D><53><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>棨Ӳ<E6A3A8><D3B2><EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD>
|
||||
// No.1-No.599 ʵʱ<CAB5><CAB1><EFBFBD>汨<EFBFBD><E6B1A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// Max addr: 0x3200 + 16*1000 (0x3e80) = 0x7080
|
||||
#define ALARM_POINTER (unsigned int)0x3100 // alarm record start ponit addr
|
||||
#define ALARM_POINTER_WIDTH (unsigned int)3
|
||||
#define ALARM_POINTER_CRC (unsigned int)(ALARM_POINTER_WIDTH-1)
|
||||
#define ALARM_BASE (unsigned int)(ALARM_POINTER+ALARM_POINTER_WIDTH) // alarm record start eeprom addr
|
||||
#define ALARM_WIDTH (unsigned int)26
|
||||
#define ALARM_WIDTH_CRC (ALARM_WIDTH-1)
|
||||
#define ALARM_DEPTH (unsigned int)600
|
||||
|
||||
// HISTORY DATA
|
||||
// NO.0 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (NRH,LRH,(RR//RH), NIDX )
|
||||
// No.1-No.2000 <20><>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>
|
||||
// Max addr: 0x7100 + 18*2000 (0x8ca0) = 0xffa0
|
||||
#define HISTORY_POINTER (unsigned int)0x7100 // history record start ponit addr
|
||||
#define HISTORY_POINTER_WIDTH (unsigned int)3
|
||||
#define HISTORY_POINTER_CRC (unsigned int)(HISTORY_POINTER_WIDTH-1)
|
||||
#define HISTORY_BASE (unsigned int)(HISTORY_POINTER+HISTORY_POINTER_WIDTH) // history record start eeprom addr
|
||||
#define HISTORY_WIDTH (unsigned int)18
|
||||
#define HISTORY_WIDTH_CRC (unsigned int)(HISTORY_WIDTH-1)
|
||||
#define HISTORY_DEPTH (unsigned int)2000
|
||||
|
||||
//******************************************************************************
|
||||
// for memory WIDTH
|
||||
#define RECORD_TIME_WIDTH 6
|
||||
#define RECORD_TIME_CRC (RECORD_TIME_WIDTH-1)
|
||||
|
||||
//******************************************************************************
|
||||
extern u16 historyPeriodSet,saveTimeCounter;;
|
||||
//******************************************************************************
|
||||
|
||||
void SaveParameterInit(void);
|
||||
void CopyTimeToBackUpArray(u8 *backups);
|
||||
void CopyAccToBackUpArray(u8 *backups);
|
||||
u16 WriteaAnAlarmData(u16 pointer);
|
||||
u16 AlarmWrite(void);
|
||||
void ClearAlarmRecord(void);
|
||||
void ClearHistoryRecord(void);
|
||||
void ClearDateRecord(void);
|
||||
void SetHistoryRecordTime(void);
|
||||
|
||||
void WriteRecordTimeData(void);
|
||||
u16 ReadRecentHistoryData(u8 *recent);
|
||||
u16 WriteAnHistoryData(u16 pointer);
|
||||
u16 HistoryRecordWrite(void);
|
||||
|
||||
u16 ReadRecentDateAccData(u8 *recent);
|
||||
u16 DateAccWrite(void);
|
||||
void DataStorageManagement(void);
|
||||
void ReadRecordToComBuf(void);
|
||||
|
||||
/*******************/
|
||||
#endif
|
||||
54
user/Compute/StaticTemperature.c
Executable file
54
user/Compute/StaticTemperature.c
Executable file
@@ -0,0 +1,54 @@
|
||||
#include "../main/SystemInclude.h"
|
||||
|
||||
// for flowrate compute
|
||||
s32 RHCalibDeltaVaule, TACalibDeltaVaule, RHTemperature;
|
||||
static u16 zeroCalibType;
|
||||
|
||||
//******************************************************************************
|
||||
u16 ComputeRHTemperature(u16 RHRes)
|
||||
{
|
||||
s32 computeBuf;
|
||||
|
||||
RHCalibDeltaVaule = (u32)RHHighTa-(u32)RHLowTa;
|
||||
TACalibDeltaVaule = (u32)staticHighTemperature-(u32)staticLowTemperature;
|
||||
|
||||
computeBuf = (u32)RHRes-(u32)RHLowTa;
|
||||
computeBuf *= TACalibDeltaVaule;
|
||||
computeBuf /= RHCalibDeltaVaule;
|
||||
computeBuf += (u32)staticLowTemperature;
|
||||
|
||||
return (u16)computeBuf;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
void StaticTGasCompute(void)
|
||||
{
|
||||
voltageDetected[TRH] = ComputeRHTemperature(voltageDetected[RRRES]);
|
||||
|
||||
//==============================================================================
|
||||
#ifndef ENABLE_RR_CALIBRATION
|
||||
#pragma message("[undefined] ENABLE_RR_CALIBRATION")
|
||||
#elif(ENABLE_RR_CALIBRATION)
|
||||
// ͨ<><CDA8><EFBFBD>ߵ<EFBFBD><DFB5>±궨<C2B1><EAB6A8><EFBFBD><EFBFBD>RR<52><52><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¶<EFBFBD>
|
||||
RHCalibDeltaVaule = (u32)RRHigh-(u32)RRLow;
|
||||
TACalibDeltaVaule = (u32)staticHighTemperature-(u32)staticLowTemperature;
|
||||
|
||||
tmpSLA = (u32)voltageDetected[RRRES]-(u32)RRLow;
|
||||
tmpSLA *= TACalibDeltaVaule;
|
||||
tmpSLA /= RHCalibDeltaVaule;
|
||||
tmpSLA += (u32)staticLowTemperature;
|
||||
voltageDetected[TGAS] = (u16)tmpSLA;
|
||||
#else
|
||||
// ͨ<><CDA8>RRĬ<52>ϵ<EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¶<EFBFBD>
|
||||
voltageDetected[TGAS] = voltageDetected[TPCB];
|
||||
#endif
|
||||
|
||||
//==============================================================================
|
||||
#ifndef ENABLE_PRESSURE_TEMPERATURE
|
||||
#pragma message("[undefined] ENABLE_PRESSURE_TEMPERATURE")
|
||||
#elif(!ENABLE_PRESSURE_TEMPERATURE)
|
||||
GasTemperature = (u16)voltageDetected[TGAS];
|
||||
GasTemperature -= (u16)TEMPRETURE_OFFSET;
|
||||
#endif
|
||||
}
|
||||
|
||||
32
user/Compute/StaticTemperature.h
Executable file
32
user/Compute/StaticTemperature.h
Executable file
@@ -0,0 +1,32 @@
|
||||
/********************************************************************************************************
|
||||
** HY3106<30><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>
|
||||
**
|
||||
** Copyright (c) Siargo, Ltd. 2011
|
||||
** All Rights Reserved.
|
||||
**
|
||||
**-------------------------------------------------------------------------------------------------------
|
||||
********************************************************************************************************/
|
||||
#ifndef __StaticTemperature_h__
|
||||
#define __StaticTemperature_h__
|
||||
|
||||
//******************************************************************************
|
||||
#define STATIC_LOW_TA_DEFAULT TEMPRETURE_OFFSET
|
||||
#define STATIC_HIGH_TA_DEFAULT (TEMPRETURE_OFFSET+500)
|
||||
|
||||
#define RH_0_DEFAULT 8500
|
||||
#define RH_50_DEFAULT 10000
|
||||
|
||||
#define RES_FACTOR_DEFAULT 30
|
||||
#define RES_FACTOR_MIN 25
|
||||
#define RES_FACTOR_MAX 35
|
||||
|
||||
// for flowrate compute
|
||||
extern s32 RHCalibDeltaVaule, TACalibDeltaVaule, RHTemperature;
|
||||
//******************************************************************************
|
||||
void StaticTemperatureInit(void);
|
||||
void StaticTGasCompute(void);
|
||||
u16 ComputeRHTemperature(u16 RHRes);
|
||||
|
||||
//******************************************************************************
|
||||
#endif
|
||||
//******************************************************************************
|
||||
255
user/Compute/TemperatureCorrect.c
Executable file
255
user/Compute/TemperatureCorrect.c
Executable file
@@ -0,0 +1,255 @@
|
||||
#include "../main/SystemInclude.h"
|
||||
//==============================================================================
|
||||
/*
|
||||
resFactor,temperatureFactor must be define in internal modbus
|
||||
*/
|
||||
u16 calibTANode[CURVE_DATA_MAX];
|
||||
u16 calibTAVal[CURVE_DATA_MAX], curveTANum;
|
||||
|
||||
/******************************************************************************/
|
||||
void TemperatureCorrectInit(void)
|
||||
{
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void TemperatureCorrection(void)
|
||||
{
|
||||
float tempF;
|
||||
|
||||
#ifndef TEMP_CORR_USE_RR
|
||||
#pragma message("[undefined] TEMP_CORR_USE_RR")
|
||||
#elif(TEMP_CORR_USE_RR)
|
||||
// currentFlowRate = ((RH-RHROOM)*temperatureFactor*currentFlowRate)/(RHROOM*resFactor)
|
||||
// resFactor: default 0.0030 --->30
|
||||
// temperatureFactor: default 0.0030 --->30
|
||||
// tmpSLA = (signed long int)voltageDetected[NRR];
|
||||
// tmpSLA -= (signed long int)NRHRoom;
|
||||
// tmpSLA *= (signed long int)temperatureFactor;
|
||||
// tmpSLA *= (signed long int)10000;
|
||||
//
|
||||
// tmpSLB = (signed long int)NRHRoom;
|
||||
// tmpSLB *= (signed long int)resFactor;
|
||||
// tmpSLA /= tmpSLB;
|
||||
// tmpSLA += (signed long int)10000;
|
||||
|
||||
#ifndef ENABLE_MULTI_PONIT_TA_CORR
|
||||
#pragma message("[undefined] ENABLE_MULTI_PONIT_TA_CORR")
|
||||
#elif(ENABLE_MULTI_PONIT_TA_CORR)
|
||||
tmpSLB = (signed long int)GetTACurveValue(voltageDetected[CTYPE_FR]);
|
||||
#else
|
||||
tmpSLB = (signed long int)NRHRoom;
|
||||
#endif
|
||||
|
||||
if((tmpSLB > NRR_MAX) || (tmpSLB < NRR_MIN))
|
||||
{
|
||||
voltageDetected[TCOE] = 10000;
|
||||
return;
|
||||
}
|
||||
|
||||
tmpSLA = (signed long int)voltageDetected[NRR];
|
||||
tmpSLA -= (signed long int)tmpSLB;
|
||||
tmpSLA *= (signed long int)temperatureFactor;
|
||||
tmpSLA *= (signed long int)10000;
|
||||
|
||||
tmpSLB *= (signed long int)resFactor;
|
||||
tmpSLA /= tmpSLB;
|
||||
tmpSLA += (signed long int)10000;
|
||||
//------------------------------------------------------------------------------
|
||||
#else
|
||||
//------------------------------------------------------------------------------
|
||||
#ifndef ENABLE_MULTI_PONIT_TA_CORR
|
||||
#pragma message("[undefined] ENABLE_MULTI_PONIT_TA_CORR")
|
||||
#elif(ENABLE_MULTI_PONIT_TA_CORR)
|
||||
tmpSLB = (signed long int)GetTACurveValue(voltageDetected[CTYPE_FR]);
|
||||
#else
|
||||
tmpSLB = (signed long int)calibTemperature;
|
||||
#endif
|
||||
|
||||
if((tmpSLB > 13500) || (tmpSLB < 11000))
|
||||
{
|
||||
voltageDetected[TCOE] = 10000;
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef TEMP_CORR_USE_TA
|
||||
#pragma message("[undefined] TEMP_CORR_USE_TA")
|
||||
#elif(TEMP_CORR_USE_TA)
|
||||
tmpSLA = (signed long int)voltageDetected[TPCB];
|
||||
#else
|
||||
tmpSLA = (signed long int)voltageDetected[TGAS];
|
||||
#endif
|
||||
|
||||
tmpSLA -= tmpSLB;
|
||||
tmpSLA *= (signed long int)temperatureFactor;
|
||||
tmpSLA /= (signed long int)100;
|
||||
tmpSLA += (signed long int)10000;
|
||||
#endif
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
if(tmpSLA > 12000) tmpSLA = 12000;
|
||||
else if(tmpSLA < 8000) tmpSLA = 8000;
|
||||
voltageDetected[TCOE] = (unsigned int)tmpSLA;
|
||||
tempF = (float)tmpSLA;
|
||||
tempF /= (float)10000;
|
||||
tempF *= (float)currentFlowRate;
|
||||
|
||||
currentFlowRate = (unsigned long int)tempF;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߽ڵ<DFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>
|
||||
u8 ReadTACurveNodeAndValue(u16 I)
|
||||
{
|
||||
ReadMultiByteFromEEPROM(TACURVE_DATA_BASE + I * TACURVE_DATA_WIDTH, tempDev.Byte, TACURVE_DATA_WIDTH, PARA_EEPROM);
|
||||
if(tempDev.Byte[TACURVE_DATA_CRC] == CRC8(tempDev.Byte, TACURVE_DATA_CRC))
|
||||
{
|
||||
tempDev.Byte[TACURVE_DATA_CRC] = 0;
|
||||
|
||||
calibTAVal[I] = tempDev.Word[0];
|
||||
calibTANode[I] = tempDev.Word[1];
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
calibTAVal[I] = 0;
|
||||
calibTANode[I] = 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
//Ĭ<>ϵĶ<CFB5><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߲<EFBFBD><DFB2><EFBFBD>
|
||||
void DefaultTACuvre(void)
|
||||
{
|
||||
curveTANum = 5;
|
||||
calibTANode[0] = 0;
|
||||
calibTANode[1] = 5000;
|
||||
calibTANode[2] = 10000;
|
||||
calibTANode[3] = 15000;
|
||||
calibTANode[4] = 20000;
|
||||
|
||||
calibTAVal[0] = 0;
|
||||
calibTAVal[1] = 0;
|
||||
calibTAVal[2] = 0;
|
||||
calibTAVal[3] = 0;
|
||||
calibTAVal[4] = 0;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߲<EFBFBD><DFB2><EFBFBD>
|
||||
void RetriveTACurve(void)
|
||||
{
|
||||
ReadMultiByteFromMemory(TACURVE_NUM, tempL.Byte, TACURVE_NUM_WIDTH);
|
||||
if(tempL.Byte[1] != CRC8(tempL.Byte, 1)) goto RetResetCurve;
|
||||
|
||||
curveTANum = tempL.Byte[0];
|
||||
if((curveTANum > CURVE_DATA_MAX)||(curveTANum < 3)) goto RetResetCurve;
|
||||
|
||||
for(unsigned char I = 0; I < curveTANum; I++) ReadTACurveNodeAndValue(I);
|
||||
return;
|
||||
|
||||
RetResetCurve:
|
||||
DefaultTACuvre();
|
||||
return;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
u16 GetTACurveValue(u16 calibIndex)
|
||||
{
|
||||
u16 I;
|
||||
|
||||
if((curveTANum < 3) || (curveTANum > CURVE_DATA_MAX))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(I = 0; I < curveTANum - 1; I++)
|
||||
{
|
||||
if(calibTANode[I] > 32767) continue;
|
||||
if(calibTANode[I] > calibIndex) break;
|
||||
}
|
||||
|
||||
if(I == 0) return calibTAVal[0];
|
||||
|
||||
Secondary.NodeX = calibIndex;
|
||||
if(calibTANode[I] > 32767) Secondary.NodeH = 0;
|
||||
else Secondary.NodeH = calibTANode[I];
|
||||
if(calibTANode[I-1] > 32767) Secondary.NodeL = 0;
|
||||
else Secondary.NodeL = calibTANode[I-1];
|
||||
|
||||
Secondary.ValueH = calibTAVal[I];
|
||||
Secondary.ValueL = calibTAVal[I-1];
|
||||
|
||||
return SecondaryCompute();
|
||||
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void ReadCurveByCom(void)
|
||||
{
|
||||
u16 I;
|
||||
|
||||
I = MBBuf.StartAddr;
|
||||
I -= INT_CURVE_NODE1;
|
||||
I /= INT_CURVE_WIDTH;
|
||||
|
||||
MBBuf.RxPointer[MBBuf.Index++] = 0;
|
||||
MBBuf.RxPointer[MBBuf.Index++] = 0;
|
||||
if(calibType == INTCMD_1ST_TABLE) {
|
||||
tempL.Word[1] = calibTANode[I];
|
||||
tempL.Word[0] = calibTAVal[I];
|
||||
}
|
||||
else if(calibType == INTCMD_2ND_TABLE) {
|
||||
tempL.Word[1] = ATypeNode[I];
|
||||
tempL.Word[0] = ATypeVal[I];
|
||||
}
|
||||
|
||||
MBBuf.RxPointer[MBBuf.Index++] = tempL.Byte[3];
|
||||
MBBuf.RxPointer[MBBuf.Index++] = tempL.Byte[2];
|
||||
MBBuf.RxPointer[MBBuf.Index++] = tempL.Byte[1];
|
||||
MBBuf.RxPointer[MBBuf.Index++] = tempL.Byte[0];
|
||||
|
||||
MBBuf.DataByte = CURVE_DATA_WIDTH;
|
||||
ModbusVariablePointerDec();
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void WriteCurveByCom(void)
|
||||
{
|
||||
MBBuf.DataByte = CURVE_DATA_WIDTH;
|
||||
if(MBBuf.ByteNumber < MBBuf.DataByte)
|
||||
{
|
||||
MBBuf.ByteNumber = 0;
|
||||
MBBuf.BusError = ILLEGAL_DATA_VALUE;
|
||||
return;
|
||||
}
|
||||
|
||||
u16 I;
|
||||
|
||||
I = MBBuf.StartAddr;
|
||||
I -= INT_CURVE_NODE1;
|
||||
I /= INT_CURVE_WIDTH;
|
||||
|
||||
tempDev.Byte[5] = MBBuf.RxPointer[MBBuf.Index++];
|
||||
tempDev.Byte[4] = MBBuf.RxPointer[MBBuf.Index++];
|
||||
tempDev.Byte[3] = MBBuf.RxPointer[MBBuf.Index++];
|
||||
tempDev.Byte[2] = MBBuf.RxPointer[MBBuf.Index++];
|
||||
tempDev.Byte[1] = MBBuf.RxPointer[MBBuf.Index++];
|
||||
tempDev.Byte[0] = MBBuf.RxPointer[MBBuf.Index++];
|
||||
|
||||
tempDev.DWord[1] = 0;
|
||||
if(calibType == INTCMD_1ST_TABLE)
|
||||
{
|
||||
WriteMultiByteToMemory(TACURVE_DATA_BASE+I*TACURVE_DATA_WIDTH, &tempDev.Byte[0], TACURVE_DATA_WIDTH);
|
||||
calibTANode[I] = tempDev.Word[1];
|
||||
calibTAVal[I] = tempDev.Word[0];
|
||||
}
|
||||
else if(calibType == INTCMD_2ND_TABLE)
|
||||
{
|
||||
WriteMultiByteToMemory(ATYPECURVE_DATA_BASE+I*ATYPECURVE_DATA_WIDTH, &tempDev.Byte[0], ATYPECURVE_DATA_WIDTH);
|
||||
ATypeNode[I] = tempDev.Word[1];
|
||||
ATypeVal[I] = tempDev.Word[0];
|
||||
}
|
||||
}
|
||||
|
||||
29
user/Compute/TemperatureCorrect.h
Executable file
29
user/Compute/TemperatureCorrect.h
Executable file
@@ -0,0 +1,29 @@
|
||||
/********************************************************************************************************
|
||||
** HY3106<30><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>
|
||||
**
|
||||
** Copyright (c) Siargo, Ltd. 2011
|
||||
** All Rights Reserved.
|
||||
**
|
||||
**-------------------------------------------------------------------------------------------------------
|
||||
********************************************************************************************************/
|
||||
#ifndef __TemperatureCorrect_h__
|
||||
#define __TemperatureCorrect_h__
|
||||
|
||||
|
||||
#define CODE_COEFF_GIAN 10000
|
||||
//==============================================================================
|
||||
extern u16 calibTANode[];
|
||||
extern u16 calibTAVal[], curveTANum;
|
||||
extern u16 resFactor,temperatureFactor;
|
||||
|
||||
/******************************************************************************/
|
||||
void TemperatureCorrectInit(void);
|
||||
u8 ReadTACurveNodeAndValue(u16 I);
|
||||
void DefaultTACuvre(void);
|
||||
void RetriveTACurve(void);
|
||||
u16 GetTACurveValue(u16 calibIndex);
|
||||
void ReadCurveByCom(void);
|
||||
void WriteCurveByCom(void);
|
||||
|
||||
void TemperatureCorrection(void);
|
||||
#endif
|
||||
455
user/Compute/UnitConverter.c
Executable file
455
user/Compute/UnitConverter.c
Executable file
@@ -0,0 +1,455 @@
|
||||
#include "../main/SystemInclude.h"
|
||||
|
||||
u16 flowDisUnit, flowComUnit, AccDisUnit, AccComputeUnit, AccComUnit;
|
||||
long double lastUnit, currentUnit;
|
||||
|
||||
/******************************************************************************/
|
||||
void CombinedUnitByFlowRate(void)
|
||||
{
|
||||
switch(flowDisUnit)
|
||||
{
|
||||
#if(ENABLE_SCCM_SL)
|
||||
case SCCM: flowUnit = SCCM_SL; break;
|
||||
#endif
|
||||
|
||||
case SLPM:
|
||||
if(AccDisUnit == SL) flowUnit = SLPM_SL;
|
||||
else if(AccDisUnit == NM3) flowUnit = SLPM_NM3;
|
||||
else flowUnit = SLPM_NM3;
|
||||
break;
|
||||
|
||||
#if(ENABLE_NCMH_NM3)
|
||||
case NCMH: flowUnit = NCMH_NM3; break;
|
||||
#endif
|
||||
|
||||
#if(ENABLE_SCFM_SCF)
|
||||
case SCFM: flowUnit = SCFM_SCF; break;
|
||||
#endif
|
||||
|
||||
#if(ENABLE_KGH_KG)
|
||||
case KGH: flowUnit = KGH_KG; break;
|
||||
#endif
|
||||
|
||||
#if(ENABLE_SCFH_SCF)
|
||||
case SCFH: flowUnit = SCFH_SCF; break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void CombinedUnitByACC(void)
|
||||
{
|
||||
switch(AccDisUnit)
|
||||
{
|
||||
case SL:
|
||||
if(flowDisUnit == SLPM) flowUnit = SLPM_SL;
|
||||
else if(flowDisUnit == NM3) flowUnit = SLPM_NM3;
|
||||
#if(ENABLE_SCCM_SL)
|
||||
else if(flowDisUnit == SCCM) flowUnit = SCCM_SL;
|
||||
#endif
|
||||
else flowUnit = SLPM_NM3;
|
||||
break;
|
||||
|
||||
case NM3:
|
||||
if(flowDisUnit == SLPM) flowUnit = SLPM_NM3;
|
||||
#if(ENABLE_NCMH_NM3)
|
||||
else if(flowDisUnit == NM3) flowUnit = NCMH_NM3;
|
||||
#endif
|
||||
else flowUnit = SLPM_NM3;
|
||||
break;
|
||||
|
||||
case SCF:
|
||||
#if(ENABLE_SCFM_SCF)
|
||||
flowUnit = SCFM_SCF;
|
||||
#elif(ENABLE_SCFH_SCF)
|
||||
flowUnit = SCFH_SCF;
|
||||
#endif
|
||||
break;
|
||||
|
||||
#if(ENABLE_KGH_KG)
|
||||
case KGH: flowUnit = KGH_KG; break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
u16 JudgeflowUserUnit(u16 judgeUnit)
|
||||
{
|
||||
switch(judgeUnit)
|
||||
{
|
||||
#if(ENABLE_SCCM_SL)
|
||||
case SCCM: return 1;
|
||||
#endif
|
||||
|
||||
#if(ENABLE_SLPM_NM3)
|
||||
case SLPM: return 1;
|
||||
#endif
|
||||
|
||||
#if(ENABLE_NCMH_NM3)
|
||||
case NCMH: return 1;
|
||||
#endif
|
||||
|
||||
#if(ENABLE_SCFM_SCF)
|
||||
case SCFM: return 1;
|
||||
#endif
|
||||
|
||||
#if(ENABLE_SCFH_SCF)
|
||||
case SCFH: return 1;
|
||||
#endif
|
||||
|
||||
#if(ENABLE_KGH_KG)
|
||||
case KGH: return 1;
|
||||
#endif
|
||||
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
u16 JudgeflowAccUnit(u16 judgeUnit)
|
||||
{
|
||||
switch(judgeUnit)
|
||||
{
|
||||
#if(ENABLE_SCCM_SL)
|
||||
case ML: return 1;
|
||||
#endif
|
||||
|
||||
#if(ENABLE_SLPM_NM3)||(ENABLE_SLPM_SL)
|
||||
case SL: return 1;
|
||||
#endif
|
||||
|
||||
#if((ENABLE_SLPM_NM3)||(ENABLE_NCMH_NM3))
|
||||
case NM3: return 1;
|
||||
#endif
|
||||
|
||||
#if((ENABLE_SCFM_SCF)||(ENABLE_SCFH_SCF))
|
||||
case SCF: return 1;
|
||||
#endif
|
||||
|
||||
#if(ENABLE_KGH_KG)
|
||||
case KG: return 1;
|
||||
#endif
|
||||
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
u16 JudgeflowUnit(u16 judgeUnit)
|
||||
{
|
||||
switch(judgeUnit)
|
||||
{
|
||||
//--------------------------------------------------------------------------
|
||||
#ifndef ENABLE_SCCM_SL
|
||||
#pragma message("[undefined] ENABLE_SCCM_SL")
|
||||
#elif(ENABLE_SCCM_SL)
|
||||
case SCCM_SL:
|
||||
flowDisUnit = SCCM;
|
||||
flowComUnit = SCCM;
|
||||
|
||||
AccDisUnit = SL;
|
||||
AccComputeUnit = SL;
|
||||
AccComUnit = SL;
|
||||
break;
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
#ifndef ENABLE_SLPM_NM3
|
||||
#pragma message("[undefined] ENABLE_SLPM_NM3")
|
||||
#elif(ENABLE_SLPM_NM3)
|
||||
case SLPM_NM3:
|
||||
flowDisUnit = SLPM;
|
||||
flowComUnit = SLPM;
|
||||
|
||||
AccDisUnit = NM3;
|
||||
AccComputeUnit = NM3;
|
||||
AccComUnit = NM3;
|
||||
break;
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
#ifndef ENABLE_NCMH_NM3
|
||||
#pragma message("[undefined] ENABLE_NCMH_NM3")
|
||||
#elif(ENABLE_NCMH_NM3)
|
||||
case NCMH_NM3:
|
||||
flowDisUnit = NCMH;
|
||||
#ifndef ENABLE_FIXED_UART_FR
|
||||
#pragma message("[undefined] ENABLE_FIXED_UART_FR")
|
||||
#elif(ENABLE_FIXED_UART_FR)
|
||||
flowComUnit = SLPM;
|
||||
#else
|
||||
flowComUnit = NCMH;
|
||||
#endif
|
||||
|
||||
AccDisUnit = NM3;
|
||||
AccComputeUnit = NM3;
|
||||
AccComUnit = NM3;
|
||||
break;
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
#ifndef ENABLE_SCFM_SCF
|
||||
#pragma message("[undefined] ENABLE_SCFM_SCF")
|
||||
#elif(ENABLE_SCFM_SCF)
|
||||
case SCFM_SCF:
|
||||
flowDisUnit = SCFM;
|
||||
flowComUnit = SCFM;
|
||||
|
||||
AccDisUnit = SCF;
|
||||
AccComputeUnit = SCF;
|
||||
AccComUnit = SCF;
|
||||
break;
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
#ifndef ENABLE_KGH_KG
|
||||
#pragma message("[undefined] ENABLE_KGH_KG")
|
||||
#elif(ENABLE_KGH_KG)
|
||||
case KGH_KG:
|
||||
flowDisUnit = KGH;
|
||||
flowComUnit = KGH;
|
||||
|
||||
AccDisUnit = KG;
|
||||
AccComputeUnit = KG;
|
||||
AccComUnit = KG;
|
||||
break;
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
#ifndef ENABLE_SLPM_SL
|
||||
#pragma message("[undefined] ENABLE_SLPM_SL")
|
||||
#elif(ENABLE_SLPM_SL)
|
||||
case SLPM_SL:
|
||||
flowDisUnit = SLPM;
|
||||
flowComUnit = SLPM;
|
||||
|
||||
AccDisUnit = SL;
|
||||
AccComputeUnit = ACC_STD_UINT;
|
||||
#ifndef ENABLE_FIXED_UART_FR
|
||||
#pragma message("[undefined] ENABLE_FIXED_UART_FR")
|
||||
#elif(ENABLE_FIXED_UART_FR)
|
||||
AccComUnit = ACC_STD_UINT;
|
||||
#else
|
||||
AccComUnit = SL;
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
#ifndef ENABLE_SCFH_SCF
|
||||
#pragma message("[undefined] ENABLE_SCFH_SCF")
|
||||
#elif(ENABLE_SCFH_SCF)
|
||||
case SCFH_SCF:
|
||||
flowDisUnit = SCFH;
|
||||
flowComUnit = SCFH;
|
||||
|
||||
AccDisUnit = SCF;
|
||||
AccComputeUnit = SCF;
|
||||
AccComUnit = SCF;
|
||||
break;
|
||||
#endif
|
||||
|
||||
default: return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
u32 ConvertFlowrate(u32 flowRateBuf, u16 targetUnit, u16 originalUnit)
|
||||
{
|
||||
if(targetUnit == originalUnit) return flowRateBuf;
|
||||
|
||||
long double flowRateTemp;
|
||||
switch(originalUnit)
|
||||
{
|
||||
case SCCM: lastUnit = (long double)ONE_SCCM_TO_STD_FR; break;
|
||||
case SLPM: lastUnit = (long double)ONE_SLPM_TO_STD_FR; break;
|
||||
case NCMH: lastUnit = (long double)ONE_NCMH_TO_STD_FR; break;
|
||||
case SCFM: lastUnit = (long double)ONE_SCFM_TO_STD_FR; break;
|
||||
case KGH: lastUnit = (long double)ONE_KGH_TO_STD_FR; break;
|
||||
case SCFH: lastUnit = (long double)ONE_SCFH_TO_STD_FR; break;
|
||||
default: lastUnit = 1;
|
||||
}
|
||||
|
||||
switch(targetUnit)
|
||||
{
|
||||
case SCCM: flowRateTemp = (long double)ONE_STD_FR_TO_SCCM; break;
|
||||
case SLPM: flowRateTemp = (long double)ONE_STD_FR_TO_SLPM; break;
|
||||
case NCMH:
|
||||
flowRateTemp = (long double)ONE_STD_FR_TO_NCMH;
|
||||
break;
|
||||
case SCFM: flowRateTemp = (long double)ONE_STD_FR_TO_SCFM; break;
|
||||
case KGH: flowRateTemp = (long double)ONE_STD_FR_TO_KGH; break;
|
||||
case SCFH: flowRateTemp = (long double)ONE_STD_FR_TO_SCFH; break;
|
||||
default: flowRateTemp = 1;
|
||||
}
|
||||
|
||||
flowRateTemp *= (long double)lastUnit;
|
||||
flowRateTemp *= (long double)flowRateBuf;
|
||||
|
||||
return (u32)flowRateTemp;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void ConvertAllFlowRateAndSave(u16 NewFlowUnit)
|
||||
{
|
||||
u16 I;
|
||||
long double totalFlowRateCompute;
|
||||
u16 originalFlowUnit, originalAccComputeUnit;
|
||||
unsigned long long int tmpQWordA;
|
||||
|
||||
originalFlowUnit = flowComUnit;
|
||||
originalAccComputeUnit = AccComputeUnit;
|
||||
if(JudgeflowUnit(NewFlowUnit)) return;
|
||||
|
||||
disable_interrupts();
|
||||
// flowUnit
|
||||
// max flowRate
|
||||
maxFlowRate = ConvertFlowrate(maxFlowRate, flowComUnit, originalFlowUnit);
|
||||
tempDev.DWord[0] = maxFlowRate;
|
||||
maxFlowRate = WriteLongParameterToMemory(OUT_MAX_FLOW);
|
||||
tempL.DWord = maxFlowRate;
|
||||
maxFlowRateH = tempL.Word[1];
|
||||
maxFlowRateL = tempL.Word[0];
|
||||
|
||||
// min flowRate
|
||||
minFlowRate = ConvertFlowrate(minFlowRate, flowComUnit, originalFlowUnit);
|
||||
tempDev.DWord[0] = minFlowRate;
|
||||
minFlowRate = WriteLongParameterToMemory(OUT_MIN_FLOW);
|
||||
tempL.DWord = minFlowRate;
|
||||
minFlowRateH = tempL.Word[1];
|
||||
minFlowRateL = tempL.Word[0];
|
||||
|
||||
// alarmUpperFlowRate = ConvertFlowrate(alarmUpperFlowRate, flowComUnit, originalFlowUnit);
|
||||
// tempDev.DWord[0] = alarmUpperFlowRate;
|
||||
// alarmUpperFlowRate = WriteShortParameterToEEPROM(HIGH_FLOW_ALARM, HIGH_FLOW_ALARM_WIDTH);
|
||||
//
|
||||
// alarmLowerFlowRate = ConvertFlowrate(alarmLowerFlowRate, flowComUnit, originalFlowUnit);
|
||||
// tempDev.DWord[0] = alarmLowerFlowRate;
|
||||
// alarmLowerFlowRate = WriteParameterToEEPROM(LOW_FLOW_ALARM, LOW_FLOW_ALARM_WIDTH);
|
||||
|
||||
// correct data
|
||||
for(I = 0; I < (u16)dcoefNum; I++)
|
||||
{
|
||||
dcoefNode[I] = ConvertFlowrate(dcoefNode[I], flowComUnit, originalFlowUnit);
|
||||
StoreDevCoefNodeAndValue(I);
|
||||
}
|
||||
|
||||
// Convert ACC FlowRate
|
||||
// to STD flowunit
|
||||
if(originalAccComputeUnit != AccComputeUnit)
|
||||
{
|
||||
// У<D0A3><D7BC><EFBFBD><EFBFBD>ΪSLPMʱ<4D><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪNM3,6λС<CEBB><D0A1>
|
||||
switch(originalAccComputeUnit)
|
||||
{
|
||||
//case ML: lastUnit = (long double)ONE_ML_TO_STD_ACC; break;
|
||||
case SL: lastUnit = (long double)ONE_SL_TO_STD_ACC; break;
|
||||
case NM3: lastUnit = (long double)ONE_NCM_TO_STD_ACC; break;
|
||||
case SCF: lastUnit = (long double)ONE_SCF_TO_STD_ACC; break;
|
||||
case KG: lastUnit = (long double)ONE_KG_TO_STD_ACC; break;
|
||||
default: lastUnit = 1;
|
||||
}
|
||||
|
||||
// to User FlowUnit
|
||||
switch(AccComputeUnit)
|
||||
{
|
||||
//case ML: totalFlowRateCompute = (long double)ONE_STD_ACC_TO_ML; break;
|
||||
case SL: totalFlowRateCompute = (long double)ONE_STD_ACC_TO_SL; break;
|
||||
case NM3: totalFlowRateCompute = (long double)ONE_STD_ACC_TO_NCM; break;
|
||||
case SCF: totalFlowRateCompute = (long double)ONE_STD_ACC_TO_SCF; break;
|
||||
case KG: totalFlowRateCompute = (long double)ONE_STD_ACC_TO_KG; break;
|
||||
default: totalFlowRateCompute = 1;
|
||||
}
|
||||
|
||||
ReleaseTotalToDisArray();
|
||||
ReleaseToIntAndDecimalBuf();
|
||||
totalFlowRateCompute *= (long double)flowTotalBuffer;
|
||||
totalFlowRateCompute *= lastUnit;
|
||||
flowTotalBuffer = (unsigned long long int)totalFlowRateCompute;
|
||||
|
||||
// convert HEX TO BCD
|
||||
tmpQWordA = flowTotalBuffer;
|
||||
tmpQWordA /= 1000000000;
|
||||
tmpLA = (u32)tmpQWordA;
|
||||
tmpQWordA *= 1000000000;
|
||||
flowTotalBuffer -= tmpQWordA;
|
||||
tmpLB = (u32)flowTotalBuffer;
|
||||
|
||||
ConvertHEXToBCDArray(tmpLB, &Dis2[5], 9, HIGH_FIRST);
|
||||
ConvertHEXToBCDArray(tmpLA, &Dis2[0], 5, HIGH_FIRST);
|
||||
SendToTotalArray();
|
||||
|
||||
ReleaseToIntAndDecimalBufForUart();
|
||||
for(I=0; I <= REC_ACC_DEPTH; I++) FRAMWriteTotal();
|
||||
|
||||
lastRemaining = 0;
|
||||
flowAccCumulationRemaining = 0;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
tempL.Word[0] = NewFlowUnit;
|
||||
flowUnit = WriteShortParameterToMemory(FLOW_UNIT);
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
u16 ReturnStartUnitBit(u16 stdBit)
|
||||
{
|
||||
switch(AccComputeUnit)
|
||||
{
|
||||
case SL:
|
||||
if(AccComUnit == ML) stdBit += 3;
|
||||
break;
|
||||
|
||||
case NM3:
|
||||
if(AccComUnit == SL) stdBit += 3;
|
||||
break;
|
||||
}
|
||||
|
||||
return stdBit;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
// V2004
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λΪSLPM<50><4D>NCMHʱ<48><CAB1><EFBFBD><EFBFBD>С<EFBFBD><D0A1>λ 1mL
|
||||
// Flow Unit = SLPM: (((Flow*60)/1000)*1000)/TimeBase
|
||||
// Flow Unit = NCMH: (Flow*1000)/TimeBase
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŵ<EFBFBD><C5B4><EFBFBD><EFBFBD><EFBFBD>
|
||||
// FRUnitForHour[] ={28800, 14400, 7200, 3600, 1800, 900}
|
||||
// FRUnitForMinute[] ={480, 240, 120, 60, 30, 15}
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0xFFFFFFF/(1000/15):65000000
|
||||
u16 ConvertTimeBaseAndUnit(u16 unit, u16 timeBaseIndex)
|
||||
{
|
||||
switch(unit)
|
||||
{
|
||||
case SCCM: // ACC->SLPM
|
||||
case SLPM: // ACC->SLPM
|
||||
AccComputeTimeBase = (u32)FRUnitForMinute[timeBaseIndex];
|
||||
return 1;
|
||||
|
||||
case SCFM:
|
||||
AccComputeTimeBase = (u32)FRUnitForMinute[timeBaseIndex];
|
||||
break;
|
||||
|
||||
default: AccComputeTimeBase = (u32)FRUnitForHour[timeBaseIndex];
|
||||
break;
|
||||
}
|
||||
|
||||
return 1000;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
void UnitConverterInit(void)
|
||||
{
|
||||
//ReadMultiByteFromEEPROM(CALIB_DIAMETER, tempL.Byte, CALIB_DIAMETER_WIDTH, PARA_EEPROM);
|
||||
//if(tempL.Byte[CALIB_DIAMETER_CRC] != CRC8(tempL.Byte, CALIB_DIAMETER_CRC)) flowUnit = CALIB_DIAMETER_DEFAULT;
|
||||
//else flowUnit = tempL.Word[0];
|
||||
|
||||
flowUnit = (u16)ReadShortParameterFromMemory(FLOW_UNIT, FLOW_UNIT_DEFAULT);
|
||||
if(JudgeflowUnit(flowUnit))
|
||||
{
|
||||
flowUnit = FLOW_UNIT_DEFAULT;
|
||||
JudgeflowUnit(flowUnit);
|
||||
}
|
||||
}
|
||||
|
||||
169
user/Compute/UnitConverter.h
Executable file
169
user/Compute/UnitConverter.h
Executable file
@@ -0,0 +1,169 @@
|
||||
/********************************************************************************************************
|
||||
** HY3106<30><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>
|
||||
**
|
||||
** Copyright (c) Siargo, Ltd. 2011
|
||||
** All Rights Reserved.
|
||||
**
|
||||
**-------------------------------------------------------------------------------------------------------
|
||||
********************************************************************************************************/
|
||||
#ifndef __UnitConverter_h__
|
||||
#define __UnitConverter_h__
|
||||
|
||||
//==============================================================================
|
||||
// Update V2006
|
||||
//******************************************************************************
|
||||
#if(FR_STD_UNIT==NCMH)
|
||||
//******************************************************************************
|
||||
// for acc
|
||||
#define ACC_STD_UINT NM3
|
||||
//mL
|
||||
#define ONE_STD_ACC_TO_ML 1000000.0
|
||||
#define ONE_ML_TO_STD_ACC (1/ONE_STD_ACC_TO_ML)
|
||||
//SL
|
||||
#define ONE_STD_ACC_TO_SL 1000.0
|
||||
#define ONE_SL_TO_STD_ACC (1/ONE_STD_ACC_TO_SL)
|
||||
//NM3
|
||||
#define ONE_STD_ACC_TO_NCM 1.0
|
||||
#define ONE_NCM_TO_STD_ACC 1.0
|
||||
//SCF
|
||||
#define ONE_STD_ACC_TO_SCF 35.314724827664
|
||||
#define ONE_SCF_TO_STD_ACC (1.0/ONE_STD_ACC_TO_SCF)
|
||||
|
||||
//KG
|
||||
#define ONE_STD_ACC_TO_KG 1.205
|
||||
#define ONE_KG_TO_STD_ACC (1.0/ONE_STD_ACC_TO_KG)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// flowRate
|
||||
// SCCM
|
||||
#define ONE_STD_FR_TO_SCCM (ONE_STD_ACC_TO_ML/60.0)
|
||||
#define ONE_SCCM_TO_STD_FR (1.0/ONE_STD_FR_TO_SCCM)
|
||||
// SLPM
|
||||
#define ONE_STD_FR_TO_SLPM (ONE_STD_ACC_TO_SL/60.0)
|
||||
#define ONE_SLPM_TO_STD_FR (1.0/ONE_STD_FR_TO_SLPM)
|
||||
// NCMH
|
||||
#define ONE_STD_FR_TO_NCMH 1.0
|
||||
#define ONE_NCMH_TO_STD_FR 1.0
|
||||
// SCFH
|
||||
#define ONE_STD_FR_TO_SCFH ONE_STD_ACC_TO_SCF
|
||||
#define ONE_SCFH_TO_STD_FR (1.0/ONE_STD_FR_TO_SCFH)
|
||||
// SCFM
|
||||
#define ONE_STD_FR_TO_SCFM (ONE_STD_FR_TO_SCFH/60.0) // 35.314724827664 /60 for(SCFM)
|
||||
#define ONE_SCFM_TO_STD_FR (1.0/ONE_STD_FR_TO_SCFM)
|
||||
|
||||
// KGH
|
||||
#define ONE_STD_FR_TO_KGH ONE_STD_ACC_TO_KG
|
||||
#define ONE_KGH_TO_STD_FR ONE_KG_TO_STD_ACC
|
||||
|
||||
//******************************************************************************
|
||||
#elif(FR_STD_UNIT==SLPM)
|
||||
//******************************************************************************
|
||||
// for acc
|
||||
#define ACC_STD_UINT NM3
|
||||
//mL
|
||||
#define ONE_STD_ACC_TO_ML 1000000.0
|
||||
#define ONE_ML_TO_STD_ACC (1.0/ONE_STD_ACC_TO_ML)
|
||||
//SL
|
||||
#define ONE_STD_ACC_TO_SL 1000.0
|
||||
#define ONE_SL_TO_STD_ACC (1.0/ONE_STD_ACC_TO_SL)
|
||||
//NM3
|
||||
#define ONE_STD_ACC_TO_NCM 1.0
|
||||
#define ONE_NCM_TO_STD_ACC 1.0
|
||||
//SCF
|
||||
#define ONE_STD_ACC_TO_SCF 35.314724827664
|
||||
#define ONE_SCF_TO_STD_ACC (1.0/ONE_STD_ACC_TO_SCF)
|
||||
|
||||
//KG
|
||||
#define ONE_STD_ACC_TO_KG 1.205
|
||||
#define ONE_KG_TO_STD_ACC (1/ONE_STD_ACC_TO_KG)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// flowRate
|
||||
// SCCM
|
||||
#define ONE_STD_FR_TO_SCCM (1000.0/60.0)
|
||||
#define ONE_SCCM_TO_STD_FR (1.0/ONE_STD_FR_TO_SCCM)
|
||||
// SLPM
|
||||
#define ONE_STD_FR_TO_SLPM 1.0
|
||||
#define ONE_SLPM_TO_STD_FR 1.0
|
||||
// NCMH
|
||||
#define ONE_STD_FR_TO_NCMH (0.001*60)
|
||||
#define ONE_NCMH_TO_STD_FR (1.0/ONE_STD_FR_TO_NCMH)
|
||||
// SCFH
|
||||
#define ONE_STD_FR_TO_SCFH (0.035314724827664*60)
|
||||
#define ONE_SCFH_TO_STD_FR (1/ONE_STD_FR_TO_SCFH)
|
||||
// SCFM
|
||||
#define ONE_STD_FR_TO_SCFM 0.035314724827664
|
||||
#define ONE_SCFM_TO_STD_FR (1.0/ONE_STD_FR_TO_SCFM)
|
||||
|
||||
// KGH
|
||||
#define ONE_STD_FR_TO_KGH (0.001205*60)
|
||||
#define ONE_KGH_TO_STD_FR (1.0/ONE_STD_FR_TO_KGH)
|
||||
|
||||
//******************************************************************************
|
||||
#elif(FR_STD_UNIT==SCCM)
|
||||
//******************************************************************************
|
||||
// for acc
|
||||
#define ACC_STD_UINT SL
|
||||
//mL
|
||||
#define ONE_STD_ACC_TO_ML 1000.0
|
||||
#define ONE_ML_TO_STD_ACC (1.0/ONE_STD_ACC_TO_ML)
|
||||
//SL
|
||||
#define ONE_STD_ACC_TO_SL 1.0
|
||||
#define ONE_SL_TO_STD_ACC 1.0
|
||||
//NM3
|
||||
#define ONE_STD_ACC_TO_NCM 0.001
|
||||
#define ONE_NCM_TO_STD_ACC 1000.0
|
||||
//SCF
|
||||
#define ONE_STD_ACC_TO_SCF 0.035314724827664
|
||||
#define ONE_SCF_TO_STD_ACC (1.0/ONE_STD_ACC_TO_SCF)
|
||||
|
||||
//KG
|
||||
#define ONE_STD_ACC_TO_KG 0.001205
|
||||
#define ONE_KG_TO_STD_ACC (1.0/ONE_STD_ACC_TO_KG)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// flowRate
|
||||
// SCCM
|
||||
#define ONE_STD_FR_TO_SCCM 1.0
|
||||
#define ONE_SCCM_TO_STD_FR 1.0
|
||||
// SLPM
|
||||
#define ONE_STD_FR_TO_SLPM 0.001
|
||||
#define ONE_SLPM_TO_STD_FR (1.0/ONE_STD_FR_TO_SLPM)
|
||||
// NCMH
|
||||
#define ONE_STD_FR_TO_NCMH (0.000001*60)
|
||||
#define ONE_NCMH_TO_STD_FR (1.0/ONE_STD_FR_TO_NCMH)
|
||||
// SCFH
|
||||
#define ONE_STD_FR_TO_SCFH (0.000035314724827664*60)
|
||||
#define ONE_SCFH_TO_STD_FR (1.0/ONE_STD_FR_TO_SCFH)
|
||||
// SCFM
|
||||
#define ONE_STD_FR_TO_SCFM 0.000035314724827664
|
||||
#define ONE_SCFM_TO_STD_FR (1.0/ONE_STD_FR_TO_SCFM)
|
||||
|
||||
// KGH
|
||||
#define ONE_STD_FR_TO_KGH (0.000001205*60)
|
||||
#define ONE_KGH_TO_STD_FR (1.0/ONE_STD_FR_TO_KGH)
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
#endif
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#define MIN_TIME_BASE 125 // 125ms
|
||||
//******************************************************************************
|
||||
extern u16 flowDisUnit, flowComUnit, AccDisUnit, AccComputeUnit, AccComUnit;
|
||||
//------------------------------------------------------------------------------
|
||||
void CombinedUnitByFlowRate(void);
|
||||
void CombinedUnitByACC(void);
|
||||
u16 JudgeflowUserUnit(u16 judgeUnit);
|
||||
u16 JudgeflowAccUnit(u16 judgeUnit);
|
||||
u16 JudgeflowUnit(u16 judgeUnit);
|
||||
u32 ConvertFlowrate(u32 flowRateBuf, u16 targetUnit, u16 originalUnit);
|
||||
void ConvertAllFlowRateAndSave(u16 NewFlowUnit);
|
||||
u16 ReturnStartUnitBit(u16 stdBit);
|
||||
u16 ConvertTimeBaseAndUnit(u16 unit, u16 timeBaseIndex);
|
||||
void UnitConverterInit(void);
|
||||
|
||||
//******************************************************************************
|
||||
#endif
|
||||
//******************************************************************************
|
||||
|
||||
|
||||
73
user/Compute/UnitConverterDefine.h
Executable file
73
user/Compute/UnitConverterDefine.h
Executable file
@@ -0,0 +1,73 @@
|
||||
/********************************************************************************************************
|
||||
** HY3106<30><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>
|
||||
**
|
||||
** Copyright (c) Siargo, Ltd. 2011
|
||||
** All Rights Reserved.
|
||||
**
|
||||
**-------------------------------------------------------------------------------------------------------
|
||||
********************************************************************************************************/
|
||||
#ifndef __UnitConverterDefine_h__
|
||||
#define __UnitConverterDefine_h__
|
||||
|
||||
/******************************************************************************
|
||||
<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>BIT0-BIT7<54><37>
|
||||
0--FR: sccm, Acc: SL
|
||||
1--FR: SLPM, Acc: NM3
|
||||
2--FR: NM3/h Acc: NM3
|
||||
3--FR: SCFH Acc: SCF
|
||||
4--NC
|
||||
5---
|
||||
6--FR: KG/h Acc: KG
|
||||
7--FR: SLPM Acc: SL
|
||||
8---
|
||||
9--FR: SCFM Acc: SCF
|
||||
|
||||
BIT8 <20>¶ȵ<C2B6>λ: 0-<2D>棬1-<2D>H
|
||||
BIT10 ʪ<>ȵ<EFBFBD>λ: 0-%RH
|
||||
BIT12-BIT13 ѹ<><D1B9><EFBFBD><EFBFBD>λ:
|
||||
00-kPa<50><61>
|
||||
01-PSI
|
||||
10-bar
|
||||
BIT14 Ũ<>ȵ<EFBFBD>λ: 0-%<25><>1-PPM
|
||||
*******************************************************************************/
|
||||
//******************************************************************************
|
||||
//<2F><>λת<CEBB><D7AA>
|
||||
//Unit conversion
|
||||
#define SCCM_SL 0
|
||||
#define SLPM_NM3 1
|
||||
#define NCMH_NM3 2
|
||||
#define SCFH_SCF 3
|
||||
#define PPM_PPM 4
|
||||
//#define CMH_M3 5
|
||||
#define KGH_KG 6
|
||||
#define SLPM_SL 7
|
||||
//#define SLPM_M3 8
|
||||
#define SCFM_SCF 9
|
||||
#define UNIT_MAX SCFM_SCF
|
||||
#define UNIT_MASK 0x00FF
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// for flowrate
|
||||
#define SCCM 0
|
||||
#define SLPM 1
|
||||
#define NCMH 2
|
||||
#define SCFM 3
|
||||
#define KGH 4
|
||||
#define SCFH 5
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// for acc
|
||||
#define ML 0
|
||||
#define SL 1
|
||||
#define NM3 2
|
||||
#define SCF 3
|
||||
#define KG 4
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// for PRESS
|
||||
#define KPA 0
|
||||
#define PSI BIT12
|
||||
#define BAR BIT13
|
||||
#define PRESS_UNIT_MASK (BIT12+BIT13)
|
||||
|
||||
#endif
|
||||
39
user/Compute/VHHCompute.c
Executable file
39
user/Compute/VHHCompute.c
Executable file
@@ -0,0 +1,39 @@
|
||||
#include "../main/SystemInclude.h"
|
||||
|
||||
// for compute buffer
|
||||
float RRExtGain;
|
||||
u16 RRExtGainRes;
|
||||
|
||||
/******************************************************************************/
|
||||
void RHCircuitParameterInit(void)
|
||||
{
|
||||
// A type external gain res
|
||||
RRExtGainRes = (u16)ReadParameterFromEEPROM(RR_GAINRES, RR_GAINRES_WIDTH, RR_GAINRES_DEFAULT);
|
||||
RRExtGain = (float)RR_OPGAIN_RES;
|
||||
RRExtGain /= (float)RRExtGainRes;
|
||||
RRExtGain += 1.0;
|
||||
RRExtGain = 1.0/RRExtGain;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
void ComputeRRParameter(void)
|
||||
{
|
||||
float tmpRR;
|
||||
|
||||
//===========================================================================
|
||||
// compute VRR ADC INPUT
|
||||
tmpSLA = (u32)voltageDetected[RRIDX];
|
||||
tmpSLA -= (u32)32768;
|
||||
tmpRR = (float)VRR_VREF;
|
||||
tmpRR *= (float)tmpSLA;
|
||||
tmpRR += (float)VRR_VDC;
|
||||
voltageDetected[NVRR] = (u16)tmpRR;
|
||||
|
||||
//===========================================================================
|
||||
// compute RR
|
||||
tmpRR *= (float)RRExtGain;
|
||||
tmpRR = (VRR_RREF*tmpRR)/(VREF-tmpRR);
|
||||
|
||||
voltageDetected[NRR] = (u16)tmpRR;
|
||||
voltageDetected[NRR] = MovingAverage(voltageDetected[NRR], 30, NRR);
|
||||
}
|
||||
20
user/Compute/VHHCompute.h
Executable file
20
user/Compute/VHHCompute.h
Executable file
@@ -0,0 +1,20 @@
|
||||
/********************************************************************************************************
|
||||
** HY3106<30><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>
|
||||
**
|
||||
** Copyright (c) Siargo, Ltd. 2011
|
||||
** All Rights Reserved.
|
||||
**
|
||||
********************************************************************************************************/
|
||||
#ifndef __VHHCompute_h__
|
||||
#define __VHHCompute_h__
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
extern u16 RRExtGainRes;
|
||||
extern float RRExtGain;
|
||||
/******************************************************************************/
|
||||
|
||||
void RHCircuitParameterInit(void);
|
||||
void ComputeRRParameter(void);
|
||||
void SaveVHHAndNRHInTempretureMode(void);
|
||||
#endif
|
||||
Reference in New Issue
Block a user