NULL
This commit is contained in:
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
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user