Adding EliteEISMode.h

This commit is contained in:
Taylor Liao
2021-07-28 22:56:34 +08:00
parent d379f0b5f7
commit 5f3e5bbd6b
5 changed files with 104 additions and 25 deletions
@@ -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;
}
@@ -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
@@ -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;
@@ -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
@@ -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;
}
}