Compare commits

...

4 Commits

Author SHA1 Message Date
JayC319 9e2c1373f1 [update] new Cali Mode version 2022-08-15 18:30:02 +08:00
JayC319 ab5926a933 [update] cali mode update 2022-08-15 17:25:09 +08:00
JayC319 ba29ac9418 [update] changes on DAC_VOUT 2022-08-11 10:46:15 +08:00
JayC319 6754c4b9e8 [update] added new calibration mode 2022-08-10 18:08:03 +08:00
10 changed files with 167 additions and 112 deletions
@@ -44,6 +44,8 @@ extern "C" {
#define E_LATCH_OFF LOAD2, D6
#define E_LATCH_VOUT_SMALL_ON LOAD2, D7
#define HIGH_Z_OPEN() latch_single_ctrl(E_LATCH_HIGH_Z, 0);
#define HIGH_Z_CLOSE() latch_single_ctrl(E_LATCH_HIGH_Z, 1);
uint8_t update_latch_stat(uint8_t latch, uint8_t dio, uint8_t value);
uint8_t latch_single_ctrl(uint8_t latch, uint8_t dio, uint8_t value);
uint8_t latch_multi_ctrl(void);
@@ -9,8 +9,8 @@ extern "C" {
#define ADC_CH_CURR AIN0_GND
#define ADC_CH_VIN AIN1_GND
#define ADC_CH_VOUT AIN2_GND
#define ADC_CH_BAT AIN3_GND
#define ADC_CH_VOUT AIN2_GND
#define MEASURE_CURRENT() read_adc_data(ADC_CH_CURR, FSR3)
#define MEASURE_VOLT() read_adc_data(ADC_CH_VIN, FSR3)
@@ -224,6 +224,7 @@ static void __small_switch_lv2(uint8_t gain2_en, uint16_t plot, int16_t *I_GAIN_
void IinADCGainCtrl(uint8_t IinADCLevel)
{
/* hardware need open before close, so don't change position*/
if (IinADCLevel == 0) {
// ADC gain level = 0, using 2M resister
@@ -276,14 +277,12 @@ void IinADCGainCtrl(uint8_t IinADCLevel)
lastIinADCGainLevel = 3;
}
curr_rec_en = false;
return;
}
void VinADCGainCtrl(uint8_t VinADCLevel)
{
{
/* hardware need open before close, so don't change position*/
if (VinADCLevel == 0) {
// Vin ADC gain level = 0, using 1M resister
@@ -324,7 +323,6 @@ void VinADCGainCtrl(uint8_t VinADCLevel)
}
volt_rec_en = false;
return;
}
@@ -94,7 +94,7 @@ static void WorkModeLED()
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_CYAN);
break;
case CURVE_CALI_ADC:
case CURVE_CALI:
if (instru.AdcChannel == RIS_ADC_IIN) {
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_RED);
} else if (instru.AdcChannel == RIS_ADC_VIN) {
@@ -205,6 +205,12 @@ struct wm_ocp_ctx_t {
struct wm_meas_t measure;
};
struct wm_adc_cali_ctx_t {
struct wm_meas_t measure;
};
int wm_init(void);
int wm_deinit(void);
void *wm_get(void);
@@ -698,6 +704,29 @@ static int __ocp_create(void)
return 0;
}
static int __adc_cali_create()
{
struct wm_meas_t *m;
struct wm_adc_cali_ctx_t *p;
void **wm = &workMode_p;
p = malloc(sizeof(struct wm_adc_cali_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;
*wm = p;
return 0;
}
int wm_init(void)
{
int mode = instru.eliteFxn;
@@ -762,7 +791,10 @@ int wm_init(void)
case CURVE_DPV_ADVANCE_SMPRATE:
if (__dpv_advance_create()) return -2;
break;
case CURVE_CALI:
if (__adc_cali_create()) return -2;
break;
default:
// printf("DO NOT support!!");
return -3;
@@ -21,33 +21,33 @@
// RIS (real instruction)
enum all_mode_e {
CURVE_IV = 0x01, // I-V Curve //0x10,
CURVE_IV_CY = 0x02, // Cycle I-V //0x20,
CURVE_VO = 0x03, // Function Generator //0x30,
CURVE_RT = 0x04, // R-T Graph //0x40,
CURVE_VT = 0x05, // V-T Graph //0x50,
CURVE_IT = 0x06, // I-T Graph //0x60,
CURVE_CC = 0x07, // Constant Current (CC) //0xD0,
CURVE_OCP = 0x08, // Open Circuit Potential (OCP)
CURVE_CV = 0x09, // Cyclic Voltammetry (CV) //0xC0,
CURVE_LSV = 0x0A, // Linear Sweep Voltammetry (LSV) //0x02,
CURVE_CA = 0x0B, // Chronoamperometric Graph (CA) //0x03,
CURVE_UNI_PULSE = 0x0D, // universal pulse
CURVE_IV = 0x01,
CURVE_IV_CY = 0x02,
CURVE_VO = 0x03,
CURVE_RT = 0x04,
CURVE_VT = 0x05,
CURVE_IT = 0x06,
CURVE_CC = 0x07,
CURVE_OCP = 0x08,
CURVE_CV = 0x09,
CURVE_LSV = 0x0A,
CURVE_CA = 0x0B,
CURVE_UNI_PULSE = 0x0D,
CURVE_DPV = 0x0E,
CURVE_DPV_SMPRATE = 0x0F,
CURVE_DPV_ADVANCE = 0x10,
CURVE_DPV_ADVANCE_SMPRATE = 0x11,
CURVE_CALI_ADC = 0xF1, // Cali ADC - test //0x92,
CURVE_CALI = 0xF1, // 0xF1
SET_SAMPLE_RATE = 0xE0, //0x70,
SET_ADC_DAC_GAIN = 0xE1, //0x80,
SET_SAMPLE_RATE = 0xE0,
SET_ADC_DAC_GAIN = 0xE1, //0xE1
SET_PARA = 0xE2
};
enum set_para_e {
DAC_VOLT = 0x01,
DAC_VOLT = 0x01,
};
enum dev_para_e {
@@ -711,13 +711,15 @@ static void cali_IT_plot(void) {
} else {
cali_count++;
ADCValueSUM = ADCValueSUM + MEAS_CURR(wm);
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
InputNotify(NOTIFY_VOLT, ADCValueSUM);
ADCValueAVG = ADCValueSUM / cali_count;
InputNotify(NOTIFY_CURRENT, ADCValueAVG);
InputNotify(NOTIFY_VOLT, MEAS_CURR(wm));
InputNotify(NOTIFY_IMPEDANCE, (int32_t)cali_count);
}
}
if (rec_cnt == 2) {
volt_rec_en = true;
curr_rec_en = true;
rec_cnt = 0;
}
@@ -792,19 +794,21 @@ static void cali_VT_plot(void) {
PeriodicEvent = false;
ADCValueSUM = 0;
cali_count = 0;
cali_count = 0;
ModeLED(NO_EVENT);
} else {
cali_count++;
ADCValueSUM = ADCValueSUM + MEAS_VIN(wm);
ADCValueAVG = ADCValueSUM / cali_count;
InputNotify(NOTIFY_VOLT, MEAS_VIN(wm));
InputNotify(NOTIFY_CURRENT, ADCValueSUM);
InputNotify(NOTIFY_CURRENT, ADCValueAVG);
InputNotify(NOTIFY_IMPEDANCE, (int32_t)cali_count);
}
}
if (rec_cnt == 2) {
volt_rec_en = true;
curr_rec_en = true;
rec_cnt = 0;
}
ADC_cnt++;
@@ -828,20 +832,20 @@ static void cali_VT_plot(void) {
return;
}
static void cali_Vout_plot(void) {
static void cali_Vout_plot() {
void *wm = wm_get();
static int32_t ADCValueSUM = 0;
static uint16_t cali_count = 0;
static uint8_t ADC_cnt = 0;
static uint8_t rec_cnt = 0;
uint16_t cali_count_max = 1000;
uint16_t cali_count_max = 2000;
int32_t ADCValueAVG = 0;
/* ADC_cnt: 0 - read Vin and do NOT buffer the Vin after changing gain twice
* 1 - read Vin and increase ADC_cnt
* 2 - read Vin and reset ADC_cnt
*/
if(vscanReset)
return;
if (ADC_cnt == 0) {
ADC_rxbuf = MEASURE_DAC();
@@ -853,9 +857,9 @@ static void cali_Vout_plot(void) {
if (cali_count >= cali_count_max) {
ADCValueAVG = ADCValueSUM / cali_count;
InputNotify(NOTIFY_VOLT, ADCValueAVG);
InputNotify(NOTIFY_VOLT, ADCValueAVG);
SendNotify();
uint8_t CIS_buf[9] = {0};
CIS_buf[0] = 5; //data len
CIS_buf[1] = instru.chip_id;
@@ -864,7 +868,7 @@ static void cali_Vout_plot(void) {
CIS_buf[4] = 0x00;
CIS_buf[5] = instru.VinADCGainLv;
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 9, CIS_buf);
//HIGH_Z_OPEN();
PeriodicEvent = false;
ADCValueSUM = 0;
cali_count = 0;
@@ -872,14 +876,16 @@ static void cali_Vout_plot(void) {
} else {
cali_count++;
ADCValueSUM = ADCValueSUM + MEAS_VOUT(wm);
ADCValueAVG = ADCValueSUM / cali_count;
InputNotify(NOTIFY_VOLT, MEAS_VOUT(wm));
InputNotify(NOTIFY_CURRENT, ADCValueSUM);
InputNotify(NOTIFY_IMPEDANCE, (int32_t)cali_count);
InputNotify(NOTIFY_CURRENT, ADCValueAVG);
InputNotify(NOTIFY_IMPEDANCE, (int32_t)cali_count);
}
}
if (rec_cnt == 2) {
volt_rec_en = true;
curr_rec_en = true;
rec_cnt = 0;
}
ADC_cnt++;
@@ -3,10 +3,10 @@
#define VERSION_DATE
#define VERSION_DATE_YEAR 22
#define VERSION_DATE_MONTH 7
#define VERSION_DATE_DAY 22
#define VERSION_DATE_HOUR 14
#define VERSION_DATE_MINUTE 39
#define VERSION_DATE_MONTH 8
#define VERSION_DATE_DAY 15
#define VERSION_DATE_HOUR 18
#define VERSION_DATE_MINUTE 30
// this is NOT the version hash !!
// it's the last version hash
@@ -870,10 +870,11 @@ static void update_ZM_instruction(uint8 *ins) {
instru.IinADCGainLv = ins[4];
if (instru.IinADCGainLv != I_GAIN_AUTO) {
instru.IinADCAutoGainEn = 0;
//IinADCGainCtrl(instru.IinADCGainLv);
} else {
instru.IinADCAutoGainEn = 1;
instru.IinADCGainLv = I_GAIN_100R;
IinADCGainCtrl(instru.IinADCGainLv);
//IinADCGainCtrl(instru.IinADCGainLv);
}
break;
}
@@ -884,31 +885,29 @@ static void update_ZM_instruction(uint8 *ins) {
} else {
instru.VinADCAutoGainEn = 1;
instru.VinADCGainLv = VIN_GAIN_1K;
VinADCGainCtrl(instru.VinADCGainLv);
//VinADCGainCtrl(instru.VinADCGainLv);
}
break;
}
case RIS_DAC_VOUT : {
// instru.VoutGainLv = ins[4];
// if(instru.VoutGainLv == VOUT_GAIN_AUTO){
// instru.VoutGainLv = VOUT_GAIN_15K;
// }
instru.VoutGainLv = ins[4];
VoutGainControl(instru.VoutGainLv);
//VoutGainControl(instru.VoutGainLv);
break;
}
case RIS_HIGH_Z : {
switch(ins[4]) {
case 0x00 : {
if (PeriodicEvent) {
latch_single_ctrl(E_LATCH_HIGH_Z, 0); // 0 => open high_z mode
//latch_single_ctrl(E_LATCH_HIGH_Z, 0); // 0 => open high_z mode
HIGH_Z_OPEN();
}
break;
}
case 0x01 : {
if (PeriodicEvent) {
latch_single_ctrl(E_LATCH_HIGH_Z, 1); // 1 => close high_z mode
//latch_single_ctrl(E_LATCH_HIGH_Z, 1); // 1 => close high_z mode
HIGH_Z_CLOSE();
}
break;
}
@@ -925,28 +924,47 @@ static void update_ZM_instruction(uint8 *ins) {
break;
}
case CURVE_CALI_ADC: {
switch(ins[3]) {
case CURVE_CALI: {
switch(ins[3]) {
case RIS_ADC_IIN : { // 0x00
instru.eliteFxn = CURVE_CALI_ADC;
instru.eliteFxn = CURVE_CALI;
instru.AdcChannel = RIS_ADC_IIN;
instru.notifyRate = 1000;
ModeLED(WORKING);
break;
}
case RIS_ADC_VIN : { // 0x01
instru.eliteFxn = CURVE_CALI_ADC;
instru.eliteFxn = CURVE_CALI;
instru.AdcChannel = RIS_ADC_VIN;
instru.notifyRate = 1000;
ModeLED(WORKING);
break;
}
case RIS_DAC_VOUT : { // 0x02
instru.eliteFxn = CURVE_CALI_ADC;
instru.eliteFxn = CURVE_CALI;
instru.AdcChannel = RIS_DAC_VOUT;
instru.notifyRate = 1000;
instru.VoltConstant = ( ((uint16_t)(ins[4])) << 8) | (uint16_t)(ins[5]); // output voltage
DAC0_W_T(instru.VoltConstant);
instru.hign_z_en = 1;
switch(ins[4]) {
case 0x00: {
instru.VoltConstant = 0x2710;
break;
}
case 0x01: {
instru.VoltConstant = 0x61A8;
break;
}
case 0x02: {
instru.VoltConstant = 0xC350;
break;
}
case 0x03: {
instru.VoltConstant = 0xEA60;
break;
}
}
DAC0_W_T(instru.VoltConstant);
ModeLED(WORKING);
break;
}
@@ -1290,7 +1308,8 @@ static void update_ZM_instruction(uint8 *ins) {
switch (ins[3]){
case DAC_VOLT:
value = (ins[4] << 8) | ins[5]; // usercode
if(value < DAC_VOUT_GAIN_LARGE_BOUNDARY_USERCODE && value > DAC_VOUT_GAIN_LARGE_BOUNDARY1_USERCODE){
instru.VoutGainLv = VOUT_GAIN_15K;
} else {
@@ -1361,59 +1380,38 @@ static void update_ZM_instruction(uint8 *ins) {
break;
}
case 0x50: {
initCISBuf();
case 0x90 : {
led_rainbow(LED_BR_LV8);
VoutGainControl(0x00);
cis_buf[0] = 2;
cis_buf[1] = (uint8_t) ADC_rxbuf >> 8;
cis_buf[2] = (uint8_t) ADC_rxbuf;
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
HIGH_Z_CLOSE();
uint16_t volts = ( ((uint16_t)(ins[4])) << 8) | (uint16_t)(ins[5]);
dac_write_through_mode(0x01, 0x01, volts);
//CPUdelay(32000000);
led_color_set(LED_NB_MAX, LED_BR_LV1, LED_CLR_BLUE);
CPUdelay(32000000);
ADC_rxbuf = MEASURE_DAC();
CPUdelay(32000000);
ADC_rxbuf = MEASURE_DAC();
led_rainbow(LED_BR_LV1);
uint8_t CIS_buf[9] = {0};
CIS_buf[0] = 5; //data len
CIS_buf[1] = instru.chip_id;
CIS_buf[2] = (uint8_t) ((ADC_rxbuf & 0xFF00) >> 8);
CIS_buf[3] = (uint8_t) (ADC_rxbuf & 0x00FF);
CIS_buf[4] = 0x00;
CIS_buf[5] = instru.VinADCGainLv;
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 9, CIS_buf);
break;
}
case 0x51: {
initCISBuf();
cis_buf[0] = 2;
cis_buf[1] = (uint8_t) ADC_rxbuf >> 8;
cis_buf[2] = (uint8_t) ADC_rxbuf;
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, BLE_CIS_BUFF_SIZE, cis_buf);
break;
}
case 0x61: {
dac_ldac_mode(ins[4], ins[5]);
break;
}
case 0x62: {
dac_clear_mode();
break;
}
case 0x63: {
dac_power_control_mode(ins[4], ins[5], ins[6]);
break;
}
case 0x64: {
dac_linearity_mode(ins[4]);
break;
}
case 0x65: {
uint16_t volts = (uint16_t)ins[6] << 8 | ins[7];
dac_write_mode(ins[4], ins[5], volts);
break;
}
case 0x66: {
uint16_t volts = (uint16_t)ins[6] << 8 | ins[7];
DAC0_W_T(volts);
break;
}
}
break;
}
@@ -86,7 +86,7 @@ static void ZM_init() {
(instru.eliteFxn == CURVE_CA) || \
(instru.eliteFxn == CURVE_VO) || \
(instru.eliteFxn == CURVE_OCP) || \
(instru.eliteFxn == CURVE_CALI_ADC) \
(instru.eliteFxn == CURVE_CALI) \
)
#define Ve1MatchVe2Mode() ( \
@@ -105,9 +105,15 @@ static void peri_mode(void)
vscanReset = true;
if (first_highz_flag && GPT.cnt_lead_time >= 1000) {
if (instru.eliteFxn == CURVE_OCP) {
latch_single_ctrl(E_LATCH_HIGH_Z, instru.hign_z_en); // HIGH Z MODE // 1: close; 0: open;
HIGH_Z_OPEN(); // HIGH Z MODE // 1: close; 0: open;
} else {
latch_single_ctrl(E_LATCH_HIGH_Z, instru.hign_z_en); // HIGH Z MODE // 1: close; 0: open;
//latch_single_ctrl(E_LATCH_HIGH_Z, instru.hign_z_en); // HIGH Z MODE // 1: close; 0: open;
if(instru.hign_z_en == 1) {
HIGH_Z_CLOSE();
}
else{
HIGH_Z_OPEN();
}
}
first_highz_flag = false;
}
@@ -151,7 +157,7 @@ static void peri_mode(void)
(instru.eliteFxn == CURVE_DPV_SMPRATE) ||
(instru.eliteFxn == CURVE_DPV_ADVANCE) ||
(instru.eliteFxn == CURVE_DPV_ADVANCE_SMPRATE) ||
(instru.eliteFxn == CURVE_CALI_ADC)) {
(instru.eliteFxn == CURVE_CALI)) {
batteryCheck_flag = false;
tempCheck_flag = false;
@@ -255,7 +261,7 @@ static void uni_pulse_mode(void)
(instru.eliteFxn == CURVE_DPV_SMPRATE) ||
(instru.eliteFxn == CURVE_DPV_ADVANCE) ||
(instru.eliteFxn == CURVE_DPV_ADVANCE_SMPRATE) ||
(instru.eliteFxn == CURVE_CALI_ADC)) {
(instru.eliteFxn == CURVE_CALI)) {
batteryCheck_flag = false;
tempCheck_flag = false;
@@ -314,6 +320,8 @@ static void uni_pulse_mode(void)
static void mode_init_set(void)
{
batteryADC_flag = false;
volt_rec_en = true;
curr_rec_en = true;
@@ -350,6 +358,10 @@ static void mode_init_set(void)
IinADCGainCtrl(instru.IinADCGainLv);
VoutGainControl(instru.VoutGainLv);
// if(instru.eliteFxn == CURVE_CALI) {
// volt_rec_en = true;
// curr_rec_en = true;
// }
if (Ve1MatchVe2Mode()) {
if (instru.Ve1 == instru.Ve2) {
DAC0_W_T(Usercode_Correction_to_DAC(instru.VoutGainLv, 25000));
@@ -554,13 +566,16 @@ static void EliteADCControl(uint32_t time)
}
break;
case CURVE_CALI_ADC:
case CURVE_CALI:
if (instru.AdcChannel == RIS_ADC_IIN) {
cali_IT_plot();
} else if (instru.AdcChannel == RIS_ADC_VIN) {
cali_VT_plot();
} else if (instru.AdcChannel == RIS_DAC_VOUT) {
cali_Vout_plot();
}
break;
@@ -612,9 +627,13 @@ static void mode_done(void)
(instru.eliteFxn == CURVE_DPV) ||
(instru.eliteFxn == CURVE_DPV_SMPRATE) ||
(instru.eliteFxn == CURVE_DPV_ADVANCE) ||
(instru.eliteFxn == CURVE_DPV_ADVANCE_SMPRATE)) {
(instru.eliteFxn == CURVE_DPV_ADVANCE_SMPRATE) ||
(instru.eliteFxn == CURVE_CALI))
{
if (!PeriodicEvent) {
finishMode = true;
// if(!(instru.eliteFxn == CURVE_CALI))
SendNotify();
Eliteinterrupt();
}