reset avg_count and unmerge
This commit is contained in:
+1
-2
@@ -1121,7 +1121,6 @@ static void SetSamplingTime(uint32_t freq){
|
||||
BpSINC3(1);
|
||||
SetADCDataRate(ADC1M6sps);
|
||||
SetDFTNUM(DFTNUM16384);
|
||||
// SetCTIA(32); //disconncted
|
||||
instru.settingIndex = 1;
|
||||
}
|
||||
|
||||
@@ -1132,7 +1131,6 @@ static void SetSamplingTime(uint32_t freq){
|
||||
SetADCDataRate(ADC1M6sps);
|
||||
SetSinc3OSR(Sinc3OSR4);
|
||||
SetDFTNUM(DFTNUM8192);
|
||||
// SetCTIA(0); //1pF
|
||||
|
||||
// select_REG(0x2044); //0x2044
|
||||
// w32_REG(0x00001010); //ADC data rate = 1.6MHz | SINC3 4
|
||||
@@ -1231,3 +1229,4 @@ static void SetSamplingTime(uint32_t freq){
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+1
-21
@@ -140,7 +140,7 @@ static uint32_t CalcDelayTime(uint32_t freq){
|
||||
|
||||
// 1000Hz
|
||||
if (freq >= 100000) {
|
||||
decadeSamplingTime = 500;
|
||||
decadeSamplingTime = 1025;
|
||||
}
|
||||
|
||||
// 100Hz
|
||||
@@ -169,7 +169,6 @@ static uint32_t CalcDelayTime(uint32_t freq){
|
||||
}
|
||||
|
||||
delayTime += decadeSamplingTime; //delay+reading time
|
||||
time_tester += delayTime;
|
||||
|
||||
return delayTime;
|
||||
}
|
||||
@@ -363,23 +362,4 @@ static int32_t cali_DAC_outputV(int32_t voltLV) { // LPDAC output, voltLV = Vb
|
||||
return vscan;
|
||||
}
|
||||
|
||||
static void Cali_DAC_output () {
|
||||
static int32_t LPvolt = 0;
|
||||
|
||||
if (instru.DAC_type == HSDACtype_DC) {
|
||||
HS_cali_config();
|
||||
HSDAC_output(instru.VAmpSet);
|
||||
} else if (instru.DAC_type == LPDACtype_DC) {
|
||||
LP_cali_config();
|
||||
LPvolt = (int32_t)(instru.VAmpSet);
|
||||
LPvolt = (LPvolt - 25000) * 4 * 4000;
|
||||
cali_DAC_outputV(LPvolt);
|
||||
} else if (instru.DAC_type == HSDACtype_AC) {
|
||||
HS_cali_config();
|
||||
DAC_outputF(0x00000800);
|
||||
SetWGAmp(instru.VAmpSet); // sine wave generation usage
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+2
-1
@@ -7,6 +7,7 @@ static void eis_fscan(void)
|
||||
struct wm_eis_ctx_t *eis = (struct wm_eis_ctx_t *)wm_get();
|
||||
|
||||
if (vscanReset) {
|
||||
eis->_in_reset_flag = true;
|
||||
|
||||
eis->_f1 = User2Freq(eis->_f1);
|
||||
eis->_f2 = User2Freq(eis->_f2);
|
||||
@@ -143,7 +144,7 @@ static void eis_fscan(void)
|
||||
SetSamplingTime(instru.fset);
|
||||
|
||||
instru.sampleRate = 2000;
|
||||
time_tester += 2000;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+7
-10
@@ -101,15 +101,12 @@ struct HEADSTAGE_INSTRUCTION {
|
||||
/** Iin, Vin, Vout **/
|
||||
#define EIS_HSTIA 0x00
|
||||
#define EIS_LPTIA 0x01
|
||||
#define EIS_DAC 0x02
|
||||
#define HIGH_Z 0x03
|
||||
#define IIN_ADC 0x04
|
||||
#define VIN_ADC 0x05
|
||||
#define VOUT_DAC 0x06
|
||||
|
||||
#define HSDACtype_DC 0x00
|
||||
#define LPDACtype_DC 0x01
|
||||
#define HSDACtype_AC 0x02
|
||||
#define EIS_HSDAC 0x02
|
||||
#define EIS_LPDAC 0x03
|
||||
#define VOUT_DAC 0x04
|
||||
#define IIN_ADC 0x05
|
||||
#define VIN_ADC 0x06
|
||||
#define HIGH_Z 0x07
|
||||
|
||||
/** ADC Iin gain level **/
|
||||
#define I_GAIN_3M 0x07 // largest gain
|
||||
@@ -291,7 +288,7 @@ static void InitEliteInstruction(){
|
||||
|
||||
// EIS DAC
|
||||
instru.VAmpSet = EIS_HSDAC_ZERO;
|
||||
instru.DAC_type = HSDACtype_DC;
|
||||
instru.DAC_type = EIS_HSDAC;
|
||||
|
||||
// EIS ADC
|
||||
instru.HSTIAGainLv = 0;
|
||||
|
||||
+3
-1
@@ -180,12 +180,14 @@ static void WorkModeLED()
|
||||
Elite_led_color(COLOR_ORANGE);
|
||||
} else if (instru.AdcChannel == VOUT_DAC) {
|
||||
Elite_led_color(COLOR_BLUE);
|
||||
}else if (instru.AdcChannel == EIS_DAC) {
|
||||
}else if (instru.AdcChannel == EIS_HSDAC) {
|
||||
Elite_led_color(COLOR_PURPLE_DARK);
|
||||
} else if (instru.AdcChannel == EIS_HSTIA) {
|
||||
Elite_led_color(COLOR_WHITE);
|
||||
} else if (instru.AdcChannel == EIS_LPTIA) {
|
||||
Elite_led_color(COLOR_RED);
|
||||
} else if (instru.AdcChannel == EIS_LPDAC) {
|
||||
Elite_led_color(COLOR_BLUE);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
+2
-2
@@ -54,8 +54,8 @@ static void Eliteinterrupt() {
|
||||
InitGPT();
|
||||
initINSBuf();
|
||||
initDATBuf();
|
||||
// AD5940_HWReset();
|
||||
// AD5940_init();
|
||||
AD5940_HWReset();
|
||||
AD5940_init();
|
||||
|
||||
// HSTIAGainCtrl(HSRTIA_200R);
|
||||
// LPTIAGainCtrl(LPRTIA_200R);
|
||||
|
||||
+2
@@ -70,6 +70,7 @@ struct wm_eis_ctx_t {
|
||||
bool _switchNeg;
|
||||
bool _switchPos;
|
||||
bool _firstSwitch;
|
||||
bool _in_reset_flag;
|
||||
};
|
||||
|
||||
struct wm_vo_ctx_t {
|
||||
@@ -217,6 +218,7 @@ static int __eis_create(void)
|
||||
p->_switchPos = false;
|
||||
p->_switchNeg = false;
|
||||
p->_firstSwitch = true;
|
||||
p->_in_reset_flag = false;
|
||||
|
||||
*wm = p;
|
||||
|
||||
|
||||
-1
@@ -69,7 +69,6 @@ enum all_mode_e {
|
||||
#define cali_HSDAC_amp 0x49
|
||||
#define cali_HSTIA_setGain 0x59
|
||||
#define cali_HSDAC_DC 0x69
|
||||
#define cali_HSTIA_Iin 0x65
|
||||
|
||||
// mode parameter
|
||||
#define STEP_TO_VSETRATE(step) step2VsetRate(step)
|
||||
|
||||
+60
-28
@@ -393,7 +393,14 @@ static void EIS_Plot(void) //real and imag impedance plot
|
||||
EnDFTnADC(1);
|
||||
instru.sampleRate = CalcDelayTime(instru.fset);
|
||||
fout_flag = false;
|
||||
|
||||
if (eis->_in_reset_flag) {
|
||||
avg_count = 0;
|
||||
high_freq_cnt = 0;
|
||||
realSum = 0;
|
||||
imagSum = 0;
|
||||
ADC_cnt = 0;
|
||||
eis->_in_reset_flag = false;
|
||||
}
|
||||
} else {
|
||||
if (ADC_cnt == 0){
|
||||
HSTIA_change_gain();
|
||||
@@ -411,7 +418,7 @@ static void EIS_Plot(void) //real and imag impedance plot
|
||||
else if (ADC_cnt == 1) {
|
||||
HSTIA_change_gain();
|
||||
if (firstFreq_flag) {
|
||||
if (instru.f1 >= 10000000) {
|
||||
if (instru.fset >= 10000000) {
|
||||
if (high_freq_cnt == 3) {
|
||||
firstFreq_flag = false;
|
||||
}
|
||||
@@ -429,37 +436,39 @@ static void EIS_Plot(void) //real and imag impedance plot
|
||||
}
|
||||
}
|
||||
else if (ADC_cnt == 2) {
|
||||
realSum += instru.real;
|
||||
imagSum += instru.imag;
|
||||
avg_count ++;
|
||||
instru.sampleRate = CalcDelayTime(instru.fset);
|
||||
if (avg_count == avgNumTable[instru.avgnum]){
|
||||
avg_real = realSum / avg_count;
|
||||
avg_imag = imagSum / avg_count;
|
||||
avg_count = 0;
|
||||
realSum = 0;
|
||||
imagSum = 0;
|
||||
EnDFTnADC(0);
|
||||
if(eis->_direction_up){
|
||||
if (instru.fset >= eis->_fmax) {
|
||||
PeriodicEvent = false;
|
||||
finishMode = 1;
|
||||
}
|
||||
} else {
|
||||
if (instru.fset <= eis->_fmin) {
|
||||
PeriodicEvent = false;
|
||||
finishMode = 1;
|
||||
realSum += instru.real;
|
||||
imagSum += instru.imag;
|
||||
avg_count++;
|
||||
instru.sampleRate = CalcDelayTime(instru.fset);
|
||||
if (avg_count == avgNumTable[instru.avgnum]){
|
||||
avg_real = (realSum + avg_count / 2) / avg_count;
|
||||
avg_imag = (imagSum + avg_count / 2) / avg_count;
|
||||
avg_count = 0;
|
||||
realSum = 0;
|
||||
imagSum = 0;
|
||||
EnDFTnADC(0);
|
||||
if(eis->_direction_up){
|
||||
if (instru.fset >= eis->_fmax) {
|
||||
PeriodicEvent = false;
|
||||
finishMode = 1;
|
||||
}
|
||||
} else {
|
||||
if (instru.fset <= eis->_fmin) {
|
||||
PeriodicEvent = false;
|
||||
finishMode = 1;
|
||||
}
|
||||
}
|
||||
notify_flag = true;
|
||||
high_freq_cnt = 0;
|
||||
}
|
||||
notify_flag = true;
|
||||
}
|
||||
ADC_cnt = 0;
|
||||
ADC_cnt = 0;
|
||||
}
|
||||
}
|
||||
|
||||
InputNotify(NOTIFY_CURRENT, avg_imag);
|
||||
InputNotify(NOTIFY_VOLT, avg_real);
|
||||
InputNotify(NOTIFY_IMPEDANCE, instru.fset);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -604,6 +613,28 @@ static void cali_IT_plot(void) {
|
||||
temp = (ReadRealZ() & 0x0003FFFF);
|
||||
}
|
||||
|
||||
// switch (instru.AdcChannel) {
|
||||
// case EIS_HSTIA: {
|
||||
// if (instru.HSTIAGainLv == 0) {
|
||||
// cali_count_max = 5000;
|
||||
// } else {
|
||||
// cali_count_max = 1000;
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// case EIS_LPTIA: {
|
||||
// if (instru.LPTIAGainLv == 0) {
|
||||
// cali_count_max = 5000;
|
||||
// } else {
|
||||
// cali_count_max = 1000;
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// default:{
|
||||
// cali_count_max = 1000;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
cali_count_max = 3000;
|
||||
|
||||
if (record_flag == false) {
|
||||
@@ -618,9 +649,9 @@ static void cali_IT_plot(void) {
|
||||
|
||||
uint8_t CIS_buf[9] = {0};
|
||||
CIS_buf[0] = instru.chip_id;
|
||||
CIS_buf[1] = (uint8_t) ((ADCValueAVG & 0xFF0000) >> 16);
|
||||
CIS_buf[2] = (uint8_t) ((ADCValueAVG & 0x00FF00) >> 8);
|
||||
CIS_buf[3] = (uint8_t) (ADCValueAVG & 0x0000FF);
|
||||
CIS_buf[1] = (uint8_t) ((ADCValueAVG & 0xFF00) >> 8);
|
||||
CIS_buf[2] = (uint8_t) (ADCValueAVG & 0x00FF);
|
||||
CIS_buf[3] = 0x00;
|
||||
CIS_buf[4] = instru.HSTIAGainLv;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 9, CIS_buf);
|
||||
|
||||
@@ -752,3 +783,4 @@ static void cali_VT_plot(void) {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+47
-53
@@ -584,7 +584,13 @@ static bool fset_flag;
|
||||
static bool fout_flag;
|
||||
static bool gainChange_flag;
|
||||
static bool firstFreq_flag;
|
||||
static uint32_t time_tester = 0;
|
||||
static uint32_t time0 = 0;
|
||||
static uint32_t time1 = 0;
|
||||
static uint32_t delta_time = 0;
|
||||
static uint32_t time10 = 0;
|
||||
static uint32_t time11 = 0;
|
||||
static uint32_t delta_time1 = 0;
|
||||
static uint32_t test_cnt = 0;
|
||||
|
||||
//pulse mode variable
|
||||
static bool stiFirstTime;
|
||||
@@ -653,8 +659,6 @@ static void InitEliteFlag();
|
||||
|
||||
//EIS crap
|
||||
static void AD5940_HWReset();
|
||||
static void LP_cali_config ();
|
||||
static void HS_cali_config ();
|
||||
|
||||
#include "EliteInstruction.h"
|
||||
#include "EliteADC.h"
|
||||
@@ -1035,13 +1039,11 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
case HIGH_Z : {
|
||||
switch(ins[4]) {
|
||||
case 0x00 : {
|
||||
AD5940_HWReset();
|
||||
AD5940_init();
|
||||
// SetEISHIGHZ(0); //open CE0
|
||||
SetEISHIGHZ(0); //open CE0
|
||||
break;
|
||||
}
|
||||
case 0x01 : {
|
||||
// SetEISHIGHZ(1); //close CE0
|
||||
SetEISHIGHZ(1); //close CE0
|
||||
break;
|
||||
}
|
||||
default : {
|
||||
@@ -1050,7 +1052,16 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case EIS_HSTIA : { // 0x00
|
||||
case EIS_HSDAC : {
|
||||
if(ins[4] == 0x00) {
|
||||
instru.DAC_type = EIS_HSDAC;
|
||||
} else if (ins[4] == 0x01) {
|
||||
instru.DAC_type = EIS_LPDAC;
|
||||
}
|
||||
HSDAC_GainControl(0x00); // fix HSDAC gain at default
|
||||
break;
|
||||
}
|
||||
case EIS_HSTIA : {
|
||||
instru.HSTIAGainLv = ins[4];
|
||||
if (instru.HSTIAGainLv != HSRTIA_GAIN_AUTO) {
|
||||
instru.HSTIAAutoGainEnable = 0;
|
||||
@@ -1062,7 +1073,7 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
HSTIAGainCtrl(instru.HSTIAGainLv);
|
||||
break;
|
||||
}
|
||||
case EIS_LPTIA : { // 0x01
|
||||
case EIS_LPTIA : {
|
||||
instru.LPTIAGainLv = ins[4];
|
||||
if (instru.LPTIAGainLv != LPRTIA_GAIN_AUTO) {
|
||||
instru.LPTIAAutoGainEnable = 0;
|
||||
@@ -1074,17 +1085,6 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
LPTIAGainCtrl(instru.LPTIAGainLv);
|
||||
break;
|
||||
}
|
||||
case EIS_DAC : { // 0x02
|
||||
if(ins[4] == 0x00) {
|
||||
instru.DAC_type = HSDACtype_DC;
|
||||
} else if (ins[4] == 0x01) {
|
||||
instru.DAC_type = LPDACtype_DC;
|
||||
} else if (ins[4] == 0x02) {
|
||||
instru.DAC_type = HSDACtype_AC;
|
||||
}
|
||||
HSDAC_GainControl(0x00); // fix HSDAC gain at default
|
||||
break;
|
||||
}
|
||||
default :{
|
||||
break;
|
||||
}
|
||||
@@ -1103,7 +1103,7 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
|
||||
case CURVE_CALI_ADC: {
|
||||
switch(ins[3]) {
|
||||
case IIN_ADC : { // 0x04
|
||||
case IIN_ADC : { // 0x05
|
||||
instru.eliteFxn = CURVE_CALI_ADC;
|
||||
instru.AdcChannel = IIN_ADC;
|
||||
instru.notifyRate = 1000;
|
||||
@@ -1112,7 +1112,7 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
ModeLED(WORKING);
|
||||
break;
|
||||
}
|
||||
case VIN_ADC : { // 0x05
|
||||
case VIN_ADC : { // 0x06
|
||||
instru.eliteFxn = CURVE_CALI_ADC;
|
||||
instru.AdcChannel = VIN_ADC;
|
||||
instru.notifyRate = 1000;
|
||||
@@ -1121,7 +1121,7 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
ModeLED(WORKING);
|
||||
break;
|
||||
}
|
||||
case VOUT_DAC : { // 0x03
|
||||
case VOUT_DAC : { // 0x04
|
||||
instru.eliteFxn = CURVE_CALI_ADC;
|
||||
instru.AdcChannel = VOUT_DAC;
|
||||
instru.notifyRate = 1000;
|
||||
@@ -1133,22 +1133,38 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
ModeLED(WORKING);
|
||||
break;
|
||||
}
|
||||
case EIS_HSDAC :{ // 0x02
|
||||
instru.eliteFxn = CURVE_CALI_ADC;
|
||||
instru.notifyRate = 1000;
|
||||
instru.sampleRate = 15;
|
||||
static int32_t LPvolt = 0;
|
||||
instru.VAmpSet = ((uint16_t)(ins[4]) << 8) | (uint16_t)(ins[5]);
|
||||
|
||||
if (instru.DAC_type == EIS_HSDAC) {
|
||||
instru.AdcChannel = EIS_HSDAC;
|
||||
HS_cali_config();
|
||||
HSDAC_output(instru.VAmpSet);
|
||||
// SetWGAmp(instru.VAmpSet); // sine wave generation usage
|
||||
} else if (instru.DAC_type == EIS_LPDAC) {
|
||||
instru.AdcChannel = EIS_LPDAC;
|
||||
LP_cali_config();
|
||||
LPvolt = ((int32_t)(ins[4]) << 8) | (int32_t)(ins[5]);
|
||||
LPvolt = (LPvolt - 25000) * 4 * 4000;
|
||||
DAC_outputV(LPvolt);
|
||||
}
|
||||
ModeLED(WORKING);
|
||||
break;
|
||||
}
|
||||
case EIS_HSTIA :{ // 0x00
|
||||
// instru.VAmpSet = ((uint16_t)(ins[4]) << 8) | (uint16_t)(ins[5]);
|
||||
// instru.DAC_type = HSDACtype_DC;
|
||||
// Cali_DAC_output(); // HSDAC output DC bias
|
||||
instru.eliteFxn = CURVE_CALI_ADC;
|
||||
instru.AdcChannel = EIS_HSTIA;
|
||||
instru.notifyRate = 1000;
|
||||
instru.sampleRate = 15;
|
||||
// HS_cali_config();
|
||||
HS_cali_config();
|
||||
ModeLED(WORKING);
|
||||
break;
|
||||
}
|
||||
case EIS_LPTIA :{ // 0x01
|
||||
// instru.VAmpSet = ((uint16_t)(ins[4]) << 8) | (uint16_t)(ins[5]);
|
||||
// instru.DAC_type = LPDACtype_DC;
|
||||
// Cali_DAC_output(); // LPDAC output DC bias
|
||||
instru.eliteFxn = CURVE_CALI_ADC;
|
||||
instru.AdcChannel = EIS_LPTIA;
|
||||
instru.notifyRate = 1000;
|
||||
@@ -1158,16 +1174,6 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
ModeLED(WORKING);
|
||||
break;
|
||||
}
|
||||
case EIS_DAC :{ // 0x02
|
||||
instru.eliteFxn = CURVE_CALI_ADC;
|
||||
instru.AdcChannel = EIS_DAC;
|
||||
instru.notifyRate = 1000;
|
||||
instru.sampleRate = 15;
|
||||
instru.VAmpSet = ((uint16_t)(ins[4]) << 8) | (uint16_t)(ins[5]);
|
||||
Cali_DAC_output();
|
||||
ModeLED(WORKING);
|
||||
break;
|
||||
}
|
||||
default : {
|
||||
break;
|
||||
}
|
||||
@@ -1457,19 +1463,6 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
LED_color(DARKLED, 0x80, 0x00, 0x80);
|
||||
break;
|
||||
}
|
||||
case cali_HSTIA_Iin: { // 0x65
|
||||
instru.VAmpSet = ((uint16_t)(ins[4]) << 8) | (uint16_t)(ins[5]);
|
||||
instru.DAC_type = HSDACtype_DC;
|
||||
Cali_DAC_output(); // HSDAC output DC bias
|
||||
|
||||
instru.eliteFxn = CURVE_CALI_ADC;
|
||||
instru.AdcChannel = EIS_HSTIA;
|
||||
instru.notifyRate = 1000;
|
||||
instru.sampleRate = 15;
|
||||
// HS_cali_config();
|
||||
ModeLED(WORKING);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1500,6 +1493,7 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
}
|
||||
|
||||
case VIS_STI: {
|
||||
time0 = (Timestamp_get32()) / 31;
|
||||
for(int i = 0; i < 12; i++) {
|
||||
FlushNotify();
|
||||
}
|
||||
|
||||
+3
-1
@@ -179,7 +179,9 @@ static void SimpleBLEPeripheral_performPeriodicTask(void) {
|
||||
SendNotify(); //send
|
||||
notify_flag = false;
|
||||
fset_flag = true;
|
||||
time_tester = 0;
|
||||
time0 = (Timestamp_get32()) / 31;
|
||||
time1 = 0;
|
||||
delta_time = 0;
|
||||
}
|
||||
|
||||
mode_done(); //finishMode = 1, SendNotify(), Eliteinterrupt()
|
||||
|
||||
Reference in New Issue
Block a user