Separate out EIS voltage set to DAC_outputV()

This commit is contained in:
Taylor Liao
2021-08-04 23:58:15 +08:00
parent bd96102ec2
commit 96d94f79b7
4 changed files with 74 additions and 62 deletions
@@ -60,12 +60,34 @@ static bool DACReset;
#define AD5940_SYS_CLOCK 16000000
#define Cutoff_Freq 250000
static uint32_t DAC_outputV(uint32_t voltLV) {
#define VBIAS_LSB 107422 // 2200/4096 [mV] = 107422 [5nV]
#define VZERO_LSB 6875008 //VBIAS_LSB * 64
#define DAC12BIT_LSB 107422
struct eis_dac_volt {
uint32_t vb;
uint32_t vz;
uint32_t vzcode;
uint32_t vbcode;
uint32_t DACOutCode;
} eis_dac_volt = {0};
static void DAC_outputV(int32_t voltLV) {
static int32_t vztemp;
vztemp = (-0.45 * voltLV) + 249000000;
if (voltLV < 0) {
vztemp -= DAC12BIT_LSB;
}
eis_dac_volt.vzcode = (vztemp - 40000000 + VZERO_LSB / 2) / VZERO_LSB;
eis_dac_volt.vz = eis_dac_volt.vzcode * VZERO_LSB + 40000000;
eis_dac_volt.vb = voltLV + eis_dac_volt.vz;
eis_dac_volt.vbcode = ((eis_dac_volt.vb - 40000000 + VBIAS_LSB / 2) / VBIAS_LSB);
eis_dac_volt.DACOutCode = (0x0003FFFF & ((eis_dac_volt.vzcode << 12) + eis_dac_volt.vbcode));
select_REG(0x2120);
w32_REG(voltLV);
return voltLV;
w32_REG(eis_dac_volt.DACOutCode);
}
static uint32_t DAC_outputF(uint32_t freq) {
@@ -39,37 +39,25 @@ static void freq_out()
return;
}
#define VBIAS_LSB 107422 // 2200/4096 [mV] = 107422 [5nV]
#define VZERO_LSB 6875008 //VBIAS_LSB * 64
#define DAC12BIT_LSB 107422
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)
{
struct wm_cv_ctx_t *cv = (struct wm_cv_ctx_t *)wm_get();
static int32_t vztemp;
void *wm = wm_get();
/* in [5nV] ver */
vztemp = (-0.45 * Vset) + 249000000;
if (Vset < 0) {
vztemp -= DAC12BIT_LSB;
}
eis_cv.vzcode = (vztemp - 40000000 + VZERO_LSB / 2) / VZERO_LSB;
eis_cv.vz = eis_cv.vzcode * VZERO_LSB + 40000000;
eis_cv.vb = Vset + eis_cv.vz;
eis_cv.vbcode = ((eis_cv.vb - 40000000 + VBIAS_LSB / 2) / VBIAS_LSB);
eis_cv.DACOutCode = (0x0003FFFF & ((eis_cv.vzcode << 12) + eis_cv.vbcode));
// vztemp = (-0.45 * Vset) + 249000000;
// if (Vset < 0) {
// vztemp -= DAC12BIT_LSB;
// }
// eis_cv.vzcode = (vztemp - 40000000 + VZERO_LSB / 2) / VZERO_LSB;
// eis_cv.vz = eis_cv.vzcode * VZERO_LSB + 40000000;
//
// eis_cv.vb = Vset + eis_cv.vz;
// eis_cv.vbcode = ((eis_cv.vb - 40000000 + VBIAS_LSB / 2) / VBIAS_LSB);
// eis_cv.DACOutCode = (0x0003FFFF & ((eis_cv.vzcode << 12) + eis_cv.vbcode));
DAC_outputV(eis_cv.DACOutCode);
DAC_outputV(Vset);
if (Vset == cv->_Vinit && cv->bFirst){
Elite_led_color(COLOR_ORANGE);
@@ -478,7 +466,7 @@ static void CV_Plot(void)
ADC_cnt++;
} else if (ADC_cnt == 1) {
vscan = (int32_t)(eis_cv.vb - eis_cv.vz) / 200;
vscan = (int32_t)(eis_dac_volt.vb - eis_dac_volt.vz) / 200;
ADC_cnt++;
} else if (ADC_cnt == 2) {
@@ -678,7 +678,7 @@ static void setEIS_EIS (void)
w32_REG(0b111111); //0b101011
select_REG(DE0RESCON);
w32_REG(0x000000FF);
w32_REG(0x00000000); // 10Ohm
select_REG(HSTIACON);
w32_REG(0x00000000);
@@ -687,7 +687,8 @@ static void setEIS_EIS (void)
select_REG(DFTCON); //20D0
w32_REG(0x001000C1);
select_REG(SWCON); //200C
w32_REG(0x00026305); //AIN2 short to 1.11V
w32_REG(0x00026355); //D5 | P5 | N3 | T6 | T9 0b010 0110 0011 0101 0101
// w32_REG(0x00026305); //AIN2 short to 1.11V
// w32_REG(0x00026905); //0b010 0110 1001 0000 0101
select_REG(AFECON); //2000
@@ -1384,14 +1385,15 @@ static void update_ZM_instruction(uint8 *ins) {
// select_REG(LPDACDAT0); //2120 //output Vout
// w32_REG(0x00000799); //bias
// select_REG(DE0RESCON); //20F8 //DE0's gain
// w32_REG(0x00000068);
select_REG(DE0RESCON); //20F8 //DE0's gain
w32_REG(0x000000FF);
select_REG(ADCCON); //21A8
w32_REG(0x00000101); //HSTIA_P | HSTIA_N
select_REG(DFTCON); //20D0
w32_REG(0x001000C1);
select_REG(SWCON); //200C
w32_REG(0x00026305);
w32_REG(0x00026355); //D5 | P5 | N3 | T6 | T9 0b010 0110 0011 0101 0101
// w32_REG(0x00026305);
// w32_REG(0x00026905); //0b0100110100100000101
select_REG(WGFCW); //2030
w32_REG(0x00333333); //SINEFCW/2^30 * 16 MHz
@@ -129,7 +129,7 @@ static void SimpleBLEPeripheral_performPeriodicTask(void) {
// Default working flow is vscan -> ADC read -> send notify
// We will need a flag to control vscan, ADC and notify
// static bool first_highz_flag = false;
static bool first_highz_flag = false;
GPT.DeltaGptimerCounter = GPT.GptimerCounter - GPT.GptimerCounter0;
GPT.GptimerCounter0 = GPT.GptimerCounter;
@@ -142,7 +142,7 @@ static void SimpleBLEPeripheral_performPeriodicTask(void) {
record_flag = true;
firstTimeReset = true;
notifyFirst_flag = true;
// first_highz_flag = true;
first_highz_flag = true;
I_GAIN_100R_counter = 0;
I_GAIN_3K_counter = 0;
I_GAIN_100K_counter = 0;
@@ -162,38 +162,38 @@ static void SimpleBLEPeripheral_performPeriodicTask(void) {
VoutGainControl(instru.VoutGainLevel);
*/
// if (Ve1MatchVe2Mode()) {
// if (instru.eliteFxn == CURVE_EIS){
// if (instru.f1 == instru.f2) {
// DAC_outputF(instru.f1);
// PeriodicEvent = false;
// ModeLED(NO_EVENT);
// }
// } else {
// if (instru.Ve1 == instru.Ve2) {
//// DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLevel, instru.Ve1));
// DAC_outputV(instru.Ve1);
// PeriodicEvent = false;
// SetEISHIGHZ(1):
// // PIN_setOutputValue(pin_handle, HIGH_Z_MODE, 0); // 0: open highz;
// ModeLED(NO_EVENT);
// }
// }
// }
if (Ve1MatchVe2Mode()) {
if (instru.eliteFxn == CURVE_EIS){
if (instru.f1 == instru.f2) {
DAC_outputF(instru.f1);
PeriodicEvent = false;
ModeLED(NO_EVENT);
}
} else {
if (instru.Ve1 == instru.Ve2) {
// DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLevel, instru.Ve1));
DAC_outputV(instru.Ve1);
PeriodicEvent = false;
SetEISHIGHZ(1);
// PIN_setOutputValue(pin_handle, HIGH_Z_MODE, 0); // 0: open highz;
ModeLED(NO_EVENT);
}
}
}
}
GPT.LeadTimeCounter = GPT.LeadTimeCounter + GPT.DeltaGptimerCounter;
if (leadTimeReset && GPT.LeadTimeCounter <= 2000) {
vscanReset = true;
// if (first_highz_flag && GPT.LeadTimeCounter >= 1000) {
// if (instru.eliteFxn == CURVE_OCP) {
// PIN_setOutputValue(pin_handle, HIGH_Z_MODE, 0);
// } else {
// SetEISHIGHZ(1); // // High Z | 1 off | 0 on
//// PIN_setOutputValue(pin_handle, HIGH_Z_MODE, 1); // HIGH Z MODE // 1: close; 0: open;
// }
// first_highz_flag = false;
// }
if (first_highz_flag && GPT.LeadTimeCounter >= 1000) {
if (instru.eliteFxn == CURVE_OCP) {
PIN_setOutputValue(pin_handle, HIGH_Z_MODE, 0);
} else {
SetEISHIGHZ(1); // // High Z | 1 off | 0 on
// PIN_setOutputValue(pin_handle, HIGH_Z_MODE, 1); // HIGH Z MODE // 1: close; 0: open;
}
first_highz_flag = false;
}
} else {
if (notifyFirst_flag) {
GPT.NotifyCounter = instru.notifyRate - 20;