Compare commits

..

46 Commits

Author SHA1 Message Date
weiting2 83e2a6537c note 2020-12-29 15:35:40 +08:00
weiting2 509419610b WGAmp 2020-12-29 14:14:03 +08:00
frankydtai 4d5c4182fd CTL_WRT_WGAMPL added 2020-12-28 15:35:59 +08:00
weiting2 91fadb0d97 WGAmp 2020-12-25 10:53:53 +08:00
weiting2 0ff4833fb0 WGAmp 2020-12-25 10:50:50 +08:00
weiting2 2f2967c09a WGAmp 2020-12-25 10:47:18 +08:00
frankydtai ba5b306fd5 CTL_WRT_WGAMPL added 2020-12-23 15:07:26 +08:00
frankydtai 2190115d6f CTL_WRT_WGAMPL added 2020-12-23 14:07:50 +08:00
frankydtai a7d083c6bc Merge remote-tracking branch 'origin/EliteEIS_developement' into EliteEIS_developement
# Conflicts:
#	simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/EliteSPI.h
#	simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/Elite_def.h
#	simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage/headstage.h
2020-12-23 13:59:53 +08:00
frankydtai 7f51e113d6 CTL_WRT_WGAMPL added 2020-12-23 13:58:25 +08:00
weiting2 651e42d218 DFT finished 2020-12-21 10:54:17 +08:00
weiting2 8bbd4dbb41 commit 2020-12-11 17:01:49 +08:00
weiting2 a032346630 DFT in test 2020-11-24 10:16:33 +08:00
weiting2 6b78e8ebbe Waveform Generation Done 2020-11-19 11:43:35 +08:00
weiting2 824ec33776 Waveform Generation Done 2020-11-10 16:14:41 +08:00
weiting2 969a726332 AC debug 2020-11-04 21:10:26 +08:00
weiting2 1215f8a30c SPI fixed 2020-10-29 14:50:20 +08:00
weiting2 89e7706ac2 adjust more READ again.... 2020-10-28 16:16:27 +08:00
weiting2 352e6f5e3b adjust more READ again.... 2020-10-27 16:12:40 +08:00
weiting2 87c82df18c adjust more READ again... 2020-10-23 13:29:14 +08:00
weiting2 8f4eb259cf adjust more READ again.. 2020-10-22 14:47:34 +08:00
weiting2 ad12b9e857 adjust more READ again. 2020-10-20 16:37:17 +08:00
weiting2 3c91123424 adjust more READ again 2020-10-19 17:29:43 +08:00
weiting2 0c602842a3 adjust more READ 2020-10-13 16:23:44 +08:00
weiting2 a36b9e3ec2 adjust READ 2020-10-13 09:46:43 +08:00
YiChin c7a92aa317 test SPICMD_READREG 2020-10-07 18:47:09 +08:00
YiChin 9ea145192e update SPI1 phase 2020-10-07 17:30:18 +08:00
frankydtai 82abbcc528 AD_CS to Board_SP1_CS 2020-10-07 15:17:54 +08:00
YiChin b99b75a31d verification by bluetooth communication 2020-10-06 18:10:21 +08:00
YiChin f5fa44b95a verification by bluetooth communication 2020-10-06 16:50:18 +08:00
frankydtai ff64788ba4 verification by bluetooth communication 2020-10-06 15:02:48 +08:00
frankydtai 1c49b2e204 INITIALIZATION debug 2020-10-06 14:01:06 +08:00
YiChin 171e3b2df6 INITIALIZATION set 2020-10-05 16:42:14 +08:00
frankydtai 16636e1c1d INITIALIZATION set 2020-10-05 16:28:13 +08:00
YiChin 817eb45cb8 test volt output 2020-09-29 17:54:14 +08:00
YiChin 2ea3c76a49 test volt output 2020-09-29 14:17:56 +08:00
YiChin 4fc2c9c348 test volt output 2020-09-29 14:10:43 +08:00
YiChin a321ea5f3e test volt output 2020-09-29 13:42:22 +08:00
frankydtai 13ace26dd0 Merge remote-tracking branch 'origin/EliteEIS_developement' into EliteEIS_developement 2020-09-29 12:04:30 +08:00
frankydtai ceb73191dc SPI DAC registers set 2020-09-29 11:57:58 +08:00
YiChin d5b5ebdadb power test passed 2020-09-23 14:48:42 +08:00
YiChin 9ac63d8313 SPI DAC 2020-09-15 17:40:53 +08:00
frankydtai 0966c99b20 SPI DAC 2020-09-15 17:13:45 +08:00
roy 6f51cc35e2 delete something 2020-09-14 15:05:50 +08:00
frankydtai e85974b12b updated pins 2020-09-14 11:16:58 +08:00
frankydtai f342ff0763 test EIS 2020-09-11 16:08:21 +08:00
29 changed files with 1307 additions and 3127 deletions
@@ -16,7 +16,7 @@
# sources were generated) is:
# C:\ti\simplelink\ble_sdk_2_02_02_25\examples\cc2650em\simple_peripheral\ccs\config\src
#
GEN_SRC_DIR ?= ../../../../../ti/simplelink/ble_sdk_2_02_02_25/examples/cc2650em/simple_peripheral/ccs/config/src
GEN_SRC_DIR ?= ../../config/src
ifeq (,$(wildcard $(GEN_SRC_DIR)))
$(error "ERROR: GEN_SRC_DIR must be set to the directory containing the generated sources")
@@ -1,12 +1,12 @@
XOPTS = -I"C:/ti/xdctools_3_32_00_06_core/packages/" -Dxdc_target_types__=C:/ti/tirtos_cc13xx_cc26xx_2_21_01_08/products/bios_6_46_01_38/packages/ti/targets/arm/elf/std.h -Dxdc_target_name__=M3
XOPTS = -I"C:/ti/xdctools_3_32_02_25_core/packages/" -Dxdc_target_types__=C:/ti/tirtos_cc13xx_cc26xx_2_21_01_08/products/bios_6_46_01_38/packages/ti/targets/arm/elf/std.h -Dxdc_target_name__=M3
vpath % C:/ti/tirtos_cc13xx_cc26xx_2_21_01_08/products/bios_6_46_01_38/packages/ti/sysbios/
vpath %.c C:/ti/xdctools_3_32_00_06_core/packages/
vpath %.c C:/ti/xdctools_3_32_02_25_core/packages/
CCOPTS = --endian=little -mv7M3 --abi=eabi -q -ms --opt_for_speed=0 --program_level_compile -o3 -g --optimize_with_debug -Dti_sysbios_knl_Task_minimizeLatency__D=FALSE -Dti_sysbios_family_arm_cc26xx_Boot_driverlibVersion=2 -Dti_sysbios_knl_Clock_stopCheckNext__D=TRUE -Dti_sysbios_family_arm_m3_Hwi_enableException__D=TRUE -Dti_sysbios_family_arm_m3_Hwi_disablePriority__D=32U -Dti_sysbios_family_arm_m3_Hwi_numSparseInterrupts__D=0U
XDC_ROOT = C:/ti/xdctools_3_32_00_06_core/packages/
XDC_ROOT = C:/ti/xdctools_3_32_02_25_core/packages/
BIOS_ROOT = C:/ti/tirtos_cc13xx_cc26xx_2_21_01_08/products/bios_6_46_01_38/packages/ti/sysbios/
@@ -16,14 +16,14 @@ BIOS_INC = -I"C:/ti/tirtos_cc13xx_cc26xx_2_21_01_08/products/bios_6_46_01_38/pa
TARGET_INC = -I"C:/ti/tirtos_cc13xx_cc26xx_2_21_01_08/products/bios_6_46_01_38/packages/"
INCS = $(BIOS_INC) $(TARGET_INC) --include_path="C:/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.4.LTS/include" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/icall/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/profiles/roles/cc26xx" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/profiles/roles" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/profiles/dev_info" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/profiles/simple_profile/cc26xx" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/profiles/simple_profile" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/common/cc26xx" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/heapmgr" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/controller/cc26xx/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/hal/src/target/_common" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/target" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/hal/src/target/_common/cc26xx" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/hal/src/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/osal/src/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/services/src/sdata" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/services/src/saddr" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/icall/src/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/rom" --include_path="C:/ti/tirtos_cc13xx_cc26xx_2_21_01_08/products/cc26xxware_2_24_03_17272" -IC:/ti/tirtos_cc13xx_cc26xx_2_21_01_08/products/bios_6_46_01_38/packages/
INCS = $(BIOS_INC) $(TARGET_INC) --include_path="C:/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.3.LTS/include" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app/headstage" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/examples/simple_peripheral/cc26xx/app" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/icall/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/profiles/roles/cc26xx" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/profiles/roles" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/profiles/dev_info" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/profiles/simple_profile/cc26xx" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/profiles/simple_profile" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/common/cc26xx" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/heapmgr" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/controller/cc26xx/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/hal/src/target/_common" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/target" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/hal/src/target/_common/cc26xx" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/hal/src/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/osal/src/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/services/src/sdata" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/services/src/saddr" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/components/icall/src/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/inc" --include_path="C:/ti/simplelink/ble_sdk_2_02_02_25/src/rom" --include_path="C:/ti/tirtos_cc13xx_cc26xx_2_21_01_08/products/cc26xxware_2_24_03_17272" -IC:/ti/tirtos_cc13xx_cc26xx_2_21_01_08/products/bios_6_46_01_38/packages/
CC = C:/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.4.LTS/bin/armcl -c $(CCOPTS) -I C:/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.4.LTS/include
ASM = C:/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.4.LTS/bin/armcl -c $(CCOPTS) -I C:/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.4.LTS/include
AR = C:/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.4.LTS/bin/armar rq
CC = C:/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.3.LTS/bin/armcl -c $(CCOPTS) -I C:/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.3.LTS/include
ASM = C:/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.3.LTS/bin/armcl -c $(CCOPTS) -I C:/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.3.LTS/include
AR = C:/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.3.LTS/bin/armar rq
DEL = C:/ti/xdctools_3_32_00_06_core/packages/../bin/rm -f
CP = C:/ti/xdctools_3_32_00_06_core/packages/../bin/cp -f
DEL = C:/ti/xdctools_3_32_02_25_core/packages/../bin/rm -f
CP = C:/ti/xdctools_3_32_02_25_core/packages/../bin/cp -f
define RM
$(if $(wildcard $1),$(DEL) $1,:)
@@ -106,7 +106,7 @@ extern const PIN_Config BoardGpioInitTable[];
#define Board_BP_Pin_J2_15 DIO8 /* MOSI */
#define Board_BP_Pin_J2_14 DIO7 /* MISO */
#define Board_BP_Pin_J2_13 DIO9 /* DAC_CS */
#define Board_BP_Pin_J2_12 DIO12 /* ADC_CS */
#define Board_BP_Pin_J2_12 DIO12 /* AD_CS */
#define Board_BP_Pin_J2_11 IOID_UNUSED /* NC */
/* Mapping of BoosterPack Connector Pins to BoosterPack Standard Functions (reflecting the BoosterPack Standard)
@@ -1,246 +0,0 @@
#ifndef Elite15_PIN
#define Elite_15PIN
#include "Elite_PIN.h"
static void update_latch_status (uint32_t latch_num, uint32_t elite_pin, bool highlow) {
switch (latch_num) {
case LOAD0: {
switch (elite_pin) {
case D0: {
LH.LATCH0[0] = highlow;
break;
}
case D1: {
LH.LATCH0[1] = highlow;
break;
}
case D2: {
LH.LATCH0[2] = highlow;
break;
}
case D3: {
LH.LATCH0[3] = highlow;
break;
}
case D4: {
LH.LATCH0[4] = highlow;
break;
}
case D5: {
LH.LATCH0[5] = highlow;
break;
}
case D6: {
LH.LATCH0[6] = highlow;
break;
}
case D7: {
LH.LATCH0[7] = highlow;
break;
}
default: {
break;
}
}
break;
}
case LOAD1: {
switch (elite_pin) {
case D0: {
LH.LATCH1[0] = highlow;
break;
}
case D1: {
LH.LATCH1[1] = highlow;
break;
}
case D2: {
LH.LATCH1[2] = highlow;
break;
}
case D3: {
LH.LATCH1[3] = highlow;
break;
}
case D4: {
LH.LATCH1[4] = highlow;
break;
}
case D5: {
LH.LATCH1[5] = highlow;
break;
}
case D6: {
LH.LATCH1[6] = highlow;
break;
}
case D7: {
LH.LATCH1[7] = highlow;
break;
}
default: {
break;
}
}
break;
}
case LOAD2: {
switch (elite_pin) {
case D0: {
LH.LATCH2[0] = highlow;
break;
}
case D1: {
LH.LATCH2[1] = highlow;
break;
}
case D2: {
LH.LATCH2[2] = highlow;
break;
}
case D3: {
LH.LATCH2[3] = highlow;
break;
}
case D4: {
LH.LATCH2[4] = highlow;
break;
}
case D5: {
LH.LATCH2[5] = highlow;
break;
}
case D6: {
LH.LATCH2[6] = highlow;
break;
}
case D7: {
LH.LATCH2[7] = highlow;
break;
}
default: {
break;
}
}
break;
}
default: {
break;
}
}
}
static void PIN15_setOutputValue (uint32_t latch_num, uint32_t pin_num, bool highlow) {
ELITE15_SPI_CLOSE();
add_elite_pin();
update_latch_status (latch_num, pin_num, highlow);
// PIN_setOutputValue(&ZM_rst, latch_num, 1); // Turn on latch
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(pin_handle, D4, LH.LATCH0[4]);
PIN_setOutputValue(pin_handle, D5, LH.LATCH0[5]);
PIN_setOutputValue(pin_handle, D6, LH.LATCH0[6]);
PIN_setOutputValue(pin_handle, D7, LH.LATCH0[7]);
break;
}
case LOAD1: {
PIN_setOutputValue(pin_handle, D0, LH.LATCH1[0]);
PIN_setOutputValue(pin_handle, D1, LH.LATCH1[1]);
PIN_setOutputValue(pin_handle, D2, LH.LATCH1[2]);
PIN_setOutputValue(pin_handle, D3, LH.LATCH1[3]);
PIN_setOutputValue(pin_handle, D4, LH.LATCH1[4]);
PIN_setOutputValue(pin_handle, D5, LH.LATCH1[5]);
PIN_setOutputValue(pin_handle, D6, LH.LATCH1[6]);
PIN_setOutputValue(pin_handle, D7, LH.LATCH1[7]);
break;
}
case LOAD2: {
PIN_setOutputValue(pin_handle, D0, LH.LATCH2[0]);
PIN_setOutputValue(pin_handle, D1, LH.LATCH2[1]);
PIN_setOutputValue(pin_handle, D2, LH.LATCH2[2]);
PIN_setOutputValue(pin_handle, D3, LH.LATCH2[3]);
PIN_setOutputValue(pin_handle, D4, LH.LATCH2[4]);
PIN_setOutputValue(pin_handle, D5, LH.LATCH2[5]);
PIN_setOutputValue(pin_handle, D6, LH.LATCH2[6]);
PIN_setOutputValue(pin_handle, D7, LH.LATCH2[7]);
break;
}
default: {
break;
}
}
PIN_setOutputValue(&ZM_rst, latch_num, 1); // Turn on latch
CPUdelay(10);
PIN_setOutputValue(&ZM_rst, latch_num, 0); // Turn off latch
remove_elite_pin();
ELITE15_SPI_HOLD();
}
static void Init_Elite15_PIN () {
InitLH();
add_elite_pin();
PIN_setOutputValue(pin_handle, D0, 0);
PIN_setOutputValue(pin_handle, D1, 0);
PIN_setOutputValue(pin_handle, D2, 0);
PIN_setOutputValue(pin_handle, D3, 0);
PIN_setOutputValue(pin_handle, D4, 0);
PIN_setOutputValue(pin_handle, D5, 0);
PIN_setOutputValue(pin_handle, D6, 0);
PIN_setOutputValue(pin_handle, D7, 0);
PIN_setOutputValue(pin_handle, LOAD0, 0);
PIN_setOutputValue(pin_handle, LOAD1, 1);
PIN_setOutputValue(pin_handle, LOAD2, 1);
CPUdelay(10);
PIN_setOutputValue(pin_handle, LOAD1, 0);
PIN_setOutputValue(pin_handle, LOAD2, 0);
PIN_setOutputValue(pin_handle, D0, 0);
PIN_setOutputValue(pin_handle, D1, 0);
PIN_setOutputValue(pin_handle, D2, 0);
PIN_setOutputValue(pin_handle, D3, 0);
PIN_setOutputValue(pin_handle, D4, 1);
PIN_setOutputValue(pin_handle, D5, 1);
PIN_setOutputValue(pin_handle, D6, 1);
PIN_setOutputValue(pin_handle, D7, 1);
CPUdelay(10);
PIN_setOutputValue(pin_handle, LOAD0, 1);
PIN_setOutputValue(pin_handle, LOAD0, 0);
remove_elite_pin();
// InitLH();
// add_elite_pin();
//
// PIN_setOutputValue(pin_handle, LOAD0, 1);
// PIN_setOutputValue(pin_handle, LOAD1, 1);
// PIN_setOutputValue(pin_handle, LOAD2, 1);
// CPUdelay(10);
// PIN_setOutputValue(pin_handle, D0, 0);
// PIN_setOutputValue(pin_handle, D1, 0);
// PIN_setOutputValue(pin_handle, D2, 0);
// PIN_setOutputValue(pin_handle, D3, 0);
// PIN_setOutputValue(pin_handle, D4, 0);
// PIN_setOutputValue(pin_handle, D5, 0);
// PIN_setOutputValue(pin_handle, D6, 0);
// PIN_setOutputValue(pin_handle, D7, 0);
// CPUdelay(10);
// PIN_setOutputValue(pin_handle, LOAD0, 0);
// PIN_setOutputValue(pin_handle, LOAD1, 0);
// PIN_setOutputValue(pin_handle, LOAD2, 0);
//
// remove_elite_pin();
}
#endif
@@ -80,86 +80,6 @@ static void CAL_ADC_write(uint8_t ADCin) {
CAL_ADC_SPI(2, spi_ADC_txbuf, spi_ADC_rxbuf);
}
/* Gain Control for Vin & Iin */
static void IinADCGainControl(uint8_t IinADCLevel){
if(IinADCLevel == 0){
// ADC gain level = 0, using 3M resister
PIN15_setOutputValue(Turnon_I_LARGE, 0);
PIN15_setOutputValue(Turnon_I_MID, 0);
PIN15_setOutputValue(Turnon_I_SMALL, 0);
}
else if(IinADCLevel == 1){
// ADC gain level = 1, using 100K resister
PIN15_setOutputValue(Turnon_I_LARGE, 0);
PIN15_setOutputValue(Turnon_I_MID, 0);
PIN15_setOutputValue(Turnon_I_SMALL, 1);
}
else if(IinADCLevel == 2){
// ADC gain level = 2, using 3K resister
PIN15_setOutputValue(Turnon_I_LARGE, 0);
PIN15_setOutputValue(Turnon_I_MID, 1);
PIN15_setOutputValue(Turnon_I_SMALL, 0);
}
else if(IinADCLevel == 3){
// ADC gain level = 3, using 100R resistor
PIN15_setOutputValue(Turnon_I_LARGE, 1);
PIN15_setOutputValue(Turnon_I_MID, 0);
PIN15_setOutputValue(Turnon_I_SMALL, 0);
}
else if(IinADCLevel == 4){
// ADC gain level = 3, auto gain (using 100R resister)
PIN15_setOutputValue(Turnon_I_LARGE, 1);
PIN15_setOutputValue(Turnon_I_MID, 0);
PIN15_setOutputValue(Turnon_I_SMALL, 0);
}
else{
// default using 100R resister
PIN15_setOutputValue(Turnon_I_LARGE, 1);
PIN15_setOutputValue(Turnon_I_MID, 0);
PIN15_setOutputValue(Turnon_I_SMALL, 0);
}
if(IinADCLevel == 0 || IinADCLevel == 1 || IinADCLevel == 2 || IinADCLevel == 3){
lastIinADCGainLevel = IinADCLevel;
}else{
lastIinADCGainLevel = 3;
}
}
static void VinADCGainControl(uint8_t VinADCLevel){
if(VinADCLevel == 0){
// Vin ADC gain level = 0, using 1M resister
PIN15_setOutputValue(Turnon_V_SMALL, 0);
PIN15_setOutputValue(Turnon_V_MID, 0);
}
else if(VinADCLevel == 1){
// Vin ADC gain level = 1, using 30K resister
PIN15_setOutputValue(Turnon_V_SMALL, 0);
PIN15_setOutputValue(Turnon_V_MID, 1);
}
else if(VinADCLevel == 2){
// Vin ADC gain level = 2, using 1K resister
PIN15_setOutputValue(Turnon_V_SMALL, 1);
PIN15_setOutputValue(Turnon_V_MID, 0);
}
else if(VinADCLevel == 3){
// Vin ADC gain level = 3, auto gain (using 1K resister)
PIN15_setOutputValue(Turnon_V_SMALL, 1);
PIN15_setOutputValue(Turnon_V_MID, 0);
}
else{
// default using 1K resister
PIN15_setOutputValue(Turnon_V_SMALL, 1);
PIN15_setOutputValue(Turnon_V_MID, 0);
}
if(VinADCLevel == 0 || VinADCLevel == 1 || VinADCLevel == 2){
lastVinADCGainLevel = VinADCLevel;
}else{
lastVinADCGainLevel = 2;
}
}
static void ADCChannelSelect(uint8_t ADCChannel){
// set ADC parameter
// 0xC1~F1 = reading AIN0~AIN3. Using FSR+-6V, resolution = 187.5uV
@@ -238,20 +158,12 @@ static void ReadADCBat(uint8_t *buf){
/* for Elite1.5-re */
// Iin theoretical boundary <2.67, 1.89~80, 63~2600, >1900 (uA)
/* Old boundary
#define I_GAIN_SMALL_BOUNDARY 4000 // 4 uA = 4,000,000 pA
#define I_GAIN_MID1_BOUNDARY1 2000 // 2 uA = 2,000,000 pA
#define I_GAIN_MID1_BOUNDARY2 90000 // 90 uA = 90,000,000 pA
#define I_GAIN_MID2_BOUNDARY1 70000 // 70 uA = 70,000,000 pA
#define I_GAIN_MID2_BOUNDARY2 1800000 // 1800 uA = 1,800,000 nA
#define I_GAIN_LARGE_BOUNDARY 950000 // 950 uA = 950,000 nA
*/
#define I_GAIN_SMALL_BOUNDARY 4000 // 4 uA = 4,000,000 pA
#define I_GAIN_MID1_BOUNDARY1 2500 // 2.5 uA = 2,500,000 pA
#define I_GAIN_MID1_BOUNDARY2 100000 // 100 uA = 100,000,000 pA
#define I_GAIN_MID2_BOUNDARY1 85000 // 85 uA = 85,000,000 pA
#define I_GAIN_MID2_BOUNDARY2 2050000 // 2050 uA = 2,050,000 nA
#define I_GAIN_LARGE_BOUNDARY 1800000 // 1800 uA = 1,800,000 nA
// Vin theoretical boundary <7, 5~200, >100 (mV)
#define VIN_GAIN_SMALL_BOUNDARY 7000 // 7 mV = 7,000,000 nV
@@ -277,286 +189,286 @@ static int32_t AutoGainReadVin(uint8_t *buf){
return RealVolt;
}
static void AutoGainChangeIin(int32_t RealCurrent){
// switch to 1 level current(small) 3M
// 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(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);
I_GAIN_3M_counter = 0;
record_flag = false;
}
}
// switch to 2 level current
else if (RealCurrent < I_GAIN_MID2_BOUNDARY1 && RealCurrent > -1*I_GAIN_MID2_BOUNDARY1){
I_GAIN_100K_counter++;
if(I_GAIN_100K_counter > 2){
INSTRUCTION.ADCGainLevel = I_GAIN_100K;
IinADCGainControl(INSTRUCTION.ADCGainLevel);
I_GAIN_100K_counter = 0;
record_flag = false;
}
}
// switch to 3 level current
else{
I_GAIN_3K_counter++;
if(I_GAIN_3K_counter > 2){
INSTRUCTION.ADCGainLevel = I_GAIN_3K;
IinADCGainControl(INSTRUCTION.ADCGainLevel);
I_GAIN_3K_counter = 0;
record_flag = false;
}
}
}else{
if(I_GAIN_3K_counter > 0){
I_GAIN_3K_counter--;
}
if(I_GAIN_100K_counter > 0){
I_GAIN_100K_counter--;
}
if(I_GAIN_3M_counter > 0){
I_GAIN_3M_counter--;
}
}
}
else if(INSTRUCTION.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);
I_GAIN_100R_counter = 0;
record_flag = false;
}
}
else if (RealCurrent < I_GAIN_MID2_BOUNDARY1 && RealCurrent > -1*I_GAIN_MID2_BOUNDARY1){
// 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);
I_GAIN_3M_counter = 0;
record_flag = false;
}
}
// switch to 2 level current
else{
I_GAIN_100K_counter++;
if(I_GAIN_100K_counter > 2){
INSTRUCTION.ADCGainLevel = I_GAIN_100K;
IinADCGainControl(INSTRUCTION.ADCGainLevel);
I_GAIN_100K_counter = 0;
record_flag = false;
}
}
}else{
if(I_GAIN_100R_counter > 0){
I_GAIN_100R_counter--;
}
if(I_GAIN_100K_counter > 0){
I_GAIN_100K_counter--;
}
if(I_GAIN_3M_counter > 0){
I_GAIN_3M_counter--;
}
}
}
else if(INSTRUCTION.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);
I_GAIN_3M_counter = 0;
record_flag = false;
}
}
else if (RealCurrent > I_GAIN_MID1_BOUNDARY2 || RealCurrent < -1*I_GAIN_MID1_BOUNDARY2){
// 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);
I_GAIN_100R_counter = 0;
record_flag = false;
}
}
// switch to 3 level current
else{
I_GAIN_3K_counter++;
if(I_GAIN_3K_counter > 2){
INSTRUCTION.ADCGainLevel = I_GAIN_3K;
IinADCGainControl(INSTRUCTION.ADCGainLevel);
I_GAIN_3K_counter = 0;
record_flag = false;
}
}
}else{
if(I_GAIN_100R_counter > 0){
I_GAIN_100R_counter--;
}
if(I_GAIN_3K_counter > 0){
I_GAIN_3K_counter--;
}
if(I_GAIN_3M_counter > 0){
I_GAIN_3M_counter--;
}
}
}
else if(INSTRUCTION.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);
I_GAIN_100R_counter = 0;
record_flag = false;
}
}
// switch to 3 level current
else if(RealCurrent > I_GAIN_MID1_BOUNDARY2 || RealCurrent < -1*I_GAIN_MID1_BOUNDARY2){
I_GAIN_3K_counter++;
if(I_GAIN_3K_counter > 2){
INSTRUCTION.ADCGainLevel = I_GAIN_3K;
IinADCGainControl(INSTRUCTION.ADCGainLevel);
I_GAIN_3K_counter = 0;
record_flag = false;
}
}
// switch to 2 level current
else{
I_GAIN_100K_counter++;
if(I_GAIN_100K_counter > 2){
INSTRUCTION.ADCGainLevel = I_GAIN_100K;
IinADCGainControl(INSTRUCTION.ADCGainLevel);
I_GAIN_100K_counter = 0;
record_flag = false;
}
//static void AutoGainChangeIin(int32_t RealCurrent){
// // switch to 1 level current(small) 3M
// // 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(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);
// I_GAIN_3M_counter = 0;
// record_flag = false;
// }
// }
// // switch to 2 level current
// else if (RealCurrent < I_GAIN_MID2_BOUNDARY1 && RealCurrent > -1*I_GAIN_MID2_BOUNDARY1){
// I_GAIN_100K_counter++;
// if(I_GAIN_100K_counter > 2){
// INSTRUCTION.ADCGainLevel = I_GAIN_100K;
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
// I_GAIN_100K_counter = 0;
// record_flag = false;
// }
// }
// // switch to 3 level current
// else{
// I_GAIN_3K_counter++;
// if(I_GAIN_3K_counter > 2){
// INSTRUCTION.ADCGainLevel = I_GAIN_3K;
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
// I_GAIN_3K_counter = 0;
// record_flag = false;
// }
// }
// }else{
// if(I_GAIN_3K_counter > 0){
// I_GAIN_3K_counter--;
// }
// if(I_GAIN_100K_counter > 0){
// I_GAIN_100K_counter--;
// }
// if(I_GAIN_3M_counter > 0){
// I_GAIN_3M_counter--;
// }
// }
// }
// else if(INSTRUCTION.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);
// I_GAIN_100R_counter = 0;
// record_flag = false;
// }
// }
// else if (RealCurrent < I_GAIN_MID2_BOUNDARY1 && RealCurrent > -1*I_GAIN_MID2_BOUNDARY1){
// // 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);
// I_GAIN_3M_counter = 0;
// record_flag = false;
// }
// }
// // switch to 2 level current
// else{
// I_GAIN_100K_counter++;
// if(I_GAIN_100K_counter > 2){
// INSTRUCTION.ADCGainLevel = I_GAIN_100K;
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
// I_GAIN_100K_counter = 0;
// record_flag = false;
// }
// }
// }else{
// if(I_GAIN_100R_counter > 0){
// I_GAIN_100R_counter--;
// }
// if(I_GAIN_100K_counter > 0){
// I_GAIN_100K_counter--;
// }
// if(I_GAIN_3M_counter > 0){
// I_GAIN_3M_counter--;
// }
// }
// }
// else if(INSTRUCTION.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);
// I_GAIN_3M_counter = 0;
// record_flag = false;
// }
// }
// else if (RealCurrent > I_GAIN_MID1_BOUNDARY2 || RealCurrent < -1*I_GAIN_MID1_BOUNDARY2){
// // 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);
// I_GAIN_100R_counter = 0;
// record_flag = false;
// }
// }
// // switch to 3 level current
// else{
// I_GAIN_3K_counter++;
// if(I_GAIN_3K_counter > 2){
// INSTRUCTION.ADCGainLevel = I_GAIN_3K;
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
// I_GAIN_3K_counter = 0;
// record_flag = false;
// }
// }
// }else{
// if(I_GAIN_100R_counter > 0){
// I_GAIN_100R_counter--;
// }
// if(I_GAIN_3K_counter > 0){
// I_GAIN_3K_counter--;
// }
// if(I_GAIN_3M_counter > 0){
// I_GAIN_3M_counter--;
// }
// }
// }
// else if(INSTRUCTION.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);
// I_GAIN_100R_counter = 0;
// record_flag = false;
// }
// }
// // switch to 3 level current
// else if(RealCurrent > I_GAIN_MID1_BOUNDARY2 || RealCurrent < -1*I_GAIN_MID1_BOUNDARY2){
// I_GAIN_3K_counter++;
// if(I_GAIN_3K_counter > 2){
// INSTRUCTION.ADCGainLevel = I_GAIN_3K;
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
// I_GAIN_3K_counter = 0;
// record_flag = false;
// }
// }
// // switch to 2 level current
// else{
// I_GAIN_100K_counter++;
// if(I_GAIN_100K_counter > 2){
// INSTRUCTION.ADCGainLevel = I_GAIN_100K;
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
// I_GAIN_100K_counter = 0;
// record_flag = false;
// }
//
// }
// }else{
// if(I_GAIN_100R_counter > 0){
// I_GAIN_100R_counter--;
// }
// if(I_GAIN_3K_counter > 0){
// I_GAIN_3K_counter--;
// }
// if(I_GAIN_100K_counter > 0){
// I_GAIN_100K_counter--;
// }
// }
// }
//}
}
}else{
if(I_GAIN_100R_counter > 0){
I_GAIN_100R_counter--;
}
if(I_GAIN_3K_counter > 0){
I_GAIN_3K_counter--;
}
if(I_GAIN_100K_counter > 0){
I_GAIN_100K_counter--;
}
}
}
}
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(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);
VIN_GAIN_1K_counter = 0;
record_flag = false;
}
}
// switch to 2 level volt
else{
VIN_GAIN_30K_counter++;
if(VIN_GAIN_30K_counter > 2){
INSTRUCTION.VinADCGainLevel = VIN_GAIN_30K;
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
VIN_GAIN_30K_counter = 0;
record_flag = false;
}
}
}else{
if(VIN_GAIN_1K_counter > 0){
VIN_GAIN_1K_counter--;
}
if(VIN_GAIN_30K_counter > 0){
VIN_GAIN_30K_counter--;
}
}
}
else if(INSTRUCTION.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);
VIN_GAIN_1M_counter = 0;
record_flag = false;
}
}
else if (RealVin > VIN_GAIN_MID1_BOUNDARY2 || RealVin < -1*VIN_GAIN_MID1_BOUNDARY2){
// switch to 3 level volt
VIN_GAIN_1K_counter++;
if(VIN_GAIN_1K_counter > 2){
INSTRUCTION.VinADCGainLevel = VIN_GAIN_1K;
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
VIN_GAIN_1K_counter = 0;
record_flag = false;
}
}else{
if(VIN_GAIN_1K_counter > 0){
VIN_GAIN_1K_counter--;
}
if(VIN_GAIN_1M_counter > 0){
VIN_GAIN_1M_counter--;
}
}
}
else if(INSTRUCTION.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);
VIN_GAIN_1M_counter = 0;
record_flag = false;
}
}
// switch to 2 level volt
else{
VIN_GAIN_30K_counter++;
if(VIN_GAIN_30K_counter > 2){
INSTRUCTION.VinADCGainLevel = VIN_GAIN_30K;
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
VIN_GAIN_30K_counter = 0;
record_flag = false;
}
}
}else{
if(VIN_GAIN_1M_counter > 0){
VIN_GAIN_1M_counter--;
}
if(VIN_GAIN_30K_counter > 0){
VIN_GAIN_30K_counter--;
}
}
}
}
//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(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);
// VIN_GAIN_1K_counter = 0;
// record_flag = false;
// }
// }
// // switch to 2 level volt
// else{
// VIN_GAIN_30K_counter++;
// if(VIN_GAIN_30K_counter > 2){
// INSTRUCTION.VinADCGainLevel = VIN_GAIN_30K;
// VinADCGainControl(INSTRUCTION.VinADCGainLevel);
// VIN_GAIN_30K_counter = 0;
// record_flag = false;
// }
// }
// }else{
// if(VIN_GAIN_1K_counter > 0){
// VIN_GAIN_1K_counter--;
// }
// if(VIN_GAIN_30K_counter > 0){
// VIN_GAIN_30K_counter--;
// }
// }
// }
// else if(INSTRUCTION.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);
// VIN_GAIN_1M_counter = 0;
// record_flag = false;
// }
// }
// else if (RealVin > VIN_GAIN_MID1_BOUNDARY2 || RealVin < -1*VIN_GAIN_MID1_BOUNDARY2){
// // switch to 3 level volt
// VIN_GAIN_1K_counter++;
// if(VIN_GAIN_1K_counter > 2){
// INSTRUCTION.VinADCGainLevel = VIN_GAIN_1K;
// VinADCGainControl(INSTRUCTION.VinADCGainLevel);
// VIN_GAIN_1K_counter = 0;
// record_flag = false;
// }
// }else{
// if(VIN_GAIN_1K_counter > 0){
// VIN_GAIN_1K_counter--;
// }
// if(VIN_GAIN_1M_counter > 0){
// VIN_GAIN_1M_counter--;
// }
// }
// }
// else if(INSTRUCTION.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);
// VIN_GAIN_1M_counter = 0;
// record_flag = false;
// }
// }
// // switch to 2 level volt
// else{
// VIN_GAIN_30K_counter++;
// if(VIN_GAIN_30K_counter > 2){
// INSTRUCTION.VinADCGainLevel = VIN_GAIN_30K;
// VinADCGainControl(INSTRUCTION.VinADCGainLevel);
// VIN_GAIN_30K_counter = 0;
// record_flag = false;
// }
// }
// }else{
// if(VIN_GAIN_1M_counter > 0){
// VIN_GAIN_1M_counter--;
// }
// if(VIN_GAIN_30K_counter > 0){
// VIN_GAIN_30K_counter--;
// }
// }
// }
//}
static uint16_t ADC_CURRENT_AVG_calibration (uint8_t ADC_channel) {
uint32_t ADCValueTemp = 0;
@@ -5,34 +5,31 @@
static bool DACReset;
//#ifdef ELITE_VERSION_1_3
//#define DACOUT 0x30
//
//static void DAC_outputV(uint16_t voltLV) {
// // C = command, X = don't care, D = data
// // CCCC XXXX = command
// // DDDD DDDD = v1
// // DDDD XXXX = v2
//
// uint8_t v1, v2 = 0;
// v1 = (uint8_t) (voltLV >> 4) & 0xFF;
// v2 = (uint8_t) ((voltLV & 0x000F) << 4) & 0xF0;
//
// spi_DACtxbuf[0] = command;
// spi_DACtxbuf[1] = v1;
// spi_DACtxbuf[2] = v2;
// for (int i = 3; i < SPI_DAC_SIZE; i++) {
// spi_DACtxbuf[i] = 0;
// }
//
// DAC_SPI(SPI_DAC_SIZE, spi_DACtxbuf, spi_rxbuf);
//}
//#endif
#ifdef ELITE_VERSION_1_3
#define DACOUT 0x30
static void DAC_outputV(uint16_t voltLV) {
// C = command, X = don't care, D = data
// CCCC XXXX = command
// DDDD DDDD = v1
// DDDD XXXX = v2
uint8_t v1, v2 = 0;
v1 = (uint8_t) (voltLV >> 4) & 0xFF;
v2 = (uint8_t) ((voltLV & 0x000F) << 4) & 0xF0;
spi_DACtxbuf[0] = command;
spi_DACtxbuf[1] = v1;
spi_DACtxbuf[2] = v2;
for (int i = 3; i < SPI_DAC_SIZE; i++) {
spi_DACtxbuf[i] = 0;
}
DAC_SPI(SPI_DAC_SIZE, spi_DACtxbuf, spi_rxbuf);
}
#endif
#ifdef ELITE_VERSION_1_4
#define DACCLS 0x02
#define DACOUT 0x31
static uint16_t DAC_outputV(uint16_t voltLV) {
// C = command, X = don't care, D = data
// CCCC CCCC = command
@@ -55,26 +52,19 @@ static uint16_t DAC_outputV(uint16_t voltLV) {
return voltLV;
}
#endif
static void VoutGainControl(uint8_t VOUTLevel){
if(VOUTLevel == 0){
// VOUT gain level = 0, using 240K resister
PIN15_setOutputValue(Turon_VOUT_SMALL, 0);
}
else if(VOUTLevel == 1){
// VOUT gain level = 1, using 15K resister
PIN15_setOutputValue(Turon_VOUT_SMALL, 1);
}
else if(VOUTLevel == 2){
// VOUT gain level = 2, using 15K resister
PIN15_setOutputValue(Turon_VOUT_SMALL, 1);
}
else{
// default using 15K resister
PIN15_setOutputValue(Turon_VOUT_SMALL, 1);
}
#ifdef ELITE_VERSION_EIS
static uint32_t DAC_outputV(uint32_t voltLV) {
// uint8_t v1, v2 = 0;
// v1 = (uint8_t) ((voltLV & 0xFF00) >> 8);
// v2 = (uint8_t) (voltLV & 0x00FF);
EIS_LPDAC_SPI(voltLV);
return voltLV;
}
#endif
static int32_t User2Real(uint16_t UserCode){
@@ -84,27 +74,22 @@ static int32_t User2Real(uint16_t UserCode){
// DAC Vout theoretical boundary <300, 100~ (mV)
#define DAC_VOUT_GAIN_SMALL_BOUNDARY 100000 // 25500(usercode) = 100 mV
#define DAC_VOUT_GAIN_LARGE_BOUNDARY 300000 // 26500(usercode) = 300 mV
#define DAC_VOUT_GAIN_LARGE_BOUNDARY_USERCODE 26500 // 26500(usercode) = 300 mV
#define DAC_VOUT_GAIN_LARGE_BOUNDARY1_USERCODE 23500 // 23500(usercode) = -300 mV
#define DAC_VOUT_GAIN_SMALL_BOUNDARY 100000 // 100 mV = 25500(usercode)
#define DAC_VOUT_GAIN_LARGE_BOUNDARY 300000 // 300 mV = 26500(usercode)
static void AutoGainChangeVout(int32_t userCode){
int32_t RealVolt = (userCode - 25000) * 200; // (userCode - 25000) / 5 * 1000 [1uV]
static void AutoGainChangeVout(int32_t RealVolt){
RealVolt = (RealVolt - 25000) * 200; // (RealVolt - 25000) / 5 * 1000
// 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);
record_flag = false;
}
if(INSTRUCTION.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);
record_flag = false;
}
}
@@ -112,7 +97,6 @@ static void AutoGainChangeVout(int32_t userCode){
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);
record_flag = false;
}
}
@@ -29,7 +29,7 @@
*/
#define BOARD_C7A1
#define BOARD_C6D4
typedef struct _formula{
@@ -46,11 +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
#ifdef BOARD_C6E1
{
.ADC_volt[0].coeff = (-6251051),
.ADC_volt[0].offset = 102081366120,
@@ -78,45 +77,41 @@ struct _correction{
.Usercode2DAC[1].coeff = (-10511469),
.Usercode2DAC[1].offset = 563770560100,
.Usercode2DAC15v = MEGA_15V,
};
#endif
#ifdef BOARD_C7A1
{
.ADC_volt[0].coeff = (6256),
.ADC_volt[0].offset = -101532028,
.ADC_volt[0].coeff = (6204),
.ADC_volt[0].offset = -100237253,
.ADC_volt[1].coeff = (215138),
.ADC_volt[1].offset = -3501890770,
.ADC_volt[1].coeff = (214511),
.ADC_volt[1].offset = -3485722036,
.ADC_volt[2].coeff = (6245014),
.ADC_volt[2].offset = -101751226981,
.ADC_volt[2].coeff = (6213224),
.ADC_volt[2].offset = -101104189300,
.ADC_current[0].coeff = 3125920,
.ADC_current[0].offset = (-50880328288),
.ADC_current[0].coeff = 2078892,
.ADC_current[0].offset = (-33685110900),
.ADC_current[1].coeff = 71636129,
.ADC_current[1].offset = (-1166093783868),
.ADC_current[1].coeff = 64769469,
.ADC_current[1].offset = (-1048938859469),
.ADC_current[2].coeff = 1459555637,
.ADC_current[2].offset = (-23757721396024),
.ADC_current[2].coeff = 2090182091,
.ADC_current[2].offset = (-33847893234994),
.ADC_current[3].coeff = 30723232882,
.ADC_current[3].offset = (-500144809348170),
.ADC_current[3].coeff = 60030468992,
.ADC_current[3].offset = (-972275155887907),
.Usercode2DAC[0].coeff = (-10543817),
.Usercode2DAC[0].offset = 583163641972,
.Usercode2DAC[0].coeff = (-10512772),
.Usercode2DAC[0].offset = 581302323013,
.Usercode2DAC[1].coeff = (-178077711),
.Usercode2DAC[1].offset = 4777894559527,
.Usercode2DAC15v = 41485,
.Usercode2DAC[1].coeff = (-178991273),
.Usercode2DAC[1].offset = 4794464882260,
};
#endif
#ifdef BOARD_C6D4 //not well
#ifdef BOARD_C6D4
{
.ADC_volt[0].coeff = (6226),
.ADC_volt[0].offset = -100075170,
@@ -144,107 +139,6 @@ struct _correction{
.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
{
.ADC_volt[0].coeff = (6251),
.ADC_volt[0].offset = -99750397,
.ADC_volt[1].coeff = (214419),
.ADC_volt[1].offset = -3491659841,
.ADC_volt[2].coeff = (6227737),
.ADC_volt[2].offset = -101557618268,
.ADC_current[0].coeff = 3138613,
.ADC_current[0].offset = (-51149570420),
.ADC_current[1].coeff = 71715555,
.ADC_current[1].offset = (-1168777305352),
.ADC_current[2].coeff = 1455501991,
.ADC_current[2].offset = (-23719715469357),
.ADC_current[3].coeff = 30688298312,
.ADC_current[3].offset = (-500150163983795),
.Usercode2DAC[0].coeff = (-10540182),
.Usercode2DAC[0].offset = 584459109821,
.Usercode2DAC[1].coeff = (-179175265),
.Usercode2DAC[1].offset = 4801179734836,
.Usercode2DAC15v = MEGA_15V,
};
#endif
#ifdef BOARD_C874
{
.ADC_volt[0].coeff = (6260),
.ADC_volt[0].offset = -99787811,
.ADC_volt[1].coeff = (214494),
.ADC_volt[1].offset = -3492178752,
.ADC_volt[2].coeff = (6231057),
.ADC_volt[2].offset = -101591914655,
.ADC_current[0].coeff = 3148251,
.ADC_current[0].offset = (-51277675282),
.ADC_current[1].coeff = 71859885,
.ADC_current[1].offset = (-1170556644217),
.ADC_current[2].coeff = 1462458824,
.ADC_current[2].offset = (-23822062635236),
.ADC_current[3].coeff = 30748473913,
.ADC_current[3].offset = (-500860829105930),
.Usercode2DAC[0].coeff = (-10570366),
.Usercode2DAC[0].offset = 585189864243,
.Usercode2DAC[1].coeff = (-178920333),
.Usercode2DAC[1].offset = 4794801719146,
.Usercode2DAC15v = 41355,
};
#endif
@@ -330,41 +224,43 @@ static int32_t DecodeADCValue(uint8_t ADCGain, uint8_t ADCChannel, uint8_t *ADC_
// #0 board, (0x5f75 <= rawdata) && (rawdata <= 0x5fb2)
// ((0x5f97 < rawdata) && (rawdata < 0x6589)) || ((0x5999 < rawdata) && (rawdata < 0x5f93))
static void ADC_overflow(uint8_t gain, uint8_t *rawdata){
// Gain boundary defines different ADC gain level working area
// Gain0Boundary = {lowerbound, upperbound}, is the lower and upper bound of gain level 0 working area.
uint16_t U16Rawdata = 0;
U16Rawdata = (((uint16_t) (rawdata[0]))<<8) | ((uint16_t) (rawdata[1]));
if(gain == I_GAIN_3M){
if( U16Rawdata <= Correction.Gain0Boundary[0]){
rawdata[0] = Correction.Gain0Boundary[0] >> 4;
rawdata[1] = (uint8_t) (Correction.Gain0Boundary[0] & 0x00FF);
}
else if(U16Rawdata >= Correction.Gain0Boundary[1]){
rawdata[0] = (uint8_t) (Correction.Gain0Boundary[1] >> 4);
rawdata[1] = (uint8_t) (Correction.Gain0Boundary[1] & 0x00FF);
}
}
else if(gain == I_GAIN_100K){
if( U16Rawdata <= Correction.Gain1Boundary[0]){
rawdata[0] = Correction.Gain1Boundary[0] >> 4;
rawdata[1] = (uint8_t) (Correction.Gain1Boundary[0] & 0x00FF);
}
else if(U16Rawdata >= Correction.Gain1Boundary[1]){
rawdata[0] = (uint8_t) (Correction.Gain1Boundary[1] >> 4);
rawdata[1] = (uint8_t) (Correction.Gain1Boundary[1] & 0x00FF);
}
}
}
//static void ADC_overflow(uint8_t gain, uint8_t *rawdata){
//
// // Gain boundary defines different ADC gain level working area
// // Gain0Boundary = {lowerbound, upperbound}, is the lower and upper bound of gain level 0 working area.
//
// uint16_t U16Rawdata = 0;
// U16Rawdata = (((uint16_t) (rawdata[0]))<<8) | ((uint16_t) (rawdata[1]));
//
// if(gain == I_GAIN_3M){
// if( U16Rawdata <= Correction.Gain0Boundary[0]){
// rawdata[0] = Correction.Gain0Boundary[0] >> 4;
// rawdata[1] = (uint8_t) (Correction.Gain0Boundary[0] & 0x00FF);
// }
// else if(U16Rawdata >= Correction.Gain0Boundary[1]){
// rawdata[0] = (uint8_t) (Correction.Gain0Boundary[1] >> 4);
// rawdata[1] = (uint8_t) (Correction.Gain0Boundary[1] & 0x00FF);
// }
// }
// else if(gain == I_GAIN_100K){
// if( U16Rawdata <= Correction.Gain1Boundary[0]){
// rawdata[0] = Correction.Gain1Boundary[0] >> 4;
// rawdata[1] = (uint8_t) (Correction.Gain1Boundary[0] & 0x00FF);
// }
// else if(U16Rawdata >= Correction.Gain1Boundary[1]){
// rawdata[0] = (uint8_t) (Correction.Gain1Boundary[1] >> 4);
// rawdata[1] = (uint8_t) (Correction.Gain1Boundary[1] & 0x00FF);
// }
// }
//}
// User will enter -5V~+5V in UI.
// websever and controler use 0~50000 represent -5~+5V
// this function should turn 0~50000 into DACcode which output the exactly voltage user want
static uint16_t Usercode_Correction_to_DAC(uint8_t DACGain, uint16_t usercode)
{
AutoGainChangeVout(usercode);
long long usercode_32;
uint16_t DACcode = 0;
@@ -22,11 +22,7 @@ struct _GPT{
uint32_t BatteryADCCounter;
uint32_t BatteryCheckCounter;
uint32_t GptimerMultiple;
uint32_t StiCounter;
uint32_t LedGCounter;
uint32_t LedRCounter;
uint32_t Gas0Counter;
uint32_t Gas1Counter;
uint32_t TestCounter;
}GPT = {0};
static void InitCT(){
@@ -46,10 +42,5 @@ static void InitGPT(){
GPT.LeadTimeCounter = 0;
GPT.BatteryADCCounter = 0;
GPT.BatteryCheckCounter = 0;
GPT.StiCounter = 0;
GPT.LedGCounter = 0;
GPT.LedRCounter = 0;
GPT.Gas0Counter = 0;
GPT.Gas1Counter = 0;
}
#endif
@@ -75,90 +75,6 @@ struct HEADSTAGE_INSTRUCTION {
uint8_t charge;
int32_t constantCurrent;
int32_t Currentmax;
int32_t sti_v1;
int32_t sti_v2;
int32_t sti_v3;
int32_t sti_v4;
int32_t sti_v5;
int32_t sti_v6;
int32_t sti_v7;
int32_t sti_t1;
int32_t sti_t2;
int32_t sti_t3;
int32_t sti_t4;
int32_t sti_t5;
int32_t sti_t6;
int32_t sti_t7;
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;
@@ -205,91 +121,5 @@ static void InitEliteInstruction(){
INSTRUCTION.Currentmax = 0;
INSTRUCTION.StepTime = STEPTIME_ONE_SEC;
INSTRUCTION.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;
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;
}
#endif
@@ -8,25 +8,19 @@ static bool TurnOnElite(uint8_t key) {
if (key == 0) {
// press 1 sec, power on LED, read bat power
if (TurnOnCounter >= CLOCK_ONE_SECOND) {
headstage_battery_volt();
uint16_t bat = ((uint16_t)(NotifyVoltBat[2]) << 8 & 0xFF00 ) |
((uint16_t)(NotifyVoltBat[3]) & 0x00FF);
if( bat < 768 && bat > 20){
PIN15_setOutputValue(enable_5v, 0);
return false;
}else{
PIN15_setOutputValue(enable_5v, 1); // enable 5V
TurnOn10V();
ModeLED(BT_WAIT);
return true;
}
PIN_setOutputValue(pin_handle, enable_5v, 1);// enable 5V
Elite_SPI_init();
ModeLED(BT_WAIT);
AD5940_init();
// DAC_outputV(0x3FFFF);
return true;
} else {
TurnOnCounter++;
return false;
}
} else {
TurnOnCounter = 0;
PIN15_setOutputValue(enable_5v, 0); // disable 5V
PIN_setOutputValue(pin_handle, enable_5v, 0); // disable 5V
return false;
}
}
@@ -46,7 +40,7 @@ static void EliteKeyPress(uint8_t key) {
// press 3~4 sec, shutdown 2650
else if (ShutDownCounter > (CLOCK_ONE_SECOND*3) ) {
LED_color(DARKLED, 0xFF, 0xFF, 0x00);
PIN15_setOutputValue(enable_5v, 0); // disable 5V
PIN_setOutputValue(pin_handle, enable_5v, 0); // disable 5V
}
ShutDownCounter ++;
} else {
@@ -66,10 +60,4 @@ static void EliteKeyPress(uint8_t key) {
}
}
static void TurnOn10V() {
If10Von = true;
PIN15_setOutputValue(enable_10v, 1);
CPUdelay(8000);
}
#endif
@@ -149,11 +149,6 @@ static void WorkModeLED() {
WORKLED();
break;
}
case PULSE_MODE:{
// Elite_led_color(COLOR_YELLOW);
WORKLED();
break;
}
case CONSTANT_CURRENT:{
WORKLED();
break;
@@ -1,528 +0,0 @@
#ifndef ELITEPULSE
#define ELITEPULSE
#define Vset INSTRUCTION.Vset
static void PULSE_Vscan(PULSEMode *PULSE)
{
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;
}
} else if(!stiFirstTime) {
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;
}
} 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 {
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 {
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_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;
PeriodicEvent = false;
megaTrigEnable = false;
ModeLED(NO_EVENT);
}
}
}
}
//InputNotify(NOTIFY_IMPEDANCE, testV);
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);
}
}
#endif
@@ -3,33 +3,16 @@
#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();
InitGPT();
InitLH();
PIN15_setOutputValue(HIGH_Z_MODE, 0); // 0 => open high_z mode
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));
// VinADCGainControl(VIN_GAIN_AUTO);
// IinADCGainControl(I_GAIN_AUTO);
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.VoltConstant));
initINSBuf();
initDATBuf();
@@ -48,34 +31,23 @@ static void reset() {
spi_ADC_rxbuf[i] = 0;
}
PIN_setOutputValue(pin_handle, AD_CS, 1); // AD_CS HIGH
// PIN15_setOutputValue(DAC_CS, 1); // DAC_CS HIGH
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();
ModeLED(NO_EVENT);
InitEliteFlag();
InitCT();
InitGPT();
InitLH();
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));
// VinADCGainControl(VIN_GAIN_AUTO);
// IinADCGainControl(I_GAIN_AUTO);
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.VoltConstant));
initINSBuf();
initDATBuf();
@@ -94,6 +66,7 @@ static void Eliteinterrupt() {
spi_ADC_rxbuf[i] = 0;
}
PIN_setOutputValue(pin_handle, AD_CS, 1); // AD_CS HIGH
CPUdelay(8000);
}
#endif
@@ -16,7 +16,7 @@
/* application use SPI parameters and buffers */
#define SPI_LED_SIZE 28
#define SPI_DAC_SIZE 3
#define SPI_DAC_SIZE 5
#define SPI_ADC_SIZE 4
static uint16_t spi_LEDtxbuf[SPI_LED_SIZE] = {0};
@@ -36,13 +36,10 @@ static SPI_Params spiParams1;
static SPI_Transaction LED_transaction;
static SPI_Transaction ADC_DAC_transaction;
static void ELITE15_SPI_HOLD();
static void ELITE15_SPI_CLOSE();
static void Elite_SPI_init(){
SPI_init();
SPI_Params_init(&spiParams0);
spiParams0.bitRate = 2000; // 12k
spiParams0.bitRate = 2000; // 2k
spiParams0.mode = SPI_MASTER;
spiParams0.dataSize = 16;
spiParams0.frameFormat = SPI_POL0_PHA1;
@@ -52,7 +49,8 @@ static void Elite_SPI_init(){
spiParams1.bitRate = 1000000; // 1M
spiParams1.mode = SPI_MASTER;
spiParams1.dataSize = 8;
spiParams1.frameFormat = SPI_POL0_PHA1;
spiParams1.frameFormat = SPI_POL0_PHA0;
spiHandle1 = SPI_open(Board_SPI1, &spiParams1); // ADC DAC SPI
}
@@ -65,9 +63,7 @@ static void LED_SPI(uint8_t length, uint16_t *spi_txbuf, uint16_t *spi_rxbuf) {
}
static void ADC_SPI(uint8_t length, uint8_t *spi_txbuf, uint8_t *spi_rxbuf) {
// PIN15_setOutputValue(ADC_CS, 0); // ADC_CS LOW
PIN_setOutputValue(pin_handle, LOAD0, 1);
PIN_setOutputValue(pin_handle, D6, 0); // ADC_CS LOW
PIN_setOutputValue(pin_handle, AD_CS, 0); // CS_ADC
ADC_DAC_transaction.count = length;
ADC_DAC_transaction.txBuf = spi_txbuf;
@@ -75,58 +71,228 @@ 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
update_latch_status (ADC_CS, 1);
// PIN15_setOutputValue(ADC_CS, 1); // ADC_CS HIGH
PIN_setOutputValue(pin_handle, AD_CS, 1); // CS_ADC
}
static void DAC_SPI(uint8_t length, uint8_t *spi_txbuf, uint8_t *spi_rxbuf) {
// PIN15_setOutputValue(DAC_CS, 0); // DAC_CS LOW
PIN_setOutputValue(pin_handle, LOAD0, 1);
PIN_setOutputValue(pin_handle, D7, 0); // DAC_CS LOW
ADC_DAC_transaction.count = length;
ADC_DAC_transaction.txBuf = spi_txbuf;
ADC_DAC_transaction.rxBuf = spi_rxbuf;
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
PIN_setOutputValue(pin_handle, D7, 1); // DAC_CS HOGH
update_latch_status (DAC_CS, 1);
// PIN15_setOutputValue(DAC_CS, 1); // DAC_CS HIGH
}
static void ELITE15_SPI_HOLD() {
Elite_SPI_init();
PIN_setOutputValue(pin_handle, LOAD0, 1);
PIN_setOutputValue(pin_handle, LOAD1, 0);
PIN_setOutputValue(pin_handle, LOAD2, 0);
}
static void ELITE15_SPI_CLOSE() {
PIN_setOutputValue(pin_handle, LOAD0, 0);
PIN_setOutputValue(pin_handle, LOAD1, 0);
PIN_setOutputValue(pin_handle, LOAD2, 0);
SPI_close(spiHandle0);
SPI_close(spiHandle1);
}
/* Elite1.5 Calibration SPI */
static void CAL_ADC_SPI(uint8_t length, uint8_t *spi_txbuf, uint8_t *spi_rxbuf) {
// PIN15_setOutputValue(ADC_CS, 0); // ADC_CS LOW
PIN_setOutputValue(pin_handle, LOAD0, 1);
PIN_setOutputValue(pin_handle, D6, 0); // ADC_CS LOW
ADC_DAC_transaction.count = length;
ADC_DAC_transaction.txBuf = spi_txbuf;
ADC_DAC_transaction.rxBuf = spi_rxbuf;
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
PIN_setOutputValue(pin_handle, D6, 1); // ADC_CS HOGH
update_latch_status (ADC_CS, 1);
// PIN15_setOutputValue(ADC_CS, 1); // ADC_CS HIGH
PIN_setOutputValue(pin_handle, AD_CS, 1); // CS_ADC
}
static void CAL_LED_SPI(uint8_t length, uint16_t *spi_txbuf, uint16_t *spi_rxbuf) {
LED_transaction.count = length;
LED_transaction.txBuf = spi_txbuf;
LED_transaction.rxBuf = spi_rxbuf;
SPI_transfer(spiHandle0, &LED_transaction);
}
#ifdef ELITE_VERSION_EIS
//define SPI command
#define SPICMD_SETADDR 0x20
#define SPICMD_WRITEREG 0x2D
#define SPICMD_READREG 0x6D
//define REG
#define LPDACCON0 0x2128
#define LPDACSW0 0x2124
#define LPDACDAT0 0x2120
#define LPREFBUFCON 0x2050
#define SWMUX 0x235C
#define LPTIASW0 0x20E4
#define SWCON 0x200C
#define HSDACCON 0x2010
#define HSDACDAT 0x2048
#define LPTIACON0 0x20EC
#define HSTIACON 0x20FC
#define AFECON 0x2000
#define DSWFULLCON 0x2150
#define NSWFULLCON 0x2154
#define PSWFULLCON 0x2158
#define TSWFULLCON 0x215C
#define WGFCW 0x2030
#define WGPHASE 0x2034
#define WGOFFSET 0x2038
#define WGAMPLITUDE 0x203C
#define WGCON 0x2014
#define DE0RESCON 0x20F8
#define ADCCON 0x21A8
#define DFTCON 0x20D0
#define ADCFILTERCON 0x2044
static void select_REG(uint16_t addr){
PIN_setOutputValue(pin_handle, AD_CS, 0);
// CPUdelay(16000);
spi_DACtxbuf[0] = SPICMD_SETADDR;
spi_DACtxbuf[1] = (uint8_t)((addr & 0xFF00) >> 8);
spi_DACtxbuf[2] = (uint8_t)(addr & 0x00FF);
ADC_DAC_transaction.count = 3;
ADC_DAC_transaction.txBuf = spi_DACtxbuf;
ADC_DAC_transaction.rxBuf = spi_rxbuf;
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
// CPUdelay(16000);
PIN_setOutputValue(pin_handle, AD_CS, 1);
}
static void w16_REG(uint16_t data){
PIN_setOutputValue(pin_handle, AD_CS, 0);
spi_DACtxbuf[0] = SPICMD_WRITEREG;
spi_DACtxbuf[1] = (uint8_t)((data & 0xFF00) >> 8);
spi_DACtxbuf[2] = (uint8_t)(data & 0x00FF);
ADC_DAC_transaction.count = 3;
ADC_DAC_transaction.txBuf = spi_DACtxbuf;
ADC_DAC_transaction.rxBuf = spi_rxbuf;
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
PIN_setOutputValue(pin_handle, AD_CS, 1);
}
static void r16_REG(){
PIN_setOutputValue(pin_handle, AD_CS, 0);
spi_DACtxbuf[0] = SPICMD_READREG;
spi_DACtxbuf[1] = 0x00;
spi_DACtxbuf[2] = 0x00;
spi_DACtxbuf[3] = 0x00;
ADC_DAC_transaction.count = 4;
ADC_DAC_transaction.txBuf = spi_DACtxbuf;
ADC_DAC_transaction.rxBuf = spi_rxbuf;
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
PIN_setOutputValue(pin_handle, AD_CS, 1);
}
static void w32_REG(uint32_t data){
PIN_setOutputValue(pin_handle, AD_CS, 0);
spi_DACtxbuf[0] = SPICMD_WRITEREG;
spi_DACtxbuf[1] = (uint8_t)((data & 0xFF000000) >> 24);
spi_DACtxbuf[2] = (uint8_t)((data & 0x00FF0000) >> 16);
spi_DACtxbuf[3] = (uint8_t)((data & 0x0000FF00) >> 8);
spi_DACtxbuf[4] = (uint8_t)(data & 0x000000FF);
ADC_DAC_transaction.count = 5;
ADC_DAC_transaction.txBuf = spi_DACtxbuf;
ADC_DAC_transaction.rxBuf = spi_rxbuf;
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
PIN_setOutputValue(pin_handle, AD_CS, 1);
}
static void r32_REG(){
PIN_setOutputValue(pin_handle, AD_CS, 0);
spi_DACtxbuf[0] = SPICMD_READREG;
spi_DACtxbuf[1] = 0x00;
spi_DACtxbuf[2] = 0x00;
spi_DACtxbuf[3] = 0x00;
spi_DACtxbuf[4] = 0x00;
spi_DACtxbuf[5] = 0x00;
ADC_DAC_transaction.count = 6;
ADC_DAC_transaction.txBuf = spi_DACtxbuf;
ADC_DAC_transaction.rxBuf = spi_rxbuf;
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
PIN_setOutputValue(pin_handle, AD_CS, 1);
}
static void AD5940_init(){
PIN_setOutputValue(pin_handle, AD_reset, 0);
PIN_setOutputValue(pin_handle, AD_reset, 1);
select_REG(0x0908);//initiation
w16_REG(0x02C9);
select_REG(0x0C08);
w16_REG(0x206C);
select_REG(0x21F0);
w16_REG(0x0010);
select_REG(0x0410);
w16_REG(0x02C9);
select_REG(0x0A28);
w16_REG(0x0009);
select_REG(0x238C);
w16_REG(0x0104);
select_REG(0x0A04);
w16_REG(0x4859);
select_REG(0x0A04);
w16_REG(0xF27B);
select_REG(0x0A00);
w16_REG(0x8009);
select_REG(0x0A04);
w16_REG(0x4859);
select_REG(0x22F0);
w16_REG(0x0000);
select_REG(SWCON); //200C
w32_REG(0x402B5);
select_REG(HSDACCON); //2010 //ac gain
w32_REG(0x001E);
select_REG(WGFCW); //2030
w32_REG(0x340000);
select_REG(WGCON); //2014
w32_REG(0x4); //AC on/off; 0x0:DC 0x4:AC 0x5:trapezoid
select_REG(LPDACCON0); //2128 //DC on
w32_REG(0b0000001);
select_REG(LPDACSW0); //2124 //operation
w32_REG(0b101011);
select_REG(LPDACDAT0); //2120 //output Vout
w32_REG(0x00000);
// select_REG(HSTIACON); //20FC //SE0's gain
// w32_REG(0x0);
select_REG(DE0RESCON); //20F8 //DE0's gain
w32_REG(0x68);
select_REG(ADCCON); //21A8
w32_REG(0x101);
select_REG(DFTCON); //20D0
w32_REG(0x00C1);
select_REG(ADCFILTERCON); //2044
w32_REG(0x00D0);
select_REG(AFECON); //2000
w32_REG(0x30CFC0);
// w32_REG(0b1100011100111111000000);
}
static void EIS_LPDAC_SPI(){
// uint32_t con = 0b00001;//12 bit DAC
// uint32_t sw = 0b01010;//test mode
// uint32_t volt = 0;//2.4v
// uint32_t buf = 0;//LP reference
// uint32_t cm = 0;//common mode disabled
// select_REG(LPDACCON0);
// w32_REG(con);
// select_REG(LPDACSW0);
// w32_REG(sw);
// select_REG(LPDACDAT0);
// w32_REG(volt);
// select_REG(LPREFBUFCON);
// w32_REG(buf);
// select_REG(SWMUX);
// w32_REG(cm);
}
#endif
#endif // ELITE_SPI
@@ -1,7 +1,7 @@
#ifndef ELITE_WORK_DATA
#define ELITE_WORK_DATA
#define CLOCK_ONE_SECOND 10000
#define CLOCK_ONE_SECOND 00001
#include "EliteInstruction.h"
@@ -327,230 +327,6 @@ CVSCANMode * InitCVSCANMode(){
}
/*End of CONSTANT_VSCAN Mode*/
/* PULSE_MODE Mode(PULSE_MODE)*/
typedef struct _PULSEMode {
MEASURE;
int32_t _Vset;
int32_t _sti_v1;
int32_t _sti_v2;
int32_t _sti_v3;
int32_t _sti_v4;
int32_t _sti_v5;
int32_t _sti_v6;
int32_t _sti_v7;
int32_t _sti_t1;
int32_t _sti_t2;
int32_t _sti_t3;
int32_t _sti_t4;
int32_t _sti_t5;
int32_t _sti_t6;
int32_t _sti_t7;
int32_t _sti_t;
int32_t _sti_v; //output voltage now
int32_t _sti_t_flag; //Where's the time stage turn
uint16_t _sti_cy;
uint16_t _sti_lp;
//ledG
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;
int32_t _ledG_t;
uint8_t _ledG_sw;
int32_t _ledG_t_flag;
uint16_t _ledG_cy;
uint16_t _ledG_lp;
//ledR
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;
int32_t _ledR_t;
uint8_t _ledR_sw;
int32_t _ledR_t_flag;
uint16_t _ledR_cy;
uint16_t _ledR_lp;
//gas0
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;
int32_t _gas0_t;
uint8_t _gas0_sw;
int32_t _gas0_t_flag;
uint16_t _gas0_cy;
uint16_t _gas0_lp;
//gas1
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;
int32_t _gas1_t;
uint8_t _gas1_sw;
int32_t _gas1_t_flag;
uint16_t _gas1_cy;
uint16_t _gas1_lp;
} PULSEMode;
PULSEMode * InitPULSEMode() {
PULSEMode *ret = malloc(sizeof(PULSEMode));
ret->_measureCurrent = 0;
ret->_measureVin = 0;
ret->_measureVout = 0;
ret->_measureBat = 0;
ret->_VoViSwitch = INSTRUCTION.VoViSwitch;
ret->_Vset = 0;
ret->_sti_v1 = INSTRUCTION.sti_v1;
ret->_sti_v2 = INSTRUCTION.sti_v2;
ret->_sti_v3 = INSTRUCTION.sti_v3;
ret->_sti_v4 = INSTRUCTION.sti_v4;
ret->_sti_v5 = INSTRUCTION.sti_v5;
ret->_sti_v6 = INSTRUCTION.sti_v6;
ret->_sti_v7 = INSTRUCTION.sti_v7;
ret->_sti_t1 = INSTRUCTION.sti_t1;
ret->_sti_t2 = INSTRUCTION.sti_t2;
ret->_sti_t3 = INSTRUCTION.sti_t3;
ret->_sti_t4 = INSTRUCTION.sti_t4;
ret->_sti_t5 = INSTRUCTION.sti_t5;
ret->_sti_t6 = INSTRUCTION.sti_t6;
ret->_sti_t7 = INSTRUCTION.sti_t7;
ret->_sti_t = INSTRUCTION.sti_t1;
ret->_sti_v = INSTRUCTION.sti_v1;
ret->_sti_t_flag = 1;
ret->_sti_cy = INSTRUCTION.sti_cy;
ret->_sti_lp = INSTRUCTION.sti_loop;
//ledG
ret->_ledG_sw1 = INSTRUCTION.ledG_sw1;
ret->_ledG_sw2 = INSTRUCTION.ledG_sw2;
ret->_ledG_sw3 = INSTRUCTION.ledG_sw3;
ret->_ledG_sw4 = INSTRUCTION.ledG_sw4;
ret->_ledG_sw5 = INSTRUCTION.ledG_sw5;
ret->_ledG_sw6 = INSTRUCTION.ledG_sw6;
ret->_ledG_sw7 = INSTRUCTION.ledG_sw7;
ret->_ledG_t1 = INSTRUCTION.ledG_t1;
ret->_ledG_t2 = INSTRUCTION.ledG_t2;
ret->_ledG_t3 = INSTRUCTION.ledG_t3;
ret->_ledG_t4 = INSTRUCTION.ledG_t4;
ret->_ledG_t5 = INSTRUCTION.ledG_t5;
ret->_ledG_t6 = INSTRUCTION.ledG_t6;
ret->_ledG_t7 = INSTRUCTION.ledG_t7;
ret->_ledG_t = INSTRUCTION.ledG_t1;
ret->_ledG_sw = INSTRUCTION.ledG_sw1;
ret->_ledG_t_flag = 1;
ret->_ledG_cy = INSTRUCTION.ledG_cy;
ret->_ledG_lp = INSTRUCTION.ledG_loop;
//ledR
ret->_ledR_sw1 = INSTRUCTION.ledR_sw1;
ret->_ledR_sw2 = INSTRUCTION.ledR_sw2;
ret->_ledR_sw3 = INSTRUCTION.ledR_sw3;
ret->_ledR_sw4 = INSTRUCTION.ledR_sw4;
ret->_ledR_sw5 = INSTRUCTION.ledR_sw5;
ret->_ledR_sw6 = INSTRUCTION.ledR_sw6;
ret->_ledR_sw7 = INSTRUCTION.ledR_sw7;
ret->_ledR_t1 = INSTRUCTION.ledR_t1;
ret->_ledR_t2 = INSTRUCTION.ledR_t2;
ret->_ledR_t3 = INSTRUCTION.ledR_t3;
ret->_ledR_t4 = INSTRUCTION.ledR_t4;
ret->_ledR_t5 = INSTRUCTION.ledR_t5;
ret->_ledR_t6 = INSTRUCTION.ledR_t6;
ret->_ledR_t7 = INSTRUCTION.ledR_t7;
ret->_ledR_t = INSTRUCTION.ledR_t1;
ret->_ledR_sw = INSTRUCTION.ledR_sw1;
ret->_ledR_t_flag = 1;
ret->_ledR_cy = INSTRUCTION.ledR_cy;
ret->_ledR_lp = INSTRUCTION.ledR_loop;
//gas0
ret->_gas0_sw1 = INSTRUCTION.gas0_sw1;
ret->_gas0_sw2 = INSTRUCTION.gas0_sw2;
ret->_gas0_sw3 = INSTRUCTION.gas0_sw3;
ret->_gas0_sw4 = INSTRUCTION.gas0_sw4;
ret->_gas0_sw5 = INSTRUCTION.gas0_sw5;
ret->_gas0_sw6 = INSTRUCTION.gas0_sw6;
ret->_gas0_sw7 = INSTRUCTION.gas0_sw7;
ret->_gas0_t1 = INSTRUCTION.gas0_t1;
ret->_gas0_t2 = INSTRUCTION.gas0_t2;
ret->_gas0_t3 = INSTRUCTION.gas0_t3;
ret->_gas0_t4 = INSTRUCTION.gas0_t4;
ret->_gas0_t5 = INSTRUCTION.gas0_t5;
ret->_gas0_t6 = INSTRUCTION.gas0_t6;
ret->_gas0_t7 = INSTRUCTION.gas0_t7;
ret->_gas0_t = INSTRUCTION.gas0_t1;
ret->_gas0_sw = INSTRUCTION.gas0_sw1;
ret->_gas0_t_flag = 1;
ret->_gas0_cy = INSTRUCTION.gas0_cy;
ret->_gas0_lp = INSTRUCTION.gas0_loop;
//gas1
ret->_gas1_sw1 = INSTRUCTION.gas1_sw1;
ret->_gas1_sw2 = INSTRUCTION.gas1_sw2;
ret->_gas1_sw3 = INSTRUCTION.gas1_sw3;
ret->_gas1_sw4 = INSTRUCTION.gas1_sw4;
ret->_gas1_sw5 = INSTRUCTION.gas1_sw5;
ret->_gas1_sw6 = INSTRUCTION.gas1_sw6;
ret->_gas1_sw7 = INSTRUCTION.gas1_sw7;
ret->_gas1_t1 = INSTRUCTION.gas1_t1;
ret->_gas1_t2 = INSTRUCTION.gas1_t2;
ret->_gas1_t3 = INSTRUCTION.gas1_t3;
ret->_gas1_t4 = INSTRUCTION.gas1_t4;
ret->_gas1_t5 = INSTRUCTION.gas1_t5;
ret->_gas1_t6 = INSTRUCTION.gas1_t6;
ret->_gas1_t7 = INSTRUCTION.gas1_t7;
ret->_gas1_t = INSTRUCTION.gas1_t1;
ret->_gas1_sw = INSTRUCTION.gas1_sw1;
ret->_gas1_t_flag = 1;
ret->_gas1_cy = INSTRUCTION.gas1_cy;
ret->_gas1_lp = INSTRUCTION.gas1_loop;
return ret;
}
/*End of PULSE_MODE Mode*/
/* Cycle CC Mode */
typedef struct _CCCMode{
int32_t _measureCurrent;
@@ -647,7 +423,6 @@ typedef union _WorkMode{
LSVMode *LSV;
CVSCANMode *CVSCAN;
PSMode *PS;
PULSEMode *PULSE;
// CCCMode *CCC;
}WorkMode;
@@ -689,9 +464,6 @@ void InitWorkMode(WorkMode *WM){
case CONSTANT_VSCAN:
WM->CVSCAN = InitCVSCANMode();
break;
case PULSE_MODE:
WM->PULSE = InitPULSEMode();
break;
// case CYCLE_CONSTANT_CURRENT:
// WM->CCC = InitCCCMode();
// break;
@@ -764,12 +536,6 @@ void FreeWorkMode(WorkMode *WM){
WM->CVSCAN = NULL;
}
break;
case PULSE_MODE:
if(WM->PULSE != NULL){
free(WM->PULSE);
WM->PULSE = NULL;
}
break;
// case CYCLE_CONSTANT_CURRENT:
// if(WM->CCC != NULL){
// free(WM->CCC);
@@ -8,112 +8,40 @@
/* SPI Board */
#define Board_SPI0_MISO PIN_UNASSIGNED
#define Board_SPI0_MOSI D1
#define Board_SPI0_CLK D0
#define Board_SPI0_MOSI IOID_4
#define Board_SPI0_CLK IOID_3
#define Board_SPI0_CS PIN_UNASSIGNED
#define Board_SPI1_MISO IOID_1
#define Board_SPI1_MOSI D3
#define Board_SPI1_CLK D2
#define Board_SPI1_MOSI IOID_6
#define Board_SPI1_CLK IOID_5
#define Board_SPI1_CS PIN_UNASSIGNED
#define D0 IOID_3
#define D1 IOID_4
#define D2 IOID_5
#define D3 IOID_6
#define D4 IOID_7
#define D5 IOID_8
#define D6 IOID_9
#define D7 IOID_10
#define AD_CS IOID_10
#define LOAD0 IOID_13
#define LOAD1 IOID_12
#define LOAD2 IOID_11
//#define SD_MISO IOID_11
//#define SD_CS IOID_8
//#define SD_CLK IOID_7
//#define SD_MOSI IOID_13
#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
#define MEM_CS LOAD0, D5
#define Turnon_I_MID LOAD2, D0
#define Turnon_I_SMALL LOAD2, D4
#define Turnon_I_LARGE LOAD2, D1
#define Turnon_V_SMALL LOAD2, D2
#define Turnon_V_MID LOAD2, D3
#define Turon_VOUT_SMALL LOAD2, D7
//#define Turnon10K Turnon_I_MID
//#define Turnon200R Turnon_I_LARGE
/* I2C */
#ifdef ELITE_VERSION_1_4
#define Board_I2C0_SCL0 PIN_UNASSIGNED
#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 enable_5v IOID_9
#define AD_reset IOID_13
PIN_Handle pin_handle;
static PIN_State ZM_rst;
const PIN_Config BLE_IO[] = {
// D0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL,
// 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,
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,
enable_5v | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,// 5V_enable
AD_reset | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
switch_on | PIN_INPUT_EN | PIN_PULLDOWN,
AD_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,
PIN_TERMINATE
};
static void add_elite_pin() {
// PIN_Status elite15_status;
PIN_add(pin_handle,
D0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL);
PIN_add(pin_handle,
D1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL);
PIN_add(pin_handle,
D2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL);
PIN_add(pin_handle,
D3 | 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);
}
/*!
@@ -231,8 +159,6 @@ const I2CCC26XX_HWAttrsV1 i2cCC26xxHWAttrs[CC2650_MA_I2CCOUNT] = {
.intNum = INT_I2C_IRQ,
.intPriority = ~0,
.swiPriority = 0,
.sdaPin = Board_I2C0_SDA0,
.sclPin = Board_I2C0_SCL0,
}
};
@@ -85,7 +85,7 @@ static void measureBat(){
uint16_t bat = ((uint16_t)(NotifyVoltBat[2]) << 8 & 0xFF00 ) |
((uint16_t)(NotifyVoltBat[3]) & 0x00FF);
if( bat < 768 && bat > 20){
PIN15_setOutputValue(enable_5v, 0);
PIN_setOutputValue(pin_handle, enable_5v, 0);
}
}
@@ -39,13 +39,16 @@
#define ADC_TEST 0x91
#define CALI_DAC_MODE 0x93
#define CALI_ADC_MODE 0x92
#define PULSE_MODE 0x94
// CIS (control instruction)
#define CIS_VERSION 0x40
#define CIS_VOLT 0x10
#define CIS_LED_TEST 0x70
#define CTL_WRT 0x20
#define CTL_RD 0x21
#define CTL_RD_DFTR 0x78
#define CTL_RD_DFTI 0x7C
#define CTL_WRT_WGAMPL 0x3C
// mode parameter
#define STEP_TO_VSETRATE(step) step2VsetRate(step)
#define VMAX(v1,v2) ((v1 >= v2) ? v1 : v2)
@@ -56,21 +59,6 @@
#define ReadADCVolt(x) ((x==0)? ReadADCVout(spi_ADC_rxbuf) : ReadADCVin(spi_ADC_rxbuf))
#define PARA_1 0x01
#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
//Elite LED
#define COLOR_BLACK 0x00
@@ -96,6 +84,5 @@
#define WORKING 0x04
#define POST_WORK 0x05
#define MEGA_15V 41406
#define VALUE_ZERO_TO_ONE(_v) (_v == 0) ? 1 : _v
#endif
@@ -62,8 +62,7 @@ static void DACenable(WorkMode *WorkModeData, int32_t VoltData ,uint8_t afterRea
case VT_CURVE:
case CYCLIC_VOLTAMMETRY:
case LINEAR_SWEEP_VOLTAMMETRY:
case CONSTANT_VSCAN:
case PULSE_MODE:{
case CONSTANT_VSCAN:{
break;
}
default:{
@@ -83,8 +82,7 @@ static void DACenable(WorkMode *WorkModeData, int32_t VoltData ,uint8_t afterRea
}
case IT_CURVE:
case VT_CURVE:
case CONSTANT_CURRENT:
case PULSE_MODE:{
case CONSTANT_CURRENT:{
break;
}
case CYCLIC_VOLTAMMETRY:{
@@ -144,10 +142,6 @@ static void CC_Plot(WorkMode *WorkModeData){
#define CURRENT_MODE WorkModeData->CVSCAN
break;
}
case PULSE_MODE:{
#define CURRENT_MODE WorkModeData->PULSE
break;
}
default: {
break;
}
@@ -285,10 +279,6 @@ static void IT_Plot(WorkMode *WorkModeData) {
#define CURRENT_MODE WorkModeData->CVSCAN
break;
}
case PULSE_MODE:{
#define CURRENT_MODE WorkModeData->PULSE
break;
}
default: {
break;
}
@@ -367,10 +357,6 @@ static void VT_Plot(WorkMode *WorkModeData) {
#define CURRENT_MODE WorkModeData->CVSCAN
break;
}
case PULSE_MODE:{
#define CURRENT_MODE WorkModeData->PULSE
break;
}
default: {
break;
}
@@ -454,10 +440,6 @@ static void readIin(WorkMode *WorkModeData){
#define TEMP_MODE WorkModeData->CVSCAN
break;
}
case PULSE_MODE:{
#define TEMP_MODE WorkModeData->PULSE
break;
}
default: {
break;
}
@@ -465,12 +447,12 @@ static void readIin(WorkMode *WorkModeData){
if(INSTRUCTION.AutoGainEnable){
TEMP_MODE->_measureCurrent = AutoGainReadIin(spi_ADC_rxbuf);
AutoGainChangeIin(TEMP_MODE->_measureCurrent);
// AutoGainChangeIin(TEMP_MODE->_measureCurrent);
}else{
ReadADCIin(spi_ADC_rxbuf);
TEMP_MODE->_measureCurrent = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
if(lastIinADCGainLevel != INSTRUCTION.ADCGainLevel){
IinADCGainControl(INSTRUCTION.ADCGainLevel);
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
record_flag = false;
}
}
@@ -515,10 +497,6 @@ static int32_t readVinVout(WorkMode *WorkModeData){
#define TEMP_MODE WorkModeData->CVSCAN
break;
}
case PULSE_MODE:{
#define TEMP_MODE WorkModeData->PULSE
break;
}
default: {
break;
}
@@ -529,12 +507,12 @@ static int32_t readVinVout(WorkMode *WorkModeData){
if(TEMP_MODE->_VoViSwitch == 0x01 || TEMP_MODE->_VoViSwitch == 0x02){
if(INSTRUCTION.VinAutoGainEnable){
TEMP_MODE->_measureVin = AutoGainReadVin(spi_ADC_rxbuf);
AutoGainChangeVin(TEMP_MODE->_measureVin);
// AutoGainChangeVin(TEMP_MODE->_measureVin);
}else{
ReadADCVolt(TEMP_MODE->_VoViSwitch);
TEMP_MODE->_measureVin = DecodeADCValue(INSTRUCTION.VinADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
if(lastVinADCGainLevel != INSTRUCTION.VinADCGainLevel){
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
// VinADCGainControl(INSTRUCTION.VinADCGainLevel);
record_flag = false;
}
@@ -587,10 +565,6 @@ static void cali_IT_plot(WorkMode *WorkModeData) {
#define CURRENT_MODE WorkModeData->CVSCAN
break;
}
case PULSE_MODE:{
#define CURRENT_MODE WorkModeData->PULSE
break;
}
default: {
#define CURRENT_MODE WorkModeData->VT
break;
@@ -598,11 +572,8 @@ static void cali_IT_plot(WorkMode *WorkModeData) {
}
static uint8_t ADCSwitch = 0;
int32_t ADCValueTemp = 0;
static int32_t ADCValueSUM = 0;
int32_t ADCValueAVG = 0;
int16_t ADCValueAVG_RAW = 0;
static uint16_t cali_count_max = 1000;
if(ADCSwitch == 0){ /**read Iin(buffer)**/
if(INSTRUCTION.AutoGainEnable){
@@ -611,15 +582,10 @@ static void cali_IT_plot(WorkMode *WorkModeData) {
ReadADCIin(spi_ADC_rxbuf);
CURRENT_MODE->_measureCurrent = (int32_t) (spi_ADC_rxbuf[0] << 8) | (int32_t) (spi_ADC_rxbuf[1]);
if(lastIinADCGainLevel != INSTRUCTION.ADCGainLevel){
IinADCGainControl(INSTRUCTION.ADCGainLevel);
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
record_flag = false;
}
}
if(INSTRUCTION.ADCGainLevel == 0) {
cali_count_max = 5000;
} else {
cali_count_max = 1000;
}
if(record_flag == false){
static int recordCount = 0;
@@ -630,7 +596,7 @@ static void cali_IT_plot(WorkMode *WorkModeData) {
}
}else{
static uint16_t cali_count = 0;
if(cali_count >= cali_count_max){
if(cali_count >= 1000){
ADCValueAVG = ADCValueSUM / cali_count;
InputNotify(NOTIFY_CURRENT, ADCValueAVG);
@@ -709,10 +675,6 @@ static void cali_VT_plot(WorkMode *WorkModeData) {
#define CURRENT_MODE WorkModeData->CVSCAN
break;
}
case PULSE_MODE:{
#define CURRENT_MODE WorkModeData->PULSE
break;
}
default: {
#define CURRENT_MODE WorkModeData->VT
break;
@@ -721,11 +683,8 @@ static void cali_VT_plot(WorkMode *WorkModeData) {
static uint8_t ADCSwitch = 0;
static int32_t VoltData;
int32_t ADCValueTemp = 0;
static int32_t ADCValueSUM = 0;
int32_t ADCValueAVG = 0;
int16_t ADCValueAVG_RAW = 0;
static uint16_t cali_count_max = 1000;
if(ADCSwitch == 0){ /**read Iin(buffer)**/
if(CURRENT_MODE->_VoViSwitch == 0x01 || CURRENT_MODE->_VoViSwitch == 0x02){
@@ -735,19 +694,13 @@ static void cali_VT_plot(WorkMode *WorkModeData) {
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
CURRENT_MODE->_measureVin = (int32_t) (spi_ADC_rxbuf[0] << 8) | (int32_t) (spi_ADC_rxbuf[1]);
if(lastVinADCGainLevel != INSTRUCTION.VinADCGainLevel){
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
// VinADCGainControl(INSTRUCTION.VinADCGainLevel);
record_flag = false;
}
}
VoltData = CURRENT_MODE->_measureVin;
}
if(INSTRUCTION.VinADCGainLevel == 0) {
cali_count_max = 5000;
} else {
cali_count_max = 1000;
}
// else if(CURRENT_MODE->_VoViSwitch == 0x00){
// ReadADCVolt(CURRENT_MODE->_VoViSwitch);
// CURRENT_MODE->_measureVout = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_DAC, spi_ADC_rxbuf);
@@ -763,7 +716,7 @@ static void cali_VT_plot(WorkMode *WorkModeData) {
}
}else{
static uint16_t cali_count = 0;
if(cali_count >= cali_count_max){
if(cali_count >= 1000){
ADCValueAVG = ADCValueSUM / cali_count;
InputNotify(NOTIFY_VOLT, ADCValueAVG);
@@ -3,10 +3,10 @@
#define VERSION_DATE
#define VERSION_DATE_YEAR 20
#define VERSION_DATE_MONTH 12
#define VERSION_DATE_DAY 11
#define VERSION_DATE_MONTH 9
#define VERSION_DATE_DAY 7
#define VERSION_DATE_HOUR 17
#define VERSION_DATE_MINUTE 20
#define VERSION_DATE_MINUTE 58
// this is NOT the version hash !!
// it's the last version hash
@@ -38,15 +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;
}
// PIN15_setOutputValue(MEGA_G_LED, 1);
}
static void ZM_update_instruction_callback(uint8_t ins_type, uint8_t chip_ID, uint8_t *ins);
@@ -55,30 +46,12 @@ 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);
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);
PIN_setOutputValue(pin_handle, AD_CS, 1); // AD_CS HIGH
InitEliteInstruction();
IinADCGainControl(INSTRUCTION.ADCGainLevel);
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
VoutGainControl(INSTRUCTION.VoutGainLevel);
elite_gptimer_open();
// PIN_registerIntCb(pin_handle, switch_on_callback);
// PIN_setInterrupt(pin_handle, switch_on | PIN_IRQ_POSEDGE);
elite_gptimer_open();
}
static void ZM_update_instruction_callback(uint8_t ins_type, uint8_t chip_ID, uint8_t *ins) {}
@@ -137,9 +110,8 @@ static void SimpleBLEPeripheral_performPeriodicTask(WorkMode *WorkModeData) {
EliteWorkReset = false;
batteryADC_flag = false;
record_flag = true;
VinADCGainControl(INSTRUCTION.VinADCGainLevel);
IinADCGainControl(INSTRUCTION.ADCGainLevel);
VoutGainControl(INSTRUCTION.VoutGainLevel);
// VinADCGainControl(INSTRUCTION.VinADCGainLevel);
// IinADCGainControl(INSTRUCTION.ADCGainLevel);
if( Ve1MatchVe2Mode() ){
if (INSTRUCTION.Ve1 == INSTRUCTION.Ve2) {
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.Ve1));
@@ -188,7 +160,7 @@ 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);
PIN_setOutputValue(pin_handle, enable_5v, 0);
}
//ADC counter
@@ -218,160 +190,18 @@ static void SimpleBLEPeripheral_performPeriodicTask(WorkMode *WorkModeData) {
}
// EliteDone();
}
else if (INSTRUCTION.eliteFxn == PULSE_MODE) {
/** Periodic Event **/
// Default working flow is vscan -> ADC read -> send notify
// We will need a flag to control vscan, ADC and notify
GPT.DeltaGptimerCounter = GPT.GptimerCounter - GPT.GptimerCounter0;
GPT.GptimerCounter0 = GPT.GptimerCounter;
if(EliteWorkReset){
InitEliteGPtimer();
EliteWorkReset = false;
batteryADC_flag = false;
record_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);
if (Ve1MatchVe2Mode()) {
if (INSTRUCTION.Ve1 == INSTRUCTION.Ve2) {
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.Ve1));
PeriodicEvent = false;
ModeLED(NO_EVENT);
}
} else if (INSTRUCTION.eliteFxn == PULSE_MODE) {
if(!megaStiEnable && !megaLedGEnable && !megaLedREnable && !megaGas0Enable && !megaGas1Enable){
PeriodicEvent = false;
ModeLED(NO_EVENT);
}
}
}
GPT.LeadTimeCounter = GPT.LeadTimeCounter + GPT.DeltaGptimerCounter;
if(leadTimeReset && GPT.LeadTimeCounter <= 2000){
vscanReset = true;
}else{
if(notifyFirst_flag){
GPT.NotifyCounter = INSTRUCTION.notifyRate - 20;
notifyFirst_flag = false;
}
vscanReset = false;
leadTimeReset = false;
}
//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));
//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);
}
}
// if(GPT.VscanRateCounter >= INSTRUCTION.VsetRate){
// if(GPT.VscanRateCounter >= INSTRUCTION.VsetRate * 2){
// GPT.GptimerMultiple = GPT.VscanRateCounter / INSTRUCTION.VsetRate;
// }else{
// GPT.GptimerMultiple = 1;
// }
// GPT.VscanRateCounter -= INSTRUCTION.VsetRate * GPT.GptimerMultiple; //To get right time
// vscan_flag = true;
// if(vscan_flag){
// EliteVscanControl(WorkModeData);
// vscan_flag = false;
// }
// }
//battery counter
GPT.BatteryADCCounter = GPT.BatteryADCCounter + GPT.DeltaGptimerCounter;
GPT.BatteryCheckCounter = GPT.BatteryCheckCounter + GPT.DeltaGptimerCounter;
if(GPT.BatteryCheckCounter >= 50000){
GPT.BatteryCheckCounter -= 50000; //To get right time
batteryCheck_flag = true;
}
uint16_t bat = ((uint16_t)(NotifyVoltBat[2]) << 8 & 0xFF00 ) | ((uint16_t)(NotifyVoltBat[3]) & 0x00FF);
if( bat < 768 && bat > 20){
// PIN15_setOutputValue(enable_5v, 0);
}
//ADC counter
GPT.SampleRateCounter = GPT.SampleRateCounter + GPT.DeltaGptimerCounter;
if(GPT.SampleRateCounter >= INSTRUCTION.sampleRate){
GPT.SampleRateCounter = 0; //To get right data, ADC must be delay 1.5ms
ADC_flag = true;
if(ADC_flag){
EliteADCControl(WorkModeData);
ADC_flag = false;
}
}
//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
notify_flag = true;
if(vscanReset){
notify_flag = false;
}
if(notify_flag && megaStiEnable){
InputNotify(NOTIFY_IMPEDANCE, Mega_Trig_receive);
SendNotify();
Mega_Trig_receive = false;
notify_flag = false;
}
}
// EliteDone();
}
else if(INSTRUCTION.eliteFxn == VOLT_OUTPUT){
}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);
PeriodicEvent = false;
}
else if(INSTRUCTION.eliteFxn == CALI_DAC_MODE){
}else if(INSTRUCTION.eliteFxn == CALI_DAC_MODE){
DAC_outputV(INSTRUCTION.VoltConstant); //UserCode -> DAC code -> DAC out
FreeWorkMode(WorkModeData);
PeriodicEvent = false;
}
else{
// InitFlag();
InitFlag();
}
}
@@ -422,10 +252,6 @@ static void EliteADCControl(WorkMode *WorkModeData) {
break;
}
case PULSE_MODE:{
CC_Plot(WorkModeData);
break;
}
default:{
break;
}
@@ -471,10 +297,6 @@ static void EliteVscanControl(WorkMode *WorkModeData) {
CVSCAN_Vscan(WorkModeData->CVSCAN);
break;
}
case PULSE_MODE:{
// PULSE_Vscan(WorkModeData->PULSE);
break;
}
default:{
break;
}
@@ -546,24 +546,22 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
// 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;
// init DAC, set output ~= 0 V
// DAC_outputV(25000);
elite_gptimer_start();
// Application main loops
GPT.GptimerCounter0 = GPT.GptimerCounter;
batteryADC_flag = false;
headstage_battery_volt();
// headstage_battery_volt();
headstage_init_device_info();
for (;;) {
@@ -617,12 +615,10 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
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
counter6994++;
} else if (counter6994 == CLOCK_ONE_SECOND/2) {
PIN15_setOutputValue(shutdown_6994, 1); // OFF = 1 => turn off 6994
counter6994++;
}
EliteKeyPress(key);
@@ -630,43 +626,29 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
// if(key != 0){ //detect Elite battery power when no periodic event
// measureBat();
// }
if(Free_Work_Mode){
FreeWorkMode(WorkModeData);
InitEliteInstruction();
Free_Work_Mode = false;
}
/* Megafly trigger */
// trig = PIN_getInputValue(MEGA_TRIG); // trigger: 1 -> 0
if (Mega_PeriodicEvent) {
Mega_PeriodicEvent = false;
PeriodicEvent = true;
} else {
}
// if(Free_Work_Mode){
// FreeWorkMode(WorkModeData);
// InitEliteInstruction();
//// IinADCGainControl(INSTRUCTION.ADCGainLevel);
// DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoutGainLevel, INSTRUCTION.VoltConstant));
//
// Free_Work_Mode = false;
// }
} 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);
InitPeriodicEvent = false;
}
// Perform periodic application task
SimpleBLEPeripheral_performPeriodicTask(WorkModeData);
key = PIN_getInputValue(switch_on);
EliteKeyPress(key); // onPress=> key = 0; 1.lighten LED 2.long press shut down 2650
}
// else { // if there is periodic event
// if(InitPeriodicEvent){
// InitWorkMode(WorkModeData);
// InitPeriodicEvent = false;
// }
//
// // Perform periodic application task
// SimpleBLEPeripheral_performPeriodicTask(WorkModeData);
// key = PIN_getInputValue(switch_on);
// EliteKeyPress(key); // onPress=> key = 0; 1.lighten LED 2.long press shut down 2650
// }
}
#ifdef FEATURE_OAD