[update] update Elite_mode_ADC_DAC file
This commit is contained in:
+52
-115
@@ -124,9 +124,10 @@ static void IinADCGainControl(uint8_t IinADCLevel){
|
||||
}else{
|
||||
lastIinADCGainLevel = 3;
|
||||
}
|
||||
record_flag = false;
|
||||
}
|
||||
|
||||
static void VinADCGainControl(uint8_t VinADCLevel){
|
||||
static void VinADCGainCtrl(uint8_t VinADCLevel){
|
||||
if(VinADCLevel == 0){
|
||||
// Vin ADC gain level = 0, using 1M resister
|
||||
PIN15_setOutputValue(Turnon_V_SMALL, 0);
|
||||
@@ -154,10 +155,11 @@ static void VinADCGainControl(uint8_t VinADCLevel){
|
||||
}
|
||||
|
||||
if(VinADCLevel == 0 || VinADCLevel == 1 || VinADCLevel == 2){
|
||||
lastVinADCGainLevel = VinADCLevel;
|
||||
lastVinADCGainLv = VinADCLevel;
|
||||
}else{
|
||||
lastVinADCGainLevel = 2;
|
||||
lastVinADCGainLv = 2;
|
||||
}
|
||||
record_flag = false;
|
||||
}
|
||||
|
||||
static void ADCChannelSelect(uint8_t ADCChannel){
|
||||
@@ -199,7 +201,6 @@ static void ADCChannelSelect(uint8_t ADCChannel){
|
||||
|
||||
static void ReadADCIin(uint8_t *buf){
|
||||
// Read data twice since the first data we get is previous data
|
||||
// IinADCGainControl(instru.ADCGainLevel);
|
||||
ADCChannelSelect(ADC_CH_CURRENT);
|
||||
ADC_read(buf);
|
||||
|
||||
@@ -210,7 +211,6 @@ static void ReadADCIin(uint8_t *buf){
|
||||
static void ReadADCVin(uint8_t *buf){
|
||||
// Read data twice since the first data we get is previous data
|
||||
|
||||
// VinADCGainControl(instru.VinADCGainLevel);
|
||||
ADCChannelSelect(ADC_CH_VOLT);
|
||||
ADC_read(buf);
|
||||
|
||||
@@ -259,20 +259,20 @@ static void ReadADCBat(uint8_t *buf){
|
||||
#define VIN_GAIN_MID1_BOUNDARY2 300000 // 300 mV = 300,000,000 nV
|
||||
#define VIN_GAIN_LARGE_BOUNDARY 250000 // 250 mV = 250,000,000 nV
|
||||
|
||||
static int32_t AutoGainReadIin(uint8_t *buf){
|
||||
static int32_t read_cali_Iin(uint8_t *buf){
|
||||
int32_t RealCurrent = 0;
|
||||
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
RealCurrent = DecodeADCValue(instru.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
RealCurrent = DecodeADCValue(instru.ADCGainLv, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
|
||||
return RealCurrent;
|
||||
}
|
||||
|
||||
static int32_t AutoGainReadVin(uint8_t *buf){
|
||||
static int32_t read_cali_Vin(uint8_t *buf){
|
||||
int32_t RealVolt = 0;
|
||||
|
||||
ReadADCVin(spi_ADC_rxbuf);
|
||||
RealVolt = DecodeADCValue(instru.VinADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
|
||||
RealVolt = DecodeADCValue(instru.VinADCGainLv, ADC_CH_VOLT, spi_ADC_rxbuf);
|
||||
|
||||
return RealVolt;
|
||||
}
|
||||
@@ -282,36 +282,33 @@ static void AutoGainChangeIin(int32_t RealCurrent){
|
||||
// switch to 2 level current 100K
|
||||
// switch to 3 level current 3K
|
||||
// switch to 4 level current(large) 100R
|
||||
if(instru.ADCGainLevel == I_GAIN_100R){
|
||||
if(instru.ADCGainLv == I_GAIN_100R){
|
||||
if(RealCurrent < I_GAIN_LARGE_BOUNDARY && RealCurrent > -1*I_GAIN_LARGE_BOUNDARY){
|
||||
// switch to 1 level current(small)
|
||||
if (RealCurrent < I_GAIN_MID1_BOUNDARY1 && RealCurrent > -1*I_GAIN_MID1_BOUNDARY1){
|
||||
I_GAIN_3M_counter++;
|
||||
if(I_GAIN_3M_counter > 2){
|
||||
instru.ADCGainLevel = I_GAIN_3M;
|
||||
IinADCGainControl(instru.ADCGainLevel);
|
||||
instru.ADCGainLv = I_GAIN_3M;
|
||||
IinADCGainControl(instru.ADCGainLv);
|
||||
I_GAIN_3M_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
// switch to 2 level current
|
||||
else if (RealCurrent < I_GAIN_MID2_BOUNDARY1 && RealCurrent > -1*I_GAIN_MID2_BOUNDARY1){
|
||||
I_GAIN_100K_counter++;
|
||||
if(I_GAIN_100K_counter > 2){
|
||||
instru.ADCGainLevel = I_GAIN_100K;
|
||||
IinADCGainControl(instru.ADCGainLevel);
|
||||
instru.ADCGainLv = I_GAIN_100K;
|
||||
IinADCGainControl(instru.ADCGainLv);
|
||||
I_GAIN_100K_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
// switch to 3 level current
|
||||
else{
|
||||
I_GAIN_3K_counter++;
|
||||
if(I_GAIN_3K_counter > 2){
|
||||
instru.ADCGainLevel = I_GAIN_3K;
|
||||
IinADCGainControl(instru.ADCGainLevel);
|
||||
instru.ADCGainLv = I_GAIN_3K;
|
||||
IinADCGainControl(instru.ADCGainLv);
|
||||
I_GAIN_3K_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
@@ -326,15 +323,14 @@ static void AutoGainChangeIin(int32_t RealCurrent){
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(instru.ADCGainLevel == I_GAIN_3K){
|
||||
else if(instru.ADCGainLv == I_GAIN_3K){
|
||||
// switch to 4 level current(large)
|
||||
if(RealCurrent > I_GAIN_MID2_BOUNDARY2 || RealCurrent < -1*I_GAIN_MID2_BOUNDARY2){
|
||||
I_GAIN_100R_counter++;
|
||||
if(I_GAIN_100R_counter > 2){
|
||||
instru.ADCGainLevel = I_GAIN_100R;
|
||||
IinADCGainControl(instru.ADCGainLevel);
|
||||
instru.ADCGainLv = I_GAIN_100R;
|
||||
IinADCGainControl(instru.ADCGainLv);
|
||||
I_GAIN_100R_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
else if (RealCurrent < I_GAIN_MID2_BOUNDARY1 && RealCurrent > -1*I_GAIN_MID2_BOUNDARY1){
|
||||
@@ -342,20 +338,18 @@ static void AutoGainChangeIin(int32_t RealCurrent){
|
||||
if(RealCurrent < I_GAIN_MID1_BOUNDARY1 && RealCurrent > -1*I_GAIN_MID1_BOUNDARY1){
|
||||
I_GAIN_3M_counter++;
|
||||
if(I_GAIN_3M_counter > 2){
|
||||
instru.ADCGainLevel = I_GAIN_3M;
|
||||
IinADCGainControl(instru.ADCGainLevel);
|
||||
instru.ADCGainLv = I_GAIN_3M;
|
||||
IinADCGainControl(instru.ADCGainLv);
|
||||
I_GAIN_3M_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
// switch to 2 level current
|
||||
else{
|
||||
I_GAIN_100K_counter++;
|
||||
if(I_GAIN_100K_counter > 2){
|
||||
instru.ADCGainLevel = I_GAIN_100K;
|
||||
IinADCGainControl(instru.ADCGainLevel);
|
||||
instru.ADCGainLv = I_GAIN_100K;
|
||||
IinADCGainControl(instru.ADCGainLv);
|
||||
I_GAIN_100K_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
@@ -370,15 +364,14 @@ static void AutoGainChangeIin(int32_t RealCurrent){
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(instru.ADCGainLevel == I_GAIN_100K){
|
||||
else if(instru.ADCGainLv == I_GAIN_100K){
|
||||
// switch to 1 level current(small)
|
||||
if(RealCurrent < I_GAIN_MID1_BOUNDARY1 && RealCurrent > -1*I_GAIN_MID1_BOUNDARY1){
|
||||
I_GAIN_3M_counter++;
|
||||
if(I_GAIN_3M_counter > 2){
|
||||
instru.ADCGainLevel = I_GAIN_3M;
|
||||
IinADCGainControl(instru.ADCGainLevel);
|
||||
instru.ADCGainLv = I_GAIN_3M;
|
||||
IinADCGainControl(instru.ADCGainLv);
|
||||
I_GAIN_3M_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
else if (RealCurrent > I_GAIN_MID1_BOUNDARY2 || RealCurrent < -1*I_GAIN_MID1_BOUNDARY2){
|
||||
@@ -386,20 +379,18 @@ static void AutoGainChangeIin(int32_t RealCurrent){
|
||||
if(RealCurrent > I_GAIN_MID2_BOUNDARY2 || RealCurrent < -1*I_GAIN_MID2_BOUNDARY2){
|
||||
I_GAIN_100R_counter++;
|
||||
if(I_GAIN_100R_counter > 2){
|
||||
instru.ADCGainLevel = I_GAIN_100R;
|
||||
IinADCGainControl(instru.ADCGainLevel);
|
||||
instru.ADCGainLv = I_GAIN_100R;
|
||||
IinADCGainControl(instru.ADCGainLv);
|
||||
I_GAIN_100R_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
// switch to 3 level current
|
||||
else{
|
||||
I_GAIN_3K_counter++;
|
||||
if(I_GAIN_3K_counter > 2){
|
||||
instru.ADCGainLevel = I_GAIN_3K;
|
||||
IinADCGainControl(instru.ADCGainLevel);
|
||||
instru.ADCGainLv = I_GAIN_3K;
|
||||
IinADCGainControl(instru.ADCGainLv);
|
||||
I_GAIN_3K_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
@@ -414,36 +405,33 @@ static void AutoGainChangeIin(int32_t RealCurrent){
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(instru.ADCGainLevel == I_GAIN_3M){
|
||||
else if(instru.ADCGainLv == I_GAIN_3M){
|
||||
if(RealCurrent > I_GAIN_SMALL_BOUNDARY || RealCurrent < -1*I_GAIN_SMALL_BOUNDARY){
|
||||
// switch to 4 level current(large)
|
||||
if(RealCurrent > I_GAIN_MID2_BOUNDARY2 || RealCurrent < -1*I_GAIN_MID2_BOUNDARY2){
|
||||
I_GAIN_100R_counter++;
|
||||
if(I_GAIN_100R_counter > 2){
|
||||
instru.ADCGainLevel = I_GAIN_100R;
|
||||
IinADCGainControl(instru.ADCGainLevel);
|
||||
instru.ADCGainLv = I_GAIN_100R;
|
||||
IinADCGainControl(instru.ADCGainLv);
|
||||
I_GAIN_100R_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
// switch to 3 level current
|
||||
else if(RealCurrent > I_GAIN_MID1_BOUNDARY2 || RealCurrent < -1*I_GAIN_MID1_BOUNDARY2){
|
||||
I_GAIN_3K_counter++;
|
||||
if(I_GAIN_3K_counter > 2){
|
||||
instru.ADCGainLevel = I_GAIN_3K;
|
||||
IinADCGainControl(instru.ADCGainLevel);
|
||||
instru.ADCGainLv = I_GAIN_3K;
|
||||
IinADCGainControl(instru.ADCGainLv);
|
||||
I_GAIN_3K_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
// switch to 2 level current
|
||||
else{
|
||||
I_GAIN_100K_counter++;
|
||||
if(I_GAIN_100K_counter > 2){
|
||||
instru.ADCGainLevel = I_GAIN_100K;
|
||||
IinADCGainControl(instru.ADCGainLevel);
|
||||
instru.ADCGainLv = I_GAIN_100K;
|
||||
IinADCGainControl(instru.ADCGainLv);
|
||||
I_GAIN_100K_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -465,26 +453,24 @@ static void AutoGainChangeVin(int32_t RealVin){
|
||||
// switch to 1 level volt(small) 1M
|
||||
// switch to 2 level volt 30K
|
||||
// switch to 3 level volt(large) 1K
|
||||
if(instru.VinADCGainLevel == VIN_GAIN_1M){
|
||||
if(instru.VinADCGainLv == VIN_GAIN_1M){
|
||||
if(RealVin > VIN_GAIN_SMALL_BOUNDARY || RealVin < -1*VIN_GAIN_SMALL_BOUNDARY){
|
||||
// switch to 3 level volt(large)
|
||||
if (RealVin > VIN_GAIN_MID1_BOUNDARY2 || RealVin < -1*VIN_GAIN_MID1_BOUNDARY2){
|
||||
VIN_GAIN_1K_counter++;
|
||||
if(VIN_GAIN_1K_counter > 2){
|
||||
instru.VinADCGainLevel = VIN_GAIN_1K;
|
||||
VinADCGainControl(instru.VinADCGainLevel);
|
||||
instru.VinADCGainLv = VIN_GAIN_1K;
|
||||
VinADCGainCtrl(instru.VinADCGainLv);
|
||||
VIN_GAIN_1K_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
// switch to 2 level volt
|
||||
else{
|
||||
VIN_GAIN_30K_counter++;
|
||||
if(VIN_GAIN_30K_counter > 2){
|
||||
instru.VinADCGainLevel = VIN_GAIN_30K;
|
||||
VinADCGainControl(instru.VinADCGainLevel);
|
||||
instru.VinADCGainLv = VIN_GAIN_30K;
|
||||
VinADCGainCtrl(instru.VinADCGainLv);
|
||||
VIN_GAIN_30K_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
@@ -496,25 +482,23 @@ static void AutoGainChangeVin(int32_t RealVin){
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(instru.VinADCGainLevel == VIN_GAIN_30K){
|
||||
else if(instru.VinADCGainLv == VIN_GAIN_30K){
|
||||
// switch to 1 level volt(small)
|
||||
if(RealVin < VIN_GAIN_MID1_BOUNDARY1 && RealVin > -1*VIN_GAIN_MID1_BOUNDARY1){
|
||||
VIN_GAIN_1M_counter++;
|
||||
if(VIN_GAIN_1M_counter > 2){
|
||||
instru.VinADCGainLevel = VIN_GAIN_1M;
|
||||
VinADCGainControl(instru.VinADCGainLevel);
|
||||
instru.VinADCGainLv = VIN_GAIN_1M;
|
||||
VinADCGainCtrl(instru.VinADCGainLv);
|
||||
VIN_GAIN_1M_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
else if (RealVin > VIN_GAIN_MID1_BOUNDARY2 || RealVin < -1*VIN_GAIN_MID1_BOUNDARY2){
|
||||
// switch to 3 level volt
|
||||
VIN_GAIN_1K_counter++;
|
||||
if(VIN_GAIN_1K_counter > 2){
|
||||
instru.VinADCGainLevel = VIN_GAIN_1K;
|
||||
VinADCGainControl(instru.VinADCGainLevel);
|
||||
instru.VinADCGainLv = VIN_GAIN_1K;
|
||||
VinADCGainCtrl(instru.VinADCGainLv);
|
||||
VIN_GAIN_1K_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}else{
|
||||
if(VIN_GAIN_1K_counter > 0){
|
||||
@@ -525,26 +509,24 @@ static void AutoGainChangeVin(int32_t RealVin){
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(instru.VinADCGainLevel == VIN_GAIN_1K){
|
||||
else if(instru.VinADCGainLv == VIN_GAIN_1K){
|
||||
if(RealVin < VIN_GAIN_LARGE_BOUNDARY && RealVin > -1*VIN_GAIN_LARGE_BOUNDARY){
|
||||
// switch to 1 level volt(small)
|
||||
if (RealVin < VIN_GAIN_MID1_BOUNDARY1 && RealVin > -1*VIN_GAIN_MID1_BOUNDARY1){
|
||||
VIN_GAIN_1M_counter++;
|
||||
if(VIN_GAIN_1M_counter > 2){
|
||||
instru.VinADCGainLevel = VIN_GAIN_1M;
|
||||
VinADCGainControl(instru.VinADCGainLevel);
|
||||
instru.VinADCGainLv = VIN_GAIN_1M;
|
||||
VinADCGainCtrl(instru.VinADCGainLv);
|
||||
VIN_GAIN_1M_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
// switch to 2 level volt
|
||||
else{
|
||||
VIN_GAIN_30K_counter++;
|
||||
if(VIN_GAIN_30K_counter > 2){
|
||||
instru.VinADCGainLevel = VIN_GAIN_30K;
|
||||
VinADCGainControl(instru.VinADCGainLevel);
|
||||
instru.VinADCGainLv = VIN_GAIN_30K;
|
||||
VinADCGainCtrl(instru.VinADCGainLv);
|
||||
VIN_GAIN_30K_counter = 0;
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
@@ -558,49 +540,4 @@ static void AutoGainChangeVin(int32_t RealVin){
|
||||
}
|
||||
}
|
||||
|
||||
static uint16_t ADC_CURRENT_AVG_calibration (uint8_t ADC_channel) {
|
||||
uint32_t ADCValueTemp = 0;
|
||||
uint32_t ADCValueSUM = 0;
|
||||
uint32_t ADCValueAVG = 0;
|
||||
uint16_t ADCValueAVG_RAW = 0;
|
||||
#define avgcount 10000
|
||||
|
||||
// Red light for start acquiring data
|
||||
Elite_led_color(COLOR_RED);
|
||||
// CPUdelay(10);
|
||||
for(int i=0; i<avgcount; i++){
|
||||
CAL_ADC_write(ADC_channel);
|
||||
CAL_ADC_read(spi_ADC_rxbuf);
|
||||
CPUdelay(10);
|
||||
CAL_ADC_write(ADC_channel);
|
||||
CAL_ADC_read(spi_ADC_rxbuf);
|
||||
CPUdelay(500);
|
||||
|
||||
ADCValueTemp = 0x0000FFFF & (((uint32_t) (spi_ADC_rxbuf[0]) << 8) | ((uint32_t) (spi_ADC_rxbuf[1])));
|
||||
ADCValueSUM = ADCValueSUM + ADCValueTemp;
|
||||
}
|
||||
|
||||
ADCValueAVG = ADCValueSUM / avgcount;
|
||||
ADCValueAVG_RAW = (uint16_t) (ADCValueAVG & 0x0000FFFF);
|
||||
|
||||
// Blue light for data acquire done
|
||||
Elite_led_color(COLOR_BLUE);
|
||||
|
||||
if (ADCValueAVG_RAW > 0x7FFF) {
|
||||
ADCValueAVG_RAW = 0x0000;
|
||||
}
|
||||
|
||||
// clean data
|
||||
ADCValueAVG = 0;
|
||||
ADCValueSUM = 0;
|
||||
ADCValueTemp = 0;
|
||||
|
||||
// // Blue light for data acquire done
|
||||
// Elite_led_color(COLOR_BLUE);
|
||||
|
||||
|
||||
|
||||
return ADCValueAVG_RAW;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+1
-3
@@ -73,6 +73,7 @@ static void VoutGainControl(uint8_t VOUTLevel){
|
||||
// default using 15K resister
|
||||
PIN15_setOutputValue(Turon_VOUT_SMALL, 1);
|
||||
}
|
||||
record_flag = false;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -97,7 +98,6 @@ static void AutoGainChangeVout(int32_t userCode){
|
||||
if(instru.VoutGainLevel == VOUT_GAIN_AUTO){
|
||||
instru.VoutGainLevel = VOUT_GAIN_15K;
|
||||
VoutGainControl(instru.VoutGainLevel);
|
||||
record_flag = false;
|
||||
}
|
||||
|
||||
if(instru.VoutGainLevel == VOUT_GAIN_15K){
|
||||
@@ -105,7 +105,6 @@ static void AutoGainChangeVout(int32_t userCode){
|
||||
// switch to 2 level volt(large)
|
||||
instru.VoutGainLevel = VOUT_GAIN_240K;
|
||||
VoutGainControl(instru.VoutGainLevel);
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
else if(instru.VoutGainLevel == VOUT_GAIN_240K){
|
||||
@@ -113,7 +112,6 @@ static void AutoGainChangeVout(int32_t userCode){
|
||||
// switch to 1 level volt(small)
|
||||
instru.VoutGainLevel = VOUT_GAIN_15K;
|
||||
VoutGainControl(instru.VoutGainLevel);
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -32,10 +32,10 @@ struct HEADSTAGE_INSTRUCTION {
|
||||
uint8_t AutoGainEnable;
|
||||
uint8_t VinAutoGainEnable;
|
||||
uint8_t VoutAutoGainEnable;
|
||||
uint8_t ADCGainLevel;
|
||||
uint8_t ADCGainLv;
|
||||
// voltage output gain
|
||||
uint16_t VoutGainLevel;
|
||||
uint8_t VinADCGainLevel;
|
||||
uint8_t VinADCGainLv;
|
||||
|
||||
/** Notify parameter **/
|
||||
uint32_t notifyRate;
|
||||
@@ -129,9 +129,9 @@ static void InitEliteInstruction(){
|
||||
instru.AutoGainEnable = 1;
|
||||
instru.VinAutoGainEnable = 1;
|
||||
instru.VoutAutoGainEnable = 1;
|
||||
instru.ADCGainLevel = I_GAIN_AUTO;
|
||||
instru.ADCGainLv = I_GAIN_AUTO;
|
||||
instru.VoutGainLevel = VOUT_GAIN_AUTO;
|
||||
instru.VinADCGainLevel = VIN_GAIN_AUTO;
|
||||
instru.VinADCGainLv = VIN_GAIN_AUTO;
|
||||
instru.notifyRate = STEPTIME_ONE_SEC;
|
||||
instru.cycleNumber = 1;
|
||||
instru.charge = 1; //0:discharge 1:charge
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ static void reset() {
|
||||
|
||||
PIN15_setOutputValue(HIGH_Z_MODE, 0); // HIGH Z MODE // 1: close; 0: open;
|
||||
|
||||
VinADCGainControl(VIN_GAIN_AUTO);
|
||||
VinADCGainCtrl(VIN_GAIN_AUTO);
|
||||
IinADCGainControl(I_GAIN_AUTO);
|
||||
|
||||
instru.VoutGainLevel = VOUT_GAIN_15K;
|
||||
|
||||
+282
-276
@@ -26,7 +26,9 @@ static void volt_out() {
|
||||
DACOutCode = Usercode_Correction_to_DAC(instru.VoutGainLevel, instru.VoltConstant);
|
||||
DAC_outputV(DACOutCode);
|
||||
|
||||
if ((instru.eliteFxn == CURVE_IV)||(instru.eliteFxn == CURVE_IV_CY)||(instru.eliteFxn == CURVE_CC)){
|
||||
if ((instru.eliteFxn == CURVE_IV) ||
|
||||
(instru.eliteFxn == CURVE_CC) ||
|
||||
(instru.eliteFxn == CURVE_IV_CY)) {
|
||||
int32_t RealV;
|
||||
RealV = (int32_t)(Vout / 200);//[1uV]
|
||||
InputNotify(NOTIFY_IMPEDANCE, RealV);
|
||||
@@ -99,290 +101,273 @@ static void DACenable(uint8_t afterRead){
|
||||
}
|
||||
}
|
||||
|
||||
static void CC_Plot(void)
|
||||
static void read_Iin_put_buf(void)
|
||||
{
|
||||
static uint8_t ADCSwitch = 0;
|
||||
static uint8_t BatSwitch = 0;
|
||||
static int32_t VoltData = 0;
|
||||
static uint8_t rec_cnt = 0;
|
||||
void *wm = wm_get();
|
||||
|
||||
if (instru.AutoGainEnable > 1 || instru.AutoGainEnable < 0)
|
||||
return;
|
||||
|
||||
/* read Iin and do NOT buffer the Iin after changing gain twice */
|
||||
MEAS_CURR(wm) = read_cali_Iin(spi_ADC_rxbuf);
|
||||
if (instru.AutoGainEnable) {
|
||||
AutoGainChangeIin(MEAS_CURR(wm));
|
||||
} else {
|
||||
if (lastIinADCGainLevel != instru.ADCGainLv) {
|
||||
IinADCGainControl(instru.ADCGainLv);
|
||||
}
|
||||
}
|
||||
|
||||
if (record_flag == false) {
|
||||
rec_cnt++;
|
||||
} else {
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
}
|
||||
|
||||
if (rec_cnt == 2) {
|
||||
record_flag = true;
|
||||
rec_cnt = 0;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void read_Vin_put_buf(void)
|
||||
{
|
||||
static uint8_t rec_cnt = 0;
|
||||
void *wm = wm_get();
|
||||
|
||||
if (instru.AutoGainEnable > 1 || instru.AutoGainEnable < 0)
|
||||
return;
|
||||
|
||||
/* read Vin and do NOT buffer the Vin after changing gain twice */
|
||||
MEAS_VIN(wm) = read_cali_Vin(spi_ADC_rxbuf);
|
||||
if (instru.VinAutoGainEnable) {
|
||||
AutoGainChangeVin(MEAS_VIN(wm));
|
||||
} else {
|
||||
if (lastVinADCGainLv != instru.VinADCGainLv) {
|
||||
VinADCGainCtrl(instru.VinADCGainLv);
|
||||
}
|
||||
}
|
||||
|
||||
if (record_flag == false) {
|
||||
rec_cnt++;
|
||||
} else {
|
||||
if (instru.VoViSwitch == 0x02) {
|
||||
int32_t Vscan = (Vset / 200 - MEAS_VIN(wm));
|
||||
Vscan = (int32_t)(Vscan);//[1uV]
|
||||
InputNotify(NOTIFY_VOLT, Vscan);
|
||||
} else {
|
||||
InputNotify(NOTIFY_VOLT, MEAS_VIN(wm));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (rec_cnt == 2) {
|
||||
record_flag = true;
|
||||
rec_cnt = 0;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void CC_Plot(void)
|
||||
{
|
||||
static uint8_t ADC_cnt = 0;
|
||||
static uint8_t BatSwitch = 0;
|
||||
void *wm = wm_get();
|
||||
|
||||
/* the time for measuring battery */
|
||||
if (batteryCheck_flag) {
|
||||
if (BatSwitch == 0) {
|
||||
if (ADCSwitch == 0) { /**read Iin(buffer),read bat**/
|
||||
if (instru.AutoGainEnable) {
|
||||
MEAS_CURR(wm) = AutoGainReadIin(spi_ADC_rxbuf);
|
||||
AutoGainChangeIin(MEAS_CURR(wm));
|
||||
} else {
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
MEAS_CURR(wm) = DecodeADCValue(instru.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
if (lastIinADCGainLevel != instru.ADCGainLevel) {
|
||||
IinADCGainControl(instru.ADCGainLevel);
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
if (record_flag == false) {
|
||||
static int recordCount = 0;
|
||||
recordCount++;
|
||||
if (recordCount == 2) {
|
||||
record_flag = true;
|
||||
recordCount = 0;
|
||||
}
|
||||
} else {
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
}
|
||||
if (ADC_cnt == 0) { /**read Iin(buffer),read bat**/
|
||||
read_Iin_put_buf();
|
||||
DACenable(AFTER_READ_I);
|
||||
|
||||
ReadADCBat(spi_ADC_rxbuf);
|
||||
BatSwitch++;
|
||||
} else if(ADCSwitch == 1 || ADCSwitch == 3) { /**read Bat**/
|
||||
ReadADCBat(spi_ADC_rxbuf);
|
||||
BatSwitch++;
|
||||
} else if(ADCSwitch == 2) { /**read V(buffer),read bat**/
|
||||
if (VOLT_SW(wm) == 0x01 || VOLT_SW(wm) == 0x02) {
|
||||
if (instru.VinAutoGainEnable) {
|
||||
MEAS_VIN(wm) = AutoGainReadVin(spi_ADC_rxbuf);
|
||||
AutoGainChangeVin(MEAS_VIN(wm));
|
||||
} else {
|
||||
ReadADCVolt(VOLT_SW(wm));
|
||||
MEAS_VIN(wm) = DecodeADCValue(instru.VinADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
|
||||
if (lastVinADCGainLevel != instru.VinADCGainLevel) {
|
||||
VinADCGainControl(instru.VinADCGainLevel);
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
VoltData = MEAS_VIN(wm);
|
||||
} else if (VOLT_SW(wm) == 0x00) {
|
||||
ReadADCVolt(VOLT_SW(wm));
|
||||
MEAS_VOUT(wm) = DecodeADCValue(instru.ADCGainLevel, ADC_CH_DAC, spi_ADC_rxbuf);
|
||||
VoltData = MEAS_VOUT(wm);
|
||||
}
|
||||
|
||||
if (instru.VoViSwitch == 0x02) {
|
||||
int32_t Vscan = (Vset / 200 - MEAS_VIN(wm));
|
||||
Vscan = (int32_t)(Vscan);//[1uV]
|
||||
InputNotify(NOTIFY_VOLT, Vscan);
|
||||
} else {
|
||||
InputNotify(NOTIFY_VOLT, VoltData);
|
||||
}
|
||||
} else if (ADC_cnt == 1 || ADC_cnt == 3) { /**read Bat**/
|
||||
ReadADCBat(spi_ADC_rxbuf);
|
||||
|
||||
} else if (ADC_cnt == 2) { /**read V(buffer),read bat**/
|
||||
read_Vin_put_buf();
|
||||
DACenable(AFTER_READ_V);
|
||||
|
||||
ReadADCBat(spi_ADC_rxbuf);
|
||||
BatSwitch++;
|
||||
}
|
||||
} else if(BatSwitch == 1) {
|
||||
BatSwitch++;
|
||||
|
||||
} else if (BatSwitch == 1) {
|
||||
ReadADCBat(spi_ADC_rxbuf);
|
||||
BatSwitch++;
|
||||
} else if(BatSwitch == 2) {
|
||||
|
||||
} else if (BatSwitch == 2) {
|
||||
headstage_battery_volt();
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
batteryCheck_flag = false;
|
||||
BatSwitch = 0;
|
||||
ADCSwitch = 3;
|
||||
ADC_cnt = 3;
|
||||
}
|
||||
} else {
|
||||
BatSwitch = 0;
|
||||
if (ADCSwitch == 0) { /**read Iin(buffer),read V**/
|
||||
if (instru.AutoGainEnable) {
|
||||
MEAS_CURR(wm) = AutoGainReadIin(spi_ADC_rxbuf);
|
||||
AutoGainChangeIin(MEAS_CURR(wm));
|
||||
} else {
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
MEAS_CURR(wm) = DecodeADCValue(instru.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
if (lastIinADCGainLevel != instru.ADCGainLevel) {
|
||||
IinADCGainControl(instru.ADCGainLevel);
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
if (record_flag == false) {
|
||||
static int recordCount = 0;
|
||||
recordCount++;
|
||||
if (recordCount == 2) {
|
||||
record_flag = true;
|
||||
recordCount = 0;
|
||||
}
|
||||
} else {
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
}
|
||||
DACenable(AFTER_READ_I);
|
||||
|
||||
ReadADCVolt(VOLT_SW(wm));
|
||||
ADCSwitch++;
|
||||
} else if(ADCSwitch == 1) { /**read V**/
|
||||
ReadADCVolt(VOLT_SW(wm));
|
||||
ADCSwitch++;
|
||||
} else if(ADCSwitch == 2) { /**read V(buffer),read Iin**/
|
||||
if (VOLT_SW(wm) == 0x01 || VOLT_SW(wm) == 0x02) {
|
||||
if (instru.VinAutoGainEnable) {
|
||||
MEAS_VIN(wm) = AutoGainReadVin(spi_ADC_rxbuf);
|
||||
AutoGainChangeVin(MEAS_VIN(wm));
|
||||
} else {
|
||||
ReadADCVolt(VOLT_SW(wm));
|
||||
MEAS_VIN(wm) = DecodeADCValue(instru.VinADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
|
||||
if (lastVinADCGainLevel != instru.VinADCGainLevel) {
|
||||
VinADCGainControl(instru.VinADCGainLevel);
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
VoltData = MEAS_VIN(wm);
|
||||
} else if (VOLT_SW(wm) == 0x00) {
|
||||
ReadADCVolt(VOLT_SW(wm));
|
||||
MEAS_VOUT(wm) = DecodeADCValue(instru.ADCGainLevel, ADC_CH_DAC, spi_ADC_rxbuf);
|
||||
VoltData = MEAS_VOUT(wm);
|
||||
}
|
||||
|
||||
if (instru.VoViSwitch == 0x02) {
|
||||
int32_t Vscan = (Vset / 200 - MEAS_VIN(wm));
|
||||
Vscan = (int32_t)(Vscan);//[1uV]
|
||||
InputNotify(NOTIFY_VOLT, Vscan);
|
||||
} else {
|
||||
InputNotify(NOTIFY_VOLT, VoltData);
|
||||
}
|
||||
DACenable(AFTER_READ_V);
|
||||
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
ADCSwitch++;
|
||||
} else if (ADCSwitch == 3) { /**read Iin**/
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
ADCSwitch = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* the time for Not measuring battery */
|
||||
/* ADC_cnt: 0 - read Iin and do NOT buffer the Iin after changing gain twice,
|
||||
* and output DAC, and read Vin, and increase ADC_cnt
|
||||
* 1 - read Vin and increase ADC_cnt
|
||||
* 2 - read Vin and do NOT buffer the Vin after changing gain twice,
|
||||
* and output DAC, and read Iin, and increase ADC_cnt
|
||||
* 3 - read Iin and reset ADC_cnt
|
||||
*/
|
||||
BatSwitch = 0;
|
||||
if (ADC_cnt == 0) {
|
||||
read_Iin_put_buf();
|
||||
DACenable(AFTER_READ_I);
|
||||
ReadADCVolt(VOLT_SW(wm));
|
||||
ADC_cnt++;
|
||||
|
||||
} else if (ADC_cnt == 1) {
|
||||
ReadADCVolt(VOLT_SW(wm));
|
||||
ADC_cnt++;
|
||||
|
||||
} else if (ADC_cnt == 2) {
|
||||
read_Vin_put_buf();
|
||||
DACenable(AFTER_READ_V);
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
ADC_cnt++;
|
||||
|
||||
} else if (ADC_cnt == 3) {
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
ADC_cnt = 0;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void IT_Plot(void)
|
||||
{
|
||||
static uint8_t ADCSwitch = 0;
|
||||
static uint8_t ADC_cnt = 0;
|
||||
void *wm = wm_get();
|
||||
|
||||
/* measure battery if needs */
|
||||
if (batteryCheck_flag) {
|
||||
EliteADCBattery();
|
||||
if (!batteryCheck_flag) {
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
ADCSwitch = 2;
|
||||
}
|
||||
} else {
|
||||
if (ADCSwitch == 0) { /**read Iin(buffer)**/
|
||||
if (instru.AutoGainEnable) {
|
||||
MEAS_CURR(wm) = AutoGainReadIin(spi_ADC_rxbuf);
|
||||
AutoGainChangeIin(MEAS_CURR(wm));
|
||||
} else {
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
MEAS_CURR(wm) = DecodeADCValue(instru.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
if (lastIinADCGainLevel != instru.ADCGainLevel) {
|
||||
IinADCGainControl(instru.ADCGainLevel);
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
if (record_flag == false) {
|
||||
static int recordCount = 0;
|
||||
recordCount++;
|
||||
if (recordCount == 2) {
|
||||
record_flag = true;
|
||||
recordCount = 0;
|
||||
}
|
||||
} else {
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
}
|
||||
ADCSwitch++;
|
||||
} else if (ADCSwitch == 1) { /**read Iin**/
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
ADCSwitch++;
|
||||
} else if(ADCSwitch == 2) { /**read Iin**/
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
ADCSwitch = 0;
|
||||
ADC_cnt = 2;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* ADC_cnt: 0 - read Iin and do NOT buffer the Iin after changing gain twice
|
||||
* 1 - read Iin and increase ADC_cnt
|
||||
* 2 - read Iin and reset ADC_cnt
|
||||
*/
|
||||
if (ADC_cnt == 0) {
|
||||
read_Iin_put_buf();
|
||||
ADC_cnt++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ADC_cnt == 1) {
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
ADC_cnt++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(ADC_cnt == 2) {
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
ADC_cnt = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
static void VT_Plot(void)
|
||||
{
|
||||
static uint8_t ADCSwitch = 0;
|
||||
static int32_t VoltData;
|
||||
static uint8_t ADC_cnt = 0;
|
||||
void *wm = wm_get();
|
||||
|
||||
/* measure battery if needs */
|
||||
if (batteryCheck_flag) {
|
||||
EliteADCBattery();
|
||||
if (!batteryCheck_flag) {
|
||||
ReadADCVolt(VOLT_SW(wm));
|
||||
ADCSwitch = 2;
|
||||
ReadADCVin(spi_ADC_rxbuf);
|
||||
ADC_cnt = 2;
|
||||
}
|
||||
} else {
|
||||
if (ADCSwitch == 0) { /**read V(buffer)**/
|
||||
if (VOLT_SW(wm) == 0x01 || VOLT_SW(wm) == 0x02) {
|
||||
if (instru.VinAutoGainEnable) {
|
||||
MEAS_VIN(wm) = AutoGainReadVin(spi_ADC_rxbuf);
|
||||
AutoGainChangeVin(MEAS_VIN(wm));
|
||||
} else {
|
||||
ReadADCVolt(VOLT_SW(wm));
|
||||
MEAS_VIN(wm) = DecodeADCValue(instru.VinADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
|
||||
|
||||
if (lastVinADCGainLevel != instru.VinADCGainLevel) {
|
||||
VinADCGainControl(instru.VinADCGainLevel);
|
||||
record_flag = false;
|
||||
}
|
||||
}
|
||||
VoltData = MEAS_VIN(wm);
|
||||
} else if (VOLT_SW(wm) == 0x00) {
|
||||
ReadADCVolt(VOLT_SW(wm));
|
||||
MEAS_VOUT(wm) = DecodeADCValue(instru.ADCGainLevel, ADC_CH_DAC, spi_ADC_rxbuf);
|
||||
VoltData = MEAS_VOUT(wm);
|
||||
}
|
||||
|
||||
if (record_flag == false) {
|
||||
static int recordCount = 0;
|
||||
recordCount++;
|
||||
if (recordCount == 2) {
|
||||
record_flag = true;
|
||||
recordCount = 0;
|
||||
}
|
||||
} else {
|
||||
InputNotify(NOTIFY_VOLT, VoltData);
|
||||
}
|
||||
ADCSwitch++;
|
||||
} else if (ADCSwitch == 1) { /**read V**/
|
||||
ReadADCVolt(VOLT_SW(wm));
|
||||
ADCSwitch++;
|
||||
} else if (ADCSwitch == 2) { /**read V**/
|
||||
ReadADCVolt(VOLT_SW(wm));
|
||||
ADCSwitch = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* 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 (ADC_cnt == 0) {
|
||||
read_Vin_put_buf();
|
||||
ADC_cnt++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ADC_cnt == 1) {
|
||||
ReadADCVin(spi_ADC_rxbuf);
|
||||
ADC_cnt++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ADC_cnt == 2) {
|
||||
ReadADCVin(spi_ADC_rxbuf);
|
||||
ADC_cnt = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void cali_IT_plot(void) {
|
||||
void *wm = wm_get();
|
||||
|
||||
static uint8_t ADCSwitch = 0;
|
||||
static int32_t ADCValueSUM = 0;
|
||||
int32_t ADCValueAVG = 0;
|
||||
static uint16_t cali_count_max = 1000;
|
||||
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 = 0;
|
||||
int32_t ADCValueAVG = 0;
|
||||
|
||||
if(ADCSwitch == 0){ /**read Iin(buffer)**/
|
||||
if(instru.AutoGainEnable){
|
||||
/* ADC_cnt: 0 - read Iin and do NOT buffer the Iin after changing gain twice
|
||||
* 1 - read Iin and increase ADC_cnt
|
||||
* 2 - read Iin and reset ADC_cnt
|
||||
*/
|
||||
if (ADC_cnt == 0) {
|
||||
if (instru.AutoGainEnable) {
|
||||
MEAS_CURR(wm) = 0xFFFF;
|
||||
}else{
|
||||
} else {
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
MEAS_CURR(wm) = (int32_t) (spi_ADC_rxbuf[0] << 8) | (int32_t) (spi_ADC_rxbuf[1]);
|
||||
if(lastIinADCGainLevel != instru.ADCGainLevel){
|
||||
IinADCGainControl(instru.ADCGainLevel);
|
||||
record_flag = false;
|
||||
if (lastIinADCGainLevel != instru.ADCGainLv) {
|
||||
IinADCGainControl(instru.ADCGainLv);
|
||||
}
|
||||
}
|
||||
if(instru.ADCGainLevel == 0) {
|
||||
|
||||
if (instru.ADCGainLv == 0) {
|
||||
cali_count_max = 5000;
|
||||
} else {
|
||||
cali_count_max = 1000;
|
||||
}
|
||||
|
||||
if(record_flag == false){
|
||||
static int recordCount = 0;
|
||||
recordCount++;
|
||||
if(recordCount == 2){
|
||||
record_flag = true;
|
||||
recordCount = 0;
|
||||
}
|
||||
}else{
|
||||
static uint16_t cali_count = 0;
|
||||
if(cali_count >= cali_count_max){
|
||||
if (record_flag == false) {
|
||||
rec_cnt++;
|
||||
} else {
|
||||
if (cali_count >= cali_count_max) {
|
||||
ADCValueAVG = ADCValueSUM / cali_count;
|
||||
|
||||
InputNotify(NOTIFY_CURRENT, ADCValueAVG);
|
||||
@@ -393,75 +378,81 @@ static void cali_IT_plot(void) {
|
||||
CIS_buf[1] = (uint8_t) ((ADCValueAVG & 0xFF00) >> 8);
|
||||
CIS_buf[2] = (uint8_t) (ADCValueAVG & 0x00FF);
|
||||
CIS_buf[3] = 0x00;
|
||||
CIS_buf[4] = instru.ADCGainLevel;
|
||||
CIS_buf[4] = instru.ADCGainLv;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 9, CIS_buf);
|
||||
ADCValueSUM = 0;
|
||||
cali_count = 0;
|
||||
|
||||
PeriodicEvent = false;
|
||||
ADCValueSUM = 0;
|
||||
cali_count = 0;
|
||||
ModeLED(NO_EVENT);
|
||||
}else{
|
||||
} else {
|
||||
cali_count++;
|
||||
ADCValueSUM = ADCValueSUM + MEAS_CURR(wm);
|
||||
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
|
||||
InputNotify(NOTIFY_VOLT, ADCValueSUM);
|
||||
InputNotify(NOTIFY_IMPEDANCE, (int32_t)cali_count);
|
||||
}
|
||||
|
||||
}
|
||||
ADCSwitch++;
|
||||
|
||||
if (rec_cnt == 2) {
|
||||
record_flag = true;
|
||||
rec_cnt = 0;
|
||||
}
|
||||
ADC_cnt++;
|
||||
|
||||
return;
|
||||
}
|
||||
else if(ADCSwitch == 1){ /**read Iin**/
|
||||
|
||||
if (ADC_cnt == 1) {
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
ADCSwitch++;
|
||||
ADC_cnt++;
|
||||
|
||||
return;
|
||||
}
|
||||
else if(ADCSwitch == 2){ /**read Iin**/
|
||||
|
||||
if (ADC_cnt == 2) {
|
||||
ReadADCIin(spi_ADC_rxbuf);
|
||||
ADCSwitch = 0;
|
||||
ADC_cnt = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void cali_VT_plot(void) {
|
||||
void *wm = wm_get();
|
||||
|
||||
static uint8_t ADCSwitch = 0;
|
||||
static int32_t VoltData = 0;
|
||||
static int32_t ADCValueSUM = 0;
|
||||
int32_t ADCValueAVG = 0;
|
||||
static uint16_t cali_count_max = 1000;
|
||||
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 = 0;
|
||||
int32_t ADCValueAVG = 0;
|
||||
|
||||
if(ADCSwitch == 0){ /**read Iin(buffer)**/
|
||||
if(VOLT_SW(wm) == 0x01 || VOLT_SW(wm) == 0x02){
|
||||
if(instru.VinAutoGainEnable){
|
||||
MEAS_VIN(wm) = 0xFFFF;
|
||||
}else{
|
||||
ReadADCVolt(VOLT_SW(wm));
|
||||
MEAS_VIN(wm) = (int32_t) (spi_ADC_rxbuf[0] << 8) | (int32_t) (spi_ADC_rxbuf[1]);
|
||||
if(lastVinADCGainLevel != instru.VinADCGainLevel){
|
||||
VinADCGainControl(instru.VinADCGainLevel);
|
||||
record_flag = false;
|
||||
}
|
||||
|
||||
}
|
||||
VoltData = MEAS_VIN(wm);
|
||||
/* 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 (ADC_cnt == 0) {
|
||||
if (instru.VinAutoGainEnable) {
|
||||
MEAS_VIN(wm) = 0xFFFF;
|
||||
} else {
|
||||
ReadADCVin(spi_ADC_rxbuf);
|
||||
MEAS_VIN(wm) = (int32_t) (spi_ADC_rxbuf[0] << 8) | (int32_t) (spi_ADC_rxbuf[1]);
|
||||
if (lastVinADCGainLv != instru.VinADCGainLv) VinADCGainCtrl(instru.VinADCGainLv);
|
||||
}
|
||||
|
||||
if(instru.VinADCGainLevel == 0) {
|
||||
if (instru.VinADCGainLv == 0) {
|
||||
cali_count_max = 5000;
|
||||
} else {
|
||||
cali_count_max = 1000;
|
||||
}
|
||||
|
||||
if(record_flag == false){
|
||||
static int recordCount = 0;
|
||||
recordCount++;
|
||||
if(recordCount == 2){
|
||||
record_flag = true;
|
||||
recordCount = 0;
|
||||
}
|
||||
}else{
|
||||
static uint16_t cali_count = 0;
|
||||
if(cali_count >= cali_count_max){
|
||||
if (record_flag == false) {
|
||||
rec_cnt++;
|
||||
} else {
|
||||
if (cali_count >= cali_count_max) {
|
||||
ADCValueAVG = ADCValueSUM / cali_count;
|
||||
|
||||
InputNotify(NOTIFY_VOLT, ADCValueAVG);
|
||||
@@ -472,14 +463,14 @@ static void cali_VT_plot(void) {
|
||||
CIS_buf[1] = (uint8_t) ((ADCValueAVG & 0xFF00) >> 8);
|
||||
CIS_buf[2] = (uint8_t) (ADCValueAVG & 0x00FF);
|
||||
CIS_buf[3] = 0x00;
|
||||
CIS_buf[4] = instru.VinADCGainLevel;
|
||||
CIS_buf[4] = instru.VinADCGainLv;
|
||||
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 9, CIS_buf);
|
||||
ADCValueSUM = 0;
|
||||
cali_count = 0;
|
||||
|
||||
PeriodicEvent = false;
|
||||
ADCValueSUM = 0;
|
||||
cali_count = 0;
|
||||
ModeLED(NO_EVENT);
|
||||
}else{
|
||||
} else {
|
||||
cali_count++;
|
||||
ADCValueSUM = ADCValueSUM + MEAS_VIN(wm);
|
||||
InputNotify(NOTIFY_VOLT, MEAS_VIN(wm));
|
||||
@@ -487,16 +478,31 @@ static void cali_VT_plot(void) {
|
||||
InputNotify(NOTIFY_IMPEDANCE, (int32_t)cali_count);
|
||||
}
|
||||
}
|
||||
ADCSwitch++;
|
||||
|
||||
if (rec_cnt == 2) {
|
||||
record_flag = true;
|
||||
rec_cnt = 0;
|
||||
}
|
||||
ADC_cnt++;
|
||||
|
||||
return;
|
||||
}
|
||||
else if(ADCSwitch == 1){ /**read v**/
|
||||
ReadADCVolt(VOLT_SW(wm));
|
||||
ADCSwitch++;
|
||||
|
||||
if (ADC_cnt == 1) {
|
||||
ReadADCVin(spi_ADC_rxbuf);
|
||||
ADC_cnt++;
|
||||
|
||||
return;
|
||||
}
|
||||
else if(ADCSwitch == 2){ /**read v**/
|
||||
ReadADCVolt(VOLT_SW(wm));
|
||||
ADCSwitch = 0;
|
||||
|
||||
if (ADC_cnt == 2) {
|
||||
ReadADCVin(spi_ADC_rxbuf);
|
||||
ADC_cnt = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+4
-4
@@ -3,10 +3,10 @@
|
||||
#define VERSION_DATE
|
||||
|
||||
#define VERSION_DATE_YEAR 21
|
||||
#define VERSION_DATE_MONTH 5
|
||||
#define VERSION_DATE_DAY 25
|
||||
#define VERSION_DATE_HOUR 10
|
||||
#define VERSION_DATE_MINUTE 12
|
||||
#define VERSION_DATE_MONTH 6
|
||||
#define VERSION_DATE_DAY 9
|
||||
#define VERSION_DATE_HOUR 14
|
||||
#define VERSION_DATE_MINUTE 28
|
||||
|
||||
// this is NOT the version hash !!
|
||||
// it's the last version hash
|
||||
|
||||
+23
-27
@@ -576,7 +576,7 @@ static int16_t VIN_GAIN_30K_counter;
|
||||
static int16_t VIN_GAIN_1K_counter;
|
||||
static int16_t VOUT_GAIN_240K_counter;
|
||||
static int16_t VOUT_GAIN_15K_counter;
|
||||
static uint8_t lastVinADCGainLevel;
|
||||
static uint8_t lastVinADCGainLv;
|
||||
static uint8_t lastIinADCGainLevel;
|
||||
static bool btWaitLedFlag = 0;
|
||||
static bool noEventLedFlag = 0;
|
||||
@@ -590,7 +590,7 @@ static void update_latch_status (uint32_t latch_num, uint32_t elite_pin, bool hi
|
||||
static int32_t DecodeADCValue(uint8_t ADCGain, uint8_t ADCChannel, uint8_t *ADC_raw);
|
||||
static void headstage_battery_volt();
|
||||
static void EliteADCBattery();
|
||||
static void VinADCGainControl(uint8_t VinADCLevel);
|
||||
static void VinADCGainCtrl(uint8_t VinADCLevel);
|
||||
static void VoutGainControl(uint8_t VOUTLevel);
|
||||
static void PIN15_setOutputValue (uint32_t latch_num, uint32_t pin_num, bool highlow);
|
||||
|
||||
@@ -744,11 +744,11 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
|
||||
// TODO: input to json
|
||||
instru.AutoGainEnable = 1;
|
||||
instru.ADCGainLevel = I_GAIN_100R;
|
||||
IinADCGainControl(instru.ADCGainLevel);
|
||||
instru.ADCGainLv = I_GAIN_100R;
|
||||
IinADCGainControl(instru.ADCGainLv);
|
||||
instru.VinAutoGainEnable = 1;
|
||||
instru.VinADCGainLevel = VIN_GAIN_1K;
|
||||
VinADCGainControl(instru.VinADCGainLevel);
|
||||
instru.VinADCGainLv = VIN_GAIN_1K;
|
||||
VinADCGainCtrl(instru.VinADCGainLv);
|
||||
// end
|
||||
|
||||
|
||||
@@ -768,11 +768,11 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
|
||||
// TODO: input to json
|
||||
instru.AutoGainEnable = 1;
|
||||
instru.ADCGainLevel = I_GAIN_100R;
|
||||
IinADCGainControl(instru.ADCGainLevel);
|
||||
instru.ADCGainLv = I_GAIN_100R;
|
||||
IinADCGainControl(instru.ADCGainLv);
|
||||
instru.VinAutoGainEnable = 1;
|
||||
instru.VinADCGainLevel = VIN_GAIN_1K;
|
||||
VinADCGainControl(instru.VinADCGainLevel);
|
||||
instru.VinADCGainLv = VIN_GAIN_1K;
|
||||
VinADCGainCtrl(instru.VinADCGainLv);
|
||||
// end
|
||||
|
||||
|
||||
@@ -903,26 +903,24 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
case SET_ADC_DAC_GAIN: {
|
||||
switch(ins[3]){
|
||||
case IIN_ADC : {
|
||||
instru.ADCGainLevel = ins[4];
|
||||
if (instru.ADCGainLevel != I_GAIN_AUTO) {
|
||||
instru.ADCGainLv = ins[4];
|
||||
if (instru.ADCGainLv != I_GAIN_AUTO) {
|
||||
instru.AutoGainEnable = 0;
|
||||
} else {
|
||||
instru.AutoGainEnable = 1;
|
||||
instru.ADCGainLevel = I_GAIN_100R;
|
||||
IinADCGainControl(instru.ADCGainLevel);
|
||||
record_flag = false;
|
||||
instru.ADCGainLv = I_GAIN_100R;
|
||||
IinADCGainControl(instru.ADCGainLv);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case VIN_ADC : {
|
||||
instru.VinADCGainLevel = ins[4];
|
||||
if (instru.VinADCGainLevel != VIN_GAIN_AUTO) {
|
||||
instru.VinADCGainLv = ins[4];
|
||||
if (instru.VinADCGainLv != VIN_GAIN_AUTO) {
|
||||
instru.VinAutoGainEnable = 0;
|
||||
} else {
|
||||
instru.VinAutoGainEnable = 1;
|
||||
instru.VinADCGainLevel = VIN_GAIN_1K;
|
||||
VinADCGainControl(instru.VinADCGainLevel);
|
||||
record_flag = false;
|
||||
instru.VinADCGainLv = VIN_GAIN_1K;
|
||||
VinADCGainCtrl(instru.VinADCGainLv);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -1051,16 +1049,14 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
}
|
||||
|
||||
case 0x02: {
|
||||
instru.VinADCGainLevel = ins[4]; //0:VIN_GAIN_1M, 1:VIN_GAIN_30K, 2:VIN_GAIN_1K, 3:VIN_GAIN_AUTO
|
||||
if (instru.VinADCGainLevel != VIN_GAIN_AUTO) {
|
||||
instru.VinADCGainLv = ins[4]; //0:VIN_GAIN_1M, 1:VIN_GAIN_30K, 2:VIN_GAIN_1K, 3:VIN_GAIN_AUTO
|
||||
if (instru.VinADCGainLv != VIN_GAIN_AUTO) {
|
||||
instru.VinAutoGainEnable = 0;
|
||||
VinADCGainControl(instru.VinADCGainLevel);
|
||||
record_flag = false;
|
||||
VinADCGainCtrl(instru.VinADCGainLv);
|
||||
} else {
|
||||
instru.VinAutoGainEnable = 1;
|
||||
instru.VinADCGainLevel = VIN_GAIN_1K;
|
||||
VinADCGainControl(instru.VinADCGainLevel);
|
||||
record_flag = false;
|
||||
instru.VinADCGainLv = VIN_GAIN_1K;
|
||||
VinADCGainCtrl(instru.VinADCGainLv);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
+5
-5
@@ -62,7 +62,7 @@ static void ZM_init() {
|
||||
|
||||
/* when elite open, must change vin level,
|
||||
measure battery value will be right */
|
||||
VinADCGainControl(VIN_GAIN_AUTO);
|
||||
VinADCGainCtrl(VIN_GAIN_AUTO);
|
||||
|
||||
elite_gptimer_open();
|
||||
elite_gptimer_start();
|
||||
@@ -146,8 +146,8 @@ static void SimpleBLEPeripheral_performPeriodicTask(void) {
|
||||
vscanReset = true;
|
||||
leadTimeReset = true;
|
||||
|
||||
VinADCGainControl(instru.VinADCGainLevel);
|
||||
IinADCGainControl(instru.ADCGainLevel);
|
||||
VinADCGainCtrl(instru.VinADCGainLv);
|
||||
IinADCGainControl(instru.ADCGainLv);
|
||||
VoutGainControl(instru.VoutGainLevel);
|
||||
if (Ve1MatchVe2Mode()) {
|
||||
if (instru.Ve1 == instru.Ve2) {
|
||||
@@ -250,8 +250,8 @@ static void SimpleBLEPeripheral_performPeriodicTask(void) {
|
||||
notifyFirst_flag = true;
|
||||
//pulsemode variable
|
||||
stiFirstTime = true;
|
||||
VinADCGainControl(instru.VinADCGainLevel);
|
||||
IinADCGainControl(instru.ADCGainLevel);
|
||||
VinADCGainCtrl(instru.VinADCGainLv);
|
||||
IinADCGainControl(instru.ADCGainLv);
|
||||
VoutGainControl(instru.VoutGainLevel);
|
||||
if (Ve1MatchVe2Mode()) {
|
||||
if (instru.Ve1 == instru.Ve2) {
|
||||
|
||||
Reference in New Issue
Block a user