Compare commits
143 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c94c382dae | |||
| 0a19abd0e8 | |||
| 284cfe6d05 | |||
| 3298b6226b | |||
| dfcaf2d908 | |||
| d517318a67 | |||
| d0aa520329 | |||
| 9a875b8459 | |||
| 73ac2f5c90 | |||
| efcb1132de | |||
| 7492ed161d | |||
| ae7ec2e5ce | |||
| 63fde4bdbc | |||
| 32ccb8838f | |||
| 5b6fd53830 | |||
| 86eef98b13 | |||
| 3fdbfcf39f | |||
| 847ea9f3c0 | |||
| 25bd5b5ebe | |||
| 335fe6a9a4 | |||
| 6a0480613c | |||
| 300fb9a44c | |||
| 4fac2aa380 | |||
| d2ab4c1fe8 | |||
| 6048e10ab7 | |||
| 6bd94e3f73 | |||
| fc302d4c75 | |||
| 26a35a1446 | |||
| 8f2eda7281 | |||
| e26a97a32f | |||
| 5bdb0b04da | |||
| 8f8407601e | |||
| 4c6dbcf98d | |||
| 20ccd5de56 | |||
| 3c3ad8ccc7 | |||
| 1030d6625b | |||
| 326f3eb6b6 | |||
| 9dd7228eb5 | |||
| 59ac6b9909 | |||
| e24ce8e5d5 | |||
| 8720300bfc | |||
| 23fc75a236 | |||
| 80c25267cb | |||
| 81d1aff615 | |||
| 3221fe6492 | |||
| 4ca7d5b681 | |||
| 49677aa5b1 | |||
| bbfef99a65 | |||
| 05f11fd147 | |||
| f0aedf786d | |||
| a12146a479 | |||
| 410bef2e23 | |||
| 17c6a506cb | |||
| 0b9c945aee | |||
| 53ef219d6e | |||
| a14b2480db | |||
| 89368d5352 | |||
| f7903a0a31 | |||
| 56f42d21c5 | |||
| 52a8baad08 | |||
| 7acdbf6e78 | |||
| 393394be6f | |||
| b7f305e378 | |||
| cad8a78164 | |||
| 0c4ebcac79 | |||
| e700657d5d | |||
| ea9fb92d53 | |||
| ba215c7ca9 | |||
| 564dc6e266 | |||
| 86a2e54694 | |||
| 358950bec0 | |||
| de2cb269b7 | |||
| 151e829973 | |||
| 19121b55a7 | |||
| 31f03582a3 | |||
| 0859f6da6d | |||
| 120b7086e5 | |||
| d393872d8c | |||
| 3ab9afdcd3 | |||
| 8812b4c103 | |||
| 4cccced7ac | |||
| 7b3d342be6 | |||
| 97409c88c3 | |||
| 1d675d9d78 | |||
| 1774a255d8 | |||
| 1863016b63 | |||
| 1e89a540a1 | |||
| 5daa67e054 | |||
| 05ce7f7f44 | |||
| 9391c700a1 | |||
| 16c4ecf9f2 | |||
| 7280f76fae | |||
| 3a5d40a5d9 | |||
| 40dd596fef | |||
| 56b240b101 | |||
| bf36103499 | |||
| 477144dc24 | |||
| 0aa45cfedc | |||
| 4691345831 | |||
| 8445f8c263 | |||
| 7176f91a3f | |||
| e37065ce91 | |||
| 2537b76256 | |||
| 59e275c997 | |||
| bfe61896e8 | |||
| 0ad8b13db2 | |||
| 3c8abc04a8 | |||
| a48cf75c90 | |||
| 4f7017d5b2 | |||
| 79f0d57161 | |||
| d76e8e6f3f | |||
| b6147c1fe5 | |||
| 4bbd92127a | |||
| 337c2aef8d | |||
| e943d22a5f | |||
| bceb8b9134 | |||
| 14adc8a768 | |||
| 7c44ad2272 | |||
| c8272dd455 | |||
| cb2aa2126b | |||
| f74a412611 | |||
| f0b92f8578 | |||
| e7cae7dc21 | |||
| 1c41bd7a45 | |||
| a671a4916d | |||
| 15ea1488c9 | |||
| f92dd743ef | |||
| eddbe3980a | |||
| b27df1489b | |||
| dc3f2ee046 | |||
| ba7f03daeb | |||
| 079500faff | |||
| ce0defe5e9 | |||
| 7b1bcd5147 | |||
| 787eb5dce1 | |||
| 9d73fab37e | |||
| 6a833aabee | |||
| e40d0896b8 | |||
| c265eb0118 | |||
| cead3b0b5c | |||
| 238c09befd | |||
| de1867d523 | |||
| 906e02e265 |
+1
-1
@@ -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 ?= ../../config/src
|
||||
GEN_SRC_DIR ?= ../../../../../ti/simplelink/ble_sdk_2_02_02_25/examples/cc2650em/simple_peripheral/ccs/config/src
|
||||
|
||||
ifeq (,$(wildcard $(GEN_SRC_DIR)))
|
||||
$(error "ERROR: GEN_SRC_DIR must be set to the directory containing the generated sources")
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
+9
-9
@@ -1,12 +1,12 @@
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
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_02_25_core/packages/
|
||||
vpath %.c C:/ti/xdctools_3_32_00_06_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_02_25_core/packages/
|
||||
XDC_ROOT = C:/ti/xdctools_3_32_00_06_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.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/
|
||||
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/
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
define RM
|
||||
$(if $(wildcard $1),$(DEL) $1,:)
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
+104
@@ -76,6 +76,11 @@ static void ADCGainControl(uint8_t ADCLevel){
|
||||
PIN_setOutputValue(pin_handle, Turnon10K, 0);
|
||||
PIN_setOutputValue(pin_handle, Turnon100R, 1);
|
||||
}
|
||||
else if(ADCLevel == 3){
|
||||
// ADC gain level = 0, auto gain (using 200R resister)
|
||||
PIN_setOutputValue(pin_handle, Turnon10K, 0);
|
||||
PIN_setOutputValue(pin_handle, Turnon100R, 0);
|
||||
}
|
||||
else{
|
||||
// default using 200R resister
|
||||
PIN_setOutputValue(pin_handle, Turnon10K, 0);
|
||||
@@ -121,4 +126,103 @@ static void ADCChannelSelect(uint8_t ADCChannel){
|
||||
}
|
||||
}
|
||||
|
||||
static void ReadVolt(uint8_t *buf){
|
||||
// Read data twice since the first data we get is previous data
|
||||
ADCChannelSelect(ADC_CH_VOLT);
|
||||
CPUdelay(10);
|
||||
ADC_read(buf);
|
||||
|
||||
ADCChannelSelect(ADC_CH_VOLT);
|
||||
CPUdelay(10);
|
||||
ADC_read(buf);
|
||||
}
|
||||
|
||||
static void ReadCurrent(uint8_t *buf){
|
||||
// Read data twice since the first data we get is previous data
|
||||
ADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
ADCChannelSelect(ADC_CH_CURRENT);
|
||||
CPUdelay(10);
|
||||
ADC_read(buf);
|
||||
|
||||
ADCChannelSelect(ADC_CH_CURRENT);
|
||||
CPUdelay(10);
|
||||
ADC_read(buf);
|
||||
}
|
||||
|
||||
// theoretical boundary <20, 10~500, >100 (uA)
|
||||
#define GAIN_SMALL_BOUNDARY 40000 // 40 uA = 40,000,000 pA
|
||||
#define GAIN_MID_BOUNDARY1 20000 // 20 uA = 20,000,000 pA
|
||||
#define GAIN_MID_BOUNDARY2 400000 // 400 uA = 400,000,000 pA
|
||||
#define GAIN_LARGE_BOUNDARY 200000 // 200 uA = 200,000 nA
|
||||
|
||||
static int32_t AutoGainReadCurrent(uint8_t *buf){
|
||||
int32_t Real_Current = 0;
|
||||
|
||||
if(INSTRUCTION.ADCGainLevel == GAIN_AUTO){
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200R;
|
||||
}
|
||||
|
||||
if(INSTRUCTION.ADCGainLevel == GAIN_200R){
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
|
||||
// switch to mid range current
|
||||
if(Real_Current < GAIN_LARGE_BOUNDARY && Real_Current > -1*GAIN_LARGE_BOUNDARY){
|
||||
// LED_color(DARKLED, 0x00, 0x0F, 0xFF);
|
||||
INSTRUCTION.ADCGainLevel = GAIN_10K;
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
|
||||
// switch to small range current
|
||||
if (Real_Current < GAIN_MID_BOUNDARY1 && Real_Current > -1*GAIN_MID_BOUNDARY1){
|
||||
// LED_color(DARKLED, 0x00, 0x00, 0xFF);
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200K;
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(INSTRUCTION.ADCGainLevel == GAIN_10K){
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
|
||||
// switch to large range current
|
||||
if(Real_Current > GAIN_MID_BOUNDARY2 || Real_Current < -1*GAIN_MID_BOUNDARY2){
|
||||
// LED_color(DARKLED, 0xFF, 0x0F, 0x0F);
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200R;
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
}
|
||||
|
||||
// switch to small range current
|
||||
else if (Real_Current < GAIN_MID_BOUNDARY1 && Real_Current > -1*GAIN_MID_BOUNDARY1){
|
||||
// LED_color(DARKLED, 0x00, 0x00, 0xFF);
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200K;
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
}
|
||||
}
|
||||
else if(INSTRUCTION.ADCGainLevel == GAIN_200K){
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
|
||||
// switch to mid range current
|
||||
if(Real_Current > GAIN_SMALL_BOUNDARY || Real_Current < -1*GAIN_SMALL_BOUNDARY){
|
||||
// LED_color(DARKLED, 0x00, 0x0F, 0xFF);
|
||||
INSTRUCTION.ADCGainLevel = GAIN_10K;
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
|
||||
// switch to large range current
|
||||
// if(Real_Current > GAIN_MID_BOUNDARY2 || Real_Current < -1*GAIN_MID_BOUNDARY2){
|
||||
// LED_color(DARKLED, 0xFF, 0x0F, 0x0F);
|
||||
// INSTRUCTION.ADCGainLevel = GAIN_200R;
|
||||
// ReadCurrent(spi_ADC_rxbuf);
|
||||
// Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
// }
|
||||
}
|
||||
}
|
||||
return Real_Current;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+104
-219
@@ -2,41 +2,47 @@
|
||||
#ifndef ELITECCMODE
|
||||
#define ELITECCMODE
|
||||
|
||||
#define CURRENT_LV_FOUR 4
|
||||
#define CURRENT_LV_THREE 3
|
||||
#define CURRENT_LV_TWO 2
|
||||
#define CC_ZERO_POINT 1500000
|
||||
#define MAX_DAC_UC 50000
|
||||
#define MIN_DAC_UC 0
|
||||
#define CURRENT_LV_ONE 1
|
||||
#define CURRENT_LV_ZERO 0
|
||||
|
||||
static void CCModeDACControl(int32_t IUC_Measure_Difference);
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* @struct Constant Current Code
|
||||
*
|
||||
* @brief A struct to handle CC mode command
|
||||
*/
|
||||
typedef struct _CURRENT_USER_CODE {
|
||||
/** current level range: 0-4 **/
|
||||
// current level = 0 => 0-499 nA => ADCGainLevel = 200K
|
||||
// current level = 1 => 500-999 nA => ADCGainLevel = 10K
|
||||
// current level = 2 => 0-499 uA => ADCGainLevel = 10K
|
||||
// current level = 3 => 500-999 uA => ADCGainLevel = 200R
|
||||
// current level = 4 => 0-499 mA => ADCGainLevel = 200R
|
||||
uint8_t lv;
|
||||
|
||||
/** current value **/
|
||||
// current value divide current level into 50000 pieces
|
||||
uint16_t value;
|
||||
// current value divide current level into 3,000,001 pieces
|
||||
// 1,500,000 is zero point
|
||||
int32_t value;
|
||||
|
||||
/** ADC level range: 0-2 **/
|
||||
// constant current value will decide ADC gain level
|
||||
// if |1500000 - value| > 10000 (+-100 uA) => lv = GAIN_200R
|
||||
// else if |1500000 - valule| > 1000 (+-10 uA) => lv = GAIN_10K
|
||||
// else lv = GAIN_200K
|
||||
uint8_t lv;
|
||||
|
||||
/* Vmax and Vmin */
|
||||
// Vmax protect battery charge
|
||||
// Vmin protect battery discharge
|
||||
// uint = mV
|
||||
uint16_t Vmax;
|
||||
uint16_t Vmin;
|
||||
|
||||
/** transform a current user code (IUC) to real current in nA **/
|
||||
int32_t (*_Transform2RealnA)(struct _CURRENT_USER_CODE *);
|
||||
|
||||
/** Measure Current **/
|
||||
int32_t _MeasureCurrent;
|
||||
|
||||
/** transform a current user code (IUC) to real current in pA **/
|
||||
// handle current lv 0~2
|
||||
int32_t (*_Transform2RealpA)(struct _CURRENT_USER_CODE *);
|
||||
|
||||
/** transform an IUC to real current in nA **/
|
||||
// handle current lv 3~4
|
||||
int32_t (*_Transform2RealnA)(struct _CURRENT_USER_CODE *);
|
||||
|
||||
/** MeasureCurrent operation **/
|
||||
void (*SetMeasureCurrent)(struct _CURRENT_USER_CODE *, int32_t);
|
||||
|
||||
@@ -45,174 +51,109 @@ typedef struct _CURRENT_USER_CODE {
|
||||
|
||||
//static CURRENT_USER_CODE CurrentUserCode;
|
||||
|
||||
static int32_t CCModeReadCurrent(CURRENT_USER_CODE *CurrentUserCode){
|
||||
int32_t Real_Current = 0;
|
||||
CCModeReset = 0; // This flag will control DAC working
|
||||
static int32_t CCModeReadCurrent(void *WorkModeData){
|
||||
|
||||
int32_t Real_Current = 0;
|
||||
CURRENT_USER_CODE *CurrentUserCode = WorkModeData;
|
||||
// CurrentUserCode = WorkModeData;
|
||||
|
||||
CCModeDACEnable = 1; // This flag will control DAC working
|
||||
|
||||
// set current value and ADC gain level
|
||||
CCCurrent2IUC(CurrentUserCode);
|
||||
|
||||
// if(CurrentUserCode->lv == CURRENT_LV_FOUR){
|
||||
// Real_Current = CurrentUserCode->_Transform2RealnA(CurrentUserCode);
|
||||
// }
|
||||
// else{
|
||||
// Real_Current = CurrentUserCode->_Transform2RealpA(CurrentUserCode);
|
||||
// }
|
||||
|
||||
// set ADC gain according to constant current value
|
||||
SetCCModeGain(CurrentUserCode);
|
||||
INSTRUCTION.ADCGainLevel = CurrentUserCode->lv;
|
||||
|
||||
// read ADC current
|
||||
ADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
ADCChannelSelect(ADC_CH_CURRENT);
|
||||
CPUdelay(10);
|
||||
ADC_read(spi_ADC_rxbuf);
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
|
||||
// decode ADC value and put it into notify buffer
|
||||
Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
Real_Current = 8787877;
|
||||
|
||||
CurrentUserCode->SetMeasureCurrent(CurrentUserCode, Real_Current);
|
||||
|
||||
return Real_Current;
|
||||
}
|
||||
|
||||
static int32_t CCModeVoltOut(CURRENT_USER_CODE *CurrentUserCode){
|
||||
int32_t MeasureCurrent = 0;
|
||||
static int32_t CCModeVoltOut(void *WorkModeData){
|
||||
int32_t MeasureCurrent = 0, IUCCurrent = 0;
|
||||
CURRENT_USER_CODE *CurrentUserCode = WorkModeData;
|
||||
|
||||
if(CCModeReset){
|
||||
if(!CCModeDACEnable){
|
||||
// DAC should not work now
|
||||
return 0;
|
||||
}
|
||||
|
||||
// MeasureCurrent = CurrentUserCode->GetMeasureCurrent(CurrentUserCode);
|
||||
IUCCurrent = CurrentUserCode->_Transform2RealnA(CurrentUserCode);
|
||||
if(CurrentUserCode->lv == GAIN_200K || CurrentUserCode->lv == GAIN_10K ){
|
||||
MeasureCurrent = CurrentUserCode->GetMeasureCurrent(CurrentUserCode);
|
||||
CCModeDACControl(IUCCurrent - MeasureCurrent);
|
||||
}
|
||||
else{
|
||||
MeasureCurrent = CurrentUserCode->GetMeasureCurrent(CurrentUserCode);
|
||||
CCModeDACControl(IUCCurrent - MeasureCurrent);
|
||||
}
|
||||
// NotifyCurrent[0] = (uint8_t) (IUCCurrent >> 24);
|
||||
// NotifyCurrent[1] = (uint8_t) ((IUCCurrent & 0x00FF0000) >> 16);
|
||||
// NotifyCurrent[2] = (uint8_t) ((IUCCurrent & 0x0000FF00) >> 8);
|
||||
// NotifyCurrent[3] = (uint8_t) (IUCCurrent & 0x000000FF);
|
||||
//
|
||||
// NotifyVolt[0] = (uint8_t) (MeasureCurrent >> 24);
|
||||
// NotifyVolt[1] = (uint8_t) ((MeasureCurrent & 0x00FF0000) >> 16);
|
||||
// NotifyVolt[2] = (uint8_t) ((MeasureCurrent & 0x0000FF00) >> 8);
|
||||
// NotifyVolt[3] = (uint8_t) (MeasureCurrent & 0x000000FF);
|
||||
|
||||
NotifyCurrent[0] = (uint8_t) (MeasureCurrent >> 24);
|
||||
NotifyCurrent[1] = (uint8_t) ((MeasureCurrent & 0x00FF0000) >> 16);
|
||||
NotifyCurrent[2] = (uint8_t) ((MeasureCurrent & 0x0000FF00) >> 8);
|
||||
NotifyCurrent[3] = (uint8_t) (MeasureCurrent & 0x000000FF);
|
||||
|
||||
NotifyVolt[0] = (uint8_t) (MeasureCurrent >> 24);
|
||||
NotifyVolt[1] = (uint8_t) ((MeasureCurrent & 0x00FF0000) >> 16);
|
||||
NotifyVolt[2] = (uint8_t) ((MeasureCurrent & 0x0000FF00) >> 8);
|
||||
NotifyVolt[3] = (uint8_t) (MeasureCurrent & 0x000000FF);
|
||||
|
||||
// INSTRUCTION.VoltConstant = 24999 + 500;
|
||||
// DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant));
|
||||
DACCode2Real2Notify(Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant));
|
||||
CCModeDACEnable = 0;
|
||||
return MeasureCurrent;
|
||||
}
|
||||
|
||||
static void SetCCModeGain(CURRENT_USER_CODE *CurrentUserCode){
|
||||
switch(CurrentUserCode->lv){
|
||||
case CURRENT_LV_FOUR:{
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200R;
|
||||
break;
|
||||
}
|
||||
case CURRENT_LV_THREE:{
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200R;
|
||||
break;
|
||||
}
|
||||
case CURRENT_LV_TWO:{
|
||||
INSTRUCTION.ADCGainLevel = GAIN_10K;
|
||||
break;
|
||||
}
|
||||
case CURRENT_LV_ONE:{
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200K;
|
||||
break;
|
||||
}
|
||||
case CURRENT_LV_ZERO:{
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200K;
|
||||
break;
|
||||
}
|
||||
default :{
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200R;
|
||||
break;
|
||||
}
|
||||
static void CCModeDACControl(int32_t IUC_Measure_Difference){
|
||||
if(IUC_Measure_Difference > 100000 || IUC_Measure_Difference < -100000){
|
||||
INSTRUCTION.VoltConstant = INSTRUCTION.VoltConstant + IUC_Measure_Difference/1e4;
|
||||
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant));
|
||||
}
|
||||
else if(IUC_Measure_Difference > 1000 || IUC_Measure_Difference < -1000){
|
||||
INSTRUCTION.VoltConstant = INSTRUCTION.VoltConstant + IUC_Measure_Difference/1e3;
|
||||
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant));
|
||||
}
|
||||
else if(IUC_Measure_Difference > 0){
|
||||
INSTRUCTION.VoltConstant = INSTRUCTION.VoltConstant + 1;
|
||||
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant));
|
||||
}
|
||||
else if(IUC_Measure_Difference < 0){
|
||||
INSTRUCTION.VoltConstant = INSTRUCTION.VoltConstant - 1;
|
||||
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant));
|
||||
}
|
||||
}
|
||||
|
||||
/* Transform setting CC into IUC
|
||||
*
|
||||
* User code in CC mode : 0 ~ 3000000
|
||||
* Real current value : -15.00000 ~ 15.00000 mA
|
||||
* => user code = 1500000 mapping to 0.00000 mA
|
||||
*/
|
||||
static void CCCurrent2IUC(CURRENT_USER_CODE *CurrentUserCode){
|
||||
if (INSTRUCTION.CurrentLV == CURRENT_LV_MA){
|
||||
// largest current ( 0~500 mA)
|
||||
CurrentUserCode->lv = CURRENT_LV_FOUR;
|
||||
CurrentUserCode->value = (uint16_t) (INSTRUCTION.ConstantCurrent);
|
||||
int32_t CurrentValue = 0;
|
||||
|
||||
CurrentUserCode->value = INSTRUCTION.ConstantCurrent;
|
||||
CurrentValue = CurrentUserCode->value - CC_ZERO_POINT;
|
||||
|
||||
/* set ADC level */
|
||||
// largest current
|
||||
if (CurrentValue > 10000 || CurrentValue < -10000){
|
||||
CurrentUserCode->lv = GAIN_200R;
|
||||
}
|
||||
else if (INSTRUCTION.CurrentLV == CURRENT_LV_UA){
|
||||
if(INSTRUCTION.ConstantCurrent >= 50000){
|
||||
// mid range current ( 500 uA ~ 999 uA)
|
||||
CurrentUserCode->lv = CURRENT_LV_THREE;
|
||||
CurrentUserCode->value = (uint16_t) (INSTRUCTION.ConstantCurrent - 50000);
|
||||
}
|
||||
else{
|
||||
// mid range current ( 0 uA ~ 499 uA)
|
||||
CurrentUserCode->lv = CURRENT_LV_TWO;
|
||||
CurrentUserCode->value = (uint16_t) (INSTRUCTION.ConstantCurrent);
|
||||
}
|
||||
// mid range current
|
||||
else if (CurrentValue > 1000 || CurrentValue < -1000){
|
||||
CurrentUserCode->lv = GAIN_10K;
|
||||
}
|
||||
// least range current
|
||||
else{
|
||||
if(INSTRUCTION.ConstantCurrent >= 50000){
|
||||
// mid range current ( 500 nA ~ 999 nA)
|
||||
CurrentUserCode->lv = CURRENT_LV_ONE;
|
||||
CurrentUserCode->value = (uint16_t) (INSTRUCTION.ConstantCurrent - 50000);
|
||||
}
|
||||
else{
|
||||
// mid range current ( 0 nA ~ 499 nA)
|
||||
CurrentUserCode->lv = CURRENT_LV_ZERO;
|
||||
CurrentUserCode->value = (uint16_t) (INSTRUCTION.ConstantCurrent);
|
||||
}
|
||||
CurrentUserCode->lv = GAIN_200K;
|
||||
}
|
||||
}
|
||||
|
||||
//static int32_t IUC2RealnA(){
|
||||
//
|
||||
//}
|
||||
//
|
||||
//static int32_t IUC2RealpA{
|
||||
//
|
||||
//}
|
||||
/*********************************************************************
|
||||
* @fn Transform2RealpA
|
||||
*
|
||||
* @brief transform an IUC into real current value in pA.
|
||||
*
|
||||
* @param self, which is an IUC
|
||||
*
|
||||
* @return an int32_t current value in pA
|
||||
*/
|
||||
static int32_t _Transform2RealpA(CURRENT_USER_CODE *self){
|
||||
int32_t IUCReal;
|
||||
/** current level range: 0-4 **/
|
||||
// current level = 0 => 0-499 nA => ADCGainLevel = 200K
|
||||
// current level = 1 => 500-999 nA => ADCGainLevel = 10K
|
||||
// current level = 2 => 0-499 uA => ADCGainLevel = 10K
|
||||
// current level = 3 => 500-999 uA => ADCGainLevel = 200R
|
||||
// current level = 4 => 0-499 mA => ADCGainLevel = 200R
|
||||
|
||||
// Saturate if current > 500 uA
|
||||
if (self->lv == CURRENT_LV_FOUR){
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
if (self->lv == CURRENT_LV_THREE){
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
// 0-499 nA
|
||||
if (self->lv == CURRENT_LV_ZERO){
|
||||
IUCReal = (int32_t) (self->value) * 1e3;
|
||||
}
|
||||
|
||||
// 500-999 nA
|
||||
else if (self->lv == CURRENT_LV_ONE){
|
||||
IUCReal = ((int32_t) (self->value) * 1e3);
|
||||
IUCReal = IUCReal + 500e3;
|
||||
}
|
||||
|
||||
// 0-499 uA
|
||||
else if (self->lv == CURRENT_LV_TWO){
|
||||
IUCReal = (int32_t) (self->value) * 1e6;
|
||||
}
|
||||
return IUCReal;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Transform2RealnA
|
||||
*
|
||||
@@ -225,86 +166,30 @@ static int32_t _Transform2RealpA(CURRENT_USER_CODE *self){
|
||||
static int32_t _Transform2RealnA(CURRENT_USER_CODE *self){
|
||||
int32_t IUCReal;
|
||||
|
||||
// Saturate if current < 500 uA
|
||||
if (self->lv == CURRENT_LV_ZERO | self->lv == CURRENT_LV_ONE | self->lv == CURRENT_LV_TWO){
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 500-999 uA
|
||||
if (self->lv == CURRENT_LV_THREE){
|
||||
IUCReal = (int32_t) (self->value) * 1e3;
|
||||
IUCReal = IUCReal + 500e3;
|
||||
}
|
||||
|
||||
// 0-499 mA
|
||||
else if (self->lv == 4){
|
||||
IUCReal = (int32_t) (self->value) * 1e6;
|
||||
}
|
||||
// self->value : 0 ~ 3000000 (which is -1500000 ~ 1500000 (10nA) )
|
||||
IUCReal = (self->value - CC_ZERO_POINT) * 10;
|
||||
return IUCReal;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn CompareCurrent
|
||||
*
|
||||
* @brief compare an int32 current with CURRENT_USER_CODE (IUC) type current.
|
||||
*
|
||||
* @param unit is current unit (0 = pA, 1 = nA)
|
||||
* value is current value
|
||||
*
|
||||
* @return 0 if equal
|
||||
* 1 if IUC is larger
|
||||
* 2 if int32 current is larger.
|
||||
*/
|
||||
static uint8_t CompareCurrent(CURRENT_USER_CODE *self, uint8_t unit, int32_t value){
|
||||
int32_t ErrorRangeIUCReal;
|
||||
|
||||
// unit = pA
|
||||
if (unit == 0){
|
||||
if (self->_Transform2RealpA(self) > value){
|
||||
return 1;
|
||||
}
|
||||
else if (self->_Transform2RealpA(self) < value){
|
||||
return 2;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// unit = nA
|
||||
else if (unit == 1){
|
||||
if (self->_Transform2RealnA(self) > value){
|
||||
return 1;
|
||||
}
|
||||
else if (self->_Transform2RealnA(self) < value){
|
||||
return 2;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
static void SetMeasureCurrent(CURRENT_USER_CODE *self, int32_t current){
|
||||
self->_MeasureCurrent = current;
|
||||
}
|
||||
|
||||
static int32_t GetMeasureCurrent(CURRENT_USER_CODE *self){
|
||||
LED_color(DARKLED, 0x0F, 0x00, 0xFF);
|
||||
return self->_MeasureCurrent;
|
||||
}
|
||||
|
||||
static CURRENT_USER_CODE *InitCurrentUserCode(){
|
||||
CURRENT_USER_CODE *CurrentUserCode = malloc(sizeof(CURRENT_USER_CODE));
|
||||
CurrentUserCode->lv = 0;
|
||||
CurrentUserCode->value = 0;
|
||||
CurrentUserCode->_MeasureCurrent = 0;
|
||||
CurrentUserCode->value = CC_ZERO_POINT;
|
||||
CurrentUserCode->lv = GAIN_AUTO;
|
||||
CurrentUserCode->Vmax = MAX_DAC_UC; // max DAC UserCode
|
||||
CurrentUserCode->Vmin = MIN_DAC_UC; // min DAC UserCode
|
||||
CurrentUserCode-> _MeasureCurrent = 0;
|
||||
CurrentUserCode->_Transform2RealnA = &_Transform2RealnA;
|
||||
CurrentUserCode->_Transform2RealpA = &_Transform2RealpA;
|
||||
CurrentUserCode->SetMeasureCurrent = &SetMeasureCurrent;
|
||||
CurrentUserCode->GetMeasureCurrent = &GetMeasureCurrent;
|
||||
return CurrentUserCode;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
+89
-43
@@ -133,15 +133,13 @@ static uint16_t DPVCurve() {
|
||||
}
|
||||
|
||||
static uint16_t CVCurve() {
|
||||
static uint8_t ramp0;
|
||||
static uint8_t ramp1;
|
||||
static uint16_t outputV;
|
||||
static bool direction_up;
|
||||
static bool current_direction_up;
|
||||
static uint16_t DACOutCode;
|
||||
static bool direction_up; // direction_up = true, if Vfinal > Vorigin
|
||||
static bool current_direction_up; // current_direction_up = true, Vstep => positive. vice versa
|
||||
|
||||
// reset origin volt at the begin
|
||||
if (DACReset) {
|
||||
outputV = INSTRUCTION.VoltOrigin;
|
||||
DACUserCode = INSTRUCTION.VoltOrigin;
|
||||
if (INSTRUCTION.VoltFinal > INSTRUCTION.VoltOrigin) {
|
||||
direction_up = true;
|
||||
current_direction_up = true;
|
||||
@@ -149,51 +147,99 @@ static uint16_t CVCurve() {
|
||||
direction_up = false;
|
||||
current_direction_up = false;
|
||||
}
|
||||
ramp0 = (uint8_t)(INSTRUCTION.VoltOrigin & 0x00FF); // right byte
|
||||
ramp1 = (uint8_t)((INSTRUCTION.VoltOrigin >> 8) & 0x00FF); // left byte
|
||||
DACReset = false;
|
||||
|
||||
DACOutCode = Usercode_Correction_to_DAC(DACUserCode);
|
||||
DAC_outputV(DACOutCode); // output VOLT_ORIGIN
|
||||
DACReset = false;
|
||||
|
||||
return DACOutCode;
|
||||
}
|
||||
|
||||
// output a certain volt
|
||||
DAC_outputV(outputV);
|
||||
if (StepTimeCounter == INSTRUCTION.StepTime) {
|
||||
|
||||
if (direction_up) {
|
||||
if (outputV >= INSTRUCTION.VoltFinal) {
|
||||
current_direction_up = false; // problem occurs when origin == 0000 final == ffff!!!!!!
|
||||
} else if (outputV <= INSTRUCTION.VoltOrigin) {
|
||||
current_direction_up = true;
|
||||
if (INSTRUCTION.CycleNumber == 0) {
|
||||
PeriodicEvent = false; // periodic event end
|
||||
DACReset = true;
|
||||
// Decide next direction
|
||||
if (direction_up) {
|
||||
if (DACUserCode >= INSTRUCTION.VoltFinal) {
|
||||
current_direction_up = false; // problem occurs when origin == 0000 final == ffff!!!!!!
|
||||
} else if (DACUserCode <= INSTRUCTION.VoltOrigin) {
|
||||
current_direction_up = true;
|
||||
if (INSTRUCTION.CycleNumber == 0) {
|
||||
PeriodicEvent = false; // periodic event end
|
||||
DACReset = true;
|
||||
}
|
||||
INSTRUCTION.CycleNumber--;
|
||||
}
|
||||
INSTRUCTION.CycleNumber--;
|
||||
}
|
||||
} else {
|
||||
if (outputV <= INSTRUCTION.VoltFinal) {
|
||||
current_direction_up = true; // problem occurs when origin == 0000 final == ffff!!!!!!
|
||||
} else if (outputV >= INSTRUCTION.VoltOrigin) {
|
||||
current_direction_up = false;
|
||||
if (INSTRUCTION.CycleNumber == 0) {
|
||||
PeriodicEvent = false; // periodic event end
|
||||
DACReset = true;
|
||||
} else {
|
||||
if (DACUserCode <= INSTRUCTION.VoltFinal) {
|
||||
current_direction_up = true; // problem occurs when origin == 0000 final == ffff!!!!!!
|
||||
} else if (DACUserCode >= INSTRUCTION.VoltOrigin) {
|
||||
current_direction_up = false;
|
||||
if (INSTRUCTION.CycleNumber == 0) {
|
||||
PeriodicEvent = false; // periodic event end
|
||||
DACReset = true;
|
||||
}
|
||||
INSTRUCTION.CycleNumber--;
|
||||
}
|
||||
INSTRUCTION.CycleNumber--;
|
||||
}
|
||||
}
|
||||
|
||||
if (current_direction_up) {
|
||||
if (outputV + INSTRUCTION.Step < outputV)
|
||||
outputV = 0xffff;
|
||||
else
|
||||
outputV = outputV + INSTRUCTION.Step;
|
||||
} else {
|
||||
if (outputV - INSTRUCTION.Step > outputV)
|
||||
outputV = 0x0000;
|
||||
else
|
||||
outputV = outputV - INSTRUCTION.Step;
|
||||
}
|
||||
// Next output voltage
|
||||
if (direction_up) {
|
||||
if (current_direction_up) {
|
||||
// DACUserCode overflow ?
|
||||
if (DACUserCode + INSTRUCTION.Step < DACUserCode) {
|
||||
DACUserCode = INSTRUCTION.VoltFinal;
|
||||
}
|
||||
else if (DACUserCode + INSTRUCTION.Step > INSTRUCTION.VoltFinal) {
|
||||
DACUserCode = INSTRUCTION.VoltFinal;
|
||||
}
|
||||
else {
|
||||
DACUserCode = DACUserCode + INSTRUCTION.Step;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// DACUserCode underflow ?
|
||||
if (DACUserCode - INSTRUCTION.Step > DACUserCode || DACUserCode > 60000) {
|
||||
DACUserCode = INSTRUCTION.VoltOrigin;
|
||||
}
|
||||
|
||||
return outputV;
|
||||
// reach Vorigin ?
|
||||
else if (DACUserCode - INSTRUCTION.Step < INSTRUCTION.VoltOrigin) {
|
||||
DACUserCode = INSTRUCTION.VoltOrigin;
|
||||
}
|
||||
else {
|
||||
DACUserCode = DACUserCode - INSTRUCTION.Step;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (current_direction_up) {
|
||||
if (DACUserCode + INSTRUCTION.Step < DACUserCode) {
|
||||
DACUserCode = INSTRUCTION.VoltOrigin;
|
||||
}
|
||||
else if (DACUserCode + INSTRUCTION.Step > INSTRUCTION.VoltOrigin) {
|
||||
DACUserCode = INSTRUCTION.VoltOrigin;
|
||||
}
|
||||
else {
|
||||
DACUserCode = DACUserCode + INSTRUCTION.Step;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (DACUserCode - INSTRUCTION.Step > DACUserCode || DACUserCode > 60000) {
|
||||
DACUserCode = INSTRUCTION.VoltFinal;
|
||||
}
|
||||
else if (DACUserCode - INSTRUCTION.Step < INSTRUCTION.VoltFinal) {
|
||||
DACUserCode = INSTRUCTION.VoltFinal;
|
||||
}
|
||||
else {
|
||||
DACUserCode = DACUserCode - INSTRUCTION.Step;
|
||||
}
|
||||
}
|
||||
}
|
||||
DACOutCode = Usercode_Correction_to_DAC(DACUserCode);
|
||||
DAC_outputV(DACOutCode);
|
||||
}
|
||||
return DACOutCode;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
+5
@@ -57,4 +57,9 @@ static uint16_t DAC_outputV(uint16_t voltLV) {
|
||||
|
||||
#endif
|
||||
|
||||
static int32_t User2Real(uint16_t UserCode){
|
||||
/* transfer usercode to real voltage value (mV) */
|
||||
return (int32_t) ((UserCode - 25000)*2)/10;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+382
-36
@@ -29,7 +29,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#define BOARD_BAY_BAY
|
||||
#define BOARD_MERCURY
|
||||
|
||||
typedef struct _formula{
|
||||
|
||||
@@ -66,8 +66,8 @@ struct _correction{
|
||||
.DAC2RealV.coeff = (-18959656),
|
||||
.DAC2RealV.offset = 565743281498,
|
||||
|
||||
.Usercode2DAC.coeff = (-10548714),
|
||||
.Usercode2DAC.offset = 562100522714,
|
||||
.Usercode2DAC.coeff = (-10517325),
|
||||
.Usercode2DAC.offset = 561574831511,
|
||||
|
||||
.Gain0Boundary[0] = 0x5F75,
|
||||
.Gain0Boundary[1] = 0x5FB2,
|
||||
@@ -82,11 +82,11 @@ struct _correction{
|
||||
.ADC_volt.coeff = (-6259045),
|
||||
.ADC_volt.offset = 150606390230,
|
||||
|
||||
.ADC_current[0].coeff = 27661202,
|
||||
.ADC_current[0].offset = (-664225386769),
|
||||
.ADC_current[0].coeff = 30675739,
|
||||
.ADC_current[0].offset = (-736666253953),
|
||||
|
||||
.ADC_current[1].coeff = 663176124,
|
||||
.ADC_current[1].offset = (-15925056526152),
|
||||
.ADC_current[1].coeff = 749057318,
|
||||
.ADC_current[1].offset = (-17984432358007),
|
||||
|
||||
.ADC_current[2].coeff = 31242587,
|
||||
.ADC_current[2].offset = (-750184492407),
|
||||
@@ -144,8 +144,8 @@ struct _correction{
|
||||
.ADC_current[1].coeff = 658398533,
|
||||
.ADC_current[1].offset = -16001498741131,
|
||||
|
||||
.ADC_current[2].coeff = 30908351,
|
||||
.ADC_current[2].offset = -746548614824,
|
||||
.ADC_current[2].coeff = 30908351000,
|
||||
.ADC_current[2].offset = -746548614824000,
|
||||
|
||||
.DAC2RealV.coeff = (-19007867),
|
||||
.DAC2RealV.offset = 646316924837,
|
||||
@@ -199,13 +199,13 @@ struct _correction{
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef BOARD_BAY_BAY
|
||||
#ifdef BOARD_GENIUS
|
||||
{
|
||||
.ADC_volt.coeff = (-6236652),
|
||||
.ADC_volt.offset = 101533279052,
|
||||
|
||||
.ADC_current[0].coeff = 309083900,
|
||||
.ADC_current[0].offset = (-7414775955140),
|
||||
.ADC_current[0].coeff = 31094976,
|
||||
.ADC_current[0].offset = (-507114075439),
|
||||
|
||||
.ADC_current[1].coeff = 31218018,
|
||||
.ADC_current[1].offset = (-508593562044),
|
||||
@@ -283,6 +283,341 @@ struct _correction{
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_LITTLE_STAR
|
||||
{
|
||||
.ADC_volt.coeff = (-6224192),
|
||||
.ADC_volt.offset = 101472884698,
|
||||
|
||||
.ADC_current[0].coeff = 31293602,
|
||||
.ADC_current[0].offset = (-510187416959),
|
||||
|
||||
.ADC_current[1].coeff = 655130048,
|
||||
.ADC_current[1].offset = (-10680093830418),
|
||||
|
||||
.ADC_current[2].coeff = 31450484,
|
||||
.ADC_current[2].offset = (-512697942950),
|
||||
|
||||
.DAC2RealV.coeff = (-18690126),
|
||||
.DAC2RealV.offset = 564319610294 ,
|
||||
|
||||
.Usercode2DAC.coeff = (-10524846),
|
||||
.Usercode2DAC.offset = 561713962333,
|
||||
|
||||
.Gain0Boundary[0] = 0x5E2F,
|
||||
.Gain0Boundary[1] = 0x5E96,
|
||||
|
||||
.Gain1Boundary[0] = 0x5878,
|
||||
.Gain1Boundary[1] = 0x645A
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_517
|
||||
{
|
||||
.ADC_volt.coeff = (-6244769),
|
||||
.ADC_volt.offset = 101714685687,
|
||||
|
||||
.ADC_current[0].coeff = 30919726,
|
||||
.ADC_current[0].offset = (-503489101786),
|
||||
|
||||
.ADC_current[1].coeff = 654824495,
|
||||
.ADC_current[1].offset = (-10660542778914),
|
||||
|
||||
.ADC_current[2].coeff = 31376265,
|
||||
.ADC_current[2].offset = (-510797752348),
|
||||
|
||||
.DAC2RealV.coeff = (-18690126),
|
||||
.DAC2RealV.offset = 564319610294 ,
|
||||
|
||||
.Usercode2DAC.coeff = (-10500774),
|
||||
.Usercode2DAC.offset = 560779455904,
|
||||
|
||||
.Gain0Boundary[0] = 0x5E2F,
|
||||
.Gain0Boundary[1] = 0x5E96,
|
||||
|
||||
.Gain1Boundary[0] = 0x5878,
|
||||
.Gain1Boundary[1] = 0x645A
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_FISH_VET
|
||||
{
|
||||
.ADC_volt.coeff = (-6243954),
|
||||
.ADC_volt.offset = 101956814341,
|
||||
|
||||
.ADC_current[0].coeff = 6208753,
|
||||
.ADC_current[0].offset = (-101076436901),
|
||||
|
||||
.ADC_current[1].coeff = 68760643,
|
||||
.ADC_current[1].offset = (-1123221851971),
|
||||
|
||||
.ADC_current[2].coeff = 61882330,
|
||||
.ADC_current[2].offset = (-1010385966159),
|
||||
|
||||
.DAC2RealV.coeff = (-18690126),
|
||||
.DAC2RealV.offset = 564319610294,
|
||||
|
||||
.Usercode2DAC.coeff = (-10517326),
|
||||
.Usercode2DAC.offset = 561574831512,
|
||||
|
||||
.Gain0Boundary[0] = 0x5E2F,
|
||||
.Gain0Boundary[1] = 0x5E96,
|
||||
|
||||
.Gain1Boundary[0] = 0x5878,
|
||||
.Gain1Boundary[1] = 0x645A
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_KELLY
|
||||
{
|
||||
.ADC_volt.coeff = (-6238112),
|
||||
.ADC_volt.offset = 101628014509,
|
||||
|
||||
.ADC_current[0].coeff = 6087943,
|
||||
.ADC_current[0].offset = (-99768174580),
|
||||
|
||||
.ADC_current[1].coeff = 68915156,
|
||||
.ADC_current[1].offset = (-1121470119188),
|
||||
|
||||
.ADC_current[2].coeff = 61800515,
|
||||
.ADC_current[2].offset = (-1006755993534),
|
||||
|
||||
.DAC2RealV.coeff = (-18690126),
|
||||
.DAC2RealV.offset = 564319610294,
|
||||
|
||||
.Usercode2DAC.coeff = (-10528309),
|
||||
.Usercode2DAC.offset = 561035476688,
|
||||
|
||||
.Gain0Boundary[0] = 0x5E2F,
|
||||
.Gain0Boundary[1] = 0x5E96,
|
||||
|
||||
.Gain1Boundary[0] = 0x5878,
|
||||
.Gain1Boundary[1] = 0x645A
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_BAY_BAY
|
||||
{
|
||||
.ADC_volt.coeff = (-6223734),
|
||||
.ADC_volt.offset = 101647006833,
|
||||
|
||||
.ADC_current[0].coeff = 31039179,
|
||||
.ADC_current[0].offset = (-506383432096),
|
||||
|
||||
.ADC_current[1].coeff = 647940355,
|
||||
.ADC_current[1].offset = (-10611041889224),
|
||||
|
||||
.ADC_current[2].coeff = 31094976,
|
||||
.ADC_current[2].offset = (-507114075439),
|
||||
|
||||
.DAC2RealV.coeff = (-18690126),
|
||||
.DAC2RealV.offset = 564319610294,
|
||||
|
||||
.Usercode2DAC.coeff = (-10541677),
|
||||
.Usercode2DAC.offset = 562208801371,
|
||||
|
||||
.Gain0Boundary[0] = 0x5E2F,
|
||||
.Gain0Boundary[1] = 0x5E96,
|
||||
|
||||
.Gain1Boundary[0] = 0x5878,
|
||||
.Gain1Boundary[1] = 0x645A
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_MEOWMI
|
||||
{
|
||||
.ADC_volt.coeff = (-6265015),
|
||||
.ADC_volt.offset = 101843650153,
|
||||
|
||||
.ADC_current[0].coeff = 62522034,
|
||||
.ADC_current[0].offset = (-1016702373525),
|
||||
|
||||
.ADC_current[1].coeff = 31613132,
|
||||
.ADC_current[1].offset = (-514033175600),
|
||||
|
||||
.ADC_current[2].coeff = 565897139,
|
||||
.ADC_current[2].offset = (-9201204539440),
|
||||
|
||||
.DAC2RealV.coeff = (-18990774),
|
||||
.DAC2RealV.offset = 570886531263,
|
||||
|
||||
.Usercode2DAC.coeff = (-10541427),
|
||||
.Usercode2DAC.offset = 562159124753,
|
||||
|
||||
.Gain0Boundary[0] = 0x5D96,
|
||||
.Gain0Boundary[1] = 0x5DD9,
|
||||
|
||||
.Gain1Boundary[0] = 0x57CD,
|
||||
.Gain1Boundary[1] = 0x639F
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_EUROPEAN
|
||||
{
|
||||
.ADC_volt.coeff = (-6264190),
|
||||
.ADC_volt.offset = 101683809669,
|
||||
|
||||
.ADC_current[0].coeff = 31301451,
|
||||
.ADC_current[0].offset = (-508301866021),
|
||||
|
||||
.ADC_current[1].coeff = 656423459,
|
||||
.ADC_current[1].offset = (-10660544072862),
|
||||
|
||||
.ADC_current[2].coeff = 31414514,
|
||||
.ADC_current[2].offset = (-510185549182),
|
||||
|
||||
.DAC2RealV.coeff = (-18990774),
|
||||
.DAC2RealV.offset = 570886531263,
|
||||
|
||||
.Usercode2DAC.coeff = (-10513774),
|
||||
.Usercode2DAC.offset = 559795292677,
|
||||
|
||||
.Gain0Boundary[0] = 0x5D96,
|
||||
.Gain0Boundary[1] = 0x5DD9,
|
||||
|
||||
.Gain1Boundary[0] = 0x57CD,
|
||||
.Gain1Boundary[1] = 0x639F
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_EARTH
|
||||
{
|
||||
.ADC_volt.coeff = (-6256660),
|
||||
.ADC_volt.offset = 101658275678,
|
||||
|
||||
.ADC_current[0].coeff = 31271240,
|
||||
.ADC_current[0].offset = (-508496329863),
|
||||
|
||||
.ADC_current[1].coeff = 659931818,
|
||||
.ADC_current[1].offset = (-10729666444387),
|
||||
|
||||
.ADC_current[2].coeff = 31485559000,
|
||||
.ADC_current[2].offset = (-511907957163000),
|
||||
|
||||
.DAC2RealV.coeff = (-19047143),
|
||||
.DAC2RealV.offset = 565935714286,
|
||||
|
||||
.Usercode2DAC.coeff = (-10500262),
|
||||
.Usercode2DAC.offset = 559630236100,
|
||||
|
||||
.Gain0Boundary[0] = 0x5D96,
|
||||
.Gain0Boundary[1] = 0x5DD9,
|
||||
|
||||
.Gain1Boundary[0] = 0x57CD,
|
||||
.Gain1Boundary[1] = 0x639F
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_WATER_STAR
|
||||
{
|
||||
.ADC_volt.coeff = (-6259808),
|
||||
.ADC_volt.offset = 102009860128,
|
||||
|
||||
.ADC_current[0].coeff = 31335917,
|
||||
.ADC_current[0].offset = (-511426612252),
|
||||
|
||||
.ADC_current[1].coeff = 658172815,
|
||||
.ADC_current[1].offset = (-10738251896209),
|
||||
|
||||
.ADC_current[2].coeff = 31482687000,
|
||||
.ADC_current[2].offset = (-513650531545000),
|
||||
|
||||
.DAC2RealV.coeff = (-10548297),
|
||||
.DAC2RealV.offset = 562611756757,
|
||||
|
||||
.Usercode2DAC.coeff = (-10500262),
|
||||
.Usercode2DAC.offset = 559630236100,
|
||||
|
||||
.Gain0Boundary[0] = 0x5D96,
|
||||
.Gain0Boundary[1] = 0x5DD9,
|
||||
|
||||
.Gain1Boundary[0] = 0x57CD,
|
||||
.Gain1Boundary[1] = 0x639F
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_MARS
|
||||
{
|
||||
.ADC_volt.coeff = (-6270623),
|
||||
.ADC_volt.offset = 102383421553,
|
||||
|
||||
.ADC_current[0].coeff = 31187022,
|
||||
.ADC_current[0].offset = (-509159321195),
|
||||
|
||||
.ADC_current[1].coeff = 655981611,
|
||||
.ADC_current[1].offset = (-10709717111320),
|
||||
|
||||
.ADC_current[2].coeff = 31256968,
|
||||
.ADC_current[2].offset = (-510275213115),
|
||||
|
||||
.DAC2RealV.coeff = (-18937347),
|
||||
.DAC2RealV.offset = 568558163265,
|
||||
|
||||
.Usercode2DAC.coeff = (-10561141),
|
||||
.Usercode2DAC.offset = 564249134291,
|
||||
|
||||
.Gain0Boundary[0] = 0x5D96,
|
||||
.Gain0Boundary[1] = 0x5DD9,
|
||||
|
||||
.Gain1Boundary[0] = 0x57CD,
|
||||
.Gain1Boundary[1] = 0x639F
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_VENUS
|
||||
{
|
||||
.ADC_volt.coeff = (-6268996),
|
||||
.ADC_volt.offset = 102204055818,
|
||||
|
||||
.ADC_current[0].coeff = 31131930,
|
||||
.ADC_current[0].offset = (-507382432547),
|
||||
|
||||
.ADC_current[1].coeff = 654620883,
|
||||
.ADC_current[1].offset = (-10668953588943),
|
||||
|
||||
.ADC_current[2].coeff = 31245260000,
|
||||
.ADC_current[2].offset = (-509181085054000),
|
||||
|
||||
.DAC2RealV.coeff = (-19009388),
|
||||
.DAC2RealV.offset = 567032653061,
|
||||
|
||||
.Usercode2DAC.coeff = (-10521117),
|
||||
.Usercode2DAC.offset = 561308254899,
|
||||
|
||||
.Gain0Boundary[0] = 0x5D96,
|
||||
.Gain0Boundary[1] = 0x5DD9,
|
||||
|
||||
.Gain1Boundary[0] = 0x57CD,
|
||||
.Gain1Boundary[1] = 0x639F
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef BOARD_MERCURY
|
||||
{
|
||||
.ADC_volt.coeff = (-6259808),
|
||||
.ADC_volt.offset = 102009860128,
|
||||
|
||||
.ADC_current[0].coeff = 31335917,
|
||||
.ADC_current[0].offset = (-511426612252),
|
||||
|
||||
.ADC_current[1].coeff = 658172815,
|
||||
.ADC_current[1].offset = (-10738251896209),
|
||||
|
||||
.ADC_current[2].coeff = 31482687000,
|
||||
.ADC_current[2].offset = (-513650531545000),
|
||||
|
||||
.DAC2RealV.coeff = (-19009388),
|
||||
.DAC2RealV.offset = 567032653061,
|
||||
|
||||
.Usercode2DAC.coeff = (-10548297),
|
||||
.Usercode2DAC.offset = 562611756757,
|
||||
|
||||
.Gain0Boundary[0] = 0x5D96,
|
||||
.Gain0Boundary[1] = 0x5DD9,
|
||||
|
||||
.Gain1Boundary[0] = 0x57CD,
|
||||
.Gain1Boundary[1] = 0x639F
|
||||
};
|
||||
#endif
|
||||
|
||||
// this function turn ADC measure value (0xXXXX) into real voltage
|
||||
// unit should be mV
|
||||
@@ -308,34 +643,35 @@ static int32_t DecodeADCCurrent(uint8_t ADCGain, uint16_t ADC_measure){
|
||||
}
|
||||
|
||||
static int32_t DecodeResister(uint8_t ADCGainLevel, uint16_t CurrentMeasure, uint16_t VoltMeasure){
|
||||
long long ADCRealResister = 0, ADCRealCurrent=0, ADCRealVolt=0;
|
||||
int32_t current_32, volt_32, resister_32;
|
||||
long long ADCRealCurrent=0, ADCRealVolt=0;
|
||||
int32_t resister_32;
|
||||
|
||||
// get measure current
|
||||
ADCRealCurrent = (Correction.ADC_current[ADCGainLevel].coeff * CurrentMeasure + Correction.ADC_current[ADCGainLevel].offset)/1e7;
|
||||
current_32 = (int32_t) (ADCRealCurrent);
|
||||
|
||||
// get measure volt
|
||||
// This step is necessary, if the measure resister !>> 10 ohm
|
||||
ADCRealVolt = (Correction.ADC_volt.coeff * VoltMeasure + Correction.ADC_volt.offset);
|
||||
ADCRealVolt = ADCRealVolt / 1e4;
|
||||
volt_32 = (int32_t) (ADCRealVolt);
|
||||
|
||||
if (INSTRUCTION.ADCGainLevel == GAIN_200R){
|
||||
resister_32 = (int32_t) ((ADCRealVolt) / (ADCRealCurrent/1e3)); // nV / uA = mV
|
||||
}
|
||||
else{
|
||||
resister_32 = (int32_t) ((ADCRealVolt) / (ADCRealCurrent/1e6)); // nV / uA = mV
|
||||
}
|
||||
// NotifyVolt[0] = (uint8_t) (volt_32 >> 24);
|
||||
// NotifyVolt[1] = (uint8_t) ((volt_32 & 0x00FF0000) >> 16);
|
||||
// NotifyVolt[2] = (uint8_t) ((volt_32 & 0x0000FF00) >> 8);
|
||||
// NotifyVolt[3] = (uint8_t) (volt_32 & 0x000000FF);
|
||||
//
|
||||
// NotifyCurrent[0] = (uint8_t) (current_32 >> 24);
|
||||
// NotifyCurrent[1] = (uint8_t) ((current_32 & 0x00FF0000) >> 16);
|
||||
// NotifyCurrent[2] = (uint8_t) ((current_32 & 0x0000FF00) >> 8);
|
||||
// NotifyCurrent[3] = (uint8_t) (current_32 & 0x000000FF);
|
||||
// if (INSTRUCTION.ADCGainLevel == GAIN_200R){
|
||||
resister_32 = (int32_t) ((ADCRealVolt) / (ADCRealCurrent/1e3)); // nV / uA = mV
|
||||
// }
|
||||
// else{
|
||||
// resister_32 = (int32_t) ((ADCRealVolt) / (ADCRealCurrent/1e6)); // nV / uA = mV
|
||||
// }
|
||||
int32_t volt_32 = (int32_t) (ADCRealVolt);
|
||||
int32_t current_32 = (int32_t) (ADCRealCurrent);
|
||||
|
||||
NotifyVolt[0] = (uint8_t) (volt_32 >> 24);
|
||||
NotifyVolt[1] = (uint8_t) ((volt_32 & 0x00FF0000) >> 16);
|
||||
NotifyVolt[2] = (uint8_t) ((volt_32 & 0x0000FF00) >> 8);
|
||||
NotifyVolt[3] = (uint8_t) (volt_32 & 0x000000FF);
|
||||
|
||||
NotifyCurrent[0] = (uint8_t) (current_32 >> 24);
|
||||
NotifyCurrent[1] = (uint8_t) ((current_32 & 0x00FF0000) >> 16);
|
||||
NotifyCurrent[2] = (uint8_t) ((current_32 & 0x0000FF00) >> 8);
|
||||
NotifyCurrent[3] = (uint8_t) (current_32 & 0x000000FF);
|
||||
|
||||
NotifyImpedance[0] = (uint8_t) (resister_32 >> 24);
|
||||
NotifyImpedance[1] = (uint8_t) ((resister_32 & 0x00FF0000) >> 16);
|
||||
@@ -349,7 +685,7 @@ static int32_t DecodeResister(uint8_t ADCGainLevel, uint16_t CurrentMeasure, uin
|
||||
static int32_t DecodeADCValue(uint8_t ADCGain, uint8_t ADCChannel, uint8_t *ADC_raw){
|
||||
|
||||
uint16_t ADC_measure = (uint16_t) (ADC_raw[0] << 8) | (uint16_t) (ADC_raw[1]);
|
||||
int32_t ADCRealVolt = 0, ret = 0, ADCRealCurrent = 0, ADCRealResister = 0;
|
||||
int32_t ADCRealVolt = 0, ret = 0, ADCRealCurrent = 0;
|
||||
|
||||
// return real volt to controller
|
||||
if(ADCChannel == ADC_CH_VOLT){
|
||||
@@ -364,12 +700,20 @@ static int32_t DecodeADCValue(uint8_t ADCGain, uint8_t ADCChannel, uint8_t *ADC_
|
||||
// return real current to controller
|
||||
else if(ADCChannel == ADC_CH_CURRENT){
|
||||
|
||||
if (INSTRUCTION.eliteFxn == IV_CURVE) {
|
||||
if ( (INSTRUCTION.eliteFxn == IV_CURVE) || (INSTRUCTION.eliteFxn == CV_CURVE)) {
|
||||
// wait 0.1 sec until circuit stable => discard first data means wait 0.1 sec
|
||||
if(DiscardIVFirstData){
|
||||
DiscardIVFirstData = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ADCRealCurrent_long += DecodeADCCurrent(ADCGain, ADC_measure);
|
||||
avg_number++;
|
||||
// return a real time current (used for deciding auto gain)
|
||||
ret = DecodeADCCurrent(ADCGain, ADC_measure);
|
||||
ADCRealCurrent_long = ADCRealCurrent_long + ret;
|
||||
avg_number ++;
|
||||
|
||||
if (StepTimeCounter == INSTRUCTION.StepTime) {
|
||||
if (StepTimeCounter == INSTRUCTION.StepTime - 1) {
|
||||
DiscardIVFirstData = 1;
|
||||
ADCRealCurrent_long = ADCRealCurrent_long / avg_number;
|
||||
NotifyCurrent[0] = (uint8_t) (ADCRealCurrent_long >> 24);
|
||||
NotifyCurrent[1] = (uint8_t) ((ADCRealCurrent_long & 0x00FF0000) >> 16);
|
||||
@@ -379,6 +723,8 @@ static int32_t DecodeADCValue(uint8_t ADCGain, uint8_t ADCChannel, uint8_t *ADC_
|
||||
ADCRealCurrent_long = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// IT curve
|
||||
else {
|
||||
ADCRealCurrent = DecodeADCCurrent(ADCGain, ADC_measure);
|
||||
NotifyCurrent[0] = (uint8_t) (ADCRealCurrent >> 24);
|
||||
|
||||
+26
-11
@@ -2,20 +2,35 @@
|
||||
#ifndef ELITEIT
|
||||
#define ELITEIT
|
||||
|
||||
static int32_t IT_Plot() {
|
||||
//static int32_t IT_Plot() {
|
||||
// // read ADC current
|
||||
// int32_t Real_Current = 0;
|
||||
// ADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
// ADCChannelSelect(ADC_CH_CURRENT);
|
||||
// CPUdelay(10);
|
||||
// ADC_read(spi_ADC_rxbuf);
|
||||
//
|
||||
// // check if ADC over/under flow
|
||||
// // let the output saturate if over/under flow
|
||||
//// ADC_overflow(INSTRUCTION.ADCGainLevel, spi_ADC_rxbuf);
|
||||
//
|
||||
// // decode ADC value and put it into notify buffer
|
||||
// Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
//
|
||||
// return Real_Current;
|
||||
//}
|
||||
|
||||
static int32_t IT_Plot() {
|
||||
// read ADC current
|
||||
int32_t Real_Current = 0;
|
||||
ADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
ADCChannelSelect(ADC_CH_CURRENT);
|
||||
CPUdelay(10);
|
||||
ADC_read(spi_ADC_rxbuf);
|
||||
|
||||
// check if ADC over/under flow
|
||||
// let the output saturate if over/under flow
|
||||
// ADC_overflow(INSTRUCTION.ADCGainLevel, spi_ADC_rxbuf);
|
||||
|
||||
// decode ADC value and put it into notify buffer
|
||||
Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
if(INSTRUCTION.AutoGainEnable){
|
||||
Real_Current = AutoGainReadCurrent(spi_ADC_rxbuf);
|
||||
}
|
||||
else{
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
}
|
||||
|
||||
return Real_Current;
|
||||
}
|
||||
|
||||
+16
-2
@@ -13,7 +13,7 @@ static uint16_t VoltScan() {
|
||||
Voltage = SWVCurve();
|
||||
} else if (INSTRUCTION.eliteFxn == DIFFERENTIAL_PULSE_VOLTAMMETRY) {
|
||||
Voltage = DPVCurve();
|
||||
} else if (INSTRUCTION.eliteFxn == CYCLIC_VOLTAMMETRY) {
|
||||
} else if (INSTRUCTION.eliteFxn == CV_CURVE) {
|
||||
Voltage = CVCurve();
|
||||
}
|
||||
|
||||
@@ -52,8 +52,22 @@ static uint16_t OneWayVoltScan() {
|
||||
DACReset = true;
|
||||
}
|
||||
} else {
|
||||
// output the next output volt
|
||||
|
||||
DACUserCode = DACUserCode - INSTRUCTION.Step;
|
||||
|
||||
// check if DACUserCode underflow
|
||||
if(DACUserCode >= 60000){
|
||||
// LED_color(DARKLED, 0xFF, 0x00, 0x00);
|
||||
DACUserCode = INSTRUCTION.VoltFinal;
|
||||
}
|
||||
|
||||
// int32_t DACUC = DACUserCode;
|
||||
// NotifyImpedance[0] = (uint8_t) (DACUC >> 24);
|
||||
// NotifyImpedance[1] = (uint8_t) ((DACUC & 0x00FF0000) >> 16);
|
||||
// NotifyImpedance[2] = (uint8_t) ((DACUC & 0x0000FF00) >> 8);
|
||||
// NotifyImpedance[3] = (uint8_t) (DACUC & 0x000000FF);
|
||||
|
||||
// output the next output volt
|
||||
DACOutCode = Usercode_Correction_to_DAC(DACUserCode);
|
||||
DAC_outputV(DACOutCode);
|
||||
|
||||
|
||||
+10
-9
@@ -30,23 +30,24 @@ struct HEADSTAGE_INSTRUCTION {
|
||||
/** Sample rate **/
|
||||
// SampleRate = SampleRateTable[SampleRateIndex]
|
||||
uint8_t SampleRateIndex;
|
||||
uint16_t SampleRate;
|
||||
uint32_t SampleRate;
|
||||
|
||||
/** DAC parameter **/
|
||||
// volt san parameter
|
||||
uint16_t VoltOrigin;
|
||||
uint16_t VoltFinal;
|
||||
uint16_t Step;
|
||||
uint8_t StepTime;
|
||||
uint16_t StepTime;
|
||||
// constant volt
|
||||
uint16_t VoltConstant;
|
||||
|
||||
/** ADC parameter **/
|
||||
uint8_t ADCGainLevel;
|
||||
|
||||
uint8_t AutoGainEnable;
|
||||
|
||||
/** Constant Current Parameter **/
|
||||
uint8_t CurrentLV; // nA? uA? mA?
|
||||
uint32_t ConstantCurrent;
|
||||
int32_t ConstantCurrent;
|
||||
|
||||
/** Resister Measure **/
|
||||
uint8_t ResisterMeter;
|
||||
@@ -75,10 +76,10 @@ static void InitEliteInstruction(){
|
||||
INSTRUCTION.VoltFinal = DAC_POS_MAX;
|
||||
INSTRUCTION.Step = 0x0005; // 0x0005 = 1mV
|
||||
INSTRUCTION.StepTime = STEPTIME_HALF_SEC; // about 0.5 sec
|
||||
INSTRUCTION.VoltConstant = 24999; // is about 0V
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200R;
|
||||
INSTRUCTION.ResisterMeter = RESISTER_METER_SMALL;
|
||||
INSTRUCTION.CurrentLV = 0x00;
|
||||
INSTRUCTION.VoltConstant = 25000; // is about 0V
|
||||
INSTRUCTION.ADCGainLevel = GAIN_AUTO;
|
||||
INSTRUCTION.AutoGainEnable = 1;
|
||||
INSTRUCTION.ResisterMeter = RESISTER_METER_LARGE;
|
||||
INSTRUCTION.ConstantCurrent = 0x00000000;
|
||||
INSTRUCTION.eliteFxn = 0; // default is a null event
|
||||
INSTRUCTION.CycleNumber = 0;
|
||||
@@ -97,7 +98,7 @@ static void GetInstructionParameter(uint8 *ins){
|
||||
// CurrentLV=0 => unit is nA
|
||||
// CurrentLV=1 => unit is uA
|
||||
// CurrentLV=2 => unit is mA
|
||||
INSTRUCTION.CurrentLV = (*ins);
|
||||
// INSTRUCTION.CurrentLV = (*ins);
|
||||
|
||||
// ConstantCurrentRange=0 => current value is 0~499
|
||||
// ConstantCurrentRange=1 => current value is 500~999
|
||||
|
||||
+7
-4
@@ -29,7 +29,7 @@ static void WorkModeLED() {
|
||||
WORKLED();
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY: {
|
||||
case CV_CURVE: {
|
||||
WORKLED();
|
||||
break;
|
||||
}
|
||||
@@ -50,14 +50,17 @@ static void WorkModeLED() {
|
||||
break;
|
||||
}
|
||||
case VT_CURVE: {
|
||||
// WORKLED();
|
||||
WORKLED();
|
||||
break;
|
||||
}
|
||||
case IT_CURVE: {
|
||||
WORKLED();
|
||||
break;
|
||||
}
|
||||
|
||||
case CONSTANT_CURRENT:{
|
||||
WORKLED();
|
||||
break;
|
||||
}
|
||||
case VIS_RST: {
|
||||
LEDPowerON();
|
||||
break;
|
||||
@@ -82,7 +85,7 @@ static void KeyWorkModeLED() {
|
||||
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
|
||||
break;
|
||||
}
|
||||
case CYCLIC_VOLTAMMETRY:{
|
||||
case CV_CURVE:{
|
||||
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
|
||||
break;
|
||||
}
|
||||
|
||||
+11
-3
@@ -5,12 +5,16 @@
|
||||
static void reset() {
|
||||
PeriodicEvent = false;
|
||||
DACReset = true;
|
||||
CCModeReset = 1;
|
||||
CCModeDACEnable = 0;
|
||||
InitEliteInstruction();
|
||||
SampleRate_counter = 1;
|
||||
StepTimeCounter = 1;
|
||||
DiscardIVFirstData = 1;
|
||||
avg_number = 0;
|
||||
ADCRealCurrent_long = 0;
|
||||
ADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant));
|
||||
|
||||
if (INSTRUCTION.eliteFxn == CONSTANT_CURRENT){
|
||||
INSTRUCTION.eliteFxn = 0;
|
||||
|
||||
@@ -48,12 +52,15 @@ static void reset() {
|
||||
static void Eliteinterrupt() {
|
||||
PeriodicEvent = false;
|
||||
DACReset = true;
|
||||
CCModeReset = 1;
|
||||
CCModeDACEnable = 0;
|
||||
InitEliteInstruction();
|
||||
StepTimeCounter = 1;
|
||||
SampleRate_counter = 1;
|
||||
DiscardIVFirstData = 1;
|
||||
avg_number = 0;
|
||||
ADCRealCurrent_long = 0;
|
||||
ADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant));
|
||||
|
||||
LEDPowerON();
|
||||
for (int i = 0; i < BLE_INS_BUFF_SIZE; i++) {
|
||||
@@ -87,10 +94,11 @@ static void Eliteinterrupt() {
|
||||
static void CleanBuffer() {
|
||||
PeriodicEvent = false;
|
||||
DACReset = true;
|
||||
CCModeReset = 1;
|
||||
CCModeDACEnable = 0;
|
||||
// InitEliteInstruction();
|
||||
SampleRate_counter = 1;
|
||||
StepTimeCounter = 1;
|
||||
DiscardIVFirstData = 1;
|
||||
avg_number = 0;
|
||||
ADCRealCurrent_long = 0;
|
||||
|
||||
|
||||
+1
-3
@@ -7,9 +7,7 @@ static void VT_Plot() {
|
||||
uint8_t ADCGain = 0;
|
||||
|
||||
// read ADC volt
|
||||
ADCChannelSelect(ADC_CH_VOLT);
|
||||
CPUdelay(10);
|
||||
ADC_read(spi_ADC_rxbuf);
|
||||
ReadVolt(spi_ADC_rxbuf);
|
||||
|
||||
// decode ADC value and put it into notify buffer
|
||||
DecodeADCValue(ADCGain, ADC_CH_VOLT, spi_ADC_rxbuf);
|
||||
|
||||
+81
-45
@@ -10,61 +10,97 @@ static void ZT_notify(int32_t impedance);
|
||||
// change the output voltage step
|
||||
// => get a R-T curve (with resolution = 1 sample/volt step )
|
||||
static void ZT_Plot() {
|
||||
int32_t Real_Resister = 0;
|
||||
// int32_t Real_Resister = 0;
|
||||
static uint16_t CurrentMeasure=0, VoltMeasure=0;
|
||||
uint8_t SPICurrent[SPI_ADC_SIZE]={0}, SPIVolt[SPI_ADC_SIZE]={0};
|
||||
static uint8_t VoltCurrentSwitch = 0;
|
||||
|
||||
// set ADC GAIN
|
||||
if(INSTRUCTION.ResisterMeter == RESISTER_METER_SMALL){
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200R;
|
||||
}
|
||||
else if(INSTRUCTION.ResisterMeter == RESISTER_METER_MIDDLE1){
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200R;
|
||||
}
|
||||
else if(INSTRUCTION.ResisterMeter == RESISTER_METER_MIDDLE2){
|
||||
INSTRUCTION.ADCGainLevel = GAIN_10K;
|
||||
}
|
||||
else{
|
||||
INSTRUCTION.ADCGainLevel = GAIN_200K;
|
||||
}
|
||||
ADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
int32_t volt_32 = 0;
|
||||
int32_t current_32 = 0;
|
||||
int32_t resister_32 = 0;
|
||||
|
||||
if(VoltCurrentSwitch < 9){
|
||||
ADCChannelSelect(ADC_CH_CURRENT);
|
||||
CPUdelay(10);
|
||||
ADC_read(SPICurrent);
|
||||
VoltCurrentSwitch ++;
|
||||
}
|
||||
else if(VoltCurrentSwitch == 9){
|
||||
// read current
|
||||
ADCChannelSelect(ADC_CH_CURRENT);
|
||||
CPUdelay(10);
|
||||
ADC_read(SPICurrent);
|
||||
CurrentMeasure = (uint16_t) (SPICurrent[0] << 8) | (uint16_t) (SPICurrent[1]);
|
||||
VoltCurrentSwitch ++;
|
||||
}
|
||||
else if(VoltCurrentSwitch <18){
|
||||
// read volt
|
||||
ADCChannelSelect(ADC_CH_VOLT);
|
||||
CPUdelay(10);
|
||||
ADC_read(SPIVolt);
|
||||
VoltCurrentSwitch++;
|
||||
}
|
||||
else if(VoltCurrentSwitch == 18){
|
||||
// read volt
|
||||
ADCChannelSelect(ADC_CH_VOLT);
|
||||
CPUdelay(10);
|
||||
ADC_read(SPIVolt);
|
||||
VoltMeasure = (uint16_t) (SPIVolt[0] << 8) | (uint16_t) (SPIVolt[1]);
|
||||
VoltCurrentSwitch++;
|
||||
if(INSTRUCTION.AutoGainEnable){
|
||||
current_32 = AutoGainReadCurrent(SPICurrent);
|
||||
}
|
||||
else{
|
||||
VoltCurrentSwitch = 0;
|
||||
ReadCurrent(spi_ADC_rxbuf);
|
||||
current_32 = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
}
|
||||
|
||||
|
||||
volt_32 = User2Real(INSTRUCTION.VoltConstant)*1e4;
|
||||
// ReadVolt(SPIVolt);
|
||||
// VoltMeasure = (uint16_t) (SPIVolt[0] << 8) | (uint16_t) (SPIVolt[1]);
|
||||
// volt_32 = DecodeADCVolt(VoltMeasure)*1e4;
|
||||
resister_32 = volt_32 / current_32;
|
||||
|
||||
NotifyVolt[0] = (uint8_t) (volt_32 >> 24);
|
||||
NotifyVolt[1] = (uint8_t) ((volt_32 & 0x00FF0000) >> 16);
|
||||
NotifyVolt[2] = (uint8_t) ((volt_32 & 0x0000FF00) >> 8);
|
||||
NotifyVolt[3] = (uint8_t) (volt_32 & 0x000000FF);
|
||||
|
||||
NotifyCurrent[0] = (uint8_t) (current_32 >> 24);
|
||||
NotifyCurrent[1] = (uint8_t) ((current_32 & 0x00FF0000) >> 16);
|
||||
NotifyCurrent[2] = (uint8_t) ((current_32 & 0x0000FF00) >> 8);
|
||||
NotifyCurrent[3] = (uint8_t) (current_32 & 0x000000FF);
|
||||
|
||||
NotifyImpedance[0] = (uint8_t) (resister_32 >> 24);
|
||||
NotifyImpedance[1] = (uint8_t) ((resister_32 & 0x00FF0000) >> 16);
|
||||
NotifyImpedance[2] = (uint8_t) ((resister_32 & 0x0000FF00) >> 8);
|
||||
NotifyImpedance[3] = (uint8_t) (resister_32 & 0x000000FF);
|
||||
|
||||
// set ADC GAIN
|
||||
// if(INSTRUCTION.ResisterMeter == RESISTER_METER_LARGE){
|
||||
// INSTRUCTION.ADCGainLevel = GAIN_200R;
|
||||
// }
|
||||
// else if(INSTRUCTION.ResisterMeter == RESISTER_METER_MIDDLE2){
|
||||
// INSTRUCTION.ADCGainLevel = GAIN_200R;
|
||||
// }
|
||||
// else if(INSTRUCTION.ResisterMeter == RESISTER_METER_MIDDLE1){
|
||||
// INSTRUCTION.ADCGainLevel = GAIN_10K;
|
||||
// }
|
||||
// else{
|
||||
// INSTRUCTION.ADCGainLevel = GAIN_200K;
|
||||
// }
|
||||
// ADCGainControl(INSTRUCTION.ADCGainLevel);
|
||||
|
||||
// Use 9-th measure value as real-measure value
|
||||
// because some value in the begin are garbage
|
||||
// if(VoltCurrentSwitch < 9){
|
||||
// ADCChannelSelect(ADC_CH_CURRENT);
|
||||
// CPUdelay(10);
|
||||
// ADC_read(SPICurrent);
|
||||
// VoltCurrentSwitch ++;
|
||||
// }
|
||||
// else if(VoltCurrentSwitch == 9){
|
||||
// // read current
|
||||
// ADCChannelSelect(ADC_CH_CURRENT);
|
||||
// CPUdelay(10);
|
||||
// ADC_read(SPICurrent);
|
||||
// CurrentMeasure = (uint16_t) (SPICurrent[0] << 8) | (uint16_t) (SPICurrent[1]);
|
||||
// VoltCurrentSwitch ++;
|
||||
// }
|
||||
// else if(VoltCurrentSwitch <18){
|
||||
// // read volt
|
||||
// ADCChannelSelect(ADC_CH_VOLT);
|
||||
// CPUdelay(10);
|
||||
// ADC_read(SPIVolt);
|
||||
// VoltCurrentSwitch++;
|
||||
// }
|
||||
// else if(VoltCurrentSwitch == 18){
|
||||
// // read volt
|
||||
// ADCChannelSelect(ADC_CH_VOLT);
|
||||
// CPUdelay(10);
|
||||
// ADC_read(SPIVolt);
|
||||
// VoltMeasure = (uint16_t) (SPIVolt[0] << 8) | (uint16_t) (SPIVolt[1]);
|
||||
// VoltCurrentSwitch++;
|
||||
// }
|
||||
// else{
|
||||
// VoltCurrentSwitch = 0;
|
||||
// }
|
||||
|
||||
// decode ADC value and put it into notify buffer
|
||||
DecodeResister(INSTRUCTION.ADCGainLevel, CurrentMeasure, VoltMeasure);
|
||||
// DecodeResister(INSTRUCTION.ADCGainLevel, CurrentMeasure, VoltMeasure);
|
||||
// Real_Resister = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
|
||||
}
|
||||
|
||||
|
||||
+63
-34
@@ -190,14 +190,14 @@ MUX
|
||||
PGA
|
||||
programmable gain amplifier configuration
|
||||
(Full Scale Range = FSR)
|
||||
000 = FSR is ��6.144 V
|
||||
001 = FSR is ��4.096 V
|
||||
010 = FSR is ��2.048 V (default)
|
||||
011 = FSR is ��1.024 V
|
||||
100 = FSR is ��0.512 V
|
||||
101 = FSR is ��0.256 V
|
||||
110 = FSR is ��0.256 V
|
||||
111 = FSR is ��0.256 V
|
||||
000 = FSR is 6.144 V
|
||||
001 = FSR is 4.096 V
|
||||
010 = FSR is 2.048 V (default)
|
||||
011 = FSR is 1.024 V
|
||||
100 = FSR is 0.512 V
|
||||
101 = FSR is 0.256 V
|
||||
110 = FSR is 0.256 V
|
||||
111 = FSR is 0.256 V
|
||||
|
||||
M
|
||||
ADC operating mode
|
||||
@@ -579,7 +579,7 @@ static void set_update_instruction_callback(update_instruction_callback_type cal
|
||||
|
||||
// real instruction
|
||||
#define IV_CURVE 0b00010000
|
||||
#define CYCLIC_VOLTAMMETRY 0b00100000
|
||||
#define CV_CURVE 0b00100000
|
||||
#define VOLT_OUTPUT 0b00110000
|
||||
#define ZT_CURVE 0b01000000
|
||||
#define VT_CURVE 0b01010000
|
||||
@@ -607,11 +607,12 @@ static int32_t DAC_to_realV(uint16_t DACcode);
|
||||
#define DAC_NEG_MAX 0xFFFF
|
||||
static uint16_t DACUserCode = 0x0000;
|
||||
|
||||
static uint32_t SampleRateTable[6] = {10, 100, 1000, 5000, 10000, 100000}; // 1 =>100 Hz, 10000=>0.01 Hz
|
||||
static uint16_t SampleRate_counter = 1;
|
||||
static uint32_t SampleRateTable[6] = {100, 1000, 10000, 50000, 100000, 1000000}; // 1 =>100 Hz, 10000=>0.01 Hz
|
||||
static uint32_t SampleRate_counter = 1;
|
||||
|
||||
// record value for IV curve to calculate average current
|
||||
static int16_t avg_number = 0;
|
||||
static uint8_t DiscardIVFirstData = 1;
|
||||
static uint16_t avg_number = 0;
|
||||
static long long ADCRealCurrent_long = 0;
|
||||
|
||||
// Step time macro
|
||||
@@ -620,7 +621,7 @@ static long long ADCRealCurrent_long = 0;
|
||||
#define STEPTIME_TWO_SEC 20000
|
||||
|
||||
// Constant Current Mode function
|
||||
static uint8_t CCModeReset = 1;
|
||||
static uint8_t CCModeDACEnable = 0;
|
||||
static int32_t CCModeReadCurrent();
|
||||
static int32_t CCModeVoltOut();
|
||||
static void SetCCModeGain();
|
||||
@@ -635,8 +636,7 @@ static uint16_t PulseWidth_16;
|
||||
static uint8_t PulsePeriod;
|
||||
static uint16_t PulsePeriod_16;
|
||||
|
||||
static uint16_t StepTime_16 = 0;
|
||||
static uint8_t StepTimeCounter = 1;
|
||||
static uint16_t StepTimeCounter = 1;
|
||||
|
||||
// real instruction fxn
|
||||
static uint16_t VoltScan(); // used in I-V and cyclic
|
||||
@@ -700,7 +700,7 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
INSTRUCTION.chip_id = chip_ID;
|
||||
|
||||
uint8_t oper = ins[1] & 0xF0; // this is don't care in RIS
|
||||
uint8_t data_length = ins[1] & 0x0F;
|
||||
// uint8_t data_length = ins[1] & 0x0F;
|
||||
|
||||
if (!If10Von) {
|
||||
// TurnOn10V();
|
||||
@@ -711,10 +711,10 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
case INS_TYPE_RIS: {
|
||||
switch (ins[2]) {
|
||||
case IV_CURVE: {
|
||||
CleanBuffer();
|
||||
// CleanBuffer();
|
||||
INSTRUCTION.eliteFxn = IV_CURVE;
|
||||
DACReset = true;
|
||||
INSTRUCTION.SampleRate = 10;
|
||||
INSTRUCTION.SampleRate = 1000;
|
||||
|
||||
if (ins[3] | ins[4]) {
|
||||
INSTRUCTION.VoltOrigin = ((uint16_t)(ins[3]) << 8) | (uint16_t)(ins[4]);
|
||||
@@ -802,18 +802,19 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
break;
|
||||
}
|
||||
|
||||
case CYCLIC_VOLTAMMETRY: {
|
||||
CleanBuffer();
|
||||
INSTRUCTION.eliteFxn = CYCLIC_VOLTAMMETRY;
|
||||
case CV_CURVE: {
|
||||
// CleanBuffer();
|
||||
INSTRUCTION.eliteFxn = CV_CURVE;
|
||||
DACReset = true;
|
||||
INSTRUCTION.SampleRate = 1000;
|
||||
|
||||
if (ins[3] | ins[4]) {
|
||||
INSTRUCTION.VoltOrigin = ((uint16_t)(ins[3]) << 8) | (uint16_t)(ins[4]);
|
||||
INSTRUCTION.VoltOrigin = Usercode_Correction_to_DAC(INSTRUCTION.VoltOrigin);
|
||||
// INSTRUCTION.VoltOrigin = Usercode_Correction_to_DAC(INSTRUCTION.VoltOrigin);
|
||||
}
|
||||
if (ins[5] | ins[6]) {
|
||||
INSTRUCTION.VoltFinal = ((uint16_t)(ins[5]) << 8) | (uint16_t)(ins[6]);
|
||||
INSTRUCTION.VoltFinal = Usercode_Correction_to_DAC(INSTRUCTION.VoltFinal);
|
||||
// INSTRUCTION.VoltFinal = Usercode_Correction_to_DAC(INSTRUCTION.VoltFinal);
|
||||
}
|
||||
|
||||
if (ins[7] | ins[8]) {
|
||||
@@ -831,6 +832,7 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case VOLT_OUTPUT: {
|
||||
INSTRUCTION.eliteFxn = VOLT_OUTPUT;
|
||||
INSTRUCTION.VoltConstant = ( ((uint16_t)(ins[3])) << 8) | (uint16_t)(ins[4]);
|
||||
@@ -841,14 +843,14 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
|
||||
// impedance test
|
||||
case ZT_CURVE: {
|
||||
CleanBuffer();
|
||||
// CleanBuffer();
|
||||
INSTRUCTION.eliteFxn = ZT_CURVE;
|
||||
// INSTRUCTION.VoltConstant = ( ((uint16_t)(ins[3])) << 8) | (uint16_t)(ins[4]);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_CURVE: {
|
||||
CleanBuffer();
|
||||
// CleanBuffer();
|
||||
INSTRUCTION.eliteFxn = VT_CURVE;
|
||||
// SimpleProfile_SetParameter(BLE_DAT_BUFF_CHAR, BLE_DAT_BUFF_SIZE, not_buf);
|
||||
// VT_Plot(); // enable 10v = 0
|
||||
@@ -856,7 +858,7 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
}
|
||||
|
||||
case IT_CURVE: {
|
||||
CleanBuffer();
|
||||
// CleanBuffer();
|
||||
INSTRUCTION.eliteFxn = IT_CURVE;
|
||||
// IT_Plot(); // enable 10v = 1
|
||||
break;
|
||||
@@ -881,8 +883,8 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
|
||||
case CONSTANT_CURRENT:{
|
||||
INSTRUCTION.eliteFxn = CONSTANT_CURRENT;
|
||||
INSTRUCTION.CurrentLV = ins[3];
|
||||
INSTRUCTION.ConstantCurrent = ( (uint32_t) (ins[4])<<24 | (uint32_t) (ins[5])<<16 | (uint32_t) (ins[6])<<8 | (uint32_t) (ins[7]) );
|
||||
INSTRUCTION.SampleRate = 2;
|
||||
INSTRUCTION.ConstantCurrent = ( (uint32_t) (ins[3])<<24 | (uint32_t) (ins[4])<<16 | (uint32_t) (ins[5])<<8 | (uint32_t) (ins[6]) );
|
||||
// GetInstructionParameter(ins+2);
|
||||
// CCCurrent2IUC();
|
||||
break;
|
||||
@@ -890,6 +892,21 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
|
||||
case SET_ADC_GAIN: {
|
||||
INSTRUCTION.ADCGainLevel = ins[3];
|
||||
if(INSTRUCTION.ADCGainLevel != GAIN_AUTO){
|
||||
INSTRUCTION.AutoGainEnable = 0;
|
||||
}
|
||||
else{
|
||||
INSTRUCTION.AutoGainEnable = 1;
|
||||
}
|
||||
// if(INSTRUCTION.ADCGainLevel == GAIN_200R){
|
||||
// LED_color(DARKLED, 0x0F, 0x00, 0x00);
|
||||
// }
|
||||
// else if(INSTRUCTION.ADCGainLevel == GAIN_10K){
|
||||
// LED_color(DARKLED, 0x0F, 0x00, 0x0F);
|
||||
// }
|
||||
// else if(INSTRUCTION.ADCGainLevel == GAIN_200K){
|
||||
// LED_color(DARKLED, 0x0F, 0x02, 0xFF);
|
||||
// }
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -903,15 +920,27 @@ static void update_ZM_instruction(uint8 *ins) {
|
||||
int32_t ADCRealValue = 0;
|
||||
uint8_t CIS_buf[9] = {0};
|
||||
|
||||
ADCGainControl(ins[3]);
|
||||
ADCChannelSelect(ins[4]);
|
||||
CPUdelay(1600);
|
||||
ADC_read(spi_ADC_rxbuf);
|
||||
// for(int i=0 ; i<10 ; i++){
|
||||
ADCGainControl(ins[3]);
|
||||
ADCChannelSelect(ins[4]);
|
||||
CPUdelay(10);
|
||||
ADC_read(spi_ADC_rxbuf);
|
||||
// CPUdelay(10);
|
||||
//
|
||||
// ADCValueTemp = ( uint16_t) (spi_ADC_rxbuf[0]) << 8 | (uint16_t) (spi_ADC_rxbuf[1]);
|
||||
// ADCValueAVG = ADCValueAVG + ADCValueTemp;
|
||||
// }
|
||||
// ADCValueAVG = ADCValueAVG / 10;
|
||||
// ADCValueTemp = (uint16_t) (ADCValueAVG);
|
||||
|
||||
CIS_buf[0] = chip_ID;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
CIS_buf[i + 1] = spi_ADC_rxbuf[i];
|
||||
for(int i=0; i<4 ; i++){
|
||||
CIS_buf[i+1] = spi_ADC_rxbuf[i];
|
||||
}
|
||||
// CIS_buf[1] = (uint8_t) ((ADCValueTemp & 0xFF00) >> 8);
|
||||
// CIS_buf[2] = (uint8_t) (ADCValueTemp & 0x00FF);
|
||||
// CIS_buf[3] = spi_ADC_rxbuf[2];
|
||||
// CIS_buf[4] = spi_ADC_rxbuf[3];
|
||||
|
||||
// decode ADC measure value
|
||||
ADCRealValue = DecodeADCValue(ins[3], ins[4], spi_ADC_rxbuf);
|
||||
|
||||
+34
-21
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* impedance_meter.h
|
||||
*
|
||||
* Created on: 2019�~1��15��
|
||||
* Created on: 2019/01/15
|
||||
* Author: benny
|
||||
*/
|
||||
#ifndef HEADSTAGE_H
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <ti/drivers/PIN.h>
|
||||
#include "board.h"
|
||||
|
||||
static void SimpleBLEPeripheral_performPeriodicTask(CURRENT_USER_CODE *CurrentUserCode);
|
||||
static void SimpleBLEPeripheral_performPeriodicTask(void *WorkModeData);
|
||||
|
||||
static void SimpleBLEPeripheral_clockHandler(UArg arg) {
|
||||
// Store the event.
|
||||
@@ -51,6 +51,7 @@ static void ZM_init() {
|
||||
PIN_setOutputValue(pin_handle, DAC_CS, 1); // DAC_CS HIGH
|
||||
|
||||
InitEliteInstruction();
|
||||
ADCGainControl(GAIN_AUTO);
|
||||
elite_gptimer_open();
|
||||
|
||||
// PIN_registerIntCb(pin_handle, switch_on_callback);
|
||||
@@ -72,6 +73,7 @@ static void DACCode2Real2Notify(uint16_t DACcode) {
|
||||
|
||||
#define IsPeriodicMode() ( \
|
||||
(INSTRUCTION.eliteFxn == IV_CURVE) || \
|
||||
(INSTRUCTION.eliteFxn == CV_CURVE) || \
|
||||
(INSTRUCTION.eliteFxn == IT_CURVE) || \
|
||||
(INSTRUCTION.eliteFxn == VT_CURVE) || \
|
||||
(INSTRUCTION.eliteFxn == ZT_CURVE) || \
|
||||
@@ -87,10 +89,9 @@ static void DACCode2Real2Notify(uint16_t DACcode) {
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
static void SimpleBLEPeripheral_performPeriodicTask(CURRENT_USER_CODE *CurrentUserCode) {
|
||||
static void SimpleBLEPeripheral_performPeriodicTask(void *WorkModeData) {
|
||||
if ( IsPeriodicMode() ){
|
||||
|
||||
// XXX Using nwe clock => StepTime/SampleRate should change
|
||||
if (StepTimeCounter == INSTRUCTION.StepTime){
|
||||
StepTimeCounter = 1;
|
||||
}
|
||||
@@ -112,36 +113,45 @@ static void SimpleBLEPeripheral_performPeriodicTask(CURRENT_USER_CODE *CurrentUs
|
||||
|
||||
// In IV, CV, and func-gen mode, DAC will output voltage
|
||||
// else DAC do nothing.
|
||||
EliteDACControl();
|
||||
EliteDACControl(WorkModeData);
|
||||
|
||||
// Control ADC to sample rate
|
||||
EliteADCControl(CurrentUserCode);
|
||||
EliteADCControl(WorkModeData);
|
||||
|
||||
// Notify control, check if we need to send notify
|
||||
EliteNotifyControl();
|
||||
}
|
||||
}
|
||||
|
||||
static void EliteDACControl(CURRENT_USER_CODE *CurrentUserCode) {
|
||||
if (INSTRUCTION.eliteFxn == IV_CURVE) {
|
||||
static void EliteDACControl(void *WorkModeData) {
|
||||
if ((INSTRUCTION.eliteFxn == IV_CURVE) || (INSTRUCTION.eliteFxn == CV_CURVE)) {
|
||||
// output a certain voltage and put it into NotifyVolt
|
||||
DACCode2Real2Notify(VoltScan());
|
||||
}
|
||||
else if (INSTRUCTION.eliteFxn == ZT_CURVE){
|
||||
if(INSTRUCTION.ResisterMeter == RESISTER_METER_SMALL){
|
||||
// output 5mV
|
||||
INSTRUCTION.VoltConstant = 24999 + 50;
|
||||
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant));
|
||||
// output 1V
|
||||
if (DACReset) {
|
||||
INSTRUCTION.VoltConstant = 25000 + 5000;
|
||||
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant));
|
||||
DACReset = false;
|
||||
}
|
||||
}
|
||||
else{
|
||||
// output 100mV
|
||||
INSTRUCTION.VoltConstant = 24999 + 500;
|
||||
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant));
|
||||
// output 1V
|
||||
if (DACReset) {
|
||||
INSTRUCTION.VoltConstant = 25000 + 5000;
|
||||
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant));
|
||||
DACReset = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(INSTRUCTION.eliteFxn == CONSTANT_CURRENT){
|
||||
CCModeVoltOut(CurrentUserCode);
|
||||
// DAC_outputV(Usercode_Correction_to_DAC(CurrentUserCode->value));
|
||||
if (DACReset) {
|
||||
DAC_outputV(Usercode_Correction_to_DAC(25000));
|
||||
DACReset = false;
|
||||
}
|
||||
CCModeVoltOut(WorkModeData);
|
||||
}
|
||||
|
||||
else{
|
||||
@@ -150,13 +160,17 @@ static void EliteDACControl(CURRENT_USER_CODE *CurrentUserCode) {
|
||||
}
|
||||
}
|
||||
|
||||
static void EliteADCControl(CURRENT_USER_CODE *CurrentUserCode) {
|
||||
if (SampleRate_counter == INSTRUCTION.SampleRate) {
|
||||
static void EliteADCControl(uint32_t **WorkModeData) {
|
||||
if (SampleRate_counter == INSTRUCTION.SampleRate-1) {
|
||||
switch (INSTRUCTION.eliteFxn) {
|
||||
case IV_CURVE:{
|
||||
IT_Plot();
|
||||
break;
|
||||
}
|
||||
case CV_CURVE:{
|
||||
IT_Plot();
|
||||
break;
|
||||
}
|
||||
case IT_CURVE:{
|
||||
IT_Plot();
|
||||
break;
|
||||
@@ -171,8 +185,7 @@ static void EliteADCControl(CURRENT_USER_CODE *CurrentUserCode) {
|
||||
break;
|
||||
}
|
||||
case CONSTANT_CURRENT:{
|
||||
CCModeReadCurrent(CurrentUserCode);
|
||||
|
||||
CCModeReadCurrent(WorkModeData);
|
||||
break;
|
||||
}
|
||||
default:{
|
||||
@@ -183,7 +196,7 @@ static void EliteADCControl(CURRENT_USER_CODE *CurrentUserCode) {
|
||||
}
|
||||
|
||||
static void EliteNotifyControl() {
|
||||
if ((INSTRUCTION.eliteFxn == IV_CURVE)) {
|
||||
if ((INSTRUCTION.eliteFxn == IV_CURVE) || (INSTRUCTION.eliteFxn == CV_CURVE)) {
|
||||
// output the last notify, and reset Elite
|
||||
if (!PeriodicEvent) {
|
||||
SendNotify();
|
||||
|
||||
+4
-2
@@ -551,14 +551,16 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
|
||||
|
||||
ZM_init();
|
||||
Elite_SPI_init();
|
||||
void *WorkModeData = malloc(sizeof(uint32_t));
|
||||
CURRENT_USER_CODE *CurrentUserCode = InitCurrentUserCode();
|
||||
WorkModeData = &CurrentUserCode;
|
||||
|
||||
uint8_t key = 0;
|
||||
uint16_t counter6994 = 0;
|
||||
bool EliteOn = 0;
|
||||
|
||||
// init DAC, set output ~= 0 V
|
||||
DAC_outputV(Usercode_Correction_to_DAC(24999));
|
||||
DAC_outputV(Usercode_Correction_to_DAC(25000));
|
||||
elite_gptimer_start();
|
||||
|
||||
// Application main loops
|
||||
@@ -634,7 +636,7 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
|
||||
// if there is periodic event
|
||||
else {
|
||||
// Perform periodic application task
|
||||
SimpleBLEPeripheral_performPeriodicTask(CurrentUserCode);
|
||||
SimpleBLEPeripheral_performPeriodicTask(WorkModeData );
|
||||
|
||||
key = PIN_getInputValue(switch_on);
|
||||
EliteKeyPress(key); // onPress=> key = 0; 1.lighten LED 2.long press shut down 2650
|
||||
|
||||
Reference in New Issue
Block a user