fix ADCGain
This commit is contained in:
+62
-15
@@ -188,48 +188,95 @@ static int32_t AutoGainReadCurrent(uint8_t *buf){
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200R;
|
||||
}
|
||||
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
|
||||
return Real_Current;
|
||||
}
|
||||
|
||||
|
||||
static void AutoGainChange(int32_t Real_Current){
|
||||
if(INSTRUCTION.ADCGainLevel == GAIN_200R){
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
// switch to mid range current
|
||||
if(Real_Current < GAIN_LARGE_BOUNDARY && Real_Current > -1*GAIN_LARGE_BOUNDARY){
|
||||
// switch to small range current
|
||||
if (Real_Current < GAIN_MID_BOUNDARY1 && Real_Current > -1*GAIN_MID_BOUNDARY1){
|
||||
GAIN_200K_counter++;
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200K;
|
||||
if(GAIN_200K_counter > 5){
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200K;
|
||||
GAIN_200K_counter = 0;
|
||||
}
|
||||
}else{
|
||||
INSTRUCTION.ADCGainLevel = GAIN_10K;
|
||||
GAIN_10K_counter++;
|
||||
if(GAIN_10K_counter > 5){
|
||||
INSTRUCTION.ADCGainLevel = GAIN_10K;
|
||||
GAIN_10K_counter = 0;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(GAIN_200K_counter > 0){
|
||||
GAIN_200K_counter--;
|
||||
}
|
||||
if(GAIN_10K_counter > 0){
|
||||
GAIN_10K_counter--;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(INSTRUCTION.ADCGainLevel == GAIN_10K){
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
// switch to large range current
|
||||
if(Real_Current > GAIN_MID_BOUNDARY2 || Real_Current < -1*GAIN_MID_BOUNDARY2){
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200R;
|
||||
GAIN_200R_counter++;
|
||||
if(GAIN_200R_counter > 5){
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200R;
|
||||
GAIN_200R_counter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// switch to small range current
|
||||
else if (Real_Current < GAIN_MID_BOUNDARY1 && Real_Current > -1*GAIN_MID_BOUNDARY1){
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200K;
|
||||
GAIN_200K_counter++;
|
||||
if(GAIN_200K_counter > 5){
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200K;
|
||||
GAIN_200K_counter = 0;
|
||||
}
|
||||
|
||||
}else{
|
||||
if(GAIN_200R_counter > 0){
|
||||
GAIN_200R_counter--;
|
||||
}
|
||||
if(GAIN_200K_counter > 0){
|
||||
GAIN_200K_counter--;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(INSTRUCTION.ADCGainLevel == GAIN_200K){
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
|
||||
// switch to mid range current
|
||||
if(Real_Current > GAIN_SMALL_BOUNDARY || Real_Current < -1*GAIN_SMALL_BOUNDARY){
|
||||
// switch to large range current
|
||||
if(Real_Current > GAIN_MID_BOUNDARY2 || Real_Current < -1*GAIN_MID_BOUNDARY2){
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200R;
|
||||
GAIN_200R_counter++;
|
||||
if(GAIN_200R_counter > 5){
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200R;
|
||||
GAIN_200R_counter = 0;
|
||||
}
|
||||
|
||||
}else{
|
||||
INSTRUCTION.ADCGainLevel = GAIN_10K;
|
||||
GAIN_10K_counter++;
|
||||
if(GAIN_10K_counter > 5){
|
||||
INSTRUCTION.ADCGainLevel = GAIN_10K;
|
||||
GAIN_10K_counter = 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(GAIN_200R_counter > 0){
|
||||
GAIN_200R_counter--;
|
||||
}
|
||||
if(GAIN_10K_counter > 0){
|
||||
GAIN_10K_counter--;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Real_Current;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+1
@@ -45,6 +45,7 @@ static void CV3_Plot(CV3Mode *CV3){
|
||||
// read current
|
||||
if(INSTRUCTION.AutoGainEnable){
|
||||
CV3->_MeasureData = AutoGainReadCurrent(spi_ADC_rxbuf);
|
||||
AutoGainChange(CV3->_MeasureData);
|
||||
}else{
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
CV3->_MeasureData = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
|
||||
+1
@@ -149,6 +149,7 @@ static void CV_Plot(CVMode *CV){
|
||||
// read current
|
||||
if(INSTRUCTION.AutoGainEnable){
|
||||
CV->_MeasureData = AutoGainReadCurrent(spi_ADC_rxbuf);
|
||||
AutoGainChange(CV->_MeasureData);
|
||||
}else{
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
CV->_MeasureData = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
|
||||
+1
@@ -56,6 +56,7 @@ static void IV_Plot(IVMode *IV) {
|
||||
// read current
|
||||
if(INSTRUCTION.AutoGainEnable){
|
||||
IV->_MeasureData = AutoGainReadCurrent(spi_ADC_rxbuf);
|
||||
AutoGainChange(IV->_MeasureData);
|
||||
}else{
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
IV->_MeasureData = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
#define VERSION_DATE_YEAR 20
|
||||
#define VERSION_DATE_MONTH 5
|
||||
#define VERSION_DATE_DAY 26
|
||||
#define VERSION_DATE_HOUR 11
|
||||
#define VERSION_DATE_HOUR 16
|
||||
#define VERSION_DATE_MINUTE 10
|
||||
|
||||
// this is NOT the version hash !!
|
||||
|
||||
+1
@@ -702,6 +702,7 @@ static uint16_t DPVCurve(WorkMode *WorkModeData);
|
||||
static uint16_t CVCurve(CVMode *CV);
|
||||
static uint16_t SWVCurve(WorkMode *WorkModeData);
|
||||
static uint16_t CV3Curve(CV3Mode *CV3);
|
||||
static void AutoGainChange();
|
||||
|
||||
static void CV3_Vscan(CV3Mode *CV3);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user