Merge remote-tracking branch 'origin/Elite_IVtest' into Elite_IVtest
This commit is contained in:
+115
-83
@@ -10,6 +10,22 @@
|
||||
#define DACposMax 0x0000
|
||||
#define DACnegMax 0xFFFF
|
||||
|
||||
typedef struct _formula{
|
||||
|
||||
int32_t coeff = 0;
|
||||
int32_t offset = 0;
|
||||
|
||||
}Formula;
|
||||
|
||||
typedef struct _correction{
|
||||
|
||||
Formula ADC_volt = 0;
|
||||
Formula ADC_current[3] = 0;
|
||||
uint32_t Gain0Boundary[2] = {0, 0};
|
||||
uint32_t Gain1BoundARY[2] = {0, 0};
|
||||
|
||||
}Correction_data;
|
||||
|
||||
/*
|
||||
* Correction Array include all the correction coeff and offset
|
||||
*
|
||||
@@ -37,15 +53,92 @@
|
||||
#define BORAD_Chao_I
|
||||
|
||||
#ifdef BORAD_CLASS_LEADER
|
||||
static int32_t Correction[10] = {-629, 15221058, 3056, -74771591, };
|
||||
static Correction_data Correction;
|
||||
|
||||
Correction.ADC_volt.coeff = (-629);
|
||||
Correction.ADC_volt.offset = 15447740;
|
||||
|
||||
Correction.ADC_current_200k.coeff = 3056;
|
||||
Correction.ADC_current_200k.offset = -74771591;
|
||||
|
||||
Correction.ADC_current_10K.coeff = 65461;
|
||||
Correction.ADC_current_10K.offset = -1601786957;
|
||||
|
||||
Correction.ADC_current_200R.coeff = 3369;
|
||||
Correction.ADC_current_200R.offset = -82598293;
|
||||
|
||||
Correction.Gain0Boundary[0] = 0x5F75;
|
||||
Correction.Gain0Boundary[1] = 0x5FB2;
|
||||
|
||||
Correction.Gain1Boundary[0] = 0x5999;
|
||||
Correction.Gain1Boundary[1] = 0x6589;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef BORAD_TRICERATOPS
|
||||
static int32_t Correction[10] = {0};
|
||||
static Correction_data Correction;
|
||||
|
||||
Correction.ADC_volt.coeff = (-626);
|
||||
Correction.ADC_volt.offset = 15065046;
|
||||
|
||||
Correction.ADC_current_200k.coeff = 0;
|
||||
Correction.ADC_current_200k.offset = 0;
|
||||
|
||||
Correction.ADC_current_10K.coeff = 0;
|
||||
Correction.ADC_current_10K.offset = 0;
|
||||
|
||||
Correction.ADC_current_200R.coeff = 0;
|
||||
Correction.ADC_current_200R.offset = 0;
|
||||
|
||||
Correction.Gain0Boundary[0] = 0;
|
||||
Correction.Gain0Boundary[1] = 0;
|
||||
|
||||
Correction.Gain1Boundary[0] = 0;
|
||||
Correction.Gain1Boundary[1] = 0;
|
||||
#endif
|
||||
|
||||
#ifdef BORAD_Chao_I
|
||||
static int32_t Correction[10] = {0};
|
||||
static Correction_data Correction;
|
||||
|
||||
Correction.ADC_volt.coeff = (-627);
|
||||
Correction.ADC_volt.offset = 15122868;
|
||||
|
||||
Correction.ADC_current_200k.coeff = 3091;
|
||||
Correction.ADC_current_200k.offset = (-74147760);
|
||||
|
||||
Correction.ADC_current_10K.coeff = 66127;
|
||||
Correction.ADC_current_10K.offset = (-1586449560);
|
||||
|
||||
Correction.ADC_current_200R.coeff = 3118;
|
||||
Correction.ADC_current_200R.offset = (74817847);
|
||||
|
||||
Correction.Gain0Boundary[0] = 0x5D96;
|
||||
Correction.Gain0Boundary[1] = 0x5DD9;
|
||||
|
||||
Correction.Gain1Boundary[0] = 0x57CD;
|
||||
Correction.Gain1Boundary[1] = 0x639F;
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_TWENTY_ONE
|
||||
static Correction_data Correction;
|
||||
|
||||
Correction.ADC_volt.coeff = (-625);
|
||||
Correction.ADC_volt.offset = 15221058;
|
||||
|
||||
Correction.ADC_current[0].coeff = 3002;
|
||||
Correction.ADC_current[0].offset = -72955265;
|
||||
|
||||
Correction.ADC_current[1].coeff = 65840;
|
||||
Correction.ADC_current[1].offset = -1600149874;
|
||||
|
||||
Correction.ADC_current[2].coeff = 3090;
|
||||
Correction.ADC_current[2].offset = -75102578;
|
||||
|
||||
Correction.Gain0Boundary[0] = 0x5ECD;
|
||||
Correction.Gain0Boundary[1] = 0x5F0D;
|
||||
|
||||
Correction.Gain1Boundary[0] = 0x5900;
|
||||
Correction.Gain1Boundary[1] = 0x64DD;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -53,70 +146,22 @@ static int32_t Correction[10] = {0};
|
||||
// unit should be mV
|
||||
static int32_t DecodeADCVolt(uint16_t ADC_measure){
|
||||
int32_t ADCRealVolt = 0;
|
||||
|
||||
//int32_t coeff = (-626), offset = 15065046; //Triceratop
|
||||
//int32_t coeff = (-625), offset = 15221058; //Twenty One
|
||||
//int32_t coeff = (-629), offset = 15447740; //Class Leader
|
||||
int32_t coeff = (-627), offset = 15122868; //Chao I
|
||||
|
||||
ADCRealVolt = (coeff * ADC_measure + offset);
|
||||
ADCRealVolt = (Correction.ADC_volt.coeff * ADC_measure + Correction.ADC_volt.offset);
|
||||
ADCRealVolt = ADCRealVolt / 1000;
|
||||
return ADCRealVolt;
|
||||
}
|
||||
|
||||
// this function turn ADC measure value (0xXXXX) into real current
|
||||
// unit should be pA
|
||||
|
||||
/* Decode ADC current for class leader */
|
||||
//static int32_t DecodeADCCurrent(uint8_t ADCGain, uint16_t ADC_measure){
|
||||
// int32_t ADCRealCurrent = 0;
|
||||
// int32_t coeff[3] = {0}, offset[3] = {0};
|
||||
//
|
||||
// coeff[0] = 3056; // 200k resister, I < 100nA
|
||||
// coeff[1] = 65461; // 10k resister, 100nA < I < 100uA
|
||||
// coeff[2] = 3369; // 200R resister, I > 100uA
|
||||
//
|
||||
// offset[0] = -74771591;
|
||||
// offset[1] = -1601786957;
|
||||
// offset[2] = -82598293;
|
||||
//
|
||||
// ADCRealCurrent = (coeff[ADCGain] * ADC_measure + offset[ADCGain])/1000;
|
||||
// return ADCRealCurrent;
|
||||
//}
|
||||
|
||||
/* Decode ADC current for CHAO-I */
|
||||
static int32_t DecodeADCCurrent(uint8_t ADCGain, uint16_t ADC_measure){
|
||||
int32_t ADCRealCurrent = 0;
|
||||
int32_t coeff[3] = {0}, offset[3] = {0};
|
||||
|
||||
coeff[0] = 3091; // 200k resister, I < 100nA
|
||||
coeff[1] = 66127; // 10k resister, 100nA < I < 100uA
|
||||
coeff[2] = 3118; // 200R resister, I > 100uA
|
||||
|
||||
offset[0] = -74147760;
|
||||
offset[1] = -1586449560;
|
||||
offset[2] = -74817847;
|
||||
|
||||
ADCRealCurrent = (coeff[ADCGain] * ADC_measure + offset[ADCGain])/1000;
|
||||
return ADCRealCurrent;
|
||||
}
|
||||
|
||||
/* Decode ADC current for twenty-one */
|
||||
// static int32_t DecodeADCCurrent(uint8_t ADCGain, uint16_t ADC_measure){
|
||||
// int32_t ADCRealCurrent = 0;
|
||||
// int32_t coeff[3] = {0}, offset[3] = {0};
|
||||
static int32_t DecodeADCCurrent(uint8_t ADCGain, uint16_t ADC_measure){
|
||||
int32_t ADCRealCurrent = 0;
|
||||
int32_t coeff[3] = {0}, offset[3] = {0};
|
||||
|
||||
// coeff[0] = 3002; // 200k resister, I < 100nA
|
||||
// coeff[1] = 65840; // 10k resister, 100nA < I < 100uA
|
||||
// coeff[2] = 3090; // 200R resister, I > 100uA
|
||||
|
||||
// offset[0] = -72955265;
|
||||
// offset[1] = -1600149874;
|
||||
// offset[2] = -75102578;
|
||||
|
||||
// ADCRealCurrent = (coeff[ADCGain] * ADC_measure + offset[ADCGain])/1000;
|
||||
// return ADCRealCurrent;
|
||||
// }
|
||||
ADCRealCurrent = (Correction.ADC_current[ADCGain].coeff * ADC_measure + Correction.ADC_current[ADCGain].offset)/1000;
|
||||
return ADCRealCurrent;
|
||||
}
|
||||
|
||||
// Decode ADC measure value (could be a volt or current) and put it into notify buffer
|
||||
static int32_t DecodeADCValue(uint8_t ADCGain, uint8_t ADCChannel, uint8_t *ADC_raw){
|
||||
@@ -183,40 +228,27 @@ static void ADC_overflow(uint8_t gain, uint8_t *rawdata){
|
||||
// Gain boundary defines different ADC gain level working area
|
||||
// Gain0Boundary = {lowerbound, upperbound}, is the lower and upper bound of gain level 0 working area.
|
||||
|
||||
// // Boundary for class leader
|
||||
// uint16_t Gain0Boundary[2] = {0x5F75, 0x5FB2};
|
||||
// uint16_t Gain1Boundary[2] = {0x5999, 0x6589};
|
||||
|
||||
// // Boundary for CHAO-I
|
||||
uint16_t Gain0Boundary[2] = {0x5D96, 0x5DD9};
|
||||
uint16_t Gain1Boundary[2] = {0x57CD, 0x639F};
|
||||
|
||||
// Boundary for twenty-one
|
||||
// uint16_t Gain0Boundary[2] = {0x5ECD, 0x5F0D};
|
||||
// uint16_t Gain1Boundary[2] = {0x5900, 0x64DD};
|
||||
|
||||
uint16_t U16Rawdata = 0;
|
||||
U16Rawdata = (((uint16_t) (rawdata[0]))<<8) | ((uint16_t) (rawdata[1]));
|
||||
|
||||
|
||||
if(gain == GAIN_200K){
|
||||
if( U16Rawdata <= Gain0Boundary[0]){
|
||||
rawdata[0] = Gain0Boundary[0] >> 4;
|
||||
rawdata[1] = (uint8_t) (Gain0Boundary[0] & 0x00FF);
|
||||
if( U16Rawdata <= Correction.Gain0Boundary[0]){
|
||||
rawdata[0] = Correction.Gain0Boundary[0] >> 4;
|
||||
rawdata[1] = (uint8_t) (Correction.Gain0Boundary[0] & 0x00FF);
|
||||
}
|
||||
else if(U16Rawdata >= Gain0Boundary[1]){
|
||||
rawdata[0] = (uint8_t) (Gain0Boundary[1] >> 4);
|
||||
rawdata[1] = (uint8_t) (Gain0Boundary[1] & 0x00FF);
|
||||
else if(U16Rawdata >= Correction.Gain0Boundary[1]){
|
||||
rawdata[0] = (uint8_t) (Correction.Gain0Boundary[1] >> 4);
|
||||
rawdata[1] = (uint8_t) (Correction.Gain0Boundary[1] & 0x00FF);
|
||||
}
|
||||
}
|
||||
else if(gain == GAIN_10K){
|
||||
if( U16Rawdata <= Gain1Boundary[0]){
|
||||
rawdata[0] = Gain1Boundary[0] >> 4;
|
||||
rawdata[1] = (uint8_t) (Gain1Boundary[0] & 0x00FF);
|
||||
if( U16Rawdata <= Correction.Gain1Boundary[0]){
|
||||
rawdata[0] = Correction.Gain1Boundary[0] >> 4;
|
||||
rawdata[1] = (uint8_t) (Correction.Gain1Boundary[0] & 0x00FF);
|
||||
}
|
||||
else if(U16Rawdata >= Gain1Boundary[1]){
|
||||
rawdata[0] = (uint8_t) (Gain1Boundary[1] >> 4);
|
||||
rawdata[1] = (uint8_t) (Gain1Boundary[1] & 0x00FF);
|
||||
else if(U16Rawdata >= Correction.Gain1Boundary[1]){
|
||||
rawdata[0] = (uint8_t) (Correction.Gain1Boundary[1] >> 4);
|
||||
rawdata[1] = (uint8_t) (Correction.Gain1Boundary[1] & 0x00FF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user