Current surge at -2V

This commit is contained in:
Taylor Liao
2021-07-20 09:41:02 +08:00
parent 5093fb354f
commit 540a53e917
6 changed files with 122 additions and 82 deletions
@@ -96,7 +96,7 @@ static void cv_vscan(void)
// cv->_Vstep = instru.step / 5 * instru.VsetRate;
// }
if (instru.step < 100) { //for EIS not having the voltage resolution like EDC 1mV at a time
if (instru.step < 100) { //for EIS not having the voltage resolution like EDC, 1mV at a time
instru.step = 100;
}
@@ -127,9 +127,9 @@ static void cv_vscan(void)
(instru.Vinit > instru.Ve1 && instru.Vinit > instru.Ve2)
) {
if (cv->_current_direction_up) {
Vset = Vset + cv->_Vstep;// * GPT.GptimerMultiple;
Vset = Vset + cv->_Vstep; //* GPT.GptimerMultiple;
} else {
Vset = Vset - cv->_Vstep;// * GPT.GptimerMultiple;
Vset = Vset - cv->_Vstep; //* GPT.GptimerMultiple;
}
if (instru.Vinit < instru.Ve1 && instru.Vinit < instru.Ve2) {
@@ -19,6 +19,19 @@
bool _current_direction_up; \
uint16_t _cycleNumber
//#define FOUT_PARA \
// uint16_t f0; \
// uint16_t f1; \
// uint16_t f2; \
// uint16_t fmax; \
// uint16_t fmin; \
// uint16_t bias; \
// uint16_t acamp; \
// uint16_t avgnum; \
// uint16_t rtia; \
// uint16_t ppd; \
// uint8_t scale;
#define MEAS_CURR(_m) (((struct wm_meas_t *)(_m))->_measureCurrent)
#define MEAS_VIN(_m) (((struct wm_meas_t *)(_m))->_measureVin)
#define MEAS_VOUT(_m) (((struct wm_meas_t *)(_m))->_measureVout)
@@ -34,6 +47,25 @@ struct wm_meas_t {
};
/* member of mode */
//struct wm_eisz_ctx_t {
// struct wm_meas_t measure;
// FOUT_PARA;
//}
//struct wm_eis_cv_ctx_t {
// struct wm_meas_t measure;
// uint32_t vb;
// uint32_t vz;
// uint32_t vzcode;
// uint32_t vbcode;
// uint32_t DACOutCode;
// uint32_t VBIAS_LSB;
// uint32_t VZERO_LSB;
// Uint16_t DAC12BIT_LSB;
// uint16_t Vmid;
// bool bFirst;
//}
struct wm_vo_ctx_t {
/* WARNING: please keep MEASURE at first!! */
struct wm_meas_t measure;
@@ -84,6 +116,7 @@ struct wm_cv_ctx_t {
/* WARNING: please keep MEASURE at first!! */
struct wm_meas_t measure;
VOUT_PARA;
bool bFirst;
};
struct wm_lsv_ctx_t {
@@ -141,6 +174,34 @@ static void *workMode_p = NULL;
static bool Free_Work_Mode = false;
/* init mode func */
//static int __eis_cv_create(void)
//{
// struct wm_meas_t *m;
// struct wm_eis_cv_ctx_t *p;
// void **wm = &workMode_p;
//
// p = malloc(sizeof(struct wm_eis_cv_ctx_t));
// if (!p) return -1;
//
// m = (struct wm_meas_t *)p;
// m->_measureCurrent = 0;
// m->_measureVin = 0;
// m->_measureVout = 0;
// m->_measureBat = 0;
// m->_VoViSwitch = instru.VoViSwitch;
//
// p->vb = 0;
// p->vz = 0;
// p->vzcode = 0;
// p->vbcode = 0;
// p->DACOutCode = 0;
// p->VBIAS_LSB = 2200000/4096; //uV
// p->VZERO_LSB = VBIAS_LSB * 64; //uV
// p->DAC12BIT_LSB = 537; //uV
// p->Vmid = 1300000; //uV
// p->bFirst = true;
//}
static int __vo_create(void)
{
struct wm_meas_t *m;
@@ -340,6 +401,7 @@ static int __cv_create(void)
p->_Vmin = (instru.Vmin - 25000) * 2 / 25; //(instru.Vmin - 25000) * 4 * 10000; //[5nV]
p->_Vset = 0;
p->_Vstep = 0;
p->bFirst = true;
p->_direction_up = true;
p->_current_direction_up = true;
p->_cycleNumber = instru.cycleNumber;
@@ -33,7 +33,7 @@ enum all_mode_e {
CURVE_LSV = 0x0A, // Linear Sweep Voltammetry (LSV) //0x02,
CURVE_CA = 0x0B, // Chronoamperometric Graph (CA) //0x03,
CURVE_PULSE = 0x0C, //0x94,
CURVE_EIS = 0x10,
CURVE_EIS = 0x10, //Should Change to 0xD1
CURVE_CALI_DAC = 0xF0, //0x93,
@@ -53,57 +53,47 @@ static void freq_out()
return;
}
#define VBIAS_LSB (2200f/4096) //mV
#define VZERO_LSB (DAC12BIT_LSB * 64) //mV
#define DAC12BIT_LSB 0.537 //mV
#define Vmid 32 * VZERO_LSB + 200 //mV
#define VBIAS_LSB (2200000/4096) //uV
#define VZERO_LSB (VBIAS_LSB * 64) //uV
#define DAC12BIT_LSB 537 //uV
#define Vmid 32 * VZERO_LSB //uV
struct eis_cv {
uint32_t vb;
uint32_t vz;
uint32_t vzcode;
uint32_t vbcode;
uint32_t DACOutCode;
} eis_cv = {0};
static void vscan_volt_out(void)
{
static uint16_t vb, vz, vbcode, vzcode;
static uint32_t DACOutCode;
struct wm_cv_ctx_t *cv = (struct wm_cv_ctx_t *)wm_get();
static uint32_t vztemp;
void *wm = wm_get();
// vzcode = (Vmid - Vset / 2) + 0.5;
// vz = vzcode * VZERO_LSB;
//
// if (Vset < 0) {
// vz -= DAC12BIT_LSB;
// }
//
// vb = Vset + vz;
//
// vbcode = (vb / VBIAS_LSB) + 0.5;
//
// DACOutCode = (0x0003FFFF & ((vzcode << 12) + vbcode));
// }
//
// DAC_outputV(DACOutCode);
// return;
vztemp = (Vmid - Vset * 500) + 0.5;
eis_cv.vzcode = vztemp / VZERO_LSB + 0.5;// (vztemp - 200000) / VZERO_LSB + 0.5;
eis_cv.vz = eis_cv.vzcode * VZERO_LSB + 0.5; //eis_cv.vzcode * VZERO_LSB + 200000 + 0.5;
if (Vset == cv->_Vinit && cv->bFirst){
Elite_led_color(COLOR_ORANGE);
CPUdelay(30000);
Elite_led_color(COLOR_CYAN);
}
vz = 200; //0.2V
vbcode = 0;
vzcode = 0;
if (Vset < 0) {
vz = 2200; // 2.2V
vzcode = 59;
vbcode = 52;
} else if (Vset == 0) {
DACOutCode = 0x00006180;
eis_cv.vz = eis_cv.vz - DAC12BIT_LSB + 0.5;
}
if (Vset != 0) {
vb = Vset + vz;
eis_cv.vb = (Vset * 1000) + (eis_cv.vzcode * VZERO_LSB + 0.5);// + 200000;
eis_cv.vbcode = (eis_cv.vb / VBIAS_LSB) + 0.5;
eis_cv.DACOutCode = (0x0003FFFF & ((eis_cv.vzcode << 12) + eis_cv.vbcode));
vbcode += (uint32_t)((vb - 200) * 1000 / 537);
// InputNotify(NOTIFY_CURRENT, eis_cv.vb);
// InputNotify(NOTIFY_VOLT, eis_cv.vz);
// InputNotify(NOTIFY_IMPEDANCE, eis_cv.DACOutCode);
if (vbcode < (vzcode * 64)) {
vbcode -= 1;
}
DACOutCode = (0x0003FFFF & ((vzcode << 12) + vbcode));
}
DAC_outputV(DACOutCode);
DAC_outputV(eis_cv.DACOutCode);
return;
// void *wm = wm_get();
@@ -152,8 +142,12 @@ static void CalcuResistance()
static int32_t neg_18bit(int32_t ret)
{
if (ret > 131072) {
ret = ret - 262144;
// if (ret > 131072) {
// ret = ret - 262144;
// }
ret &= 0x3FFFF;
if (ret & (1 << 17)) {
ret |= 0xFFFC0000;
}
return ret;
@@ -457,50 +451,35 @@ static void CV_Plot(void)
{
struct wm_cv_ctx_t *cv = (struct wm_cv_ctx_t *)wm_get();
static uint8_t ADC_cnt = 0;
static uint32_t vbcode, vzcode, vb, vz, DACoutCode;
static int32_t Iin, vscan, mea_vscan;
static uint32_t VSE, VRE;
void *wm = wm_get();
if (ADC_cnt == 0) {
//read_Iin_change_gain();
DACenable(AFTER_READ_V);
// select_REG(0x21A8);
// w32_REG(0x00008202); //LPTIA_N | LPTIA_LPFILTER
vscan = (int32_t)(eis_cv.vb - eis_cv.vz); //uA
ADC_cnt++;
} else if (ADC_cnt == 1) {
select_REG(0x2078);
Iin = (int32_t)(neg_18bit(r32_REG()) / -1000);
select_REG(0x21A8);
w32_REG(0x00008202); //LPTIA_N | LPTIA_LPFILTER
ADC_cnt++;
} else if (ADC_cnt == 2) {
// select_REG(0x21A8);
// w32_REG(0x0000880E); //SE0
select_REG(0x2120);
DACoutCode = r32_REG();
select_REG(0x2078);
ADC_cnt++;
} else if (ADC_cnt == 3) {
vzcode = (uint32_t) ((0x0003F000 & DACoutCode) >> 12);
vbcode = (uint32_t) (0x00000FFF & DACoutCode);
// select_REG(0x2074);
// VSE = r32_REG();
Iin = neg_18bit(r32_REG()) * 1000; //uA
ADC_cnt++;
} else if (ADC_cnt == 4) {
vz = (200000 + 34375 * vzcode);
vb = (200000 + 537 * vbcode);
vscan = (int32_t)(vb - vz) / 1000;
// select_REG(0x21A8);
// w32_REG(0x0000081A); //RE0
select_REG(0x21A8);
w32_REG(0x0000021A); //ADCP - VRE0 | ADCN - LPTIA0_N
ADC_cnt++;
} else if (ADC_cnt == 5) {
select_REG(0x21A8);
w32_REG(0x0000009A); //ADCP - VRE0 | ADCN - LPTIA0_N
select_REG(0x2074);
mea_vscan = r32_REG();
ADC_cnt = 0;
@@ -508,8 +487,6 @@ static void CV_Plot(void)
InputNotify(NOTIFY_CURRENT, Iin);
InputNotify(NOTIFY_VOLT, vscan);
InputNotify(NOTIFY_IMPEDANCE, mea_vscan);
return;
}
@@ -877,6 +877,8 @@ static void update_ZM_instruction(uint8 *ins) {
instru.VsetRate = VsetRateTable[instru.VsetRateIndex];//N
instru.cycleNumber = ((uint16_t)(ins[14]) << 8) | (uint16_t)(ins[15]);
// instru.VoutGainLevel = VOUT_GAIN_240K;
ModeLED(WORKING);
}
@@ -1229,7 +1231,7 @@ static void update_ZM_instruction(uint8 *ins) {
select_REG(0x20BC); //HSOSCCON
w32_REG(0x00000000); //switch to 32MHz output
select_REG(0x2044); //ADCFILTERCON
w32_REG(0x0000C0D0); //ADC data rate = 1.6MHz // 16samples to average
w32_REG(0x0000C0D0); //ADC data rate = 1.6MHz // 16 samples to average
select_REG(0x2010); //HSDACCON
w32_REG(0x0000000E); //DAC gain = 2, > 80 kHz
select_REG(0x238C); //ADCBUFCON
@@ -1270,8 +1272,7 @@ static void update_ZM_instruction(uint8 *ins) {
select_REG(0x20E4); //LPTIASW0
w32_REG(0x00003014); //SW12 | SW13 | SW2 | SW4
select_REG(0x20EC); //LPTIACON0
w32_REG(0x0000E058); //RF 1MR | RTIA 200R | Rload 0 | High Current Mode
// w32_REG(0x0000E038); //RF 1MR | RTIA 200R | Rload 0 | High Current Mode
w32_REG(0x0000E038); //RF 1MR | RTIA 200R | Rload 0 | High Current Mode
select_REG(0x2128); //LPDACCON0
w32_REG(0x00000001);
@@ -1283,9 +1284,9 @@ static void update_ZM_instruction(uint8 *ins) {
select_REG(0x21A8); //ADCCON
w32_REG(0x00008202); //LPTIA_N | LPTIA_LPFILTER
select_REG(0x2044); //ADCFILTERCON
w32_REG(0x000100D1); //0b10000000011010001
w32_REG(0x0001A091);
select_REG(0x20D0); //DFTCON
w32_REG(0x000100C1); //Average input for DFT
w32_REG(0x001000C1); //Average input for DFT | dftnum max
//AFE and PWMB
select_REG(0x2000); //AFECON
@@ -624,11 +624,11 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
// if(key != 0){ //detect Elite battery power when no periodic event
// measureBat();
// }
// if(Free_Work_Mode){
// wm_deinit();
// InitEliteInstruction();
// Free_Work_Mode = false;
// }
if(Free_Work_Mode){
wm_deinit();
InitEliteInstruction();
Free_Work_Mode = false;
}
} else {
EliteOn = TurnOnElite(key);
}