From f5416d5e1f3cf0ff4cee9146f76d8d2aaa8eee02 Mon Sep 17 00:00:00 2001 From: Roy Date: Mon, 15 Mar 2021 15:44:47 +0800 Subject: [PATCH] measure battery when run mode --- .../cc26xx/app/headstage/Elite_mode_ADC_DAC.h | 182 +++++++++--------- .../cc26xx/app/headstage/Elite_version.h | 6 +- .../cc26xx/app/headstage/impedance_meter.h | 22 +-- 3 files changed, 105 insertions(+), 105 deletions(-) diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_mode_ADC_DAC.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_mode_ADC_DAC.h index 425ec5cfd..6d47243af 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_mode_ADC_DAC.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_mode_ADC_DAC.h @@ -106,80 +106,80 @@ static void CC_Plot(void) static int32_t VoltData = 0; void *wm = wm_get(); -// if (batteryCheck_flag) { -// if (BatSwitch == 0) { -// if (ADCSwitch == 0) { /**read Iin(buffer),read bat**/ -// if (instru.AutoGainEnable) { -// MEAS_CURR(wm) = AutoGainReadIin(spi_ADC_rxbuf); -// AutoGainChangeIin(MEAS_CURR(wm)); -// } else { -// ReadADCIin(spi_ADC_rxbuf); -// MEAS_CURR(wm) = DecodeADCValue(instru.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf); -// if (lastIinADCGainLevel != instru.ADCGainLevel) { -// IinADCGainControl(instru.ADCGainLevel); -// record_flag = false; -// } -// } -// if (record_flag == false) { -// static int recordCount = 0; -// recordCount++; -// if (recordCount == 2) { -// record_flag = true; -// recordCount = 0; -// } -// } else { -// InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm)); -// } -// DACenable(AFTER_READ_I); -// -// ReadADCBat(spi_ADC_rxbuf); -// BatSwitch++; -// } else if(ADCSwitch == 1 || ADCSwitch == 3) { /**read Bat**/ -// ReadADCBat(spi_ADC_rxbuf); -// BatSwitch++; -// } else if(ADCSwitch == 2) { /**read V(buffer),read bat**/ -// if (VOLT_SW(wm) == 0x01 || VOLT_SW(wm) == 0x02) { -// if (instru.VinAutoGainEnable) { -// MEAS_VIN(wm) = AutoGainReadVin(spi_ADC_rxbuf); -// AutoGainChangeVin(MEAS_VIN(wm)); -// } else { -// ReadADCVolt(VOLT_SW(wm)); -// MEAS_VIN(wm) = DecodeADCValue(instru.VinADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf); -// if (lastVinADCGainLevel != instru.VinADCGainLevel) { -// VinADCGainControl(instru.VinADCGainLevel); -// record_flag = false; -// } -// } -// VoltData = MEAS_VIN(wm); -// } else if (VOLT_SW(wm) == 0x00) { -// ReadADCVolt(VOLT_SW(wm)); -// MEAS_VOUT(wm) = DecodeADCValue(instru.ADCGainLevel, ADC_CH_DAC, spi_ADC_rxbuf); -// VoltData = MEAS_VOUT(wm); -// } -// -// if (instru.VoViSwitch == 0x02) { -// int32_t Vscan = (Vset / 200 - MEAS_VIN(wm)); -// Vscan = (int32_t)(Vscan);//[1uV] -// InputNotify(NOTIFY_VOLT, Vscan); -// } else { -// InputNotify(NOTIFY_VOLT, VoltData); -// } -// DACenable(AFTER_READ_V); -// -// ReadADCBat(spi_ADC_rxbuf); -// BatSwitch++; -// } -// } else if(BatSwitch == 1) { -// ReadADCBat(spi_ADC_rxbuf); -// BatSwitch++; -// } else if(BatSwitch == 2) { -// headstage_battery_volt(); -// ReadADCIin(spi_ADC_rxbuf); -// batteryCheck_flag = false; -// BatSwitch = 0; -// ADCSwitch = 3; -// } -// } else { + if (batteryCheck_flag) { + if (BatSwitch == 0) { + if (ADCSwitch == 0) { /**read Iin(buffer),read bat**/ + if (instru.AutoGainEnable) { + MEAS_CURR(wm) = AutoGainReadIin(spi_ADC_rxbuf); + AutoGainChangeIin(MEAS_CURR(wm)); + } else { + ReadADCIin(spi_ADC_rxbuf); + MEAS_CURR(wm) = DecodeADCValue(instru.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf); + if (lastIinADCGainLevel != instru.ADCGainLevel) { + IinADCGainControl(instru.ADCGainLevel); + record_flag = false; + } + } + if (record_flag == false) { + static int recordCount = 0; + recordCount++; + if (recordCount == 2) { + record_flag = true; + recordCount = 0; + } + } else { + InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm)); + } + DACenable(AFTER_READ_I); + + ReadADCBat(spi_ADC_rxbuf); + BatSwitch++; + } else if(ADCSwitch == 1 || ADCSwitch == 3) { /**read Bat**/ + ReadADCBat(spi_ADC_rxbuf); + BatSwitch++; + } else if(ADCSwitch == 2) { /**read V(buffer),read bat**/ + if (VOLT_SW(wm) == 0x01 || VOLT_SW(wm) == 0x02) { + if (instru.VinAutoGainEnable) { + MEAS_VIN(wm) = AutoGainReadVin(spi_ADC_rxbuf); + AutoGainChangeVin(MEAS_VIN(wm)); + } else { + ReadADCVolt(VOLT_SW(wm)); + MEAS_VIN(wm) = DecodeADCValue(instru.VinADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf); + if (lastVinADCGainLevel != instru.VinADCGainLevel) { + VinADCGainControl(instru.VinADCGainLevel); + record_flag = false; + } + } + VoltData = MEAS_VIN(wm); + } else if (VOLT_SW(wm) == 0x00) { + ReadADCVolt(VOLT_SW(wm)); + MEAS_VOUT(wm) = DecodeADCValue(instru.ADCGainLevel, ADC_CH_DAC, spi_ADC_rxbuf); + VoltData = MEAS_VOUT(wm); + } + + if (instru.VoViSwitch == 0x02) { + int32_t Vscan = (Vset / 200 - MEAS_VIN(wm)); + Vscan = (int32_t)(Vscan);//[1uV] + InputNotify(NOTIFY_VOLT, Vscan); + } else { + InputNotify(NOTIFY_VOLT, VoltData); + } + DACenable(AFTER_READ_V); + + ReadADCBat(spi_ADC_rxbuf); + BatSwitch++; + } + } else if(BatSwitch == 1) { + ReadADCBat(spi_ADC_rxbuf); + BatSwitch++; + } else if(BatSwitch == 2) { + headstage_battery_volt(); + ReadADCIin(spi_ADC_rxbuf); + batteryCheck_flag = false; + BatSwitch = 0; + ADCSwitch = 3; + } + } else { BatSwitch = 0; if (ADCSwitch == 0) { /**read Iin(buffer),read V**/ if (instru.AutoGainEnable) { @@ -245,7 +245,7 @@ static void CC_Plot(void) ReadADCIin(spi_ADC_rxbuf); ADCSwitch = 0; } -// } + } } static void IT_Plot(void) @@ -253,13 +253,13 @@ static void IT_Plot(void) static uint8_t ADCSwitch = 0; void *wm = wm_get(); -// if (batteryCheck_flag) { -// EliteADCBattery(); -// if (!batteryCheck_flag) { -// ReadADCIin(spi_ADC_rxbuf); -// ADCSwitch = 2; -// } -// } else { + if (batteryCheck_flag) { + EliteADCBattery(); + if (!batteryCheck_flag) { + ReadADCIin(spi_ADC_rxbuf); + ADCSwitch = 2; + } + } else { if (ADCSwitch == 0) { /**read Iin(buffer)**/ if (instru.AutoGainEnable) { MEAS_CURR(wm) = AutoGainReadIin(spi_ADC_rxbuf); @@ -290,7 +290,7 @@ static void IT_Plot(void) ReadADCIin(spi_ADC_rxbuf); ADCSwitch = 0; } -// } + } } static void VT_Plot(void) @@ -299,13 +299,13 @@ static void VT_Plot(void) static int32_t VoltData; void *wm = wm_get(); -// if (batteryCheck_flag) { -// EliteADCBattery(); -// if (!batteryCheck_flag) { -// ReadADCVolt(VOLT_SW(wm)); -// ADCSwitch = 2; -// } -// } else { + if (batteryCheck_flag) { + EliteADCBattery(); + if (!batteryCheck_flag) { + ReadADCVolt(VOLT_SW(wm)); + ADCSwitch = 2; + } + } else { if (ADCSwitch == 0) { /**read V(buffer)**/ if (VOLT_SW(wm) == 0x01 || VOLT_SW(wm) == 0x02) { if (instru.VinAutoGainEnable) { @@ -345,7 +345,7 @@ static void VT_Plot(void) ReadADCVolt(VOLT_SW(wm)); ADCSwitch = 0; } -// } + } } static void cali_IT_plot(void) { 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 e6e6954c3..cad41b917 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 @@ -4,9 +4,9 @@ #define VERSION_DATE_YEAR 21 #define VERSION_DATE_MONTH 3 -#define VERSION_DATE_DAY 12 -#define VERSION_DATE_HOUR 12 -#define VERSION_DATE_MINUTE 12 +#define VERSION_DATE_DAY 15 +#define VERSION_DATE_HOUR 15 +#define VERSION_DATE_MINUTE 44 // this is NOT the version hash !! // it's the last version hash diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/impedance_meter.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/impedance_meter.h index 4725cc046..e96624c01 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/impedance_meter.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/impedance_meter.h @@ -192,17 +192,17 @@ static void SimpleBLEPeripheral_performPeriodicTask(void) { } //battery counter -// GPT.BatteryADCCounter = GPT.BatteryADCCounter + GPT.DeltaGptimerCounter; -// GPT.BatteryCheckCounter = GPT.BatteryCheckCounter + GPT.DeltaGptimerCounter; -// if(GPT.BatteryCheckCounter >= 50000){ -// GPT.BatteryCheckCounter -= 50000; //To get right time -// batteryCheck_flag = true; -// } -// -// uint16_t bat = ((uint16_t)(NotifyVoltBat[2]) << 8 & 0xFF00 ) | ((uint16_t)(NotifyVoltBat[3]) & 0x00FF); -// if( bat < 768 && bat > 20){ -// PIN15_setOutputValue(enable_5v, 0); -// } + GPT.BatteryADCCounter = GPT.BatteryADCCounter + GPT.DeltaGptimerCounter; + GPT.BatteryCheckCounter = GPT.BatteryCheckCounter + GPT.DeltaGptimerCounter; + if(GPT.BatteryCheckCounter >= 50000){ + GPT.BatteryCheckCounter -= 50000; //To get right time + batteryCheck_flag = true; + } + + uint16_t bat = ((uint16_t)(NotifyVoltBat[2]) << 8 & 0xFF00 ) | ((uint16_t)(NotifyVoltBat[3]) & 0x00FF); + if( bat < 768 && bat > 20){ + PIN15_setOutputValue(enable_5v, 0); + } //ADC counter GPT.SampleRateCounter = GPT.SampleRateCounter + GPT.DeltaGptimerCounter;