Compare commits

..

1 Commits

Author SHA1 Message Date
YiChin 283cb69a6b update DEFAULT_DESIRED_CONN_INTERVAL range 8~30 2020-07-17 10:34:20 +08:00
38 changed files with 4775 additions and 4110 deletions
@@ -34,17 +34,17 @@
<listOptionValue builtIn="false" value="LINK_ORDER=TOOLS/ccs_linker_defines.cmd;TOOLS/cc26xx_app.cmd;"/>
<listOptionValue builtIn="false" value="RTSC_MBS_VERSION=2.2.0"/>
</option>
<option id="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION.277675815" name="Compiler version" superClass="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION" value="18.1.4.LTS" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION.277675815" superClass="com.ti.ccstudio.buildDefinitions.core.OPT_CODEGEN_VERSION" value="18.1.4.LTS" valueType="string"/>
<targetPlatform id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.targetPlatformDebug.1593934674" name="Platform" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.targetPlatformDebug"/>
<builder buildPath="${BuildDirectory}" id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.builderDebug.632414212" keepEnvironmentInBuildfile="false" name="GNU Make" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.builderDebug"/>
<builder buildPath="${BuildDirectory}" id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.builderDebug.632414212" name="GNU Make.FlashROM" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.builderDebug"/>
<tool id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.compilerDebug.154623462" name="ARM Compiler" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.compilerDebug">
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.SILICON_VERSION.974280107" name="Target processor version (--silicon_version, -mv)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.SILICON_VERSION" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.SILICON_VERSION.7M3" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CODE_STATE.1783826131" name="Designate code state, 16-bit (thumb) or 32-bit (--code_state)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CODE_STATE" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CODE_STATE.16" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.ABI.1536570599" name="Application binary interface. (--abi)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.ABI" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.ABI.eabi" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.LITTLE_ENDIAN.1895413316" name="Little endian code [See 'General' page to edit] (--little_endian, -me)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.LITTLE_ENDIAN" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.OPT_LEVEL.322983319" name="Optimization level (--opt_level, -O)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.OPT_LEVEL" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.OPT_LEVEL.4" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.OPT_FOR_SPEED.1305400753" name="Speed vs. size trade-offs (--opt_for_speed, -mf)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.OPT_FOR_SPEED" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.OPT_FOR_SPEED.0" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.INCLUDE_PATH.1468985930" name="Add dir to #include search path (--include_path, -I)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.INCLUDE_PATH" valueType="includePath">
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.SILICON_VERSION.974280107" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.SILICON_VERSION" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.SILICON_VERSION.7M3" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CODE_STATE.1783826131" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CODE_STATE" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CODE_STATE.16" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.ABI.1536570599" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.ABI" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.ABI.eabi" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.LITTLE_ENDIAN.1895413316" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.LITTLE_ENDIAN" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.OPT_LEVEL.322983319" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.OPT_LEVEL" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.OPT_LEVEL.4" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.OPT_FOR_SPEED.1305400753" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.OPT_FOR_SPEED" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.OPT_FOR_SPEED.0" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.INCLUDE_PATH.1468985930" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.INCLUDE_PATH" valueType="includePath">
<listOptionValue builtIn="false" value="${CG_TOOL_ROOT}/include"/>
<listOptionValue builtIn="false" value="C:\ti\simplelink\ble_sdk_2_02_02_25\src\examples\simple_peripheral\cc26xx\app\headstage"/>
<listOptionValue builtIn="false" value="${SRC_EX}/examples/simple_peripheral/cc26xx/app"/>
@@ -70,7 +70,7 @@
<listOptionValue builtIn="false" value="${SRC_BLE_CORE}/rom"/>
<listOptionValue builtIn="false" value="${CC26XXWARE}"/>
</option>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEFINE.1897088" name="Pre-define NAME (--define, -D)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEFINE" valueType="definedSymbols">
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEFINE.1897088" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEFINE" valueType="definedSymbols">
<listOptionValue builtIn="false" value="BOARD_DISPLAY_EXCLUDE_UART"/>
<listOptionValue builtIn="false" value="POWER_SAVING"/>
<listOptionValue builtIn="false" value="BOOSTXL_CC2650MA"/>
@@ -86,19 +86,19 @@
<listOptionValue builtIn="false" value="xdc_runtime_Assert_DISABLE_ALL"/>
<listOptionValue builtIn="false" value="xdc_runtime_Log_DISABLE_ALL"/>
</option>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEBUGGING_MODEL.871011287" name="Debugging model" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEBUGGING_MODEL" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEBUGGING_MODEL.SYMDEBUG__DWARF" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.C_DIALECT.863089168" name="C Dialect" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.C_DIALECT" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.C_DIALECT.C99" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.GCC.1454248503" name="Enable support for GCC extensions (DEPRECATED) (--gcc)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.GCC" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_SUPPRESS.1965115059" name="Suppress diagnostic &lt;id&gt; (--diag_suppress, -pds)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_SUPPRESS" valueType="stringList">
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEBUGGING_MODEL.871011287" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEBUGGING_MODEL" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DEBUGGING_MODEL.SYMDEBUG__DWARF" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.C_DIALECT.863089168" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.C_DIALECT" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.C_DIALECT.C99" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.GCC.1454248503" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.GCC" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_SUPPRESS.1965115059" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_SUPPRESS" valueType="stringList">
<listOptionValue builtIn="false" value="48"/>
</option>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WARNING.1638011093" name="Treat diagnostic &lt;id&gt; as warning (--diag_warning, -pdsw)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WARNING" valueType="stringList">
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WARNING.1638011093" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WARNING" valueType="stringList">
<listOptionValue builtIn="false" value="225"/>
</option>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WRAP.1920170652" name="Wrap diagnostic messages (--diag_wrap)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WRAP" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WRAP.off" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DISPLAY_ERROR_NUMBER.2038786257" name="Emit diagnostic identifier numbers (--display_error_number, -pden)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DISPLAY_ERROR_NUMBER" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.GEN_FUNC_SUBSECTIONS.811478344" name="Place each function in a separate subsection (--gen_func_subsections, -ms)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.GEN_FUNC_SUBSECTIONS" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.GEN_FUNC_SUBSECTIONS.on" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CMD_FILE.1229809338" name="Read options from specified file (--cmd_file, -@)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CMD_FILE" valueType="stringList">
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WRAP.1920170652" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WRAP" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DIAG_WRAP.off" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DISPLAY_ERROR_NUMBER.2038786257" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.DISPLAY_ERROR_NUMBER" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.GEN_FUNC_SUBSECTIONS.811478344" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.GEN_FUNC_SUBSECTIONS" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.GEN_FUNC_SUBSECTIONS.on" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CMD_FILE.1229809338" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compilerID.CMD_FILE" valueType="stringList">
<listOptionValue builtIn="false" value="${SRC_EX}/config/build_components.opt"/>
<listOptionValue builtIn="false" value="${ORG_PROJ_DIR}/build_config.opt"/>
<listOptionValue builtIn="false" value="${ORG_PROJ_DIR}/../../ccs/config/ccs_compiler_defines.bcfg"/>
@@ -109,48 +109,48 @@
<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__ASM2_SRCS.463094612" name="Assembly Sources" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.compiler.inputType__ASM2_SRCS"/>
</tool>
<tool id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.linkerDebug.1351821865" name="ARM Linker" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exe.linkerDebug">
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.STACK_SIZE.174129193" name="Set C system stack size (--stack_size, -stack)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.STACK_SIZE" value="256" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.HEAP_SIZE.567300083" name="Heap size for C/C++ dynamic memory allocation (--heap_size, -heap)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.HEAP_SIZE" value="0" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.MAP_FILE.1800982811" name="Link information (map) listed into &lt;file&gt; (--map_file, -m)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.MAP_FILE" value="&quot;${ProjName}.map&quot;" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.OUTPUT_FILE.1091211742" name="Specify output file name (--output_file, -o)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.OUTPUT_FILE" value="${ProjName}.out" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.LIBRARY.1479599481" name="Include library file or command file as input (--library, -l)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.LIBRARY" valueType="libs">
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.STACK_SIZE.174129193" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.STACK_SIZE" value="256" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.HEAP_SIZE.567300083" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.HEAP_SIZE" value="0" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.MAP_FILE.1800982811" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.MAP_FILE" value="&quot;${ProjName}.map&quot;" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.OUTPUT_FILE.1091211742" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.OUTPUT_FILE" value="${ProjName}.out" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.LIBRARY.1479599481" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.LIBRARY" valueType="libs">
<listOptionValue builtIn="false" value="libc.a"/>
<listOptionValue builtIn="false" value="${CC26XXWARE}/driverlib/bin/ccs/driverlib.lib"/>
<listOptionValue builtIn="false" value="${ROM}/common_rom_releases/03282014/common_rom.symbols"/>
</option>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.SEARCH_PATH.672837228" name="Add &lt;dir&gt; to library search path (--search_path, -i)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.SEARCH_PATH" valueType="libPaths">
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.SEARCH_PATH.672837228" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.SEARCH_PATH" valueType="libPaths">
<listOptionValue builtIn="false" value="${CG_TOOL_ROOT}/lib"/>
<listOptionValue builtIn="false" value="${CG_TOOL_ROOT}/include"/>
</option>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.DIAG_SUPPRESS.544523272" name="Suppress diagnostic &lt;id&gt; (--diag_suppress)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.DIAG_SUPPRESS" valueType="stringList">
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.DIAG_SUPPRESS.544523272" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.DIAG_SUPPRESS" valueType="stringList">
<listOptionValue builtIn="false" value="10247-D"/>
<listOptionValue builtIn="false" value="16002-D"/>
</option>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.DIAG_WRAP.1281207998" name="Wrap diagnostic messages (--diag_wrap)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.DIAG_WRAP" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.DIAG_WRAP.off" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.DISPLAY_ERROR_NUMBER.468817864" name="Emit diagnostic identifier numbers (--display_error_number)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.DISPLAY_ERROR_NUMBER" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.XML_LINK_INFO.1679096029" name="Detailed link information data-base into &lt;file&gt; (--xml_link_info, -xml_link_info)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.XML_LINK_INFO" value="&quot;${ProjName}_linkInfo.xml&quot;" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.COMPRESS_DWARF.254835397" name="Aggressively reduce size of the DWARF information (--compress_dwarf)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.COMPRESS_DWARF" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.COMPRESS_DWARF.on" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.UNUSED_SECTION_ELIMINATION.1848192295" name="Eliminate sections not needed in the executable (--unused_section_elimination)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.UNUSED_SECTION_ELIMINATION" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.UNUSED_SECTION_ELIMINATION.on" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.DIAG_WRAP.1281207998" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.DIAG_WRAP" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.DIAG_WRAP.off" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.DISPLAY_ERROR_NUMBER.468817864" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.DISPLAY_ERROR_NUMBER" value="true" valueType="boolean"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.XML_LINK_INFO.1679096029" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.XML_LINK_INFO" value="&quot;${ProjName}_linkInfo.xml&quot;" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.COMPRESS_DWARF.254835397" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.COMPRESS_DWARF" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.COMPRESS_DWARF.on" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.UNUSED_SECTION_ELIMINATION.1848192295" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.UNUSED_SECTION_ELIMINATION" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.linkerID.UNUSED_SECTION_ELIMINATION.on" valueType="enumerated"/>
<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exeLinker.inputType__CMD_SRCS.1999849945" name="Linker Command Files" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exeLinker.inputType__CMD_SRCS"/>
<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exeLinker.inputType__CMD2_SRCS.25027104" name="Linker Command Files" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exeLinker.inputType__CMD2_SRCS"/>
<inputType id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exeLinker.inputType__GEN_CMDS.888093741" name="Generated Linker Command Files" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.exeLinker.inputType__GEN_CMDS"/>
</tool>
<tool id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.hex.19288898" name="ARM Hex Utility" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.hex">
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.hex.ROMWIDTH.11734737" name="Specify rom width (--romwidth, -romwidth=width)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.hex.ROMWIDTH" value="8" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.hex.MEMWIDTH.466140455" name="Specify memory width (--memwidth, -memwidth=width)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.hex.MEMWIDTH" value="8" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.hex.OUTPUT_FORMAT.824070691" name="Output format" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.hex.OUTPUT_FORMAT" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.hex.OUTPUT_FORMAT.INTEL" valueType="enumerated"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.hex.ROMWIDTH.11734737" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.hex.ROMWIDTH" value="8" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.hex.MEMWIDTH.466140455" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.hex.MEMWIDTH" value="8" valueType="string"/>
<option id="com.ti.ccstudio.buildDefinitions.TMS470_18.1.hex.OUTPUT_FORMAT.824070691" superClass="com.ti.ccstudio.buildDefinitions.TMS470_18.1.hex.OUTPUT_FORMAT" value="com.ti.ccstudio.buildDefinitions.TMS470_18.1.hex.OUTPUT_FORMAT.INTEL" valueType="enumerated"/>
</tool>
<tool id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.1392704063" name="XDCtools" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool">
<option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.XDC_PATH.225737408" name="Package repositories (--xdcpath)" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.XDC_PATH" valueType="stringList">
<option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.XDC_PATH.225737408" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.XDC_PATH" valueType="stringList">
<listOptionValue builtIn="false" value="${COM_TI_RTSC_TIRTOSCC13XX_CC26XX_REPOS}"/>
<listOptionValue builtIn="false" value="${TARGET_CONTENT_BASE}"/>
</option>
<option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.TARGET.571281110" name="Target (-t)" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.TARGET" value="ti.targets.arm.elf.M3" valueType="string"/>
<option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.PLATFORM.205178830" name="Platform (-p)" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.PLATFORM" value="ti.platforms.simplelink:CC2640F128" valueType="string"/>
<option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.PLATFORM_RAW.1097777495" name="Platform (-p)" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.PLATFORM_RAW" value="ti.platforms.simplelink:CC2640F128" valueType="string"/>
<option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.BUILD_PROFILE.744121344" name="Build-profile (-r)" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.BUILD_PROFILE" value="release" valueType="string"/>
<option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.CODEGEN_TOOL_DIR.165807018" name="Compiler tools directory (-c)" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.CODEGEN_TOOL_DIR" value="${CG_TOOL_ROOT}" valueType="string"/>
<option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.COMPILE_OPTIONS.391961861" name="Additional compiler options (--compileOptions)" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.COMPILE_OPTIONS" value="&quot;${COMPILER_FLAGS}&quot;" valueType="string"/>
<option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.TARGET.571281110" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.TARGET" value="ti.targets.arm.elf.M3" valueType="string"/>
<option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.PLATFORM.205178830" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.PLATFORM" value="ti.platforms.simplelink:CC2640F128" valueType="string"/>
<option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.PLATFORM_RAW.1097777495" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.PLATFORM_RAW" value="ti.platforms.simplelink:CC2640F128" valueType="string"/>
<option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.BUILD_PROFILE.744121344" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.BUILD_PROFILE" value="release" valueType="string"/>
<option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.CODEGEN_TOOL_DIR.165807018" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.CODEGEN_TOOL_DIR" value="${CG_TOOL_ROOT}" valueType="string"/>
<option id="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.COMPILE_OPTIONS.391961861" superClass="com.ti.rtsc.buildDefinitions.XDC_3.16.tool.COMPILE_OPTIONS" value="&quot;${COMPILER_FLAGS}&quot;" valueType="string"/>
</tool>
</toolChain>
</folderInfo>
@@ -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
@@ -6,6 +6,7 @@
#include "EliteSPI.h"
#include "EliteNotify.h"
// Elite ADC macro
// ADC command, Elite will use these cmd to control ADC
#define CMD_CURRENT_MEASURE 0xC5
@@ -46,6 +47,7 @@ static void ADC_write(uint8_t ADCin) {
spi_ADC_txbuf[0] = ADCin;
spi_ADC_txbuf[1] = 0b11101011;
ADC_SPI(2, spi_ADC_txbuf, spi_ADC_rxbuf);
}
@@ -55,110 +57,37 @@ static void ADC_read(uint8_t *ADCdata){
spi_ADC_rxbuf[i] = 0;
}
ADC_SPI(2, spi_ADC_txbuf, spi_ADC_rxbuf);
ADC_SPI(SPI_ADC_SIZE, spi_ADC_txbuf, ADCdata);
}
/* Elite1.5 Calibration Usage */
static void CAL_ADC_read(uint8_t *ADCdata){
for(int i=0 ; i<SPI_ADC_SIZE ; i++){
spi_ADC_txbuf[i] = 0;
spi_ADC_rxbuf[i] = 0;
}
CAL_ADC_SPI(SPI_ADC_SIZE, spi_ADC_txbuf, ADCdata);
}
static void CAL_ADC_write(uint8_t ADCin) {
for(int i=0 ; i<SPI_ADC_SIZE ; i++){
spi_ADC_txbuf[i] = 0;
spi_ADC_rxbuf[i] = 0;
static void ADCGainControl(uint8_t ADCLevel){
if(ADCLevel == 0){
// ADC gain level = 0, using 200K resister
PIN_setOutputValue(pin_handle, Turnon10K, 0);
PIN_setOutputValue(pin_handle, Turnon200R, 0);
}
spi_ADC_txbuf[0] = ADCin;
spi_ADC_txbuf[1] = 0b11101011;
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(ADCLevel == 1){
// ADC gain level = 1, using 10K resister
PIN_setOutputValue(pin_handle, Turnon10K, 1);
PIN_setOutputValue(pin_handle, Turnon200R, 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(ADCLevel == 2){
// ADC gain level = 2, using 200R resister
PIN_setOutputValue(pin_handle, Turnon10K, 0);
PIN_setOutputValue(pin_handle, Turnon200R, 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 if(ADCLevel == 3){
// ADC gain level = 0, auto gain (using 200R resister)
PIN_setOutputValue(pin_handle, Turnon10K, 0);
PIN_setOutputValue(pin_handle, Turnon200R, 1);
}
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;
// default using 200R resister
PIN_setOutputValue(pin_handle, Turnon10K, 0);
PIN_setOutputValue(pin_handle, Turnon200R, 1);
}
}
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
@@ -197,20 +126,8 @@ static void ADCChannelSelect(uint8_t ADCChannel){
}
}
static void ReadADCIin(uint8_t *buf){
static void ReadVolt(uint8_t *buf){
// Read data twice since the first data we get is previous data
// IinADCGainControl(instru.ADCGainLevel);
ADCChannelSelect(ADC_CH_CURRENT);
ADC_read(buf);
ADCChannelSelect(ADC_CH_CURRENT);
ADC_read(buf);
}
static void ReadADCVin(uint8_t *buf){
// Read data twice since the first data we get is previous data
// VinADCGainControl(instru.VinADCGainLevel);
ADCChannelSelect(ADC_CH_VOLT);
ADC_read(buf);
@@ -218,7 +135,7 @@ static void ReadADCVin(uint8_t *buf){
ADC_read(buf);
}
static void ReadADCVout(uint8_t *buf){
static void ReadVoutVolt(uint8_t *buf){
// Read data twice since the first data we get is previous data
ADCChannelSelect(ADC_CH_DAC);
ADC_read(buf);
@@ -227,7 +144,17 @@ static void ReadADCVout(uint8_t *buf){
ADC_read(buf);
}
static void ReadADCBat(uint8_t *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);
ADC_read(buf);
ADCChannelSelect(ADC_CH_CURRENT);
ADC_read(buf);
}
static void ReadBatVolt(uint8_t *buf){
// Read data twice since the first data we get is previous data
ADCChannelSelect(ADC_CH_BAT);
ADC_read(buf);
@@ -236,371 +163,124 @@ static void ReadADCBat(uint8_t *buf){
ADC_read(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
#define VIN_GAIN_MID1_BOUNDARY1 5000 // 5 mV = 5,000,000 nV
#define VIN_GAIN_MID1_BOUNDARY2 300000 // 300 mV = 300,000,000 nV
#define VIN_GAIN_LARGE_BOUNDARY 250000 // 250 mV = 250,000,000 nV
// 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 AutoGainReadIin(uint8_t *buf){
int32_t RealCurrent = 0;
//#define GAIN_SMALL_BOUNDARY 8000 // 8 uA = 8,000,000 pA
//#define GAIN_MID_BOUNDARY1 3000 // 3 uA = 3,000,000 pA
//#define GAIN_MID_BOUNDARY2 90000 // 90 uA = 90,000,000 pA
//#define GAIN_LARGE_BOUNDARY 70000 // 70 uA = 70,000 nA
ReadADCIin(spi_ADC_rxbuf);
RealCurrent = DecodeADCValue(instru.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
/* for Elite1.4-re which 6.3kohm replaced by 10kohm */
// theoretical boundary <40, 30~1350, >1000 (uA)
#define GAIN_SMALL_BOUNDARY 40000 // 40 uA = 40,000,000 pA
#define GAIN_MID_BOUNDARY1 30000 // 30 uA = 30,000,000 pA
#define GAIN_MID_BOUNDARY2 1350000 // 1350 uA = 1350,000,000 pA
#define GAIN_LARGE_BOUNDARY 1000000 // 1000 uA = 1000,000 nA
return RealCurrent;
}
static int32_t AutoGainReadCurrent(uint8_t *buf){
static int32_t AutoGainReadVin(uint8_t *buf){
int32_t RealVolt = 0;
int32_t Real_Current = 0;
ReadADCVin(spi_ADC_rxbuf);
RealVolt = DecodeADCValue(instru.VinADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
if(INSTRUCTION.ADCGainLevel == GAIN_AUTO){
INSTRUCTION.ADCGainLevel = GAIN_200R;
}
return RealVolt;
ReadCurrent(spi_ADC_rxbuf);
Real_Current = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
return Real_Current;
}
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(instru.ADCGainLevel == I_GAIN_100R){
if(RealCurrent < I_GAIN_LARGE_BOUNDARY && RealCurrent > -1*I_GAIN_LARGE_BOUNDARY){
// switch to 1 level current(small)
if (RealCurrent < I_GAIN_MID1_BOUNDARY1 && RealCurrent > -1*I_GAIN_MID1_BOUNDARY1){
I_GAIN_3M_counter++;
if(I_GAIN_3M_counter > 2){
instru.ADCGainLevel = I_GAIN_3M;
IinADCGainControl(instru.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){
instru.ADCGainLevel = I_GAIN_100K;
IinADCGainControl(instru.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){
instru.ADCGainLevel = I_GAIN_3K;
IinADCGainControl(instru.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(instru.ADCGainLevel == I_GAIN_3K){
// switch to 4 level current(large)
if(RealCurrent > I_GAIN_MID2_BOUNDARY2 || RealCurrent < -1*I_GAIN_MID2_BOUNDARY2){
I_GAIN_100R_counter++;
if(I_GAIN_100R_counter > 2){
instru.ADCGainLevel = I_GAIN_100R;
IinADCGainControl(instru.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){
instru.ADCGainLevel = I_GAIN_3M;
IinADCGainControl(instru.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){
instru.ADCGainLevel = I_GAIN_100K;
IinADCGainControl(instru.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(instru.ADCGainLevel == I_GAIN_100K){
// switch to 1 level current(small)
if(RealCurrent < I_GAIN_MID1_BOUNDARY1 && RealCurrent > -1*I_GAIN_MID1_BOUNDARY1){
I_GAIN_3M_counter++;
if(I_GAIN_3M_counter > 2){
instru.ADCGainLevel = I_GAIN_3M;
IinADCGainControl(instru.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){
instru.ADCGainLevel = I_GAIN_100R;
IinADCGainControl(instru.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){
instru.ADCGainLevel = I_GAIN_3K;
IinADCGainControl(instru.ADCGainLevel);
I_GAIN_3K_counter = 0;
record_flag = false;
}
static void AutoGainChange(int32_t Real_Current){
if(INSTRUCTION.ADCGainLevel == GAIN_200R){
// switch to mid range current
if(Real_Current < GAIN_LARGE_BOUNDARY && Real_Current > -1*GAIN_LARGE_BOUNDARY){
// switch to small range current
if (Real_Current < GAIN_MID_BOUNDARY1 && Real_Current > -1*GAIN_MID_BOUNDARY1){
GAIN_200K_counter++;
if(GAIN_200K_counter > 5){
INSTRUCTION.ADCGainLevel = GAIN_200K;
GAIN_200K_counter = 0;
}
}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--;
GAIN_10K_counter++;
if(GAIN_10K_counter > 5){
INSTRUCTION.ADCGainLevel = GAIN_10K;
GAIN_10K_counter = 0;
}
}
}else{
if(GAIN_200K_counter > 0){
GAIN_200K_counter--;
}
if(GAIN_10K_counter > 0){
GAIN_10K_counter--;
}
}
else if(instru.ADCGainLevel == I_GAIN_3M){
if(RealCurrent > I_GAIN_SMALL_BOUNDARY || RealCurrent < -1*I_GAIN_SMALL_BOUNDARY){
// switch to 4 level current(large)
if(RealCurrent > I_GAIN_MID2_BOUNDARY2 || RealCurrent < -1*I_GAIN_MID2_BOUNDARY2){
I_GAIN_100R_counter++;
if(I_GAIN_100R_counter > 2){
instru.ADCGainLevel = I_GAIN_100R;
IinADCGainControl(instru.ADCGainLevel);
I_GAIN_100R_counter = 0;
record_flag = false;
}
}
else if(INSTRUCTION.ADCGainLevel == GAIN_10K){
// switch to large range current
if(Real_Current > GAIN_MID_BOUNDARY2 || Real_Current < -1*GAIN_MID_BOUNDARY2){
GAIN_200R_counter++;
if(GAIN_200R_counter > 5){
INSTRUCTION.ADCGainLevel = GAIN_200R;
GAIN_200R_counter = 0;
}
// switch to 3 level current
else if(RealCurrent > I_GAIN_MID1_BOUNDARY2 || RealCurrent < -1*I_GAIN_MID1_BOUNDARY2){
I_GAIN_3K_counter++;
if(I_GAIN_3K_counter > 2){
instru.ADCGainLevel = I_GAIN_3K;
IinADCGainControl(instru.ADCGainLevel);
I_GAIN_3K_counter = 0;
record_flag = false;
}
}
// switch to small range current
else if (Real_Current < GAIN_MID_BOUNDARY1 && Real_Current > -1*GAIN_MID_BOUNDARY1){
GAIN_200K_counter++;
if(GAIN_200K_counter > 5){
INSTRUCTION.ADCGainLevel = GAIN_200K;
GAIN_200K_counter = 0;
}
// switch to 2 level current
else{
I_GAIN_100K_counter++;
if(I_GAIN_100K_counter > 2){
instru.ADCGainLevel = I_GAIN_100K;
IinADCGainControl(instru.ADCGainLevel);
I_GAIN_100K_counter = 0;
record_flag = false;
}else{
if(GAIN_200R_counter > 0){
GAIN_200R_counter--;
}
if(GAIN_200K_counter > 0){
GAIN_200K_counter--;
}
}
}
else if(INSTRUCTION.ADCGainLevel == GAIN_200K){
// switch to mid range current
if(Real_Current > GAIN_SMALL_BOUNDARY || Real_Current < -1*GAIN_SMALL_BOUNDARY){
// switch to large range current
if(Real_Current > GAIN_MID_BOUNDARY2 || Real_Current < -1*GAIN_MID_BOUNDARY2){
GAIN_200R_counter++;
if(GAIN_200R_counter > 5){
INSTRUCTION.ADCGainLevel = GAIN_200R;
GAIN_200R_counter = 0;
}
}else{
GAIN_10K_counter++;
if(GAIN_10K_counter > 5){
INSTRUCTION.ADCGainLevel = GAIN_10K;
GAIN_10K_counter = 0;
}
}
}else{
if(I_GAIN_100R_counter > 0){
I_GAIN_100R_counter--;
}else{
if(GAIN_200R_counter > 0){
GAIN_200R_counter--;
}
if(I_GAIN_3K_counter > 0){
I_GAIN_3K_counter--;
}
if(I_GAIN_100K_counter > 0){
I_GAIN_100K_counter--;
if(GAIN_10K_counter > 0){
GAIN_10K_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(instru.VinADCGainLevel == VIN_GAIN_1M){
if(RealVin > VIN_GAIN_SMALL_BOUNDARY || RealVin < -1*VIN_GAIN_SMALL_BOUNDARY){
// switch to 3 level volt(large)
if (RealVin > VIN_GAIN_MID1_BOUNDARY2 || RealVin < -1*VIN_GAIN_MID1_BOUNDARY2){
VIN_GAIN_1K_counter++;
if(VIN_GAIN_1K_counter > 2){
instru.VinADCGainLevel = VIN_GAIN_1K;
VinADCGainControl(instru.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){
instru.VinADCGainLevel = VIN_GAIN_30K;
VinADCGainControl(instru.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(instru.VinADCGainLevel == VIN_GAIN_30K){
// switch to 1 level volt(small)
if(RealVin < VIN_GAIN_MID1_BOUNDARY1 && RealVin > -1*VIN_GAIN_MID1_BOUNDARY1){
VIN_GAIN_1M_counter++;
if(VIN_GAIN_1M_counter > 2){
instru.VinADCGainLevel = VIN_GAIN_1M;
VinADCGainControl(instru.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){
instru.VinADCGainLevel = VIN_GAIN_1K;
VinADCGainControl(instru.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(instru.VinADCGainLevel == VIN_GAIN_1K){
if(RealVin < VIN_GAIN_LARGE_BOUNDARY && RealVin > -1*VIN_GAIN_LARGE_BOUNDARY){
// switch to 1 level volt(small)
if (RealVin < VIN_GAIN_MID1_BOUNDARY1 && RealVin > -1*VIN_GAIN_MID1_BOUNDARY1){
VIN_GAIN_1M_counter++;
if(VIN_GAIN_1M_counter > 2){
instru.VinADCGainLevel = VIN_GAIN_1M;
VinADCGainControl(instru.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){
instru.VinADCGainLevel = VIN_GAIN_30K;
VinADCGainControl(instru.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;
uint32_t ADCValueSUM = 0;
uint32_t ADCValueAVG = 0;
uint16_t ADCValueAVG_RAW = 0;
#define avgcount 10000
// Red light for start acquiring data
Elite_led_color(COLOR_RED);
// CPUdelay(10);
for(int i=0; i<avgcount; i++){
CAL_ADC_write(ADC_channel);
CAL_ADC_read(spi_ADC_rxbuf);
CPUdelay(10);
CAL_ADC_write(ADC_channel);
CAL_ADC_read(spi_ADC_rxbuf);
CPUdelay(500);
ADCValueTemp = 0x0000FFFF & (((uint32_t) (spi_ADC_rxbuf[0]) << 8) | ((uint32_t) (spi_ADC_rxbuf[1])));
ADCValueSUM = ADCValueSUM + ADCValueTemp;
}
ADCValueAVG = ADCValueSUM / avgcount;
ADCValueAVG_RAW = (uint16_t) (ADCValueAVG & 0x0000FFFF);
// Blue light for data acquire done
Elite_led_color(COLOR_BLUE);
if (ADCValueAVG_RAW > 0x7FFF) {
ADCValueAVG_RAW = 0x0000;
}
// clean data
ADCValueAVG = 0;
ADCValueSUM = 0;
ADCValueTemp = 0;
// // Blue light for data acquire done
// Elite_led_color(COLOR_BLUE);
return ADCValueAVG_RAW;
}
#define ReadADCVolt(x) ((x==0)? ReadVoutVolt(spi_ADC_rxbuf) : ReadVolt(spi_ADC_rxbuf))
#endif
@@ -0,0 +1,32 @@
#ifndef ELITECCC
#define ELITECCC
#include "EliteCCMode.h"
// XXX : should we reset DAC output after STOP?
static void CCModeReverseCurrent(CCCMode *CCC){
if(CCC->StandBy){
if(CT.StandByCounter == CCC->StandByTime){
CCC->StandBy = false;
CT.StandByCounter = 0;
}
else{
CT.StandByCounter ++;
}
}
else{
// reverse charge/discharge
if(CCC->BatteryV == CCC->VMax){
CCC->StandBy = true;
CCC->value = CCC->DischargeCurrent;
}
else if(CCC->BatteryV == CCC->VMin){
CCC->StandBy = true;
CCC->value = CCC->ChargeCurrent;
}
}
}
#endif
@@ -2,8 +2,8 @@
#ifndef ELITECCMODE
#define ELITECCMODE
#define Vset instru.Vset
#define DELTAVOLTMAX 2000000 //2000000 = 10mV
#define Vset INSTRUCTION.Vset
#define DELTAVOLTMAX 100000
/* Transform setting CC into IUC
*
@@ -11,67 +11,241 @@
* Real current value : -15.00000 ~ 15.00000 mA
* => user code = 1500000 mapping to 0.00000 mA
*/
static void cc_vscan(void)
{
struct wm_cc_ctx_t *cc = (struct wm_cc_ctx_t *)wm_get();
struct wm_meas_t *m = &cc->measure;
uint16_t divisionRate;
int32_t deltaI;
int32_t deltaV;
int32_t Iin;
int32_t Vin;
if (vscanReset) {
Vset = 0;
if (cc->_charge == 0) {
cc->_Iset = instru.constantCurrent * 200 * (-1);
//[50pA] //controller UI 15000uA => Elite 1500000 => 1500000 * 10 * 1000 / 50 [50pA];
static void CC_Plot(WorkMode *WorkModeData){
switch (INSTRUCTION.eliteFxn) {
case IT_CURVE:{
#define CURRENT_MODE WorkModeData->IT
break;
}
Iin = m->_measureCurrent * 20; //[50pA] nA => 50pA
Vin = m->_measureVin * 200; //[5nV]
Vset = Vin + cc->_Iset / 20 ; //[5nV]
if (Vset >= 1100000000) { // 5.5V
Vset = 1100000000;
} else if (Vset <= -1000000000) { //-5V
Vset = -1000000000;
case VT_CURVE:{
#define CURRENT_MODE WorkModeData->VT
break;
}
case ZT_CURVE:{
#define CURRENT_MODE WorkModeData->RT
break;
}
case IV_CURVE:{
#define CURRENT_MODE WorkModeData->IV
break;
}
case CV_CURVE:{
#define CURRENT_MODE WorkModeData->CV
break;
}
case CONSTANT_CURRENT:{
#define CURRENT_MODE WorkModeData->CC
break;
}
case CYCLIC_VOLTAMMETRY:{
#define CURRENT_MODE WorkModeData->CV3
break;
}
case LINEAR_SWEEP_VOLTAMMETRY:{
#define CURRENT_MODE WorkModeData->LSV
break;
}
case CONSTANT_VSCAN:{
#define CURRENT_MODE WorkModeData->CVSCAN
break;
}
default: {
break;
}
}
if (!vscanReset) {
Iin = m->_measureCurrent * 20; //[50pA] nA => 50pA
deltaI = Iin - cc->_Iset;
static uint8_t ADCSwitch = 0;
static uint8_t BatSwitch = 0;
static int32_t VoltData = 0;
if (deltaI > 2000000 || deltaI < -2000000) { //100uA
divisionRate = 1;
} else {
divisionRate = 20;
if(batteryCheck_flag){
if(ADCSwitch == 0){
if(BatSwitch == 0){ /**read Iin(buffer),read bat**/
if(INSTRUCTION.AutoGainEnable){
CURRENT_MODE->_measureCurrent = AutoGainReadCurrent(spi_ADC_rxbuf);
AutoGainChange(CURRENT_MODE->_measureCurrent);
}else{
ReadCurrent(spi_ADC_rxbuf);
CURRENT_MODE->_measureCurrent = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
}
InputNotify(NOTIFY_CURRENT, CURRENT_MODE->_measureCurrent);
DACenable(WorkModeData, VoltData, AFTER_READ_I);
ReadBatVolt(spi_ADC_rxbuf);
BatSwitch++;
}else if(BatSwitch == 1){
ReadBatVolt(spi_ADC_rxbuf);
BatSwitch++;
}else if(BatSwitch == 2){
headstage_battery_volt();
ReadCurrent(spi_ADC_rxbuf);
batteryCheck_flag = false;
BatSwitch = 0;
ADCSwitch = 3;
}
}
else if(ADCSwitch == 1 || ADCSwitch == 3){
if(BatSwitch == 0){ /**read Bat**/
ReadBatVolt(spi_ADC_rxbuf);
BatSwitch++;
}else if(BatSwitch == 1){
ReadBatVolt(spi_ADC_rxbuf);
BatSwitch++;
}else if(BatSwitch == 2){
headstage_battery_volt();
ReadCurrent(spi_ADC_rxbuf);
batteryCheck_flag = false;
BatSwitch = 0;
ADCSwitch = 3;
}
}
else if(ADCSwitch == 2){
if(BatSwitch == 0){ /**read V(buffer),read bat**/
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
if(CURRENT_MODE->_VoViSwitch == 0x01){
CURRENT_MODE->_measureVin = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
VoltData = CURRENT_MODE->_measureVin;
}else if(CURRENT_MODE->_VoViSwitch == 0x00){
CURRENT_MODE->_measureVout = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_DAC, spi_ADC_rxbuf);
VoltData = CURRENT_MODE->_measureVout;
}
InputNotify(NOTIFY_VOLT, VoltData);
DACenable(WorkModeData, VoltData, AFTER_READ_V);
ReadBatVolt(spi_ADC_rxbuf);
BatSwitch++;
}else if(BatSwitch == 1){
ReadBatVolt(spi_ADC_rxbuf);
BatSwitch++;
}else if(BatSwitch == 2){
headstage_battery_volt();
ReadCurrent(spi_ADC_rxbuf);
batteryCheck_flag = false;
BatSwitch = 0;
ADCSwitch = 3;
}
}
}else{
BatSwitch = 0;
if(ADCSwitch == 0){ /**read Iin(buffer),read V**/
if(INSTRUCTION.AutoGainEnable){
CURRENT_MODE->_measureCurrent = AutoGainReadCurrent(spi_ADC_rxbuf);
AutoGainChange(CURRENT_MODE->_measureCurrent);
}else{
ReadCurrent(spi_ADC_rxbuf);
CURRENT_MODE->_measureCurrent = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
}
InputNotify(NOTIFY_CURRENT, CURRENT_MODE->_measureCurrent);
DACenable(WorkModeData, VoltData, AFTER_READ_I);
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
ADCSwitch++;
}
else if(ADCSwitch == 1){ /**read V**/
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
ADCSwitch++;
}
else if(ADCSwitch == 2){ /**read V(buffer),read Iin**/
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
if(CURRENT_MODE->_VoViSwitch == 0x01 || CURRENT_MODE->_VoViSwitch == 0x02){
CURRENT_MODE->_measureVin = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
VoltData = CURRENT_MODE->_measureVin;
}else if(CURRENT_MODE->_VoViSwitch == 0x00){
CURRENT_MODE->_measureVout = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_DAC, spi_ADC_rxbuf);
VoltData = CURRENT_MODE->_measureVout;
}
if(INSTRUCTION.VoViSwitch == 0x02){
int32_t Vscan = (Vset / 200 - CURRENT_MODE->_measureVin);
Vscan = (int32_t)(Vscan);//[1uV]
InputNotify(NOTIFY_VOLT, Vscan);
}else{
InputNotify(NOTIFY_VOLT, VoltData);
}
DACenable(WorkModeData, VoltData, AFTER_READ_V);
ReadCurrent(spi_ADC_rxbuf);
ADCSwitch++;
}
else if(ADCSwitch == 3){ /**read Iin**/
ReadCurrent(spi_ADC_rxbuf);
ADCSwitch = 0;
}
}
#undef CURRENT_MODE
}
static void CC_Vscan(CCMode *CC){
static int32_t Iin = 0;
static int32_t deltaI = 0;
static int32_t deltaV = 0;
uint16_t divisionRate;
if(vscanReset){
Vset = 0;
if(CC->_charge == 0){
CC->_Iset *= -1;
}
Iin = CC->_measureCurrent * 20; //[50pA] nA => 50pA
deltaI = Iin - CC->_Iset;
if(deltaI > 20000000 || deltaI < -20000000){ //1mA
divisionRate = 1000;
}else{
divisionRate = 10;
}
deltaV = -1 * (deltaI / divisionRate); //-5 * deltaI / 5000 //pV=> 5nV
if (deltaV > DELTAVOLTMAX) { //2000000 = 10mV
if(deltaV > DELTAVOLTMAX){ //100000 = 500uV
deltaV = DELTAVOLTMAX;
} else if (deltaV < (-DELTAVOLTMAX)) {
}else if(deltaV < (-DELTAVOLTMAX)){
deltaV = (-DELTAVOLTMAX);
}
Vset = Vset + deltaV; //[5nV]
if (Vset >= 1100000000) { // 5.5V
Vset = 1100000000;
} else if (Vset <= -1000000000) { //-5V
Vset = -1000000000;
}
if (Vset <= cc->_Vmin) {
Vset = cc->_Vmin;
} else if (Vset >= cc->_Vmax) {
Vset = cc->_Vmax;
if(Vset <= CC->_Vmin){
Vset = CC->_Vmin;
}else if(Vset >= CC->_Vmax){
Vset = CC->_Vmax;
}
}
if(!vscanReset){
Iin = CC->_measureCurrent * 20; //[50pA] nA => 50pA
deltaI = Iin - CC->_Iset;
if(deltaI > 20000000 || deltaI < -20000000){ //1mA
divisionRate = 1000;
}else{
divisionRate = 10;
}
deltaV = -1 * (deltaI / divisionRate); //-5 * deltaI / 5000 //pV=> 5nV
if(deltaV > DELTAVOLTMAX){ //100000 = 500uV
deltaV = DELTAVOLTMAX;
}else if(deltaV < (-DELTAVOLTMAX)){
deltaV = (-DELTAVOLTMAX);
}
Vset = Vset + deltaV; //[5nV]
if(Vset <= CC->_Vmin){
Vset = CC->_Vmin;
}else if(Vset >= CC->_Vmax){
Vset = CC->_Vmax;
}
}
// int32_t RealV;
// RealV = (int32_t)(deltaV);
// InputNotify(NOTIFY_IMPEDANCE, RealV);
}
#endif
@@ -1,27 +1,25 @@
#ifndef ELITECV3
#define ELITECV3
#define Vset instru.Vset
#define Vset INSTRUCTION.Vset
static void cv_volt_out(void)
{
struct wm_cv_ctx_t *cv = (struct wm_cv_ctx_t *)wm_get();
struct wm_meas_t *m = &cv->measure;
uint16_t DACOutCode;
int32_t Vin;
int32_t Vout;
int32_t DeltaVout;
static uint16_t CV3Curve(CV3Mode *CV3){
static uint16_t DACOutCode;
static int32_t Vin;
static int32_t Vout;
static int32_t DeltaVout;
Vin = m->_measureVin * 200;//[5nV]
if (DACReset) {
Vin = CV3->_measureVin * 200;//[5nV]
if(DACReset){
Vout = Vset + Vin;
} else {
DACReset = false;
}else{
DeltaVout = Vset - (Vout - Vin);
Vout = Vout + DeltaVout;
}
instru.VoltConstant = Vout / 40000 + 25000;//5nV=>usercode
DACOutCode = Usercode_Correction_to_DAC(instru.VoutGainLevel, instru.VoltConstant);
INSTRUCTION.VoltConstant = Vout / 40000 + 25000;//5nV=>usercode
DACOutCode = Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant);
int32_t RealV2;
RealV2 = (int32_t)((Vout - Vin) / 200);//[1uV]
@@ -33,110 +31,100 @@ static void cv_volt_out(void)
DAC_outputV(DACOutCode);
return;
return DACOutCode;
}
static void cv_vscan(void)
{
struct wm_cv_ctx_t *cv = (struct wm_cv_ctx_t *)wm_get();
static bool VminCounter;
static bool VmaxCounter;
static void CV3_Vscan(CV3Mode *CV3){
static int16_t VminCounter;
static int16_t VmaxCounter;
static uint16_t CycleCounter;
NotifyCycleNumber = (instru.cycleNumber - cv->_cycleNumber + 1);
NotifyCycleNumber = (INSTRUCTION.cycleNumber - CV3->_cycleNumber + 1);
if (vscanReset) {
VmaxCounter = false;
VminCounter = false;
if(vscanReset){
VmaxCounter = 0;
VminCounter = 0;
CycleCounter = 0;
if (instru.directionInit == 1) {
cv->_direction_up = true;
cv->_current_direction_up = true;
} else {
cv->_direction_up = false;
cv->_current_direction_up = false;
if(INSTRUCTION.directionInit == 1){
CV3->_direction_up = true;
CV3->_current_direction_up = true;
}else{
CV3->_direction_up = false;
CV3->_current_direction_up = false;
}
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
if (instru.step <= 10) {
cv->_Vstep = instru.step * instru.VsetRate / 5;
} else {
cv->_Vstep = instru.step / 5 * instru.VsetRate;
if(INSTRUCTION.step <= 10){
CV3->_Vstep = INSTRUCTION.step * INSTRUCTION.VsetRate / 5;
}else{
CV3->_Vstep = INSTRUCTION.step / 5 * INSTRUCTION.VsetRate;
}
if (cv->_Vmin == cv->_Vinit) {
VminCounter = true;
if(CV3->_Vmin == CV3->_Vinit){
VminCounter = -1;
}
if (cv->_Vmax == cv->_Vinit) {
VmaxCounter = true;
if(CV3->_Vmax == CV3->_Vinit){
VmaxCounter = -1;
}
Vset = cv->_Vinit;
Vset = CV3->_Vinit;
}
if (!vscanReset) {
if ((instru.Vinit < instru.Ve1 && instru.Vinit < instru.Ve2) ||
(instru.Vinit > instru.Ve1 && instru.Vinit > instru.Ve2)
) {
if (cv->_current_direction_up) {
Vset = Vset + cv->_Vstep * GPT.GptimerMultiple;
} else {
Vset = Vset - cv->_Vstep * GPT.GptimerMultiple;
}
if(!vscanReset){
if (Vset >= CV3->_Vmax){
VmaxCounter++;
}else if (Vset <= CV3->_Vmin){
VminCounter++;
}
if (instru.Vinit < instru.Ve1 && instru.Vinit < instru.Ve2) {
if (Vset == cv->_Vmin) {
VminCounter = true;
instru.Vinit = instru.Vmin;
cv->_Vinit = cv->_Vmin;
}
} else if (instru.Vinit > instru.Ve1 && instru.Vinit > instru.Ve2) {
if (Vset == cv->_Vmax) {
VmaxCounter = true;
instru.Vinit = instru.Vmax;
cv->_Vinit = cv->_Vmax;
}
}
} else {
if (Vset >= cv->_Vmax) {
VmaxCounter = true;
} else if (Vset <= cv->_Vmin) {
VminCounter = true;
}
if (CV3->_current_direction_up){
Vset = Vset + CV3->_Vstep;
}else{
Vset = Vset - CV3->_Vstep;
}
if (cv->_current_direction_up) {
Vset = Vset + cv->_Vstep * GPT.GptimerMultiple;
} else {
Vset = Vset - cv->_Vstep * GPT.GptimerMultiple;
}
if (VmaxCounter && VminCounter) {
if (cv->_direction_up && cv->_current_direction_up) {
if (Vset >= cv->_Vinit) {
cv->_cycleNumber--;
VminCounter = false;
VmaxCounter = false;
}
}
if (!cv->_direction_up && !cv->_current_direction_up) {
if (Vset <= cv->_Vinit) {
cv->_cycleNumber--;
VminCounter = false;
VmaxCounter = false;
if(VmaxCounter != 0 && VminCounter != 0){
if(VmaxCounter == VminCounter && CV3->_direction_up && CV3->_current_direction_up){
if(CycleCounter != VmaxCounter){
if(Vset >= CV3->_Vinit){
CV3->_cycleNumber--;
CycleCounter = VmaxCounter; //VmaxCounter = VminCounter = CycleCounter
}
}
}
if (Vset >= cv->_Vmax) {
cv->_current_direction_up = false;
} else if (Vset <= cv->_Vmin) {
cv->_current_direction_up = true;
}
/*stop condition*/
if (cv->_cycleNumber == 0) {
PeriodicEvent = false;
if(VmaxCounter == VminCounter && !CV3->_direction_up && !CV3->_current_direction_up){
if(CycleCounter != VmaxCounter){
if(Vset <= CV3->_Vinit){
CV3->_cycleNumber--;
CycleCounter = VmaxCounter; //VmaxCounter = VminCounter = CycleCounter
}
}
}
}
if (Vset >= CV3->_Vmax){
CV3->_current_direction_up = false;
}else if (Vset <= CV3->_Vmin){
CV3->_current_direction_up = true;
}
/*stop condition*/
if(CV3->_cycleNumber == 0){
// PeriodicEvent = false;
InitEliteFlag();
INSTRUCTION.eliteFxn = CONSTANT_CURRENT;
INSTRUCTION.sampleRate = 15;
INSTRUCTION.charge = 0x01;
INSTRUCTION.constantCurrent = 0x00;
INSTRUCTION.Vmax = 0xC350;
INSTRUCTION.Vmin = 0x0000;
INSTRUCTION.notifyRate = 500;
INSTRUCTION.VoViSwitch = 0x02;//read Vscan = Vout - Vin
}
}
// int32_t RealV;
// RealV = (int32_t)(Vset / 500);//[1uV]
// InputNotify(NOTIFY_VOLT, RealV);
}
#endif
@@ -2,82 +2,214 @@
#ifndef ELITECV
#define ELITECV
static void iv_cy_vscan(void)
{
struct wm_iv_cy_ctx_t *iv_cy = (struct wm_iv_cy_ctx_t *)wm_get();
static bool VminCounter;
static bool VmaxCounter;
static uint16_t SWVCurve(WorkMode *WorkModeData) {
static uint8_t counter;
static uint16_t outputV;
static uint16_t Volt;
static bool direction_up;
NotifyCycleNumber = (instru.cycleNumber - iv_cy->_cycleNumber + 1);
// reset origin volt at the begin
if (DACReset) {
Volt = INSTRUCTION.Ve1;
outputV = INSTRUCTION.Ve1;
if (INSTRUCTION.Ve1 < INSTRUCTION.Ve2)
direction_up = true;
else
direction_up = false;
counter = 1;
DACReset = false;
}
if (counter == 2 * PulseWidth)
counter = 1;
else
counter++;
// output a certain volt
outputV = Volt;
DAC_outputV(outputV);
// VoltValue = (ramp1*16 + ramp0/16) * 3.05;
// check if we reach the final volt
if ((outputV >= INSTRUCTION.Ve2 && direction_up) || (outputV <= INSTRUCTION.Ve2 && !direction_up)) {
PeriodicEvent = false;
DACReset = true;
}
// prepare the next output volt
if (direction_up) {
if (counter == PulseWidth)
Volt = Volt + Amplitude;
else if (counter == 2 * PulseWidth)
Volt = Volt - (Amplitude - INSTRUCTION.step);
else
Volt = Volt;
} else {
if (counter == PulseWidth)
Volt = Volt - Amplitude;
else if (counter == 2 * PulseWidth)
Volt = Volt + (Amplitude - INSTRUCTION.step);
else
Volt = Volt;
}
return outputV;
}
static uint16_t DPVCurve(WorkMode *WorkModeData) {
static uint8_t counter;
static uint16_t Volt1;
static uint16_t Volt2;
static uint16_t outputV;
static bool direction_up;
// reset origin volt at the begin
if (DACReset) {
if (INSTRUCTION.Ve1 < INSTRUCTION.Ve2)
direction_up = true;
else
direction_up = false;
Volt1 = INSTRUCTION.Ve1;
if (direction_up)
Volt2 = INSTRUCTION.Ve1 + Amplitude;
else
Volt2 = INSTRUCTION.Ve1 - Amplitude;
counter = 1;
DACReset = false;
}
if (counter == PulsePeriod)
counter = 1;
else
counter++;
// output a certain volt
if (counter <= (PulsePeriod - PulseWidth)) {
outputV = Volt1;
DAC_outputV(Volt1);
} else {
outputV = Volt2;
DAC_outputV(Volt2);
}
// VoltValue = (ramp1*16 + ramp0/16) * 3.05;
// check if we reach the final volt
if (((outputV >= INSTRUCTION.Ve2) && direction_up) || ((outputV <= INSTRUCTION.Ve2) && !direction_up)) {
PeriodicEvent = false;
DACReset = true;
}
// check overflow/underflow and prepare for next output
if (direction_up) {
if (Volt1 + INSTRUCTION.step < Volt1)
Volt1 = 0xffff;
else
Volt1 = Volt1 + INSTRUCTION.step;
if (Volt2 + INSTRUCTION.step < Volt2)
Volt2 = 0xffff;
else
Volt2 = Volt2 + INSTRUCTION.step;
} else {
if (Volt1 - INSTRUCTION.step > Volt1)
Volt1 = 0x0000;
else
Volt1 = Volt1 - INSTRUCTION.step;
if (Volt2 - INSTRUCTION.step > Volt2)
Volt2 = 0x0000;
else
Volt2 = Volt2 - INSTRUCTION.step;
}
if (counter + 1 <= (PulsePeriod - PulseWidth)) {
return Volt1;
} else {
return Volt2;
}
}
static void CV_Vscan(CVMode *CV){
static int16_t VminCounter;
static int16_t VmaxCounter;
static uint16_t CycleCounter;
NotifyCycleNumber = (INSTRUCTION.cycleNumber - CV->_cycleNumber + 1);
if(vscanReset){
VmaxCounter = false;
VminCounter = false;
VmaxCounter = 0;
VminCounter = 0;
CycleCounter = 0;
if(instru.directionInit == 1){
iv_cy->_direction_up = true;
iv_cy->_current_direction_up = true;
}else if(instru.directionInit == 0){
iv_cy->_direction_up = false;
iv_cy->_current_direction_up = false;
if(INSTRUCTION.directionInit == 1){
CV->_direction_up = true;
CV->_current_direction_up = true;
}else if(INSTRUCTION.directionInit == 0){
CV->_direction_up = false;
CV->_current_direction_up = false;
}
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
if(instru.step <= 10){
iv_cy->_Vstep = instru.step * instru.VsetRate / 5;
if(INSTRUCTION.step <= 10){
CV->_Vstep = INSTRUCTION.step * INSTRUCTION.VsetRate / 5;
}else{
iv_cy->_Vstep = instru.step / 5 * instru.VsetRate;
CV->_Vstep = INSTRUCTION.step / 5 * INSTRUCTION.VsetRate;
}
if(iv_cy->_Vmin == iv_cy->_Vinit){
VminCounter = true;
if(CV->_Vmin == CV->_Vinit){
VminCounter = -1;
}
if(iv_cy->_Vmax == iv_cy->_Vinit){
VmaxCounter = true;
if(CV->_Vmax == CV->_Vinit){
VmaxCounter = -1;
}
Vset = iv_cy->_Vinit;
Vset = CV->_Vinit;
}
if(!vscanReset){
if (Vset >= iv_cy->_Vmax){
VmaxCounter = true;
}else if (Vset <= iv_cy->_Vmin){
VminCounter = true;
if (Vset >= CV->_Vmax){
VmaxCounter++;
}else if (Vset <= CV->_Vmin){
VminCounter++;
}
if (iv_cy->_current_direction_up){
Vset = Vset + iv_cy->_Vstep * GPT.GptimerMultiple;
if (CV->_current_direction_up){
Vset = Vset + CV->_Vstep;
}else{
Vset = Vset - iv_cy->_Vstep * GPT.GptimerMultiple;
Vset = Vset - CV->_Vstep;
}
if(VmaxCounter && VminCounter){
if(iv_cy->_direction_up && iv_cy->_current_direction_up){
if(Vset >= iv_cy->_Vinit){
iv_cy->_cycleNumber--;
VminCounter = false;
VmaxCounter = false;
if(VmaxCounter != 0 && VminCounter != 0){
if(VmaxCounter == VminCounter && CV->_direction_up && CV->_current_direction_up){
if(CycleCounter != VmaxCounter){
if(Vset >= CV->_Vinit){
CV->_cycleNumber--;
CycleCounter = VmaxCounter; //VmaxCounter = VminCounter = CycleCounter
}
}
}
if(!iv_cy->_direction_up && !iv_cy->_current_direction_up){
if(Vset <= iv_cy->_Vinit){
iv_cy->_cycleNumber--;
VminCounter = false;
VmaxCounter = false;
if(VmaxCounter == VminCounter && !CV->_direction_up && !CV->_current_direction_up){
if(CycleCounter != VmaxCounter){
if(Vset <= CV->_Vinit){
CV->_cycleNumber--;
CycleCounter = VmaxCounter; //VmaxCounter = VminCounter = CycleCounter
}
}
}
}
if (Vset >= iv_cy->_Vmax){
iv_cy->_current_direction_up = false;
}else if (Vset <= iv_cy->_Vmin){
iv_cy->_current_direction_up = true;
if (Vset >= CV->_Vmax){
CV->_current_direction_up = false;
}else if (Vset <= CV->_Vmin){
CV->_current_direction_up = true;
}
/*stop condition*/
if(iv_cy->_cycleNumber == 0){
PeriodicEvent = false;
if(CV->_cycleNumber == 0){
reset();
}
}
}
@@ -1,27 +1,25 @@
#ifndef ELITECVSCAN
#define ELITECVSCAN
#define Vset instru.Vset
#define Vset INSTRUCTION.Vset
static void ca_volt_out(void)
{
struct wm_ca_ctx_t *ca = (struct wm_ca_ctx_t *)wm_get();
struct wm_meas_t *m = &ca->measure;
uint16_t DACOutCode;
int32_t Vin;
int32_t Vout;
int32_t DeltaVout;
static uint16_t CVSCANCurve(CVSCANMode *CVSCAN){
static uint16_t DACOutCode;
static int32_t Vin;
static int32_t Vout;
static int32_t DeltaVout;
Vin = m->_measureVin * 200;//[5nV]
if (DACReset) {
Vin = CVSCAN->_measureVin * 200;//[5nV]
if(DACReset){
Vout = Vset + Vin;
} else {
DACReset = false;
}else{
DeltaVout = Vset - (Vout - Vin);
Vout = Vout + DeltaVout;
}
instru.VoltConstant = Vout / 40000 + 25000;//5nV=>usercode
DACOutCode = Usercode_Correction_to_DAC(instru.VoutGainLevel, instru.VoltConstant);
INSTRUCTION.VoltConstant = Vout / 40000 + 25000;//5nV=>usercode
DACOutCode = Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant);
int32_t RealV2;
RealV2 = (int32_t)((Vout - Vin) / 200);//[1uV]
@@ -33,19 +31,17 @@ static void ca_volt_out(void)
DAC_outputV(DACOutCode);
return;
return DACOutCode;
}
static void ca_vscan(void)
{
struct wm_ca_ctx_t *ca = (struct wm_ca_ctx_t *)wm_get();
static void CVSCAN_Vscan(CVSCANMode *CVSCAN){
if(vscanReset){
Vset = ca->_Vinit;
Vset = CVSCAN->_Vinit;
}
if(!vscanReset){
Vset = ca->_Vinit;
Vset = CVSCAN->_Vinit;
}
}
#endif
@@ -52,29 +52,9 @@ static uint16_t DAC_outputV(uint16_t voltLV) {
spi_DACtxbuf[2] = v2;
DAC_SPI(SPI_DAC_SIZE, spi_DACtxbuf, spi_rxbuf);
return voltLV;
}
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);
}
}
#endif
static int32_t User2Real(uint16_t UserCode){
@@ -82,40 +62,4 @@ static int32_t User2Real(uint16_t UserCode){
return (int32_t)((UserCode - 25000) / 5);
}
// 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
static void AutoGainChangeVout(int32_t userCode){
int32_t RealVolt = (userCode - 25000) * 200; // (userCode - 25000) / 5 * 1000 [1uV]
// switch to 1 level volt(small) 15K
// switch to 2 level volt(large) 240K
if(instru.VoutGainLevel == VOUT_GAIN_AUTO){
instru.VoutGainLevel = VOUT_GAIN_15K;
VoutGainControl(instru.VoutGainLevel);
record_flag = false;
}
if(instru.VoutGainLevel == VOUT_GAIN_15K){
if(RealVolt > DAC_VOUT_GAIN_LARGE_BOUNDARY || RealVolt < -1 * DAC_VOUT_GAIN_LARGE_BOUNDARY){
// switch to 2 level volt(large)
instru.VoutGainLevel = VOUT_GAIN_240K;
VoutGainControl(instru.VoutGainLevel);
record_flag = false;
}
}
else if(instru.VoutGainLevel == VOUT_GAIN_240K){
if(RealVolt < DAC_VOUT_GAIN_SMALL_BOUNDARY && RealVolt > -1 * DAC_VOUT_GAIN_SMALL_BOUNDARY ){
// switch to 1 level volt(small)
instru.VoutGainLevel = VOUT_GAIN_15K;
VoutGainControl(instru.VoutGainLevel);
record_flag = false;
}
}
}
#endif
@@ -7,6 +7,7 @@ struct _CT{
uint32_t SampleRate_counter;
uint16_t StepTimeCounter;
uint16_t NotifyCounter;
uint32_t StandByCounter;
}CT = {0};
// GPT counter
@@ -20,10 +21,15 @@ struct _GPT{
uint32_t LeadTimeCounter;
uint32_t BatteryADCCounter;
uint32_t BatteryCheckCounter;
uint32_t GptimerMultiple;
uint32_t StiCounter;
}GPT = {0};
static void InitCT(){
CT.SampleRate_counter = 1;
CT.StepTimeCounter = 1;
CT.NotifyCounter = 1;
CT.StandByCounter = 0;
}
static void InitGPT(){
GPT.GptimerCounter = 0;
GPT.GptimerCounter0 = 0;
@@ -34,6 +40,5 @@ static void InitGPT(){
GPT.LeadTimeCounter = 0;
GPT.BatteryADCCounter = 0;
GPT.BatteryCheckCounter = 0;
GPT.StiCounter = 0;
}
#endif
@@ -0,0 +1,79 @@
#ifndef ELITEIT
#define ELITEIT
static void IT_Plot(WorkMode *WorkModeData) {
switch (INSTRUCTION.eliteFxn) {
case IT_CURVE:{
#define CURRENT_MODE WorkModeData->IT
break;
}
case VT_CURVE:{
#define CURRENT_MODE WorkModeData->VT
break;
}
case ZT_CURVE:{
#define CURRENT_MODE WorkModeData->RT
break;
}
case IV_CURVE:{
#define CURRENT_MODE WorkModeData->IV
break;
}
case CV_CURVE:{
#define CURRENT_MODE WorkModeData->CV
break;
}
case CONSTANT_CURRENT:{
#define CURRENT_MODE WorkModeData->CC
break;
}
case CYCLIC_VOLTAMMETRY:{
#define CURRENT_MODE WorkModeData->CV3
break;
}
case LINEAR_SWEEP_VOLTAMMETRY:{
#define CURRENT_MODE WorkModeData->LSV
break;
}
case CONSTANT_VSCAN:{
#define CURRENT_MODE WorkModeData->CVSCAN
break;
}
default: {
break;
}
}
static uint8_t ADCSwitch = 0;
if(batteryCheck_flag){
EliteADCBattery();
if(!batteryCheck_flag){
ReadCurrent(spi_ADC_rxbuf);
ADCSwitch = 2;
}
}else{
if(ADCSwitch == 0){ /**read Iin(buffer)**/
if(INSTRUCTION.AutoGainEnable){
CURRENT_MODE->_measureCurrent = AutoGainReadCurrent(spi_ADC_rxbuf);
AutoGainChange(CURRENT_MODE->_measureCurrent);
}else{
ReadCurrent(spi_ADC_rxbuf);
CURRENT_MODE->_measureCurrent = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
}
InputNotify(NOTIFY_CURRENT, CURRENT_MODE->_measureCurrent);
ADCSwitch++;
}
else if(ADCSwitch == 1){ /**read Iin**/
ReadCurrent(spi_ADC_rxbuf);
ADCSwitch++;
}
else if(ADCSwitch == 2){ /**read Iin**/
ReadCurrent(spi_ADC_rxbuf);
ADCSwitch = 0;
}
}
#undef CURRENT_MODE
}
#endif
@@ -2,61 +2,208 @@
#ifndef ELITEIV
#define ELITEIV
#define Vset instru.Vset
#define Vset INSTRUCTION.Vset
static void iv_vscan(void)
{
struct wm_iv_ctx_t *iv = (struct wm_iv_ctx_t *)wm_get();
static void DACenable(WorkMode *WorkModeData, int32_t VoltData ,uint8_t afterRead){
if(afterRead == AFTER_READ_I){
switch (INSTRUCTION.eliteFxn) {
case CONSTANT_CURRENT:{
CC_Vscan(WorkModeData->CC);
OneWayVoltScan();
break;
}
case IV_CURVE:
case CV_CURVE:
case ZT_CURVE:
case IT_CURVE:
case VT_CURVE:
case CYCLIC_VOLTAMMETRY:
case LINEAR_SWEEP_VOLTAMMETRY:
case CONSTANT_VSCAN:{
break;
}
default:{
break;
}
}
}else if(afterRead == AFTER_READ_V){
switch (INSTRUCTION.eliteFxn) {
case IV_CURVE:
case CV_CURVE:{
OneWayVoltScan();
break;
}
case ZT_CURVE:{
CalcuResistance(WorkModeData->RT, VoltData);
break;
}
case IT_CURVE:
case VT_CURVE:
case CONSTANT_CURRENT:{
break;
}
case CYCLIC_VOLTAMMETRY:{
CV3Curve(WorkModeData->CV3);
break;
}
case LINEAR_SWEEP_VOLTAMMETRY:{
LSVCurve(WorkModeData->LSV);
break;
}
case CONSTANT_VSCAN:{
CVSCANCurve(WorkModeData->CVSCAN);
break;
}
default:{
break;
}
}
}
}
if (vscanReset) {
if (instru.directionInit == 1) {
iv->_direction_up = true;
iv->_current_direction_up = true;
} else if (instru.directionInit == 0) {
iv->_direction_up = false;
iv->_current_direction_up = false;
static void CalcuResistance(RTMode *RT, int32_t VoltData){
/* Elite 100 = 100R
Elite 1000 = 1KR
Elite 10000 = 10KR
Elite 100000 = 100KR
Elite 1000000 = 1MR
*/
static int32_t resister_32 = 0;
int32_t Vtemp;
Vtemp = (VoltData * 1000) - (RT->_measureCurrent * 10); //V = Vin - Iin * 10
resister_32 = Vtemp / RT->_measureCurrent; //R = V / Iin;
InputNotify(NOTIFY_IMPEDANCE, resister_32);
}
static uint16_t OneWayVoltScan() {
static uint16_t DACOutCode;
static int32_t Vout;
static int32_t DeltaVout;
if(DACReset){
Vout = Vset;
DACReset = false;
}else{
DeltaVout = Vset - (Vout);
Vout = Vout + DeltaVout;
}
INSTRUCTION.VoltConstant = Vout / 40000 + 25000; //5nV=>usercode
DACOutCode = Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant);
DAC_outputV(DACOutCode);
if ((INSTRUCTION.eliteFxn == IV_CURVE)||(INSTRUCTION.eliteFxn == CV_CURVE)||(INSTRUCTION.eliteFxn == CONSTANT_CURRENT)){
int32_t RealV;
RealV = (int32_t)(Vout / 200);//[1uV]
InputNotify(NOTIFY_IMPEDANCE, RealV);
}
return DACOutCode;
}
static void IV_Plot(IVMode *IV) {
/**********************************************
CURRENT_MODE->_VoViSwitch : 1 read Vin volt
->_VoViSwitch : 0 read Vout volt
***********************************************/
static uint8_t VoltCurrentSwitch = 0;
if(VoltCurrentSwitch == 0){ /**read Iin(buffer),read Vin**/
// read current
if(INSTRUCTION.AutoGainEnable){
IV->_measureCurrent = AutoGainReadCurrent(spi_ADC_rxbuf);
AutoGainChange(IV->_measureCurrent);
}else{
ReadCurrent(spi_ADC_rxbuf);
IV->_measureCurrent = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
}
OneWayVoltScan();
InputNotify(NOTIFY_CURRENT, IV->_measureCurrent);
// read Volt
if(IV->_VoViSwitch == 0x01){
ReadVolt(spi_ADC_rxbuf);
}else if(IV->_VoViSwitch == 0x00){
ReadVoutVolt(spi_ADC_rxbuf);
}
VoltCurrentSwitch++;
}
else if(VoltCurrentSwitch == 1){ /**read Vin**/
// read Volt
if(IV->_VoViSwitch == 0x01){
ReadVolt(spi_ADC_rxbuf);
}else if(IV->_VoViSwitch == 0x00){
ReadVoutVolt(spi_ADC_rxbuf);
}
VoltCurrentSwitch++;
}
else if(VoltCurrentSwitch == 2){ /**read Vin(buffer),read Iin**/
// read Volt
if(IV->_VoViSwitch == 0x01){
ReadVolt(spi_ADC_rxbuf);
IV->_measureVin = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
}else if(IV->_VoViSwitch == 0x00){
ReadVoutVolt(spi_ADC_rxbuf);
IV->_measureVin = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_DAC, spi_ADC_rxbuf);
}
InputNotify(NOTIFY_VOLT, IV->_measureVin);
// read current
ReadCurrent(spi_ADC_rxbuf);
VoltCurrentSwitch++;
}
else if(VoltCurrentSwitch == 3){ /**read Iin**/
// read current
ReadCurrent(spi_ADC_rxbuf);
VoltCurrentSwitch = 0;
}
}
static void IV_Vscan(IVMode *IV){
if(vscanReset){
if(INSTRUCTION.directionInit == 1){
IV->_direction_up = true;
IV->_current_direction_up = true;
}else if(INSTRUCTION.directionInit == 0){
IV->_direction_up = false;
IV->_current_direction_up = false;
}
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
if (instru.step <= 10) {
iv->_Vstep = instru.step * instru.VsetRate / 5;
} else {
iv->_Vstep = instru.step / 5 * instru.VsetRate;
if(INSTRUCTION.step <= 10){
IV->_Vstep = INSTRUCTION.step * INSTRUCTION.VsetRate / 5;
}else{
IV->_Vstep = INSTRUCTION.step / 5 * INSTRUCTION.VsetRate;
}
Vset = iv->_Vinit;
Vset = IV->_Vinit;
}
if (!vscanReset) {
if (iv->_current_direction_up) {
if (Vset >= iv->_Vmax) {
PeriodicEvent = false;
if(!vscanReset){
if(IV->_current_direction_up){
if(Vset >= IV->_Vmax){
reset();
}
} else {
if (Vset <= iv->_Vmin) {
PeriodicEvent = false;
}else{
if(Vset <= IV->_Vmin){
reset();
}
}
if (iv->_current_direction_up) {
Vset = Vset + iv->_Vstep * GPT.GptimerMultiple;
} else {
Vset = Vset - iv->_Vstep * GPT.GptimerMultiple;
if (IV->_current_direction_up){
Vset = Vset + IV->_Vstep;
}else{
Vset = Vset - IV->_Vstep;
}
}
}
static void vo_vscan(void)
{
struct wm_vo_ctx_t *vo = (struct wm_vo_ctx_t *)wm_get();
if (vscanReset) {
Vset = vo->_Vinit;
}
if(!vscanReset) {
Vset = vo->_Vinit;
}
}
#endif
@@ -1,14 +1,28 @@
#ifndef __INSTR_H__
#define __INSTR_H__
#ifdef __cpulsplus
extern "C" {
#endif
#ifndef ELITEINSTRUCTION
#define ELITEINSTRUCTION
/** ADC gain level **/
#define GAIN_200K 0x00 // largest gain
#define GAIN_10K 0x01
#define GAIN_200R 0x02 // the least gain
#define GAIN_AUTO 0x03
/* DAC reset parameter */
#define DAC_ZERO 25000
#define DAC_POS_MAX 0x0000
#define DAC_NEG_MAX 0xFFFF
// Step time macro
#define STEPTIME_HALF_SEC 5000
#define STEPTIME_ONE_SEC 10000
#define STEPTIME_TWO_SEC 20000
/*==============================
==== headstage instruction ====
=============================*/
struct HEADSTAGE_INSTRUCTION {
uint8_t chip_id;
uint8_t eliteFxn;
@@ -26,16 +40,11 @@ struct HEADSTAGE_INSTRUCTION {
int32_t Vmin;
/** ADC parameter **/
uint8_t notifyRateIndex;
uint8_t sampleRateIndex;
uint32_t sampleRate;
uint8_t VoViSwitch;
uint8_t AutoGainEnable;
uint8_t VinAutoGainEnable;
uint8_t VoutAutoGainEnable;
uint8_t ADCGainLevel;
// voltage output gain
uint16_t VoutGainLevel;
uint8_t VinADCGainLevel;
/** Notify parameter **/
uint32_t notifyRate;
@@ -45,60 +54,10 @@ 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;
uint16_t StepTime;
uint8_t AdcChannel;
} instru = {0};
/** Iin, Vin, Vout **/
#define IIN_ADC 0x00
#define VIN_ADC 0x01
#define VOUT_DAC 0x02
#define HIGH_Z 0x03
/** ADC Iin gain level **/
#define I_GAIN_3M 0x00 // largest gain
#define I_GAIN_100K 0x01
#define I_GAIN_3K 0x02
#define I_GAIN_100R 0x03 // the least gain
#define I_GAIN_AUTO 0x04
/** ADC Vin gain level **/
#define VIN_GAIN_1M 0x00
#define VIN_GAIN_30K 0x01
#define VIN_GAIN_1K 0x02
#define VIN_GAIN_AUTO 0x03
/** Vout gain level **/
#define VOUT_GAIN_240K 0x00
#define VOUT_GAIN_15K 0x01
#define VOUT_GAIN_AUTO 0x02
/* DAC reset parameter */
#define DAC_ZERO 25000
// Step time macro
#define STEPTIME_HALF_SEC 5000
#define STEPTIME_ONE_SEC 10000
#define STEPTIME_TWO_SEC 20000
} INSTRUCTION = {0};
/*********************************************************************
* @fn InitEliteInstruction
@@ -110,58 +69,57 @@ struct HEADSTAGE_INSTRUCTION {
* @return None.
*/
static void InitEliteInstruction(){
instru.chip_id = 0;
instru.eliteFxn = 0; //default is a null event
instru.VsetRateIndex = 0;
instru.VsetRate = 2;
instru.Vset = 0;
instru.VoltConstant = DAC_ZERO; //DAC_ZERO is about 0V
instru.directionInit = 1; //0:reverse 1:forward
instru.step = 0;
instru.Ve1 = DAC_ZERO;
instru.Ve2 = DAC_ZERO;
instru.Vinit = 0;
instru.Vmax = 0;
instru.Vmin = 0;
instru.notifyRateIndex = 100;
instru.sampleRate = 15;
instru.VoViSwitch = 0x01; //0:user see Vo 1: user see Vi
instru.AutoGainEnable = 1;
instru.VinAutoGainEnable = 1;
instru.VoutAutoGainEnable = 1;
instru.ADCGainLevel = I_GAIN_AUTO;
instru.VoutGainLevel = VOUT_GAIN_AUTO;
instru.VinADCGainLevel = VIN_GAIN_AUTO;
instru.notifyRate = STEPTIME_ONE_SEC;
instru.cycleNumber = 1;
instru.charge = 1; //0:discharge 1:charge
instru.constantCurrent = 0;
instru.Currentmax = 0;
instru.StepTime = STEPTIME_ONE_SEC;
instru.AdcChannel = 0;
//pulse mode
instru.sti_t1 = 0;
instru.sti_t2 = 0;
instru.sti_t3 = 0;
instru.sti_t4 = 0;
instru.sti_t5 = 0;
instru.sti_t6 = 0;
instru.sti_t7 = 0;
instru.sti_v1 = DAC_ZERO;
instru.sti_v2 = DAC_ZERO;
instru.sti_v3 = DAC_ZERO;
instru.sti_v4 = DAC_ZERO;
instru.sti_v5 = DAC_ZERO;
instru.sti_v6 = DAC_ZERO;
instru.sti_v7 = DAC_ZERO;
instru.sti_loop = 1;
instru.sti_cy = 0;
INSTRUCTION.chip_id = 0;
INSTRUCTION.eliteFxn = 0; //default is a null event
INSTRUCTION.VsetRateIndex = 0;
INSTRUCTION.VsetRate = 2;
INSTRUCTION.Vset = 0;
INSTRUCTION.VoltConstant = DAC_ZERO; //DAC_ZERO is about 0V
INSTRUCTION.directionInit = 1; //0:reverse 1:forward
INSTRUCTION.step = 0;
INSTRUCTION.Ve1 = DAC_ZERO;
INSTRUCTION.Ve2 = DAC_ZERO;
INSTRUCTION.Vinit = 0;
INSTRUCTION.Vmax = 0;
INSTRUCTION.Vmin = 0;
INSTRUCTION.sampleRateIndex = 1;
INSTRUCTION.sampleRate = 100;
INSTRUCTION.VoViSwitch = 0x01; //0:user see Vo 1: user see Vi
INSTRUCTION.AutoGainEnable = 1;
INSTRUCTION.ADCGainLevel = GAIN_AUTO;
INSTRUCTION.notifyRate = STEPTIME_ONE_SEC;
INSTRUCTION.cycleNumber = 1;
INSTRUCTION.charge = 1; //0:discharge 1:charge
INSTRUCTION.constantCurrent = 0;
INSTRUCTION.Currentmax = 0;
INSTRUCTION.StepTime = STEPTIME_ONE_SEC;
}
#ifdef __cpulsplus
/*********************************************************************
* @fn GetInstructionParameter
*
* @brief Get Constant Current mode parameter.
*
* @param ins - instruction including current value and unit
*
* @return None.
*/
static void GetInstructionParameter(uint8 *ins){
// CurrentLV=0 => unit is nA
// CurrentLV=1 => unit is uA
// CurrentLV=2 => unit is mA
// INSTRUCTION.CurrentLV = (*ins);
// ConstantCurrentRange=0 => current value is 0~499
// ConstantCurrentRange=1 => current value is 500~999
// INSTRUCTION.ConstantCurrentRange = (*ins) & 0x0F;
// ConstantCurrent divide ConstantCurrentRange into 50000 count (thus each count is 0.01)
// e.g. 485.7 uA can be represent by
// CurrentLV = 1 (unit is uA)
// ConstantCurrentRange = 0 (current range is 0~499)
// ConstantCurrent = 48570
INSTRUCTION.constantCurrent = (uint32_t) (*(ins+1))<<24 | (uint32_t) (*(ins+2))<<16 | (uint32_t) (*(ins+3))<<8 | (uint32_t) (*(ins+4));
}
#endif
#endif
#endif
@@ -12,12 +12,12 @@ static bool TurnOnElite(uint8_t key) {
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);
return false;
}else{
PIN15_setOutputValue(enable_5v, 1); // enable 5V
PIN_setOutputValue(pin_handle, enable_5v, 1); // enable 5V
TurnOn10V();
ModeLED(BT_WAIT);
LEDPowerON();
return true;
}
} else {
@@ -26,7 +26,7 @@ static bool TurnOnElite(uint8_t key) {
}
} else {
TurnOnCounter = 0;
PIN15_setOutputValue(enable_5v, 0); // disable 5V
PIN_setOutputValue(pin_handle, enable_5v, 0);
return false;
}
}
@@ -40,35 +40,36 @@ static void EliteKeyPress(uint8_t key) {
// press key => bight LED
if (ShutDownCounter == CLOCK_ONE_SECOND) {
KEYLED();
KeyWorkModeLED();
}
// 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 {
if (OriginEliteFxn == instru.eliteFxn) { // old function == currunt instruction
if (OriginEliteFxn == INSTRUCTION.eliteFxn) { // old function == currunt instruction
if (ShutDownCounter != 0) {
// dark LED
checkFlafLED();
WorkModeLED();
ShutDownCounter = 0;
}
} else { // old function != currunt instruction
OriginEliteFxn = instru.eliteFxn;
OriginEliteFxn = INSTRUCTION.eliteFxn;
if (ShutDownCounter != 0) {
ShutDownCounter = 0;
}
checkFlafLED();
// dark mode LED
WorkModeLED();
}
}
}
static void TurnOn10V() {
If10Von = true;
PIN15_setOutputValue(enable_10v, 1);
PIN_setOutputValue(pin_handle, enable_10v, 1);
CPUdelay(8000);
}
@@ -2,10 +2,12 @@
#ifndef ELITELED
#define ELITELED
#define DARKLED 0xE1
#define LIGHTLED 0xE8
static void WorkModeLED();
#define DARKLED 0xE1
#define LIGHTLED 0xE8
static void LED_color(uint8_t bright, uint8_t red, uint8_t green, uint8_t blue);
#define LEDPowerON() LED_color(DARKLED, 0x00, 0xFA, 0x00)
#define WORKLED() LED_color(0xE2, 0x00, 0x40, 0x40)
#define KEYLED() LED_color(LIGHTLED, 0xF0, 0xA0, 0x00)
static void LED_color(uint8_t bright, uint8_t red, uint8_t green, uint8_t blue) {
spi_LEDtxbuf[0] = 0x0000;
@@ -21,181 +23,124 @@ static void LED_color(uint8_t bright, uint8_t red, uint8_t green, uint8_t blue)
LED_SPI(SPI_LED_SIZE, spi_LEDtxbuf, spi_LEDrxbuf);
}
static void Elite_led_color(uint16_t color){
switch (color) {
case COLOR_RED: {
LED_color(DARKLED, 0xFF, 0x00, 0x00);
break;
}
case COLOR_ORANGE: {
LED_color(DARKLED, 0xFF, 0x58, 0x09);
break;
}
case COLOR_YELLOW: {
LED_color(LIGHTLED, 0xFF, 0x80, 0x00);
break;
}
case COLOR_GREEN: {
LED_color(DARKLED, 0x00, 0xFA, 0x00);
break;
}
case COLOR_YELLOWGREEN: {
LED_color(DARKLED, 0x64, 0xA6, 0x00);
break;
}
case COLOR_BLUE: {
LED_color(DARKLED, 0x00, 0x00, 0xAA);
break;
}
case COLOR_CYAN: {
LED_color(DARKLED, 0x00, 0x40, 0x40);
break;
}
case COLOR_MAGENTA: {
LED_color(DARKLED, 0xFF, 0x00, 0x80);
break;
}
case COLOR_PURPLE: {
LED_color(DARKLED, 0xFF, 0x00, 0xFF);
break;
}
case COLOR_WHITE: {
LED_color(DARKLED, 0xCA, 0xFF, 0xFF);
break;
}
case COLOR_BLACK: {
LED_color(0x00, 0x00, 0x00, 0x00);
break;
}
//dark LED
case COLOR_YELLOW_DARK: {
LED_color(DARKLED, 0xFF, 0x80, 0x00);
break;
}
case COLOR_GREEN_DARK: {
LED_color(DARKLED, 0x00, 0x33, 0x00);
break;
}
case COLOR_BLUE_DARK: {
LED_color(DARKLED, 0x00, 0x00, 0x33);
break;
}
case COLOR_CYAN_DARK: {
LED_color(DARKLED, 0x00, 0x10, 0x10);
break;
}
case COLOR_PURPLE_DARK: {
LED_color(DARKLED, 0x55, 0x00, 0x55);
break;
}
default: {
break;
}
}
}
static void ModeLED(uint16_t modeStatus) {
btWaitLedFlag = 0;
noEventLedFlag = 0;
preWorkLedFlag = 0;
workingLedFlag = 0;
postWorkLedFlag = 0;
switch (modeStatus) {
case BT_WAIT: {
btWaitLedFlag = 1;
BT_WAIT_LED();
break;
}
case NO_EVENT: {
noEventLedFlag = 1;
LEDPowerON();
break;
}
case PRE_WORK: {
preWorkLedFlag = 1;
Elite_led_color(COLOR_BLUE);
break;
}
case WORKING: {
workingLedFlag = 1;
WorkModeLED();
break;
}
case POST_WORK: {
postWorkLedFlag = 1;
Elite_led_color(COLOR_BLUE);
break;
}
default: {
LEDPowerON();
break;
}
}
}
static void checkFlafLED() {
if(btWaitLedFlag == 1){
ModeLED(BT_WAIT);
}
else if(noEventLedFlag == 1){
ModeLED(NO_EVENT);
}
else if(preWorkLedFlag == 1){
ModeLED(PRE_WORK);
}
else if(workingLedFlag == 1){
ModeLED(WORKING);
}
else if(postWorkLedFlag == 1){
ModeLED(POST_WORK);
}
}
static void WorkModeLED() {
switch (instru.eliteFxn) {
case CURVE_IV:
case CURVE_IV_CY:
case DIFFERENTIAL_PULSE_VOLTAMMETRY:
case SQUARE_WAVE_VOLTAMMETRY:
case CURVE_VO:
case CURVE_RT:
case CURVE_VT:
case CURVE_IT:
case CURVE_CALI_ADCTEST:
case CURVE_CV:
case CURVE_LSV:
case CURVE_CA:{
switch (INSTRUCTION.eliteFxn) {
case IV_CURVE: {
WORKLED();
break;
}
case CURVE_PULSE:{
// Elite_led_color(COLOR_YELLOW);
case CV_CURVE: {
WORKLED();
break;
}
case CURVE_CC:{
case DIFFERENTIAL_PULSE_VOLTAMMETRY: {
WORKLED();
break;
}
case CURVE_CALI_ADC:{
if(instru.AdcChannel == IIN_ADC){
Elite_led_color(COLOR_RED);
}else if(instru.AdcChannel == VIN_ADC){
Elite_led_color(COLOR_ORANGE);
case SQUARE_WAVE_VOLTAMMETRY: {
WORKLED();
break;
}
case VOLT_OUTPUT: {
WORKLED();
break;
}
case ZT_CURVE: {
WORKLED();
break;
}
case VT_CURVE: {
WORKLED();
break;
}
case IT_CURVE: {
WORKLED();
break;
}
case CONSTANT_CURRENT:{
// WORKLED();
LED_color(0xE2, 0x00, 0x00, 0xAA);
break;
}
case VIS_RST: {
LEDPowerON();
break;
}
case ADC_TEST: {
WORKLED();
break;
}
case CYCLIC_VOLTAMMETRY: {
WORKLED();
break;
}
case LINEAR_SWEEP_VOLTAMMETRY: {
WORKLED();
break;
}
case CONSTANT_VSCAN: {
WORKLED();
break;
}
default: {
LEDPowerON();
break;
}
}
}
static void KeyWorkModeLED() {
KEYLED();
/*
switch(INSTRUCTION.eliteFxn){
case IV_CURVE:{
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
break;
}
case CV_CURVE:{
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
break;
}
case DIFFERENTIAL_PULSE_VOLTAMMETRY:{
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
break;
}
case SQUARE_WAVE_VOLTAMMETRY:{
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
break;
}
case VOLT_OUTPUT:{
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
break;
}
case ZT_CURVE:{
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
break;
}
case VT_CURVE:{
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
break;
}
case IT_CURVE:{
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
break;
}
break;
}
// case VIS_RST: {
// LEDPowerON();
// break;
// }
default: {
WORKLED();
break;
}
case VIS_RST:{
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
break;
}
case ADC_TEST:{
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
break;
}
default:{
LED_color(LIGHTLED, 0xF0, 0xF0, 0x00);
break;
}
}
*/
}
#endif
@@ -1,79 +1,95 @@
#ifndef ELITELSV
#define ELITELSV
#define Vset instru.Vset
#define Vset INSTRUCTION.Vset
static void lsv_volt_out(void)
{
struct wm_lsv_ctx_t *lsv = (struct wm_lsv_ctx_t *)wm_get();
struct wm_meas_t *m = &lsv->measure;
uint16_t DACOutCode;
int32_t Vin;
int32_t Vout;
int32_t DeltaVout;
static uint16_t LSVCurve(LSVMode *LSV){
static uint16_t DACOutCode;
static int32_t Vin;
static int32_t Vout;
static int32_t DeltaVout;
Vin = m->_measureVin * 200;//[5nV]
if (DACReset) {
Vin = LSV->_measureVin * 200;//[5nV]
if(DACReset){
Vout = Vset + Vin;
} else {
DACReset = false;
}else{
DeltaVout = Vset - (Vout - Vin);
Vout = Vout + DeltaVout;
}
instru.VoltConstant = Vout / 40000 + 25000;//5nV=>usercode
DACOutCode = Usercode_Correction_to_DAC(instru.VoutGainLevel, instru.VoltConstant);
INSTRUCTION.VoltConstant = Vout / 40000 + 25000;//5nV=>usercode
DACOutCode = Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant);
int32_t RealV2;
RealV2 = (int32_t)((Vout - Vin) / 200);//[1uV]
InputNotify(NOTIFY_VOLT, RealV2);
// int32_t RealV;
// RealV = (int32_t)(Vout / 200);//[1uV]
// InputNotify(NOTIFY_IMPEDANCE, RealV);
int32_t RealV;
RealV = (int32_t)(Vout / 200);//[1uV]
InputNotify(NOTIFY_IMPEDANCE, RealV);
DAC_outputV(DACOutCode);
return;
//
return DACOutCode;
}
static void lsv_vscan(void)
{
struct wm_lsv_ctx_t *lsv = (struct wm_lsv_ctx_t *)wm_get();
static void LSV_Vscan(LSVMode *LSV){
NotifyCycleNumber = (instru.cycleNumber - lsv->_cycleNumber + 1);
NotifyCycleNumber = (INSTRUCTION.cycleNumber - LSV->_cycleNumber + 1);
if (vscanReset) {
if (instru.directionInit == 1) {
lsv->_direction_up = true;
lsv->_current_direction_up = true;
} else {
lsv->_direction_up = false;
lsv->_current_direction_up = false;
if(vscanReset){
if(INSTRUCTION.directionInit == 1){
LSV->_direction_up = true;
LSV->_current_direction_up = true;
}else{
LSV->_direction_up = false;
LSV->_current_direction_up = false;
}
//Vsetp = x * 20 * N, x=xmV ; N=VscanRate
if (instru.step <= 10) {
lsv->_Vstep = instru.step * instru.VsetRate / 5;
} else {
lsv->_Vstep = instru.step / 5 * instru.VsetRate;
if(INSTRUCTION.step <= 10){
LSV->_Vstep = INSTRUCTION.step * INSTRUCTION.VsetRate / 5;
}else{
LSV->_Vstep = INSTRUCTION.step / 5 * INSTRUCTION.VsetRate;
}
Vset = lsv->_Vinit;
Vset = LSV->_Vinit;
}
if (!vscanReset) {
if(!vscanReset){
if (lsv->_current_direction_up) {
Vset = Vset + lsv->_Vstep * GPT.GptimerMultiple;
} else {
Vset = Vset - lsv->_Vstep * GPT.GptimerMultiple;
if (LSV->_current_direction_up){
Vset = Vset + LSV->_Vstep;
}else{
Vset = Vset - LSV->_Vstep;
}
/*stop condition*/
if (Vset >= lsv->_Vmax) {
PeriodicEvent = false;
} else if (Vset <= lsv->_Vmin) {
PeriodicEvent = false;
if (Vset >= LSV->_Vmax){
// PeriodicEvent = false;
Vset = LSV->_Vmin;
InitEliteFlag();
INSTRUCTION.eliteFxn = CONSTANT_CURRENT;
INSTRUCTION.sampleRate = 15;
INSTRUCTION.charge = 0x01;
INSTRUCTION.constantCurrent = 0x00;
INSTRUCTION.Vmax = 0xC350;
INSTRUCTION.Vmin = 0x0000;
INSTRUCTION.notifyRate = 500;
INSTRUCTION.VoViSwitch = 0x02;//read Vscan = Vout - Vin
}else if (Vset <= LSV->_Vmin){
// PeriodicEvent = false;
Vset = LSV->_Vmax;
InitEliteFlag();
INSTRUCTION.eliteFxn = CONSTANT_CURRENT;
INSTRUCTION.sampleRate = 15;
INSTRUCTION.charge = 0x01;
INSTRUCTION.constantCurrent = 0x00;
INSTRUCTION.Vmax = 0xC350;
INSTRUCTION.Vmin = 0x0000;
INSTRUCTION.notifyRate = 500;
INSTRUCTION.VoViSwitch = 0x02;//read Vscan = Vout - Vin
}
}
}
@@ -1,16 +0,0 @@
#ifndef ELITE_LATCH_INIT
#define ELITE_LATCH_INIT
static void InitLH() {
for (int i=0; i<LATCH_BUFF_SIZE; i++) {
LH.LATCH0[i] = 0;
LH.LATCH1[i] = 0;
LH.LATCH2[i] = 0;
}
LH.LoadState = 0;
}
#endif
@@ -29,7 +29,6 @@ static uint8_t NotifyVolt[4] = {0};
static uint8_t NotifyImpedance[4] = {0};
static uint8_t NotifyVoltBat[4] = {0};
static uint16_t NotifyCycleNumber = 0;
static uint8_t finishMode = 0;
// ****************** New Notify Format ******************************** //
/*
@@ -90,7 +89,7 @@ static uint8_t finishMode = 0;
static void SendNotify() {
initDATBuf();
not_buf[0] = instru.chip_id;
not_buf[0] = INSTRUCTION.chip_id;
for (int i = 0; i < 4; i++) {
not_buf[i + 1] = NotifyCurrent[i];
@@ -108,25 +107,23 @@ static void SendNotify() {
not_buf[17] = (NotifyCycleNumber >> 8) & 0xff;
not_buf[18] = NotifyCycleNumber & 0xff;
not_buf[19] = (finishMode << 7) & 0x80;
for (int i = 20; i < BLE_DAT_BUFF_SIZE; i++){
not_buf[i] = 0;
}
not_buf[19] = 0;
not_buf[20] = 0;
not_buf[21] = 0;
not_buf[22] = 0;
SimpleProfile_SetParameter(BLE_DAT_BUFF_CHAR, BLE_DAT_BUFF_SIZE, not_buf);
}
static void initDATBuf(){
for (int i = 0; i < BLE_DAT_BUFF_SIZE; i++){
not_buf[i] = 0;
not_buf[i] = 0;
}
}
static void initINSBuf(){
for (int i = 0; i < BLE_INS_BUFF_SIZE; i++){
ins_buf[i] = 0;
ins_buf[i] = 0;
}
}
@@ -139,7 +136,6 @@ static void initCISBuf(){
static void initRawDataBuf(){
not_time_stamp = 0;
NotifyCycleNumber = 0;
finishMode = 0;
for (int i = 0; i < 4; i++){
NotifyCurrent[i] = 0;
@@ -152,7 +148,7 @@ static void FlushNotify(){
initRawDataBuf();
initDATBuf();
not_buf[0] = instru.chip_id;
not_buf[0] = INSTRUCTION.chip_id;
SimpleProfile_SetParameter(BLE_DAT_BUFF_CHAR, BLE_DAT_BUFF_SIZE, not_buf);
}
@@ -1,115 +0,0 @@
#ifndef ELITEPULSE
#define ELITEPULSE
#define Vset instru.Vset
static void pulse_vscan(void)
{
struct wm_pulse_ctx_t *pulse = (struct wm_pulse_ctx_t *)wm_get();
static uint16_t lastVolt;
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 = instru.sti_cy;
pulse->_sti_t_flag = 2;
pulse->_sti_v = pulse->_sti_v2;
pulse->_sti_t = pulse->_sti_t2;
if (pulse->_sti_t == 1) {
pulse->_sti_v = lastVolt;
}
} else {
pulse->_sti_t_flag = 5;
pulse->_sti_v = pulse->_sti_v5;
pulse->_sti_t = pulse->_sti_t5;
if (pulse->_sti_t == 1) {
pulse->_sti_v = lastVolt;
}
}
}
}
} 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;
PIN15_setOutputValue(HIGH_Z_MODE, 0); // 0: open highz;
ModeLED(NO_EVENT);
}
}
}
}
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));
}
}
#endif
@@ -3,25 +3,17 @@
#define ELITERESET
static void reset() {
mode_init = true;
megaStiEnable = false;
PeriodicEvent = false; // is there an PeriodicEvent?
Free_Work_Mode = true; // Free(WorkModeData)
InitPeriodicEvent = true; // need to create a WorkModeData?
InitEliteFlag();
InitFlag();
InitCT();
InitGPT();
ADCGainControl(INSTRUCTION.ADCGainLevel);
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant));
LEDPowerON();
initINSBuf();
initDATBuf();
PIN15_setOutputValue(HIGH_Z_MODE, 0); // HIGH Z MODE // 1: close; 0: open;
VinADCGainControl(VIN_GAIN_AUTO);
IinADCGainControl(I_GAIN_AUTO);
instru.VoutGainLevel = VOUT_GAIN_15K;
VoutGainControl(instru.VoutGainLevel);
DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLevel, 25000));
for (int i = 0; i < SPI_LED_SIZE; i++) {
spi_LEDtxbuf[i] = 0;
spi_LEDrxbuf[i] = 0;
@@ -37,27 +29,23 @@ static void reset() {
spi_ADC_rxbuf[i] = 0;
}
ModeLED(NO_EVENT);
PIN_setOutputValue(pin_handle, ADC_CS, 1); // ADC_CS HIGH
PIN_setOutputValue(pin_handle, DAC_CS, 1); // DAC_CS HIGH
CPUdelay(1600);
}
static void Eliteinterrupt() {
mode_init = true;
megaStiEnable = false;
PeriodicEvent = false; // is there an PeriodicEvent?
Free_Work_Mode = true; // Free(WorkModeData)
InitPeriodicEvent = true; // need to create a WorkModeData?
InitEliteFlag();
InitFlag();
InitCT();
InitGPT();
ADCGainControl(GAIN_AUTO);
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant));
LEDPowerON();
initINSBuf();
initDATBuf();
PIN15_setOutputValue(HIGH_Z_MODE, 0); // HIGH Z MODE // 1: close; 0: open;
instru.VoutGainLevel = VOUT_GAIN_15K;
VoutGainControl(instru.VoutGainLevel);
DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLevel, 25000));
for (int i = 0; i < SPI_LED_SIZE; i++) {
spi_LEDtxbuf[i] = 0;
spi_LEDrxbuf[i] = 0;
@@ -73,7 +61,8 @@ static void Eliteinterrupt() {
spi_ADC_rxbuf[i] = 0;
}
ModeLED(NO_EVENT);
PIN_setOutputValue(pin_handle, ADC_CS, 1); // ADC_CS HIGH
PIN_setOutputValue(pin_handle, DAC_CS, 1); // DAC_CS HIGH
CPUdelay(8000);
}
#endif
@@ -36,8 +36,6 @@ 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();
@@ -65,73 +63,26 @@ 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
ADC_DAC_transaction.count = length;
ADC_DAC_transaction.txBuf = spi_txbuf;
ADC_DAC_transaction.rxBuf = spi_rxbuf;
PIN_setOutputValue(pin_handle, DAC_CS, 1); // DAC_CS HIGH
PIN_setOutputValue(pin_handle, ADC_CS, 0); // ADC_CS LOW
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
PIN_setOutputValue(pin_handle, ADC_CS, 1); // ADC_CS HIGH
PIN_setOutputValue(pin_handle, D6, 1); // ADC_CS HIGH
update_latch_status (ADC_CS, 1);
// PIN15_setOutputValue(ADC_CS, 1); // ADC_CS HIGH
}
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;
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 HIGH
update_latch_status (DAC_CS, 1);
// PIN15_setOutputValue(DAC_CS, 1); // DAC_CS HIGH
}
static void ELITE15_SPI_HOLD() {
Elite_SPI_init();
#ifdef ELITE_PIN_1_5_RE
PIN_setOutputValue(pin_handle, D6, LH.LATCH0[6]); // ADC_CS
PIN_setOutputValue(pin_handle, D7, LH.LATCH0[7]); // DAC_CS
PIN_setOutputValue(pin_handle, D4, LH.LATCH0[4]); // update HIGH_Z_MODE
#endif
PIN_setOutputValue(pin_handle, LOAD0, 1);
PIN_setOutputValue(pin_handle, LOAD1, 0);
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, ADC_CS, 1); // ADC_CS HIGH
PIN_setOutputValue(pin_handle, DAC_CS, 0); // DAC_CS LOW
SPI_transfer(spiHandle1, &ADC_DAC_transaction);
PIN_setOutputValue(pin_handle, DAC_CS, 1); // DAC_CS HIGH
}
#endif // ELITE_SPI
@@ -0,0 +1,85 @@
#ifndef ELITEVT
#define ELITEVT
static void VT_Plot(WorkMode *WorkModeData) {
switch (INSTRUCTION.eliteFxn) {
case IT_CURVE:{
#define CURRENT_MODE WorkModeData->IT
break;
}
case VT_CURVE:{
#define CURRENT_MODE WorkModeData->VT
break;
}
case ZT_CURVE:{
#define CURRENT_MODE WorkModeData->RT
break;
}
case IV_CURVE:{
#define CURRENT_MODE WorkModeData->IV
break;
}
case CV_CURVE:{
#define CURRENT_MODE WorkModeData->CV
break;
}
case CONSTANT_CURRENT:{
#define CURRENT_MODE WorkModeData->CC
break;
}
case CYCLIC_VOLTAMMETRY:{
#define CURRENT_MODE WorkModeData->CV3
break;
}
case LINEAR_SWEEP_VOLTAMMETRY:{
#define CURRENT_MODE WorkModeData->LSV
break;
}
case CONSTANT_VSCAN:{
#define CURRENT_MODE WorkModeData->CVSCAN
break;
}
default: {
break;
}
}
// ADC gain is don't care when measuring voltage
INSTRUCTION.ADCGainLevel = GAIN_200R;
ADCGainControl(INSTRUCTION.ADCGainLevel);
static uint8_t ADCSwitch = 0;
static int32_t VoltData;
if(batteryCheck_flag){
EliteADCBattery();
if(!batteryCheck_flag){
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
ADCSwitch = 2;
}
}else{
if(ADCSwitch == 0){ /**read V(buffer)**/
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
if(CURRENT_MODE->_VoViSwitch == 0x01){
CURRENT_MODE->_measureVin = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
VoltData = CURRENT_MODE->_measureVin;
}else if(CURRENT_MODE->_VoViSwitch == 0x00){
CURRENT_MODE->_measureVout = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_DAC, spi_ADC_rxbuf);
VoltData = CURRENT_MODE->_measureVout;
}
InputNotify(NOTIFY_VOLT, VoltData);
ADCSwitch++;
}
else if(ADCSwitch == 1){ /**read V**/
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
ADCSwitch++;
}
else if(ADCSwitch == 2){ /**read V**/
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
ADCSwitch = 0;
}
}
#undef CURRENT_MODE
}
#endif
@@ -8,16 +8,176 @@
// change the output voltage step
// => get a R-T curve (with resolution = 1 sample/volt step )
static void rt_vscan(void)
{
struct wm_rt_ctx_t *rt = (struct wm_rt_ctx_t *)wm_get();
if (vscanReset) {
Vset = rt->_Vinit;
static void ZT_Plot(WorkMode *WorkModeData) {
switch (INSTRUCTION.eliteFxn) {
case IT_CURVE:{
#define CURRENT_MODE WorkModeData->IT
break;
}
case VT_CURVE:{
#define CURRENT_MODE WorkModeData->VT
break;
}
case ZT_CURVE:{
#define CURRENT_MODE WorkModeData->RT
break;
}
case IV_CURVE:{
#define CURRENT_MODE WorkModeData->IV
break;
}
case CV_CURVE:{
#define CURRENT_MODE WorkModeData->CV
break;
}
case CONSTANT_CURRENT:{
#define CURRENT_MODE WorkModeData->CC
break;
}
case CYCLIC_VOLTAMMETRY:{
#define CURRENT_MODE WorkModeData->CV3
break;
}
case LINEAR_SWEEP_VOLTAMMETRY:{
#define CURRENT_MODE WorkModeData->LSV
break;
}
case CONSTANT_VSCAN:{
#define CURRENT_MODE WorkModeData->CVSCAN
break;
}
default: {
break;
}
}
if(!vscanReset) {
Vset = rt->_Vinit;
static uint8_t ADCSwitch = 0;
static uint8_t BatSwitch = 0;
static int32_t VoltData = 0;
if(batteryCheck_flag){
if(ADCSwitch == 0){
if(BatSwitch == 0){ /**read Iin(buffer),read bat**/
if(INSTRUCTION.AutoGainEnable){
CURRENT_MODE->_measureCurrent = AutoGainReadCurrent(spi_ADC_rxbuf);
AutoGainChange(CURRENT_MODE->_measureCurrent);
}else{
ReadCurrent(spi_ADC_rxbuf);
CURRENT_MODE->_measureCurrent = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
}
InputNotify(NOTIFY_CURRENT, CURRENT_MODE->_measureCurrent);
DACenable(WorkModeData, VoltData, AFTER_READ_I);
ReadBatVolt(spi_ADC_rxbuf);
BatSwitch++;
}else if(BatSwitch == 1){
ReadBatVolt(spi_ADC_rxbuf);
BatSwitch++;
}else if(BatSwitch == 2){
headstage_battery_volt();
ReadCurrent(spi_ADC_rxbuf);
batteryCheck_flag = false;
BatSwitch = 0;
ADCSwitch = 3;
}
}
else if(ADCSwitch == 1 || ADCSwitch == 3){
if(BatSwitch == 0){ /**read Bat**/
ReadBatVolt(spi_ADC_rxbuf);
BatSwitch++;
}else if(BatSwitch == 1){
ReadBatVolt(spi_ADC_rxbuf);
BatSwitch++;
}else if(BatSwitch == 2){
headstage_battery_volt();
ReadCurrent(spi_ADC_rxbuf);
batteryCheck_flag = false;
BatSwitch = 0;
ADCSwitch = 3;
}
}
else if(ADCSwitch == 2){
if(BatSwitch == 0){ /**read V(buffer),read bat**/
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
if(CURRENT_MODE->_VoViSwitch == 0x01){
CURRENT_MODE->_measureVin = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
VoltData = CURRENT_MODE->_measureVin;
}else if(CURRENT_MODE->_VoViSwitch == 0x00){
CURRENT_MODE->_measureVout = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_DAC, spi_ADC_rxbuf);
VoltData = CURRENT_MODE->_measureVout;
}
InputNotify(NOTIFY_VOLT, VoltData);
DACenable(WorkModeData, VoltData, AFTER_READ_V);
ReadBatVolt(spi_ADC_rxbuf);
BatSwitch++;
}else if(BatSwitch == 1){
ReadBatVolt(spi_ADC_rxbuf);
BatSwitch++;
}else if(BatSwitch == 2){
headstage_battery_volt();
ReadCurrent(spi_ADC_rxbuf);
batteryCheck_flag = false;
BatSwitch = 0;
ADCSwitch = 3;
}
}
}else{
BatSwitch = 0;
if(ADCSwitch == 0){ /**read Iin(buffer),read V**/
if(INSTRUCTION.AutoGainEnable){
CURRENT_MODE->_measureCurrent = AutoGainReadCurrent(spi_ADC_rxbuf);
AutoGainChange(CURRENT_MODE->_measureCurrent);
}else{
ReadCurrent(spi_ADC_rxbuf);
CURRENT_MODE->_measureCurrent = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
}
InputNotify(NOTIFY_CURRENT, CURRENT_MODE->_measureCurrent);
DACenable(WorkModeData, VoltData, AFTER_READ_I);
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
ADCSwitch++;
}
else if(ADCSwitch == 1){ /**read V**/
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
ADCSwitch++;
}
else if(ADCSwitch == 2){ /**read V(buffer),read Iin**/
ReadADCVolt(CURRENT_MODE->_VoViSwitch);
if(CURRENT_MODE->_VoViSwitch == 0x01){
CURRENT_MODE->_measureVin = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
VoltData = CURRENT_MODE->_measureVin;
}else if(CURRENT_MODE->_VoViSwitch == 0x00){
CURRENT_MODE->_measureVout = DecodeADCValue(INSTRUCTION.ADCGainLevel, ADC_CH_DAC, spi_ADC_rxbuf);
VoltData = CURRENT_MODE->_measureVout;
}
InputNotify(NOTIFY_VOLT, VoltData);
DACenable(WorkModeData, VoltData, AFTER_READ_V);
ReadCurrent(spi_ADC_rxbuf);
ADCSwitch++;
}
else if(ADCSwitch == 3){ /**read Iin**/
ReadCurrent(spi_ADC_rxbuf);
ADCSwitch = 0;
}
}
#undef CURRENT_MODE
}
static void ZT_Vscan(RTMode *RT){
if(vscanReset){
Vset = ((int32_t)(INSTRUCTION.VoltConstant) - 25000) * 4 * 10000; //[5nV]
OneWayVoltScan();
}
if(!vscanReset){
}
}
#endif
@@ -6,113 +6,52 @@
#include <Board.h>
#include <ti/drivers/PIN.h>
#define ELITE_PIN_1_5
/* SPI Board */
#define Board_SPI0_MISO PIN_UNASSIGNED
#define Board_SPI0_MOSI D1
#define Board_SPI0_CLK D0
#define Board_SPI0_MOSI IOID_1
#define Board_SPI0_CLK IOID_0
#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_MISO IOID_3
#define Board_SPI1_MOSI IOID_2
#define Board_SPI1_CLK IOID_4
#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 ADC_CS IOID_8
#define DAC_CS IOID_9
#define LOAD0 IOID_13
#define LOAD1 IOID_12
#define LOAD2 IOID_11
#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_CS LOAD0, D5
#ifdef ELITE_PIN_1_5
#define MEM_HOLD LOAD0, D4
#define HIGH_Z_MODE LOAD2, D5
#endif
#ifdef ELITE_PIN_1_5_RE
#define MEM_HOLD LOAD1, D0
#define HIGH_Z_MODE LOAD0, D4
#endif
#define Turnon_I_MID LOAD2, D0
#define Turnon_I_SMALL LOAD2, D4
#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 shutdown_6994 LOAD2, D6
//#define Turnon10K Turnon_I_MID
//#define Turnon200R Turnon_I_LARGE
#define Turnon200R IOID_5
#define Turnon10K IOID_6
/* I2C */
#ifdef ELITE_VERSION_1_4
#define Board_I2C0_SCL0 PIN_UNASSIGNED
#define Board_I2C0_SDA0 PIN_UNASSIGNED
#define Board_I2C0_SCL0 IOID_7
#define Board_I2C0_SDA0 IOID_1
#endif
#define switch_on IOID_14
#define enable_10v LOAD1, D5
#define enable_5v LOAD1, D6
#define shutdown_6994 IOID_10
#define switch_on IOID_11
#define enable_10v IOID_12
#define enable_5v 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,
//
ADC_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, // ADC_CS
DAC_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, // DAC_CS
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
enable_10v | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, // 10V_enable
enable_5v | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, // 5V_enable
shutdown_6994 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, // turn off power
Turnon200R | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
Turnon10K | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
switch_on | PIN_INPUT_EN | PIN_PULLDOWN,
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 remove_elite_pin() {
PIN_close(pin_handle);
pin_handle = PIN_open(&ZM_rst, BLE_IO);
}
/*!
* @def BOOSTXL_CC2650MA_SPIName
* @brief Enum of SPI names on the CC2650 Booster Pack
@@ -2,12 +2,12 @@
***********************************************************
Read battery's method
***********************************************************
1.ReadADCBat(spi_ADC_rxbuf)
1.ReadBatVolt(spi_ADC_rxbuf)
let "spi_ADC_rxbuf" be 8000
8000 * 187.5uV * 2 = 3000000uV = 3V ;
8000 * 187.5uV * 2 = 3V ;
2.AONBatMonBatteryVoltageGet()
let "AONBatMonBatteryVoltageGet()" be 768
768 * 125 / 320 / 100 = 768 / 256 = 3V ;
768 * 125 / 320 / 100 = 3V ;
if you want to use first method, and get value 768
conversion: 8000 * 187.5 * 1e-6 * 2 / 125 * 320 * 100 = 768
@@ -34,7 +34,7 @@ static uint8_t headstage_battery_percent() {
static void headstage_battery_volt(){
uint32_t bat_volt = 0;
ReadADCBat(spi_ADC_rxbuf);
ReadBatVolt(spi_ADC_rxbuf);
bat_volt = (uint32_t) (spi_ADC_rxbuf[0] << 8) | (uint32_t) (spi_ADC_rxbuf[1]);
bat_volt = bat_volt * 12 / 125; //x * 187.5 * 1e-6 * 2 / 125 * 320 * 100 ;
InputNotify(NOTIFY_VOLT_BAT, bat_volt);
@@ -42,50 +42,19 @@ static void headstage_battery_volt(){
static void EliteADCBattery(){
static uint8_t ADCSwitch = 0;
if(instru.eliteFxn == CURVE_CALI_ADCTEST){
if(ADCSwitch == 0){ /**read V**/
ReadBatVolt(spi_ADC_rxbuf);
ADCSwitch++;
}
else if(ADCSwitch == 1){ /**read V**/
ReadBatVolt(spi_ADC_rxbuf);
ADCSwitch++;
}
else if(ADCSwitch == 2){ /**read V(buffer)**/
headstage_battery_volt();
batteryCheck_flag = false;
ADCSwitch = 0;
}else{
if(ADCSwitch == 0){ /**read V**/
ReadADCBat(spi_ADC_rxbuf);
ADCSwitch++;
}
else if(ADCSwitch == 1){ /**read V**/
ReadADCBat(spi_ADC_rxbuf);
ADCSwitch++;
}
else if(ADCSwitch == 2){ /**read V(buffer)**/
headstage_battery_volt();
batteryCheck_flag = false;
ADCSwitch = 0;
}
}
}
static void measureBat(){
GPT.DeltaGptimerCounter = GPT.GptimerCounter - GPT.GptimerCounter0;
GPT.GptimerCounter0 = GPT.GptimerCounter;
GPT.BatteryADCCounter = GPT.BatteryADCCounter + GPT.DeltaGptimerCounter;
GPT.BatteryCheckCounter = GPT.BatteryCheckCounter + GPT.DeltaGptimerCounter;
if(GPT.BatteryCheckCounter >= 50000){//5min=3000000, 5s=50000
GPT.BatteryCheckCounter = 0;
batteryCheck_flag = true;
}
if(GPT.BatteryADCCounter >= 15 && batteryCheck_flag){
GPT.BatteryADCCounter = 0; //To get the data right, ADC must be delay 1.5ms
batteryADC_flag = true;
if(batteryADC_flag){
EliteADCBattery();
batteryADC_flag = false;
}
}
uint16_t bat = ((uint16_t)(NotifyVoltBat[2]) << 8 & 0xFF00 ) |
((uint16_t)(NotifyVoltBat[3]) & 0x00FF);
if( bat < 768 && bat > 20){
PIN15_setOutputValue(enable_5v, 0);
}
}
@@ -1,105 +0,0 @@
#ifndef ELITE_DEF
#define ELITE_DEF
// define BT instruction
#define INS_TYPE_RIS 0x30
#define INS_TYPE_VIS 0xC0
#define INS_TYPE_CIS 0x70
// VIS (virtual instruction)
#define VIS_RST 0xF0
#define VIS_ASK 0x30
#define VIS_STI 0xC0
#define VIS_FUH 0x90
#define VIS_INT 0x60
#define VIS_SHIFT_200K 0xA0
#define VIS_SHIFT_10K 0xE0
#define VIS_SHIFT_200R 0x80
#define VIS_DEVICE_SHINY 0x10
#define VIS_SHINY_DIS 0x20
#define VIS_CC_ZERO 0x40
// RIS (real instruction)
enum all_mode_e {
CURVE_IV = 0x01, // 01
CURVE_IV_CY = 0x02, // cycling iv // 02
CURVE_VO = 0x03, // 03
CURVE_RT = 0x04, // 04
CURVE_VT = 0x05, // 05
CURVE_IT = 0x06, // 06
CURVE_CC = 0x07, // constant current // 07
CURVE_CC_CY = 0x08, // doesn't exist // 08
CURVE_CV = 0x09, // cyclic voltammetry // 09
CURVE_CV_HIGH_CY = 0x0A, // cyclic voltammetry(high cycle) // 0A
CURVE_LSV = 0x0B, // linear sweep voltammetry // 0B
CURVE_CA = 0x0C, // chronoamperometric graph(CA) // 0C
CURVE_PULSE = 0x0D, // 0D
DIFFERENTIAL_PULSE_VOLTAMMETRY = 0x0E, // doesn't exist // 0E
SQUARE_WAVE_VOLTAMMETRY = 0x0F, // doesn't exist // 0F
SHORT_INSTR = 0xE0,
CURVE_CALI_ADCTEST = 0x91, // F0
CURVE_CALI_DAC = 0x93, // F1
CURVE_CALI_ADC = 0x92, // F2
DEV_MODE = 0xFF
};
enum all_short_instr_e {
SET_NOTIFY_RATE2 = 0x01, //01
SET_NOTIFY_RATE = 0x70, //01
SET_ADC_DAC_GAIN = 0x80, //02
};
// CIS (control instruction)
#define CIS_VERSION 0x40
#define CIS_VOLT 0x10
#define CIS_LED_TEST 0x70
// mode parameter
#define STEP_TO_VSETRATE(step) step2VsetRate(step)
#define VMAX(v1,v2) ((v1 >= v2) ? v1 : v2)
#define VMIN(v1,v2) ((v1 < v2) ? v1 : v2)
#define VDIRECTION(v1,v2) ((v1 > v2) ? 0 : 1)
#define AFTER_READ_I 0
#define AFTER_READ_V 1
#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_END 0x11
//Elite LED
#define COLOR_BLACK 0x00
#define COLOR_RED 0x01
#define COLOR_ORANGE 0x02
#define COLOR_YELLOW 0x03
#define COLOR_GREEN 0x04
#define COLOR_BLUE 0x05
#define COLOR_CYAN 0x06
#define COLOR_MAGENTA 0x07
#define COLOR_PURPLE 0x08
#define COLOR_WHITE 0x09
#define COLOR_YELLOWGREEN 0x0A
#define COLOR_YELLOW_DARK 0xF3
#define COLOR_GREEN_DARK 0xF4
#define COLOR_BLUE_DARK 0xF5
#define COLOR_CYAN_DARK 0xF6
#define COLOR_PURPLE_DARK 0xF8
#define LEDPowerON() Elite_led_color(COLOR_GREEN)
#define WORKLED() Elite_led_color(COLOR_CYAN)
#define KEYLED() Elite_led_color(COLOR_YELLOW)
#define BT_WAIT_LED() Elite_led_color(COLOR_YELLOWGREEN)
#define BT_WAIT 0x01
#define NO_EVENT 0x02
#define PRE_WORK 0x03
#define WORKING 0x04
#define POST_WORK 0x05
#define VALUE_ZERO_TO_ONE(_v) (_v == 0) ? 1 : _v
#endif
@@ -1,502 +0,0 @@
#ifndef ELITE_MODE_ADC_DAC
#define ELITE_MODE_ADC_DAC
#define Vset instru.Vset
static void volt_out() {
static uint16_t DACOutCode;
static int32_t Vout;
static int32_t DeltaVout;
if(DACReset){
Vout = Vset;
}else{
DeltaVout = Vset - (Vout);
Vout = Vout + DeltaVout;
}
if (Vout >= 1100000000) { //1100000000 = 5.5V
Vout = 1100000000;
} else if (Vout <= -1000000000) { //-1000000000 = -5V
Vout = -1000000000;
}
instru.VoltConstant = Vout / 40000 + 25000; //5nV=>usercode
DACOutCode = Usercode_Correction_to_DAC(instru.VoutGainLevel, instru.VoltConstant);
DAC_outputV(DACOutCode);
if ((instru.eliteFxn == CURVE_IV)||(instru.eliteFxn == CURVE_IV_CY)||(instru.eliteFxn == CURVE_CC)){
int32_t RealV;
RealV = (int32_t)(Vout / 200);//[1uV]
InputNotify(NOTIFY_IMPEDANCE, RealV);
}
return;
}
static void CalcuResistance()
{
/* Elite 100 = 100R
Elite 1000 = 1KR
Elite 10000 = 10KR
Elite 100000 = 100KR
Elite 1000000 = 1MR
*/
struct wm_rt_ctx_t *rt = (struct wm_rt_ctx_t *)wm_get();
struct wm_meas_t *m = &rt->measure;
int32_t resist;
int32_t volt;
// volt = (m->_measureVin * 1000) - (m->_measureCurrent * 10); //V = Vin - Iin * 10
resist = (m->_measureVin * 1000) / m->_measureCurrent; //R = V / Iin;
InputNotify(NOTIFY_IMPEDANCE, resist);
}
static void DACenable(uint8_t afterRead){
void *wm = wm_get();
if (afterRead == AFTER_READ_I) {
switch (instru.eliteFxn) {
case CURVE_CC:
cc_vscan();
volt_out();
break;
default:
break;
}
} else if (afterRead == AFTER_READ_V) {
switch (instru.eliteFxn) {
case CURVE_IV_CY:
case CURVE_IV:
case CURVE_VO:
volt_out();
break;
case CURVE_RT:
volt_out();
CalcuResistance();
break;
case CURVE_CV:
cv_volt_out();
break;
case CURVE_LSV:{
lsv_volt_out();
break;
}
case CURVE_CA:{
ca_volt_out();
break;
}
default:{
break;
}
}
}
}
static void CC_Plot(void)
{
static uint8_t ADCSwitch = 0;
static uint8_t BatSwitch = 0;
static int32_t VoltData = 0;
void *wm = wm_get();
if (batteryCheck_flag) {
if (BatSwitch == 0) {
if (ADCSwitch == 0) { /**read Iin(buffer),read bat**/
if (instru.AutoGainEnable) {
MEAS_CURR(wm) = AutoGainReadIin(spi_ADC_rxbuf);
AutoGainChangeIin(MEAS_CURR(wm));
} else {
ReadADCIin(spi_ADC_rxbuf);
MEAS_CURR(wm) = DecodeADCValue(instru.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
if (lastIinADCGainLevel != instru.ADCGainLevel) {
IinADCGainControl(instru.ADCGainLevel);
record_flag = false;
}
}
if (record_flag == false) {
static int recordCount = 0;
recordCount++;
if (recordCount == 2) {
record_flag = true;
recordCount = 0;
}
} else {
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
}
DACenable(AFTER_READ_I);
ReadADCBat(spi_ADC_rxbuf);
BatSwitch++;
} else if(ADCSwitch == 1 || ADCSwitch == 3) { /**read Bat**/
ReadADCBat(spi_ADC_rxbuf);
BatSwitch++;
} else if(ADCSwitch == 2) { /**read V(buffer),read bat**/
if (VOLT_SW(wm) == 0x01 || VOLT_SW(wm) == 0x02) {
if (instru.VinAutoGainEnable) {
MEAS_VIN(wm) = AutoGainReadVin(spi_ADC_rxbuf);
AutoGainChangeVin(MEAS_VIN(wm));
} else {
ReadADCVolt(VOLT_SW(wm));
MEAS_VIN(wm) = DecodeADCValue(instru.VinADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
if (lastVinADCGainLevel != instru.VinADCGainLevel) {
VinADCGainControl(instru.VinADCGainLevel);
record_flag = false;
}
}
VoltData = MEAS_VIN(wm);
} else if (VOLT_SW(wm) == 0x00) {
ReadADCVolt(VOLT_SW(wm));
MEAS_VOUT(wm) = DecodeADCValue(instru.ADCGainLevel, ADC_CH_DAC, spi_ADC_rxbuf);
VoltData = MEAS_VOUT(wm);
}
if (instru.VoViSwitch == 0x02) {
int32_t Vscan = (Vset / 200 - MEAS_VIN(wm));
Vscan = (int32_t)(Vscan);//[1uV]
InputNotify(NOTIFY_VOLT, Vscan);
} else {
InputNotify(NOTIFY_VOLT, VoltData);
}
DACenable(AFTER_READ_V);
ReadADCBat(spi_ADC_rxbuf);
BatSwitch++;
}
} else if(BatSwitch == 1) {
ReadADCBat(spi_ADC_rxbuf);
BatSwitch++;
} else if(BatSwitch == 2) {
headstage_battery_volt();
ReadADCIin(spi_ADC_rxbuf);
batteryCheck_flag = false;
BatSwitch = 0;
ADCSwitch = 3;
}
} else {
BatSwitch = 0;
if (ADCSwitch == 0) { /**read Iin(buffer),read V**/
if (instru.AutoGainEnable) {
MEAS_CURR(wm) = AutoGainReadIin(spi_ADC_rxbuf);
AutoGainChangeIin(MEAS_CURR(wm));
} else {
ReadADCIin(spi_ADC_rxbuf);
MEAS_CURR(wm) = DecodeADCValue(instru.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
if (lastIinADCGainLevel != instru.ADCGainLevel) {
IinADCGainControl(instru.ADCGainLevel);
record_flag = false;
}
}
if (record_flag == false) {
static int recordCount = 0;
recordCount++;
if (recordCount == 2) {
record_flag = true;
recordCount = 0;
}
} else {
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
}
DACenable(AFTER_READ_I);
ReadADCVolt(VOLT_SW(wm));
ADCSwitch++;
} else if(ADCSwitch == 1) { /**read V**/
ReadADCVolt(VOLT_SW(wm));
ADCSwitch++;
} else if(ADCSwitch == 2) { /**read V(buffer),read Iin**/
if (VOLT_SW(wm) == 0x01 || VOLT_SW(wm) == 0x02) {
if (instru.VinAutoGainEnable) {
MEAS_VIN(wm) = AutoGainReadVin(spi_ADC_rxbuf);
AutoGainChangeVin(MEAS_VIN(wm));
} else {
ReadADCVolt(VOLT_SW(wm));
MEAS_VIN(wm) = DecodeADCValue(instru.VinADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
if (lastVinADCGainLevel != instru.VinADCGainLevel) {
VinADCGainControl(instru.VinADCGainLevel);
record_flag = false;
}
}
VoltData = MEAS_VIN(wm);
} else if (VOLT_SW(wm) == 0x00) {
ReadADCVolt(VOLT_SW(wm));
MEAS_VOUT(wm) = DecodeADCValue(instru.ADCGainLevel, ADC_CH_DAC, spi_ADC_rxbuf);
VoltData = MEAS_VOUT(wm);
}
if (instru.VoViSwitch == 0x02) {
int32_t Vscan = (Vset / 200 - MEAS_VIN(wm));
Vscan = (int32_t)(Vscan);//[1uV]
InputNotify(NOTIFY_VOLT, Vscan);
} else {
InputNotify(NOTIFY_VOLT, VoltData);
}
DACenable(AFTER_READ_V);
ReadADCIin(spi_ADC_rxbuf);
ADCSwitch++;
} else if (ADCSwitch == 3) { /**read Iin**/
ReadADCIin(spi_ADC_rxbuf);
ADCSwitch = 0;
}
}
}
static void IT_Plot(void)
{
static uint8_t ADCSwitch = 0;
void *wm = wm_get();
if (batteryCheck_flag) {
EliteADCBattery();
if (!batteryCheck_flag) {
ReadADCIin(spi_ADC_rxbuf);
ADCSwitch = 2;
}
} else {
if (ADCSwitch == 0) { /**read Iin(buffer)**/
if (instru.AutoGainEnable) {
MEAS_CURR(wm) = AutoGainReadIin(spi_ADC_rxbuf);
AutoGainChangeIin(MEAS_CURR(wm));
} else {
ReadADCIin(spi_ADC_rxbuf);
MEAS_CURR(wm) = DecodeADCValue(instru.ADCGainLevel, ADC_CH_CURRENT, spi_ADC_rxbuf);
if (lastIinADCGainLevel != instru.ADCGainLevel) {
IinADCGainControl(instru.ADCGainLevel);
record_flag = false;
}
}
if (record_flag == false) {
static int recordCount = 0;
recordCount++;
if (recordCount == 2) {
record_flag = true;
recordCount = 0;
}
} else {
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
}
ADCSwitch++;
} else if (ADCSwitch == 1) { /**read Iin**/
ReadADCIin(spi_ADC_rxbuf);
ADCSwitch++;
} else if(ADCSwitch == 2) { /**read Iin**/
ReadADCIin(spi_ADC_rxbuf);
ADCSwitch = 0;
}
}
}
static void VT_Plot(void)
{
static uint8_t ADCSwitch = 0;
static int32_t VoltData;
void *wm = wm_get();
if (batteryCheck_flag) {
EliteADCBattery();
if (!batteryCheck_flag) {
ReadADCVolt(VOLT_SW(wm));
ADCSwitch = 2;
}
} else {
if (ADCSwitch == 0) { /**read V(buffer)**/
if (VOLT_SW(wm) == 0x01 || VOLT_SW(wm) == 0x02) {
if (instru.VinAutoGainEnable) {
MEAS_VIN(wm) = AutoGainReadVin(spi_ADC_rxbuf);
AutoGainChangeVin(MEAS_VIN(wm));
} else {
ReadADCVolt(VOLT_SW(wm));
MEAS_VIN(wm) = DecodeADCValue(instru.VinADCGainLevel, ADC_CH_VOLT, spi_ADC_rxbuf);
if (lastVinADCGainLevel != instru.VinADCGainLevel) {
VinADCGainControl(instru.VinADCGainLevel);
record_flag = false;
}
}
VoltData = MEAS_VIN(wm);
} else if (VOLT_SW(wm) == 0x00) {
ReadADCVolt(VOLT_SW(wm));
MEAS_VOUT(wm) = DecodeADCValue(instru.ADCGainLevel, ADC_CH_DAC, spi_ADC_rxbuf);
VoltData = MEAS_VOUT(wm);
}
if (record_flag == false) {
static int recordCount = 0;
recordCount++;
if (recordCount == 2) {
record_flag = true;
recordCount = 0;
}
} else {
InputNotify(NOTIFY_VOLT, VoltData);
}
ADCSwitch++;
} else if (ADCSwitch == 1) { /**read V**/
ReadADCVolt(VOLT_SW(wm));
ADCSwitch++;
} else if (ADCSwitch == 2) { /**read V**/
ReadADCVolt(VOLT_SW(wm));
ADCSwitch = 0;
}
}
}
static void cali_IT_plot(void) {
void *wm = wm_get();
static uint8_t ADCSwitch = 0;
static int32_t ADCValueSUM = 0;
int32_t ADCValueAVG = 0;
static uint16_t cali_count_max = 1000;
if(ADCSwitch == 0){ /**read Iin(buffer)**/
if(instru.AutoGainEnable){
MEAS_CURR(wm) = 0xFFFF;
}else{
ReadADCIin(spi_ADC_rxbuf);
MEAS_CURR(wm) = (int32_t) (spi_ADC_rxbuf[0] << 8) | (int32_t) (spi_ADC_rxbuf[1]);
if(lastIinADCGainLevel != instru.ADCGainLevel){
IinADCGainControl(instru.ADCGainLevel);
record_flag = false;
}
}
if(instru.ADCGainLevel == 0) {
cali_count_max = 5000;
} else {
cali_count_max = 1000;
}
if(record_flag == false){
static int recordCount = 0;
recordCount++;
if(recordCount == 2){
record_flag = true;
recordCount = 0;
}
}else{
static uint16_t cali_count = 0;
if(cali_count >= cali_count_max){
ADCValueAVG = ADCValueSUM / cali_count;
InputNotify(NOTIFY_CURRENT, ADCValueAVG);
SendNotify();
uint8_t CIS_buf[9] = {0};
CIS_buf[0] = instru.chip_id;
CIS_buf[1] = (uint8_t) ((ADCValueAVG & 0xFF00) >> 8);
CIS_buf[2] = (uint8_t) (ADCValueAVG & 0x00FF);
CIS_buf[3] = 0x00;
CIS_buf[4] = instru.ADCGainLevel;
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 9, CIS_buf);
ADCValueSUM = 0;
cali_count = 0;
PeriodicEvent = false;
ModeLED(NO_EVENT);
}else{
cali_count++;
ADCValueSUM = ADCValueSUM + MEAS_CURR(wm);
InputNotify(NOTIFY_CURRENT, MEAS_CURR(wm));
InputNotify(NOTIFY_VOLT, ADCValueSUM);
InputNotify(NOTIFY_IMPEDANCE, (int32_t)cali_count);
}
}
ADCSwitch++;
}
else if(ADCSwitch == 1){ /**read Iin**/
ReadADCIin(spi_ADC_rxbuf);
ADCSwitch++;
}
else if(ADCSwitch == 2){ /**read Iin**/
ReadADCIin(spi_ADC_rxbuf);
ADCSwitch = 0;
}
}
static void cali_VT_plot(void) {
void *wm = wm_get();
static uint8_t ADCSwitch = 0;
static int32_t VoltData = 0;
static int32_t ADCValueSUM = 0;
int32_t ADCValueAVG = 0;
static uint16_t cali_count_max = 1000;
if(ADCSwitch == 0){ /**read Iin(buffer)**/
if(VOLT_SW(wm) == 0x01 || VOLT_SW(wm) == 0x02){
if(instru.VinAutoGainEnable){
MEAS_VIN(wm) = 0xFFFF;
}else{
ReadADCVolt(VOLT_SW(wm));
MEAS_VIN(wm) = (int32_t) (spi_ADC_rxbuf[0] << 8) | (int32_t) (spi_ADC_rxbuf[1]);
if(lastVinADCGainLevel != instru.VinADCGainLevel){
VinADCGainControl(instru.VinADCGainLevel);
record_flag = false;
}
}
VoltData = MEAS_VIN(wm);
}
if(instru.VinADCGainLevel == 0) {
cali_count_max = 5000;
} else {
cali_count_max = 1000;
}
if(record_flag == false){
static int recordCount = 0;
recordCount++;
if(recordCount == 2){
record_flag = true;
recordCount = 0;
}
}else{
static uint16_t cali_count = 0;
if(cali_count >= cali_count_max){
ADCValueAVG = ADCValueSUM / cali_count;
InputNotify(NOTIFY_VOLT, ADCValueAVG);
SendNotify();
uint8_t CIS_buf[9] = {0};
CIS_buf[0] = instru.chip_id;
CIS_buf[1] = (uint8_t) ((ADCValueAVG & 0xFF00) >> 8);
CIS_buf[2] = (uint8_t) (ADCValueAVG & 0x00FF);
CIS_buf[3] = 0x00;
CIS_buf[4] = instru.VinADCGainLevel;
SimpleProfile_SetParameter(BLE_CIS_BUFF_CHAR, 9, CIS_buf);
ADCValueSUM = 0;
cali_count = 0;
PeriodicEvent = false;
ModeLED(NO_EVENT);
}else{
cali_count++;
ADCValueSUM = ADCValueSUM + MEAS_VIN(wm);
InputNotify(NOTIFY_VOLT, MEAS_VIN(wm));
InputNotify(NOTIFY_CURRENT, ADCValueSUM);
InputNotify(NOTIFY_IMPEDANCE, (int32_t)cali_count);
}
}
ADCSwitch++;
}
else if(ADCSwitch == 1){ /**read v**/
ReadADCVolt(VOLT_SW(wm));
ADCSwitch++;
}
else if(ADCSwitch == 2){ /**read v**/
ReadADCVolt(VOLT_SW(wm));
ADCSwitch = 0;
}
}
#endif
@@ -2,11 +2,11 @@
#ifndef VERSION_DATE
#define VERSION_DATE
#define VERSION_DATE_YEAR 21
#define VERSION_DATE_MONTH 4
#define VERSION_DATE_DAY 9
#define VERSION_DATE_HOUR 16
#define VERSION_DATE_MINUTE 23
#define VERSION_DATE_YEAR 20
#define VERSION_DATE_MONTH 7
#define VERSION_DATE_DAY 17
#define VERSION_DATE_HOUR 10
#define VERSION_DATE_MINUTE 34
// this is NOT the version hash !!
// it's the last version hash
@@ -129,16 +129,16 @@ static void update_ins_sti_channel(uint8_t *buf, uint8 sti_chp, uint8 sti_chn) {
static void update_ins_buffer() {
uint8 header = 0b10100000;
uint8 amp_gain = (instru.amp_gain & 0b11) << 3;
uint8 amp_lbf = instru.amp_low_band_freq & 0b111;
uint8 amp_gain = (INSTRUCTION.amp_gain & 0b11) << 3;
uint8 amp_lbf = INSTRUCTION.amp_low_band_freq & 0b111;
uint8 channel = 0; // should be call update_ins_channel to modify this value
uint8 chopper = (instru.chopper) ? 0b00001000 : 0;
uint8 fast_settle = (instru.fast_settle) ? 0b00000100 : 0;
uint8 sti_enable = (instru.work_mode != STI_MODE_DISABLE) ? 0b00000010 : 0;
uint8 sti_volt_l = (instru.sti_volt & 0b11111) >> 4;
uint8 sti_volt_h = (instru.sti_volt & 0b01111) << 4;
uint8 sti_chp = instru.sti_channel_pmos & 0b1111;
uint8 sti_chn = (instru.sti_channel_nmos & 0b1111) << 4;
uint8 chopper = (INSTRUCTION.chopper) ? 0b00001000 : 0;
uint8 fast_settle = (INSTRUCTION.fast_settle) ? 0b00000100 : 0;
uint8 sti_enable = (INSTRUCTION.work_mode != STI_MODE_DISABLE) ? 0b00000010 : 0;
uint8 sti_volt_l = (INSTRUCTION.sti_volt & 0b11111) >> 4;
uint8 sti_volt_h = (INSTRUCTION.sti_volt & 0b01111) << 4;
uint8 sti_chp = INSTRUCTION.sti_channel_pmos & 0b1111;
uint8 sti_chn = (INSTRUCTION.sti_channel_nmos & 0b1111) << 4;
uint8 clk_signal = 0; // should be call update_ins_clock to modify this value
spi_txbuf[0] = header | amp_gain | amp_lbf;
@@ -193,7 +193,7 @@ static bool update_ins_rec_buffer() {
* @param: buf: pointer of the SPI buffer.
*/
static void update_ins_sti_buffer() {
switch (instru.work_mode) {
switch (INSTRUCTION.work_mode) {
case STI_MODE_POS:
case STI_MODE_NEG:
// copy [4:7]
@@ -215,7 +215,7 @@ static void update_ins_sti_buffer() {
update_ins_sti_enable(spi_txbuf, TRUE);
// ins buf [4:7]
update_ins_sti_enable(spi_txbuf + 4, TRUE);
update_ins_sti_channel(spi_txbuf + 4, 0xF, instru.sti_channel_pmos);
update_ins_sti_channel(spi_txbuf + 4, 0xF, INSTRUCTION.sti_channel_pmos);
// ins buf [8:B]
update_ins_sti_enable(spi_txbuf + 8, FALSE);
break;
@@ -238,13 +238,13 @@ static void update_ins_sti_buffer() {
spi_txbuf[15] = spi_txbuf[3];
// change content
update_ins_sti_enable(spi_txbuf + 0, TRUE);
update_ins_sti_channel(spi_txbuf + 0, instru.sti_channel_pmos, instru.sti_channel_nmos);
update_ins_sti_channel(spi_txbuf + 0, INSTRUCTION.sti_channel_pmos, INSTRUCTION.sti_channel_nmos);
// ins buf [4:7]
update_ins_sti_enable(spi_txbuf + 4, TRUE);
update_ins_sti_channel(spi_txbuf + 4, instru.sti_channel_nmos, instru.sti_channel_pmos);
update_ins_sti_channel(spi_txbuf + 4, INSTRUCTION.sti_channel_nmos, INSTRUCTION.sti_channel_pmos);
// ins buf [8:B]
update_ins_sti_enable(spi_txbuf + 8, TRUE);
update_ins_sti_channel(spi_txbuf + 8, 0xF, instru.sti_channel_nmos);
update_ins_sti_channel(spi_txbuf + 8, 0xF, INSTRUCTION.sti_channel_nmos);
// ins buf [C:F]
update_ins_sti_enable(spi_txbuf + 12, FALSE);
break;
@@ -281,12 +281,12 @@ static void headstage_tni_update_instruction_callback(uint8_t ins_type, uint8_t
}
static uint8_t *spi_transact_rec_instruction() {
if (IS_REC_MODE(instru.work_mode)) {
if (IS_REC_MODE(INSTRUCTION.work_mode)) {
PIN_setOutputValue(pin_handle, IOID_13, 1); // DBS_P2S turn on
headstage_spi_transaction(SPI_BUFFER_SIZE, spi_txbuf, spi_rxbuf);
PIN_setOutputValue(pin_handle, IOID_13, 0); // DBS_P2S turn off
} else if (IS_ARM_MODE(instru.work_mode) && !adc_clock_signal) {
} else if (IS_ARM_MODE(INSTRUCTION.work_mode) && !adc_clock_signal) {
create_ramp(spi_rxbuf);
}
@@ -22,7 +22,7 @@
#include "EliteWorkData.h"
#include <driverlib/aon_batmon.h>
static void SimpleBLEPeripheral_performPeriodicTask(void);
static void SimpleBLEPeripheral_performPeriodicTask(WorkMode *WorkModeData);
static void SimpleBLEPeripheral_clockHandler(UArg arg) {
// Store the event.
@@ -46,26 +46,16 @@ static void ZM_init() {
// initialize
pin_handle = PIN_open(&ZM_rst, BLE_IO);
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; 0: open;
PIN_setOutputValue(pin_handle, shutdown_6994, 1); // OFF = 1 => turn off 6994
PIN_setOutputValue(pin_handle, enable_10v, 0); // enable 10V
PIN_setOutputValue(pin_handle, ADC_CS, 1); // ADC_CS HIGH
PIN_setOutputValue(pin_handle, DAC_CS, 1); // DAC_CS HIGH
InitEliteInstruction();
// init DAC, set output ~= 0 V
instru.VoutGainLevel = VOUT_GAIN_15K;
VoutGainControl(instru.VoutGainLevel);
DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLevel, 25000));
/* when elite open, must change vin level,
measure battery value will be right */
VinADCGainControl(VIN_GAIN_AUTO);
ADCGainControl(GAIN_AUTO);
elite_gptimer_open();
elite_gptimer_start();
// PIN_registerIntCb(pin_handle, switch_on_callback);
// PIN_setInterrupt(pin_handle, switch_on | PIN_IRQ_POSEDGE);
@@ -76,7 +66,7 @@ static void ZM_update_instruction_callback(uint8_t ins_type, uint8_t chip_ID, ui
static void DACCode2Real2Notify(uint16_t DACcode) {
int32_t RealV;
RealV = DAC_to_realV(instru.VoutGainLevel, DACcode);
RealV = DAC_to_realV(DACcode);
NotifyVolt[0] = (uint8_t)((RealV & 0xFF000000) >> 24);
NotifyVolt[1] = (uint8_t)((RealV & 0x00FF0000) >> 16);
@@ -85,24 +75,34 @@ static void DACCode2Real2Notify(uint16_t DACcode) {
}
#define IsPeriodicMode() ( \
(instru.eliteFxn == CURVE_IV) || \
(instru.eliteFxn == CURVE_IV_CY) || \
(instru.eliteFxn == CURVE_IT) || \
(instru.eliteFxn == CURVE_VT) || \
(instru.eliteFxn == CURVE_RT) || \
(instru.eliteFxn == CURVE_CC) || \
(instru.eliteFxn == CURVE_CV) || \
(instru.eliteFxn == CURVE_LSV) || \
(instru.eliteFxn == CURVE_CA) || \
(instru.eliteFxn == CURVE_VO) || \
(instru.eliteFxn == CURVE_CALI_ADC) \
(INSTRUCTION.eliteFxn == IV_CURVE) || \
(INSTRUCTION.eliteFxn == CV_CURVE) || \
(INSTRUCTION.eliteFxn == IT_CURVE) || \
(INSTRUCTION.eliteFxn == VT_CURVE) || \
(INSTRUCTION.eliteFxn == ZT_CURVE) || \
(INSTRUCTION.eliteFxn == CONSTANT_CURRENT) || \
(INSTRUCTION.eliteFxn == CYCLIC_VOLTAMMETRY) || \
(INSTRUCTION.eliteFxn == LINEAR_SWEEP_VOLTAMMETRY) || \
(INSTRUCTION.eliteFxn == CONSTANT_VSCAN) \
)
#define Ve1MatchVe2Mode() ( \
(instru.eliteFxn == CURVE_IV) || \
(instru.eliteFxn == CURVE_IV_CY) || \
(instru.eliteFxn == CURVE_CV) || \
(instru.eliteFxn == CURVE_LSV) \
(INSTRUCTION.eliteFxn == IV_CURVE) || \
(INSTRUCTION.eliteFxn == CV_CURVE) || \
(INSTRUCTION.eliteFxn == CYCLIC_VOLTAMMETRY) || \
(INSTRUCTION.eliteFxn == LINEAR_SWEEP_VOLTAMMETRY) \
)
#define SendLastDataMode() ( \
(INSTRUCTION.eliteFxn == IV_CURVE) || \
(INSTRUCTION.eliteFxn == CV_CURVE) || \
(INSTRUCTION.eliteFxn == IT_CURVE) || \
(INSTRUCTION.eliteFxn == VT_CURVE) || \
(INSTRUCTION.eliteFxn == ZT_CURVE) || \
(INSTRUCTION.eliteFxn == CONSTANT_CURRENT) || \
(INSTRUCTION.eliteFxn == CYCLIC_VOLTAMMETRY) || \
(INSTRUCTION.eliteFxn == LINEAR_SWEEP_VOLTAMMETRY) || \
(INSTRUCTION.eliteFxn == CONSTANT_VSCAN) \
)
/*********************************************************************
@@ -114,61 +114,34 @@ static void DACCode2Real2Notify(uint16_t DACcode) {
*
* @return None.
*/
static void SimpleBLEPeripheral_performPeriodicTask(void) {
if (IsPeriodicMode()) {
static void SimpleBLEPeripheral_performPeriodicTask(WorkMode *WorkModeData) {
if ( IsPeriodicMode() ){
/** Periodic Event **/
// Default working flow is vscan -> ADC read -> send notify
// We will need a flag to control vscan, ADC and notify
static bool first_highz_flag = false;
GPT.DeltaGptimerCounter = GPT.GptimerCounter - GPT.GptimerCounter0;
GPT.GptimerCounter0 = GPT.GptimerCounter;
if (mode_init) {
GPT.SampleRateCounter = instru.sampleRate - 10;
GPT.VscanRateCounter = instru.VsetRate - 1;
mode_init = false;
if(EliteWorkReset){
InitEliteGPtimer();
EliteWorkReset = false;
batteryADC_flag = false;
record_flag = true;
firstTimeReset = true;
notifyFirst_flag = true;
first_highz_flag = true;
I_GAIN_100R_counter = 0;
I_GAIN_3K_counter = 0;
I_GAIN_100K_counter = 0;
I_GAIN_3M_counter = 0;
VIN_GAIN_1M_counter = 0;
VIN_GAIN_30K_counter = 0;
VIN_GAIN_1K_counter = 0;
VOUT_GAIN_240K_counter = 0;
VOUT_GAIN_15K_counter = 0;
DACReset = true;
vscanReset = true;
leadTimeReset = true;
VinADCGainControl(instru.VinADCGainLevel);
IinADCGainControl(instru.ADCGainLevel);
VoutGainControl(instru.VoutGainLevel);
if (Ve1MatchVe2Mode()) {
if (instru.Ve1 == instru.Ve2) {
DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLevel, instru.Ve1));
if( Ve1MatchVe2Mode() ){
if (INSTRUCTION.Ve1 == INSTRUCTION.Ve2) {
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.Ve1));
PeriodicEvent = false;
PIN15_setOutputValue(HIGH_Z_MODE, 0); // 0: open highz;
ModeLED(NO_EVENT);
}
}
}
GPT.LeadTimeCounter = GPT.LeadTimeCounter + GPT.DeltaGptimerCounter;
if (leadTimeReset && GPT.LeadTimeCounter <= 2000) {
if(leadTimeReset && GPT.LeadTimeCounter <= 2000){
vscanReset = true;
if (first_highz_flag && GPT.LeadTimeCounter >= 1000) {
PIN15_setOutputValue(HIGH_Z_MODE, 1); // HIGH Z MODE // 1: close; 0: open;
first_highz_flag = false;
}
} else {
if (notifyFirst_flag) {
GPT.NotifyCounter = instru.notifyRate - 20;
}else{
if(notifyFirst_flag){
GPT.NotifyCounter = INSTRUCTION.notifyRate - 20;
notifyFirst_flag = false;
}
vscanReset = false;
@@ -177,16 +150,11 @@ static void SimpleBLEPeripheral_performPeriodicTask(void) {
//vscan counter
GPT.VscanRateCounter = GPT.VscanRateCounter + GPT.DeltaGptimerCounter;
if (GPT.VscanRateCounter >= instru.VsetRate) {
if (GPT.VscanRateCounter >= instru.VsetRate * 2) {
GPT.GptimerMultiple = GPT.VscanRateCounter / instru.VsetRate;
} else {
GPT.GptimerMultiple = 1;
}
GPT.VscanRateCounter -= instru.VsetRate * GPT.GptimerMultiple; //To get right time
if(GPT.VscanRateCounter >= INSTRUCTION.VsetRate){
GPT.VscanRateCounter -= INSTRUCTION.VsetRate; //To get right time
vscan_flag = true;
if (vscan_flag) {
vscan_ctrl();
if(vscan_flag){
EliteVscanControl(WorkModeData);
vscan_flag = false;
}
}
@@ -201,16 +169,16 @@ static void SimpleBLEPeripheral_performPeriodicTask(void) {
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
GPT.SampleRateCounter = GPT.SampleRateCounter + GPT.DeltaGptimerCounter;
if(GPT.SampleRateCounter >= instru.sampleRate){
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();
EliteADCControl(WorkModeData);
ADC_flag = false;
}
}
@@ -218,8 +186,8 @@ static void SimpleBLEPeripheral_performPeriodicTask(void) {
//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 >= instru.notifyRate){
GPT.NotifyCounter -= instru.notifyRate; //To get right time
if(GPT.NotifyCounter >= INSTRUCTION.notifyRate){
GPT.NotifyCounter -= INSTRUCTION.notifyRate; //To get right time
notify_flag = true;
if(vscanReset){
notify_flag = false;
@@ -230,214 +198,100 @@ static void SimpleBLEPeripheral_performPeriodicTask(void) {
}
}
mode_done();
}
else if (instru.eliteFxn == CURVE_PULSE) {
/** Periodic Event **/
// Default working flow is vscan -> ADC read -> send notify
// We will need a flag to control vscan, ADC and notify
GPT.DeltaGptimerCounter = GPT.GptimerCounter - GPT.GptimerCounter0;
GPT.GptimerCounter0 = GPT.GptimerCounter;
if(mode_init){
GPT.SampleRateCounter = instru.sampleRate - 10;
GPT.VscanRateCounter = instru.VsetRate - 1;
mode_init = false;
batteryADC_flag = false;
record_flag = true;
firstTimeReset = true;
notifyFirst_flag = true;
//pulsemode variable
stiFirstTime = true;
VinADCGainControl(instru.VinADCGainLevel);
IinADCGainControl(instru.ADCGainLevel);
VoutGainControl(instru.VoutGainLevel);
if (Ve1MatchVe2Mode()) {
if (instru.Ve1 == instru.Ve2) {
DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLevel, instru.Ve1));
PeriodicEvent = false;
PIN15_setOutputValue(HIGH_Z_MODE, 0); // 0: open highz;
ModeLED(NO_EVENT);
}
} else if (instru.eliteFxn == CURVE_PULSE) {
if(!megaStiEnable){
PeriodicEvent = false;
PIN15_setOutputValue(HIGH_Z_MODE, 0); // 0: open highz;
ModeLED(NO_EVENT);
}
}
}
GPT.LeadTimeCounter = GPT.LeadTimeCounter + GPT.DeltaGptimerCounter;
if(leadTimeReset && GPT.LeadTimeCounter <= 2000){
vscanReset = true;
}else{
if(notifyFirst_flag){
GPT.NotifyCounter = instru.notifyRate - 20;
notifyFirst_flag = false;
}
vscanReset = false;
leadTimeReset = false;
}
//vscan counter
GPT.VscanRateCounter = GPT.VscanRateCounter + GPT.DeltaGptimerCounter;
//pulse mode counter
GPT.StiCounter = GPT.StiCounter + GPT.DeltaGptimerCounter;
if (vscanReset) {
DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLevel, 25000));
DAC_outputV(Usercode_Correction_to_DAC(instru.VoutGainLevel, 25000));
//vscanReset = false;
}else{
if (megaStiEnable) {
pulse_vscan();
}
}
// if(GPT.VscanRateCounter >= instru.VsetRate){
// if(GPT.VscanRateCounter >= instru.VsetRate * 2){
// GPT.GptimerMultiple = GPT.VscanRateCounter / instru.VsetRate;
// }else{
// GPT.GptimerMultiple = 1;
// }
// GPT.VscanRateCounter -= instru.VsetRate * GPT.GptimerMultiple; //To get right time
// vscan_flag = true;
// if(vscan_flag){
// vscan_ctrl();
// 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 >= instru.sampleRate){
GPT.SampleRateCounter = 0; //To get right data, ADC must be delay 1.5ms
ADC_flag = true;
if(ADC_flag){
EliteADCControl();
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 >= instru.notifyRate){
GPT.NotifyCounter -= instru.notifyRate; //To get right time
notify_flag = true;
if(vscanReset){
notify_flag = false;
}
if(notify_flag){
SendNotify();
notify_flag = false;
}
}
mode_done();
}
else if (instru.eliteFxn == CURVE_CALI_DAC) {
DAC_outputV(instru.VoltConstant); //UserCode -> DAC code -> DAC out
wm_deinit();
EliteDone();
}else if(INSTRUCTION.eliteFxn == VOLT_OUTPUT){
WorkModeData->VO->_Vset = INSTRUCTION.VoltConstant;
DAC_outputV(Usercode_Correction_to_DAC(WorkModeData->VO->_Vset)); //UserCode -> DAC code -> DAC out
FreeWorkMode(WorkModeData);
PeriodicEvent = false;
} else {
}else{
InitFlag();
}
}
static void EliteADCControl(void)
{
switch (instru.eliteFxn) {
case CURVE_IV:
case CURVE_RT:
case CURVE_CC:
case CURVE_CV:
case CURVE_CA:
case CURVE_VO:
case CURVE_LSV:
case CURVE_IV_CY:
case CURVE_PULSE:
CC_Plot();
static void EliteADCControl(WorkMode *WorkModeData) {
switch (INSTRUCTION.eliteFxn) {
case IV_CURVE:{
ZT_Plot(WorkModeData);
break;
case CURVE_IT:
IT_Plot();
}
case CV_CURVE:{
ZT_Plot(WorkModeData);
break;
case CURVE_VT:
VT_Plot();
}
case IT_CURVE:{
IT_Plot(WorkModeData);
break;
case CURVE_CALI_ADC:
if (instru.AdcChannel == IIN_ADC) cali_IT_plot();
else if (instru.AdcChannel == VIN_ADC) cali_VT_plot();
}
case VT_CURVE:{
VT_Plot(WorkModeData);
break;
default:
}
case ZT_CURVE:{
ZT_Plot(WorkModeData);
break;
}
case CONSTANT_CURRENT:{
CC_Plot(WorkModeData);
break;
}
case CYCLIC_VOLTAMMETRY:{
CC_Plot(WorkModeData);
break;
}
case LINEAR_SWEEP_VOLTAMMETRY:{
CC_Plot(WorkModeData);
break;
}
case CONSTANT_VSCAN:{
CC_Plot(WorkModeData);
break;
}
default:{
break;
}
}
static void mode_done(void)
{
if ((instru.eliteFxn == CURVE_IV) ||
(instru.eliteFxn == CURVE_CV) ||
(instru.eliteFxn == CURVE_LSV) ||
(instru.eliteFxn == CURVE_IV_CY)) {
if (!PeriodicEvent) {
finishMode = 1;
SendNotify();
Eliteinterrupt();
}
}
}
static void vscan_ctrl(void)
{
switch (instru.eliteFxn) {
case CURVE_IV:
iv_vscan();
break;
static void EliteDone() {
if ((INSTRUCTION.eliteFxn == IV_CURVE) || (INSTRUCTION.eliteFxn == CV_CURVE) || (INSTRUCTION.eliteFxn == CYCLIC_VOLTAMMETRY)) {
if (!PeriodicEvent) {
SendNotify();
reset();
}
}
}
case CURVE_IV_CY:
iv_cy_vscan();
static void EliteVscanControl(WorkMode *WorkModeData) {
switch (INSTRUCTION.eliteFxn) {
case IV_CURVE:{
IV_Vscan(WorkModeData->IV);
break;
case CURVE_VO:
vo_vscan();
}
case CV_CURVE:{
CV_Vscan(WorkModeData->CV);
break;
case CURVE_RT:
rt_vscan();
}
case ZT_CURVE:{
ZT_Vscan(WorkModeData->RT);
break;
case CURVE_CV:
cv_vscan();
}
case CYCLIC_VOLTAMMETRY:{
CV3_Vscan(WorkModeData->CV3);
break;
case CURVE_LSV:
lsv_vscan();
}
case CONSTANT_CURRENT:{
CC_Vscan(WorkModeData->CC);
break;
case CURVE_CA:
ca_vscan();
}
case LINEAR_SWEEP_VOLTAMMETRY:{
LSV_Vscan(WorkModeData->LSV);
break;
}
case CONSTANT_VSCAN:{
CVSCAN_Vscan(WorkModeData->CVSCAN);
break;
}
default:{
break;
}
@@ -472,16 +326,37 @@ static void step2VsetRate(uint32_t step){
0.01mv, index = 4, n = 10000 */
if(step >= 10000){
instru.VsetRateIndex = 0;
INSTRUCTION.VsetRateIndex = 0;
}else if (step >= 1000){
instru.VsetRateIndex = 1;
INSTRUCTION.VsetRateIndex = 1;
}else if (step >= 100){
instru.VsetRateIndex = 2;
INSTRUCTION.VsetRateIndex = 2;
}else if (step >= 10){
instru.VsetRateIndex = 3;
INSTRUCTION.VsetRateIndex = 3;
}else if (step >= 1){
instru.VsetRateIndex = 4;
INSTRUCTION.VsetRateIndex = 4;
}
}
static void InitFlag(){
PeriodicEvent = false; // is there an PeriodicEvent?
Free_Work_Mode = true; // Free(WorkModeData)
}
static void InitEliteGPtimer() {
GPT.SampleRateCounter = INSTRUCTION.sampleRate - 10;
GPT.VscanRateCounter = INSTRUCTION.VsetRate - 1;
notifyFirst_flag = true;
}
static void InitEliteFlag() {
InitPeriodicEvent = true; // need to create a WorkModeData?
DACReset = true;
vscanReset = true;
EliteWorkReset = true;
leadTimeReset = true;
GAIN_200R_counter = 0;
GAIN_200K_counter = 0;
GAIN_10K_counter = 0;
}
#endif /* IMPEDANCE_METER_H_ */
@@ -127,11 +127,11 @@
#ifndef FEATURE_OAD
// Minimum connection interval (units of 1.25ms, 80=100ms) if automatic
// parameter update request is enabled
#define DEFAULT_DESIRED_MIN_CONN_INTERVAL 6
#define DEFAULT_DESIRED_MIN_CONN_INTERVAL 8
// Maximum connection interval (units of 1.25ms, 800=1000ms) if automatic
// parameter update request is enabled
#define DEFAULT_DESIRED_MAX_CONN_INTERVAL 6
#define DEFAULT_DESIRED_MAX_CONN_INTERVAL 30
#else //! FEATURE_OAD
// Minimum connection interval (units of 1.25ms, 8=10ms) if automatic
// parameter update request is enabled
@@ -543,18 +543,25 @@ static void SimpleBLEPeripheral_init(void) {
// static void detectKey_clockHandler(UArg arg);
static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
uint8_t key= 0;
bool EliteOn = 0;
uint16_t counter6994 = 0;
batteryADC_flag = false;
// Initialize application
SimpleBLEPeripheral_init();
ZM_init();
Elite_SPI_init();
WorkMode *WorkModeData = CreateWorkMode();
uint8_t key = 0;
uint16_t counter6994 = 0;
bool EliteOn = 0;
// init DAC, set output ~= 0 V
DAC_outputV(Usercode_Correction_to_DAC(25000));
elite_gptimer_start();
// Application main loops
GPT.GptimerCounter0 = GPT.GptimerCounter;
batteryADC_flag = false;
headstage_battery_volt();
headstage_init_device_info();
@@ -605,28 +612,52 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
}
}
}
if(events & SBP_PERIODIC_EVT){
events &= ~SBP_PERIODIC_EVT;
if (!PeriodicEvent) { // if there is no periodic event
key = PIN_getInputValue(switch_on);
if (EliteOn) {
if (counter6994 < CLOCK_ONE_SECOND*5) { // counter6994 enable a IC after 35 counts
if (counter6994 < CLOCK_ONE_SECOND/2) { // counter6994 enable a IC after 35 counts
counter6994++;
} else if (counter6994 == CLOCK_ONE_SECOND*5) {
PIN15_setOutputValue(shutdown_6994, 0); // OFF = 1 => turn off 6994
} else if (counter6994 == CLOCK_ONE_SECOND/2) {
PIN_setOutputValue(pin_handle, shutdown_6994, 1); // OFF = 1 => turn off 6994
counter6994++;
} else if (counter6994 > CLOCK_ONE_SECOND*5) {
counter6994 = 0;
}
EliteKeyPress(key);
if(key != 0){ //detect Elite battery power when no periodic event
measureBat();
GPT.DeltaGptimerCounter = GPT.GptimerCounter - GPT.GptimerCounter0;
GPT.GptimerCounter0 = GPT.GptimerCounter;
GPT.BatteryADCCounter = GPT.BatteryADCCounter + GPT.DeltaGptimerCounter;
GPT.BatteryCheckCounter = GPT.BatteryCheckCounter + GPT.DeltaGptimerCounter;
if(GPT.BatteryCheckCounter >= 50000){//5min=3000000, 5s=50000
GPT.BatteryCheckCounter = 0;
batteryCheck_flag = true;
}
if(GPT.BatteryADCCounter >= 15 && batteryCheck_flag){
GPT.BatteryADCCounter = 0; //To get the data right, ADC must be delay 1.5ms
batteryADC_flag = true;
if(batteryADC_flag){
EliteADCBattery();
batteryADC_flag = false;
}
}
uint16_t bat = ((uint16_t)(NotifyVoltBat[2]) << 8 & 0xFF00 ) |
((uint16_t)(NotifyVoltBat[3]) & 0x00FF);
if( bat < 768 && bat > 20){
PIN_setOutputValue(pin_handle, enable_5v, 0);
}
}
if(Free_Work_Mode){
wm_deinit();
FreeWorkMode(WorkModeData);
InitEliteInstruction();
ADCGainControl(INSTRUCTION.ADCGainLevel);
DAC_outputV(Usercode_Correction_to_DAC(INSTRUCTION.VoltConstant));
Free_Work_Mode = false;
}
} else {
@@ -635,12 +666,12 @@ static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1) {
}
else { // if there is periodic event
if(InitPeriodicEvent){
wm_init();
InitWorkMode(WorkModeData);
InitPeriodicEvent = false;
}
// Perform periodic application task
SimpleBLEPeripheral_performPeriodicTask();
SimpleBLEPeripheral_performPeriodicTask(WorkModeData);
key = PIN_getInputValue(switch_on);
EliteKeyPress(key); // onPress=> key = 0; 1.lighten LED 2.long press shut down 2650
}
@@ -919,6 +950,7 @@ static void SimpleBLEPeripheral_processStateChangeEvt(gaprole_States_t newState)
numActive = linkDB_NumActive();
uint16_t cxnHandle;
// requestedPDUSize = LL payload = L2CAP_header + ATT header + BLE_NOT_BUFF_SIZE = 7 + BLE_NOT_BUFF_SIZE //roy
@@ -964,12 +996,11 @@ static void SimpleBLEPeripheral_processStateChangeEvt(gaprole_States_t newState)
case GAPROLE_WAITING:
SimpleBLEPeripheral_freeAttRsp(bleNotConnected);
ModeLED(BT_WAIT);
break;
case GAPROLE_WAITING_AFTER_TIMEOUT:
SimpleBLEPeripheral_freeAttRsp(bleNotConnected);
ModeLED(BT_WAIT);
#ifdef PLUS_BROADCASTER
// Reset flag for next connection.
@@ -85,7 +85,7 @@ extern "C"
// Length of Characteristic 5 in bytes
#define SIMPLEPROFILE_CHAR5_LEN 5
#define SIMPLEPROFILE_CHAR4_LEN 60
#define SIMPLEPROFILE_CHAR4_LEN 200
#define SIMPLEPROFILE_CHAR3_LEN 20
#define SIMPLEPROFILE_CHAR2_LEN 20