Compare commits

..

83 Commits

Author SHA1 Message Date
Roy 6c91a72c1b test sps 2021-04-09 18:16:32 +08:00
Roy 7c6d7c68de CC MODE deltaV = 10mV 2021-04-09 16:23:10 +08:00
Roy eff1e4a43e new 1.5re pin (use define) 2021-04-09 10:48:25 +08:00
Roy 9678266e59 fix RT (no 10 ohm) 2021-04-08 14:10:31 +08:00
Roy 6f74dc2c05 datalength extension:60bytes 2021-04-08 11:07:44 +08:00
Roy 910576ac6d datalength extension 200 bytes 2021-03-31 10:19:35 +08:00
Roy 9377dc517f battery < 3V when running mode, don't close elite 2021-03-16 14:25:21 +08:00
Roy e44d3d8e60 adjusted cc value 2021-03-16 11:24:45 +08:00
Roy f5416d5e1f measure battery when run mode 2021-03-15 15:44:47 +08:00
Roy 0d60074697 send mode finish flag 2021-03-12 12:12:24 +08:00
Roy 3c74358634 update notify rate 2021-03-10 17:25:12 +08:00
Roy 398f9977b8 add debug battery func 2021-03-08 10:05:53 +08:00
Roy 89db7e4575 don't measure battery when run mode 2021-03-08 10:01:46 +08:00
Roy 2b99b96f0f don't measure battery when run mode 2021-03-05 12:15:47 +08:00
Roy 1b67c809a9 open highz when finish experiment 2021-03-05 11:55:07 +08:00
Roy 59aac611f6 open highz when finish experiment 2021-03-05 11:31:14 +08:00
Roy 6f5baf38ce open highz when finish experiment 2021-03-05 10:29:20 +08:00
Roy 05f8eb4c51 change vin level when open elite, battery value is right 2021-03-04 11:48:12 +08:00
Roy 9bd536bb68 [update] don't meas battery when no reriodicEvent 2021-01-28 11:06:08 +08:00
Roy 81d9aaab1f [update] organize code 2021-01-28 10:41:45 +08:00
Roy 341c5939ac [update] organize code 2021-01-27 17:45:43 +08:00
Roy c50c0b4dec [update] close highz & set DAC value in pre-treated (100ms) 2021-01-27 15:03:39 +08:00
Roy 1639eddc6d [update] free malloc when change mode 2021-01-26 18:08:27 +08:00
Roy cc50bbc0a4 [update] pulse module 2021-01-26 16:08:24 +08:00
Roy 913d269a32 [update] ca module 2021-01-26 15:44:26 +08:00
Roy 5938d6645f [update] lsv module 2021-01-26 15:33:02 +08:00
Roy 3fda9fff6c [update] cv module 2021-01-26 15:16:30 +08:00
Roy 6f6346ac45 Merge branch 'Elite1.5_dev_module_0125_4' into Elite1.5_dev_module_0125_5 2021-01-26 13:42:36 +08:00
Roy 4ca15b1ec9 [update] open highz when elite int() & reset() 2021-01-26 13:40:38 +08:00
Roy 4c0cdcbfe9 [update] cc module 2021-01-26 12:30:46 +08:00
Roy ccb6939b34 [update] iv_cy module 2021-01-26 11:59:48 +08:00
Roy 27baa87562 [update] iv module 2021-01-26 11:12:00 +08:00
Roy ea862012b8 Merge branch 'Elite1.5_dev_module_0125_3' into Elite1.5_dev_module_0125_4 2021-01-26 10:53:44 +08:00
Roy d8c0d5e420 [update] open highz when elite turn on 2021-01-26 10:45:41 +08:00
Roy 43c606577a [update] rt module 2021-01-26 10:40:05 +08:00
Roy 72a64479d4 [update] vo module 2021-01-25 18:29:35 +08:00
Roy c6b45ecca4 [update] it module 2021-01-25 17:56:09 +08:00
Roy 11d828bfc7 [update] vt module 2021-01-25 17:12:09 +08:00
Roy 79bca317c2 [update] vt module 2021-01-25 17:02:32 +08:00
Roy ea254423d6 [cali] add BOARD_C5CD calibration data. 2021-01-25 10:47:06 +08:00
Roy f151d5a74d [update] fix CC mode 2021-01-25 10:18:40 +08:00
Roy 5cc2d878be [update] fix Vout mode 2021-01-22 18:31:31 +08:00
Roy 18eeeec7cc [update] update cycle 8bit to 16bit 2021-01-22 18:20:08 +08:00
Roy 81d753b5f0 [update] fix RT mode 2021-01-17 17:40:30 +08:00
Roy 0841d08972 [update] fix Vout mode (ok) 2021-01-11 23:35:43 +08:00
Roy de5bb460fc [update] fix WM (not ok) 2021-01-11 00:47:35 +08:00
Roy eb45ca6d81 [update] test struct ok 2021-01-08 18:05:27 +08:00
Roy b0d2697c92 [update] test struct fail 2021-01-08 12:27:28 +08:00
Roy 0dc0b66234 [update] test struct fail 2021-01-08 10:39:49 +08:00
Roy 11da60ab8f test struct 2021-01-08 00:42:28 +08:00
Roy 41c7db8776 [update] test TT-CURVE 2021-01-07 18:22:26 +08:00
Roy 916a8f5dc7 [update] fix Cycle I-V cycle 2021-01-05 11:08:06 +08:00
Roy 25cc8b16fa [update] fix CV3 cycle 2021-01-05 10:31:08 +08:00
Roy 67bf8b67dd [cali] add BOARD_C797 & BOARD_C639 calibration data. 2020-12-31 09:40:38 +08:00
Roy 13dfdbd502 [update] fix problem for change level 2020-12-30 16:36:16 +08:00
Roy e0ae30d40d [update] add dark led fun() 2020-12-29 11:45:09 +08:00
Roy 2c3a0a7ee8 [cali] add BOARD_C615 & BOARD_C78B calibration data. 2020-12-29 10:43:51 +08:00
Benny Liu f1086df363 turn on 6994 shutdown 2020-12-17 12:40:07 +08:00
Roy 6345ee875a [cali] add BOARD_C60C calibration data. 2020-12-16 09:59:21 +08:00
Roy 69061f9afd [cali] add BOARD_C903 calibration data. 2020-12-15 10:00:58 +08:00
Roy 3aecb50b47 [cali] add BOARD_C69F calibration data. 2020-12-14 18:37:01 +08:00
Roy e030578fd8 [update] update headstage version on elite1.5 (0,2,1,6) 2020-12-10 17:16:37 +08:00
Roy c05fefe71c Merge branch 'Elite1.5_developement_testmode1210' into Elite1.5_developement 2020-12-10 17:04:31 +08:00
Roy 177b56e8f9 [update] update pulsemode on elite1.5 2020-12-10 17:03:08 +08:00
Benny Liu aeb7a8afaf cali_count_max = 5000 for smallest Vin and Iin gain 2020-12-10 15:53:35 +08:00
Roy 0edaa77857 [update] match 1.5 ui (cali code) 2020-12-04 11:28:33 +08:00
Roy c656eebcbc [update] align notify (match megafly ui) 2020-11-26 22:48:53 +08:00
Roy e17e78bc18 [update] add Vout boundary (usc) 2020-11-26 16:14:31 +08:00
Benny Liu c3235e985f Change 1.5 Iin measurement range. 2020-11-26 15:48:01 +08:00
Roy 656e0fb485 [cali] update BOARD_C7A1 calibration data. 2020-11-23 12:12:09 +08:00
Roy d3dd5270dd [update] tag controller version 2020-11-23 10:18:46 +08:00
Roy e588b30c8b [update] monitor bat 2020-11-20 14:45:21 +08:00
Roy d3f9aec31c add BOARD_C604 calibration data. 2020-11-20 11:50:17 +08:00
Roy ed617c88c9 [update] remove megafly pin 2020-11-20 11:14:01 +08:00
Roy 0b8f4c2414 Merge branch 'Elite1.5_developement_magafly_1119_1' into Elite1.5_developement 2020-11-20 11:08:51 +08:00
Roy b5449b7404 [update]update pulsefly INSTRUCTION.notifyRate 2020-11-20 11:06:12 +08:00
Roy a3c1241f38 Merge branch 'Elite1.5_calibration' into Elite1.5_developement 2020-11-20 11:01:45 +08:00
YiChin 8753e2ddc6 dont send battery information 2020-10-22 10:38:09 +08:00
YiChin cb3894712e take away AutoGainChangeVout() 2020-10-20 18:23:13 +08:00
YiChin 995a47e200 update SPI hold 2020-10-20 17:11:36 +08:00
YiChin cde9096018 update SPI hold 2020-10-20 12:18:29 +08:00
YiChin 6c1bd24b92 update SPI hold 2020-10-19 18:40:35 +08:00
YiChin 0c129bc99b take away bat() 2020-09-25 09:43:39 +08:00
35 changed files with 2637 additions and 4170 deletions
@@ -140,10 +140,10 @@ static void PIN15_setOutputValue (uint32_t latch_num, uint32_t pin_num, bool hig
switch (latch_num) {
case LOAD0: {
PIN_setOutputValue(&ZM_rst, D0, LH.LATCH0[0]);
PIN_setOutputValue(&ZM_rst, D1, LH.LATCH0[1]);
PIN_setOutputValue(&ZM_rst, D2, LH.LATCH0[2]);
PIN_setOutputValue(&ZM_rst, D3, LH.LATCH0[3]);
// PIN_setOutputValue(&ZM_rst, D0, LH.LATCH0[0]);
// PIN_setOutputValue(&ZM_rst, D1, LH.LATCH0[1]);
// PIN_setOutputValue(&ZM_rst, D2, LH.LATCH0[2]);
// PIN_setOutputValue(&ZM_rst, D3, LH.LATCH0[3]);
PIN_setOutputValue(pin_handle, D4, LH.LATCH0[4]);
PIN_setOutputValue(pin_handle, D5, LH.LATCH0[5]);
PIN_setOutputValue(pin_handle, D6, LH.LATCH0[6]);
@@ -177,7 +177,7 @@ static void PIN15_setOutputValue (uint32_t latch_num, uint32_t pin_num, bool hig
}
}
PIN_setOutputValue(&ZM_rst, latch_num, 1); // Turn on latch
CPUdelay(10);
// CPUdelay(10);
PIN_setOutputValue(&ZM_rst, latch_num, 0); // Turn off latch
remove_elite_pin();
ELITE15_SPI_HOLD();
@@ -19,11 +19,6 @@
#define ADC_CH_DAC 0x02
#define ADC_CH_BAT 0x03
#define GPIO_CH_0 0x00
#define GPIO_CH_1 0x01
#define GPIO_CH_2 0x02
#define GPIO_CH_3 0x03
static void ADC_write(uint8_t ADCin) {
/*
* This function can only define [15]~[8] through ADCin
@@ -204,7 +199,7 @@ 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(INSTRUCTION.ADCGainLevel);
// IinADCGainControl(instru.ADCGainLevel);
ADCChannelSelect(ADC_CH_CURRENT);
ADC_read(buf);
@@ -215,7 +210,7 @@ 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(INSTRUCTION.VinADCGainLevel);
// VinADCGainControl(instru.VinADCGainLevel);
ADCChannelSelect(ADC_CH_VOLT);
ADC_read(buf);
@@ -268,7 +263,7 @@ static int32_t AutoGainReadIin(uint8_t *buf){
int32_t RealCurrent = 0;
ReadADCIin(spi_ADC_rxbuf);
RealCurrent = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
RealCurrent = DecodeADCValue(instru.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
return RealCurrent;
}
@@ -277,7 +272,7 @@ static int32_t AutoGainReadVin(uint8_t *buf){
int32_t RealVolt = 0;
ReadADCVin(spi_ADC_rxbuf);
RealVolt = DecodeADCValue(INSTRUCTION.VinADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
RealVolt = DecodeADCValue(instru.VinADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
return RealVolt;
}
@@ -287,14 +282,14 @@ 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(INSTRUCTION.ADCGainLevel == I_GAIN_100R){
if(instru.ADCGainLevel == 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){
INSTRUCTION.ADCGainLevel = I_GAIN_3M;
IinADCGainControl(INSTRUCTION.ADCGainLevel);
instru.ADCGainLevel = I_GAIN_3M;
IinADCGainControl(instru.ADCGainLevel);
I_GAIN_3M_counter = 0;
record_flag = false;
}
@@ -303,8 +298,8 @@ static void AutoGainChangeIin(int32_t RealCurrent){
else if (RealCurrent < I_GAIN_MID2_BOUNDARY1 && RealCurrent > -1*I_GAIN_MID2_BOUNDARY1){
I_GAIN_100K_counter++;
if(I_GAIN_100K_counter > 2){
INSTRUCTION.ADCGainLevel = I_GAIN_100K;
IinADCGainControl(INSTRUCTION.ADCGainLevel);
instru.ADCGainLevel = I_GAIN_100K;
IinADCGainControl(instru.ADCGainLevel);
I_GAIN_100K_counter = 0;
record_flag = false;
}
@@ -313,8 +308,8 @@ static void AutoGainChangeIin(int32_t RealCurrent){
else{
I_GAIN_3K_counter++;
if(I_GAIN_3K_counter > 2){
INSTRUCTION.ADCGainLevel = I_GAIN_3K;
IinADCGainControl(INSTRUCTION.ADCGainLevel);
instru.ADCGainLevel = I_GAIN_3K;
IinADCGainControl(instru.ADCGainLevel);
I_GAIN_3K_counter = 0;
record_flag = false;
}
@@ -331,13 +326,13 @@ static void AutoGainChangeIin(int32_t RealCurrent){
}
}
}
else if(INSTRUCTION.ADCGainLevel == I_GAIN_3K){
else if(instru.ADCGainLevel == 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){
INSTRUCTION.ADCGainLevel = I_GAIN_100R;
IinADCGainControl(INSTRUCTION.ADCGainLevel);
instru.ADCGainLevel = I_GAIN_100R;
IinADCGainControl(instru.ADCGainLevel);
I_GAIN_100R_counter = 0;
record_flag = false;
}
@@ -347,8 +342,8 @@ 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){
INSTRUCTION.ADCGainLevel = I_GAIN_3M;
IinADCGainControl(INSTRUCTION.ADCGainLevel);
instru.ADCGainLevel = I_GAIN_3M;
IinADCGainControl(instru.ADCGainLevel);
I_GAIN_3M_counter = 0;
record_flag = false;
}
@@ -357,8 +352,8 @@ static void AutoGainChangeIin(int32_t RealCurrent){
else{
I_GAIN_100K_counter++;
if(I_GAIN_100K_counter > 2){
INSTRUCTION.ADCGainLevel = I_GAIN_100K;
IinADCGainControl(INSTRUCTION.ADCGainLevel);
instru.ADCGainLevel = I_GAIN_100K;
IinADCGainControl(instru.ADCGainLevel);
I_GAIN_100K_counter = 0;
record_flag = false;
}
@@ -375,13 +370,13 @@ static void AutoGainChangeIin(int32_t RealCurrent){
}
}
}
else if(INSTRUCTION.ADCGainLevel == I_GAIN_100K){
else if(instru.ADCGainLevel == 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){
INSTRUCTION.ADCGainLevel = I_GAIN_3M;
IinADCGainControl(INSTRUCTION.ADCGainLevel);
instru.ADCGainLevel = I_GAIN_3M;
IinADCGainControl(instru.ADCGainLevel);
I_GAIN_3M_counter = 0;
record_flag = false;
}
@@ -391,8 +386,8 @@ 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){
INSTRUCTION.ADCGainLevel = I_GAIN_100R;
IinADCGainControl(INSTRUCTION.ADCGainLevel);
instru.ADCGainLevel = I_GAIN_100R;
IinADCGainControl(instru.ADCGainLevel);
I_GAIN_100R_counter = 0;
record_flag = false;
}
@@ -401,8 +396,8 @@ static void AutoGainChangeIin(int32_t RealCurrent){
else{
I_GAIN_3K_counter++;
if(I_GAIN_3K_counter > 2){
INSTRUCTION.ADCGainLevel = I_GAIN_3K;
IinADCGainControl(INSTRUCTION.ADCGainLevel);
instru.ADCGainLevel = I_GAIN_3K;
IinADCGainControl(instru.ADCGainLevel);
I_GAIN_3K_counter = 0;
record_flag = false;
}
@@ -419,14 +414,14 @@ static void AutoGainChangeIin(int32_t RealCurrent){
}
}
}
else if(INSTRUCTION.ADCGainLevel == I_GAIN_3M){
else if(instru.ADCGainLevel == 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){
INSTRUCTION.ADCGainLevel = I_GAIN_100R;
IinADCGainControl(INSTRUCTION.ADCGainLevel);
instru.ADCGainLevel = I_GAIN_100R;
IinADCGainControl(instru.ADCGainLevel);
I_GAIN_100R_counter = 0;
record_flag = false;
}
@@ -435,8 +430,8 @@ static void AutoGainChangeIin(int32_t RealCurrent){
else if(RealCurrent > I_GAIN_MID1_BOUNDARY2 || RealCurrent < -1*I_GAIN_MID1_BOUNDARY2){
I_GAIN_3K_counter++;
if(I_GAIN_3K_counter > 2){
INSTRUCTION.ADCGainLevel = I_GAIN_3K;
IinADCGainControl(INSTRUCTION.ADCGainLevel);
instru.ADCGainLevel = I_GAIN_3K;
IinADCGainControl(instru.ADCGainLevel);
I_GAIN_3K_counter = 0;
record_flag = false;
}
@@ -445,8 +440,8 @@ static void AutoGainChangeIin(int32_t RealCurrent){
else{
I_GAIN_100K_counter++;
if(I_GAIN_100K_counter > 2){
INSTRUCTION.ADCGainLevel = I_GAIN_100K;
IinADCGainControl(INSTRUCTION.ADCGainLevel);
instru.ADCGainLevel = I_GAIN_100K;
IinADCGainControl(instru.ADCGainLevel);
I_GAIN_100K_counter = 0;
record_flag = false;
}
@@ -470,14 +465,14 @@ 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(INSTRUCTION.VinADCGainLevel == VIN_GAIN_1M){
if(instru.VinADCGainLevel == 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){
INSTRUCTION.VinADCGainLevel = VIN_GAIN_1K;
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
instru.VinADCGainLevel = VIN_GAIN_1K;
VinADCGainControl(instru.VinADCGainLevel);
VIN_GAIN_1K_counter = 0;
record_flag = false;
}
@@ -486,8 +481,8 @@ static void AutoGainChangeVin(int32_t RealVin){
else{
VIN_GAIN_30K_counter++;
if(VIN_GAIN_30K_counter > 2){
INSTRUCTION.VinADCGainLevel = VIN_GAIN_30K;
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
instru.VinADCGainLevel = VIN_GAIN_30K;
VinADCGainControl(instru.VinADCGainLevel);
VIN_GAIN_30K_counter = 0;
record_flag = false;
}
@@ -501,13 +496,13 @@ static void AutoGainChangeVin(int32_t RealVin){
}
}
}
else if(INSTRUCTION.VinADCGainLevel == VIN_GAIN_30K){
else if(instru.VinADCGainLevel == 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){
INSTRUCTION.VinADCGainLevel = VIN_GAIN_1M;
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
instru.VinADCGainLevel = VIN_GAIN_1M;
VinADCGainControl(instru.VinADCGainLevel);
VIN_GAIN_1M_counter = 0;
record_flag = false;
}
@@ -516,8 +511,8 @@ static void AutoGainChangeVin(int32_t RealVin){
// switch to 3 level volt
VIN_GAIN_1K_counter++;
if(VIN_GAIN_1K_counter > 2){
INSTRUCTION.VinADCGainLevel = VIN_GAIN_1K;
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
instru.VinADCGainLevel = VIN_GAIN_1K;
VinADCGainControl(instru.VinADCGainLevel);
VIN_GAIN_1K_counter = 0;
record_flag = false;
}
@@ -530,14 +525,14 @@ static void AutoGainChangeVin(int32_t RealVin){
}
}
}
else if(INSTRUCTION.VinADCGainLevel == VIN_GAIN_1K){
else if(instru.VinADCGainLevel == 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){
INSTRUCTION.VinADCGainLevel = VIN_GAIN_1M;
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
instru.VinADCGainLevel = VIN_GAIN_1M;
VinADCGainControl(instru.VinADCGainLevel);
VIN_GAIN_1M_counter = 0;
record_flag = false;
}
@@ -546,8 +541,8 @@ static void AutoGainChangeVin(int32_t RealVin){
else{
VIN_GAIN_30K_counter++;
if(VIN_GAIN_30K_counter > 2){
INSTRUCTION.VinADCGainLevel = VIN_GAIN_30K;
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
instru.VinADCGainLevel = VIN_GAIN_30K;
VinADCGainControl(instru.VinADCGainLevel);
VIN_GAIN_30K_counter = 0;
record_flag = false;
}
@@ -608,46 +603,4 @@ static uint16_t ADC_CURRENT_AVG_calibration (uint8_t ADC_channel) {
return ADCValueAVG_RAW;
}
/* Test Elite TRIG01 function on Meagfly hardware */
static void GPIO_SPI_write(uint8_t GPIO_channel, uint16_t GPIOin) {
uint32_t TW_CH_0 [2] = {TW_SCKI_0};
uint32_t TW_CH_1 [2] = {TW_SCKI_1};
uint32_t TW_CH_2 [2] = {TW_SCKI_2};
uint32_t TW_CH_3 [2] = {TW_SCKI_3};
uint32_t CLK_CH[2] = {0};
spi_GPIO_txbuf = 0;
switch (GPIO_channel) { // channel select
case GPIO_CH_0: {
CLK_CH[0] = TW_CH_0[0];
CLK_CH[1] = TW_CH_0[1];
break;
}
case GPIO_CH_1: {
CLK_CH[0] = TW_CH_1[0];
CLK_CH[1] = TW_CH_1[1];
break;
}
case GPIO_CH_2: {
CLK_CH[0] = TW_CH_2[0];
CLK_CH[1] = TW_CH_2[1];
break;
}
case GPIO_CH_3: {
CLK_CH[0] = TW_CH_3[0];
CLK_CH[1] = TW_CH_3[1];
break;
}
default: {
break;
}
}
spi_GPIO_txbuf = GPIOin;
GPIO_SPI_transfer(CLK_CH, spi_GPIO_txbuf);
}
#endif
@@ -1,32 +0,0 @@
#ifndef ELITECCC
#define ELITECCC
#include "EliteCCMode.h"
// XXX : should we reset DAC output after STOP?
static void CCModeReverseCurrent(CCCMode *CCC){
if(CCC->StandBy){
if(CT.StandByCounter == CCC->StandByTime){
CCC->StandBy = false;
CT.StandByCounter = 0;
}
else{
CT.StandByCounter ++;
}
}
else{
// reverse charge/discharge
if(CCC->BatteryV == CCC->VMax){
CCC->StandBy = true;
CCC->value = CCC->DischargeCurrent;
}
else if(CCC->BatteryV == CCC->VMin){
CCC->StandBy = true;
CCC->value = CCC->ChargeCurrent;
}
}
}
#endif
@@ -2,8 +2,8 @@
#ifndef ELITECCMODE
#define ELITECCMODE
#define Vset INSTRUCTION.Vset
#define DELTAVOLTMAX 100000
#define Vset instru.Vset
#define DELTAVOLTMAX 2000000 //2000000 = 10mV
/* Transform setting CC into IUC
*
@@ -11,73 +11,67 @@
* Real current value : -15.00000 ~ 15.00000 mA
* => user code = 1500000 mapping to 0.00000 mA
*/
static void CC_Vscan(CCMode *CC){
static int32_t Iin = 0;
static int32_t deltaI = 0;
static int32_t deltaV = 0;
static void cc_vscan(void)
{
struct wm_cc_ctx_t *cc = (struct wm_cc_ctx_t *)wm_get();
struct wm_meas_t *m = &cc->measure;
uint16_t divisionRate;
int32_t deltaI;
int32_t deltaV;
int32_t Iin;
int32_t Vin;
if(vscanReset){
if (vscanReset) {
Vset = 0;
if(CC->_charge == 0){
CC->_Iset *= -1;
if (cc->_charge == 0) {
cc->_Iset = instru.constantCurrent * 200 * (-1);
//[50pA] //controller UI 15000uA => Elite 1500000 => 1500000 * 10 * 1000 / 50 [50pA];
}
Iin = CC->_measureCurrent * 20; //[50pA] nA => 50pA
deltaI = Iin - CC->_Iset;
Iin = m->_measureCurrent * 20; //[50pA] nA => 50pA
Vin = m->_measureVin * 200; //[5nV]
if(deltaI > 20000000 || deltaI < -20000000){ //1mA
divisionRate = 1000;
}else{
divisionRate = 10;
Vset = Vin + cc->_Iset / 20 ; //[5nV]
if (Vset >= 1100000000) { // 5.5V
Vset = 1100000000;
} else if (Vset <= -1000000000) { //-5V
Vset = -1000000000;
}
}
if (!vscanReset) {
Iin = m->_measureCurrent * 20; //[50pA] nA => 50pA
deltaI = Iin - cc->_Iset;
if (deltaI > 2000000 || deltaI < -2000000) { //100uA
divisionRate = 1;
} else {
divisionRate = 20;
}
deltaV = -1 * (deltaI / divisionRate); //-5 * deltaI / 5000 //pV=> 5nV
if(deltaV > DELTAVOLTMAX){ //100000 = 500uV
if (deltaV > DELTAVOLTMAX) { //2000000 = 10mV
deltaV = DELTAVOLTMAX;
}else if(deltaV < (-DELTAVOLTMAX)){
} else if (deltaV < (-DELTAVOLTMAX)) {
deltaV = (-DELTAVOLTMAX);
}
Vset = Vset + deltaV; //[5nV]
if(Vset <= CC->_Vmin){
Vset = CC->_Vmin;
}else if(Vset >= CC->_Vmax){
Vset = CC->_Vmax;
if (Vset >= 1100000000) { // 5.5V
Vset = 1100000000;
} else if (Vset <= -1000000000) { //-5V
Vset = -1000000000;
}
if (Vset <= cc->_Vmin) {
Vset = cc->_Vmin;
} else if (Vset >= cc->_Vmax) {
Vset = cc->_Vmax;
}
}
if(!vscanReset){
Iin = CC->_measureCurrent * 20; //[50pA] nA => 50pA
deltaI = Iin - CC->_Iset;
if(deltaI > 20000000 || deltaI < -20000000){ //1mA
divisionRate = 1000;
}else{
divisionRate = 10;
}
deltaV = -1 * (deltaI / divisionRate); //-5 * deltaI / 5000 //pV=> 5nV
if(deltaV > DELTAVOLTMAX){ //100000 = 500uV
deltaV = DELTAVOLTMAX;
}else if(deltaV < (-DELTAVOLTMAX)){
deltaV = (-DELTAVOLTMAX);
}
Vset = Vset + deltaV; //[5nV]
if(Vset <= CC->_Vmin){
Vset = CC->_Vmin;
}else if(Vset >= CC->_Vmax){
Vset = CC->_Vmax;
}
}
// int32_t RealV;
// RealV = (int32_t)(deltaV);
// InputNotify(NOTIFY_IMPEDANCE, RealV);
}
#endif
@@ -1,25 +1,27 @@
#ifndef ELITECV3
#define ELITECV3
#define Vset INSTRUCTION.Vset
#define Vset instru.Vset
static uint16_t CV3Curve(CV3Mode *CV3){
static uint16_t DACOutCode;
static int32_t Vin;
static int32_t Vout;
static int32_t DeltaVout;
static void cv_volt_out(void)
{
struct wm_cv_ctx_t *cv = (struct wm_cv_ctx_t *)wm_get();
struct wm_meas_t *m = &cv->measure;
uint16_t DACOutCode;
int32_t Vin;
int32_t Vout;
int32_t DeltaVout;
Vin = CV3->_measureVin * 200;//[5nV]
if(DACReset){
Vin = m->_measureVin * 200;//[5nV]
if (DACReset) {
Vout = Vset + Vin;
DACReset = false;
}else{
} else {
DeltaVout = Vset - (Vout - Vin);
Vout = Vout + DeltaVout;
}
INSTRUCTION.VoltConstant = Vout / 40000 + 25000;//5nV=>usercode
DACOutCode = Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.VoltConstant);
instru.VoltConstant = Vout / 40000 + 25000;//5nV=>usercode
DACOutCode = Usercode_Correction_to_DAC(instru.VoutGainLevel, instru.VoltConstant);
int32_t RealV2;
RealV2 = (int32_t)((Vout - Vin) / 200);//[1uV]
@@ -31,126 +33,110 @@ static uint16_t CV3Curve(CV3Mode *CV3){
DAC_outputV(DACOutCode);
return DACOutCode;
return;
}
static void CV3_Vscan(CV3Mode *CV3){
static int16_t VminCounter;
static int16_t VmaxCounter;
static uint16_t CycleCounter;
static void cv_vscan(void)
{
struct wm_cv_ctx_t *cv = (struct wm_cv_ctx_t *)wm_get();
static bool VminCounter;
static bool VmaxCounter;
NotifyCycleNumber = (INSTRUCTION.cycleNumber - CV3->_cycleNumber + 1);
NotifyCycleNumber = (instru.cycleNumber - cv->_cycleNumber + 1);
if(vscanReset){
VmaxCounter = 0;
VminCounter = 0;
CycleCounter = 0;
if (vscanReset) {
VmaxCounter = false;
VminCounter = false;
if(INSTRUCTION.directionInit == 1){
CV3->_direction_up = true;
CV3->_current_direction_up = true;
}else{
CV3->_direction_up = false;
CV3->_current_direction_up = false;
if (instru.directionInit == 1) {
cv->_direction_up = true;
cv->_current_direction_up = true;
} else {
cv->_direction_up = false;
cv->_current_direction_up = false;
}
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
if(INSTRUCTION.step <= 10){
CV3->_Vstep = INSTRUCTION.step * INSTRUCTION.VsetRate / 5;
}else{
CV3->_Vstep = INSTRUCTION.step / 5 * INSTRUCTION.VsetRate;
if (instru.step <= 10) {
cv->_Vstep = instru.step * instru.VsetRate / 5;
} else {
cv->_Vstep = instru.step / 5 * instru.VsetRate;
}
if(CV3->_Vmin == CV3->_Vinit){
VminCounter = -1;
if (cv->_Vmin == cv->_Vinit) {
VminCounter = true;
}
if(CV3->_Vmax == CV3->_Vinit){
VmaxCounter = -1;
if (cv->_Vmax == cv->_Vinit) {
VmaxCounter = true;
}
Vset = CV3->_Vinit;
Vset = cv->_Vinit;
}
if(!vscanReset){
if((INSTRUCTION.Vinit < INSTRUCTION.Ve1 && INSTRUCTION.Vinit < INSTRUCTION.Ve2) ||
(INSTRUCTION.Vinit > INSTRUCTION.Ve1 && INSTRUCTION.Vinit > INSTRUCTION.Ve2)
){
if (CV3->_current_direction_up){
Vset = Vset + CV3->_Vstep;
}else{
Vset = Vset - CV3->_Vstep;
if (!vscanReset) {
if ((instru.Vinit < instru.Ve1 && instru.Vinit < instru.Ve2) ||
(instru.Vinit > instru.Ve1 && instru.Vinit > instru.Ve2)
) {
if (cv->_current_direction_up) {
Vset = Vset + cv->_Vstep * GPT.GptimerMultiple;
} else {
Vset = Vset - cv->_Vstep * GPT.GptimerMultiple;
}
if(INSTRUCTION.Vinit < INSTRUCTION.Ve1 && INSTRUCTION.Vinit < INSTRUCTION.Ve2){
if(Vset == CV3->_Vmin){
VminCounter = -1;
INSTRUCTION.Vinit = INSTRUCTION.Vmin;
CV3->_Vinit = CV3->_Vmin;
if (instru.Vinit < instru.Ve1 && instru.Vinit < instru.Ve2) {
if (Vset == cv->_Vmin) {
VminCounter = true;
instru.Vinit = instru.Vmin;
cv->_Vinit = cv->_Vmin;
}
}else if(INSTRUCTION.Vinit > INSTRUCTION.Ve1 && INSTRUCTION.Vinit > INSTRUCTION.Ve2){
if(Vset == CV3->_Vmax){
VmaxCounter = -1;
INSTRUCTION.Vinit = INSTRUCTION.Vmax;
CV3->_Vinit = CV3->_Vmax;
} else if (instru.Vinit > instru.Ve1 && instru.Vinit > instru.Ve2) {
if (Vset == cv->_Vmax) {
VmaxCounter = true;
instru.Vinit = instru.Vmax;
cv->_Vinit = cv->_Vmax;
}
}
}else{
if (Vset >= CV3->_Vmax){
VmaxCounter++;
}else if (Vset <= CV3->_Vmin){
VminCounter++;
} else {
if (Vset >= cv->_Vmax) {
VmaxCounter = true;
} else if (Vset <= cv->_Vmin) {
VminCounter = true;
}
if (CV3->_current_direction_up){
Vset = Vset + CV3->_Vstep * GPT.GptimerMultiple;
}else{
Vset = Vset - CV3->_Vstep * GPT.GptimerMultiple;
if (cv->_current_direction_up) {
Vset = Vset + cv->_Vstep * GPT.GptimerMultiple;
} else {
Vset = Vset - cv->_Vstep * GPT.GptimerMultiple;
}
if(VmaxCounter != 0 && VminCounter != 0){
if(VmaxCounter == VminCounter && CV3->_direction_up && CV3->_current_direction_up){
if(CycleCounter != VmaxCounter){
if(Vset >= CV3->_Vinit){
CV3->_cycleNumber--;
CycleCounter = VmaxCounter; //VmaxCounter = VminCounter = CycleCounter
}
if (VmaxCounter && VminCounter) {
if (cv->_direction_up && cv->_current_direction_up) {
if (Vset >= cv->_Vinit) {
cv->_cycleNumber--;
VminCounter = false;
VmaxCounter = false;
}
}
if(VmaxCounter == VminCounter && !CV3->_direction_up && !CV3->_current_direction_up){
if(CycleCounter != VmaxCounter){
if(Vset <= CV3->_Vinit){
CV3->_cycleNumber--;
CycleCounter = VmaxCounter; //VmaxCounter = VminCounter = CycleCounter
}
if (!cv->_direction_up && !cv->_current_direction_up) {
if (Vset <= cv->_Vinit) {
cv->_cycleNumber--;
VminCounter = false;
VmaxCounter = false;
}
}
}
if (Vset >= CV3->_Vmax){
CV3->_current_direction_up = false;
}else if (Vset <= CV3->_Vmin){
CV3->_current_direction_up = true;
if (Vset >= cv->_Vmax) {
cv->_current_direction_up = false;
} else if (Vset <= cv->_Vmin) {
cv->_current_direction_up = true;
}
/*stop condition*/
if(CV3->_cycleNumber == 0){
// PeriodicEvent = false;
ModeLED(POST_WORK);
InitEliteFlag();
INSTRUCTION.eliteFxn = CONSTANT_CURRENT;
INSTRUCTION.sampleRate = 15;
INSTRUCTION.charge = 0x01;
INSTRUCTION.constantCurrent = 0x00;
INSTRUCTION.Vmax = 0xC350;
INSTRUCTION.Vmin = 0x0000;
INSTRUCTION.notifyRate = 500;
INSTRUCTION.VoViSwitch = 0x02;//read Vscan = Vout - Vin
if (cv->_cycleNumber == 0) {
PeriodicEvent = false;
}
}
}
// int32_t RealV;
// RealV = (int32_t)(Vset / 500);//[1uV]
// InputNotify(NOTIFY_VOLT, RealV);
}
#endif
@@ -2,215 +2,82 @@
#ifndef ELITECV
#define ELITECV
static uint16_t SWVCurve(WorkMode *WorkModeData) {
static uint8_t counter;
static uint16_t outputV;
static uint16_t Volt;
static bool direction_up;
static void iv_cy_vscan(void)
{
struct wm_iv_cy_ctx_t *iv_cy = (struct wm_iv_cy_ctx_t *)wm_get();
static bool VminCounter;
static bool VmaxCounter;
// reset origin volt at the begin
if (DACReset) {
Volt = INSTRUCTION.Ve1;
outputV = INSTRUCTION.Ve1;
if (INSTRUCTION.Ve1 < INSTRUCTION.Ve2)
direction_up = true;
else
direction_up = false;
counter = 1;
DACReset = false;
}
if (counter == 2 * PulseWidth)
counter = 1;
else
counter++;
// output a certain volt
outputV = Volt;
DAC_outputV(outputV);
// VoltValue = (ramp1*16 + ramp0/16) * 3.05;
// check if we reach the final volt
if ((outputV >= INSTRUCTION.Ve2 && direction_up) || (outputV <= INSTRUCTION.Ve2 && !direction_up)) {
PeriodicEvent = false;
DACReset = true;
}
// prepare the next output volt
if (direction_up) {
if (counter == PulseWidth)
Volt = Volt + Amplitude;
else if (counter == 2 * PulseWidth)
Volt = Volt - (Amplitude - INSTRUCTION.step);
else
Volt = Volt;
} else {
if (counter == PulseWidth)
Volt = Volt - Amplitude;
else if (counter == 2 * PulseWidth)
Volt = Volt + (Amplitude - INSTRUCTION.step);
else
Volt = Volt;
}
return outputV;
}
static uint16_t DPVCurve(WorkMode *WorkModeData) {
static uint8_t counter;
static uint16_t Volt1;
static uint16_t Volt2;
static uint16_t outputV;
static bool direction_up;
// reset origin volt at the begin
if (DACReset) {
if (INSTRUCTION.Ve1 < INSTRUCTION.Ve2)
direction_up = true;
else
direction_up = false;
Volt1 = INSTRUCTION.Ve1;
if (direction_up)
Volt2 = INSTRUCTION.Ve1 + Amplitude;
else
Volt2 = INSTRUCTION.Ve1 - Amplitude;
counter = 1;
DACReset = false;
}
if (counter == PulsePeriod)
counter = 1;
else
counter++;
// output a certain volt
if (counter <= (PulsePeriod - PulseWidth)) {
outputV = Volt1;
DAC_outputV(Volt1);
} else {
outputV = Volt2;
DAC_outputV(Volt2);
}
// VoltValue = (ramp1*16 + ramp0/16) * 3.05;
// check if we reach the final volt
if (((outputV >= INSTRUCTION.Ve2) && direction_up) || ((outputV <= INSTRUCTION.Ve2) && !direction_up)) {
PeriodicEvent = false;
DACReset = true;
}
// check overflow/underflow and prepare for next output
if (direction_up) {
if (Volt1 + INSTRUCTION.step < Volt1)
Volt1 = 0xffff;
else
Volt1 = Volt1 + INSTRUCTION.step;
if (Volt2 + INSTRUCTION.step < Volt2)
Volt2 = 0xffff;
else
Volt2 = Volt2 + INSTRUCTION.step;
} else {
if (Volt1 - INSTRUCTION.step > Volt1)
Volt1 = 0x0000;
else
Volt1 = Volt1 - INSTRUCTION.step;
if (Volt2 - INSTRUCTION.step > Volt2)
Volt2 = 0x0000;
else
Volt2 = Volt2 - INSTRUCTION.step;
}
if (counter + 1 <= (PulsePeriod - PulseWidth)) {
return Volt1;
} else {
return Volt2;
}
}
static void CV_Vscan(CVMode *CV){
static int16_t VminCounter;
static int16_t VmaxCounter;
static uint16_t CycleCounter;
NotifyCycleNumber = (INSTRUCTION.cycleNumber - CV->_cycleNumber + 1);
NotifyCycleNumber = (instru.cycleNumber - iv_cy->_cycleNumber + 1);
if(vscanReset){
VmaxCounter = 0;
VminCounter = 0;
CycleCounter = 0;
VmaxCounter = false;
VminCounter = false;
if(INSTRUCTION.directionInit == 1){
CV->_direction_up = true;
CV->_current_direction_up = true;
}else if(INSTRUCTION.directionInit == 0){
CV->_direction_up = false;
CV->_current_direction_up = false;
if(instru.directionInit == 1){
iv_cy->_direction_up = true;
iv_cy->_current_direction_up = true;
}else if(instru.directionInit == 0){
iv_cy->_direction_up = false;
iv_cy->_current_direction_up = false;
}
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
if(INSTRUCTION.step <= 10){
CV->_Vstep = INSTRUCTION.step * INSTRUCTION.VsetRate / 5;
if(instru.step <= 10){
iv_cy->_Vstep = instru.step * instru.VsetRate / 5;
}else{
CV->_Vstep = INSTRUCTION.step / 5 * INSTRUCTION.VsetRate;
iv_cy->_Vstep = instru.step / 5 * instru.VsetRate;
}
if(CV->_Vmin == CV->_Vinit){
VminCounter = -1;
if(iv_cy->_Vmin == iv_cy->_Vinit){
VminCounter = true;
}
if(CV->_Vmax == CV->_Vinit){
VmaxCounter = -1;
if(iv_cy->_Vmax == iv_cy->_Vinit){
VmaxCounter = true;
}
Vset = CV->_Vinit;
Vset = iv_cy->_Vinit;
}
if(!vscanReset){
if (Vset >= CV->_Vmax){
VmaxCounter++;
}else if (Vset <= CV->_Vmin){
VminCounter++;
if (Vset >= iv_cy->_Vmax){
VmaxCounter = true;
}else if (Vset <= iv_cy->_Vmin){
VminCounter = true;
}
if (CV->_current_direction_up){
Vset = Vset + CV->_Vstep * GPT.GptimerMultiple;
if (iv_cy->_current_direction_up){
Vset = Vset + iv_cy->_Vstep * GPT.GptimerMultiple;
}else{
Vset = Vset - CV->_Vstep * GPT.GptimerMultiple;
Vset = Vset - iv_cy->_Vstep * GPT.GptimerMultiple;
}
if(VmaxCounter != 0 && VminCounter != 0){
if(VmaxCounter == VminCounter && CV->_direction_up && CV->_current_direction_up){
if(CycleCounter != VmaxCounter){
if(Vset >= CV->_Vinit){
CV->_cycleNumber--;
CycleCounter = VmaxCounter; //VmaxCounter = VminCounter = CycleCounter
}
if(VmaxCounter && VminCounter){
if(iv_cy->_direction_up && iv_cy->_current_direction_up){
if(Vset >= iv_cy->_Vinit){
iv_cy->_cycleNumber--;
VminCounter = false;
VmaxCounter = false;
}
}
if(VmaxCounter == VminCounter && !CV->_direction_up && !CV->_current_direction_up){
if(CycleCounter != VmaxCounter){
if(Vset <= CV->_Vinit){
CV->_cycleNumber--;
CycleCounter = VmaxCounter; //VmaxCounter = VminCounter = CycleCounter
}
if(!iv_cy->_direction_up && !iv_cy->_current_direction_up){
if(Vset <= iv_cy->_Vinit){
iv_cy->_cycleNumber--;
VminCounter = false;
VmaxCounter = false;
}
}
}
if (Vset >= CV->_Vmax){
CV->_current_direction_up = false;
}else if (Vset <= CV->_Vmin){
CV->_current_direction_up = true;
if (Vset >= iv_cy->_Vmax){
iv_cy->_current_direction_up = false;
}else if (Vset <= iv_cy->_Vmin){
iv_cy->_current_direction_up = true;
}
/*stop condition*/
if(CV->_cycleNumber == 0){
if(iv_cy->_cycleNumber == 0){
PeriodicEvent = false;
ModeLED(NO_EVENT);
}
}
}
@@ -1,25 +1,27 @@
#ifndef ELITECVSCAN
#define ELITECVSCAN
#define Vset INSTRUCTION.Vset
#define Vset instru.Vset
static uint16_t CVSCANCurve(CVSCANMode *CVSCAN){
static uint16_t DACOutCode;
static int32_t Vin;
static int32_t Vout;
static int32_t DeltaVout;
static void ca_volt_out(void)
{
struct wm_ca_ctx_t *ca = (struct wm_ca_ctx_t *)wm_get();
struct wm_meas_t *m = &ca->measure;
uint16_t DACOutCode;
int32_t Vin;
int32_t Vout;
int32_t DeltaVout;
Vin = CVSCAN->_measureVin * 200;//[5nV]
if(DACReset){
Vin = m->_measureVin * 200;//[5nV]
if (DACReset) {
Vout = Vset + Vin;
DACReset = false;
}else{
} else {
DeltaVout = Vset - (Vout - Vin);
Vout = Vout + DeltaVout;
}
INSTRUCTION.VoltConstant = Vout / 40000 + 25000;//5nV=>usercode
DACOutCode = Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.VoltConstant);
instru.VoltConstant = Vout / 40000 + 25000;//5nV=>usercode
DACOutCode = Usercode_Correction_to_DAC(instru.VoutGainLevel, instru.VoltConstant);
int32_t RealV2;
RealV2 = (int32_t)((Vout - Vin) / 200);//[1uV]
@@ -31,17 +33,19 @@ static uint16_t CVSCANCurve(CVSCANMode *CVSCAN){
DAC_outputV(DACOutCode);
return DACOutCode;
return;
}
static void CVSCAN_Vscan(CVSCANMode *CVSCAN){
static void ca_vscan(void)
{
struct wm_ca_ctx_t *ca = (struct wm_ca_ctx_t *)wm_get();
if(vscanReset){
Vset = CVSCAN->_Vinit;
Vset = ca->_Vinit;
}
if(!vscanReset){
Vset = CVSCAN->_Vinit;
Vset = ca->_Vinit;
}
}
#endif
@@ -94,25 +94,25 @@ static void AutoGainChangeVout(int32_t userCode){
// switch to 1 level volt(small) 15K
// switch to 2 level volt(large) 240K
if(INSTRUCTION.VoutGainLevel == VOUT_GAIN_AUTO){
INSTRUCTION.VoutGainLevel = VOUT_GAIN_15K;
VoutGainControl(INSTRUCTION.VoutGainLevel);
if(instru.VoutGainLevel == VOUT_GAIN_AUTO){
instru.VoutGainLevel = VOUT_GAIN_15K;
VoutGainControl(instru.VoutGainLevel);
record_flag = false;
}
if(INSTRUCTION.VoutGainLevel == VOUT_GAIN_15K){
if(instru.VoutGainLevel == VOUT_GAIN_15K){
if(RealVolt > DAC_VOUT_GAIN_LARGE_BOUNDARY || RealVolt < -1 * DAC_VOUT_GAIN_LARGE_BOUNDARY){
// switch to 2 level volt(large)
INSTRUCTION.VoutGainLevel = VOUT_GAIN_240K;
VoutGainControl(INSTRUCTION.VoutGainLevel);
instru.VoutGainLevel = VOUT_GAIN_240K;
VoutGainControl(instru.VoutGainLevel);
record_flag = false;
}
}
else if(INSTRUCTION.VoutGainLevel == VOUT_GAIN_240K){
else if(instru.VoutGainLevel == VOUT_GAIN_240K){
if(RealVolt < DAC_VOUT_GAIN_SMALL_BOUNDARY && RealVolt > -1 * DAC_VOUT_GAIN_SMALL_BOUNDARY ){
// switch to 1 level volt(small)
INSTRUCTION.VoutGainLevel = VOUT_GAIN_15K;
VoutGainControl(INSTRUCTION.VoutGainLevel);
instru.VoutGainLevel = VOUT_GAIN_15K;
VoutGainControl(instru.VoutGainLevel);
record_flag = false;
}
}
@@ -29,7 +29,7 @@
*/
#define BOARD_C7A1
#define BOARD_C903
typedef struct _formula{
@@ -46,44 +46,10 @@ struct _correction{
uint16_t Gain0Boundary[2];
uint16_t Gain1Boundary[4];
uint16_t Gain2Boundary[2];
uint16_t Usercode2DAC15v;
} Correction =
#ifdef BOARD_C6E1 //not well
{
.ADC_volt[0].coeff = (-6251051),
.ADC_volt[0].offset = 102081366120,
.ADC_volt[1].coeff = (-6251051),
.ADC_volt[1].offset = 102081366120,
.ADC_volt[2].coeff = (-6251051),
.ADC_volt[2].offset = 102081366120,
.ADC_current[0].coeff = 2079230,
.ADC_current[0].offset = (-34256067906),
.ADC_current[1].coeff = 64550018,
.ADC_current[1].offset = (-1063052554820),
.ADC_current[2].coeff = 2096336928,
.ADC_current[2].offset = (-34514344284104),
.ADC_current[3].coeff = 60200953965,
.ADC_current[3].offset = (-991270580672004),
.Usercode2DAC[0].coeff = (-10511469),
.Usercode2DAC[0].offset = 563770560100,
.Usercode2DAC[1].coeff = (-10511469),
.Usercode2DAC[1].offset = 563770560100,
.Usercode2DAC15v = MEGA_15V,
};
#endif
#ifdef BOARD_C7A1
#ifdef BOARD_C7A1 //megafly
{
.ADC_volt[0].coeff = (6256),
.ADC_volt[0].offset = -101532028,
@@ -112,77 +78,11 @@ struct _correction{
.Usercode2DAC[1].coeff = (-178077711),
.Usercode2DAC[1].offset = 4777894559527,
.Usercode2DAC15v = 41485,
//.Usercode2DAC15v = 41485,
};
#endif
#ifdef BOARD_C6D4 //not well
{
.ADC_volt[0].coeff = (6226),
.ADC_volt[0].offset = -100075170,
.ADC_volt[1].coeff = (215972),
.ADC_volt[1].offset = -3484380085,
.ADC_volt[2].coeff = (6223818),
.ADC_volt[2].offset = -100571214617,
.ADC_current[0].coeff = 3136256,
.ADC_current[0].offset = (-50747854551),
.ADC_current[1].coeff = 72219340,
.ADC_current[1].offset = (-1168719058378),
.ADC_current[2].coeff = 1450319129,
.ADC_current[2].offset = (-23465744053517),
.ADC_current[3].coeff = 30710734735,
.ADC_current[3].offset = (-496978137538345),
.Usercode2DAC[0].coeff = (-10543212),
.Usercode2DAC[0].offset = 582976692942,
.Usercode2DAC[1].coeff = (-178746005),
.Usercode2DAC[1].offset = 4789272862069,
.Usercode2DAC15v = MEGA_15V,
};
#endif
#ifdef BOARD_C771 //not well
{
.ADC_volt[0].coeff = (6301),
.ADC_volt[0].offset = -102184705,
.ADC_volt[1].coeff = (216877),
.ADC_volt[1].offset = -3519583281,
.ADC_volt[2].coeff = (6298448),
.ADC_volt[2].offset = -102304286091,
.ADC_current[0].coeff = 3115431,
.ADC_current[0].offset = (-50586460394),
.ADC_current[1].coeff = 71203612,
.ADC_current[1].offset = (-1156022105141),
.ADC_current[2].coeff = 1451318434,
.ADC_current[2].offset = (-23560731221983),
.ADC_current[3].coeff = 30518004246,
.ADC_current[3].offset = (-495456618814855),
.Usercode2DAC[0].coeff = (-10568719),
.Usercode2DAC[0].offset = 585036272447,
.Usercode2DAC[1].coeff = (-179441058),
.Usercode2DAC[1].offset = 4807380622351,
.Usercode2DAC15v = MEGA_15V,
};
#endif
#ifdef BOARD_C724
#ifdef BOARD_C724 //megafly
{
.ADC_volt[0].coeff = (6251),
.ADC_volt[0].offset = -99750397,
@@ -211,11 +111,11 @@ struct _correction{
.Usercode2DAC[1].coeff = (-179175265),
.Usercode2DAC[1].offset = 4801179734836,
.Usercode2DAC15v = MEGA_15V,
//.Usercode2DAC15v = MEGA_15V,
};
#endif
#ifdef BOARD_C874
#ifdef BOARD_C874 //megafly
{
.ADC_volt[0].coeff = (6260),
.ADC_volt[0].offset = -99787811,
@@ -244,10 +144,381 @@ struct _correction{
.Usercode2DAC[1].coeff = (-178920333),
.Usercode2DAC[1].offset = 4794801719146,
.Usercode2DAC15v = 41355,
//.Usercode2DAC15v = 41355,
};
#endif
#ifdef BOARD_C604
{
.ADC_volt[0].coeff = (6194),
.ADC_volt[0].offset = -100974071,
.ADC_volt[1].coeff = (215506),
.ADC_volt[1].offset = -3517864544,
.ADC_volt[2].coeff = (6243728),
.ADC_volt[2].offset = -102012564806,
.ADC_current[0].coeff = 3139436,
.ADC_current[0].offset = (-51217085818),
.ADC_current[1].coeff = 71622830,
.ADC_current[1].offset = (-1168462302473),
.ADC_current[2].coeff = 1462344785,
.ADC_current[2].offset = (-23855062972762),
.ADC_current[3].coeff = 30689232716,
.ADC_current[3].offset = (-500670762245868),
.Usercode2DAC[0].coeff = (-10507403),
.Usercode2DAC[0].offset = 582940058695,
.Usercode2DAC[1].coeff = (-178479878),
.Usercode2DAC[1].offset = 4782895510276,
};
#endif
#ifdef BOARD_C69F
{
.ADC_volt[0].coeff = (6118),
.ADC_volt[0].offset = -99518615,
.ADC_volt[1].coeff = (209748),
.ADC_volt[1].offset = -3417768725,
.ADC_volt[2].coeff = (6131501),
.ADC_volt[2].offset = -99999128933,
.ADC_current[0].coeff = 3148514,
.ADC_current[0].offset = (-50485662786),
.ADC_current[1].coeff = 71804564,
.ADC_current[1].offset = (-1151299062516),
.ADC_current[2].coeff = 1463584080,
.ADC_current[2].offset = (-23465643586165),
.ADC_current[3].coeff = 30747070723,
.ADC_current[3].offset = (-492979538892707),
.Usercode2DAC[0].coeff = (-10534427),
.Usercode2DAC[0].offset = 577647889649,
.Usercode2DAC[1].coeff = (-178317702),
.Usercode2DAC[1].offset = 4773350420707,
};
#endif
#ifdef BOARD_C903
{
.ADC_volt[0].coeff = (6268),
.ADC_volt[0].offset = -103687047,
.ADC_volt[1].coeff = (216289),
.ADC_volt[1].offset = -3581110600,
.ADC_volt[2].coeff = (6255165),
.ADC_volt[2].offset = -103653080405,
.ADC_current[0].coeff = 3136844,
.ADC_current[0].offset = (-51057548335),
.ADC_current[1].coeff = 71729828,
.ADC_current[1].offset = (-1167474302377),
.ADC_current[2].coeff = 1457587112,
.ADC_current[2].offset = (-23722230272507),
.ADC_current[3].coeff = 30688020320,
.ADC_current[3].offset = (-499567626613052),
.Usercode2DAC[0].coeff = (-10538549),
.Usercode2DAC[0].offset = 582561125327,
.Usercode2DAC[1].coeff = (-179443367),
.Usercode2DAC[1].offset = 4806000714268,
};
#endif
#ifdef BOARD_C60C
{
.ADC_volt[0].coeff = (6232),
.ADC_volt[0].offset = -100384012,
.ADC_volt[1].coeff = (216642),
.ADC_volt[1].offset = -3529452462,
.ADC_volt[2].coeff = (6233108),
.ADC_volt[2].offset = -100604531870,
.ADC_current[0].coeff = 3145651,
.ADC_current[0].offset = (-51102123184),
.ADC_current[1].coeff = 71727284,
.ADC_current[1].offset = (-1165169041311),
.ADC_current[2].coeff = 1463455403,
.ADC_current[2].offset = (-23772125686630),
.ADC_current[3].coeff = 30773610135,
.ADC_current[3].offset = (-499913505030514),
.Usercode2DAC[0].coeff = (-10570464),
.Usercode2DAC[0].offset = 583479916773,
.Usercode2DAC[1].coeff = (-178725281),
.Usercode2DAC[1].offset = 4787957689974,
};
#endif
#ifdef BOARD_C78B
{
.ADC_volt[0].coeff = (6242),
.ADC_volt[0].offset = -101356025,
.ADC_volt[1].coeff = (215624),
.ADC_volt[1].offset = -3503045312,
.ADC_volt[2].coeff = (6243816),
.ADC_volt[2].offset = -101524034738,
.ADC_current[0].coeff = 3131950,
.ADC_current[0].offset = (-50953509336),
.ADC_current[1].coeff = 71591803,
.ADC_current[1].offset = (-1164676104750),
.ADC_current[2].coeff = 1457994881,
.ADC_current[2].offset = (-23717445756897),
.ADC_current[3].coeff = 30731877501,
.ADC_current[3].offset = (-499947688305697),
.Usercode2DAC[0].coeff = (-10509141),
.Usercode2DAC[0].offset = 581313489845,
.Usercode2DAC[1].coeff = (-177847688),
.Usercode2DAC[1].offset = 4765751343445,
};
#endif
#ifdef BOARD_C615
{
.ADC_volt[0].coeff = (6213),
.ADC_volt[0].offset = -100904734,
.ADC_volt[1].coeff = (213486),
.ADC_volt[1].offset = -3475774161,
.ADC_volt[2].coeff = (6220838),
.ADC_volt[2].offset = -101367452805,
.ADC_current[0].coeff = 3133669,
.ADC_current[0].offset = (-50985338691),
.ADC_current[1].coeff = 71848701,
.ADC_current[1].offset = (-1168930549263),
.ADC_current[2].coeff = 1465220422,
.ADC_current[2].offset = (-23836711044239),
.ADC_current[3].coeff = 30753809644,
.ADC_current[3].offset = (-500364315274466),
.Usercode2DAC[0].coeff = (-10519306),
.Usercode2DAC[0].offset = 583547544303,
.Usercode2DAC[1].coeff = (-179481859),
.Usercode2DAC[1].offset = 4808633144378,
};
#endif
#ifdef BOARD_C797
{
.ADC_volt[0].coeff = (6285),
.ADC_volt[0].offset = -102399765,
.ADC_volt[1].coeff = (217179),
.ADC_volt[1].offset = -3541219740,
.ADC_volt[2].coeff = (6293290),
.ADC_volt[2].offset = -102701705789,
.ADC_current[0].coeff = 3124793,
.ADC_current[0].offset = (-50785593516),
.ADC_current[1].coeff = 71661923,
.ADC_current[1].offset = (-1164632411724),
.ADC_current[2].coeff = 1459117290,
.ADC_current[2].offset = (-23712400276764),
.ADC_current[3].coeff = 30624856407,
.ADC_current[3].offset = (-497729976849926),
.Usercode2DAC[0].coeff = (-10517402),
.Usercode2DAC[0].offset = 581255473226,
.Usercode2DAC[1].coeff = (-178353177),
.Usercode2DAC[1].offset = 4777407394955,
};
#endif
#ifdef BOARD_C639
{
.ADC_volt[0].coeff = (6208),
.ADC_volt[0].offset = -100729867,
.ADC_volt[1].coeff = (214500),
.ADC_volt[1].offset = -3488858165,
.ADC_volt[2].coeff = (6228268),
.ADC_volt[2].offset = -101395718164,
.ADC_current[0].coeff = 3139511,
.ADC_current[0].offset = (-51174954874),
.ADC_current[1].coeff = 71851912,
.ADC_current[1].offset = (-1171152880960),
.ADC_current[2].coeff = 1461965017,
.ADC_current[2].offset = (-23828340962540),
.ADC_current[3].coeff = 30773724865,
.ADC_current[3].offset = (-501611882239925),
.Usercode2DAC[0].coeff = (-10520659),
.Usercode2DAC[0].offset = 581192312483,
.Usercode2DAC[1].coeff = (-177973792),
.Usercode2DAC[1].offset = 4768259045109,
};
#endif
#ifdef BOARD_C5CD
{
.ADC_volt[0].coeff = (6279),
.ADC_volt[0].offset = -100548659,
.ADC_volt[1].coeff = (216253),
.ADC_volt[1].offset = -3471891549,
.ADC_volt[2].coeff = (6277392),
.ADC_volt[2].offset = -100862395596,
.ADC_current[0].coeff = 3136805,
.ADC_current[0].offset = (-50213343000),
.ADC_current[1].coeff = 72032077,
.ADC_current[1].offset = (-1153034516566),
.ADC_current[2].coeff = 1465628098,
.ADC_current[2].offset = (-23459820455868),
.ADC_current[3].coeff = 30833759075,
.ADC_current[3].offset = (-493561287778940),
.Usercode2DAC[0].coeff = (-10522269),
.Usercode2DAC[0].offset = 578531626885,
.Usercode2DAC[1].coeff = (-177684018),
.Usercode2DAC[1].offset = 4759051659585,
};
#endif
#ifdef BOARD_C771 //die
{
.ADC_volt[0].coeff = (6301),
.ADC_volt[0].offset = -102184705,
.ADC_volt[1].coeff = (216877),
.ADC_volt[1].offset = -3519583281,
.ADC_volt[2].coeff = (6298448),
.ADC_volt[2].offset = -102304286091,
.ADC_current[0].coeff = 3115431,
.ADC_current[0].offset = (-50586460394),
.ADC_current[1].coeff = 71203612,
.ADC_current[1].offset = (-1156022105141),
.ADC_current[2].coeff = 1451318434,
.ADC_current[2].offset = (-23560731221983),
.ADC_current[3].coeff = 30518004246,
.ADC_current[3].offset = (-495456618814855),
.Usercode2DAC[0].coeff = (-10568719),
.Usercode2DAC[0].offset = 585036272447,
.Usercode2DAC[1].coeff = (-179441058),
.Usercode2DAC[1].offset = 4807380622351,
};
#endif
#ifdef BOARD_C6E1 // not well
{
.ADC_volt[0].coeff = (-6251051),
.ADC_volt[0].offset = 102081366120,
.ADC_volt[1].coeff = (-6251051),
.ADC_volt[1].offset = 102081366120,
.ADC_volt[2].coeff = (-6251051),
.ADC_volt[2].offset = 102081366120,
.ADC_current[0].coeff = 2079230,
.ADC_current[0].offset = (-34256067906),
.ADC_current[1].coeff = 64550018,
.ADC_current[1].offset = (-1063052554820),
.ADC_current[2].coeff = 2096336928,
.ADC_current[2].offset = (-34514344284104),
.ADC_current[3].coeff = 60200953965,
.ADC_current[3].offset = (-991270580672004),
.Usercode2DAC[0].coeff = (-10511469),
.Usercode2DAC[0].offset = 563770560100,
.Usercode2DAC[1].coeff = (-10511469),
.Usercode2DAC[1].offset = 563770560100,
};
#endif
#ifdef BOARD_C6D4 // not well
{
.ADC_volt[0].coeff = (6226),
.ADC_volt[0].offset = -100075170,
.ADC_volt[1].coeff = (215972),
.ADC_volt[1].offset = -3484380085,
.ADC_volt[2].coeff = (6223818),
.ADC_volt[2].offset = -100571214617,
.ADC_current[0].coeff = 3136256,
.ADC_current[0].offset = (-50747854551),
.ADC_current[1].coeff = 72219340,
.ADC_current[1].offset = (-1168719058378),
.ADC_current[2].coeff = 1450319129,
.ADC_current[2].offset = (-23465744053517),
.ADC_current[3].coeff = 30710734735,
.ADC_current[3].offset = (-496978137538345),
.Usercode2DAC[0].coeff = (-10543212),
.Usercode2DAC[0].offset = 582976692942,
.Usercode2DAC[1].coeff = (-178746005),
.Usercode2DAC[1].offset = 4789272862069,
};
#endif
// this function turn ADC measure value (0xXXXX) into real voltage
// unit should be uV
static int32_t DecodeADCVolt(uint8_t ADCGain, uint16_t ADC_measure){
@@ -7,7 +7,6 @@ struct _CT{
uint32_t SampleRate_counter;
uint16_t StepTimeCounter;
uint16_t NotifyCounter;
uint32_t StandByCounter;
}CT = {0};
// GPT counter
@@ -23,19 +22,8 @@ struct _GPT{
uint32_t BatteryCheckCounter;
uint32_t GptimerMultiple;
uint32_t StiCounter;
uint32_t LedGCounter;
uint32_t LedRCounter;
uint32_t Gas0Counter;
uint32_t Gas1Counter;
}GPT = {0};
static void InitCT(){
CT.SampleRate_counter = 1;
CT.StepTimeCounter = 1;
CT.NotifyCounter = 1;
CT.StandByCounter = 0;
}
static void InitGPT(){
GPT.GptimerCounter = 0;
GPT.GptimerCounter0 = 0;
@@ -47,9 +35,5 @@ static void InitGPT(){
GPT.BatteryADCCounter = 0;
GPT.BatteryCheckCounter = 0;
GPT.StiCounter = 0;
GPT.LedGCounter = 0;
GPT.LedRCounter = 0;
GPT.Gas0Counter = 0;
GPT.Gas1Counter = 0;
}
#endif
@@ -2,47 +2,61 @@
#ifndef ELITEIV
#define ELITEIV
#define Vset INSTRUCTION.Vset
#define Vset instru.Vset
static void IV_Vscan(IVMode *IV){
if(vscanReset){
if(INSTRUCTION.directionInit == 1){
IV->_direction_up = true;
IV->_current_direction_up = true;
}else if(INSTRUCTION.directionInit == 0){
IV->_direction_up = false;
IV->_current_direction_up = false;
static void iv_vscan(void)
{
struct wm_iv_ctx_t *iv = (struct wm_iv_ctx_t *)wm_get();
if (vscanReset) {
if (instru.directionInit == 1) {
iv->_direction_up = true;
iv->_current_direction_up = true;
} else if (instru.directionInit == 0) {
iv->_direction_up = false;
iv->_current_direction_up = false;
}
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
if(INSTRUCTION.step <= 10){
IV->_Vstep = INSTRUCTION.step * INSTRUCTION.VsetRate / 5;
}else{
IV->_Vstep = INSTRUCTION.step / 5 * INSTRUCTION.VsetRate;
if (instru.step <= 10) {
iv->_Vstep = instru.step * instru.VsetRate / 5;
} else {
iv->_Vstep = instru.step / 5 * instru.VsetRate;
}
Vset = IV->_Vinit;
Vset = iv->_Vinit;
}
if(!vscanReset){
if(IV->_current_direction_up){
if(Vset >= IV->_Vmax){
if (!vscanReset) {
if (iv->_current_direction_up) {
if (Vset >= iv->_Vmax) {
PeriodicEvent = false;
ModeLED(NO_EVENT);
}
}else{
if(Vset <= IV->_Vmin){
} else {
if (Vset <= iv->_Vmin) {
PeriodicEvent = false;
ModeLED(NO_EVENT);
}
}
if (IV->_current_direction_up){
Vset = Vset + IV->_Vstep * GPT.GptimerMultiple;
}else{
Vset = Vset - IV->_Vstep * GPT.GptimerMultiple;
if (iv->_current_direction_up) {
Vset = Vset + iv->_Vstep * GPT.GptimerMultiple;
} else {
Vset = Vset - iv->_Vstep * GPT.GptimerMultiple;
}
}
}
static void vo_vscan(void)
{
struct wm_vo_ctx_t *vo = (struct wm_vo_ctx_t *)wm_get();
if (vscanReset) {
Vset = vo->_Vinit;
}
if(!vscanReset) {
Vset = vo->_Vinit;
}
}
#endif
@@ -1,44 +1,14 @@
#ifndef __INSTR_H__
#define __INSTR_H__
#ifndef ELITEINSTRUCTION
#define ELITEINSTRUCTION
/** Iin, Vin, Vout **/
#define IIN_ADC 0x00
#define VIN_ADC 0x01
#define VOUT_DAC 0x02
#define HIGH_Z 0x03
/** ADC Iin gain level **/
#define I_GAIN_3M 0x00 // largest gain
#define I_GAIN_100K 0x01
#define I_GAIN_3K 0x02
#define I_GAIN_100R 0x03 // the least gain
#define I_GAIN_AUTO 0x04
/** ADC Vin gain level **/
#define VIN_GAIN_1M 0x00
#define VIN_GAIN_30K 0x01
#define VIN_GAIN_1K 0x02
#define VIN_GAIN_AUTO 0x03
/** Vout gain level **/
#define VOUT_GAIN_240K 0x00
#define VOUT_GAIN_15K 0x01
#define VOUT_GAIN_AUTO 0x02
/* DAC reset parameter */
#define DAC_ZERO 25000
// Step time macro
#define STEPTIME_HALF_SEC 5000
#define STEPTIME_ONE_SEC 10000
#define STEPTIME_TWO_SEC 20000
#ifdef __cpulsplus
extern "C" {
#endif
/*==============================
==== headstage instruction ====
=============================*/
struct HEADSTAGE_INSTRUCTION {
uint8_t chip_id;
uint8_t eliteFxn;
@@ -56,7 +26,7 @@ struct HEADSTAGE_INSTRUCTION {
int32_t Vmin;
/** ADC parameter **/
uint8_t sampleRateIndex;
uint8_t notifyRateIndex;
uint32_t sampleRate;
uint8_t VoViSwitch;
uint8_t AutoGainEnable;
@@ -92,79 +62,43 @@ struct HEADSTAGE_INSTRUCTION {
uint16_t sti_cy;
uint16_t sti_loop;
uint8_t ledG_sw1;
uint8_t ledG_sw2;
uint8_t ledG_sw3;
uint8_t ledG_sw4;
uint8_t ledG_sw5;
uint8_t ledG_sw6;
uint8_t ledG_sw7;
int32_t ledG_t1;
int32_t ledG_t2;
int32_t ledG_t3;
int32_t ledG_t4;
int32_t ledG_t5;
int32_t ledG_t6;
int32_t ledG_t7;
uint16_t ledG_cy;
uint16_t ledG_loop;
uint8_t ledR_sw1;
uint8_t ledR_sw2;
uint8_t ledR_sw3;
uint8_t ledR_sw4;
uint8_t ledR_sw5;
uint8_t ledR_sw6;
uint8_t ledR_sw7;
int32_t ledR_t1;
int32_t ledR_t2;
int32_t ledR_t3;
int32_t ledR_t4;
int32_t ledR_t5;
int32_t ledR_t6;
int32_t ledR_t7;
uint16_t ledR_cy;
uint16_t ledR_loop;
uint8_t gas0_sw1;
uint8_t gas0_sw2;
uint8_t gas0_sw3;
uint8_t gas0_sw4;
uint8_t gas0_sw5;
uint8_t gas0_sw6;
uint8_t gas0_sw7;
int32_t gas0_t1;
int32_t gas0_t2;
int32_t gas0_t3;
int32_t gas0_t4;
int32_t gas0_t5;
int32_t gas0_t6;
int32_t gas0_t7;
uint16_t gas0_cy;
uint16_t gas0_loop;
uint8_t gas1_sw1;
uint8_t gas1_sw2;
uint8_t gas1_sw3;
uint8_t gas1_sw4;
uint8_t gas1_sw5;
uint8_t gas1_sw6;
uint8_t gas1_sw7;
int32_t gas1_t1;
int32_t gas1_t2;
int32_t gas1_t3;
int32_t gas1_t4;
int32_t gas1_t5;
int32_t gas1_t6;
int32_t gas1_t7;
uint16_t gas1_cy;
uint16_t gas1_loop;
uint16_t StepTime;
uint8_t AdcChannel;
} INSTRUCTION = {0};
} instru = {0};
/** Iin, Vin, Vout **/
#define IIN_ADC 0x00
#define VIN_ADC 0x01
#define VOUT_DAC 0x02
#define HIGH_Z 0x03
/** ADC Iin gain level **/
#define I_GAIN_3M 0x00 // largest gain
#define I_GAIN_100K 0x01
#define I_GAIN_3K 0x02
#define I_GAIN_100R 0x03 // the least gain
#define I_GAIN_AUTO 0x04
/** ADC Vin gain level **/
#define VIN_GAIN_1M 0x00
#define VIN_GAIN_30K 0x01
#define VIN_GAIN_1K 0x02
#define VIN_GAIN_AUTO 0x03
/** Vout gain level **/
#define VOUT_GAIN_240K 0x00
#define VOUT_GAIN_15K 0x01
#define VOUT_GAIN_AUTO 0x02
/* DAC reset parameter */
#define DAC_ZERO 25000
// Step time macro
#define STEPTIME_HALF_SEC 5000
#define STEPTIME_ONE_SEC 10000
#define STEPTIME_TWO_SEC 20000
/*********************************************************************
* @fn InitEliteInstruction
@@ -176,120 +110,58 @@ struct HEADSTAGE_INSTRUCTION {
* @return None.
*/
static void InitEliteInstruction(){
INSTRUCTION.chip_id = 0;
INSTRUCTION.eliteFxn = 0; //default is a null event
INSTRUCTION.VsetRateIndex = 0;
INSTRUCTION.VsetRate = 2;
INSTRUCTION.Vset = 0;
INSTRUCTION.VoltConstant = DAC_ZERO; //DAC_ZERO is about 0V
INSTRUCTION.directionInit = 1; //0:reverse 1:forward
INSTRUCTION.step = 0;
INSTRUCTION.Ve1 = DAC_ZERO;
INSTRUCTION.Ve2 = DAC_ZERO;
INSTRUCTION.Vinit = 0;
INSTRUCTION.Vmax = 0;
INSTRUCTION.Vmin = 0;
INSTRUCTION.sampleRateIndex = 1;
INSTRUCTION.sampleRate = 100;
INSTRUCTION.VoViSwitch = 0x01; //0:user see Vo 1: user see Vi
INSTRUCTION.AutoGainEnable = 1;
INSTRUCTION.VinAutoGainEnable = 1;
INSTRUCTION.VoutAutoGainEnable = 1;
INSTRUCTION.ADCGainLevel = I_GAIN_AUTO;
INSTRUCTION.VoutGainLevel = VOUT_GAIN_AUTO;
INSTRUCTION.VinADCGainLevel = VIN_GAIN_AUTO;
INSTRUCTION.notifyRate = STEPTIME_ONE_SEC;
INSTRUCTION.cycleNumber = 1;
INSTRUCTION.charge = 1; //0:discharge 1:charge
INSTRUCTION.constantCurrent = 0;
INSTRUCTION.Currentmax = 0;
INSTRUCTION.StepTime = STEPTIME_ONE_SEC;
INSTRUCTION.AdcChannel = 0;
instru.chip_id = 0;
instru.eliteFxn = 0; //default is a null event
instru.VsetRateIndex = 0;
instru.VsetRate = 2;
instru.Vset = 0;
instru.VoltConstant = DAC_ZERO; //DAC_ZERO is about 0V
instru.directionInit = 1; //0:reverse 1:forward
instru.step = 0;
instru.Ve1 = DAC_ZERO;
instru.Ve2 = DAC_ZERO;
instru.Vinit = 0;
instru.Vmax = 0;
instru.Vmin = 0;
instru.notifyRateIndex = 100;
instru.sampleRate = 15;
instru.VoViSwitch = 0x01; //0:user see Vo 1: user see Vi
instru.AutoGainEnable = 1;
instru.VinAutoGainEnable = 1;
instru.VoutAutoGainEnable = 1;
instru.ADCGainLevel = I_GAIN_AUTO;
instru.VoutGainLevel = VOUT_GAIN_AUTO;
instru.VinADCGainLevel = VIN_GAIN_AUTO;
instru.notifyRate = STEPTIME_ONE_SEC;
instru.cycleNumber = 1;
instru.charge = 1; //0:discharge 1:charge
instru.constantCurrent = 0;
instru.Currentmax = 0;
instru.StepTime = STEPTIME_ONE_SEC;
instru.AdcChannel = 0;
//pulse mode
INSTRUCTION.sti_t1 = 0;
INSTRUCTION.sti_t2 = 0;
INSTRUCTION.sti_t3 = 0;
INSTRUCTION.sti_t4 = 0;
INSTRUCTION.sti_t5 = 0;
INSTRUCTION.sti_t6 = 0;
INSTRUCTION.sti_t7 = 0;
INSTRUCTION.sti_v1 = DAC_ZERO;
INSTRUCTION.sti_v2 = DAC_ZERO;
INSTRUCTION.sti_v3 = DAC_ZERO;
INSTRUCTION.sti_v4 = DAC_ZERO;
INSTRUCTION.sti_v5 = DAC_ZERO;
INSTRUCTION.sti_v6 = DAC_ZERO;
INSTRUCTION.sti_v7 = DAC_ZERO;
INSTRUCTION.sti_loop = 1;
INSTRUCTION.sti_cy = 0;
instru.sti_t1 = 0;
instru.sti_t2 = 0;
instru.sti_t3 = 0;
instru.sti_t4 = 0;
instru.sti_t5 = 0;
instru.sti_t6 = 0;
instru.sti_t7 = 0;
instru.sti_v1 = DAC_ZERO;
instru.sti_v2 = DAC_ZERO;
instru.sti_v3 = DAC_ZERO;
instru.sti_v4 = DAC_ZERO;
instru.sti_v5 = DAC_ZERO;
instru.sti_v6 = DAC_ZERO;
instru.sti_v7 = DAC_ZERO;
instru.sti_loop = 1;
instru.sti_cy = 0;
}
INSTRUCTION.ledG_sw1 = false;
INSTRUCTION.ledG_sw2 = false;
INSTRUCTION.ledG_sw3 = false;
INSTRUCTION.ledG_sw4 = false;
INSTRUCTION.ledG_sw5 = false;
INSTRUCTION.ledG_sw6 = false;
INSTRUCTION.ledG_sw7 = false;
INSTRUCTION.ledG_t1 = 0;
INSTRUCTION.ledG_t2 = 0;
INSTRUCTION.ledG_t3 = 0;
INSTRUCTION.ledG_t4 = 0;
INSTRUCTION.ledG_t5 = 0;
INSTRUCTION.ledG_t6 = 0;
INSTRUCTION.ledG_t7 = 0;
INSTRUCTION.ledG_cy = 0;
INSTRUCTION.ledG_loop = 0;
INSTRUCTION.ledR_sw1 = false;
INSTRUCTION.ledR_sw2 = false;
INSTRUCTION.ledR_sw3 = false;
INSTRUCTION.ledR_sw4 = false;
INSTRUCTION.ledR_sw5 = false;
INSTRUCTION.ledR_sw6 = false;
INSTRUCTION.ledR_sw7 = false;
INSTRUCTION.ledR_t1 = 0;
INSTRUCTION.ledR_t2 = 0;
INSTRUCTION.ledR_t3 = 0;
INSTRUCTION.ledR_t4 = 0;
INSTRUCTION.ledR_t5 = 0;
INSTRUCTION.ledR_t6 = 0;
INSTRUCTION.ledR_t7 = 0;
INSTRUCTION.ledR_cy = 0;
INSTRUCTION.ledR_loop = 0;
INSTRUCTION.gas0_sw1 = false;
INSTRUCTION.gas0_sw2 = false;
INSTRUCTION.gas0_sw3 = false;
INSTRUCTION.gas0_sw4 = false;
INSTRUCTION.gas0_sw5 = false;
INSTRUCTION.gas0_sw6 = false;
INSTRUCTION.gas0_sw7 = false;
INSTRUCTION.gas0_t1 = 0;
INSTRUCTION.gas0_t2 = 0;
INSTRUCTION.gas0_t3 = 0;
INSTRUCTION.gas0_t4 = 0;
INSTRUCTION.gas0_t5 = 0;
INSTRUCTION.gas0_t6 = 0;
INSTRUCTION.gas0_t7 = 0;
INSTRUCTION.gas0_cy = 0;
INSTRUCTION.gas0_loop = 0;
INSTRUCTION.gas1_sw1 = false;
INSTRUCTION.gas1_sw2 = false;
INSTRUCTION.gas1_sw3 = false;
INSTRUCTION.gas1_sw4 = false;
INSTRUCTION.gas1_sw5 = false;
INSTRUCTION.gas1_sw6 = false;
INSTRUCTION.gas1_sw7 = false;
INSTRUCTION.gas1_t1 = 0;
INSTRUCTION.gas1_t2 = 0;
INSTRUCTION.gas1_t3 = 0;
INSTRUCTION.gas1_t4 = 0;
INSTRUCTION.gas1_t5 = 0;
INSTRUCTION.gas1_t6 = 0;
INSTRUCTION.gas1_t7 = 0;
INSTRUCTION.gas1_cy = 0;
INSTRUCTION.gas1_loop = 0;
#ifdef __cpulsplus
}
#endif
#endif
@@ -50,14 +50,14 @@ static void EliteKeyPress(uint8_t key) {
}
ShutDownCounter ++;
} else {
if (OriginEliteFxn == INSTRUCTION.eliteFxn) { // old function == currunt instruction
if (OriginEliteFxn == instru.eliteFxn) { // old function == currunt instruction
if (ShutDownCounter != 0) {
// dark LED
checkFlafLED();
ShutDownCounter = 0;
}
} else { // old function != currunt instruction
OriginEliteFxn = INSTRUCTION.eliteFxn;
OriginEliteFxn = instru.eliteFxn;
if (ShutDownCounter != 0) {
ShutDownCounter = 0;
}
@@ -5,47 +5,34 @@
#define DARKLED 0xE1
#define LIGHTLED 0xE8
/* Channels for TRIG01 LED notation */
#define LED_PR0 0x00
#define LED_D0 0x01
#define LED_A0 0x02
#define LED_A2 0x03
#define LED_A3 0x04
#define LED_A1 0x05
#define LED_D1 0x06
#define LED_PR1 0x07
static void WorkModeLED();
static void update_LED_status (uint8_t chan, uint8_t bright, uint8_t red, uint8_t green, uint8_t blue);
static void LED_color(uint8_t bright, uint8_t red, uint8_t green, uint8_t blue) {
// spi_LEDtxbuf[0] = 0x0000;
// spi_LEDtxbuf[1] = 0x0000;
//
// for (int i = 2; i < SPI_LED_SIZE - 2; i += 2) {
// spi_LEDtxbuf[i] = 0xE000 | ((uint16_t)bright << 8) | blue;
// spi_LEDtxbuf[i + 1] = ((uint16_t)green << 8) | red;
// }
//
// spi_LEDtxbuf[SPI_LED_SIZE - 2] = 0xffff;
// spi_LEDtxbuf[SPI_LED_SIZE - 1] = 0xffff;
//
// LED_SPI(SPI_LED_SIZE, spi_LEDtxbuf, spi_LEDrxbuf);
spi_LEDtxbuf[0] = 0x0000;
spi_LEDtxbuf[1] = 0x0000;
for (int i = 2; i < SPI_LED_SIZE - 2; i += 2) {
spi_LEDtxbuf[i] = 0xE000 | ((uint16_t)bright << 8) | blue;
spi_LEDtxbuf[i + 1] = ((uint16_t)green << 8) | red;
}
spi_LEDtxbuf[SPI_LED_SIZE - 2] = 0xffff;
spi_LEDtxbuf[SPI_LED_SIZE - 1] = 0xffff;
LED_SPI(SPI_LED_SIZE, spi_LEDtxbuf, spi_LEDrxbuf);
}
static void Elite_led_color(uint16_t color){
switch (color) {
case COLOR_RED: {
LED_color(DARKLED, 0x50, 0x00, 0x00);
LED_color(DARKLED, 0xFF, 0x00, 0x00);
break;
}
case COLOR_ORANGE: {
LED_color(DARKLED, 0x50, 0x58, 0x09);
LED_color(DARKLED, 0xFF, 0x58, 0x09);
break;
}
case COLOR_YELLOW: {
LED_color(LIGHTLED, 0x50, 0x80, 0x00);
LED_color(LIGHTLED, 0xFF, 0x80, 0x00);
break;
}
case COLOR_GREEN: {
@@ -65,21 +52,42 @@ static void Elite_led_color(uint16_t color){
break;
}
case COLOR_MAGENTA: {
LED_color(DARKLED, 0x50, 0x00, 0x80);
LED_color(DARKLED, 0xFF, 0x00, 0x80);
break;
}
case COLOR_PURPLE: {
LED_color(DARKLED, 0x50, 0x00, 0xFF);
LED_color(DARKLED, 0xFF, 0x00, 0xFF);
break;
}
case COLOR_WHITE: {
LED_color(DARKLED, 0x50, 0xFF, 0xFF);
LED_color(DARKLED, 0xCA, 0xFF, 0xFF);
break;
}
case COLOR_BLACK: {
LED_color(0x00, 0x00, 0x00, 0x00);
break;
}
//dark LED
case COLOR_YELLOW_DARK: {
LED_color(DARKLED, 0xFF, 0x80, 0x00);
break;
}
case COLOR_GREEN_DARK: {
LED_color(DARKLED, 0x00, 0x33, 0x00);
break;
}
case COLOR_BLUE_DARK: {
LED_color(DARKLED, 0x00, 0x00, 0x33);
break;
}
case COLOR_CYAN_DARK: {
LED_color(DARKLED, 0x00, 0x10, 0x10);
break;
}
case COLOR_PURPLE_DARK: {
LED_color(DARKLED, 0x55, 0x00, 0x55);
break;
}
default: {
break;
}
@@ -145,35 +153,35 @@ static void checkFlafLED() {
}
static void WorkModeLED() {
switch (INSTRUCTION.eliteFxn) {
case IV_CURVE:
case CV_CURVE:
switch (instru.eliteFxn) {
case CURVE_IV:
case CURVE_IV_CY:
case DIFFERENTIAL_PULSE_VOLTAMMETRY:
case SQUARE_WAVE_VOLTAMMETRY:
case VOLT_OUTPUT:
case ZT_CURVE:
case VT_CURVE:
case IT_CURVE:
case ADC_TEST:
case CYCLIC_VOLTAMMETRY:
case LINEAR_SWEEP_VOLTAMMETRY:
case CONSTANT_VSCAN:{
case CURVE_VO:
case CURVE_RT:
case CURVE_VT:
case CURVE_IT:
case CURVE_CALI_ADCTEST:
case CURVE_CV:
case CURVE_LSV:
case CURVE_CA:{
WORKLED();
break;
}
case PULSE_MODE:{
case CURVE_PULSE:{
// Elite_led_color(COLOR_YELLOW);
WORKLED();
break;
}
case CONSTANT_CURRENT:{
case CURVE_CC:{
WORKLED();
break;
}
case CALI_ADC_MODE:{
if(INSTRUCTION.AdcChannel == IIN_ADC){
case CURVE_CALI_ADC:{
if(instru.AdcChannel == IIN_ADC){
Elite_led_color(COLOR_RED);
}else if(INSTRUCTION.AdcChannel == VIN_ADC){
}else if(instru.AdcChannel == VIN_ADC){
Elite_led_color(COLOR_ORANGE);
}
@@ -190,90 +198,4 @@ static void WorkModeLED() {
}
}
static void LED_channel_write(uint8_t chan, uint8_t bright, uint8_t red, uint8_t green, uint8_t blue) {
update_LED_status(chan, bright, red, green, blue);
spi_LEDtxbuf[0] = 0x0000;
spi_LEDtxbuf[1] = 0x0000;
for (int i = 2; i < SPI_LED_SIZE - 2; i += 2) {
spi_LEDtxbuf[i] = LED.LED_buf[i];
spi_LEDtxbuf[i+1] = LED.LED_buf[i+1];
}
spi_LEDtxbuf[SPI_LED_SIZE - 2] = 0xffff;
spi_LEDtxbuf[SPI_LED_SIZE - 1] = 0xffff;
LED_SPI(SPI_LED_SIZE, spi_LEDtxbuf, spi_LEDrxbuf);
}
static void update_LED_status (uint8_t chan, uint8_t bright, uint8_t red, uint8_t green, uint8_t blue) {
switch(chan) {
case LED_PR0: {
LED.LED_buf[2] = 0xE000 | ((uint16_t)bright << 8) | blue;
LED.LED_buf[3] = ((uint16_t)green << 8) | red;
break;
}
case LED_D0: {
LED.LED_buf[4] = 0xE000 | ((uint16_t)bright << 8) | blue;
LED.LED_buf[5] = ((uint16_t)green << 8) | red;
break;
}
case LED_A0: {
LED.LED_buf[6] = 0xE000 | ((uint16_t)bright << 8) | blue;
LED.LED_buf[7] = ((uint16_t)green << 8) | red;
break;
}
case LED_A2: {
LED.LED_buf[8] = 0xE000 | ((uint16_t)bright << 8) | blue;
LED.LED_buf[9] = ((uint16_t)green << 8) | red;
break;
}
case LED_A3: {
LED.LED_buf[10] = 0xE000 | ((uint16_t)bright << 8) | blue;
LED.LED_buf[11] = ((uint16_t)green << 8) | red;
break;
}
case LED_A1: {
LED.LED_buf[12] = 0xE000 | ((uint16_t)bright << 8) | blue;
LED.LED_buf[13] = ((uint16_t)green << 8) | red;
break;
}
case LED_D1: {
LED.LED_buf[14] = 0xE000 | ((uint16_t)bright << 8) | blue;
LED.LED_buf[15] = ((uint16_t)green << 8) | red;
break;
}
case LED_PR1: {
LED.LED_buf[16] = 0xE000 | ((uint16_t)bright << 8) | blue;
LED.LED_buf[17] = ((uint16_t)green << 8) | red;
break;
}
default: {
break;
}
}
}
static void TRIG0_LED_Init() {
spi_LEDtxbuf[0] = 0x0000;
spi_LEDtxbuf[1] = 0x0000;
for (int i = 2; i < SPI_LED_SIZE - 2; i += 2) {
spi_LEDtxbuf[i] = 0xE000;
spi_LEDtxbuf[i+1] = 0x0000;
}
spi_LEDtxbuf[SPI_LED_SIZE - 2] = 0xffff;
spi_LEDtxbuf[SPI_LED_SIZE - 1] = 0xffff;
LED_SPI(SPI_LED_SIZE, spi_LEDtxbuf, spi_LEDrxbuf);
}
#endif
@@ -1,14 +0,0 @@
#ifndef ELITE_LED_INIT
#define ELITE_LED_INIT
static void InitLED() {
for (int i = 2; i < SPI_LED_SIZE - 2; i += 2) {
LED.LED_buf[i] = 0xE000;
LED.LED_buf[i+1] = 0x0000;
}
}
#endif
@@ -1,97 +1,79 @@
#ifndef ELITELSV
#define ELITELSV
#define Vset INSTRUCTION.Vset
#define Vset instru.Vset
static uint16_t LSVCurve(LSVMode *LSV){
static uint16_t DACOutCode;
static int32_t Vin;
static int32_t Vout;
static int32_t DeltaVout;
static void lsv_volt_out(void)
{
struct wm_lsv_ctx_t *lsv = (struct wm_lsv_ctx_t *)wm_get();
struct wm_meas_t *m = &lsv->measure;
uint16_t DACOutCode;
int32_t Vin;
int32_t Vout;
int32_t DeltaVout;
Vin = LSV->_measureVin * 200;//[5nV]
if(DACReset){
Vin = m->_measureVin * 200;//[5nV]
if (DACReset) {
Vout = Vset + Vin;
DACReset = false;
}else{
} else {
DeltaVout = Vset - (Vout - Vin);
Vout = Vout + DeltaVout;
}
INSTRUCTION.VoltConstant = Vout / 40000 + 25000;//5nV=>usercode
DACOutCode = Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.VoltConstant);
instru.VoltConstant = Vout / 40000 + 25000;//5nV=>usercode
DACOutCode = Usercode_Correction_to_DAC(instru.VoutGainLevel, instru.VoltConstant);
int32_t RealV2;
RealV2 = (int32_t)((Vout - Vin) / 200);//[1uV]
InputNotify(NOTIFY_VOLT, RealV2);
int32_t RealV;
RealV = (int32_t)(Vout / 200);//[1uV]
InputNotify(NOTIFY_IMPEDANCE, RealV);
// int32_t RealV;
// RealV = (int32_t)(Vout / 200);//[1uV]
// InputNotify(NOTIFY_IMPEDANCE, RealV);
DAC_outputV(DACOutCode);
//
return DACOutCode;
return;
}
static void LSV_Vscan(LSVMode *LSV){
static void lsv_vscan(void)
{
struct wm_lsv_ctx_t *lsv = (struct wm_lsv_ctx_t *)wm_get();
NotifyCycleNumber = (INSTRUCTION.cycleNumber - LSV->_cycleNumber + 1);
NotifyCycleNumber = (instru.cycleNumber - lsv->_cycleNumber + 1);
if(vscanReset){
if(INSTRUCTION.directionInit == 1){
LSV->_direction_up = true;
LSV->_current_direction_up = true;
}else{
LSV->_direction_up = false;
LSV->_current_direction_up = false;
if (vscanReset) {
if (instru.directionInit == 1) {
lsv->_direction_up = true;
lsv->_current_direction_up = true;
} else {
lsv->_direction_up = false;
lsv->_current_direction_up = false;
}
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
if(INSTRUCTION.step <= 10){
LSV->_Vstep = INSTRUCTION.step * INSTRUCTION.VsetRate / 5;
}else{
LSV->_Vstep = INSTRUCTION.step / 5 * INSTRUCTION.VsetRate;
if (instru.step <= 10) {
lsv->_Vstep = instru.step * instru.VsetRate / 5;
} else {
lsv->_Vstep = instru.step / 5 * instru.VsetRate;
}
Vset = LSV->_Vinit;
Vset = lsv->_Vinit;
}
if(!vscanReset){
if (!vscanReset) {
if (LSV->_current_direction_up){
Vset = Vset + LSV->_Vstep * GPT.GptimerMultiple;
}else{
Vset = Vset - LSV->_Vstep * GPT.GptimerMultiple;
if (lsv->_current_direction_up) {
Vset = Vset + lsv->_Vstep * GPT.GptimerMultiple;
} else {
Vset = Vset - lsv->_Vstep * GPT.GptimerMultiple;
}
/*stop condition*/
if (Vset >= LSV->_Vmax){
ModeLED(POST_WORK);
// PeriodicEvent = false;
Vset = LSV->_Vmin;
InitEliteFlag();
INSTRUCTION.eliteFxn = CONSTANT_CURRENT;
INSTRUCTION.sampleRate = 15;
INSTRUCTION.charge = 0x01;
INSTRUCTION.constantCurrent = 0x00;
INSTRUCTION.Vmax = 0xC350;
INSTRUCTION.Vmin = 0x0000;
INSTRUCTION.notifyRate = 500;
INSTRUCTION.VoViSwitch = 0x02;//read Vscan = Vout - Vin
}else if (Vset <= LSV->_Vmin){
ModeLED(POST_WORK);
// PeriodicEvent = false;
Vset = LSV->_Vmax;
InitEliteFlag();
INSTRUCTION.eliteFxn = CONSTANT_CURRENT;
INSTRUCTION.sampleRate = 15;
INSTRUCTION.charge = 0x01;
INSTRUCTION.constantCurrent = 0x00;
INSTRUCTION.Vmax = 0xC350;
INSTRUCTION.Vmin = 0x0000;
INSTRUCTION.notifyRate = 500;
INSTRUCTION.VoViSwitch = 0x02;//read Vscan = Vout - Vin
if (Vset >= lsv->_Vmax) {
PeriodicEvent = false;
} else if (Vset <= lsv->_Vmin) {
PeriodicEvent = false;
}
}
}
@@ -29,6 +29,7 @@ static uint8_t NotifyVolt[4] = {0};
static uint8_t NotifyImpedance[4] = {0};
static uint8_t NotifyVoltBat[4] = {0};
static uint16_t NotifyCycleNumber = 0;
static uint8_t finishMode = 0;
// ****************** New Notify Format ******************************** //
/*
@@ -89,7 +90,7 @@ static uint16_t NotifyCycleNumber = 0;
static void SendNotify() {
initDATBuf();
not_buf[0] = INSTRUCTION.chip_id;
not_buf[0] = instru.chip_id;
for (int i = 0; i < 4; i++) {
not_buf[i + 1] = NotifyCurrent[i];
@@ -108,7 +109,9 @@ static void SendNotify() {
not_buf[17] = (NotifyCycleNumber >> 8) & 0xff;
not_buf[18] = NotifyCycleNumber & 0xff;
for (int i = 19; i < BLE_DAT_BUFF_SIZE; i++){
not_buf[19] = (finishMode << 7) & 0x80;
for (int i = 20; i < BLE_DAT_BUFF_SIZE; i++){
not_buf[i] = 0;
}
@@ -136,6 +139,7 @@ static void initCISBuf(){
static void initRawDataBuf(){
not_time_stamp = 0;
NotifyCycleNumber = 0;
finishMode = 0;
for (int i = 0; i < 4; i++){
NotifyCurrent[i] = 0;
@@ -148,7 +152,7 @@ static void FlushNotify(){
initRawDataBuf();
initDATBuf();
not_buf[0] = INSTRUCTION.chip_id;
not_buf[0] = instru.chip_id;
SimpleProfile_SetParameter(BLE_DAT_BUFF_CHAR, BLE_DAT_BUFF_SIZE, not_buf);
}
@@ -1,528 +1,115 @@
#ifndef ELITEPULSE
#define ELITEPULSE
#define Vset INSTRUCTION.Vset
#define Vset instru.Vset
static void PULSE_Vscan(PULSEMode *PULSE)
static void pulse_vscan(void)
{
struct wm_pulse_ctx_t *pulse = (struct wm_pulse_ctx_t *)wm_get();
static uint16_t lastVolt;
static uint16_t testV;
if (stiFirstTime) {
stiFirstTime = false;
lastVolt = 25000;
PULSE->_sti_t_flag = 1;
PULSE->_sti_v = PULSE->_sti_v1;
PULSE->_sti_t = PULSE->_sti_t1;
if (PULSE->_sti_t == 1) {
PULSE->_sti_v = lastVolt;
pulse->_sti_t_flag = 1;
pulse->_sti_v = pulse->_sti_v1;
pulse->_sti_t = pulse->_sti_t1;
if (pulse->_sti_t == 1) {
pulse->_sti_v = lastVolt;
}
} else if(!stiFirstTime) {
if (GPT.StiCounter >= PULSE->_sti_t) {
GPT.StiCounter -= PULSE->_sti_t; //to get right time
if (GPT.StiCounter >= pulse->_sti_t) {
GPT.StiCounter -= pulse->_sti_t; //to get right time
if (PULSE->_sti_lp > 0) {
if (PULSE->_sti_cy > 0) {
if (PULSE->_sti_t_flag == 1) {
PULSE->_sti_t_flag = 2;
PULSE->_sti_v = PULSE->_sti_v2;
PULSE->_sti_t = PULSE->_sti_t2;
if (PULSE->_sti_t == 1) {
PULSE->_sti_v = lastVolt;
if (pulse->_sti_lp > 0) {
if (pulse->_sti_cy > 0) {
if (pulse->_sti_t_flag == 1) {
pulse->_sti_t_flag = 2;
pulse->_sti_v = pulse->_sti_v2;
pulse->_sti_t = pulse->_sti_t2;
if (pulse->_sti_t == 1) {
pulse->_sti_v = lastVolt;
}
} else if (PULSE->_sti_t_flag == 2) {
PULSE->_sti_t_flag = 3;
PULSE->_sti_v = PULSE->_sti_v3;
PULSE->_sti_t = PULSE->_sti_t3;
if (PULSE->_sti_t == 1) {
PULSE->_sti_v = lastVolt;
} else if (pulse->_sti_t_flag == 2) {
pulse->_sti_t_flag = 3;
pulse->_sti_v = pulse->_sti_v3;
pulse->_sti_t = pulse->_sti_t3;
if (pulse->_sti_t == 1) {
pulse->_sti_v = lastVolt;
}
} else if (PULSE->_sti_t_flag == 3) {
PULSE->_sti_cy -- ;
if (PULSE->_sti_cy == 0) {
PULSE->_sti_t_flag = 4;
PULSE->_sti_v = PULSE->_sti_v4;
PULSE->_sti_t = PULSE->_sti_t4;
if (PULSE->_sti_t == 1) {
PULSE->_sti_v = lastVolt;
} else if (pulse->_sti_t_flag == 3) {
pulse->_sti_cy -- ;
if (pulse->_sti_cy == 0) {
pulse->_sti_t_flag = 4;
pulse->_sti_v = pulse->_sti_v4;
pulse->_sti_t = pulse->_sti_t4;
if (pulse->_sti_t == 1) {
pulse->_sti_v = lastVolt;
}
} else {
PULSE->_sti_t_flag = 2;
PULSE->_sti_v = PULSE->_sti_v2;
PULSE->_sti_t = PULSE->_sti_t2;
if (PULSE->_sti_t == 1) {
PULSE->_sti_v = lastVolt;
pulse->_sti_t_flag = 2;
pulse->_sti_v = pulse->_sti_v2;
pulse->_sti_t = pulse->_sti_t2;
if (pulse->_sti_t == 1) {
pulse->_sti_v = lastVolt;
}
}
}
} else if (PULSE->_sti_cy <= 0){
if (PULSE->_sti_t_flag == 4) {
PULSE->_sti_lp -- ;
if (PULSE->_sti_lp > 0) {
PULSE->_sti_cy = INSTRUCTION.sti_cy;
PULSE->_sti_t_flag = 2;
PULSE->_sti_v = PULSE->_sti_v2;
PULSE->_sti_t = PULSE->_sti_t2;
if (PULSE->_sti_t == 1) {
PULSE->_sti_v = lastVolt;
} else if (pulse->_sti_cy <= 0){
if (pulse->_sti_t_flag == 4) {
pulse->_sti_lp -- ;
if (pulse->_sti_lp > 0) {
pulse->_sti_cy = instru.sti_cy;
pulse->_sti_t_flag = 2;
pulse->_sti_v = pulse->_sti_v2;
pulse->_sti_t = pulse->_sti_t2;
if (pulse->_sti_t == 1) {
pulse->_sti_v = lastVolt;
}
} else {
PULSE->_sti_t_flag = 5;
PULSE->_sti_v = PULSE->_sti_v5;
PULSE->_sti_t = PULSE->_sti_t5;
if (PULSE->_sti_t == 1) {
PULSE->_sti_v = lastVolt;
pulse->_sti_t_flag = 5;
pulse->_sti_v = pulse->_sti_v5;
pulse->_sti_t = pulse->_sti_t5;
if (pulse->_sti_t == 1) {
pulse->_sti_v = lastVolt;
}
}
}
}
} else if (PULSE->_sti_lp <= 0) {
if (PULSE->_sti_t_flag == 5) {
PULSE->_sti_t_flag = 6;
PULSE->_sti_v = PULSE->_sti_v6;
PULSE->_sti_t = PULSE->_sti_t6;
if (PULSE->_sti_t == 1) {
PULSE->_sti_v = lastVolt;
} else if (pulse->_sti_lp <= 0) {
if (pulse->_sti_t_flag == 5) {
pulse->_sti_t_flag = 6;
pulse->_sti_v = pulse->_sti_v6;
pulse->_sti_t = pulse->_sti_t6;
if (pulse->_sti_t == 1) {
pulse->_sti_v = lastVolt;
}
} else if (PULSE->_sti_t_flag == 6) {
PULSE->_sti_t_flag = 7;
PULSE->_sti_v = PULSE->_sti_v7;
PULSE->_sti_t = PULSE->_sti_t7;
if (PULSE->_sti_t == 1) {
PULSE->_sti_v = lastVolt;
} else if (pulse->_sti_t_flag == 6) {
pulse->_sti_t_flag = 7;
pulse->_sti_v = pulse->_sti_v7;
pulse->_sti_t = pulse->_sti_t7;
if (pulse->_sti_t == 1) {
pulse->_sti_v = lastVolt;
}
} else if (PULSE->_sti_t_flag == 7) {
PULSE->_sti_v = 25000;
} else if (pulse->_sti_t_flag == 7) {
pulse->_sti_v = 25000;
PeriodicEvent = false;
megaTrigEnable = false;
PIN15_setOutputValue(HIGH_Z_MODE, 0); // 0: open highz;
ModeLED(NO_EVENT);
}
}
}
}
//InputNotify(NOTIFY_IMPEDANCE, testV);
if (lastVolt != PULSE->_sti_v) {
lastVolt = PULSE->_sti_v;
//if (PULSE->_sti_v == 25000) {
if (lastVolt != pulse->_sti_v) {
lastVolt = pulse->_sti_v;
//if (pulse->_sti_v == 25000) {
// PIN15_setOutputValue(HIGH_Z_MODE, 0); // 1 => close high_z mode
//} else {
// PIN15_setOutputValue(HIGH_Z_MODE, 1); // 1 => close high_z mode
//}
DAC_outputV(Usercode_Correction_to_DAC(VOUT_GAIN_240K, PULSE->_sti_v));
DAC_outputV(Usercode_Correction_to_DAC(VOUT_GAIN_240K, PULSE->_sti_v));
}
}
static void PULSE_ledG(PULSEMode *PULSE)
{
static bool lastSwitch;
if (ledGFirstTime) {
ledGFirstTime = false;
lastSwitch = false;
PULSE->_ledG_t_flag = 1;
PULSE->_ledG_sw = PULSE->_ledG_sw1;
PULSE->_ledG_t = PULSE->_ledG_t1;
if (PULSE->_ledG_t == 1) {
PULSE->_ledG_sw = lastSwitch;
}
} else if(!ledGFirstTime) {
if (GPT.LedGCounter >= PULSE->_ledG_t) {
GPT.LedGCounter -= PULSE->_ledG_t; //to get right time
if (PULSE->_ledG_lp > 0) {
if (PULSE->_ledG_cy > 0) {
if (PULSE->_ledG_t_flag == 1) {
PULSE->_ledG_t_flag = 2;
PULSE->_ledG_sw = PULSE->_ledG_sw2;
PULSE->_ledG_t = PULSE->_ledG_t2;
if (PULSE->_ledG_t == 1) {
PULSE->_ledG_sw = lastSwitch;
}
} else if (PULSE->_ledG_t_flag == 2) {
PULSE->_ledG_t_flag = 3;
PULSE->_ledG_sw = PULSE->_ledG_sw3;
PULSE->_ledG_t = PULSE->_ledG_t3;
if (PULSE->_ledG_t == 1) {
PULSE->_ledG_sw = lastSwitch;
}
} else if (PULSE->_ledG_t_flag == 3) {
PULSE->_ledG_cy -- ;
if (PULSE->_ledG_cy == 0) {
PULSE->_ledG_t_flag = 4;
PULSE->_ledG_sw = PULSE->_ledG_sw4;
PULSE->_ledG_t = PULSE->_ledG_t4;
if (PULSE->_ledG_t == 1) {
PULSE->_ledG_sw = lastSwitch;
}
} else {
PULSE->_ledG_t_flag = 2;
PULSE->_ledG_sw = PULSE->_ledG_sw2;
PULSE->_ledG_t = PULSE->_ledG_t2;
if (PULSE->_ledG_t == 1) {
PULSE->_ledG_sw = lastSwitch;
}
}
}
} else if (PULSE->_ledG_cy <= 0){
if (PULSE->_ledG_t_flag == 4) {
PULSE->_ledG_lp -- ;
if (PULSE->_ledG_lp > 0) {
PULSE->_ledG_cy = INSTRUCTION.ledG_cy;
PULSE->_ledG_t_flag = 2;
PULSE->_ledG_sw = PULSE->_ledG_sw2;
PULSE->_ledG_t = PULSE->_ledG_t2;
if (PULSE->_ledG_t == 1) {
PULSE->_ledG_sw = lastSwitch;
}
} else {
PULSE->_ledG_t_flag = 5;
PULSE->_ledG_sw = PULSE->_ledG_sw5;
PULSE->_ledG_t = PULSE->_ledG_t5;
if (PULSE->_ledG_t == 1) {
PULSE->_ledG_sw = lastSwitch;
}
}
}
}
} else if (PULSE->_ledG_lp <= 0) {
if (PULSE->_ledG_t_flag == 5) {
PULSE->_ledG_t_flag = 6;
PULSE->_ledG_sw = PULSE->_ledG_sw6;
PULSE->_ledG_t = PULSE->_ledG_t6;
if (PULSE->_ledG_t == 1) {
PULSE->_ledG_sw = lastSwitch;
}
} else if (PULSE->_ledG_t_flag == 6) {
PULSE->_ledG_t_flag = 7;
PULSE->_ledG_sw = PULSE->_ledG_sw7;
PULSE->_ledG_t = PULSE->_ledG_t7;
if (PULSE->_ledG_t == 1) {
PULSE->_ledG_sw = lastSwitch;
}
} else if (PULSE->_ledG_t_flag == 7) {
PULSE->_ledG_sw = false;
//PeriodicEvent = false;
//megaTrigEnable = false;
//ModeLED(NO_EVENT);
}
}
}
}
if (lastSwitch != PULSE->_ledG_sw) {
lastSwitch = PULSE->_ledG_sw;
PIN15_setOutputValue(MEGA_G_LED, PULSE->_ledG_sw);
}
}
static void PULSE_ledR(PULSEMode *PULSE)
{
static bool lastSwitch;
if (ledRFirstTime) {
ledRFirstTime = false;
lastSwitch = false;
PULSE->_ledR_t_flag = 1;
PULSE->_ledR_sw = PULSE->_ledR_sw1;
PULSE->_ledR_t = PULSE->_ledR_t1;
if (PULSE->_ledR_t == 1) {
PULSE->_ledR_sw = lastSwitch;
}
} else if(!ledRFirstTime) {
if (GPT.LedRCounter >= PULSE->_ledR_t) {
GPT.LedRCounter -= PULSE->_ledR_t; //to get right time
if (PULSE->_ledR_lp > 0) {
if (PULSE->_ledR_cy > 0) {
if (PULSE->_ledR_t_flag == 1) {
PULSE->_ledR_t_flag = 2;
PULSE->_ledR_sw = PULSE->_ledR_sw2;
PULSE->_ledR_t = PULSE->_ledR_t2;
if (PULSE->_ledR_t == 1) {
PULSE->_ledR_sw = lastSwitch;
}
} else if (PULSE->_ledR_t_flag == 2) {
PULSE->_ledR_t_flag = 3;
PULSE->_ledR_sw = PULSE->_ledR_sw3;
PULSE->_ledR_t = PULSE->_ledR_t3;
if (PULSE->_ledR_t == 1) {
PULSE->_ledR_sw = lastSwitch;
}
} else if (PULSE->_ledR_t_flag == 3) {
PULSE->_ledR_cy -- ;
if (PULSE->_ledR_cy == 0) {
PULSE->_ledR_t_flag = 4;
PULSE->_ledR_sw = PULSE->_ledR_sw4;
PULSE->_ledR_t = PULSE->_ledR_t4;
if (PULSE->_ledR_t == 1) {
PULSE->_ledR_sw = lastSwitch;
}
} else {
PULSE->_ledR_t_flag = 2;
PULSE->_ledR_sw = PULSE->_ledR_sw2;
PULSE->_ledR_t = PULSE->_ledR_t2;
if (PULSE->_ledR_t == 1) {
PULSE->_ledR_sw = lastSwitch;
}
}
}
} else if (PULSE->_ledR_cy <= 0){
if (PULSE->_ledR_t_flag == 4) {
PULSE->_ledR_lp -- ;
if (PULSE->_ledR_lp > 0) {
PULSE->_ledR_cy = INSTRUCTION.ledR_cy;
PULSE->_ledR_t_flag = 2;
PULSE->_ledR_sw = PULSE->_ledR_sw2;
PULSE->_ledR_t = PULSE->_ledR_t2;
if (PULSE->_ledR_t == 1) {
PULSE->_ledR_sw = lastSwitch;
}
} else {
PULSE->_ledR_t_flag = 5;
PULSE->_ledR_sw = PULSE->_ledR_sw5;
PULSE->_ledR_t = PULSE->_ledR_t5;
if (PULSE->_ledR_t == 1) {
PULSE->_ledR_sw = lastSwitch;
}
}
}
}
} else if (PULSE->_ledR_lp <= 0) {
if (PULSE->_ledR_t_flag == 5) {
PULSE->_ledR_t_flag = 6;
PULSE->_ledR_sw = PULSE->_ledR_sw6;
PULSE->_ledR_t = PULSE->_ledR_t6;
if (PULSE->_ledR_t == 1) {
PULSE->_ledR_sw = lastSwitch;
}
} else if (PULSE->_ledR_t_flag == 6) {
PULSE->_ledR_t_flag = 7;
PULSE->_ledR_sw = PULSE->_ledR_sw7;
PULSE->_ledR_t = PULSE->_ledR_t7;
if (PULSE->_ledR_t == 1) {
PULSE->_ledR_sw = lastSwitch;
}
} else if (PULSE->_ledR_t_flag == 7) {
PULSE->_ledR_sw = false;
//PeriodicEvent = false;
//megaTrigEnable = false;
//ModeLED(NO_EVENT);
}
}
}
}
if (lastSwitch != PULSE->_ledR_sw) {
lastSwitch = PULSE->_ledR_sw;
PIN15_setOutputValue(MEGA_R_LED, PULSE->_ledR_sw);
}
}
static void PULSE_gas0(PULSEMode *PULSE)
{
static bool lastSwitch;
if (gas0FirstTime) {
gas0FirstTime = false;
lastSwitch = false;
PULSE->_gas0_t_flag = 1;
PULSE->_gas0_sw = PULSE->_gas0_sw1;
PULSE->_gas0_t = PULSE->_gas0_t1;
if (PULSE->_gas0_t == 1) {
PULSE->_gas0_sw = lastSwitch;
}
} else if(!gas0FirstTime) {
if (GPT.Gas0Counter >= PULSE->_gas0_t) {
GPT.Gas0Counter -= PULSE->_gas0_t; //to get right time
if (PULSE->_gas0_lp > 0) {
if (PULSE->_gas0_cy > 0) {
if (PULSE->_gas0_t_flag == 1) {
PULSE->_gas0_t_flag = 2;
PULSE->_gas0_sw = PULSE->_gas0_sw2;
PULSE->_gas0_t = PULSE->_gas0_t2;
if (PULSE->_gas0_t == 1) {
PULSE->_gas0_sw = lastSwitch;
}
} else if (PULSE->_gas0_t_flag == 2) {
PULSE->_gas0_t_flag = 3;
PULSE->_gas0_sw = PULSE->_gas0_sw3;
PULSE->_gas0_t = PULSE->_gas0_t3;
if (PULSE->_gas0_t == 1) {
PULSE->_gas0_sw = lastSwitch;
}
} else if (PULSE->_gas0_t_flag == 3) {
PULSE->_gas0_cy -- ;
if (PULSE->_gas0_cy == 0) {
PULSE->_gas0_t_flag = 4;
PULSE->_gas0_sw = PULSE->_gas0_sw4;
PULSE->_gas0_t = PULSE->_gas0_t4;
if (PULSE->_gas0_t == 1) {
PULSE->_gas0_sw = lastSwitch;
}
} else {
PULSE->_gas0_t_flag = 2;
PULSE->_gas0_sw = PULSE->_gas0_sw2;
PULSE->_gas0_t = PULSE->_gas0_t2;
if (PULSE->_gas0_t == 1) {
PULSE->_gas0_sw = lastSwitch;
}
}
}
} else if (PULSE->_gas0_cy <= 0){
if (PULSE->_gas0_t_flag == 4) {
PULSE->_gas0_lp -- ;
if (PULSE->_gas0_lp > 0) {
PULSE->_gas0_cy = INSTRUCTION.gas0_cy;
PULSE->_gas0_t_flag = 2;
PULSE->_gas0_sw = PULSE->_gas0_sw2;
PULSE->_gas0_t = PULSE->_gas0_t2;
if (PULSE->_gas0_t == 1) {
PULSE->_gas0_sw = lastSwitch;
}
} else {
PULSE->_gas0_t_flag = 5;
PULSE->_gas0_sw = PULSE->_gas0_sw5;
PULSE->_gas0_t = PULSE->_gas0_t5;
if (PULSE->_gas0_t == 1) {
PULSE->_gas0_sw = lastSwitch;
}
}
}
}
} else if (PULSE->_gas0_lp <= 0) {
if (PULSE->_gas0_t_flag == 5) {
PULSE->_gas0_t_flag = 6;
PULSE->_gas0_sw = PULSE->_gas0_sw6;
PULSE->_gas0_t = PULSE->_gas0_t6;
if (PULSE->_gas0_t == 1) {
PULSE->_gas0_sw = lastSwitch;
}
} else if (PULSE->_gas0_t_flag == 6) {
PULSE->_gas0_t_flag = 7;
PULSE->_gas0_sw = PULSE->_gas0_sw7;
PULSE->_gas0_t = PULSE->_gas0_t7;
if (PULSE->_gas0_t == 1) {
PULSE->_gas0_sw = lastSwitch;
}
} else if (PULSE->_gas0_t_flag == 7) {
PULSE->_gas0_sw = false;
//PeriodicEvent = false;
//megaTrigEnable = false;
//ModeLED(NO_EVENT);
}
}
}
}
if (lastSwitch != PULSE->_gas0_sw) {
lastSwitch = PULSE->_gas0_sw;
PIN15_setOutputValue(MEGA_VAL_0, PULSE->_gas0_sw);
}
}
static void PULSE_gas1(PULSEMode *PULSE)
{
static bool lastSwitch;
if (gas1FirstTime) {
gas1FirstTime = false;
lastSwitch = true;
PULSE->_gas1_t_flag = 1;
PULSE->_gas1_sw = PULSE->_gas1_sw1;
PULSE->_gas1_t = PULSE->_gas1_t1;
if (PULSE->_gas1_t == 1) {
PULSE->_gas1_sw = lastSwitch;
}
} else if(!gas1FirstTime) {
if (GPT.Gas1Counter >= PULSE->_gas1_t) {
GPT.Gas1Counter -= PULSE->_gas1_t; //to get right time
if (PULSE->_gas1_lp > 0) {
if (PULSE->_gas1_cy > 0) {
if (PULSE->_gas1_t_flag == 1) {
PULSE->_gas1_t_flag = 2;
PULSE->_gas1_sw = PULSE->_gas1_sw2;
PULSE->_gas1_t = PULSE->_gas1_t2;
if (PULSE->_gas1_t == 1) {
PULSE->_gas1_sw = lastSwitch;
}
} else if (PULSE->_gas1_t_flag == 2) {
PULSE->_gas1_t_flag = 3;
PULSE->_gas1_sw = PULSE->_gas1_sw3;
PULSE->_gas1_t = PULSE->_gas1_t3;
if (PULSE->_gas1_t == 1) {
PULSE->_gas1_sw = lastSwitch;
}
} else if (PULSE->_gas1_t_flag == 3) {
PULSE->_gas1_cy -- ;
if (PULSE->_gas1_cy == 0) {
PULSE->_gas1_t_flag = 4;
PULSE->_gas1_sw = PULSE->_gas1_sw4;
PULSE->_gas1_t = PULSE->_gas1_t4;
if (PULSE->_gas1_t == 1) {
PULSE->_gas1_sw = lastSwitch;
}
} else {
PULSE->_gas1_t_flag = 2;
PULSE->_gas1_sw = PULSE->_gas1_sw2;
PULSE->_gas1_t = PULSE->_gas1_t2;
if (PULSE->_gas1_t == 1) {
PULSE->_gas1_sw = lastSwitch;
}
}
}
} else if (PULSE->_gas1_cy <= 0){
if (PULSE->_gas1_t_flag == 4) {
PULSE->_gas1_lp -- ;
if (PULSE->_gas1_lp > 0) {
PULSE->_gas1_cy = INSTRUCTION.gas1_cy;
PULSE->_gas1_t_flag = 2;
PULSE->_gas1_sw = PULSE->_gas1_sw2;
PULSE->_gas1_t = PULSE->_gas1_t2;
if (PULSE->_gas1_t == 1) {
PULSE->_gas1_sw = lastSwitch;
}
} else {
PULSE->_gas1_t_flag = 5;
PULSE->_gas1_sw = PULSE->_gas1_sw5;
PULSE->_gas1_t = PULSE->_gas1_t5;
if (PULSE->_gas1_t == 1) {
PULSE->_gas1_sw = lastSwitch;
}
}
}
}
} else if (PULSE->_gas1_lp <= 0) {
if (PULSE->_gas1_t_flag == 5) {
PULSE->_gas1_t_flag = 6;
PULSE->_gas1_sw = PULSE->_gas1_sw6;
PULSE->_gas1_t = PULSE->_gas1_t6;
if (PULSE->_gas1_t == 1) {
PULSE->_gas1_sw = lastSwitch;
}
} else if (PULSE->_gas1_t_flag == 6) {
PULSE->_gas1_t_flag = 7;
PULSE->_gas1_sw = PULSE->_gas1_sw7;
PULSE->_gas1_t = PULSE->_gas1_t7;
if (PULSE->_gas1_t == 1) {
PULSE->_gas1_sw = lastSwitch;
}
} else if (PULSE->_gas1_t_flag == 7) {
PULSE->_gas1_sw = true;
//PeriodicEvent = false;
//megaTrigEnable = false;
//ModeLED(NO_EVENT);
}
}
}
}
if (lastSwitch != PULSE->_gas1_sw) {
lastSwitch = PULSE->_gas1_sw;
PIN15_setOutputValue(MEGA_VAL_1, PULSE->_gas1_sw);
DAC_outputV(Usercode_Correction_to_DAC(VOUT_GAIN_240K, pulse->_sti_v));
DAC_outputV(Usercode_Correction_to_DAC(VOUT_GAIN_240K, pulse->_sti_v));
}
}
#endif
@@ -3,37 +3,24 @@
#define ELITERESET
static void reset() {
Mega_PeriodicEvent = false;
megaTrigEnable = false;
Mega_Trig_receive = false;
megaStiEnable = false;
megaLedGEnable = false;
megaLedREnable = false;
megaGas0Enable = false;
megaGas1Enable = false;
PIN15_setOutputValue(MEGA_G_LED, 0);
PIN15_setOutputValue(MEGA_R_LED, 0);
PIN15_setOutputValue(MEGA_VAL_0, 0);
PIN15_setOutputValue(MEGA_VAL_1, 1);
ModeLED(NO_EVENT);
InitEliteFlag();
InitFlag();
InitCT();
mode_init = true;
megaStiEnable = false;
PeriodicEvent = false; // is there an PeriodicEvent?
Free_Work_Mode = true; // Free(WorkModeData)
InitPeriodicEvent = true; // need to create a WorkModeData?
InitGPT();
initINSBuf();
initDATBuf();
InitLED();
PIN15_setOutputValue(HIGH_Z_MODE, 0); // 0 => open high_z mode
PIN15_setOutputValue(HIGH_Z_MODE, 0); // HIGH Z MODE // 1: close; 0: open;
VinADCGainControl(VIN_GAIN_AUTO);
IinADCGainControl(I_GAIN_AUTO);
INSTRUCTION.VoutGainLevel = VOUT_GAIN_15K;
VoutGainControl(INSTRUCTION.VoutGainLevel);
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, 25000));
initINSBuf();
initDATBuf();
instru.VoutGainLevel = VOUT_GAIN_15K;
VoutGainControl(instru.VoutGainLevel);
DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLevel, 25000));
for (int i = 0; i < SPI_LED_SIZE; i++) {
spi_LEDtxbuf[i] = 0;
@@ -50,37 +37,27 @@ static void reset() {
spi_ADC_rxbuf[i] = 0;
}
ModeLED(NO_EVENT);
CPUdelay(1600);
}
static void Eliteinterrupt() {
Mega_PeriodicEvent = false;
Mega_Trig_receive = false;
megaTrigEnable = false;
megaStiEnable = false;
megaLedGEnable = false;
megaLedREnable = false;
megaGas0Enable = false;
megaGas1Enable = false;
PIN15_setOutputValue(MEGA_G_LED, 0);
PIN15_setOutputValue(MEGA_R_LED, 0);
PIN15_setOutputValue(MEGA_VAL_0, 0);
PIN15_setOutputValue(MEGA_VAL_1, 1);
ModeLED(NO_EVENT);
InitFlag();
InitEliteFlag();
InitCT();
mode_init = true;
megaStiEnable = false;
PeriodicEvent = false; // is there an PeriodicEvent?
Free_Work_Mode = true; // Free(WorkModeData)
InitPeriodicEvent = true; // need to create a WorkModeData?
InitGPT();
PIN15_setOutputValue(HIGH_Z_MODE, 0); // 0 => open high_z mode
INSTRUCTION.VoutGainLevel = VOUT_GAIN_15K;
VoutGainControl(INSTRUCTION.VoutGainLevel);
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, 25000));
initINSBuf();
initDATBuf();
PIN15_setOutputValue(HIGH_Z_MODE, 0); // HIGH Z MODE // 1: close; 0: open;
instru.VoutGainLevel = VOUT_GAIN_15K;
VoutGainControl(instru.VoutGainLevel);
DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLevel, 25000));
for (int i = 0; i < SPI_LED_SIZE; i++) {
spi_LEDtxbuf[i] = 0;
spi_LEDrxbuf[i] = 0;
@@ -96,6 +73,7 @@ static void Eliteinterrupt() {
spi_ADC_rxbuf[i] = 0;
}
ModeLED(NO_EVENT);
CPUdelay(8000);
}
#endif
@@ -15,11 +15,9 @@
#include "Elite_PIN.h"
/* application use SPI parameters and buffers */
//#define SPI_LED_SIZE 28
#define SPI_LED_SIZE LED_BUFF_SIZE
#define SPI_LED_SIZE 28
#define SPI_DAC_SIZE 3
#define SPI_ADC_SIZE 4
#define SPI_GPIO_BUFF_SIZE 10
static uint16_t spi_LEDtxbuf[SPI_LED_SIZE] = {0};
static uint16_t spi_LEDrxbuf[SPI_LED_SIZE] = {0};
@@ -30,9 +28,6 @@ static uint8_t spi_rxbuf[SPI_DAC_SIZE] = {0};
static uint8_t spi_ADC_txbuf[SPI_ADC_SIZE] = {0};
static uint8_t spi_ADC_rxbuf[SPI_ADC_SIZE] = {0};
static uint16_t spi_GPIO_txbuf = 0;
static uint16_t SPI_GPIO[SPI_GPIO_BUFF_SIZE] = {0};
/* system use SPI parameters */
static SPI_Handle spiHandle0 = NULL; // SPI0 = LED
static SPI_Handle spiHandle1 = NULL; // SPI1 = ADC +DAC
@@ -80,7 +75,7 @@ static void ADC_SPI(uint8_t length, uint8_t *spi_txbuf, uint8_t *spi_rxbuf) {
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
PIN_setOutputValue(pin_handle, D6, 1); // ADC_CS HOGH
PIN_setOutputValue(pin_handle, D6, 1); // ADC_CS HIGH
update_latch_status (ADC_CS, 1);
// PIN15_setOutputValue(ADC_CS, 1); // ADC_CS HIGH
}
@@ -96,13 +91,18 @@ static void DAC_SPI(uint8_t length, uint8_t *spi_txbuf, uint8_t *spi_rxbuf) {
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
PIN_setOutputValue(pin_handle, D7, 1); // DAC_CS HOGH
PIN_setOutputValue(pin_handle, D7, 1); // DAC_CS HIGH
update_latch_status (DAC_CS, 1);
// PIN15_setOutputValue(DAC_CS, 1); // DAC_CS HIGH
}
static void ELITE15_SPI_HOLD() {
Elite_SPI_init();
#ifdef ELITE_PIN_1_5_RE
PIN_setOutputValue(pin_handle, D6, LH.LATCH0[6]); // ADC_CS
PIN_setOutputValue(pin_handle, D7, LH.LATCH0[7]); // DAC_CS
PIN_setOutputValue(pin_handle, D4, LH.LATCH0[4]); // update HIGH_Z_MODE
#endif
PIN_setOutputValue(pin_handle, LOAD0, 1);
PIN_setOutputValue(pin_handle, LOAD1, 0);
@@ -134,46 +134,4 @@ static void CAL_ADC_SPI(uint8_t length, uint8_t *spi_txbuf, uint8_t *spi_rxbuf)
// PIN15_setOutputValue(ADC_CS, 1); // ADC_CS HIGH
}
/* Test Elite TRIG01 function on Meagfly hardware */
static void GPIO_SPI_transfer(uint32_t *GPIO_CLK_CH, uint16_t spi_GPIO_txbuf) {
for(int i=0; i<SPI_GPIO_BUFF_SIZE; i++){
SPI_GPIO[i] = 0;
}
SPI_GPIO[0] = (spi_GPIO_txbuf & 0b0000000000000001); // MOSI
SPI_GPIO[1] = (spi_GPIO_txbuf & 0b0000000000000010);
SPI_GPIO[2] = (spi_GPIO_txbuf & 0b0000000000000100);
SPI_GPIO[3] = (spi_GPIO_txbuf & 0b0000000000001000);
SPI_GPIO[4] = (spi_GPIO_txbuf & 0b0000000000010000);
SPI_GPIO[5] = (spi_GPIO_txbuf & 0b0000000000100000);
SPI_GPIO[6] = (spi_GPIO_txbuf & 0b0000000001000000);
SPI_GPIO[7] = (spi_GPIO_txbuf & 0b0000000010000000);
SPI_GPIO[8] = (spi_GPIO_txbuf & 0b0000000100000000);
SPI_GPIO[9] = (spi_GPIO_txbuf & 0b0000001000000000);
ELITE15_SPI_CLOSE();
add_elite_pin();
PIN_setOutputValue(pin_handle, LOAD0, 1);
for (int i=SPI_GPIO_BUFF_SIZE-1; i>=0; i--) {
PIN_setOutputValue(pin_handle, GPIO_CLK_CH[1], 0); // generate clk signal
PIN_setOutputValue(pin_handle, D3, SPI_GPIO[i]); // data transfer at rising edge, MOSI = D3
PIN_setOutputValue(pin_handle, GPIO_CLK_CH[1], 1); // generate clk signal
}
PIN_setOutputValue(pin_handle, GPIO_CLK_CH[1], 0);
update_latch_status (GPIO_CLK_CH[0], GPIO_CLK_CH[1], 0);
PIN_setOutputValue(pin_handle, D3, 0);
update_latch_status (ADC_DAC_SPI_MOSI, 0);
PIN_setOutputValue(pin_handle, LOAD0, 0);
remove_elite_pin();
ELITE15_SPI_HOLD();
// PIN15_setOutputValue(ADC_DAC_SPI_MOSI, 0);
// PIN15_setOutputValue(GPIO_CLK_CH[0], GPIO_CLK_CH[1], 0);
}
#endif // ELITE_SPI
@@ -8,14 +8,16 @@
// change the output voltage step
// => get a R-T curve (with resolution = 1 sample/volt step )
static void ZT_Vscan(RTMode *RT){
if(vscanReset){
Vset = ((int32_t)(INSTRUCTION.VoltConstant) - 25000) * 4 * 10000; //[5nV]
OneWayVoltScan();
static void rt_vscan(void)
{
struct wm_rt_ctx_t *rt = (struct wm_rt_ctx_t *)wm_get();
if (vscanReset) {
Vset = rt->_Vinit;
}
if(!vscanReset){
if(!vscanReset) {
Vset = rt->_Vinit;
}
}
#endif
@@ -6,6 +6,8 @@
#include <Board.h>
#include <ti/drivers/PIN.h>
#define ELITE_PIN_1_5
/* SPI Board */
#define Board_SPI0_MISO PIN_UNASSIGNED
#define Board_SPI0_MOSI D1
@@ -30,19 +32,22 @@
#define LOAD1 IOID_12
#define LOAD2 IOID_11
#define ADC_CS LOAD0, D6 // TW_SCKI_2
#define DAC_CS LOAD0, D7 // TW_SCKI_3
#define ADC_CS LOAD0, D6
#define DAC_CS LOAD0, D7
#define ADC_DAC_SPI_MOSI LOAD0, D3
#define ADC_DAC_SPI_CLK LOAD0, D2
#define LED_MOSI LOAD0, D1
#define LED_CLK LOAD0, D0
#define MEM_HOLD LOAD0, D4 // TW_SCKI_0
#define MEM_CS LOAD0, D5 // TW_SCKI_1
#define MEM_CS LOAD0, D5
#define TW_SCKI_0 MEM_HOLD
#define TW_SCKI_1 MEM_CS
#define TW_SCKI_2 ADC_CS
#define TW_SCKI_3 DAC_CS
#ifdef ELITE_PIN_1_5
#define MEM_HOLD LOAD0, D4
#define HIGH_Z_MODE LOAD2, D5
#endif
#ifdef ELITE_PIN_1_5_RE
#define MEM_HOLD LOAD1, D0
#define HIGH_Z_MODE LOAD0, D4
#endif
#define Turnon_I_MID LOAD2, D0
#define Turnon_I_SMALL LOAD2, D4
@@ -50,6 +55,7 @@
#define Turnon_V_SMALL LOAD2, D2
#define Turnon_V_MID LOAD2, D3
#define Turon_VOUT_SMALL LOAD2, D7
#define shutdown_6994 LOAD2, D6
//#define Turnon10K Turnon_I_MID
//#define Turnon200R Turnon_I_LARGE
@@ -60,20 +66,10 @@
#define Board_I2C0_SDA0 PIN_UNASSIGNED
#endif
#define shutdown_6994 LOAD2, D6
#define switch_on IOID_14
#define HIGH_Z_MODE LOAD2, D5
#define enable_10v LOAD1, D5
#define enable_5v LOAD1, D6
/* Megafly control */
#define MEGA_G_LED LOAD1, D0
#define MEGA_R_LED LOAD1, D1
#define MEGA_VAL_0 LOAD1, D2
#define MEGA_VAL_1 LOAD1, D3
#define MEGA_TRIG IOID_0
#define MEGA_TRIG_test IOID_2
PIN_Handle pin_handle;
static PIN_State ZM_rst;
@@ -82,18 +78,16 @@ const PIN_Config BLE_IO[] = {
// D1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
// D2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
// D3 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
// D4 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
// D5 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
// D6 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
// D7 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
D4 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
D5 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
D6 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
D7 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
LOAD0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
LOAD1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
LOAD2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
switch_on | PIN_INPUT_EN | PIN_PULLDOWN, // to sense switch
MEGA_TRIG | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLDOWN,
MEGA_TRIG_test | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_PULLDOWN,
PIN_TERMINATE
};
@@ -108,28 +102,15 @@ static void add_elite_pin() {
D2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL);
PIN_add(pin_handle,
D3 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL);
PIN_add(pin_handle,
D4 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL);
PIN_add(pin_handle,
D5 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL);
PIN_add(pin_handle,
D6 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL);
PIN_add(pin_handle,
D7 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL);
// if(elite15_status != PIN_SUCCESS) {
// LED_color(DARKLED, 0x0F, 0x0F, 0x0F);
// }
}
static void megafly_trig_callback(PIN_Handle handle, PIN_Id pinId);
static void remove_elite_pin() {
PIN_close(pin_handle);
pin_handle = PIN_open(&ZM_rst, BLE_IO);
PIN_registerIntCb(pin_handle, megafly_trig_callback);
PIN_setInterrupt(pin_handle, MEGA_TRIG | PIN_IRQ_NEGEDGE);
PIN_setInterrupt(pin_handle, MEGA_TRIG_test | PIN_IRQ_NEGEDGE);
}
/*!
@@ -42,7 +42,7 @@ static void headstage_battery_volt(){
static void EliteADCBattery(){
static uint8_t ADCSwitch = 0;
if(INSTRUCTION.eliteFxn == ADC_TEST){
if(instru.eliteFxn == CURVE_CALI_ADCTEST){
ADCSwitch = 0;
}else{
if(ADCSwitch == 0){ /**read V**/
@@ -20,26 +20,37 @@
#define VIS_CC_ZERO 0x40
// RIS (real instruction)
#define IV_CURVE 0x10
#define CV_CURVE 0x20
#define VOLT_OUTPUT 0x30
#define ZT_CURVE 0x40
#define VT_CURVE 0x50
#define IT_CURVE 0x60
#define SET_SAMPLE_RATE 0x70
#define SET_ADC_DAC_GAIN 0x80
#define DIFFERENTIAL_PULSE_VOLTAMMETRY 0xA0
#define SQUARE_WAVE_VOLTAMMETRY 0xB0
#define CYCLIC_VOLTAMMETRY 0xC0
#define CONSTANT_CURRENT 0xD0
#define CYCLE_CONSTANT_CURRENT 0xF0
#define HIGH_CYCLE_CYCLIC_VOLTAMMETRY 0x01
#define LINEAR_SWEEP_VOLTAMMETRY 0x02
#define CONSTANT_VSCAN 0x03
#define ADC_TEST 0x91
#define CALI_DAC_MODE 0x93
#define CALI_ADC_MODE 0x92
#define PULSE_MODE 0x94
enum all_mode_e {
CURVE_IV = 0x01, // 01
CURVE_IV_CY = 0x02, // cycling iv // 02
CURVE_VO = 0x03, // 03
CURVE_RT = 0x04, // 04
CURVE_VT = 0x05, // 05
CURVE_IT = 0x06, // 06
CURVE_CC = 0x07, // constant current // 07
CURVE_CC_CY = 0x08, // doesn't exist // 08
CURVE_CV = 0x09, // cyclic voltammetry // 09
CURVE_CV_HIGH_CY = 0x0A, // cyclic voltammetry(high cycle) // 0A
CURVE_LSV = 0x0B, // linear sweep voltammetry // 0B
CURVE_CA = 0x0C, // chronoamperometric graph(CA) // 0C
CURVE_PULSE = 0x0D, // 0D
DIFFERENTIAL_PULSE_VOLTAMMETRY = 0x0E, // doesn't exist // 0E
SQUARE_WAVE_VOLTAMMETRY = 0x0F, // doesn't exist // 0F
SHORT_INSTR = 0xE0,
CURVE_CALI_ADCTEST = 0x91, // F0
CURVE_CALI_DAC = 0x93, // F1
CURVE_CALI_ADC = 0x92, // F2
DEV_MODE = 0xFF
};
enum all_short_instr_e {
SET_NOTIFY_RATE2 = 0x01, //01
SET_NOTIFY_RATE = 0x70, //01
SET_ADC_DAC_GAIN = 0x80, //02
};
// CIS (control instruction)
#define CIS_VERSION 0x40
@@ -58,19 +69,7 @@
#define PARA_2 0x02
#define PARA_3 0x03
#define PARA_4 0x04
#define PARA_5 0x05
#define PARA_6 0x06
#define PARA_7 0x07
#define PARA_8 0x08
#define PARA_9 0x09
#define PARA_10 0x0A
#define PARA_11 0x0B
#define PARA_12 0x0C
#define PARA_13 0x0D
#define PARA_14 0x0E
#define PARA_15 0x0F
#define PARA_16 0x10
#define PARA_17 0x11
#define PARA_END 0x11
//Elite LED
#define COLOR_BLACK 0x00
@@ -84,6 +83,12 @@
#define COLOR_PURPLE 0x08
#define COLOR_WHITE 0x09
#define COLOR_YELLOWGREEN 0x0A
#define COLOR_YELLOW_DARK 0xF3
#define COLOR_GREEN_DARK 0xF4
#define COLOR_BLUE_DARK 0xF5
#define COLOR_CYAN_DARK 0xF6
#define COLOR_PURPLE_DARK 0xF8
#define LEDPowerON() Elite_led_color(COLOR_GREEN)
#define WORKLED() Elite_led_color(COLOR_CYAN)
#define KEYLED() Elite_led_color(COLOR_YELLOW)
@@ -96,6 +101,5 @@
#define WORKING 0x04
#define POST_WORK 0x05
#define MEGA_15V 41406
#define VALUE_ZERO_TO_ONE(_v) (_v == 0) ? 1 : _v
#endif
@@ -2,11 +2,11 @@
#ifndef VERSION_DATE
#define VERSION_DATE
#define VERSION_DATE_YEAR 20
#define VERSION_DATE_MONTH 12
#define VERSION_DATE_DAY 11
#define VERSION_DATE_HOUR 17
#define VERSION_DATE_MINUTE 20
#define VERSION_DATE_YEAR 21
#define VERSION_DATE_MONTH 4
#define VERSION_DATE_DAY 9
#define VERSION_DATE_HOUR 16
#define VERSION_DATE_MINUTE 23
// this is NOT the version hash !!
// it's the last version hash
@@ -129,16 +129,16 @@ static void update_ins_sti_channel(uint8_t *buf, uint8 sti_chp, uint8 sti_chn) {
static void update_ins_buffer() {
uint8 header = 0b10100000;
uint8 amp_gain = (INSTRUCTION.amp_gain & 0b11) << 3;
uint8 amp_lbf = INSTRUCTION.amp_low_band_freq & 0b111;
uint8 amp_gain = (instru.amp_gain & 0b11) << 3;
uint8 amp_lbf = instru.amp_low_band_freq & 0b111;
uint8 channel = 0; // should be call update_ins_channel to modify this value
uint8 chopper = (INSTRUCTION.chopper) ? 0b00001000 : 0;
uint8 fast_settle = (INSTRUCTION.fast_settle) ? 0b00000100 : 0;
uint8 sti_enable = (INSTRUCTION.work_mode != STI_MODE_DISABLE) ? 0b00000010 : 0;
uint8 sti_volt_l = (INSTRUCTION.sti_volt & 0b11111) >> 4;
uint8 sti_volt_h = (INSTRUCTION.sti_volt & 0b01111) << 4;
uint8 sti_chp = INSTRUCTION.sti_channel_pmos & 0b1111;
uint8 sti_chn = (INSTRUCTION.sti_channel_nmos & 0b1111) << 4;
uint8 chopper = (instru.chopper) ? 0b00001000 : 0;
uint8 fast_settle = (instru.fast_settle) ? 0b00000100 : 0;
uint8 sti_enable = (instru.work_mode != STI_MODE_DISABLE) ? 0b00000010 : 0;
uint8 sti_volt_l = (instru.sti_volt & 0b11111) >> 4;
uint8 sti_volt_h = (instru.sti_volt & 0b01111) << 4;
uint8 sti_chp = instru.sti_channel_pmos & 0b1111;
uint8 sti_chn = (instru.sti_channel_nmos & 0b1111) << 4;
uint8 clk_signal = 0; // should be call update_ins_clock to modify this value
spi_txbuf[0] = header | amp_gain | amp_lbf;
@@ -193,7 +193,7 @@ static bool update_ins_rec_buffer() {
* @param: buf: pointer of the SPI buffer.
*/
static void update_ins_sti_buffer() {
switch (INSTRUCTION.work_mode) {
switch (instru.work_mode) {
case STI_MODE_POS:
case STI_MODE_NEG:
// copy [4:7]
@@ -215,7 +215,7 @@ static void update_ins_sti_buffer() {
update_ins_sti_enable(spi_txbuf, TRUE);
// ins buf [4:7]
update_ins_sti_enable(spi_txbuf + 4, TRUE);
update_ins_sti_channel(spi_txbuf + 4, 0xF, INSTRUCTION.sti_channel_pmos);
update_ins_sti_channel(spi_txbuf + 4, 0xF, instru.sti_channel_pmos);
// ins buf [8:B]
update_ins_sti_enable(spi_txbuf + 8, FALSE);
break;
@@ -238,13 +238,13 @@ static void update_ins_sti_buffer() {
spi_txbuf[15] = spi_txbuf[3];
// change content
update_ins_sti_enable(spi_txbuf + 0, TRUE);
update_ins_sti_channel(spi_txbuf + 0, INSTRUCTION.sti_channel_pmos, INSTRUCTION.sti_channel_nmos);
update_ins_sti_channel(spi_txbuf + 0, instru.sti_channel_pmos, instru.sti_channel_nmos);
// ins buf [4:7]
update_ins_sti_enable(spi_txbuf + 4, TRUE);
update_ins_sti_channel(spi_txbuf + 4, INSTRUCTION.sti_channel_nmos, INSTRUCTION.sti_channel_pmos);
update_ins_sti_channel(spi_txbuf + 4, instru.sti_channel_nmos, instru.sti_channel_pmos);
// ins buf [8:B]
update_ins_sti_enable(spi_txbuf + 8, TRUE);
update_ins_sti_channel(spi_txbuf + 8, 0xF, INSTRUCTION.sti_channel_nmos);
update_ins_sti_channel(spi_txbuf + 8, 0xF, instru.sti_channel_nmos);
// ins buf [C:F]
update_ins_sti_enable(spi_txbuf + 12, FALSE);
break;
@@ -281,12 +281,12 @@ static void headstage_tni_update_instruction_callback(uint8_t ins_type, uint8_t
}
static uint8_t *spi_transact_rec_instruction() {
if (IS_REC_MODE(INSTRUCTION.work_mode)) {
if (IS_REC_MODE(instru.work_mode)) {
PIN_setOutputValue(pin_handle, IOID_13, 1); // DBS_P2S turn on
headstage_spi_transaction(SPI_BUFFER_SIZE, spi_txbuf, spi_rxbuf);
PIN_setOutputValue(pin_handle, IOID_13, 0); // DBS_P2S turn off
} else if (IS_ARM_MODE(INSTRUCTION.work_mode) && !adc_clock_signal) {
} else if (IS_ARM_MODE(instru.work_mode) && !adc_clock_signal) {
create_ramp(spi_rxbuf);
}
@@ -22,7 +22,7 @@
#include "EliteWorkData.h"
#include <driverlib/aon_batmon.h>
static void SimpleBLEPeripheral_performPeriodicTask(WorkMode *WorkModeData);
static void SimpleBLEPeripheral_performPeriodicTask(void);
static void SimpleBLEPeripheral_clockHandler(UArg arg) {
// Store the event.
@@ -38,28 +38,6 @@ static void elite_gptimer_callback(GPTimerCC26XX_Handle handle, GPTimerCC26XX_In
GPT.GptimerCounter++;
}
static void megafly_trig_callback(PIN_Handle handle, PIN_Id pinId) {
// bool trig = 1;
// trig = PIN_getInputValue(MEGA_TRIG);
if (INSTRUCTION.eliteFxn == PULSE_MODE && megaTrigEnable){
Mega_PeriodicEvent = true;
Mega_Trig_receive = true;
}
switch (pinId) {
case MEGA_TRIG :{
MEGA_getTRIG = true;
break;
}
case MEGA_TRIG_test :{
MEGA_test_getTRIG = true;
break;
}
default :{
break;
}
}
// PIN15_setOutputValue(MEGA_G_LED, 1);
}
static void ZM_update_instruction_callback(uint8_t ins_type, uint8_t chip_ID, uint8_t *ins);
@@ -68,29 +46,27 @@ static void ZM_init() {
// initialize
pin_handle = PIN_open(&ZM_rst, BLE_IO);
// PIN_registerIntCb(pin_handle, megafly_trig_callback);
// PIN_setInterrupt(pin_handle, MEGA_TRIG | PIN_IRQ_NEGEDGE);
InitLED();
Init_Elite15_PIN();
ELITE15_SPI_HOLD();
PIN15_setOutputValue(shutdown_6994, 1); // OFF = 1 => turn off 6994
PIN15_setOutputValue(enable_10v, 0); // enable 10V
PIN15_setOutputValue(HIGH_Z_MODE, 0); // HIGH Z MODE // 1 => close high_z mode
/* Turn off Megafly output pin */
PIN15_setOutputValue(MEGA_G_LED, 0);
PIN15_setOutputValue(MEGA_R_LED, 0);
PIN15_setOutputValue(MEGA_VAL_0, 0);
PIN15_setOutputValue(MEGA_VAL_1, 1);
PIN15_setOutputValue(HIGH_Z_MODE, 0); // HIGH Z MODE // 1: close; 0: open;
InitEliteInstruction();
IinADCGainControl(INSTRUCTION.ADCGainLevel);
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
VoutGainControl(INSTRUCTION.VoutGainLevel);
elite_gptimer_open();
TRIG0_LED_Init();
// init DAC, set output ~= 0 V
instru.VoutGainLevel = VOUT_GAIN_15K;
VoutGainControl(instru.VoutGainLevel);
DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLevel, 25000));
/* when elite open, must change vin level,
measure battery value will be right */
VinADCGainControl(VIN_GAIN_AUTO);
elite_gptimer_open();
elite_gptimer_start();
// PIN_registerIntCb(pin_handle, switch_on_callback);
// PIN_setInterrupt(pin_handle, switch_on | PIN_IRQ_POSEDGE);
}
@@ -100,7 +76,7 @@ static void ZM_update_instruction_callback(uint8_t ins_type, uint8_t chip_ID, ui
static void DACCode2Real2Notify(uint16_t DACcode) {
int32_t RealV;
RealV = DAC_to_realV(INSTRUCTION.VoutGainLevel, DACcode);
RealV = DAC_to_realV(instru.VoutGainLevel, DACcode);
NotifyVolt[0] = (uint8_t)((RealV & 0xFF000000) >> 24);
NotifyVolt[1] = (uint8_t)((RealV & 0x00FF0000) >> 16);
@@ -109,23 +85,24 @@ static void DACCode2Real2Notify(uint16_t DACcode) {
}
#define IsPeriodicMode() ( \
(INSTRUCTION.eliteFxn == IV_CURVE) || \
(INSTRUCTION.eliteFxn == CV_CURVE) || \
(INSTRUCTION.eliteFxn == IT_CURVE) || \
(INSTRUCTION.eliteFxn == VT_CURVE) || \
(INSTRUCTION.eliteFxn == ZT_CURVE) || \
(INSTRUCTION.eliteFxn == CONSTANT_CURRENT) || \
(INSTRUCTION.eliteFxn == CYCLIC_VOLTAMMETRY) || \
(INSTRUCTION.eliteFxn == LINEAR_SWEEP_VOLTAMMETRY) || \
(INSTRUCTION.eliteFxn == CONSTANT_VSCAN) || \
(INSTRUCTION.eliteFxn == CALI_ADC_MODE) \
(instru.eliteFxn == CURVE_IV) || \
(instru.eliteFxn == CURVE_IV_CY) || \
(instru.eliteFxn == CURVE_IT) || \
(instru.eliteFxn == CURVE_VT) || \
(instru.eliteFxn == CURVE_RT) || \
(instru.eliteFxn == CURVE_CC) || \
(instru.eliteFxn == CURVE_CV) || \
(instru.eliteFxn == CURVE_LSV) || \
(instru.eliteFxn == CURVE_CA) || \
(instru.eliteFxn == CURVE_VO) || \
(instru.eliteFxn == CURVE_CALI_ADC) \
)
#define Ve1MatchVe2Mode() ( \
(INSTRUCTION.eliteFxn == IV_CURVE) || \
(INSTRUCTION.eliteFxn == CV_CURVE) || \
(INSTRUCTION.eliteFxn == CYCLIC_VOLTAMMETRY) || \
(INSTRUCTION.eliteFxn == LINEAR_SWEEP_VOLTAMMETRY) \
(instru.eliteFxn == CURVE_IV) || \
(instru.eliteFxn == CURVE_IV_CY) || \
(instru.eliteFxn == CURVE_CV) || \
(instru.eliteFxn == CURVE_LSV) \
)
/*********************************************************************
@@ -137,39 +114,61 @@ static void DACCode2Real2Notify(uint16_t DACcode) {
*
* @return None.
*/
static void SimpleBLEPeripheral_performPeriodicTask(WorkMode *WorkModeData) {
if ( IsPeriodicMode() ){
static void SimpleBLEPeripheral_performPeriodicTask(void) {
if (IsPeriodicMode()) {
/** Periodic Event **/
// Default working flow is vscan -> ADC read -> send notify
// We will need a flag to control vscan, ADC and notify
static bool first_highz_flag = false;
GPT.DeltaGptimerCounter = GPT.GptimerCounter - GPT.GptimerCounter0;
GPT.GptimerCounter0 = GPT.GptimerCounter;
if(EliteWorkReset){
InitEliteGPtimer();
EliteWorkReset = false;
if (mode_init) {
GPT.SampleRateCounter = instru.sampleRate - 10;
GPT.VscanRateCounter = instru.VsetRate - 1;
mode_init = false;
batteryADC_flag = false;
record_flag = true;
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
IinADCGainControl(INSTRUCTION.ADCGainLevel);
VoutGainControl(INSTRUCTION.VoutGainLevel);
if( Ve1MatchVe2Mode() ){
if (INSTRUCTION.Ve1 == INSTRUCTION.Ve2) {
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.Ve1));
firstTimeReset = true;
notifyFirst_flag = true;
first_highz_flag = true;
I_GAIN_100R_counter = 0;
I_GAIN_3K_counter = 0;
I_GAIN_100K_counter = 0;
I_GAIN_3M_counter = 0;
VIN_GAIN_1M_counter = 0;
VIN_GAIN_30K_counter = 0;
VIN_GAIN_1K_counter = 0;
VOUT_GAIN_240K_counter = 0;
VOUT_GAIN_15K_counter = 0;
DACReset = true;
vscanReset = true;
leadTimeReset = true;
VinADCGainControl(instru.VinADCGainLevel);
IinADCGainControl(instru.ADCGainLevel);
VoutGainControl(instru.VoutGainLevel);
if (Ve1MatchVe2Mode()) {
if (instru.Ve1 == instru.Ve2) {
DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLevel, instru.Ve1));
PeriodicEvent = false;
PIN15_setOutputValue(HIGH_Z_MODE, 0); // 0: open highz;
ModeLED(NO_EVENT);
}
}
}
GPT.LeadTimeCounter = GPT.LeadTimeCounter + GPT.DeltaGptimerCounter;
if(leadTimeReset && GPT.LeadTimeCounter <= 2000){
if (leadTimeReset && GPT.LeadTimeCounter <= 2000) {
vscanReset = true;
}else{
if(notifyFirst_flag){
GPT.NotifyCounter = INSTRUCTION.notifyRate - 20;
if (first_highz_flag && GPT.LeadTimeCounter >= 1000) {
PIN15_setOutputValue(HIGH_Z_MODE, 1); // HIGH Z MODE // 1: close; 0: open;
first_highz_flag = false;
}
} else {
if (notifyFirst_flag) {
GPT.NotifyCounter = instru.notifyRate - 20;
notifyFirst_flag = false;
}
vscanReset = false;
@@ -178,16 +177,16 @@ static void SimpleBLEPeripheral_performPeriodicTask(WorkMode *WorkModeData) {
//vscan counter
GPT.VscanRateCounter = GPT.VscanRateCounter + GPT.DeltaGptimerCounter;
if(GPT.VscanRateCounter >= INSTRUCTION.VsetRate){
if(GPT.VscanRateCounter >= INSTRUCTION.VsetRate * 2){
GPT.GptimerMultiple = GPT.VscanRateCounter / INSTRUCTION.VsetRate;
}else{
if (GPT.VscanRateCounter >= instru.VsetRate) {
if (GPT.VscanRateCounter >= instru.VsetRate * 2) {
GPT.GptimerMultiple = GPT.VscanRateCounter / instru.VsetRate;
} else {
GPT.GptimerMultiple = 1;
}
GPT.VscanRateCounter -= INSTRUCTION.VsetRate * GPT.GptimerMultiple; //To get right time
GPT.VscanRateCounter -= instru.VsetRate * GPT.GptimerMultiple; //To get right time
vscan_flag = true;
if(vscan_flag){
EliteVscanControl(WorkModeData);
if (vscan_flag) {
vscan_ctrl();
vscan_flag = false;
}
}
@@ -207,11 +206,11 @@ static void SimpleBLEPeripheral_performPeriodicTask(WorkMode *WorkModeData) {
//ADC counter
GPT.SampleRateCounter = GPT.SampleRateCounter + GPT.DeltaGptimerCounter;
if(GPT.SampleRateCounter >= INSTRUCTION.sampleRate){
if(GPT.SampleRateCounter >= instru.sampleRate){
GPT.SampleRateCounter = 0; //To get right data, ADC must be delay 1.5ms
ADC_flag = true;
if(ADC_flag){
EliteADCControl(WorkModeData);
EliteADCControl();
ADC_flag = false;
}
}
@@ -219,8 +218,8 @@ static void SimpleBLEPeripheral_performPeriodicTask(WorkMode *WorkModeData) {
//Notify counter(Notify control, check if we need to send notify)
//please don't put Notify counter before ADC counter, maybe get wrong data
GPT.NotifyCounter = GPT.NotifyCounter + GPT.DeltaGptimerCounter;
if(GPT.NotifyCounter >= INSTRUCTION.notifyRate){
GPT.NotifyCounter -= INSTRUCTION.notifyRate; //To get right time
if(GPT.NotifyCounter >= instru.notifyRate){
GPT.NotifyCounter -= instru.notifyRate; //To get right time
notify_flag = true;
if(vscanReset){
notify_flag = false;
@@ -231,9 +230,9 @@ static void SimpleBLEPeripheral_performPeriodicTask(WorkMode *WorkModeData) {
}
}
// EliteDone();
mode_done();
}
else if (INSTRUCTION.eliteFxn == PULSE_MODE) {
else if (instru.eliteFxn == CURVE_PULSE) {
/** Periodic Event **/
// Default working flow is vscan -> ADC read -> send notify
// We will need a flag to control vscan, ADC and notify
@@ -241,33 +240,33 @@ static void SimpleBLEPeripheral_performPeriodicTask(WorkMode *WorkModeData) {
GPT.DeltaGptimerCounter = GPT.GptimerCounter - GPT.GptimerCounter0;
GPT.GptimerCounter0 = GPT.GptimerCounter;
if(EliteWorkReset){
InitEliteGPtimer();
EliteWorkReset = false;
if(mode_init){
GPT.SampleRateCounter = instru.sampleRate - 10;
GPT.VscanRateCounter = instru.VsetRate - 1;
mode_init = false;
batteryADC_flag = false;
record_flag = true;
firstTimeReset = true;
notifyFirst_flag = true;
//pulsemode variable
stiFirstTime = true;
ledGFirstTime = true; //green led
ledRFirstTime = true; //red led
gas0FirstTime = true; //gas0
gas1FirstTime = true; //gas1
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
IinADCGainControl(INSTRUCTION.ADCGainLevel);
VoutGainControl(INSTRUCTION.VoutGainLevel);
VinADCGainControl(instru.VinADCGainLevel);
IinADCGainControl(instru.ADCGainLevel);
VoutGainControl(instru.VoutGainLevel);
if (Ve1MatchVe2Mode()) {
if (INSTRUCTION.Ve1 == INSTRUCTION.Ve2) {
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.Ve1));
if (instru.Ve1 == instru.Ve2) {
DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLevel, instru.Ve1));
PeriodicEvent = false;
PIN15_setOutputValue(HIGH_Z_MODE, 0); // 0: open highz;
ModeLED(NO_EVENT);
}
} else if (INSTRUCTION.eliteFxn == PULSE_MODE) {
if(!megaStiEnable && !megaLedGEnable && !megaLedREnable && !megaGas0Enable && !megaGas1Enable){
PeriodicEvent = false;
ModeLED(NO_EVENT);
}
} else if (instru.eliteFxn == CURVE_PULSE) {
if(!megaStiEnable){
PeriodicEvent = false;
PIN15_setOutputValue(HIGH_Z_MODE, 0); // 0: open highz;
ModeLED(NO_EVENT);
}
}
}
@@ -276,56 +275,37 @@ static void SimpleBLEPeripheral_performPeriodicTask(WorkMode *WorkModeData) {
vscanReset = true;
}else{
if(notifyFirst_flag){
GPT.NotifyCounter = INSTRUCTION.notifyRate - 20;
GPT.NotifyCounter = instru.notifyRate - 20;
notifyFirst_flag = false;
}
vscanReset = false;
leadTimeReset = false;
}
//vscan counter
GPT.VscanRateCounter = GPT.VscanRateCounter + GPT.DeltaGptimerCounter;
//pulse mode counter
GPT.StiCounter = GPT.StiCounter + GPT.DeltaGptimerCounter;
GPT.LedGCounter = GPT.LedGCounter + GPT.DeltaGptimerCounter;
GPT.LedRCounter = GPT.LedRCounter + GPT.DeltaGptimerCounter;
GPT.Gas0Counter = GPT.Gas0Counter + GPT.DeltaGptimerCounter;
GPT.Gas1Counter = GPT.Gas1Counter + GPT.DeltaGptimerCounter;
if (vscanReset) {
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, 25000));
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, 25000));
DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLevel, 25000));
DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLevel, 25000));
//vscanReset = false;
}else{
if (megaStiEnable) {
PULSE_Vscan(WorkModeData->PULSE);
}
if (megaLedGEnable){
PULSE_ledG(WorkModeData->PULSE);
}
if (megaLedREnable){
PULSE_ledR(WorkModeData->PULSE);
}
if (megaGas0Enable){
PULSE_gas0(WorkModeData->PULSE);
}
if (megaGas1Enable){
PULSE_gas1(WorkModeData->PULSE);
pulse_vscan();
}
}
// if(GPT.VscanRateCounter >= INSTRUCTION.VsetRate){
// if(GPT.VscanRateCounter >= INSTRUCTION.VsetRate * 2){
// GPT.GptimerMultiple = GPT.VscanRateCounter / INSTRUCTION.VsetRate;
// if(GPT.VscanRateCounter >= instru.VsetRate){
// if(GPT.VscanRateCounter >= instru.VsetRate * 2){
// GPT.GptimerMultiple = GPT.VscanRateCounter / instru.VsetRate;
// }else{
// GPT.GptimerMultiple = 1;
// }
// GPT.VscanRateCounter -= INSTRUCTION.VsetRate * GPT.GptimerMultiple; //To get right time
// GPT.VscanRateCounter -= instru.VsetRate * GPT.GptimerMultiple; //To get right time
// vscan_flag = true;
// if(vscan_flag){
// EliteVscanControl(WorkModeData);
// vscan_ctrl();
// vscan_flag = false;
// }
// }
@@ -340,16 +320,16 @@ static void SimpleBLEPeripheral_performPeriodicTask(WorkMode *WorkModeData) {
uint16_t bat = ((uint16_t)(NotifyVoltBat[2]) << 8 & 0xFF00 ) | ((uint16_t)(NotifyVoltBat[3]) & 0x00FF);
if( bat < 768 && bat > 20){
// PIN15_setOutputValue(enable_5v, 0);
PIN15_setOutputValue(enable_5v, 0);
}
//ADC counter
GPT.SampleRateCounter = GPT.SampleRateCounter + GPT.DeltaGptimerCounter;
if(GPT.SampleRateCounter >= INSTRUCTION.sampleRate){
if(GPT.SampleRateCounter >= instru.sampleRate){
GPT.SampleRateCounter = 0; //To get right data, ADC must be delay 1.5ms
ADC_flag = true;
if(ADC_flag){
EliteADCControl(WorkModeData);
EliteADCControl();
ADC_flag = false;
}
}
@@ -357,138 +337,107 @@ static void SimpleBLEPeripheral_performPeriodicTask(WorkMode *WorkModeData) {
//Notify counter(Notify control, check if we need to send notify)
//please don't put Notify counter before ADC counter, maybe get wrong data
GPT.NotifyCounter = GPT.NotifyCounter + GPT.DeltaGptimerCounter;
if(GPT.NotifyCounter >= INSTRUCTION.notifyRate){
GPT.NotifyCounter -= INSTRUCTION.notifyRate; //To get right time
if(GPT.NotifyCounter >= instru.notifyRate){
GPT.NotifyCounter -= instru.notifyRate; //To get right time
notify_flag = true;
if(vscanReset){
notify_flag = false;
}
if(notify_flag && megaStiEnable){
InputNotify(NOTIFY_IMPEDANCE, Mega_Trig_receive);
if(notify_flag){
SendNotify();
Mega_Trig_receive = false;
notify_flag = false;
}
}
// EliteDone();
}
else if(INSTRUCTION.eliteFxn == VOLT_OUTPUT){
WorkModeData->VO->_Vset = INSTRUCTION.VoltConstant;
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, WorkModeData->VO->_Vset)); //UserCode -> DAC code -> DAC out
FreeWorkMode(WorkModeData);
mode_done();
}
else if (instru.eliteFxn == CURVE_CALI_DAC) {
DAC_outputV(instru.VoltConstant); //UserCode -> DAC code -> DAC out
wm_deinit();
PeriodicEvent = false;
}
else if(INSTRUCTION.eliteFxn == CALI_DAC_MODE){
DAC_outputV(INSTRUCTION.VoltConstant); //UserCode -> DAC code -> DAC out
FreeWorkMode(WorkModeData);
PeriodicEvent = false;
}
else{
// InitFlag();
} else {
}
}
static void EliteADCControl(WorkMode *WorkModeData) {
switch (INSTRUCTION.eliteFxn) {
case IV_CURVE:{
CC_Plot(WorkModeData);
static void EliteADCControl(void)
{
switch (instru.eliteFxn) {
case CURVE_IV:
case CURVE_RT:
case CURVE_CC:
case CURVE_CV:
case CURVE_CA:
case CURVE_VO:
case CURVE_LSV:
case CURVE_IV_CY:
case CURVE_PULSE:
CC_Plot();
break;
}
case CV_CURVE:{
CC_Plot(WorkModeData);
break;
}
case IT_CURVE:{
IT_Plot(WorkModeData);
break;
}
case VT_CURVE:{
VT_Plot(WorkModeData);
break;
}
case ZT_CURVE:{
CC_Plot(WorkModeData);
break;
}
case CONSTANT_CURRENT:{
CC_Plot(WorkModeData);
break;
}
case CYCLIC_VOLTAMMETRY:{
CC_Plot(WorkModeData);
break;
}
case LINEAR_SWEEP_VOLTAMMETRY:{
CC_Plot(WorkModeData);
break;
}
case CONSTANT_VSCAN:{
CC_Plot(WorkModeData);
break;
}
case CALI_ADC_MODE:{
if(INSTRUCTION.AdcChannel == IIN_ADC){
cali_IT_plot(WorkModeData);
}else if(INSTRUCTION.AdcChannel == VIN_ADC){
cali_VT_plot(WorkModeData);
}
case CURVE_IT:
IT_Plot();
break;
}
case PULSE_MODE:{
CC_Plot(WorkModeData);
case CURVE_VT:
VT_Plot();
break;
}
default:{
case CURVE_CALI_ADC:
if (instru.AdcChannel == IIN_ADC) cali_IT_plot();
else if (instru.AdcChannel == VIN_ADC) cali_VT_plot();
break;
default:
break;
}
}
}
static void EliteDone() {
if ((INSTRUCTION.eliteFxn == IV_CURVE) || (INSTRUCTION.eliteFxn == CV_CURVE) || (INSTRUCTION.eliteFxn == CYCLIC_VOLTAMMETRY)) {
static void mode_done(void)
{
if ((instru.eliteFxn == CURVE_IV) ||
(instru.eliteFxn == CURVE_CV) ||
(instru.eliteFxn == CURVE_LSV) ||
(instru.eliteFxn == CURVE_IV_CY)) {
if (!PeriodicEvent) {
finishMode = 1;
SendNotify();
Eliteinterrupt();
}
}
}
static void EliteVscanControl(WorkMode *WorkModeData) {
switch (INSTRUCTION.eliteFxn) {
case IV_CURVE:{
IV_Vscan(WorkModeData->IV);
static void vscan_ctrl(void)
{
switch (instru.eliteFxn) {
case CURVE_IV:
iv_vscan();
break;
}
case CV_CURVE:{
CV_Vscan(WorkModeData->CV);
case CURVE_IV_CY:
iv_cy_vscan();
break;
}
case ZT_CURVE:{
ZT_Vscan(WorkModeData->RT);
case CURVE_VO:
vo_vscan();
break;
}
case CYCLIC_VOLTAMMETRY:{
CV3_Vscan(WorkModeData->CV3);
case CURVE_RT:
rt_vscan();
break;
}
case CONSTANT_CURRENT:{
CC_Vscan(WorkModeData->CC);
case CURVE_CV:
cv_vscan();
break;
}
case LINEAR_SWEEP_VOLTAMMETRY:{
LSV_Vscan(WorkModeData->LSV);
case CURVE_LSV:
lsv_vscan();
break;
}
case CONSTANT_VSCAN:{
CVSCAN_Vscan(WorkModeData->CVSCAN);
case CURVE_CA:
ca_vscan();
break;
}
case PULSE_MODE:{
// PULSE_Vscan(WorkModeData->PULSE);
break;
}
default:{
break;
}
@@ -523,38 +472,16 @@ static void step2VsetRate(uint32_t step){
0.01mv, index = 4, n = 10000 */
if(step >= 10000){
INSTRUCTION.VsetRateIndex = 0;
instru.VsetRateIndex = 0;
}else if (step >= 1000){
INSTRUCTION.VsetRateIndex = 1;
instru.VsetRateIndex = 1;
}else if (step >= 100){
INSTRUCTION.VsetRateIndex = 2;
instru.VsetRateIndex = 2;
}else if (step >= 10){
INSTRUCTION.VsetRateIndex = 3;
instru.VsetRateIndex = 3;
}else if (step >= 1){
INSTRUCTION.VsetRateIndex = 4;
instru.VsetRateIndex = 4;
}
}
static void InitFlag(){
PeriodicEvent = false; // is there an PeriodicEvent?
Free_Work_Mode = true; // Free(WorkModeData)
}
static void InitEliteGPtimer() {
GPT.SampleRateCounter = INSTRUCTION.sampleRate - 10;
GPT.VscanRateCounter = INSTRUCTION.VsetRate - 1;
notifyFirst_flag = true;
}
static void InitEliteFlag() {
InitPeriodicEvent = true; // need to create a WorkModeData?
DACReset = true;
vscanReset = true;
EliteWorkReset = true;
leadTimeReset = true;
I_GAIN_100R_counter = 0;
I_GAIN_3K_counter = 0;
I_GAIN_100K_counter = 0;
I_GAIN_3M_counter = 0;
}
#endif /* IMPEDANCE_METER_H_ */
@@ -543,26 +543,18 @@ static void SimpleBLEPeripheral_init(void) {
// static void detectKey_clockHandler(UArg arg);
static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
uint8_t key= 0;
bool EliteOn = 0;
uint16_t counter6994 = 0;
batteryADC_flag = false;
// Initialize application
SimpleBLEPeripheral_init();
ZM_init();
WorkMode *WorkModeData = CreateWorkMode();
// init DAC, set output ~= 0 V
INSTRUCTION.VoutGainLevel = VOUT_GAIN_15K;
VoutGainControl(INSTRUCTION.VoutGainLevel);
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, 25000));
uint8_t key = 0;
uint16_t counter6994 = 0;
bool EliteOn = 0;
elite_gptimer_start();
// Application main loops
GPT.GptimerCounter0 = GPT.GptimerCounter;
batteryADC_flag = false;
headstage_battery_volt();
headstage_init_device_info();
@@ -613,64 +605,42 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
}
}
}
if(events & SBP_PERIODIC_EVT){
events &= ~SBP_PERIODIC_EVT;
if (!PeriodicEvent) { // if there is no periodic event
key = PIN_getInputValue(switch_on);
if (EliteOn) {
if (counter6994 < CLOCK_ONE_SECOND/2) { // counter6994 enable a IC after 35 counts
if (counter6994 < CLOCK_ONE_SECOND*5) { // counter6994 enable a IC after 35 counts
counter6994++;
} else if (counter6994 == CLOCK_ONE_SECOND/2) {
PIN15_setOutputValue(shutdown_6994, 1); // OFF = 1 => turn off 6994
} else if (counter6994 == CLOCK_ONE_SECOND*5) {
PIN15_setOutputValue(shutdown_6994, 0); // OFF = 1 => turn off 6994
counter6994++;
} else if (counter6994 > CLOCK_ONE_SECOND*5) {
counter6994 = 0;
}
EliteKeyPress(key);
// if(key != 0){ //detect Elite battery power when no periodic event
// measureBat();
// }
if(key != 0){ //detect Elite battery power when no periodic event
measureBat();
}
if(Free_Work_Mode){
FreeWorkMode(WorkModeData);
wm_deinit();
InitEliteInstruction();
Free_Work_Mode = false;
}
/* Megafly trigger */
// trig = PIN_getInputValue(MEGA_TRIG); // trigger: 1 -> 0
if (Mega_PeriodicEvent) {
Mega_PeriodicEvent = false;
PeriodicEvent = true;
}
/*
if (MEGA_getTRIG) {
MEGA_getTRIG = false;
LED_color(DARKLED, 0xFF, 0x00, 0x00);
} else if (MEGA_test_getTRIG) {
MEGA_test_getTRIG = false;
LED_color(DARKLED, 0x00, 0xFF, 0x00);
}
*/
} else {
// EliteOn = TurnOnElite(key);
headstage_battery_volt();
uint16_t bat = ((uint16_t)(NotifyVoltBat[2]) << 8 & 0xFF00 ) |
((uint16_t)(NotifyVoltBat[3]) & 0x00FF);
PIN15_setOutputValue(enable_5v, 1); // enable 5V
TurnOn10V();
ModeLED(BT_WAIT);
EliteOn = true;
EliteOn = TurnOnElite(key);
}
}
else { // if there is periodic event
if(InitPeriodicEvent){
InitWorkMode(WorkModeData);
wm_init();
InitPeriodicEvent = false;
}
// Perform periodic application task
SimpleBLEPeripheral_performPeriodicTask(WorkModeData);
SimpleBLEPeripheral_performPeriodicTask();
key = PIN_getInputValue(switch_on);
EliteKeyPress(key); // onPress=> key = 0; 1.lighten LED 2.long press shut down 2650
}
@@ -949,16 +919,16 @@ static void SimpleBLEPeripheral_processStateChangeEvt(gaprole_States_t newState)
numActive = linkDB_NumActive();
// uint16_t cxnHandle;
//
// // requestedPDUSize = LL payload = L2CAP_header + ATT header + BLE_NOT_BUFF_SIZE = 7 + BLE_NOT_BUFF_SIZE //roy
// uint16_t requestedPDUSize = 251; //251 roy
// uint16_t requestTxTime = 2120; // (LL payload + 14) * 8 //2120 roy
// GAPRole_GetParameter(GAPROLE_CONNHANDLE, &cxnHandle);
//
// if (SUCCESS == HCI_LE_SetDataLenCmd(cxnHandle, requestedPDUSize, requestTxTime)) {
//// LED_color(DARKLED, 0xFF, 0x00, 0xFF);
// }
uint16_t cxnHandle;
// requestedPDUSize = LL payload = L2CAP_header + ATT header + BLE_NOT_BUFF_SIZE = 7 + BLE_NOT_BUFF_SIZE //roy
uint16_t requestedPDUSize = 251; //251 roy
uint16_t requestTxTime = 2120; // (LL payload + 14) * 8 //2120 roy
GAPRole_GetParameter(GAPROLE_CONNHANDLE, &cxnHandle);
if (SUCCESS == HCI_LE_SetDataLenCmd(cxnHandle, requestedPDUSize, requestTxTime)) {
// LED_color(DARKLED, 0xFF, 0x00, 0xFF);
}
// Use numActive to determine the connection handle of the last
// connection
@@ -999,6 +969,7 @@ static void SimpleBLEPeripheral_processStateChangeEvt(gaprole_States_t newState)
case GAPROLE_WAITING_AFTER_TIMEOUT:
SimpleBLEPeripheral_freeAttRsp(bleNotConnected);
ModeLED(BT_WAIT);
#ifdef PLUS_BROADCASTER
// Reset flag for next connection.
@@ -85,7 +85,7 @@ extern "C"
// Length of Characteristic 5 in bytes
#define SIMPLEPROFILE_CHAR5_LEN 5
#define SIMPLEPROFILE_CHAR4_LEN 20
#define SIMPLEPROFILE_CHAR4_LEN 60
#define SIMPLEPROFILE_CHAR3_LEN 20
#define SIMPLEPROFILE_CHAR2_LEN 20