Elite 1.4-re ADC volt correction

This commit is contained in:
alan
2019-08-16 10:16:13 +08:00
parent 64d32a6386
commit fbcb1f8ddd
2 changed files with 21 additions and 23 deletions
@@ -125,19 +125,20 @@ static void ADCChannelSelect(uint8_t ADCChannel){
// this function turn ADC measure value (0xXXXX) into real voltage
// unit should be mV
static float DecodeADCVolt(uint16_t ADC_measure){
float ADCRealVolt = 0;
float coeff = -0.629056, offset = 15447.740744;
static int32_t DecodeADCVolt(uint16_t ADC_measure){
int32_t ADCRealVolt = 0;
int32_t coeff = -62905, offset = 1544774074;
ADCRealVolt = (coeff * ADC_measure + offset);
ADCRealVolt = ADCRealVolt / 100000;
return ADCRealVolt;
}
// this function turn ADC measure value (0xXXXX) into real current
// unit should be pA
static float DecodeADCCurrent(uint8_t ADCGain, uint16_t ADC_measure){
float ADCRealCurrent = 0;
float 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] = 1;
coeff[1] = 2;
@@ -152,30 +153,27 @@ static float DecodeADCCurrent(uint8_t ADCGain, uint16_t ADC_measure){
}
// Decode ADC measure value (could be a volt or current) and put it into notify buffer
static float DecodeADCValue(uint8_t ADCGain, uint8_t ADCChannel, uint8_t *ADC_raw){
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]);
uint32_t ret = 0, ADCRealVolt = 0, ADCRealCurrent = 0;
int32_t Vout;
int32_t ret = 0, ADCRealCurrent = 0, ADCRealVolt = 0;
// return real volt to controller
if(ADCChannel == ADC_CH_VOLT){
ADCRealVolt = DecodeADCVolt(ADC_measure);
Vout = (int32_t) (ADCRealVolt / 1);
NotifyVolt[0] = (uint8_t) (Vout >> 24);
NotifyVolt[1] = (uint8_t) ((Vout & 0x00110000) >> 16);
NotifyVolt[2] = (uint8_t) ((Vout & 0x00001100) >> 8);
NotifyVolt[3] = (uint8_t) (Vout & 0x00000011);
NotifyVolt[0] = (uint8_t) (ADCRealVolt >> 24);
NotifyVolt[1] = (uint8_t) ((ADCRealVolt & 0x00110000) >> 16);
NotifyVolt[2] = (uint8_t) ((ADCRealVolt & 0x00001100) >> 8);
NotifyVolt[3] = (uint8_t) (ADCRealVolt & 0x00000011);
ret = ADCRealVolt;
}
// return real current to controller
else if(ADCChannel == ADC_CH_CURRENT){
ADCRealCurrent = DecodeADCCurrent(ADCGain, ADC_measure);
Vout = (int32_t) (ADCRealCurrent / 1);
NotifyCurrent[0] = (uint8_t) (Vout >> 24);
NotifyCurrent[1] = (uint8_t) ((Vout & 0x00110000) >> 16);
NotifyCurrent[2] = (uint8_t) ((Vout & 0x00001100) >> 8);
NotifyCurrent[3] = (uint8_t) (Vout & 0x00000011);
NotifyCurrent[0] = (uint8_t) (ADCRealCurrent >> 24);
NotifyCurrent[1] = (uint8_t) ((ADCRealCurrent & 0x00110000) >> 16);
NotifyCurrent[2] = (uint8_t) ((ADCRealCurrent & 0x00001100) >> 8);
NotifyCurrent[3] = (uint8_t) (ADCRealCurrent & 0x00000011);
ret = ADCRealCurrent;
}
@@ -593,9 +593,9 @@ static void ADC_read(uint8_t *ADCdata);
static void ADCGainControl(uint8_t ADCLevel);
static void ADCChannelSelect(uint8_t ADCChannel);
static float DecodeADCVolt(uint16_t ADC_measure);
static float DecodeADCCurrent(uint8_t ADCGain, uint16_t ADC_measure);
static float DecodeADCValue(uint8_t ADCGain, uint8_t ADCChannel, uint8_t *ADC_raw);
static int32_t DecodeADCVolt(uint16_t ADC_measure);
static int32_t DecodeADCCurrent(uint8_t ADCGain, uint16_t ADC_measure);
static int32_t DecodeADCValue(uint8_t ADCGain, uint8_t ADCChannel, uint8_t *ADC_raw);
// DAC function
static uint16_t DACCorrectionDecode(uint16_t usercode);
@@ -866,7 +866,7 @@ static void update_ZM_instruction(uint8 *ins) {
case ADCTEST:{
INSTRUCTION.eliteFxn = ADCTEST;
float ADCRealValue = 0;
int32_t ADCRealValue = 0;
uint8_t CIS_buf[9] = {0};
CIS_buf[0] = chip_ID;