From 5f3e5bbd6b10fbc1ffcac90fceb130fcce4c5e82 Mon Sep 17 00:00:00 2001 From: Taylor Liao Date: Wed, 28 Jul 2021 22:56:34 +0800 Subject: [PATCH] Adding EliteEISMode.h --- .../cc26xx/app/headstage/EliteADC.h | 12 +-- .../cc26xx/app/headstage/EliteEISMode.h | 87 +++++++++++++++++++ .../cc26xx/app/headstage/Elite_mode_ADC_DAC.h | 21 ++--- .../cc26xx/app/headstage/headstage.h | 4 +- .../cc26xx/app/headstage/impedance_meter.h | 5 +- 5 files changed, 104 insertions(+), 25 deletions(-) create mode 100644 simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteEISMode.h diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteADC.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteADC.h index af9dd240c..2d5cd071c 100644 --- a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteADC.h +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteADC.h @@ -701,15 +701,15 @@ static int32_t read_correct_Iin(){ dftdat = neg_18bit(ReadRealZ()) + 4140; if (instru.ADCGainLv == 0) { - Iin = -(dftdat * 1000 + 256) / 512.1 / 0.033; + Iin = -(0.867 * dftdat * 1000 + 256) / 512.1 / 0.033; // res = rawIin / 0.033; } else if (instru.ADCGainLv == 1) { - Iin = - (dftdat * 1000 + 6)/ 12.1 / 1.75; + Iin = - ((dftdat + dftdat * 0.086) * 1000 + 6)/ 12.1 / 1.75; // res = rawIin / 1.75; } else if (instru.ADCGainLv == 2) { - Iin = - (dftdat * 1000 + 2) / 4.1 / 5.43; + Iin = - ((dftdat + dftdat * 0.04) * 1000 + 2) / 4.1 / 5.43; // res = rawIin / 5.43; } else if (instru.ADCGainLv == 3 || instru.ADCGainLv == 4) { @@ -717,9 +717,9 @@ static int32_t read_correct_Iin(){ // Iin = rawIin / 0.102; } - InputNotify(NOTIFY_VOLT, dftdat); - InputNotify(NOTIFY_CURRENT, Iin); - InputNotify(NOTIFY_IMPEDANCE, instru.ADCGainLv); +// InputNotify(NOTIFY_VOLT, dftdat); +// InputNotify(NOTIFY_CURRENT, Iin); +// InputNotify(NOTIFY_IMPEDANCE, instru.ADCGainLv); return Iin; } diff --git a/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteEISMode.h b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteEISMode.h new file mode 100644 index 000000000..4756d9e42 --- /dev/null +++ b/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteEISMode.h @@ -0,0 +1,87 @@ + +#ifndef ELITEEIS +#define ELITEEIS + +#define fset instru.fset + +static void SweepNext(void) //0: log | 1: linear +{ + struct wm_eis_ctx_t *eis = (struct wm_eis_ctx_t *)wm_get(); + + if(eis->_direction_up) { + if(eis->_decadeIndex < eis->_decades && eis->_sweepIndex == 0) { + eis->_fd1 = instru.f1 * pow(10, eis->_decadeIndex); + eis->_fd2 = instru.f1 * pow(10, eis->_decadeIndex + 1); + } + + if(instru.scale == 0) { // logarithm + fset = eis->_fd1 * pow(10, eis->_sweepIndex * (1 / (eis->_ppd - 1))); + } + else if (instru.scale == 1) { // linear + fset = eis->_fd1 + eis->_sweepIndex * ((eis->_fd2 - eis->_fd1) / (eis->_ppd - 1)); + } + + + } else { //reverse + + if(eis->_decadeIndex < eis->_decades && eis->_sweepIndex == 0) { + eis->_fd1 = instru.f1 * pow(10, -eis->_decadeIndex); + eis->_fd2 = instru.f1 * pow(10, -(eis->_decadeIndex + 1)); + } + + if(instru.scale == 0) { // logarithm + fset = eis->_fd1 * pow(10, - (eis->_sweepIndex * (1 / (eis->_ppd - 1)))); + } + else if(instru.scale == 1) { // linear + fset = eis->_fd1 + eis->_sweepIndex * ((eis->_fd2 - eis->_fd1) / (eis->_ppd - 1)); + } + + } + + if(++eis->_sweepIndex == eis->_ppd) { + eis->_sweepIndex = 0; + eis->_decadeIndex ++; + } + +/////////////////////////////////////////// Under Construction ///////////////////////////////////////////////////////////// + +// if(eis->_decadeIndex == eis->_decades) { +// +// +// } + + +} + +static void eis_fscan(void) +{ + struct wm_eis_ctx_t *eis = (struct wm_eis_ctx_t *)wm_get(); + + if (vscanReset) { + if (instru.directionInit == 1) { + eis->_direction_up = true; + } else if (instru.directionInit == 0) { + eis->_direction_up = false; + } + + SetDACBias(instru.dcbias); + SetWGAmp(instru.acamp); + SetAVG(instru.avgnum); + + eis->_decades = CalcDecade(instru.f1, instru.f2); + + fset = instru.f1; + } + + if (!vscanReset) { + + SweepNext(); + + //stop condition + if (fset >= eis->_fmax || fset <= eis->_fmin) { + PeriodicEvent = false; + } + } +} + +#endif 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 2c8eeb22e..dabdbd5c0 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 @@ -445,7 +445,6 @@ static void Iin_Vin_Vout_Plot(void) static void CV_Plot(void) { struct wm_cv_ctx_t *cv = (struct wm_cv_ctx_t *)wm_get(); -// struct wm_meas_t *m = &cv->measure; static uint8_t ADC_cnt = 0; static int32_t vscan, rawIin, Iin, dftdat; void *wm = wm_get(); @@ -457,33 +456,30 @@ static void CV_Plot(void) } else if (ADC_cnt == 1) { vscan = (int32_t)(eis_cv.vb - eis_cv.vz) / 200; - ADC_cnt++; } else if (ADC_cnt == 2) { -// dftdat = neg_18bit(ReadRealZ()); - ADC_cnt++; } else if (ADC_cnt == 3) { read_Iin_change_gain(); -// rawIin = - dftdat * 1000 / 210;//(RtiaTable[instru.ADCGainLv]); //nA ADC_cnt++; } else if (ADC_cnt == 4) { ADC_cnt++; } else if (ADC_cnt == 5) { -// m->_measureCurrent = correct_Iin(rawIin); ADC_cnt = 0; } -// InputNotify(NOTIFY_VOLT, dftdat); -// InputNotify(NOTIFY_CURRENT, rawIin); -// InputNotify(NOTIFY_IMPEDANCE, instru.ADCGainLv); + InputNotify(NOTIFY_VOLT, vscan); + InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm)); + InputNotify(NOTIFY_IMPEDANCE, instru.ADCGainLv); return; } -static void CC_Plot(void) //real and imag impedance plot (unfixed) +//////EIS PLOT FUNCTION START////// + +static void CC_Plot(void) //real and imag impedance plot (incorrect values) { static uint8_t ADC_cnt = 0; void *wm = wm_get(); @@ -515,10 +511,7 @@ static void CC_Plot(void) //real and imag impedance plot (unfixed) return; } - -//////EIS PLOT FUNCTION START////// - -static void Nyquist_Plot(void) +static void Nyquist_Plot(void) //real and imag plot (corrected values but not good) { static uint8_t ADC_cnt = 0; static int8_t phase_cnt = 0; 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 8b7e6a2b5..85aeb6e5d 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 @@ -1343,14 +1343,14 @@ static void update_ZM_instruction(uint8 *ins) { select_REG(LPDACCON0); //2128 //DC on w32_REG(0b0000001); select_REG(LPDACSW0); //2124 //operation - w32_REG(0b101011); + w32_REG(0b101011); //0b111111 select_REG(LPDACDAT0); //2120 //output Vout w32_REG(0x00000799); //bias select_REG(DE0RESCON); //20F8 //DE0's gain w32_REG(0x00000068); select_REG(ADCCON); //21A8 - w32_REG(0x00000101); + w32_REG(0x00000101); //HSTIA_P | HSTIA_N select_REG(DFTCON); //20D0 w32_REG(0x001000C1); select_REG(SWCON); //200C 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 ab5ceeba6..71b0b8fc3 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 @@ -198,8 +198,7 @@ static void SimpleBLEPeripheral_performPeriodicTask(void) { GPT.VscanRateCounter -= instru.VsetRate * GPT.GptimerMultiple; //To get right time vscan_flag = true; if (vscan_flag) { - vscan_ctrl(); // to iv_vscan => Vset = iv->_Vinit; Vset = Vset + iv->_Vstep; - // cv_vscan + vscan_ctrl(); // vset vscan_flag = false; } } @@ -223,7 +222,7 @@ static void SimpleBLEPeripheral_performPeriodicTask(void) { GPT.SampleRateCounter = 0; //To get right data, ADC must be delay 1.5ms ADC_flag = true; if(ADC_flag){ - EliteADCControl(); //CC_Plot //CV_Plot + EliteADCControl(); //read data ADC_flag = false; } }