From c53a2d8872b35d290d47c63fb31cffbf5a87a025 Mon Sep 17 00:00:00 2001 From: YiChin Date: Tue, 26 May 2020 16:10:26 +0800 Subject: [PATCH] fix ADCGain --- .../cc26xx/app/headstage/EliteADC.h | 77 +++++++++++++++---- .../cc26xx/app/headstage/EliteCV3Mode.h | 1 + .../cc26xx/app/headstage/EliteCVCurve.h | 1 + .../cc26xx/app/headstage/EliteIVCurve.h | 1 + .../cc26xx/app/headstage/Elite_version.h | 2 +- .../cc26xx/app/headstage/headstage.h | 1 + 6 files changed, 67 insertions(+), 16 deletions(-) diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteADC.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteADC.h index 3a4eb2823..90fd7b672 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteADC.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteADC.h @@ -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 diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteCV3Mode.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteCV3Mode.h index 1098abf55..88918a185 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteCV3Mode.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteCV3Mode.h @@ -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); diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteCVCurve.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteCVCurve.h index 65d60959d..7057f0bbf 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteCVCurve.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteCVCurve.h @@ -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); diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteIVCurve.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteIVCurve.h index 6736762f6..9b6c76a5e 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteIVCurve.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteIVCurve.h @@ -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); diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_version.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_version.h index 2393a6bb8..88017321e 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_version.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_version.h @@ -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 !! diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage.h index 8241ec594..dae73d8cc 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage.h @@ -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);