re-calibrate gain level 3 (a*exp(bx) + c*exp(dx))

This commit is contained in:
Taylor
2021-09-17 16:56:37 +08:00
parent 0a8c570027
commit 427a1f8ee8
4 changed files with 39 additions and 28 deletions
@@ -415,10 +415,10 @@ static int32_t ADCCode2Volt(uint32_t code) {
// Current Squared
#define HSTIA_GAIN_SMALL_BOUNDARY 4500 //2025 //(45 * 45) // 4.5 uA = 4,500,000 pA
#define HSTIA_GAIN_MID1_BOUNDARY1 3600 //900 //(30 * 30) // 3 uA = 3,000,000 pA
#define HSTIA_GAIN_MID1_BOUNDARY2 36000 //129600 //(360 * 360) // 36 uA = 36,000,000 pA
#define HSTIA_GAIN_MID2_BOUNDARY1 28000 //62500 //(250 * 250) // 25 uA = 25,000,000 pA
#define HSTIA_GAIN_MID2_BOUNDARY2 145000 //2102500 //(1450 * 1450) // 145 uA = 140,000 nA
#define HSTIA_GAIN_LARGE_BOUNDARY 115000 //1000000 //(1000 * 1000) // 100 uA = 100,000 nA
#define HSTIA_GAIN_MID1_BOUNDARY2 40000 //129600 //(360 * 360) // 36 uA = 36,000,000 pA
#define HSTIA_GAIN_MID2_BOUNDARY1 30000 //62500 //(250 * 250) // 25 uA = 25,000,000 pA
#define HSTIA_GAIN_MID2_BOUNDARY2 166000 //2102500 //(1450 * 1450) // 166 uA = 166,000 nA
#define HSTIA_GAIN_LARGE_BOUNDARY 133000 //1000000 //(1000 * 1000) // 133 uA = 133,000 nA
static int32_t read_cali_Iin(uint8_t *buf){
int32_t RealCurrent = 0;
@@ -746,15 +746,18 @@ static uint64_t read_HSTIA_Iin(){
originalDFT = sqrt(instru.imag * instru.imag + instru.real * instru.real);
correctedDFT = (uint64_t)originalDFT * (10000 + ((uint64_t)User2Freq(instru.fset) * (uint64_t)User2Freq(instru.fset)) / ((uint64_t)CaliTable.CutoffFreq * (uint64_t)CaliTable.CutoffFreq)) / 10000;
if (first_freq < 2) {
RealCurrent = correctedDFT * 1000 / HSRTIATable[instru.ADCGainLv] * 13;
first_freq ++;
// if (instru.ADCGainLv == 3 && correctedDFT < CaliTable.Lv[instru.ADCGainLv].HSRTIA_root){
// instru.ADCGainLv = 2;
// Elite_led_color(COLOR_ORANGE);
// }
// if (instru.ADCGainLv == 2 && correctedDFT < CaliTable.Lv[instru.ADCGainLv].HSRTIA_root){
// instru.ADCGainLv = 1;
// }
if (instru.ADCGainLv == 3) {
RealCurrent = (uint64_t)CaliTable.Lv[instru.ADCGainLv].HSRTIA_a * exp((uint64_t)CaliTable.Lv[instru.ADCGainLv].HSRTIA_b * correctedDFT / 1e6) + (uint64_t)CaliTable.Lv[instru.ADCGainLv].HSRTIA_c * exp((uint64_t)CaliTable.Lv[instru.ADCGainLv].HSRTIA_d * correctedDFT / 1e6) / 1e5;
} else {
if (instru.ADCGainLv == 3) {
RealCurrent = ((int64_t)correctedDFT * (int64_t)correctedDFT * CaliTable.Lv[instru.ADCGainLv].HSRTIA_a + (int64_t)correctedDFT * CaliTable.Lv[instru.ADCGainLv].HSRTIA_b * 1e4 + (int64_t)CaliTable.Lv[instru.ADCGainLv].HSRTIA_c * 1e8) / 1e8;
} else {
RealCurrent = ((int64_t)correctedDFT * (int64_t)correctedDFT * CaliTable.Lv[instru.ADCGainLv].HSRTIA_a + (int64_t)correctedDFT * CaliTable.Lv[instru.ADCGainLv].HSRTIA_b + (int64_t)CaliTable.Lv[instru.ADCGainLv].HSRTIA_c * 1e4) / 1e8;
}
RealCurrent = ((int64_t)correctedDFT * (int64_t)correctedDFT * CaliTable.Lv[instru.ADCGainLv].HSRTIA_a + (int64_t)correctedDFT * CaliTable.Lv[instru.ADCGainLv].HSRTIA_b + (int64_t)CaliTable.Lv[instru.ADCGainLv].HSRTIA_c * 1e4) / 1e8;
}
return RealCurrent;
@@ -414,7 +414,7 @@ static void EIS_Plot(void) //real and imag impedance plot
EnDFTnADC(0);
if(gainChange_flag) {
gainChange_flag = false;
} else if (instru.fset >= 10000000 && high_freq_cnt < 3) {
} else if (instru.fset == instru.f1 && high_freq_cnt < 3) {
high_freq_cnt ++ ;
} else {
if(eis->_direction_up){
@@ -108,6 +108,7 @@ static void SendCaliValue3(void) {
cali_buf[index++] = (uint8_t) (CaliTable.Lv[0].HSRTIA_c >> 16) & 0xFF;
cali_buf[index++] = (uint8_t) (CaliTable.Lv[0].HSRTIA_c >> 8) & 0xFF;
cali_buf[index++] = (uint8_t) CaliTable.Lv[0].HSRTIA_c & 0xFF;
cali_buf[index++] = (uint8_t) CaliTable.Lv[0].HSRTIA_d & 0xFF;
cali_buf[0] = index - 1;
@@ -133,6 +134,7 @@ static void SendCaliValue4(void) {
cali_buf[index++] = (uint8_t) (CaliTable.Lv[1].HSRTIA_c >> 16) & 0xFF;
cali_buf[index++] = (uint8_t) (CaliTable.Lv[1].HSRTIA_c >> 8) & 0xFF;
cali_buf[index++] = (uint8_t) CaliTable.Lv[1].HSRTIA_c & 0xFF;
cali_buf[index++] = (uint8_t) CaliTable.Lv[1].HSRTIA_d & 0xFF;
cali_buf[0] = index - 1;
@@ -158,6 +160,7 @@ static void SendCaliValue5(void) {
cali_buf[index++] = (uint8_t) (CaliTable.Lv[2].HSRTIA_c >> 16) & 0xFF;
cali_buf[index++] = (uint8_t) (CaliTable.Lv[2].HSRTIA_c >> 8) & 0xFF;
cali_buf[index++] = (uint8_t) CaliTable.Lv[2].HSRTIA_c & 0xFF;
cali_buf[index++] = (uint8_t) CaliTable.Lv[2].HSRTIA_d & 0xFF;
cali_buf[0] = index - 1;
@@ -183,6 +186,10 @@ static void SendCaliValue6(void) {
cali_buf[index++] = (uint8_t) (CaliTable.Lv[3].HSRTIA_c >> 16) & 0xFF;
cali_buf[index++] = (uint8_t) (CaliTable.Lv[3].HSRTIA_c >> 8) & 0xFF;
cali_buf[index++] = (uint8_t) CaliTable.Lv[3].HSRTIA_c & 0xFF;
cali_buf[index++] = (uint8_t) (CaliTable.Lv[3].HSRTIA_d >> 24)& 0xFF;
cali_buf[index++] = (uint8_t) (CaliTable.Lv[3].HSRTIA_d >> 16) & 0xFF;
cali_buf[index++] = (uint8_t) (CaliTable.Lv[3].HSRTIA_d >> 8) & 0xFF;
cali_buf[index++] = (uint8_t) CaliTable.Lv[3].HSRTIA_d & 0xFF;
cali_buf[0] = index - 1;
@@ -16,6 +16,8 @@ typedef struct _SingleGainLvCali{
uint32_t HSRTIA_a;
int32_t HSRTIA_b;
int32_t HSRTIA_c;
uint32_t HSRTIA_d;
uint16_t HSRTIA_root;
}SingleGainLvCali;
struct _CaliTable{
@@ -95,35 +97,34 @@ struct _CaliTable{
#elif defined(BOARD_A4_DA_32_D4_EF_CF)
{
.DeviceName = "BOARD_A4_DA_32_D4_EF_CF",
.CutoffFreq = 271000,
// .Temp = 13,
// .HSRTIA200R = 200,
// .HSRTIA5K = 5000,
// .HSRTIA20K = 20000,
// .HSRTIA160K = 160000,
.CutoffFreq = 269500,
// hsrtia160k
.Lv[0].HSRTIA_a = 0, // 1e8
.Lv[0].HSRTIA_b = 8005810, // 1e8
.Lv[0].HSRTIA_c = -171109, // 1e4
.Lv[0].HSRTIA_d = 0,
// hsrtia20k
.Lv[1].HSRTIA_a = 364, // 1e8
.Lv[1].HSRTIA_b = 57301105, // 1e8
.Lv[1].HSRTIA_c = 2467753, // 1e4
.Lv[1].HSRTIA_a = 357, // 1e8
.Lv[1].HSRTIA_b = 57813915, // 1e8
.Lv[1].HSRTIA_c = 1543941, // 1e4
.Lv[1].HSRTIA_d = 0,
// hsrtia5k
.Lv[2].HSRTIA_a = 15417, //1e8
.Lv[2].HSRTIA_b = -62720427, // 1e8
.Lv[2].HSRTIA_c = 225612029, // 1e4
.Lv[2].HSRTIA_d = 0,
// hsrtia200r
.Lv[3].HSRTIA_a = 689559417, // 1e8
.Lv[3].HSRTIA_b = -25285161, // 1e3
.Lv[3].HSRTIA_c = 23605298,
// hsrtia200r a*exp(bx) + c*exp(dx)
.Lv[3].HSRTIA_a = 20450,
.Lv[3].HSRTIA_b = 1611, // 1e6
.Lv[3].HSRTIA_c = 4069, // 1e5
.Lv[3].HSRTIA_d = 7499, // 1e6
.Ft[0].PhaseParaA = 14585, //1e9
.Ft[0].PhaseParaB = -8859144, // 10000 Hz //1e5
.Ft[0].PhaseParaA = 14181, //1e9
.Ft[0].PhaseParaB = -8830490, // 10000 Hz //1e5
.Ft[1].PhaseParaA = 34178,
.Ft[1].PhaseParaB = -8989836, // 100 Hz
.Ft[2].PhaseParaA = 2054879,