update calibration data
This commit is contained in:
+67
-64
@@ -5,6 +5,11 @@
|
||||
#include "EliteDAC.h"
|
||||
#include "EliteADC.h"
|
||||
|
||||
/* DAC reset parameter */
|
||||
#define DACzero 0x85A2
|
||||
#define DACposMax 0x0000
|
||||
#define DACnegMax 0xFFFF
|
||||
|
||||
// this function turn ADC measure value (0xXXXX) into real voltage
|
||||
// unit should be mV
|
||||
static int32_t DecodeADCVolt(uint16_t ADC_measure){
|
||||
@@ -19,45 +24,62 @@ static int32_t DecodeADCVolt(uint16_t ADC_measure){
|
||||
// this function turn ADC measure value (0xXXXX) into real current
|
||||
// unit should be pA
|
||||
|
||||
// Decode ADC current for class leader
|
||||
/* 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};
|
||||
|
||||
coeff[0] = 3056; // 200k resister, I < 100nA
|
||||
coeff[1] = 65461; // 10k resister, 100nA < I < 100uA
|
||||
coeff[2] = 3369; // 200R resister, I > 100uA
|
||||
coeff[0] = 3002; // 200k resister, I < 100nA
|
||||
coeff[1] = 65840; // 10k resister, 100nA < I < 100uA
|
||||
coeff[2] = 3090; // 200R resister, I > 100uA
|
||||
|
||||
offset[0] = -74771591;
|
||||
offset[1] = -1601786957;
|
||||
offset[2] = -82598293;
|
||||
offset[0] = -72955265;
|
||||
offset[1] = -1600149874;
|
||||
offset[2] = -75102578;
|
||||
|
||||
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] = 2929; // 200k resister, I < 100nA
|
||||
// coeff[1] = 66009; // 10k resister, 100nA < I < 100uA
|
||||
// coeff[2] = 3120; // 200R resister, I > 100uA
|
||||
//
|
||||
// offset[0] = -70261951;
|
||||
// offset[1] = -1583533494;
|
||||
// offset[2] = -74847651;
|
||||
//
|
||||
// ADCRealCurrent = (coeff[ADCGain] * ADC_measure + offset[ADCGain]);
|
||||
// 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){
|
||||
|
||||
uint16_t ADC_measure = (uint16_t) (ADC_raw[0] << 8) | (uint16_t) (ADC_raw[1]);
|
||||
int32_t ADCRealVolt = 0, ret = 0;
|
||||
int32_t ret = 0, ADCRealCurrent = 0, ADCRealVolt = 0;
|
||||
|
||||
// return real volt to controller
|
||||
if(ADCChannel == ADC_CH_VOLT){
|
||||
@@ -71,34 +93,12 @@ static int32_t DecodeADCValue(uint8_t ADCGain, uint8_t ADCChannel, uint8_t *ADC_
|
||||
|
||||
// return real current to controller
|
||||
else if(ADCChannel == ADC_CH_CURRENT){
|
||||
|
||||
if (INSTRUCTION.eliteFxn == IVCurve) {
|
||||
ADCRealCurrent += DecodeADCCurrent(ADCGain, ADC_measure);
|
||||
|
||||
if ((SampleRate_counter % 10) == 0) {
|
||||
ADCRealCurrent = ADCRealCurrent / 10;
|
||||
ADCRealCurrent_avg = (ADCRealCurrent + ADCRealCurrent_avg*(avg_number - 1)) / avg_number;
|
||||
avg_number ++;
|
||||
ADCRealCurrent = 0;
|
||||
}
|
||||
if (StepTimeCounter == StepTime - 1) {
|
||||
NotifyCurrent[0] = (uint8_t) (ADCRealCurrent_avg >> 24);
|
||||
NotifyCurrent[1] = (uint8_t) ((ADCRealCurrent_avg & 0x00FF0000) >> 16);
|
||||
NotifyCurrent[2] = (uint8_t) ((ADCRealCurrent_avg & 0x0000FF00) >> 8);
|
||||
NotifyCurrent[3] = (uint8_t) (ADCRealCurrent_avg & 0x000000FF);
|
||||
avg_number = 1;
|
||||
ADCRealCurrent_avg = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ADCRealCurrent = DecodeADCCurrent(ADCGain, ADC_measure);
|
||||
NotifyCurrent[0] = (uint8_t) (ADCRealCurrent >> 24);
|
||||
NotifyCurrent[1] = (uint8_t) ((ADCRealCurrent & 0x00FF0000) >> 16);
|
||||
NotifyCurrent[2] = (uint8_t) ((ADCRealCurrent & 0x0000FF00) >> 8);
|
||||
NotifyCurrent[3] = (uint8_t) (ADCRealCurrent & 0x000000FF);
|
||||
ret = ADCRealCurrent;
|
||||
}
|
||||
|
||||
ADCRealCurrent = DecodeADCCurrent(ADCGain, ADC_measure);
|
||||
NotifyCurrent[0] = (uint8_t) (ADCRealCurrent >> 24);
|
||||
NotifyCurrent[1] = (uint8_t) ((ADCRealCurrent & 0x00FF0000) >> 16);
|
||||
NotifyCurrent[2] = (uint8_t) ((ADCRealCurrent & 0x0000FF00) >> 8);
|
||||
NotifyCurrent[3] = (uint8_t) (ADCRealCurrent & 0x000000FF);
|
||||
ret = ADCRealCurrent;
|
||||
}
|
||||
|
||||
else{
|
||||
@@ -114,19 +114,24 @@ 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 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]));
|
||||
|
||||
// // Boundary for CHAO-I
|
||||
// uint16_t Gain0Boundary[2] = {0x5D98, 0x5DD6};
|
||||
// uint16_t Gain1Boundary[2] = {0x57CB, 0x639F};
|
||||
|
||||
// gain = 0 => using 200K resister
|
||||
if(gain == 0){
|
||||
if(gain == Gain200K){
|
||||
if( U16Rawdata <= Gain0Boundary[0]){
|
||||
rawdata[0] = Gain0Boundary[0] >> 4;
|
||||
rawdata[1] = (uint8_t) (Gain0Boundary[0] & 0x00FF);
|
||||
@@ -136,9 +141,7 @@ static void ADC_overflow(uint8_t gain, uint8_t *rawdata){
|
||||
rawdata[1] = (uint8_t) (Gain0Boundary[1] & 0x00FF);
|
||||
}
|
||||
}
|
||||
|
||||
// gain = 1 => using 10K resister
|
||||
else if(gain == 1){
|
||||
else if(gain == Gain10K){
|
||||
if( U16Rawdata <= Gain1Boundary[0]){
|
||||
rawdata[0] = Gain1Boundary[0] >> 4;
|
||||
rawdata[1] = (uint8_t) (Gain1Boundary[0] & 0x00FF);
|
||||
|
||||
Reference in New Issue
Block a user