From eddbe3980a341269c1c2453991533de9cc5c8413 Mon Sep 17 00:00:00 2001 From: alan Date: Wed, 2 Oct 2019 17:49:06 +0800 Subject: [PATCH 1/3] 10/6 demo version --- .../simple_peripheral/cc26xx/app/headstage/EliteZTcurve.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteZTcurve.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteZTcurve.h index c8883befe..a350978dc 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteZTcurve.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteZTcurve.h @@ -30,6 +30,8 @@ static void ZT_Plot() { } ADCGainControl(INSTRUCTION.ADCGainLevel); + // Use 9-th measure value as real-measure value + // because some value in the begin are garbage if(VoltCurrentSwitch < 9){ ADCChannelSelect(ADC_CH_CURRENT); CPUdelay(10); From bceb8b913425c40fa21e112b456dccff5c45313c Mon Sep 17 00:00:00 2001 From: alan Date: Fri, 4 Oct 2019 14:47:09 +0800 Subject: [PATCH 2/3] ADC test with avg --- .../cc26xx/app/headstage/headstage.h | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) 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 807a3edd3..93efc2ce5 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 @@ -902,15 +902,27 @@ static void update_ZM_instruction(uint8 *ins) { int32_t ADCRealValue = 0; uint8_t CIS_buf[9] = {0}; - ADCGainControl(ins[3]); - ADCChannelSelect(ins[4]); - CPUdelay(1600); - ADC_read(spi_ADC_rxbuf); + uint16_t ADCValueTemp = 0; + uint32_t ADCValueAVG = 0; + + for(int i=0 ; i<10 ; i++){ + ADCGainControl(ins[3]); + ADCChannelSelect(ins[4]); + CPUdelay(10); + ADC_read(spi_ADC_rxbuf); + CPUdelay(10); + + ADCValueTemp = spi_ADC_rxbuf[0] << 8 | spi_ADC_rxbuf[1]; + ADCValueAVG = ADCValueAVG + ADCValueTemp; + } + ADCValueAVG = ADCValueAVG / 10; + ADCValueTemp = (uint16_t) (ADCValueAVG); CIS_buf[0] = chip_ID; - for (int i = 0; i < 4; i++) { - CIS_buf[i + 1] = spi_ADC_rxbuf[i]; - } + CIS_buf[1] = (uint8_t) (ADCValueTemp & 0xFF00 >> 8); + CIS_buf[2] = (uint8_t) (ADCValueTemp & 0x00FF); + CIS_buf[3] = spi_ADC_rxbuf[2]; + CIS_buf[4] = spi_ADC_rxbuf[3]; // decode ADC measure value ADCRealValue = DecodeADCValue(ins[3], ins[4], spi_ADC_rxbuf); From 337c2aef8dffd1d883dcdd77098e47b4494deade Mon Sep 17 00:00:00 2001 From: YiChin Date: Fri, 4 Oct 2019 15:03:11 +0800 Subject: [PATCH 3/3] add CV curve --- .../cc26xx/app/headstage/EliteCVCurve.h | 127 ++++++++++++------ .../app/headstage/EliteDeviceCorrection.h | 2 +- .../cc26xx/app/headstage/EliteIVCurve.h | 2 +- .../cc26xx/app/headstage/EliteLED.h | 4 +- .../cc26xx/app/headstage/headstage.h | 11 +- .../cc26xx/app/headstage/impedance_meter.h | 9 +- 6 files changed, 103 insertions(+), 52 deletions(-) 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 459f55656..5e6890074 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 @@ -133,15 +133,13 @@ static uint16_t DPVCurve() { } static uint16_t CVCurve() { - static uint8_t ramp0; - static uint8_t ramp1; - static uint16_t outputV; + static uint16_t DACOutCode; static bool direction_up; static bool current_direction_up; // reset origin volt at the begin if (DACReset) { - outputV = INSTRUCTION.VoltOrigin; + DACUserCode = INSTRUCTION.VoltOrigin; if (INSTRUCTION.VoltFinal > INSTRUCTION.VoltOrigin) { direction_up = true; current_direction_up = true; @@ -149,51 +147,98 @@ static uint16_t CVCurve() { direction_up = false; current_direction_up = false; } - ramp0 = (uint8_t)(INSTRUCTION.VoltOrigin & 0x00FF); // right byte - ramp1 = (uint8_t)((INSTRUCTION.VoltOrigin >> 8) & 0x00FF); // left byte - DACReset = false; + + DACOutCode = Usercode_Correction_to_DAC(DACUserCode); + DAC_outputV(DACOutCode); // output VOLT_ORIGIN + DACReset = false; + + return DACOutCode; } - // output a certain volt - DAC_outputV(outputV); + if (StepTimeCounter == INSTRUCTION.StepTime) { - if (direction_up) { - if (outputV >= INSTRUCTION.VoltFinal) { - current_direction_up = false; // problem occurs when origin == 0000 final == ffff!!!!!! - } else if (outputV <= INSTRUCTION.VoltOrigin) { - current_direction_up = true; - if (INSTRUCTION.CycleNumber == 0) { - PeriodicEvent = false; // periodic event end - DACReset = true; + // Next direction + if (direction_up) { + if (DACUserCode >= INSTRUCTION.VoltFinal) { + current_direction_up = false; // problem occurs when origin == 0000 final == ffff!!!!!! + } else if (DACUserCode <= INSTRUCTION.VoltOrigin) { + current_direction_up = true; + if (INSTRUCTION.CycleNumber == 0) { + PeriodicEvent = false; // periodic event end + DACReset = true; + } + INSTRUCTION.CycleNumber--; } - INSTRUCTION.CycleNumber--; - } - } else { - if (outputV <= INSTRUCTION.VoltFinal) { - current_direction_up = true; // problem occurs when origin == 0000 final == ffff!!!!!! - } else if (outputV >= INSTRUCTION.VoltOrigin) { - current_direction_up = false; - if (INSTRUCTION.CycleNumber == 0) { - PeriodicEvent = false; // periodic event end - DACReset = true; + } else { + if (DACUserCode <= INSTRUCTION.VoltFinal) { + current_direction_up = true; // problem occurs when origin == 0000 final == ffff!!!!!! + } else if (DACUserCode >= INSTRUCTION.VoltOrigin) { + current_direction_up = false; + if (INSTRUCTION.CycleNumber == 0) { + PeriodicEvent = false; // periodic event end + DACReset = true; + } + INSTRUCTION.CycleNumber--; } - INSTRUCTION.CycleNumber--; } - } - if (current_direction_up) { - if (outputV + INSTRUCTION.Step < outputV) - outputV = 0xffff; - else - outputV = outputV + INSTRUCTION.Step; - } else { - if (outputV - INSTRUCTION.Step > outputV) - outputV = 0x0000; - else - outputV = outputV - INSTRUCTION.Step; - } + // Next output voltage + if (direction_up) { + if (current_direction_up) { + if (DACUserCode + INSTRUCTION.Step < DACUserCode) { + DACUserCode = 0xffff; + } + else if (DACUserCode + INSTRUCTION.Step > INSTRUCTION.VoltFinal) { + DACUserCode = INSTRUCTION.VoltFinal; + } + else { + DACUserCode = DACUserCode + INSTRUCTION.Step; + } + } + else { + if (DACUserCode - INSTRUCTION.Step > DACUserCode) { + DACUserCode = 0x0000; + } + else if (DACUserCode + INSTRUCTION.Step < INSTRUCTION.VoltOrigin) { + DACUserCode = INSTRUCTION.VoltOrigin; + } + else { + DACUserCode = DACUserCode - INSTRUCTION.Step; + } + } + } + else { + if (current_direction_up) { + if (DACUserCode + INSTRUCTION.Step < DACUserCode) { + DACUserCode = 0xffff; + } + else if (DACUserCode + INSTRUCTION.Step > INSTRUCTION.VoltOrigin) { + DACUserCode = INSTRUCTION.VoltOrigin; + } + else { + DACUserCode = DACUserCode + INSTRUCTION.Step; + } + } + else { + if (DACUserCode - INSTRUCTION.Step > DACUserCode) { + DACUserCode = 0x0000; + } + else if (DACUserCode + INSTRUCTION.Step < INSTRUCTION.VoltFinal) { + DACUserCode = INSTRUCTION.VoltFinal; + } + else { + DACUserCode = DACUserCode - INSTRUCTION.Step; + } + } + } - return outputV; + + DACOutCode = Usercode_Correction_to_DAC(DACUserCode); + DAC_outputV(DACOutCode); + + } + return DACOutCode; } + #endif diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteDeviceCorrection.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteDeviceCorrection.h index 40529425e..5cb5396ba 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteDeviceCorrection.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteDeviceCorrection.h @@ -419,7 +419,7 @@ static int32_t DecodeADCValue(uint8_t ADCGain, uint8_t ADCChannel, uint8_t *ADC_ // return real current to controller else if(ADCChannel == ADC_CH_CURRENT){ - if (INSTRUCTION.eliteFxn == IV_CURVE) { + if ( (INSTRUCTION.eliteFxn == IV_CURVE) || (INSTRUCTION.eliteFxn == CV_CURVE)) { ADCRealCurrent_long += DecodeADCCurrent(ADCGain, ADC_measure); avg_number++; 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 803e5adf2..1707a99c0 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 @@ -13,7 +13,7 @@ static uint16_t VoltScan() { Voltage = SWVCurve(); } else if (INSTRUCTION.eliteFxn == DIFFERENTIAL_PULSE_VOLTAMMETRY) { Voltage = DPVCurve(); - } else if (INSTRUCTION.eliteFxn == CYCLIC_VOLTAMMETRY) { + } else if (INSTRUCTION.eliteFxn == CV_CURVE) { Voltage = CVCurve(); } diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteLED.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteLED.h index 71ec86d0a..969d2e61d 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteLED.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteLED.h @@ -29,7 +29,7 @@ static void WorkModeLED() { WORKLED(); break; } - case CYCLIC_VOLTAMMETRY: { + case CV_CURVE: { WORKLED(); break; } @@ -82,7 +82,7 @@ static void KeyWorkModeLED() { LED_color(LIGHTLED, 0xF0, 0xF0, 0x00); break; } - case CYCLIC_VOLTAMMETRY:{ + case CV_CURVE:{ LED_color(LIGHTLED, 0xF0, 0xF0, 0x00); break; } 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 e17811e45..f03d8016a 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 @@ -579,7 +579,7 @@ static void set_update_instruction_callback(update_instruction_callback_type cal // real instruction #define IV_CURVE 0b00010000 -#define CYCLIC_VOLTAMMETRY 0b00100000 +#define CV_CURVE 0b00100000 #define VOLT_OUTPUT 0b00110000 #define ZT_CURVE 0b01000000 #define VT_CURVE 0b01010000 @@ -801,18 +801,18 @@ static void update_ZM_instruction(uint8 *ins) { break; } - case CYCLIC_VOLTAMMETRY: { + case CV_CURVE: { CleanBuffer(); - INSTRUCTION.eliteFxn = CYCLIC_VOLTAMMETRY; + INSTRUCTION.eliteFxn = CV_CURVE; DACReset = true; if (ins[3] | ins[4]) { INSTRUCTION.VoltOrigin = ((uint16_t)(ins[3]) << 8) | (uint16_t)(ins[4]); - INSTRUCTION.VoltOrigin = Usercode_Correction_to_DAC(INSTRUCTION.VoltOrigin); + // INSTRUCTION.VoltOrigin = Usercode_Correction_to_DAC(INSTRUCTION.VoltOrigin); } if (ins[5] | ins[6]) { INSTRUCTION.VoltFinal = ((uint16_t)(ins[5]) << 8) | (uint16_t)(ins[6]); - INSTRUCTION.VoltFinal = Usercode_Correction_to_DAC(INSTRUCTION.VoltFinal); + // INSTRUCTION.VoltFinal = Usercode_Correction_to_DAC(INSTRUCTION.VoltFinal); } if (ins[7] | ins[8]) { @@ -830,6 +830,7 @@ static void update_ZM_instruction(uint8 *ins) { break; } + case VOLT_OUTPUT: { INSTRUCTION.eliteFxn = VOLT_OUTPUT; INSTRUCTION.VoltConstant = ( ((uint16_t)(ins[3])) << 8) | (uint16_t)(ins[4]); 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 c59624650..5309d5a85 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 @@ -72,6 +72,7 @@ static void DACCode2Real2Notify(uint16_t DACcode) { #define IsPeriodicMode() ( \ (INSTRUCTION.eliteFxn == IV_CURVE) || \ +(INSTRUCTION.eliteFxn == CV_CURVE) || \ (INSTRUCTION.eliteFxn == IT_CURVE) || \ (INSTRUCTION.eliteFxn == VT_CURVE) || \ (INSTRUCTION.eliteFxn == ZT_CURVE) || \ @@ -122,7 +123,7 @@ static void SimpleBLEPeripheral_performPeriodicTask(CURRENT_USER_CODE *CurrentUs } static void EliteDACControl(CURRENT_USER_CODE *CurrentUserCode) { - if (INSTRUCTION.eliteFxn == IV_CURVE) { + if ((INSTRUCTION.eliteFxn == IV_CURVE) || (INSTRUCTION.eliteFxn == CV_CURVE)) { // output a certain voltage and put it into NotifyVolt DACCode2Real2Notify(VoltScan()); } @@ -156,6 +157,10 @@ static void EliteADCControl(CURRENT_USER_CODE *CurrentUserCode) { IT_Plot(); break; } + case CV_CURVE:{ + IT_Plot(); + break; + } case IT_CURVE:{ IT_Plot(); break; @@ -181,7 +186,7 @@ static void EliteADCControl(CURRENT_USER_CODE *CurrentUserCode) { } static void EliteNotifyControl() { - if ((INSTRUCTION.eliteFxn == IV_CURVE)) { + if ((INSTRUCTION.eliteFxn == IV_CURVE) || (INSTRUCTION.eliteFxn == CV_CURVE)) { // output the last notify, and reset Elite if (!PeriodicEvent) { SendNotify();