From f5796e8ac5bbff3db54639b94fbe53ace40b5b98 Mon Sep 17 00:00:00 2001 From: weiting2 Date: Mon, 11 Nov 2019 10:26:13 +0800 Subject: [PATCH] [CC mode] read Vin --- .../cc26xx/app/headstage/EliteCCMode.h | 53 +++++++++++++------ .../cc26xx/app/headstage/headstage.h | 2 +- 2 files changed, 38 insertions(+), 17 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 cbb90d2f9..e2bc7482f 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 @@ -6,7 +6,7 @@ static void CCModeDACControl(int32_t IUC_Measure_Difference); static int32_t CCModeReadCurrent(CCMode *CC){ - static bool IVSwitch = false; + static uint8_t VoltCurrentSwitch = 0; CCModeDACEnable = 1; // This flag will control DAC working @@ -14,8 +14,15 @@ static int32_t CCModeReadCurrent(CCMode *CC){ CCCurrent2IUC(CC); // decode ADC value and put it into notify buffer -// if(IVSwitch){ - IVSwitch = false; + + // Use 9-th measure value as real-measure value + // because some value in the begin are garbage + if(VoltCurrentSwitch < 9){ + ReadCurrent(spi_ADC_rxbuf); + VoltCurrentSwitch ++; + } + else if(VoltCurrentSwitch == 9){ + // read current if(INSTRUCTION.AutoGainEnable){ CC->_MeasureData = AutoGainReadCurrent(spi_ADC_rxbuf); } @@ -23,21 +30,35 @@ static int32_t CCModeReadCurrent(CCMode *CC){ ReadCurrent(spi_ADC_rxbuf); CC->_MeasureData = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf); } -// } -// else{ -// IVSwitch = true; -// /** read battery voltage **/ -// // read ADC volt -// ReadVolt(spi_ADC_rxbuf); + VoltCurrentSwitch ++; + } + else if(VoltCurrentSwitch <18){ + // read volt + ReadVolt(spi_ADC_rxbuf); + VoltCurrentSwitch++; + } + else if(VoltCurrentSwitch == 18){ + // read volt + ReadVolt(spi_ADC_rxbuf); + CC->BatteryV = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf); + VoltCurrentSwitch++; + } + else{ + VoltCurrentSwitch = 0; + } + + +// /** read battery voltage **/ +// // read ADC volt +// ReadVolt(spi_ADC_rxbuf); // -// // decode ADC value and put it into notify buffer -// CC->BatteryV = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf); -// } +// // decode ADC value and put it into notify buffer +// CC->BatteryV = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf); // -// NotifyVolt[0] = (uint8_t) (CC->BatteryV >> 24); -// NotifyVolt[1] = (uint8_t) ((CC->BatteryV & 0x00FF0000) >> 16); -// NotifyVolt[2] = (uint8_t) ((CC->BatteryV & 0x0000FF00) >> 8); -// NotifyVolt[3] = (uint8_t) (CC->BatteryV & 0x000000FF); + NotifyVolt[0] = (uint8_t) (CC->BatteryV >> 24); + NotifyVolt[1] = (uint8_t) ((CC->BatteryV & 0x00FF0000) >> 16); + NotifyVolt[2] = (uint8_t) ((CC->BatteryV & 0x0000FF00) >> 8); + NotifyVolt[3] = (uint8_t) (CC->BatteryV & 0x000000FF); return CC->_MeasureData; } 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 1b7f4d6b6..4f4b43108 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 @@ -879,7 +879,7 @@ static void update_ZM_instruction(uint8 *ins) { case CONSTANT_CURRENT:{ INSTRUCTION.eliteFxn = CONSTANT_CURRENT; - INSTRUCTION.SampleRate = 10; + INSTRUCTION.SampleRate = 6; INSTRUCTION.ConstantCurrent = ( (uint32_t) (ins[3])<<24 | (uint32_t) (ins[4])<<16 | (uint32_t) (ins[5])<<8 | (uint32_t) (ins[6]) ); INSTRUCTION.NotifyRate = 1000; // GetInstructionParameter(ins+2);