From 46f080e6427453c1efd768fc681e9aee8a0a2eeb Mon Sep 17 00:00:00 2001 From: YiChin Date: Wed, 13 Nov 2019 11:25:35 +0800 Subject: [PATCH] stable version VERY NICE --- .../cc26xx/app/headstage/EliteCCMode.h | 37 +++++++------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteCCMode.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteCCMode.h index 207edc0eb..8ef3e3c74 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteCCMode.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteCCMode.h @@ -18,11 +18,11 @@ static int32_t CCModeReadCurrent(CCMode *CC){ // Use 9-th measure value as real-measure value // because some value in the begin are garbage - if(VoltCurrentSwitch < 9){ + if(VoltCurrentSwitch < 5){ ReadCurrent(spi_ADC_rxbuf); VoltCurrentSwitch ++; } - else if(VoltCurrentSwitch == 9){ + else if(VoltCurrentSwitch == 5){ // read current if(INSTRUCTION.AutoGainEnable){ CC->_MeasureData = AutoGainReadCurrent(spi_ADC_rxbuf); @@ -33,12 +33,12 @@ static int32_t CCModeReadCurrent(CCMode *CC){ } VoltCurrentSwitch ++; } - else if(VoltCurrentSwitch <18){ + else if(VoltCurrentSwitch <10){ // read volt ReadVolt(spi_ADC_rxbuf); VoltCurrentSwitch++; } - else if(VoltCurrentSwitch == 18){ + else if(VoltCurrentSwitch == 10){ // read volt ReadVolt(spi_ADC_rxbuf); CC->BatteryV = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf); @@ -89,11 +89,11 @@ static int32_t CCModeVoltOut(CCMode *CC){ // NotifyCurrent[2] = (uint8_t) ((IUCCurrent & 0x0000FF00) >> 8); // NotifyCurrent[3] = (uint8_t) (IUCCurrent & 0x000000FF); // - IUCCurrent = INSTRUCTION.ADCGainLevel; - NotifyImpedance[0] = (uint8_t) (IUCCurrent >> 24); - NotifyImpedance[1] = (uint8_t) ((IUCCurrent & 0x00FF0000) >> 16); - NotifyImpedance[2] = (uint8_t) ((IUCCurrent & 0x0000FF00) >> 8); - NotifyImpedance[3] = (uint8_t) (IUCCurrent & 0x000000FF); +// IUCCurrent = INSTRUCTION.ADCGainLevel; +// NotifyImpedance[0] = (uint8_t) (IUCCurrent >> 24); +// NotifyImpedance[1] = (uint8_t) ((IUCCurrent & 0x00FF0000) >> 16); +// NotifyImpedance[2] = (uint8_t) ((IUCCurrent & 0x0000FF00) >> 8); +// NotifyImpedance[3] = (uint8_t) (IUCCurrent & 0x000000FF); // DACCode2Real2Notify(Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant)); // if(IUCCurrent > 1000){ @@ -114,25 +114,14 @@ static int32_t CCModeVoltOut(CCMode *CC){ static void CCModeDACControl(int32_t IUC_Measure_Difference){ int32_t step; - if(IUC_Measure_Difference < 10 && IUC_Measure_Difference > -10){ - step = (IUC_Measure_Difference > 0) ? 1:-1; - } - else if(IUC_Measure_Difference < 100 && IUC_Measure_Difference > -100){ - step = (IUC_Measure_Difference > 0) ? 5:-5; - } - else if(IUC_Measure_Difference < 1000 && IUC_Measure_Difference > -1000){ - step = IUC_Measure_Difference / 1e3; - } - else if(IUC_Measure_Difference < 10000 && IUC_Measure_Difference > -10000){ - step = IUC_Measure_Difference / 1e4; - } - else if(IUC_Measure_Difference < 1e5 && IUC_Measure_Difference > -1e5){ - step = IUC_Measure_Difference / 1e5; + if(IUC_Measure_Difference < 300 && IUC_Measure_Difference > -300){ + step = 0; } else{ - step = IUC_Measure_Difference / 1e6; + step = (IUC_Measure_Difference > 0) ? 1:-1; } + // over/under flow if( (INSTRUCTION.VoltConstant + step) > MAX_DAC_UC || (INSTRUCTION.VoltConstant + step) < MIN_DAC_UC ){ if(step > 0){