From ff58ec8a1ecbccd192d2e0412b20ce69e228a7a7 Mon Sep 17 00:00:00 2001 From: alan Date: Tue, 3 Sep 2019 17:01:46 +0800 Subject: [PATCH] Elite 1.4-re split every function into .h file --- .../cc26xx/app/headstage/EliteCCMode.h | 6 ++ .../cc26xx/app/headstage/EliteITCurve.h | 23 +++++ .../cc26xx/app/headstage/EliteIVCurve.h | 25 ++++- .../cc26xx/app/headstage/EliteVTcurve.h | 18 ++++ .../cc26xx/app/headstage/EliteZTcurve.h | 28 ++++++ .../cc26xx/app/headstage/headstage.h | 9 +- .../cc26xx/app/headstage/impedance_meter.h | 97 +++---------------- 7 files changed, 122 insertions(+), 84 deletions(-) create mode 100644 simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteITCurve.h create mode 100644 simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteVTcurve.h create mode 100644 simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteZTcurve.h 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 993ec2774..66defbcbb 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 @@ -25,6 +25,7 @@ struct CURRENT_USER_CODE{ static int32_t CCModeReadCurrent(){ int32_t Real_Current = 0; + CCModeReset = 0; // CCCurrent2IUC(); // read ADC current @@ -42,6 +43,11 @@ static int32_t CCModeReadCurrent(){ Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf); } +static int32_t CCModeOutputDAC(){ + + +} + static void SetCCModeGain(){ switch(CurrentUserCode.lv){ case CURRENT_LV_FOUR:{ diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteITCurve.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteITCurve.h new file mode 100644 index 000000000..faf39bdb5 --- /dev/null +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteITCurve.h @@ -0,0 +1,23 @@ + +#ifndef ELITEIT +#define ELITEIT + +static int32_t IT_Plot() { + // read ADC current + int32_t Real_Current = 0; + ADCGainControl(INSTRUCTION.ADCGainLevel); + ADCChannelSelect(ADC_CH_CURRENT); + CPUdelay(10); + ADC_read(spi_ADC_rxbuf); + + // check if ADC over/under flow + // let the output saturate if over/under flow + ADC_overflow(INSTRUCTION.ADCGainLevel, spi_ADC_rxbuf); + + // decode ADC value and put it into notify buffer + Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf); + + return Real_Current; +} + +#endif 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 dcc7266d0..266ecbd20 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 @@ -2,7 +2,30 @@ #ifndef ELITEIV #define ELITEIV -static uint16_t IVCurve() { +static uint16_t VoltScan() { + uint16_t Voltage; + if (INSTRUCTION.VoltOrigin == INSTRUCTION.VoltFinal) { + // DAC_outputV(DACOUT, INSTRUCTION.VoltOrigin); //delete 'command' parameter + DAC_outputV(INSTRUCTION.VoltOrigin); + PeriodicEvent = false; + return INSTRUCTION.VoltOrigin; + } else if (INSTRUCTION.eliteFxn == SQUARE_WAVE_VOLTAMMETRY) { + Voltage = SWVCurve(); + } else if (INSTRUCTION.eliteFxn == DIFFERENTIAL_PULSE_VOLTAMMETRY) { + Voltage = DPVCurve(); + } else if (INSTRUCTION.eliteFxn == CYCLIC_VOLTAMMETRY) { + Voltage = CVCurve(); + } + + // IV plot mode + else { + Voltage = OneWayVoltScan(); + } + + return Voltage; +} + +static uint16_t OneWayVoltScan() { static uint16_t DACOutCode; // reset origin volt at the begin diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteVTcurve.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteVTcurve.h new file mode 100644 index 000000000..1ebc2c450 --- /dev/null +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteVTcurve.h @@ -0,0 +1,18 @@ + +#ifndef ELITEVT +#define ELITEVT + +static void VT_Plot() { + // ADC gain is don't care when measuring voltage + uint8_t ADCGain = 1; + + // read ADC volt + ADCChannelSelect(ADC_CH_VOLT); + CPUdelay(10); + ADC_read(spi_ADC_rxbuf); + + // decode ADC value and put it into notify buffer + DecodeADCValue(ADCGain, ADC_CH_VOLT, spi_ADC_rxbuf); +} + +#endif 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 new file mode 100644 index 000000000..bf9b7937f --- /dev/null +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteZTcurve.h @@ -0,0 +1,28 @@ + +#ifndef ELITEZT +#define ELITEZT + +// output a certain voltage e.g. 2v +// and measure the input voltage +// => calculate the resister +// change the output voltage step +// => get a R-T curve (with resolution = 1 sample/volt step ) +static void ZT_Plot() { + // read ADC current + int32_t Real_Current = 0; + ADCGainControl(INSTRUCTION.ADCGainLevel); + ADCChannelSelect(ADC_CH_CURRENT); + CPUdelay(10); + ADC_read(spi_ADC_rxbuf); + + // check if ADC over/under flow + ADC_overflow(INSTRUCTION.ADCGainLevel, spi_ADC_rxbuf); + + // decode ADC value and put it into notify buffer + Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf); + + Impedance_Calculate(INSTRUCTION.VoltConstant, Real_Current); + +} + +#endif 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 039ad34be..da541d26f 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 @@ -613,6 +613,13 @@ static int16_t avg_number = 0; static int32_t ADCRealCurrent = 0; static long long ADCRealCurrent_long = 0; +// Constant Current Mode function +static CCModeReset = 1; +static int32_t CCModeReadCurrent(); +static int32_t CCModeOutputDAC(); +static void SetCCModeGain(); +static void CCCurrent2IUC(); + // for DPVCurve SWVCurve static uint16_t Amplitude; static uint8_t PulseWidth; @@ -640,7 +647,7 @@ static uint8_t OldStep2NewStep(uint8_t OldStep); static uint8_t OldStep2NewStepTime(uint8_t StepTime); static uint8_t IVdone = 0; -static uint16_t IVCurve(); +static uint16_t OneWayVoltScan(); static void ramp_test(); static uint16_t DPVCurve(); static uint16_t CVCurve(); 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 4f7db4150..4dedc94e8 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 @@ -24,7 +24,7 @@ static void SimpleBLEPeripheral_performPeriodicTask(); static void SimpleBLEPeripheral_clockHandler(UArg arg) { // Store the event. - // events |= SBP_PERIODIC_EVT; +// events |= SBP_PERIODIC_EVT; // Wake up the application. Semaphore_post(semaphore); // send samaphore to jump out of infinite waiting(simple_peripheral.c line570) @@ -52,28 +52,6 @@ static void ZM_init() { static void ZM_update_instruction_callback(uint8_t ins_type, uint8_t chip_ID, uint8_t *ins) {} -static uint16_t VoltScan() { - uint16_t Voltage; - if (INSTRUCTION.VoltOrigin == INSTRUCTION.VoltFinal) { - // DAC_outputV(DACOUT, INSTRUCTION.VoltOrigin); //delete 'command' parameter - DAC_outputV(INSTRUCTION.VoltOrigin); - PeriodicEvent = false; - return INSTRUCTION.VoltOrigin; - } else if (INSTRUCTION.eliteFxn == SQUARE_WAVE_VOLTAMMETRY) { - Voltage = SWVCurve(); - } else if (INSTRUCTION.eliteFxn == DIFFERENTIAL_PULSE_VOLTAMMETRY) { - Voltage = DPVCurve(); - } else if (INSTRUCTION.eliteFxn == CYCLIC_VOLTAMMETRY) { - Voltage = CVCurve(); - } - - // IV plot mode - else { - Voltage = IVCurve(); - } - - return Voltage; -} static void DACCode2Real2Notify(uint16_t DACcode) { int32_t RealV; @@ -85,61 +63,6 @@ static void DACCode2Real2Notify(uint16_t DACcode) { NotifyVolt[3] = (uint8_t)(RealV & 0x000000FF); } -// output a certain voltage e.g. 2v -// and measure the input voltage -// => calculate the resister -// change the output voltage step -// => get a R-T curve (with resolution = 1 sample/volt step ) -static void ZT_Plot() { - // read ADC current - int32_t Real_Current = 0; - ADCGainControl(INSTRUCTION.ADCGainLevel); - ADCChannelSelect(ADC_CH_CURRENT); - CPUdelay(10); - ADC_read(spi_ADC_rxbuf); - - // check if ADC over/under flow - ADC_overflow(INSTRUCTION.ADCGainLevel, spi_ADC_rxbuf); - - // decode ADC value and put it into notify buffer - Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf); - - Impedance_Calculate(INSTRUCTION.VoltConstant, Real_Current); - -} - - -static void VT_Plot() { - // ADC gain is don't care when measuring voltage - uint8_t ADCGain = 1; - - // read ADC volt - ADCChannelSelect(ADC_CH_VOLT); - CPUdelay(10); - ADC_read(spi_ADC_rxbuf); - - // decode ADC value and put it into notify buffer - DecodeADCValue(ADCGain, ADC_CH_VOLT, spi_ADC_rxbuf); -} - -static int32_t IT_Plot() { - // read ADC current - int32_t Real_Current = 0; - ADCGainControl(INSTRUCTION.ADCGainLevel); - ADCChannelSelect(ADC_CH_CURRENT); - CPUdelay(10); - ADC_read(spi_ADC_rxbuf); - - // check if ADC over/under flow - // let the output saturate if over/under flow - ADC_overflow(INSTRUCTION.ADCGainLevel, spi_ADC_rxbuf); - - // decode ADC value and put it into notify buffer - Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf); - - return Real_Current; -} - #define IsPeriodicMode() ( \ (INSTRUCTION.eliteFxn == IV_CURVE) || \ (INSTRUCTION.eliteFxn == IT_CURVE) || \ @@ -148,6 +71,15 @@ static int32_t IT_Plot() { (INSTRUCTION.eliteFxn == CONSTANT_CURRENT) \ ) +/********************************************************************* + * @fn SimpleBLEPeripheral_performPeriodicTask + * + * @brief Control periodic event such as DAC out, ADC read, and send notify. + * + * @param None. + * + * @return None. + */ static void SimpleBLEPeripheral_performPeriodicTask() { if ( IsPeriodicMode() ){ if (StepTimeCounter == INSTRUCTION.StepTime){ @@ -164,6 +96,11 @@ static void SimpleBLEPeripheral_performPeriodicTask() { SampleRate_counter++; } + /** Periodic Event **/ + // Default working mode is DAC out -> ADC read -> send notify + // We will need a flag to control DAC, if we want to exchange to ADC -> DAC -> notify + // This flag can be named by FxnNameReset + // In IV, CV, and func-gen mode, DAC will output voltage // else DAC do nothing. EliteDACControl(); @@ -194,8 +131,6 @@ static void EliteADCControl() { if (SampleRate_counter == INSTRUCTION.SampleRate) { switch (INSTRUCTION.eliteFxn) { case IV_CURVE:{ -// LED_color(DARKLED, 0, 0, 255); -// LED_color(DARKLED, 0, 0, 125); IT_Plot(); break; } @@ -228,11 +163,9 @@ static void EliteNotifyControl() { // output the last notify, and reset Elite if (!PeriodicEvent) { SendNotify(); -// LED_color(DARKLED, 0xFF, 0x00, 0x00); reset(); } else if (StepTimeCounter == INSTRUCTION.StepTime - 1) { SendNotify(); -// LED_color(DARKLED, 0xFF, 0x00, 0x00); } }