[update] improve speed of changing volt on cp mode

This commit is contained in:
ROY
2023-02-23 15:52:35 +08:00
parent a04cec2dad
commit bb535e2c64
4 changed files with 57 additions and 28 deletions
@@ -121,6 +121,9 @@ static void initRawDataBuf(){
NotifyVolt[i] = 0;
NotifyImpedance[i] = 0;
}
notify_one = 0;
notify_two = 0;
notify_three = 0;
}
static void FlushNotify(){
@@ -2,11 +2,11 @@
#ifndef VERSION_DATE
#define VERSION_DATE
#define VERSION_DATE_YEAR 22
#define VERSION_DATE_MONTH 12
#define VERSION_DATE_DAY 2
#define VERSION_DATE_HOUR 17
#define VERSION_DATE_MINUTE 28
#define VERSION_DATE_YEAR 23
#define VERSION_DATE_MONTH 2
#define VERSION_DATE_DAY 23
#define VERSION_DATE_HOUR 15
#define VERSION_DATE_MINUTE 52
// this is NOT the version hash !!
// it's the last version hash
@@ -526,6 +526,9 @@ static bool first_highz_flag;
static bool tempCheck_flag;
static bool calc_avg_en;
static uint16_t dpv_step_cnt = 0;
// cp mode use
static int16_t cp_devis = 0;
static bool cp_devis_en = FALSE;
//pulse mode variable
static bool stiFirstTime;
@@ -1409,6 +1412,26 @@ static void update_ZM_instruction(uint8 *ins) {
break;
}
case 0x30: { // update divis on cp mode
uint8_t *p = ins;
cp_devis = p[5] << 8 | p[6];
if (p[4] == 0)
cp_devis_en = FALSE;
else
cp_devis_en = TRUE;
initCISBuf();
uint32_t temperature = (uint32_t)NotifyTemperature;
cis_buf[0] = 6; //data len
cis_buf[1] = 0x30;
cis_buf[2] = 3;
cis_buf[3] = cp_devis_en;
cis_buf[4] = (uint8_t)(cp_devis >> 8);
cis_buf[5] = (uint8_t)(cp_devis);
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
break;
}
}
break;
}
@@ -274,17 +274,18 @@ static void cp_vscan(void)
{
struct wm_cp_ctx_t *cp = (struct wm_cp_ctx_t *)wm_get();
struct wm_meas_t *m = &cp->measure;
uint16_t divisionRate;
static int64_t deltaI;
static int64_t deltaV;
uint8_t cc_cp_speed = instru.cc_cp_speed; // 0:low 1:normal 2:high
int32_t Iin;
int32_t Voutin;
uint8_t cc_cp_speed = instru.cc_cp_speed; // 0:low 1:normal 2:high
static int32_t i_set;
static uint8_t sum_cnt;
static int64_t sum_adc_delta_Voutin; //[5nV]
static int64_t sum_adc_delta_Iin; //[50pA]
static int32_t resis = 100;
static int32_t resis;
int16_t divisionRate;
static int64_t deltaI;
static int64_t deltaV;
static int32_t i_set;
static int64_t Rd = 0;
Iin = m->_measureCurrent * 20; //[50pA] nA => 50pA
@@ -294,7 +295,7 @@ static void cp_vscan(void)
sum_cnt = 0;
sum_adc_delta_Voutin = 0;
sum_adc_delta_Iin = 0;
resis = 100;
resis = 1000;
if (cp->_charge == 0) {
i_set = cp->_Iset * (-1);
@@ -313,31 +314,33 @@ static void cp_vscan(void)
return;
}
if (cc_cp_speed == 0) { // 0:low 1:normal 2:high
divisionRate = 500;
} else if (cc_cp_speed == 1) {
divisionRate = 50;
if (cp_devis_en == TRUE) {
cc_cp_speed = cp_devis;
} else {
divisionRate = 5;
if (cc_cp_speed == 0) { // 0:low 1:normal 2:high
divisionRate = 500;
} else if (cc_cp_speed == 1) {
divisionRate = 50;
} else {
divisionRate = 1;
}
}
deltaI = Iin - i_set;
sum_adc_delta_Voutin += Voutin;
sum_adc_delta_Iin += Iin;
sum_cnt++;
if (sum_cnt == 5) {
if (sum_adc_delta_Iin != 0) {
Rd = sum_adc_delta_Voutin * 100 / sum_adc_delta_Iin;
Rd = sum_adc_delta_Voutin * 100 / sum_adc_delta_Iin;
if ((sum_adc_delta_Iin >= 12000 || sum_adc_delta_Iin <= -12000) && Rd >= 0) { // sum_delIin >= 600nA
if (Rd <= 10) {
resis = 10;
} else if (Rd >= 10000000) {
resis = 10000000;
} else {
resis = Rd;
}
if ((sum_adc_delta_Iin >= 12000 || sum_adc_delta_Iin <= -12000) && Rd >= 0) { // sum_delIin >= 600nA
if (Rd <= 10) {
resis = 10;
} else if (Rd >= 10000000) {
resis = 10000000;
} else {
resis = Rd;
}
}