new dpv mode v.1
This commit is contained in:
+10
-8
@@ -161,6 +161,9 @@ struct wm_dpv_ctx_t {
|
||||
uint32_t _t_pa[4];
|
||||
int32_t _v_stop;
|
||||
|
||||
uint32_t _t_pulse_min[4];
|
||||
uint32_t _t_pulse_max[4];
|
||||
|
||||
bool _v_direc_init;
|
||||
};
|
||||
|
||||
@@ -581,23 +584,15 @@ static int __dpv_create(void)
|
||||
|
||||
p->_t_pulse[0] = instru.t_pulse[0];
|
||||
p->_t_pulse[1] = instru.t_pulse[1];
|
||||
p->_t_pulse[2] = instru.t_pulse[2];
|
||||
p->_t_pulse[3] = instru.t_pulse[3];
|
||||
|
||||
p->_v_initial[0] = instru.v_initial[0]; //[5nv]
|
||||
p->_v_initial[1] = instru.v_initial[1]; //[5nv]
|
||||
p->_v_initial[2] = instru.v_initial[2]; //[5nv]
|
||||
p->_v_initial[3] = instru.v_initial[3]; //[5nv]
|
||||
|
||||
p->_v_slope[0] = instru.v_slope[0];
|
||||
p->_v_slope[1] = instru.v_slope[1];
|
||||
p->_v_slope[2] = instru.v_slope[2];
|
||||
p->_v_slope[3] = instru.v_slope[3];
|
||||
|
||||
p->_v_step[0] = instru.v_step[0]; //[5nv]
|
||||
p->_v_step[1] = instru.v_step[1]; //[5nv]
|
||||
p->_v_step[2] = instru.v_step[2]; //[5nv]
|
||||
p->_v_step[3] = instru.v_step[3]; //[5nv]
|
||||
|
||||
p->_t_period = 0;
|
||||
|
||||
@@ -609,6 +604,12 @@ static int __dpv_create(void)
|
||||
|
||||
instru.period = p->_t_period;
|
||||
|
||||
p->_t_pulse_min[0] = (instru.t_pulse[0] - 100) * instru.t_pulse_min[0] / 100 + 50;
|
||||
p->_t_pulse_min[1] = (instru.t_pulse[1] - 100) * instru.t_pulse_min[1] / 100 + 50;
|
||||
|
||||
p->_t_pulse_max[0] = (instru.t_pulse[0] - 100) * instru.t_pulse_max[0] / 100 + 50;
|
||||
p->_t_pulse_max[1] = (instru.t_pulse[1] - 100) * instru.t_pulse_max[1] / 100 + 50;
|
||||
|
||||
*wm = p;
|
||||
|
||||
return 0;
|
||||
@@ -696,6 +697,7 @@ int wm_init(void)
|
||||
break;
|
||||
|
||||
case CURVE_DPV:
|
||||
case CURVE_DPV_SMPRATE:
|
||||
if (__dpv_create()) return -2;
|
||||
break;
|
||||
|
||||
|
||||
+1
@@ -35,6 +35,7 @@ enum all_mode_e {
|
||||
CURVE_PULSE = 0x0C, //0x94,
|
||||
CURVE_UNI_PULSE = 0x0D, // universal pulse
|
||||
CURVE_DPV = 0x0E,
|
||||
CURVE_DPV_SMPRATE = 0x0F,
|
||||
|
||||
CURVE_CALI_ADC = 0xF1, // Cali ADC - test //0x92,
|
||||
|
||||
|
||||
+61
-1
@@ -105,6 +105,7 @@ static void DACenable(uint8_t afterRead){
|
||||
case CURVE_CA:
|
||||
case CURVE_LSV:
|
||||
case CURVE_DPV:
|
||||
case CURVE_DPV_SMPRATE:
|
||||
vscan_volt_out();
|
||||
break;
|
||||
|
||||
@@ -255,10 +256,64 @@ void EliteCalcAvg(uint32_t time)
|
||||
return;
|
||||
}
|
||||
|
||||
static void Iin_Vin_Vout_Plot(void)
|
||||
void dpv_EliteCalcAvg(uint32_t time)
|
||||
{
|
||||
struct wm_dpv_ctx_t *p = (struct wm_dpv_ctx_t *)wm_get();
|
||||
struct wm_meas_t *meas = &p->measure;
|
||||
static uint32_t cnt = 0;
|
||||
static int64_t curr_sum = 0;
|
||||
int64_t curr_avg = 0;
|
||||
uint32_t m;
|
||||
uint32_t t = time;
|
||||
|
||||
m = t % p->_t_period;
|
||||
static bool first_v_rec = true;
|
||||
|
||||
if (calc_avg_en) {
|
||||
cnt++;
|
||||
curr_sum = curr_sum + meas->_measureCurrent;
|
||||
if (first_v_rec) {
|
||||
InputNotify(NOTIFY_VOLT, instru.Vout/200 - meas->_measureVin);
|
||||
InputNotify(NOTIFY_IMPEDANCE, instru.Vout/200);
|
||||
first_v_rec = false;
|
||||
}
|
||||
|
||||
} else {
|
||||
first_v_rec = true;
|
||||
curr_avg = curr_sum / cnt;
|
||||
if (cnt == 0) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (m < p->_t_pa[0]) {
|
||||
InputNotify(NOTIFY_CURRENT, curr_avg);
|
||||
SendNotify();
|
||||
|
||||
} else if (m < p->_t_pa[1]) {
|
||||
InputNotify(NOTIFY_CURRENT, curr_avg);
|
||||
SendNotify();
|
||||
|
||||
} else if (m < p->_t_pa[2]) {
|
||||
|
||||
} else if (m < p->_t_pa[3]) {
|
||||
|
||||
}
|
||||
|
||||
cnt = 0;
|
||||
curr_sum = 0;
|
||||
curr_avg = 0;
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void Iin_Vin_Vout_Plot(uint32_t time)
|
||||
{
|
||||
static uint8_t ADC_cnt = 0;
|
||||
void *wm = wm_get();
|
||||
uint32_t t = time;
|
||||
|
||||
/* the time for measuring battery */
|
||||
if (batteryCheck_flag && tempCheck_flag) {
|
||||
@@ -284,6 +339,11 @@ static void Iin_Vin_Vout_Plot(void)
|
||||
*/
|
||||
if (ADC_cnt == 0) {
|
||||
read_Iin_change_gain(IIN_VIN_VOUT_PLOT);
|
||||
|
||||
if (instru.eliteFxn == CURVE_DPV && vscanReset == false) {
|
||||
dpv_EliteCalcAvg(t);
|
||||
}
|
||||
|
||||
DACenable(AFTER_READ_I);
|
||||
ADC_cnt++;
|
||||
|
||||
|
||||
+3
-3
@@ -4,9 +4,9 @@
|
||||
|
||||
#define VERSION_DATE_YEAR 21
|
||||
#define VERSION_DATE_MONTH 10
|
||||
#define VERSION_DATE_DAY 26
|
||||
#define VERSION_DATE_HOUR 13
|
||||
#define VERSION_DATE_MINUTE 19
|
||||
#define VERSION_DATE_DAY 29
|
||||
#define VERSION_DATE_HOUR 19
|
||||
#define VERSION_DATE_MINUTE 1
|
||||
|
||||
// this is NOT the version hash !!
|
||||
// it's the last version hash
|
||||
|
||||
+26
-18
@@ -1092,6 +1092,8 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
* +----------+---------------+-----------------+-------------------------+
|
||||
*
|
||||
*/
|
||||
static uint8_t dpv_option;
|
||||
|
||||
//--Auto
|
||||
static int32_t dpv_e_init;
|
||||
static int32_t dpv_e_final;
|
||||
@@ -1104,15 +1106,13 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
//--advanced
|
||||
static int32_t dpv_e_1;
|
||||
static int32_t dpv_e_2;
|
||||
static uint8_t dpv_curr_rec;
|
||||
static uint8_t dpv_pulse_option;
|
||||
static uint32_t dpv_curr_rec_percent_min[4];
|
||||
static uint32_t dpv_curr_rec_percent_max[4];
|
||||
|
||||
//--engineering
|
||||
static uint8_t dpv_engi_advanced_en;
|
||||
|
||||
|
||||
// 340E0E01 4E20 7530 6225 00000032 61C1
|
||||
//
|
||||
// 340D0E02000001F403E888B83A9819
|
||||
//
|
||||
// 34020EFF
|
||||
if (ins[3] == PARA_1) {
|
||||
dpv_e_init = (int32_t)ins[4] << 8 | (int32_t)ins[5];
|
||||
dpv_e_final = (int32_t)ins[6] << 8 | (int32_t)ins[7];
|
||||
@@ -1125,7 +1125,15 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
dpv_notify_rate = (uint32_t)ins[8] << 8 | (uint32_t)ins[9];
|
||||
dpv_e_1 = (int32_t)ins[10] << 8 | (int32_t)ins[11];
|
||||
dpv_e_2 = (int32_t)ins[12] << 8 | (int32_t)ins[13];
|
||||
dpv_curr_rec = (uint8_t)ins[14];
|
||||
dpv_curr_rec_percent_min[0] = (uint32_t)ins[14];
|
||||
dpv_curr_rec_percent_max[0] = ins[15];
|
||||
dpv_curr_rec_percent_min[1] = (uint32_t)ins[14];
|
||||
dpv_curr_rec_percent_max[1] = ins[15];
|
||||
dpv_pulse_option = ins[16];
|
||||
|
||||
} else if (ins[3] == PARA_3) {
|
||||
dpv_option = ins[4];
|
||||
dpv_engi_advanced_en = ins[5];
|
||||
|
||||
} else if (ins[3] == PARA_FINAL) {
|
||||
dpv_e_init = UC_TO_5NV(dpv_e_init);
|
||||
@@ -1138,15 +1146,6 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
dpv_e_1 = UC_TO_5NV(dpv_e_1);
|
||||
dpv_e_2 = UC_TO_5NV(dpv_e_2);
|
||||
|
||||
|
||||
// dpv_e_init = UC_TO_5NV(20000); //-1V
|
||||
// dpv_e_final = UC_TO_5NV(30000); //1V
|
||||
// dpv_amp = UC_TO_5NV(25125); //25mv
|
||||
// dpv_pul_width = 500; //50ms
|
||||
// dpv_increment = UC_TO_5NV(25025); //5mv
|
||||
// dpv_step_time = 5000; //500ms
|
||||
// dpv_notify_rate = 100; //[10ms/point]
|
||||
|
||||
instru.v0 = dpv_e_init;
|
||||
instru.v_stop = dpv_e_final;
|
||||
instru.t_pulse[0] = dpv_step_time - dpv_pul_width;
|
||||
@@ -1158,6 +1157,10 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
instru.notifyRate = dpv_notify_rate;
|
||||
instru.v_slope[0] = 0; // 1234 = slop 1.234, same as scanrate
|
||||
instru.v_slope[1] = 0; // 1234 = slop 1.234
|
||||
instru.t_pulse_min[0] = dpv_curr_rec_percent_min[0];
|
||||
instru.t_pulse_max[0] = dpv_curr_rec_percent_max[0];
|
||||
instru.t_pulse_min[1] = dpv_curr_rec_percent_min[1];
|
||||
instru.t_pulse_max[1] = dpv_curr_rec_percent_max[1];
|
||||
|
||||
if (instru.v0 > instru.v_stop){
|
||||
instru.directionInit = 0;//0:reverse 1:forward
|
||||
@@ -1165,7 +1168,12 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
instru.directionInit = 1;
|
||||
}
|
||||
|
||||
instru.eliteFxn = CURVE_DPV;
|
||||
if (dpv_option == 2) {
|
||||
instru.eliteFxn = CURVE_DPV_SMPRATE;
|
||||
} else {
|
||||
instru.eliteFxn = CURVE_DPV;
|
||||
}
|
||||
|
||||
instru.VoutGainLv = VOUT_GAIN_240K;
|
||||
ModeLED(WORKING);
|
||||
}
|
||||
|
||||
+29
-11
@@ -352,7 +352,7 @@ static void uni_pulse_mode(void)
|
||||
if(GPT.NotifyCounter >= instru.notifyRate){
|
||||
GPT.NotifyCounter -= instru.notifyRate; //To get right time
|
||||
notify_flag = true;
|
||||
if (instru.eliteFxn == CURVE_UNI_PULSE) {
|
||||
if (instru.eliteFxn == CURVE_UNI_PULSE || instru.eliteFxn == CURVE_DPV) {
|
||||
notify_flag = false;
|
||||
}
|
||||
if(vscanReset){
|
||||
@@ -466,6 +466,7 @@ static void SimpleBLEPeripheral_performPeriodicTask(void)
|
||||
if (mode_init) {
|
||||
mode_init = false;
|
||||
mode_init_set();
|
||||
calc_avg_en = false;
|
||||
}
|
||||
|
||||
uni_pulse_mode();
|
||||
@@ -473,6 +474,18 @@ static void SimpleBLEPeripheral_performPeriodicTask(void)
|
||||
return;
|
||||
}
|
||||
|
||||
if (instru.eliteFxn == CURVE_DPV_SMPRATE) {
|
||||
if (mode_init) {
|
||||
mode_init = false;
|
||||
mode_init_set();
|
||||
}
|
||||
|
||||
uni_pulse_mode();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -506,7 +519,7 @@ static void EliteADCControl(uint32_t time)
|
||||
switch (instru.eliteFxn) {
|
||||
case CURVE_IV:
|
||||
case CURVE_IV_CY:
|
||||
Iin_Vin_Vout_Plot();
|
||||
Iin_Vin_Vout_Plot(t);
|
||||
if (curr_rec_en) {
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
}
|
||||
@@ -518,7 +531,7 @@ static void EliteADCControl(uint32_t time)
|
||||
break;
|
||||
|
||||
case CURVE_RT:
|
||||
Iin_Vin_Vout_Plot();
|
||||
Iin_Vin_Vout_Plot(t);
|
||||
if (curr_rec_en) {
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
}
|
||||
@@ -529,7 +542,7 @@ static void EliteADCControl(uint32_t time)
|
||||
break;
|
||||
|
||||
case CURVE_CC:
|
||||
Iin_Vin_Vout_Plot();
|
||||
Iin_Vin_Vout_Plot(t);
|
||||
if (curr_rec_en) {
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
}
|
||||
@@ -543,7 +556,7 @@ static void EliteADCControl(uint32_t time)
|
||||
case CURVE_CV:
|
||||
case CURVE_CA:
|
||||
case CURVE_LSV:
|
||||
Iin_Vin_Vout_Plot();
|
||||
Iin_Vin_Vout_Plot(t);
|
||||
if (curr_rec_en) {
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
}
|
||||
@@ -555,7 +568,7 @@ static void EliteADCControl(uint32_t time)
|
||||
break;
|
||||
|
||||
case CURVE_PULSE:
|
||||
Iin_Vin_Vout_Plot();
|
||||
Iin_Vin_Vout_Plot(t);
|
||||
if (curr_rec_en) {
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
}
|
||||
@@ -567,7 +580,7 @@ static void EliteADCControl(uint32_t time)
|
||||
break;
|
||||
|
||||
case CURVE_IT:
|
||||
Iin_Vin_Vout_Plot();
|
||||
Iin_Vin_Vout_Plot(t);
|
||||
if (curr_rec_en) {
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
}
|
||||
@@ -590,7 +603,7 @@ static void EliteADCControl(uint32_t time)
|
||||
break;
|
||||
|
||||
case CURVE_VO:
|
||||
Iin_Vin_Vout_Plot();
|
||||
Iin_Vin_Vout_Plot(t);
|
||||
if (curr_rec_en) {
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
}
|
||||
@@ -601,7 +614,7 @@ static void EliteADCControl(uint32_t time)
|
||||
break;
|
||||
|
||||
case CURVE_OCP:
|
||||
Iin_Vin_Vout_Plot();
|
||||
Iin_Vin_Vout_Plot(t);
|
||||
if (curr_rec_en) {
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
}
|
||||
@@ -626,12 +639,16 @@ static void EliteADCControl(uint32_t time)
|
||||
break;
|
||||
|
||||
case CURVE_DPV:
|
||||
Iin_Vin_Vout_Plot();
|
||||
Iin_Vin_Vout_Plot(t);
|
||||
break;
|
||||
|
||||
case CURVE_DPV_SMPRATE:
|
||||
Iin_Vin_Vout_Plot(t);
|
||||
if (curr_rec_en) {
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
}
|
||||
if (volt_rec_en) {
|
||||
InputNotify(NOTIFY_VOLT, instru.Vout/200 - MEAS_VIN(wm));
|
||||
InputNotify(NOTIFY_VOLT, MEAS_VOUT(wm) - MEAS_VIN(wm));
|
||||
InputNotify(NOTIFY_IMPEDANCE, instru.Vout/200);
|
||||
}
|
||||
break;
|
||||
@@ -698,6 +715,7 @@ static void vscan_ctrl(uint32_t time)
|
||||
break;
|
||||
|
||||
case CURVE_DPV:
|
||||
case CURVE_DPV_SMPRATE:
|
||||
dpv_vscan(t);
|
||||
|
||||
break;
|
||||
|
||||
+16
-13
@@ -537,6 +537,15 @@ static void dpv_vscan(uint32_t time)
|
||||
p->_Vset = p->_v_initial[0] + p->_v_slope[0] * t / 1000 + p->_v_step[0] * (int32_t)dpv_step_cnt; // _v_slope/100 = slope
|
||||
Vset = p->_Vset;
|
||||
|
||||
t_min = p->_t_pulse_min[0];
|
||||
t_max = p->_t_pulse_max[0];
|
||||
|
||||
if (m > t_min && m < t_max) {
|
||||
calc_avg_en = true;
|
||||
} else {
|
||||
calc_avg_en = false;
|
||||
}
|
||||
|
||||
if ((p->_v_direc_init && Vset > p->_v_stop) ||
|
||||
(!p->_v_direc_init && Vset < p->_v_stop)) {
|
||||
PeriodicEvent = false;
|
||||
@@ -549,20 +558,14 @@ static void dpv_vscan(uint32_t time)
|
||||
p->_Vset = p->_v_initial[1] + p->_v_slope[1] * t / 1000 + p->_v_step[1] * (int32_t)dpv_step_cnt;
|
||||
Vset = p->_Vset;
|
||||
|
||||
t_min = p->_t_pa[0] + p->_t_pulse_min[1];
|
||||
t_max = p->_t_pa[0] + p->_t_pulse_max[1];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (m < p->_t_pa[2]) {
|
||||
p->_Vset = p->_v_initial[2] + p->_v_slope[2] * t / 1000 + p->_v_step[2] * (int32_t)dpv_step_cnt;
|
||||
Vset = p->_Vset;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (m < p->_t_pa[3]) {
|
||||
p->_Vset = p->_v_initial[3] + p->_v_slope[3] * t / 1000 + p->_v_step[3] * (int32_t)dpv_step_cnt;
|
||||
Vset = p->_Vset;
|
||||
if (m > t_min && m < t_max) {
|
||||
calc_avg_en = true;
|
||||
} else {
|
||||
calc_avg_en = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user