This commit is contained in:
qiyongshuang
2026-08-10 10:47:09 +08:00
parent 804daf39a2
commit dfe5ceea43
150 changed files with 20271 additions and 58 deletions
@@ -0,0 +1,301 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.2606500741">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.2606500741" moduleId="org.eclipse.cdt.core.settings" name="obj">
<macros/>
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactExtension="elf" artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release" cleanCommand="${cross_rm} -rf" description="" errorParsers="org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.GCCErrorParser" id="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.2606500741" name="obj" parent="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release" postannouncebuildStep="" postbuildStep="" preannouncebuildStep="" prebuildStep="">
<folderInfo id="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.2606500741" name="/" resourcePath="">
<toolChain id="ilg.gnumcueclipse.managedbuild.cross.riscv.toolchain.elf.release.2606500741" name="RISC-V Cross GCC" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.toolchain.elf.release">
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.rvGcc.1171217701" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.rvGcc" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.rvGcc.15" valueType="enumerated"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.base.1900297968" name="Architecture" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.base" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.arch.rv32i" valueType="enumerated"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.multiply.1509705449" name="Multiply extension (RVM)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.multiply" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.atomic.1590833110" name="Atomic extension (RVA)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.atomic" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.fp.1709872289" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.fp" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.isa.fp.none" valueType="enumerated"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.compressed.1038505275" name="Compressed extension (RVC)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.compressed" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.xw.1505432023" name="Extra Compressed extension (RVXW)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.xw" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.b.1896185078" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.b" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.zmmul.724822239" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.zmmul" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.rvv.435767561" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.isa.rvv" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.isa.rvv." valueType="enumerated"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.abi.integer.387605487" name="Integer ABI" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.abi.integer" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.abi.integer.ilp32" valueType="enumerated"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.abi.fp.966196099" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.abi.fp" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.abi.fp.none" valueType="enumerated"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.tune.394563202" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.tune" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.tune.default" valueType="enumerated"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.codemodel.105093140" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.codemodel" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.codemodel.default" valueType="enumerated"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.smalldatalimit.1147643442" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.smalldatalimit" useByScannerDiscovery="false" value="8" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.align.322546450" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.align" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.align.default" valueType="enumerated"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.saverestore.367800619" name="Small prologue/epilogue (-msave-restore)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.saverestore" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.other.1526047739" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.target.other" useByScannerDiscovery="true" value="" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.level.514997414" name="Optimization Level" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.level" useByScannerDiscovery="true" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.level.size" valueType="enumerated"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.messagelength.1008570639" name="Message length (-fmessage-length=0)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.messagelength" useByScannerDiscovery="true" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.signedchar.467272439" name="'char' is signed (-fsigned-char)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.signedchar" useByScannerDiscovery="true" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.functionsections.2047756949" name="Function sections (-ffunction-sections)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.functionsections" useByScannerDiscovery="true" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.datasections.207613650" name="Data sections (-fdata-sections)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.datasections" useByScannerDiscovery="true" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.nocommon.358586167" name="No common unitialized (-fno-common)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.nocommon" useByScannerDiscovery="true" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.noinlinefunctions.1298414520" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.noinlinefunctions" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.freestanding.213924425" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.freestanding" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.nobuiltin.2007120903" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.nobuiltin" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.spconstant.938841347" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.spconstant" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.PIC.234574726" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.PIC" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.lto.1002322664" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.lto" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.nomoveloopinvariants.1270575343" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.nomoveloopinvariants" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.mrs.highcode.114339272" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.mrs.highcode" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.mrs.asmsoftlib.896763512" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.mrs.asmsoftlib" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.mrs.pipe.1835231981" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.mrs.pipe" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.mrs.caret.2021231049" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.mrs.caret" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.mrs.ccv.2026012911" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.mrs.ccv" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.other.180560481" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.optimization.other" useByScannerDiscovery="true" value="" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.syntaxonly.1145714735" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.syntaxonly" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.pedantic.1546854128" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.pedantic" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.pedanticerrors.338820707" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.pedanticerrors" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.nowarn.254465728" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.nowarn" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.unused.1961191588" name="Warn on various unused elements (-Wunused)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.unused" useByScannerDiscovery="true" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.uninitialized.929829166" name="Warn on uninitialized variables (-Wuninitialized)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.uninitialized" useByScannerDiscovery="true" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.allwarn.1168626160" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.allwarn" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.extrawarn.291772487" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.extrawarn" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.missingdeclaration.102344169" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.missingdeclaration" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.conversion.550923640" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.conversion" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.pointerarith.773148082" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.pointerarith" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.padded.1788238782" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.padded" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.shadow.427580978" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.shadow" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.logicalop.1501889551" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.logicalop" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.agreggatereturn.1785504720" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.agreggatereturn" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.floatequal.134298453" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.floatequal" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.toerrors.1117291056" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.toerrors" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.other.1918769559" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.warnings.other" useByScannerDiscovery="true" value="" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.level.1204865254" name="Debug level" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.level" useByScannerDiscovery="true" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.level.default" valueType="enumerated"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.format.867779652" name="Debug format" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.format" useByScannerDiscovery="true" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.format.dwarf4" valueType="enumerated"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.prof.2131276390" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.prof" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.gprof.1910159761" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.gprof" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.other.1654431258" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.debugging.other" useByScannerDiscovery="true" value="" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.toolchain.name.1218760634" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.toolchain.name" useByScannerDiscovery="false" value="GNU MCU RISC-V GCC" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.prefix.103341323" name="Prefix" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.prefix" useByScannerDiscovery="false" value="riscv32-wch-elf-" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.c.487601824" name="C compiler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.c" useByScannerDiscovery="false" value="gcc" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.cpp.1062130429" name="C++ compiler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.cpp" useByScannerDiscovery="false" value="g++" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.ar.1194282993" name="Archiver" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.ar" useByScannerDiscovery="false" value="ar" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.objcopy.1529355265" name="Hex/Bin converter" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.objcopy" useByScannerDiscovery="false" value="objcopy" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.objdump.1053750745" name="Listing generator" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.objdump" useByScannerDiscovery="false" value="objdump" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.size.1441326233" name="Size command" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.size" useByScannerDiscovery="false" value="size" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.make.550105535" name="Build command" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.make" useByScannerDiscovery="false" value="make" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.rm.719280496" name="Remove command" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.command.rm" useByScannerDiscovery="false" value="rm" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.toolchain.id.226017994" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.toolchain.id" useByScannerDiscovery="false" value="512258282" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.createflash.1311852988" name="Create flash image" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.createflash" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.createlisting.1983282875" name="Create extended listing" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.createlisting" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.printsize.1000761142" name="Print size" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.addtools.printsize" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="ilg.gnumcueclipse.managedbuild.cross.riscv.targetPlatform.1944008784" isAbstract="false" osList="all" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.targetPlatform"/>
<builder buildPath="${workspace_loc:/Electric_Hair_Dryer/obj" id="ilg.gnumcueclipse.managedbuild.cross.riscv.builder.1421508906" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" stopOnErr="true" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.builder"/>
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.assembler.1244756189" name="GNU RISC-V Cross Assembler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.assembler">
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.usepreprocessor.1692176068" name="Use preprocessor" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.usepreprocessor" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.nostdinc.821897907" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.nostdinc" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.preprocessonly.1205312655" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.preprocessonly" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.defs.181380015" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.defs" useByScannerDiscovery="true" valueType="definedSymbols"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.undefs.1514976831" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.undefs" useByScannerDiscovery="true" valueType="undefDefinedSymbols"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.include.paths.1034038285" name="Include paths (-I)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.include.paths" useByScannerDiscovery="true" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Startup}&quot;"/>
</option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.include.systempaths.496720673" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.include.systempaths" useByScannerDiscovery="true" valueType="includePath"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.include.files.1898455566" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.include.files" useByScannerDiscovery="true" valueType="includeFiles"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.otherwarnings.1717778600" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.otherwarnings" useByScannerDiscovery="true" value="" valueType="string"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.flags.1578223870" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.flags" useByScannerDiscovery="false" valueType="stringList"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.asmlisting.1937791148" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.asmlisting" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.savetemps.119863881" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.savetemps" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.verbose.1408057941" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.verbose" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.other.1308239903" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.assembler.other" useByScannerDiscovery="false" value="" valueType="string"/>
<inputType id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.assembler.input.126366858" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.assembler.input"/>
</tool>
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.1731377187" name="GNU RISC-V Cross C Compiler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler">
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.nostdinc.1633344562" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.nostdinc" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.preprocessonly.208069239" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.preprocessonly" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.defs.177116515" name="Defined symbols (-D)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.defs" useByScannerDiscovery="true" valueType="definedSymbols"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.undef.1820512625" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.undef" useByScannerDiscovery="true" valueType="undefDefinedSymbols"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.paths.1567947810" name="Include paths (-I)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.paths" useByScannerDiscovery="true" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Debug}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Core}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/User}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Peripheral/inc}&quot;"/>
</option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.systempaths.2011720354" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.systempaths" useByScannerDiscovery="true" valueType="includePath"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.files.542153928" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.files" useByScannerDiscovery="true" valueType="includeFiles"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.std.2020844713" name="Language standard" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.std" useByScannerDiscovery="true" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.std.gnu99" valueType="enumerated"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.otheroptimizations.92321033" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.otheroptimizations" useByScannerDiscovery="true" value="" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.warning.missingprototypes.1180998530" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.warning.missingprototypes" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.warning.strictprototypes.684937223" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.warning.strictprototypes" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.warning.badfunctioncast.1090658371" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.warning.badfunctioncast" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.otherwarnings.882361093" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.otherwarnings" useByScannerDiscovery="true" value="" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.asmlisting.1019398219" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.asmlisting" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.savetemps.1858747105" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.savetemps" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.verbose.658438318" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.verbose" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.other.1132663916" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.other" useByScannerDiscovery="true" value="" valueType="string"/>
<inputType id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.input.2036806839" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.input"/>
</tool>
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.cpp.compiler.1610882921" name="GNU RISC-V Cross C++ Compiler" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.cpp.compiler">
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.nostdinc.1306818359" name="Do not search system directories (-nostdinc)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.nostdinc" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.nostdincpp.411115799" name="Do not search system C++ directories (-nostdinc++)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.nostdincpp" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.preprocessonly.704235280" name="Preprocess only (-E)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.preprocessonly" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.defs.256688978" name="Defined symbols (-D)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.defs" useByScannerDiscovery="true" valueType="definedSymbols"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.undef.1769659537" name="Undefined symbols (-U)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.undef" useByScannerDiscovery="true" valueType="undefDefinedSymbols"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.include.paths.1641430352" name="Include paths (-I)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.include.paths" useByScannerDiscovery="true" valueType="includePath"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.include.systempaths.1217742259" name="Include system paths (-isystem)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.include.systempaths" useByScannerDiscovery="true" valueType="includePath"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.include.files.1922780842" name="Include files (-include)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.include.files" useByScannerDiscovery="true" valueType="includeFiles"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.std.426208505" name="Language standard" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.std" useByScannerDiscovery="true" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.std.gnucpp11" valueType="enumerated"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.abiversion.1671052931" name="ABI version" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.abiversion" useByScannerDiscovery="true" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.abiversion.0" valueType="enumerated"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.noexceptions.1891612477" name="Do not use exceptions (-fno-exceptions)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.noexceptions" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.nortti.76308566" name="Do not use RTTI (-fno-rtti)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.nortti" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.nousecxaatexit.390229569" name="Do not use _cxa_atexit() (-fno-use-cxa-atexit)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.nousecxaatexit" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.nothreadsafestatics.1143999424" name="Do not use thread-safe statics (-fno-threadsafe-statics)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.nothreadsafestatics" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.otheroptimizations.1589858535" name="Other optimization flags" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.otheroptimizations" useByScannerDiscovery="true" value="" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.warnabi.1304561076" name="Warn on ABI violations (-Wabi)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.warnabi" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.warning.ctordtorprivacy.534922494" name="Warn on class privacy (-Wctor-dtor-privacy)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.warning.ctordtorprivacy" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.warning.noexcept.1102421587" name="Warn on no-except expressions (-Wnoexcept)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.warning.noexcept" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.warning.nonvirtualdtor.249412631" name="Warn on virtual destructors (-Wnon-virtual-dtor)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.warning.nonvirtualdtor" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.warning.strictnullsentinel.1022346732" name="Warn on uncast NULL (-Wstrict-null-sentinel)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.warning.strictnullsentinel" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.warning.signpromo.1510049602" name="Warn on sign promotion (-Wsign-promo)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.warning.signpromo" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.warneffc.1507924344" name="Warn about Effective C++ violations (-Weffc++)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.warneffc" useByScannerDiscovery="true" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.otherwarnings.521572828" name="Other warning flags" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.otherwarnings" useByScannerDiscovery="true" value="" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.asmlisting.842958016" name="Generate assembler listing (-Wa,-adhlns=&quot;$@.lst&quot;)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.asmlisting" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.savetemps.715871177" name="Save temporary files (--save-temps Use with caution!)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.savetemps" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.verbose.974774820" name="Verbose (-v)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.verbose" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.other.1293392631" name="Other compiler flags" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.compiler.other" useByScannerDiscovery="true" value="" valueType="string"/>
<inputType id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.cpp.compiler.input.1079228323" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.cpp.compiler.input"/>
</tool>
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.linker.1620074387" name="GNU RISC-V Cross C Linker" outputPrefix="" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.linker">
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.scriptfile.1390103472" name="Script files (-T)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.scriptfile" useByScannerDiscovery="false" valueType="stringList">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Ld/Link.ld}&quot;"/>
</option>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.nostart.913830613" name="Do not use standard start files (-nostartfiles)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.nostart" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.nodeflibs.1285997013" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.nodeflibs" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.nostdlibs.179047434" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.nostdlibs" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.gcsections.194760422" name="Remove unused sections (-Xlinker --gc-sections)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.gcsections" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.printgcsections.270824644" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.printgcsections" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.strip.1802601885" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.strip" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.libs.813115939" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.libs" useByScannerDiscovery="false" valueType="libs">
<listOptionValue builtIn="false" value="IQmath_RV32"/>
</option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.paths.2057340378" name="Library search path (-L)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.paths" useByScannerDiscovery="false" valueType="libPaths">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/User}&quot;"/>
</option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.flags.1125808200" name="Linker flags (-Xlinker [option])" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.flags" useByScannerDiscovery="false" valueType="stringList"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.otherobjs.16994550" name="Other objects" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.otherobjs" useByScannerDiscovery="false" valueType="userObjs">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/User/libM12023_SV_1.0_COMCoreV1.5_Library.a}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/User/IQmath_RV32.a}&quot;"/>
</option>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.mapfilename.789195953" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.mapfilename" useByScannerDiscovery="false" value="&quot;${BuildArtifactFileBaseName}.map&quot;" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.picolibc.62047318" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.picolibc" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.picolibc.disabled" valueType="enumerated"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.cref.824432654" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.cref" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.printmap.751686263" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.printmap" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnano.239404511" name="Use newlib-nano (--specs=nano.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnano" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnosys.351964161" name="Do not use syscalls (--specs=nosys.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usenewlibnosys" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.useprintffloat.695795083" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.useprintffloat" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usescanffloat.1839373535" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.usescanffloat" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.verbose.1444336626" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.verbose" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.printfloat.2044235126" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.printfloat" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.printf.888161142" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.printf" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.iqmath.1390292521" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.iqmath" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.other.1683775650" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.linker.other" useByScannerDiscovery="false" value="" valueType="string"/>
<inputType id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.linker.input.1859223768" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.cpp.linker.1947503520" name="GNU RISC-V Cross C++ Linker" outputPrefix="" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.cpp.linker">
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.scriptfile.1751226764" name="Script files (-T)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.scriptfile" useByScannerDiscovery="false" valueType="stringList">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/Ld/Link.ld}&quot;"/>
</option>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.nostart.642896175" name="Do not use standard start files (-nostartfiles)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.nostart" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.nodeflibs.282300763" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.nodeflibs" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.nostdlibs.924960428" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.nostdlibs" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.gcsections.1689063433" name="Remove unused sections (-Xlinker --gc-sections)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.gcsections" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.printgcsections.621524254" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.printgcsections" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.strip.679063538" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.strip" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.libs.579700779" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.libs" useByScannerDiscovery="false" valueType="libs">
<listOptionValue builtIn="false" value="IQmath_RV32"/>
</option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.paths.1029177148" name="Library search path (-L)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.paths" useByScannerDiscovery="false" valueType="libPaths">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/User}&quot;"/>
</option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.flags.1251620602" name="Linker flags (-Xlinker [option])" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.flags" useByScannerDiscovery="false" valueType="stringList"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.otherobjs.1493906625" name="Other objects" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.otherobjs" useByScannerDiscovery="false" valueType="userObjs">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/User/libM12023_SV_1.0_COMCoreV1.5_Library.a}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/User/IQmath_RV32.a}&quot;"/>
</option>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.mapfilename.1354773182" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.mapfilename" useByScannerDiscovery="false" value="&quot;${BuildArtifactFileBaseName}.map&quot;" valueType="string"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.picolibc.4345436542" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.picolibc" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.picolibc.disabled" valueType="enumerated"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.cref.1007621036" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.cref" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.printmap.2073713641" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.printmap" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.usenewlibnano.1540675679" name="Use newlib-nano (--specs=nano.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.usenewlibnano" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.usenewlibnosys.561457319" name="Do not use syscalls (--specs=nosys.specs)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.usenewlibnosys" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.useprintffloat.1497004994" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.useprintffloat" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.usescanffloat.881728961" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.usescanffloat" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.verbose.922041698" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.verbose" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.printfloat.476377985" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.printfloat" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.printf.626387227" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.printf" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.iqmath.1441123220" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.iqmath" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.other.1748689212" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.cpp.linker.other" useByScannerDiscovery="false" value="" valueType="string"/>
</tool>
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.archiver.1292785366" name="GNU RISC-V Cross Archiver" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.archiver">
<outputType id="cdt.managedbuild.tool.gnu.archiver.output.1527226663" superClass="cdt.managedbuild.tool.gnu.archiver.output" outputPrefix="lib"/>
<option id="gnu.both.lib.option.flags.22122911" superClass="gnu.both.lib.option.flags" useByScannerDiscovery="false" value="-r" valueType="string"/>
</tool>
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.createflash.1801165667" name="GNU RISC-V Cross Create Flash Image" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.createflash">
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createflash.textsection.1097396305" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createflash.textsection" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createflash.datasection.2034511797" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createflash.datasection" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createflash.choice.1726268709" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createflash.choice" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createflash.choice.ihex" valueType="enumerated"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createflash.createalgorithmfile.2643315497" superClass="ilg.gnuarmeclipse.managedbuild.cross.risv.option.createflash.createalgorithmfile" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createflash.othersection.1890795928" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createflash.othersection" useByScannerDiscovery="false" valueType="stringList"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createflash.other.788974495" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createflash.other" useByScannerDiscovery="false" value="" valueType="string"/>
</tool>
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.createlisting.1356766765" name="GNU RISC-V Cross Create Listing" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.createlisting">
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.source.2052761852" name="Display source (--source|-S)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.source" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.allheaders.439659821" name="Display all headers (--all-headers|-x)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.allheaders" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.demangle.67111865" name="Demangle names (--demangle|-C)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.demangle" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.debugging.1623481730" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.debugging" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.disassemble.1859590835" name="Disassemble (--disassemble|-d)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.disassemble" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.fileheaders.160868348" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.fileheaders" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.linenumbers.1549373929" name="Display line numbers (--line-numbers|-l)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.linenumbers" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.reloc.1008747895" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.reloc" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.symbols.577922241" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.symbols" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.wide.1298918921" name="Wide lines (--wide|-w)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.wide" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.other.1560864108" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.createlisting.other" useByScannerDiscovery="false" value="" valueType="string"/>
</tool>
<tool id="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.printsize.712424314" name="GNU RISC-V Cross Print Size" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.tool.printsize">
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.printsize.format.1404031980" name="Size format" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.printsize.format" useByScannerDiscovery="false" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.printsize.format.berkeley" valueType="enumerated"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.printsize.hex.176087647" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.printsize.hex" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.printsize.totals.380903440" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.printsize.totals" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.printsize.other.1271150877" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.printsize.other" useByScannerDiscovery="false" value="" valueType="string"/>
</tool>
</toolChain>
</folderInfo>
<sourceEntries>
<entry excluding="User/Motor_UsbData.h|User/Motor_UsbData.c|Startup/startup_ch32v20x_D8W.S|Startup/startup_ch32v20x_D8.S" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
</sourceEntries>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
<storageModule moduleId="ilg.gnumcueclipse.managedbuild.packs"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="999.ilg.gnumcueclipse.managedbuild.cross.riscv.target.elf.275846018" name="Executable file" projectType="ilg.gnumcueclipse.managedbuild.cross.riscv.target.elf"/>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.debug.767917625;ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.debug.767917625.;ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.1375371130;ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.input.1473381709">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074;ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074.;ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.1731377187;ilg.gnumcueclipse.managedbuild.cross.riscv.tool.c.compiler.input.2036806839">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
</cproject>
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<projectDescription>
<name>Electric_Hair_Dryer</name>
<comment/>
<projects/>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments/>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments/>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
<linkedResources>
<link>
<name>Core</name>
<type>2</type>
<location>PARENT-2-PROJECT_LOC/SRC/Core</location>
</link>
<link>
<name>Debug</name>
<type>2</type>
<location>PARENT-2-PROJECT_LOC/SRC/Debug</location>
</link>
<link>
<name>Ld</name>
<type>2</type>
<location>PARENT-2-PROJECT_LOC/SRC/Ld</location>
</link>
<link>
<name>Peripheral</name>
<type>2</type>
<location>PARENT-2-PROJECT_LOC/SRC/Peripheral</location>
</link>
<link>
<name>Startup</name>
<type>2</type>
<location>PARENT-2-PROJECT_LOC/SRC/Startup</location>
</link>
</linkedResources>
<filteredResources>
<filter>
<name/>
<type>6</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-*.wvproj</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
@@ -0,0 +1,32 @@
Vendor=WCH
Toolchain=RISC-V
Series=CH32V203
RTOS=NoneOS
CalibrateSupport=false
CalibrateCommand=
UIConfigSupport=false
UIConfigCommand=
ExternalFlashSupport=false
MCU=CH32V203RBT6
Link=WCH-Link
PeripheralVersion=1.0
Description=ROM(byte): 64K, SRAM(byte): 20K, CHIP PINS: 32, GPIO PORTS: 27.\nWCH CH32V2 series of mainstream MCUs covers the needs of a large variety of applications in the industrial,medical and consumer markets. High performance with first-class peripherals and low-power,low-voltage operation is paired with a high level of integration at accessible prices with a simple architecture and easy-to-use tools.
TempratureScope=
ArtifactType=executable
Mcu Type=CH32V20x
Address=0x08000000
Target Path=obj/Electric_Hair_Dryer.hex
Exe Path=
Exe Arguments=
CLKSpeed=1
DebugInterfaceMode=0
Erase All=true
Program=true
Verify=true
Reset=true
SDIPrintf=false
Disable Power Output=false
Clear CodeFlash=false
Disable Code-Protect=false
Flash Type=
Algorithm File=
@@ -0,0 +1,458 @@
{
"version": "1.0",
"hasAllParsed": true,
"isNormalMRSProject": true,
"basic": {
"chipInfo": {
"vendor": "WCH",
"toolchain": "RISC-V",
"series": "CH32V203",
"rtos": "NoneOS",
"mcu": "CH32V203RBT6",
"description": "ROM(byte): 64K, SRAM(byte): 20K, CHIP PINS: 32, GPIO PORTS: 27.\\nWCH CH32V2 series of mainstream MCUs covers the needs of a large variety of applications in the industrial,medical and consumer markets. High performance with first-class peripherals and low-power,low-voltage operation is paired with a high level of integration at accessible prices with a simple architecture and easy-to-use tools.",
"tempratureScope": "",
"artifactType": "executable",
"link": "WCH-Link",
"peripheral_version": "1.0",
"calibrateSupport": false,
"calibrateCommand": "",
"UIConfigSupport": false,
"UIConfigCommand": "",
"externalFlashSupport": false
},
"linkedFolders": [
{
"name": "Core",
"location": "../../SRC/Core"
},
{
"name": "Debug",
"location": "../../SRC/Debug"
},
{
"name": "Ld",
"location": "../../SRC/Ld"
},
{
"name": "Peripheral",
"location": "../../SRC/Peripheral"
},
{
"name": "Startup",
"location": "../../SRC/Startup"
}
],
"removedResources": [
{
"parentLogicPath": "",
"type": "file",
"name": "*.wvproj"
}
],
"projectName": "Electric_Hair_Dryer",
"architecture": "RISC-V",
"projectType": "c"
},
"buildConfig": {
"configurations": [
{
"buildArtifact": {
"artifact_name": "${ProjName}",
"artifact_extension": "elf",
"output_prefix": "",
"artifact_type": "Executable"
},
"parallelizationNumber": "optimal",
"stop_on_first_build_error": true,
"pre_script": "",
"pre_script_description": "",
"post_script": "",
"post_script_description": "",
"excludeResources": [
"${project}/User/Motor_UsbData.h",
"${project}/User/Motor_UsbData.c",
"${project}/Startup/startup_ch32v20x_D8W.S",
"${project}/Startup/startup_ch32v20x_D8.S"
],
"optimization": {
"level": "size",
"message_length": true,
"char_is_signed": true,
"function_sections": true,
"data_sections": true,
"no_common_unitialized": true,
"do_not_inline_functions": false,
"assume_freestanding_environment": false,
"disable_builtin": false,
"single_precision_constants": false,
"position_independent_code": false,
"link_time_optimizer": false,
"disable_loop_invariant_move": false,
"optimize_unused_sections_declared_as_high_code": false,
"code_generation_without_hardware_floating": false,
"use_pipelines": false,
"show_caret_indicating_the_column": false,
"calling_convention_variant": false,
"other_optimization_flags": ""
},
"warnings": {
"check_syntax_only": false,
"pedantic": false,
"pedantic_warnings_as_errors": false,
"inhibit_all_warnings": false,
"warn_on_various_unused_elements": true,
"warn_on_uninitialized_variables": true,
"enable_all_common_warnings": false,
"enable_extra_warnings": false,
"warn_on_undeclared_global_function": false,
"warn_on_implicit_conversions": false,
"warn_if_pointer_arthmetic": false,
"warn_if_padding_is_included": false,
"warn_if_shadowed_variable": false,
"warn_if_suspicious_logical_ops": false,
"warn_if_struct_is_returned": false,
"warn_if_floats_are_compared_as_equal": false,
"generate_errors_instead_of_warnings": false,
"other_warning_flags": ""
},
"debugging": {
"debug_level": "default",
"debug_format": "dwarf4",
"generate_prof_information": false,
"generate_gprof_information": false,
"other_debugging_flags": ""
},
"assembler": {
"preprocessor": {
"use_preprocessor": true,
"do_not_search_system_directories": false,
"preprocess_only": false,
"defined_symbols": [],
"undefined_symbols": []
},
"includes": {
"include_paths": [
"${project}/Startup"
],
"include_system_paths": [],
"include_files": []
},
"other_warning_flags": "",
"miscellaneous": {
"assembler_flags": [],
"generate_assembler_listing": false,
"save_temporary_files": false,
"verbose": false,
"other_assembler_flags": ""
}
},
"ccompiler": {
"preprocessor": {
"do_not_search_system_directories": false,
"preprocess_only": false,
"defined_symbols": [],
"undefined_symbols": []
},
"includes": {
"include_paths": [
"${project}/Debug",
"${project}/Core",
"${project}/User",
"${project}/Peripheral/inc"
],
"include_system_paths": [],
"include_files": []
},
"optimization": {
"language_standard": "gnu99",
"other_optimization_flags": ""
},
"warnings": {
"warn_if_a_global_function_has_no_prototype": false,
"warn_if_a_function_has_no_arg_type": false,
"warn_if_wrong_cast": false,
"other_warning_flags": ""
},
"miscellaneous": {
"generate_assembler_listing": false,
"save_temporary_files": false,
"verbose": false,
"other_compiler_flags": ""
}
},
"cppcompiler": {
"preprocessor": {
"do_not_search_system_directories": false,
"do_not_search_system_cpp_directories": false,
"preprocess_only": false,
"defined_symbols": [],
"undefined_symbols": []
},
"includes": {
"include_paths": [],
"include_system_paths": [],
"include_files": []
},
"optimization": {
"cpp_language_standard": "gnucpp11",
"abi_version": "0",
"do_not_use_exceptions": false,
"do_not_use_rtti": false,
"do_not_use__cxa_atexit": false,
"do_not_use_thread_safe_statics": false,
"other_optimization_flags": ""
},
"warnings": {
"warn_on_abi_violations": false,
"warn_on_class_privacy": false,
"warn_on_no_except_expressions": false,
"warn_on_virtual_destructors": false,
"warn_on_uncast_null": false,
"warn_on_sign_promotion": false,
"warn_about_effictive_cpp_violcations": false,
"other_warning_flags": ""
},
"miscellaneous": {
"generate_assembler_listing": false,
"save_temporary_files": false,
"verbose": false,
"other_compiler_flags": ""
}
},
"clinker": {
"general": {
"scriptFiles": [
"${project}/Ld/Link.ld"
],
"do_not_use_standard_start_files": true,
"do_not_use_default_libraries": false,
"no_startup_or_default_libs": false,
"remove_unused_sections": true,
"print_removed_sections": false,
"omit_all_symbol_information": false
},
"libraries": {
"libraries": [
"IQmath_RV32"
],
"library_search_path": [
"${project}/User"
]
},
"miscellaneous": {
"picolibc": "disabled",
"linker_flags": [],
"other_objects": [
"${project}/User/libM12023_SV_1.0_COMCoreV1.5_Library.a",
"${project}/User/IQmath_RV32.a"
],
"generate_map": "\"${BuildArtifactFileBaseName}.map\"",
"cross_reference": false,
"print_link_map": false,
"use_newlib_nano": true,
"use_float_with_nano_printf": false,
"use_float_with_nano_scanf": false,
"do_not_use_syscalls": true,
"verbose": false,
"use_wch_printffloat": false,
"use_wch_printf": false,
"use_iqmath": false,
"other_linker_flags": ""
}
},
"cpplinker": {
"general": {
"scriptFiles": [
"${project}/Ld/Link.ld"
],
"do_not_use_standard_start_files": true,
"do_not_use_default_libraries": false,
"no_startup_or_default_libs": false,
"remove_unused_sections": true,
"print_removed_sections": false,
"omit_all_symbol_information": false
},
"libraries": {
"libraries": [
"IQmath_RV32"
],
"library_search_path": [
"${project}/User"
]
},
"miscellaneous": {
"picolibc": "disabled",
"linker_flags": [],
"other_objects": [
"${project}/User/libM12023_SV_1.0_COMCoreV1.5_Library.a",
"${project}/User/IQmath_RV32.a"
],
"generate_map": "\"${BuildArtifactFileBaseName}.map\"",
"cross_reference": false,
"print_link_map": false,
"use_newlib_nano": true,
"use_float_with_nano_printf": false,
"use_float_with_nano_scanf": false,
"do_not_use_syscalls": true,
"verbose": false,
"use_wch_printffloat": false,
"use_wch_printf": false,
"use_iqmath": false,
"other_linker_flags": ""
}
},
"archiver": {
"archiver_flags": "-r",
"libOutputPrefix": "lib"
},
"createFlash": {
"enabled": true,
"outputFileFormat": "ihex",
"copy_only_section_text": false,
"copy_only_section_data": false,
"copy_only_sections": [],
"create_algorithm_file": false,
"other_flags": ""
},
"createList": {
"enabled": true,
"display_source": false,
"display_all_headers": true,
"demangle_names": true,
"display_debug_info": false,
"disassemble": true,
"display_file_headers": false,
"display_line_numbers": false,
"display_relocation_info": false,
"display_symbols": false,
"wide_lines": false,
"other_flags": ""
},
"printSize": {
"enabled": true,
"size_format": "berkeley",
"hex": false,
"show_totals": false,
"other_flags": ""
},
"configVariables": [],
"riscvTargetProcessor": {
"architecture": "rv32i",
"multiply_extension": true,
"atomic_extension": true,
"floating_point": "none",
"compressed_extension": true,
"extra_compressed_extension": true,
"bit_extension": false,
"multiplication_subset_of_the_M_extension": false,
"vector_cryptography_extensions": "",
"integer_ABI": "ilp32",
"floating_point_ABI": "none",
"tuning": "default",
"code_model": "default",
"small_data_limit": 8,
"align": "default",
"save_restore": true,
"other_target_flags": ""
},
"component_toolchain": "${WCH:Toolchain:GCC15}",
"name": "obj"
}
]
},
"flashConfig": {
"mcutype": "CH32V20x",
"address": "0x08000000",
"target_path": "obj/Electric_Hair_Dryer.hex",
"clkSpeed": "High",
"debug_interface_mode": "",
"erase": true,
"program": true,
"verify": true,
"reset": true,
"sdiPrintf": false,
"disablepowerout": false,
"clearcodeflash": false,
"disablecodeprotect": false,
"flashType": "",
"asmFile_path": "",
"exepath": "",
"exearguments": ""
},
"debugConfigurations": {
"openOCDCfg": {
"useLocalOpenOCD": true,
"executable": "${WCH:OpenOCD:default}",
"gdbport": 3333,
"telnetport": 4444,
"tclport": 6666,
"configOptions": [
"-f \"${WCH:OpenOCD:default}/bin/wch-riscv.cfg\""
],
"host": "127.0.0.1",
"port": 3333,
"skipDownloadBeforeDebug": false,
"enablePageEraser": false,
"enableNoZeroWaitingAreaFlash": false
},
"gdbCfg": {
"executable": "${WCH:Toolchain:GCC15}",
"options": [],
"commands": [
"set mem inaccessible-by-default off",
"set architecture riscv:rv32",
"set remotetimeout unlimited",
"set disassembler-options xw"
]
},
"startup": {
"initCommands": {
"initReset": true,
"initResetType": "init",
"additionalCommands": [],
"armSemihosting": false,
"armSemihosting_old": false
},
"loadedFiles": {
"loadSymbols": true,
"useProjBinaryForSymbols": true,
"useFileForSymbols": false,
"symbolFile": "",
"symbolFileOffset": "",
"loadImage": true,
"useProjBinaryForImage": true,
"useFileForImage": false,
"executableFile": "",
"executableFileOffset": ""
},
"runCommands": {
"runReset": true,
"runResetType": "halt",
"additionalCommands": [],
"setBreakAt": "handle_reset",
"continue": true,
"setBreak": true,
"setProgramCounter": false,
"setProgramCounterAddress": ""
},
"debugInRAM": false
},
"svdpath": "${WCH:SDK:default}/RISC-V/CH32V203/NoneOS/CH32V203xx.svd",
"output": {
"showDebugGDBTrace": true,
"saveDebugOutputToFile": false,
"showDebugOutputTimestamps": true
},
"reserve": {
"PROGRAM_NAME": "obj/Electric_Hair_Dryer.elf",
"PROJECT_ATTR": "Electric_Hair_Dryer",
"PROJECT_BUILD_CONFIG_AUTO_ATTR": true,
"PROJECT_BUILD_CONFIG_ID_ATTR": "",
"ATTR_BUILD_BEFORE_LAUNCH_ATTR": 2,
"GdbServerAllocateConsole": true,
"GdbServerAllocateTelnetConsole": false,
"StartGdbCLient": true,
"UPDATE_THREADLIST_ON_SUSPEND": false
}
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,79 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : M0_Control_Configure.h
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description : Function selection and configuration.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __M0_CONTROL_CONFIGURE_H
#define __M0_CONTROL_CONFIGURE_H
#define OBSERVER_ADAPTOR
//#define POSICOM
#define IF_VIBRATION_COM
//#define SIX_SECTOR_POSITION
#define TWELVE_SECTOR_POSITION
#define SPEED_RECOVERKEY
#if defined SPEED_RECOVERKEY
#define POWERON_START
//#define KEY_START
#endif
#define ZEROCROSSOVER_TR
//#define ZEROCROSSOVER_OC
//电压限幅表选择,共8种配置:100,098,096,094,092,090,088,086
//#define MAG100_TABLE_USED
//#define MAG098_TABLE_USED
//#define MAG096_TABLE_USED
//#define MAG094_TABLE_USED
#define MAG092_TABLE_USED
//#define MAG090_TABLE_USED
//#define MAG088_TABLE_USED
//#define MAG086_TABLE_USED
#if ( (!defined(MAG100_TABLE_USED))&&(!defined(MAG098_TABLE_USED))&&\
(!defined(MAG096_TABLE_USED))&&(!defined(MAG094_TABLE_USED))\
&&(!defined(MAG092_TABLE_USED))&&(!defined(MAG090_TABLE_USED))\
&&(!defined(MAG088_TABLE_USED))&&(!defined(MAG086_TABLE_USED)))
#error "Invalid configuration: No voltage limit selected"
#endif
#if ( (!defined(SIX_SECTOR_POSITION))&&(!defined(TWELVE_SECTOR_POSITION)))
#error "Invalid configuration: No HFVQI configure"
#endif
#if ( (defined(SIX_SECTOR_POSITION))&&(defined(TWELVE_SECTOR_POSITION)))
#error "Invalid configuration: Duplicate HFVQI configure"
#endif
#if defined SPEED_RECOVERKEY
#if ((defined(POWERON_START))&&(defined(KEY_START)))
#error "Invalid configuration: Duplicate Startmode configure"
#endif
#if ((!defined(POWERON_START))&&(!defined(KEY_START)))
#error "Invalid configuration: No Startmode configure"
#endif
#endif
#if ((!defined(ZEROCROSSOVER_TR))&&(!defined(ZEROCROSSOVER_OC)))
#error "Invalid configuration: No ZeroCrossmode configure"
#endif
/* Exported variables -------------------------------------------------------*/
/* Exported macro -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------ */
#endif
@@ -0,0 +1,36 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : M0_Control_Library.h
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description : Project header file processing.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __M0_CONTROL_LIBRAYR_H
#define __M0_CONTROL_LIBRAYR_H
#include "ch32v20x.h"
#include "ch32v20x_opa.h"
#include "debug.h"
#include "M0_type_and_Constant.h"
#include "M0_Control_Configure.h"
#include "M1_Motor_Parameter.h"
#include "M2_PID_Parameter.h"
#include "M3_LBG_Observer_Parameter.h"
#include "M4_SVPWM_ADC1R.h"
#include "M5_Operation_and_Display.h"
#include "M5_MotorStart.h"
#include "M6_SpeedLoop.h"
#include "M6_CurrentLoop.h"
#include "M7_Interrupt.h"
#include "M8_Protection.h"
#include "M9_Appication_Blocks.h"
#include "MA_HFVQI_Parameter.h"
#include <MB_Operation_Flash.h>
#include "Motor_SPI_USART_MonitorData.h"
#endif
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,61 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : M1_Motor_Parameter.h
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description : Definition of motor parameters file.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __M1_MOTOR_PARAMETER_H
#define __M1_MOTOR_PARAMETER_H
#define RATED_FREQ_M 1833
#define RATED_VOLT_M _IQ18(220)
#define RATED_CURR_M _IQ18(1)
#define POLEPARE_M 1
#define ROTOR_FLUX_M _IQ(0.00930)
#define STATOR_RES_M _IQ(25.24)
#define STATOR_LD_M _IQ(0.0019301)
#define STATOR_LQ_M _IQ(0.0054236)
#define INERTIA_M _IQ(0.00002)
#define FRICTION_M _IQ(0.0001)
#define STATOR_RES_TOTAL_M (STATOR_RES_M + _IQ(2.0))
#define IDQLPF_CF_HIGH_M 600
#define IDQLPF_CF_LOW_M 200
#define IDQLPF_PERIOD_M LBG_CAL_PERIOD_M
#define IDQLPF_WcT_HIGH_M _IQmpyI32(_IQmpy(IDQLPF_PERIOD_M,PI_2_Q24),IDQLPF_CF_HIGH_M)
#define IDQLPF_WcT_LOW_M _IQmpyI32(_IQmpy(IDQLPF_PERIOD_M,PI_2_Q24),IDQLPF_CF_LOW_M)
#define IDQLPF_CF_OBSERVER_M 1200
#define IDQLPF_PERIOD_OBSERVER_M LBG_CAL_PERIOD_M
#define IDQLPF_WcT_OBSERVER_M _IQmpyI32(_IQmpy(IDQLPF_PERIOD_OBSERVER_M,PI_2_Q24),IDQLPF_CF_OBSERVER_M)
#define IDQLPF_CF_INITIAL_M 200
#define IDQLPF_PERIOD_INITIAL_M LBG_CAL_PERIOD_M
#define IDQLPF_WcT_INITIAL_M _IQmpyI32(_IQmpy(IDQLPF_PERIOD_INITIAL_M,PI_2_Q24),IDQLPF_CF_INITIAL_M)
/* Exported variables -------------------------------------------------------*/
extern Motor_Sructure_Type MStruc_M;
extern Motor_Base_Type MBase_M;
extern Runningstatus_Type RunningStatus_M;
extern volatile uint16_t System_Status_Global;
/* Exported macro -----------------------------------------------------------*/
/* Exported functions -------------------------------------------------------*/
void Motor_Prameter_Define(Motor_Base_Type *Basestruc);
void Motor_Status_Initial_M(Motor_Sructure_Type *MStruc);
void Global_Status_Initial(void);
void Motor_FilerPara_Cal_M(Motor_Sructure_Type *MStruc);
void Motor_BaseCal_M(Motor_Base_Type *Basestruc);
#endif
@@ -0,0 +1,149 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : M1_Motor_Parameter_Init.h
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description : Motor parameters and state initialization.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include "M0_Control_Library.h"
Motor_Sructure_Type MStruc_M;
Motor_Base_Type MBase_M;
Runningstatus_Type RunningStatus_M;
volatile uint16_t System_Status_Global;
/******************************************************************************
* Function Name : Motor_Prameter_Define
* Description : Motor Prameter Define
* Input : Pointer to motor base value parameter structure
* Output : None
* Return : None
******************************************************************************/
void Motor_Prameter_Define(Motor_Base_Type *Basestruc)
{
Basestruc->Fn = RATED_FREQ_M;
Basestruc->Vn = RATED_VOLT_M;
Basestruc->In = RATED_CURR_M;
Basestruc->Flux = ROTOR_FLUX_M;
Basestruc->Pn = POLEPARE_M;
Basestruc->Rs = STATOR_RES_M;
Basestruc->Ld = STATOR_LD_M;
Basestruc->Lq = STATOR_LQ_M;
Basestruc->Rstotal = STATOR_RES_TOTAL_M;
Basestruc->Inertia = INERTIA_M;
Basestruc->Friction = FRICTION_M;
}
/******************************************************************************
* Function Name : Motor_Status_Initial_M
* Description : Motor Status Initialization
* Input : Pointer to the motor overall status structure
* Output : None
* Return : None
******************************************************************************/
void Motor_Status_Initial_M(Motor_Sructure_Type *MStruc)
{
MStruc->VRef2R.cd = _IQ(0.0);
MStruc->VRef2R.cq = _IQ(0.0);
MStruc->VRef2R.peak = _IQ(0.0);
MStruc->VRef2RC.cd = _IQ(0.0);
MStruc->VRef2RC.cq = _IQ(0.0);
MStruc->VRef2RC.peak = _IQ(0.0);
MStruc->VRef2S.Alpha = _IQ(0.0);
MStruc->VRef2S.Beta = _IQ(0.0);
MStruc->VRef2SC.Alpha = _IQ(0.0);
MStruc->VRef2SC.Beta = _IQ(0.0);
MStruc->CRef2R.cd = _IQ(0.0);
MStruc->CRef2R.cq = _IQ(0.0);
MStruc->CRef2R.peak = _IQ(0.0);
MStruc->C3S.PhaseA = _IQ(0.0);
MStruc->C3S.PhaseB = _IQ(0.0);
MStruc->C3S.PhaseC = _IQ(0.0);
MStruc->C2S.Alpha = _IQ(0.0);
MStruc->C2S.Beta = _IQ(0.0);
MStruc->C2R_H.cd = _IQ(0.0);
MStruc->C2R_H.cq = _IQ(0.0);
MStruc->C2R_L.cd = _IQ(0.0);
MStruc->C2R_L.cq = _IQ(0.0);
MStruc->C2R.cd = _IQ(0.0);
MStruc->C2R.cq = _IQ(0.0);
MStruc->C2R_Obs.cd = _IQ(0.0);
MStruc->C2R_Obs.cq = _IQ(0.0);
MStruc->C2S_Obs.Alpha = _IQ(0.0);
MStruc->C2S_Obs.Beta = _IQ(0.0);
MStruc->IdLPF1stH.Out_Pre = _IQ(0.0);
MStruc->IdLPF1stH.Out_New = _IQ(0.0);
MStruc->IdLPF1stL.Out_Pre = _IQ(0.0);
MStruc->IdLPF1stL.Out_New = _IQ(0.0);
MStruc->IqLPF1stH.Out_Pre = _IQ(0.0);
MStruc->IqLPF1stH.Out_New = _IQ(0.0);
MStruc->IqLPF1stL.Out_Pre = _IQ(0.0);
MStruc->IqLPF1stL.Out_New = _IQ(0.0);
MStruc->IdLPF1stObs.Out_Pre = _IQ(0.0);
MStruc->IdLPF1stObs.Out_New = _IQ(0.0);
MStruc->IqLPF1stObs.Out_Pre = _IQ(0.0);
MStruc->IqLPF1stObs.Out_New = _IQ(0.0);
MStruc->IdLPF1stInj.Out_Pre = _IQ(0.0);
MStruc->IdLPF1stInj.Out_New = _IQ(0.0);
MStruc->IqLPF1stInj.Out_Pre = _IQ(0.0);
MStruc->IqLPF1stInj.Out_New = _IQ(0.0);
}
/******************************************************************************
* Function Name : Global_Status_Initial
* Description : Initialization of system status and motor operation status
* Input : None
* Output : None
* Return : None
******************************************************************************/
void Global_Status_Initial(void)
{
System_Status_Global |= SPEED_CONTROL_M;
System_Status_Global |= FIRST_START_M;
RunningStatus_M = IDLE;
}
/******************************************************************************
* Function Name : Motor_FilerPara_Cal_M
* Description : Motor Phase Filter Parameter Initialization
* Input : Pointer to the motor overall status structure
* Output : None
* Return : None
******************************************************************************/
void Motor_FilerPara_Cal_M(Motor_Sructure_Type *MStruc)
{
MStruc->IdLPF1stH.Input_Coef = _IQdiv(IDQLPF_WcT_HIGH_M,(IDQLPF_WcT_HIGH_M + UNIT_Q24));
MStruc->IdLPF1stH.Output_Coef = _IQdiv(UNIT_Q24,(IDQLPF_WcT_HIGH_M + UNIT_Q24));
MStruc->IdLPF1stL.Input_Coef = _IQdiv(IDQLPF_WcT_LOW_M,(IDQLPF_WcT_LOW_M + UNIT_Q24));
MStruc->IdLPF1stL.Output_Coef = _IQdiv(UNIT_Q24,(IDQLPF_WcT_LOW_M + UNIT_Q24));
MStruc->IqLPF1stH.Input_Coef = _IQdiv(IDQLPF_WcT_HIGH_M,(IDQLPF_WcT_HIGH_M + UNIT_Q24));
MStruc->IqLPF1stH.Output_Coef = _IQdiv(UNIT_Q24,(IDQLPF_WcT_HIGH_M + UNIT_Q24));
MStruc->IqLPF1stL.Input_Coef = _IQdiv(IDQLPF_WcT_LOW_M,(IDQLPF_WcT_LOW_M + UNIT_Q24));
MStruc->IqLPF1stL.Output_Coef = _IQdiv(UNIT_Q24,(IDQLPF_WcT_LOW_M + UNIT_Q24));
MStruc->IdLPF1stObs.Input_Coef = _IQdiv(IDQLPF_WcT_OBSERVER_M,(IDQLPF_WcT_OBSERVER_M + UNIT_Q24));
MStruc->IdLPF1stObs.Output_Coef = _IQdiv(UNIT_Q24,(IDQLPF_WcT_OBSERVER_M + UNIT_Q24));
MStruc->IqLPF1stObs.Input_Coef = _IQdiv(IDQLPF_WcT_OBSERVER_M,(IDQLPF_WcT_OBSERVER_M + UNIT_Q24));
MStruc->IqLPF1stObs.Output_Coef = _IQdiv(UNIT_Q24,(IDQLPF_WcT_OBSERVER_M + UNIT_Q24));
MStruc->IdLPF1stInj.Input_Coef = _IQdiv(IDQLPF_WcT_INITIAL_M,(IDQLPF_WcT_INITIAL_M + UNIT_Q24));
MStruc->IdLPF1stInj.Output_Coef = _IQdiv(UNIT_Q24,(IDQLPF_WcT_INITIAL_M + UNIT_Q24));
MStruc->IqLPF1stInj.Input_Coef = _IQdiv(IDQLPF_WcT_INITIAL_M,(IDQLPF_WcT_INITIAL_M + UNIT_Q24));
MStruc->IqLPF1stInj.Output_Coef = _IQdiv(UNIT_Q24,(IDQLPF_WcT_INITIAL_M + UNIT_Q24));
}
@@ -0,0 +1,96 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : M2_PID_Parameter.h
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description : Definition of PID control parameters.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __M2_MOTOR_PID_H
#define __M2_MOTOR_PID_H
#define SPEED_REGULATOR_FREQ_M SPEED_LOOP_CAL_FREQ
#define SPEED_REGULATOR_PERIOD_M (_IQ(1.0)/SPEED_REGULATOR_FREQ_M)
#define SPEED_REGULATOR_KP_M _IQ(0.000006)
#define SPEED_REGULATOR_KI_M _IQ(0.000006)
#define SPEED_REGULATOR_KD_M _IQ(0.0)
#define SPEED_REGULATOR_KPADJ_M _IQ(1.0)
#define SPEED_REGULATOR_KIADJ_M _IQ(1.0)
#define SPEED_REGULATOR_KDADJ_M _IQ(1.0)
#define SPEED_REGULATOR_ULIM_M _IQ(0.8)
#define SPEED_REGULATOR_LLIM_M _IQ(-0.1)
#define SPEED_REGULATOR_DLIM_M _IQ(1.0)
#ifdef MAG100_TABLE_USED
#define MAX_MODULATIONSQUARE _IQ(1.0000)
#define MAX_MODULATION _IQ(1.0000)
#elif defined MAG098_TABLE_USED
#define MAX_MODULATIONSQUARE _IQ(0.9604)
#define MAX_MODULATION _IQ(0.9800)
#elif defined MAG096_TABLE_USED
#define MAX_MODULATIONSQUARE _IQ(0.9216)
#define MAX_MODULATION _IQ(0.9600)
#elif defined MAG094_TABLE_USED
#define MAX_MODULATIONSQUARE _IQ(0.8836)
#define MAX_MODULATION _IQ(0.9400)
#elif defined MAG092_TABLE_USED
#define MAX_MODULATIONSQUARE _IQ(0.8464)
#define MAX_MODULATION _IQ(0.9200)
#elif defined MAG090_TABLE_USED
#define MAX_MODULATIONSQUARE _IQ(0.8100)
#define MAX_MODULATION _IQ(0.9000)
#elif defined MAG088_TABLE_USED
#define MAX_MODULATIONSQUARE _IQ(0.7744)
#define MAX_MODULATION _IQ(0.8800)
#elif defined MAG086_TABLE_USED
#define MAX_MODULATIONSQUARE _IQ(0.7396)
#define MAX_MODULATION _IQ(0.8600)
#endif
#define CURR_REGULATOR_FREQ_M FREQ_SVPWM
#define CURR_REGULATOR_BW_M (uint16_t)(PI_2f * 200)
#define DAXIS_CURR_REGULATOR_KD_M _IQ(0.0)
#define DAXIS_CURR_REGULATOR_KPADJ_M _IQ(5.0)
#define DAXIS_CURR_REGULATOR_KIADJ_M _IQ(1.0)
#define DAXIS_CURR_REGULATOR_KDADJ_M _IQ(1.0)
#define DAXIS_CURR_REGULATOR_ULIM_M _IQ(0.25)
#define DAXIS_CURR_REGULATOR_LLIM_M _IQ(-0.25)
#define DAXIS_CURR_REGULATOR_DLIM_M _IQ(1.0)
#define QAXIS_CURR_REGULATOR_KD_M _IQ(0.0)
#define QAXIS_CURR_REGULATOR_KPADJ_M _IQ(5.0)
#define QAXIS_CURR_REGULATOR_KIADJ_M _IQ(1.0)
#define QAXIS_CURR_REGULATOR_KDADJ_M _IQ(1.0)
#define QAXIS_CURR_REGULATOR_ULIM_M MAX_MODULATION
#define QAXIS_CURR_REGULATOR_LLIM_M (-MAX_MODULATION)
#define QAXIS_CURR_REGULATOR_DLIM_M _IQ(1.0)
#define DAXIS_CURR_REF_INIT1_M _IQ(0.3)
#define DAXIS_CURR_REF_INIT2_M _IQ(0.15)
#define DAXIS_CURR_REF_STEP1_M _IQ(0.0002)
#define DAXIS_CURR_REF_STEP2_M _IQ(0.00002)
#define DAXIS_CURR_WEAK_SPEED_M _IQ(1.5)
/* Exported variables -------------------------------------------------------*/
extern Motor_PID_Type Mpid_M;
extern DCurrProcess_Type DCurrProcess_M;
extern _iq24 Magnitude_table[];
/* Exported macro -----------------------------------------------------------*/
/* Exported functions -------------------------------------------------------*/
void PID_Prameter_Define(Motor_PID_Type * Mpid);
void PID_Output_Init(Motor_PID_Type * Mpid);
void PID_ParaBase_Cal_M(Motor_Base_Type *Basestruc,Motor_PID_Type * Mpid);
void DCurrProcess_Parameter_Define(DCurrProcess_Type * DCurrProcess);
#endif
@@ -0,0 +1,137 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : M2_PID_Parameter_Initl.c
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description : PID control structure definition and state initialization.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include "M0_Control_Library.h"
Motor_PID_Type Mpid_M;
DCurrProcess_Type DCurrProcess_M;
#ifdef MAG100_TABLE_USED
_iq24 Magnitude_table[256] = MAG100_LIMIT_TABLE;
#elif defined MAG098_TABLE_USED
_iq24 Magnitude_table[256] = MAG098_LIMIT_TABLE;
#elif defined MAG096_TABLE_USED
_iq24 Magnitude_table[256] = MAG096_LIMIT_TABLE;
#elif defined MAG094_TABLE_USED
_iq24 Magnitude_table[256] = MAG094_LIMIT_TABLE;
#elif defined MAG092_TABLE_USED
_iq24 Magnitude_table[256] = MAG092_LIMIT_TABLE;
#elif defined MAG090_TABLE_USED
_iq24 Magnitude_table[256] = MAG090_LIMIT_TABLE;
#elif defined MAG088_TABLE_USED
_iq24 Magnitude_table[256] = MAG088_LIMIT_TABLE;
#elif defined MAG086_TABLE_USED
_iq24 Magnitude_table[256] = MAG086_LIMIT_TABLE;
#endif
/******************************************************************************
* Function Name : PID_Prameter_Define
* Description : Speed regulator and current regulator machine parameter definition
* Input : Pointer to motor PID controller structure
* Output : None
* Return : None
******************************************************************************/
void PID_Prameter_Define (Motor_PID_Type * Mpid)
{
Mpid->Speed.CalFreq = SPEED_LOOP_CAL_FREQ;
Mpid->Speed.CalT = SPEED_REGULATOR_PERIOD_M;
Mpid->Speed.Kpreal= SPEED_REGULATOR_KP_M;
Mpid->Speed.Kireal= SPEED_REGULATOR_KI_M;
Mpid->Speed.Kdreal= SPEED_REGULATOR_KD_M;
Mpid->Speed.Kpadj = SPEED_REGULATOR_KPADJ_M;
Mpid->Speed.Kiadj = SPEED_REGULATOR_KIADJ_M;
Mpid->Speed.Kdadj = SPEED_REGULATOR_KDADJ_M;
if(STARTUP_DIRECTION==1)
{
Mpid->Speed.Upper_Lim = SPEED_REGULATOR_ULIM_M;
Mpid->Speed.Lower_Lim = SPEED_REGULATOR_LLIM_M;
}
else
{
Mpid->Speed.Upper_Lim = -SPEED_REGULATOR_LLIM_M;
Mpid->Speed.Lower_Lim = -SPEED_REGULATOR_ULIM_M;
}
Mpid->Speed.Deltalim = SPEED_REGULATOR_DLIM_M;
Mpid->dCurr.CalFreq= CURR_REGULATOR_FREQ_M;
Mpid->dCurr.CalT= _IQ(1.0)/CURR_REGULATOR_FREQ_M;
Mpid->dCurr.Bw= CURR_REGULATOR_BW_M;
Mpid->dCurr.Kdreal= DAXIS_CURR_REGULATOR_KD_M;
Mpid->dCurr.Kpadj = DAXIS_CURR_REGULATOR_KPADJ_M;
Mpid->dCurr.Kiadj = DAXIS_CURR_REGULATOR_KIADJ_M;
Mpid->dCurr.Kdadj = DAXIS_CURR_REGULATOR_KDADJ_M;
Mpid->dCurr.Upper_Lim = DAXIS_CURR_REGULATOR_ULIM_M;
Mpid->dCurr.Lower_Lim = DAXIS_CURR_REGULATOR_LLIM_M;
Mpid->dCurr.Deltalim = QAXIS_CURR_REGULATOR_DLIM_M;
Mpid->qCurr.CalFreq= CURR_REGULATOR_FREQ_M;
Mpid->qCurr.CalT= _IQ(1.0)/CURR_REGULATOR_FREQ_M;
Mpid->qCurr.Bw= CURR_REGULATOR_BW_M;
Mpid->qCurr.Kdreal= QAXIS_CURR_REGULATOR_KD_M;
Mpid->qCurr.Kpadj = QAXIS_CURR_REGULATOR_KPADJ_M;
Mpid->qCurr.Kiadj = QAXIS_CURR_REGULATOR_KIADJ_M;
Mpid->qCurr.Kdadj = QAXIS_CURR_REGULATOR_KDADJ_M;
Mpid->qCurr.Upper_Lim = QAXIS_CURR_REGULATOR_ULIM_M;
Mpid->qCurr.Lower_Lim = QAXIS_CURR_REGULATOR_LLIM_M;
Mpid->qCurr.Deltalim = QAXIS_CURR_REGULATOR_DLIM_M;
}
/******************************************************************************
* Function Name : PID_Output_Init
* Description : Speed regulator, current regulator output state initialization.
* Input : Pointer to motor PID controller structure
* Output : None
* Return : None
******************************************************************************/
void PID_Output_Init(Motor_PID_Type * Mpid)
{
Mpid->Speed.Err_New= 0;
Mpid->Speed.Err_Prev1= 0;
Mpid->Speed.Err_Prev2= 0;
Mpid->Speed.Output_New = 0;
Mpid->Speed.Output_Prev = 0;
Mpid->Speed.Deltaoutput = 0;
Mpid->Speed.Propotion = 0;
Mpid->Speed.Integer = 0;
Mpid->Speed.Differential = 0;
Mpid->dCurr.Err_New= 0;
Mpid->dCurr.Err_Prev1= 0;
Mpid->dCurr.Err_Prev2= 0;
Mpid->dCurr.Output_New= 0;
Mpid->dCurr.Output_Prev= 0;
Mpid->dCurr.Deltaoutput =0;
Mpid->qCurr.Err_New= 0;
Mpid->qCurr.Err_Prev1= 0;
Mpid->qCurr.Err_Prev2= 0;
Mpid->qCurr.Output_New = 0;
Mpid->qCurr.Output_Prev = 0;
Mpid->qCurr.Deltaoutput = 0;
}
/******************************************************************************
* Function Name : DCurrProcess_Parameter_Define
* Description : Definition of parameters related to d-axis current processing
* Input : d-axis current processing structure
* Output : None
* Return : None
******************************************************************************/
void DCurrProcess_Parameter_Define(DCurrProcess_Type * DCurrProcess)
{
DCurrProcess->Target1 = DAXIS_CURR_REF_INIT1_M;
DCurrProcess->Target2 = DAXIS_CURR_REF_INIT2_M;
DCurrProcess->AdjustStep1 = DAXIS_CURR_REF_STEP1_M;
DCurrProcess->AdjustStep2 = DAXIS_CURR_REF_STEP2_M;
DCurrProcess->Weakpoint = DAXIS_CURR_WEAK_SPEED_M;
}
@@ -0,0 +1,164 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : M3_LBG_Observer_Initial.c
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include "M0_Control_Library.h"
Motor_LBG_Type MLBG_M;
Observer_Status_Type LBG_Status_M;
_iq24 LBG_SpeedBuffer_M[LBG_SPEED_BUFFERSIZE_M];
/******************************************************************************
* Function Name : LBG_Parameter_Define
* Description : LBG Observer Parameter Definition
* Input : LBG observer structure pointer, LBG observer state structure pointer
* Output : None
* Return : None
******************************************************************************/
void LBG_Parameter_Define (Motor_LBG_Type *MLBG,Observer_Status_Type *LBGStatus)
{
MLBG->Para.CalFreq = LBG_CAL_FREQ_M;
MLBG->Para.CalT = LBG_CAL_PERIOD_M;
MLBG->Para.K1CerrC = LBG_K1_CERROR_CURR_M;
MLBG->Para.K2CerrE = LBG_K2_CERROR_EMF_M;
MLBG->Para.kCE_Adj = LBG_K2_CERROR_EMF_ADJ_M;
MLBG->Para.Caltimes = LBG_CAL_TIMES_M;
MLBG->Cal_Struc.EUlim = LBG_MAX_EMF_M;
MLBG->Cal_Struc.ELlim = LBG_MIN_EMF_M;
MLBG->Cal_Struc.CUlim = LBG_MAX_CURR_M;
MLBG->Cal_Struc.CLlim = LBG_MIN_CURR_M;
MLBG->Cal_Struc.SpeedLPF1st_M.Input_Coef = _IQdiv(LBG_SPEEDLPF_WcT_M,(LBG_SPEEDLPF_WcT_M + UNIT_Q24));
MLBG->Cal_Struc.SpeedLPF1st_M.Output_Coef = _IQdiv(UNIT_Q24,(LBG_SPEEDLPF_WcT_M + UNIT_Q24));
MLBG->Cal_Struc.Posicom_Enable = LBG_POSICOM_ENABLE;
MLBG->Speed_PLL.Kpreal = PLL_KP_M;
MLBG->Speed_PLL.Kireal = PLL_KI_M;
MLBG->Speed_PLL.Upper_Lim = LBG_SPEED_MAX_M;
MLBG->Speed_PLL.Lower_Lim = LBG_SPEED_MIN_M;
MLBG->Adaptor.Enable = LBG_ADAPTOR_ENABLE;
MLBG->Adaptor.Gain = LBG_ADAPTOR_COEF_M;
MLBG->Adaptor.EMF_Adj = LBG_ADAPTOR_EMF_ADJ_M;
MLBG->SpeedBuffPara.Length = LBG_SPEED_BUFFERSIZE_M;
LBGStatus->OverspeedThresh = LBG_OVERSPEED_THRESH_M;
LBGStatus->OverspeedcntThresh = LBG_OVERSPEED_CNT_THRESH_M;
LBGStatus->UnderspeedThresh = LBG_UNDERSPEED_THRESH_M;
LBGStatus->UnderspeedcntThresh = LBG_UNDERSPEED_CNT_THRESH_M;
LBGStatus->VarianceThresh = LBG_SPEED_VARIANCE_THRESH_M;
LBGStatus->UnstableCntThresh = LBG_UNSTABLE_CNT_THRESH_M;
LBGStatus->UnstableSpeedThresh = LBG_UNSTABLE_SPEED_THRESH_M;
LBGStatus->ConvergeCntThresh = LBG_CONVERGED_CNT_THRESH_M;
LBGStatus->ConvergeUpper = LBG_CONVERGED_UPPER_THRESH_M;
LBGStatus->ConvergeLower = LBG_CONVERGED_LOWER_THRESH_M;
LBGStatus->ConvergeEmfBandup = LBG_CONVERGED_EMFUP_THRESH_M;
LBGStatus->ConvergeEmfBanddown = LBG_CONVERGED_EMFDOWN_THRESH_M;
LBGStatus->StallSpeedBand = LBG_STALLBAND_M;
LBGStatus->StallSpeed = LBG_STALLSPEED_M;
LBGStatus->StallCurr = LBG_STALLCURR_M;
LBGStatus->StallCntThresh = LBG_STALL_CNT_THRESH_M;
LBGStatus->ReverseCntThresh = LBG_REVERSE_CNT_THRESH_M;
LBGStatus->ReverseSpeedThresh = LBG_REVERSE_SPEED_THRESH_M;
MLBG->Cal_Struc.EMFLPF1st_M.Input_Coef = _IQdiv(LBG_EMFLPF_WcT_M,(LBG_EMFLPF_WcT_M + UNIT_Q24));
MLBG->Cal_Struc.EMFLPF1st_M.Output_Coef = _IQdiv(UNIT_Q24,(LBG_EMFLPF_WcT_M + UNIT_Q24));
}
/******************************************************************************
* Function Name : LBG_Status_Init
* Description : LBG Observer State Initialization
* Input : LBG observer structure pointer, LBG observer state structure pointer
* Output : None
* Return : None
******************************************************************************/
void LBG_Status_Init (Motor_LBG_Type *MLBG,Observer_Status_Type *LBGStatus)
{
MLBG->Cal_Struc.Inimark = FALSE;
MLBG->Cal_Struc.EalphaNew = _IQ(0.0);
MLBG->Cal_Struc.EalphaPrev = _IQ(0.0);
MLBG->Cal_Struc.EbetaNew = _IQ(0.0);
MLBG->Cal_Struc.EbetaPrev = _IQ(0.0);
MLBG->Cal_Struc.CalphaNew = _IQ(0.0);
MLBG->Cal_Struc.CalphaPrev = _IQ(0.0);
MLBG->Cal_Struc.CbetaNew = _IQ(0.0);
MLBG->Cal_Struc.CbetaPrev = _IQ(0.0);
MLBG->Cal_Struc.ThetaErr = _IQ(0.0);
MLBG->Cal_Struc.PosiElecPU = _IQ(0.0);
MLBG->Cal_Struc.PosiElecPU_Pre = _IQ(0.0);
MLBG->Cal_Struc.PosiElecPU_Cali = _IQ(0.0);
MLBG->Cal_Struc.PosiElecPU_Com = _IQ(0.0);
MLBG->Cal_Struc.Angspeed_Inst = _IQ(0.0);
MLBG->Cal_Struc.Angspeed_Aver1 = _IQ(0.0);
MLBG->Cal_Struc.Angspeed_Aver2 = _IQ(0.0);
MLBG->Cal_Struc.Triangle.Cos = _IQ(0.0);
MLBG->Cal_Struc.Triangle.Sin = _IQ(0.0);
MLBG->Cal_Struc.Obs_Calcnt =0;
LBGStatus->Overspeed = FALSE;
LBGStatus->Underspeed = FALSE;
LBGStatus->Reliable = FALSE;
LBGStatus->Convergence = FALSE;
LBGStatus->Timeout = FALSE;
LBGStatus->Stable = TRUE;
LBGStatus->Stall = FALSE;
LBGStatus->Reverse = FALSE;
LBGStatus->Overspeed_CNT =0;
LBGStatus->Underspeed_CNT = 0;
LBGStatus->Converged_CNT = 0;
LBGStatus->Unstable_CNT = 0;
LBGStatus->Stall_CNT = 0;
LBGStatus->Reverse_CNT = 0;
MLBG->Speed_PLL.Error_New = _IQ(0.0);
MLBG->Speed_PLL.Error_Prev = _IQ(0.0);
MLBG->Speed_PLL.Output_New = _IQ(0.0);
MLBG->Speed_PLL.Output_Prev = _IQ(0.0);
#if defined OBSERVER_ADAPTOR
MLBG->Adaptor.Alpha_Err = _IQ(0.0);
MLBG->Adaptor.Alpha_Pre = _IQ(0.0);
MLBG->Adaptor.Alpha_New = _IQ(0.0);
MLBG->Adaptor.Beta_Err = _IQ(0.0);
MLBG->Adaptor.Beta_Pre = _IQ(0.0);
MLBG->Adaptor.Beta_New = _IQ(0.0);
#endif
}
/******************************************************************************
* Function Name : LBG_Cal_Init
* Description : LBG Calculation Initialization
* Input : Pointer to motor start control structure,
* pointer to overall motor status structure, pointer to LBG observer structure
* Output : None
* Return : None
******************************************************************************/
void LBG_Cal_Init (InjStart_Type *InjStart,Motor_Sructure_Type *MStruc,Motor_LBG_Type *MLBG)
{
LBG_EMF_CalInitial(MStruc,InjStart,MLBG);
#if defined OBSERVER_ADAPTOR
LBG_Adaptor_CalInitial(MLBG);
#endif
LBG_Speed_CalInitial(MLBG,&(LBG_SpeedBuffer_M[0]),InjStart->RampInjSpeedRef);
}
@@ -0,0 +1,102 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : M3_LBG_Observer_Parameter.h
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __M3_LBG_OBSERVER_H
#define __M3_LBG_OBSERVER_H
#define LBG_CAL_FREQ_M FREQ_SVPWM
#define LBG_CAL_PERIOD_M _IQ(1.0)/LBG_CAL_FREQ_M
#define LBG_K1_CERROR_CURR_M (-30000)
#define LBG_K2_CERROR_EMF_M 40000
#define LBG_K2_CERROR_EMF_ADJ_M 20
#define LBG_CAL_TIMES_M 2
#define LBG_MAX_EMF_M _IQ(2.0)
#define LBG_MIN_EMF_M _IQ(-2.0)
#define LBG_MAX_CURR_M _IQ(2.0)
#define LBG_MIN_CURR_M _IQ(-2.0)
#define PLL_KP_M 140
#define PLL_KI_M 25148
#define LBG_SPEED_MAX_M _IQ(1.5)
#define LBG_SPEED_MIN_M _IQ(0.01)
#if defined OBSERVER_ADAPTOR
#define LBG_ADAPTOR_ENABLE 1;
#else
#define LBG_ADAPTOR_ENABLE 0;
#endif
#define LBG_ADAPTOR_COEF_M 8000
#define LBG_ADAPTOR_EMF_ADJ_M _IQ(0.5)
#define LBG_SPEED_BUFFERSIZE_M 96
#if defined POSICOM
#define LBG_POSICOM_ENABLE 1;
#else
#define LBG_POSICOM_ENABLE 0;
#endif
#define LBG_SPEEDLPF_CF_M 50
#define LBG_SPEEDLPF_PERIOD_M (_IQ(1.0)/SPEED_LOOP_CAL_FREQ)
#define LBG_SPEEDLPF_WcT_M _IQmpyI32(_IQmpy(LBG_SPEEDLPF_PERIOD_M,PI_2_Q24),LBG_SPEEDLPF_CF_M)
#define LBG_OVERSPEED_THRESH_M _IQ(1.5)
#define LBG_UNDERSPEED_THRESH_M _IQ(0.05)
#define LBG_OVERSPEED_CNT_THRESH_M 500
#define LBG_UNDERSPEED_CNT_THRESH_M 500
#define LBG_SPEED_VARIANCE_THRESH_M _IQ(0.2)
#define LBG_UNSTABLE_CNT_THRESH_M 300
#define LBG_UNSTABLE_SPEED_THRESH_M _IQ(0.02)
#define LBG_CONVERGED_CNT_THRESH_M 100
#define LBG_CONVERGED_UPPER_THRESH_M _IQ(1.2)
#define LBG_CONVERGED_LOWER_THRESH_M _IQ(0.8)
#define LBG_CONVERGED_EMFUP_THRESH_M _IQ(0.5)
#define LBG_CONVERGED_EMFDOWN_THRESH_M _IQ(-0.2)
#define LBG_EMFLPF_CF_M 50
#define LBG_EMFLPF_PERIOD_M (_IQ(1.0)/SPEED_LOOP_CAL_FREQ)
#define LBG_EMFLPF_WcT_M _IQmpyI32(_IQmpy(LBG_EMFLPF_PERIOD_M,PI_2_Q24),LBG_EMFLPF_CF_M)
#define LBG_STALLBAND_M _IQ(0.5)
#define LBG_STALLSPEED_M _IQ(0.1)
#define LBG_STALLCURR_M _IQMPY_MACRO(_IQ(0.9),SPEED_REGULATOR_ULIM_M)
#define LBG_STALL_CNT_THRESH_M 100
#define LBG_REVERSE_CNT_THRESH_M 100
#define LBG_REVERSE_SPEED_THRESH_M _IQ(0.02)
/* Exported variables -------------------------------------------------------*/
extern Motor_LBG_Type MLBG_M;
extern Observer_Status_Type LBG_Status_M;
extern _iq24 LBG_SpeedBuffer_M[LBG_SPEED_BUFFERSIZE_M];
void LBG_Parameter_Define (Motor_LBG_Type *MLBG,Observer_Status_Type *LBGStatus);
void LBG_Paramter_Cal (Motor_Base_Type *Basestruc,Motor_LBG_Type *MLBG);
void LBG_Status_Init (Motor_LBG_Type *MLBG,Observer_Status_Type *LBGStatus);
void LBG_EMF_CalInitial(Motor_Sructure_Type *MStruc,InjStart_Type * InjStart,Motor_LBG_Type *MLBG);
void LBG_Adaptor_CalInitial(Motor_LBG_Type *MLBG);
void LBG_Speed_CalInitial(Motor_LBG_Type *MLBG,_iq24 *Buffer,_iq24 SpeedInial);
void LBG_EMF_Cal(Motor_Sructure_Type *MStruc,Motor_LBG_Type *MLBG);
void LBG_Speed_Posi_Cal(Motor_LBG_Type *MLBG);
void LBG_Cal_Init (InjStart_Type *InjStart,Motor_Sructure_Type *MStruc,Motor_LBG_Type *MLBG);
#endif
@@ -0,0 +1,659 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : M4_SVPWM_ADC1R.c
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include "M0_Control_Library.h"
SVPWM_1R_Type SVPWM_Cal_M;
ADCStruc_Type ADC_M;
PWMCali_Type PWMCali_M;
/******************************************************************************
* Function Name : SVPWM_1R_Paramter_Init
* Description : SVPWM Parameter Initialization
* Input : SVPWM calculation structure, PWM correction structure pointer,
* motor base value parameter structure pointer
* Output : None
* Return : None
******************************************************************************/
void SVPWM_1R_Paramter_Init(SVPWM_1R_Type *SVPWM_Cal,PWMCali_Type *PWMCali,Motor_Base_Type *Mbase)
{
SVPWM_Cal->T = ((uint16_t)(TIMER_CLOCK_FREQ_SVPWM/(uint32_t)(FREQ_SVPWM)));
SVPWM_Cal->T_IQ16 = (_IQ16(SVPWM_Cal->T));
SVPWM_Cal->HALF_T = SVPWM_Cal->T/2;
SVPWM_Cal->Quard_T = SVPWM_Cal->T/4;
SVPWM_Cal->BusVolt = _IQ18div(DCBUS_RATED_VOLT,Mbase->Vbase);
SVPWM_Cal->coef1 = _IQ16mpy(_IQ16div(SVPWM_Cal->T_IQ16/2,SVPWM_Cal->BusVolt>>2),Three_Q16);
SVPWM_Cal->coef2 = _IQ16mpy(_IQ16div(SVPWM_Cal->T_IQ16/2,SVPWM_Cal->BusVolt>>2),SQRT3_Q16);
SVPWM_Cal->Maxmodulesqure = MAX_MODULATIONSQUARE;
SVPWM_Cal->Maxmodule = MAX_MODULATION;
PWMCali->Currconverttime = CURR_CONVERT_CLOCK_ADC;
PWMCali->ADCTimeMin = CURR_MAX_TRTN_CLOCK_ADC + DEADTIME_CLOCK_SVPWM + CURR_CONVERT_CLOCK_ADC ;
PWMCali->ADCTimeMinDouble = PWMCali->ADCTimeMin*2;
PWMCali->ADCTimeMinHalf = PWMCali->ADCTimeMin/2;
}
/******************************************************************************
* Function Name : SVPWM_Status_Initial_M
* Description : SVPWM State Initialization
* Input : SVPWM calculation structure, PWM correction structure pointer
* Output : None
* Return : None
******************************************************************************/
void SVPWM_1R_Status_Init_M(SVPWM_1R_Type *SVPWM_Cal,PWMCali_Type *PWMCali)
{
TIM1->CH1CVR = SVPWM_Cal->Quard_T;
TIM1->CH2CVR = SVPWM_Cal->Quard_T;
TIM1->CH3CVR = SVPWM_Cal->Quard_T;
TIM1->CH4CVR = SVPWM_Cal->Quard_T - PWMCali->Currconverttime;
TIM3->CH4CVR = SVPWM_Cal->HALF_T - PWMCali->Currconverttime;
SVPWM_Cal->cc1 = SVPWM_Cal->Quard_T;
SVPWM_Cal->cc2 = SVPWM_Cal->Quard_T;
SVPWM_Cal->cc3 = SVPWM_Cal->Quard_T;
SVPWM_Cal->cc1Load = SVPWM_Cal->Quard_T;
SVPWM_Cal->cc2Load = SVPWM_Cal->Quard_T;
SVPWM_Cal->cc3Load = SVPWM_Cal->Quard_T;
SVPWM_Cal->cc1Loadup = SVPWM_Cal->Quard_T;
SVPWM_Cal->cc2Loadup = SVPWM_Cal->Quard_T;
SVPWM_Cal->cc3Loadup = SVPWM_Cal->Quard_T;
SVPWM_Cal->sector = 1;
SVPWM_Cal->VoltLimMark = 0;
SVPWM_Cal->PWMUcali1 = SVPWM_Cal->Quard_T;
SVPWM_Cal->PWMUcali2 = SVPWM_Cal->Quard_T;
SVPWM_Cal->PWMVcali1 = SVPWM_Cal->Quard_T;
SVPWM_Cal->PWMVcali2 = SVPWM_Cal->Quard_T;
SVPWM_Cal->PWMWcali1 = SVPWM_Cal->Quard_T;
SVPWM_Cal->PWMWcali2 = SVPWM_Cal->Quard_T;
PWMCali->Cali_Buff.Cali1 = SVPWM_Cal->Quard_T;
PWMCali->Cali_Buff.Cali2 = SVPWM_Cal->Quard_T;
PWMCali->Cali_Buff.Cali3 = SVPWM_Cal->Quard_T;
PWMCali->Cali_Buff.Cali4 = SVPWM_Cal->Quard_T;
PWMCali->Cali_Buff.Cali5 = SVPWM_Cal->Quard_T;
PWMCali->Cali_Buff.Cali6 = SVPWM_Cal->Quard_T;
PWMCali->ADC_Trig.Trig1 = SVPWM_Cal->Quard_T - PWMCali->Currconverttime;
PWMCali->ADC_Trig.Trig2 = SVPWM_Cal->HALF_T - PWMCali->Currconverttime;
PWMCali->ADC_Trig.Trig1_limmark = FALSE;
PWMCali->ADC_Trig.Trig2_limmark = FALSE;
PWMCali->DMA_Trig.Trig1 = 1;
PWMCali->DMA_Trig.Trig2 = SVPWM_Cal->HALF_T +1;
PWMCali->DMA_Trig.Trig3 = 1;
PWMCali->DMA_Trig.Trig4 = SVPWM_Cal->HALF_T +1;
PWMCali->DMA_Trig.Trig5 = 1;
PWMCali->DMA_Trig.Trig6 = SVPWM_Cal->HALF_T +1;
TIM2->CH3CVR = PWMCali->DMA_Trig.Trig1;
TIM3->CH3CVR = PWMCali->DMA_Trig.Trig2;
TIM4->CH2CVR = PWMCali->DMA_Trig.Trig3;
TIM2->CH1CVR = PWMCali->DMA_Trig.Trig4;
TIM3->CH1CVR = PWMCali->DMA_Trig.Trig5;
TIM2->CH2CVR = PWMCali->DMA_Trig.Trig6;
PWMCali->CaliMark = 0;
}
/******************************************************************************
* Function Name : ADC_Parameter_Init
* Description : ADC Parameter Calculation
* Input : ADC calculation structure pointer,
* motor base value parameter structure pointer
* Output : None
* Return : None
******************************************************************************/
void ADC_Parameter_Init (ADCStruc_Type *ADCStruc,Motor_Base_Type *Mbase)
{
ADCStruc->RatedCurr_ConvInv = _IQ16mpyIQX(_IQ16div(_IQ16(128),_IQ16(32767)),\
16,_IQ18div(CURR_SAMPLE_RANGE_ADC,Mbase->Ibase),18);
ADCStruc->AdcChannel1 = ADC1_CURR_CHANNEL_PHASE_M;
ADCStruc->AdcChannel2 = ADC2_CURR_CHANNEL_PHASE_M;
ADCStruc->DCVoltRatedADC = _IQ18div(_IQ18mpy(DCVOLT_CONV_RATIO,DCBUS_RATED_VOLT),_IQ18(3.3))*4096;
ADCStruc->DCVoltRatedADCInv =_IQ18div(_IQ18(1.0),ADCStruc->DCVoltRatedADC);
ADCStruc->DCVoltAverSizeInv1 = _IQ(1.0)/DCVOLT_AVER_SIZE;
ADCStruc->DCVoltAverSizeInv2 = _IQ(1.0) - ADCStruc->DCVoltAverSizeInv1;
ADCStruc->VdcLPF1st.Input_Coef = _IQdiv(DCVOLT_LPF_WcT_M,(DCVOLT_LPF_WcT_M + UNIT_Q24));
ADCStruc->VdcLPF1st.Output_Coef = _IQdiv(UNIT_Q24,(DCVOLT_LPF_WcT_M + UNIT_Q24));
ADCStruc->DCVoltPres=0;
ADCStruc->DCVoltAver=0;
ADCStruc->DCVoltcali=0;
ADCStruc->DCVolt_Filter=0;
ADCStruc->VdcLPF1st.Out_New=0;
ADCStruc->VdcLPF1st.Out_Pre=0;
}
/******************************************************************************
* Function Name : ADC_Status_Init
* Description : ADC Status Init
* Input : ADC calculation structure pointer
* Output : None
* Return : None
******************************************************************************/
void ADC_Status_Init (ADCStruc_Type *ADCStruc)
{
ADCStruc->ADC_Result.Value1 = ADC_M.OffsetValue1;
ADCStruc->ADC_Result.Value2 = ADC_M.OffsetValue2;
// ADCStruc->DCVoltPres = DCVOLT_INIT;
// ADCStruc->DCVoltAver = DCVOLT_INIT;
// ADCStruc->DCVolt_Filter = DCVOLT_INIT;
// ADCStruc->DCVoltcali = _IQ(1.0);
//
// ADCStruc->VdcLPF1st.Out_New =0;
// ADCStruc->VdcLPF1st.Out_Pre =0;
}
/******************************************************************************
* Function Name : SVPWM_1R_Timer_Configure
* Description : SVPWM Port and Timer Initialization
* Input : None
* Output : None
* Return : None
******************************************************************************/
void SVPWM_1R_Timer_Configure()
{
TIM_TimeBaseInitTypeDef TIM1_TimeBaseStructure={0};
TIM_TimeBaseInitTypeDef TIM3_TimeBaseInitStructure= {0};
TIM_OCInitTypeDef TIM1_OCInitStructure={0};
TIM_OCInitTypeDef TIM3_OCInitStructure= {0};
TIM_BDTRInitTypeDef TIM_BDTRInitStructure={0};
GPIO_InitTypeDef GPIO_InitStructure={0};
DMA_InitTypeDef DMA1_InitStructure = {0};
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB\
| RCC_APB2Periph_AFIO | RCC_APB2Periph_TIM1, ENABLE);
RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM2 |RCC_APB1Periph_TIM3\
| RCC_APB1Periph_TIM4, ENABLE );
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_SetBits(GPIOB,GPIO_Pin_12);
TIM_DeInit(TIM1);
TIM_TimeBaseStructInit(&TIM1_TimeBaseStructure);
TIM1_TimeBaseStructure.TIM_Prescaler = TIMER_PRESCALER_SVPWM;
TIM1_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_CenterAligned1;
TIM1_TimeBaseStructure.TIM_Period = SVPWM_Cal_M.HALF_T-1;
TIM1_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM1_TimeBaseStructure.TIM_RepetitionCounter = TIMER_UPDATE_RATE_SVPWM;
TIM_TimeBaseInit(TIM1, &TIM1_TimeBaseStructure);
TIM_OCStructInit(&TIM1_OCInitStructure);
TIM1_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM1_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM1_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
//dummy value
TIM1_OCInitStructure.TIM_Pulse = SVPWM_Cal_M.HALF_T/2;
TIM1_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM1_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
//TIM1_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low; //SA2603
TIM1_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;
TIM1_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset;
TIM_OC1Init(TIM1, &TIM1_OCInitStructure);
TIM_OC2Init(TIM1, &TIM1_OCInitStructure);
TIM_OC3Init(TIM1, &TIM1_OCInitStructure);
TIM_OCStructInit(&TIM1_OCInitStructure);
TIM1_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
TIM1_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM1_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
TIM1_OCInitStructure.TIM_Pulse = SVPWM_Cal_M.HALF_T - 1;
TIM1_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM1_OCInitStructure.TIM_OCNPolarity =TIM_OCNPolarity_Low;
TIM1_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;
TIM1_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
TIM_OC4Init(TIM1, &TIM1_OCInitStructure);
TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Disable);
TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Disable);
TIM_OC3PreloadConfig(TIM1, TIM_OCPreload_Disable);
TIM_OC4PreloadConfig(TIM1, TIM_OCPreload_Enable);
TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;
TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_1;
TIM_BDTRInitStructure.TIM_DeadTime = DEADTIME_CONFIGURE;
TIM_BDTRInitStructure.TIM_Break = TIM_Break_Enable;
TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_Low;
TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Disable;
TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure);
TIM_SetCounter(TIM1,0);
TIM_ClearFlag(TIM1, TIM_FLAG_Update);
TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE);
DMA_DeInit(DMA1_Channel1);
DMA_DeInit(DMA1_Channel2);
DMA_DeInit(DMA1_Channel4);
DMA_DeInit(DMA1_Channel5);
DMA_DeInit(DMA1_Channel6);
DMA_DeInit(DMA1_Channel7);
DMA1_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA1_InitStructure.DMA_BufferSize = 1;
DMA1_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA1_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
DMA1_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
DMA1_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA1_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA1_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
DMA1_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA1_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(TIM1->CH1CVR);
DMA1_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&(PWMCali_M.Cali_Buff.Cali1);
DMA_Init(DMA1_Channel1, &DMA1_InitStructure);
DMA1_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(TIM1->CH1CVR);
DMA1_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&(PWMCali_M.Cali_Buff.Cali2);
DMA_Init(DMA1_Channel2, &DMA1_InitStructure);
DMA1_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(TIM1->CH2CVR);
DMA1_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&(PWMCali_M.Cali_Buff.Cali3);
DMA_Init(DMA1_Channel4, &DMA1_InitStructure);
DMA1_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(TIM1->CH2CVR);
DMA1_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&(PWMCali_M.Cali_Buff.Cali4);
DMA_Init(DMA1_Channel5, &DMA1_InitStructure);
DMA1_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(TIM1->CH3CVR);
DMA1_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&(PWMCali_M.Cali_Buff.Cali5);
DMA_Init(DMA1_Channel6, &DMA1_InitStructure);
DMA1_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(TIM1->CH3CVR);
DMA1_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&(PWMCali_M.Cali_Buff.Cali6);
DMA_Init(DMA1_Channel7, &DMA1_InitStructure);
DMA_Cmd(DMA1_Channel1, ENABLE);
DMA_Cmd(DMA1_Channel2, ENABLE);
DMA_Cmd(DMA1_Channel4, ENABLE);
DMA_Cmd(DMA1_Channel5, ENABLE);
DMA_Cmd(DMA1_Channel6, ENABLE);
DMA_Cmd(DMA1_Channel7, ENABLE);
TIM_DeInit(TIM3);
TIM_DeInit(TIM2);
TIM_DeInit(TIM4);
TIM_TimeBaseStructInit(&TIM3_TimeBaseInitStructure);
TIM3_TimeBaseInitStructure.TIM_Prescaler = TIMER_PRESCALER_SVPWM;
TIM3_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM3_TimeBaseInitStructure.TIM_Period = SVPWM_Cal_M.T-1;
TIM_TimeBaseInit(TIM3, &TIM3_TimeBaseInitStructure);
TIM_TimeBaseInit(TIM2, &TIM3_TimeBaseInitStructure);
TIM_TimeBaseInit(TIM4, &TIM3_TimeBaseInitStructure);
TIM_OCStructInit(&TIM3_OCInitStructure);
TIM3_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
TIM3_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM3_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC3Init(TIM2, &TIM3_OCInitStructure);
TIM_OC3Init(TIM3, &TIM3_OCInitStructure);
TIM_OC2Init(TIM4, &TIM3_OCInitStructure);
TIM_OC1Init(TIM2, &TIM3_OCInitStructure);
TIM_OC1Init(TIM3, &TIM3_OCInitStructure);
TIM_OC2Init(TIM2, &TIM3_OCInitStructure);
TIM_OC4Init(TIM3, &TIM3_OCInitStructure);
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);
TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable);
TIM_OC4PreloadConfig(TIM3, TIM_OCPreload_Enable);
TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Enable);
TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Enable);
TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Enable);
TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Enable);
TIM_SelectOutputTrigger(TIM1, TIM_TRGOSource_Update);
TIM_SelectInputTrigger(TIM3, TIM_TS_ITR0);
TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset);
TIM_SelectOutputTrigger(TIM1, TIM_TRGOSource_Update);
TIM_SelectInputTrigger(TIM2, TIM_TS_ITR0);
TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Reset);
TIM_SelectOutputTrigger(TIM1, TIM_TRGOSource_Update);
TIM_SelectInputTrigger(TIM4, TIM_TS_ITR0);
TIM_SelectSlaveMode(TIM4, TIM_SlaveMode_Reset);
TIM_SetCounter(TIM3,0);
TIM_SetCounter(TIM2,0);
TIM_SetCounter(TIM4,0);
}
/******************************************************************************
* Function Name : ADC_OPA_Configure
* Description : ADC/OPA Configuration
* Input : ADC calculation structure pointer, ADC register pointer
* Output : None
* Return : None
******************************************************************************/
void ADC_OPA_Configure(ADCStruc_Type *ADCStruc)
{
ADC_InitTypeDef ADC_InitStructure={0};
GPIO_InitTypeDef GPIO_InitStructure={0};
OPA_InitTypeDef OPA1_InitStructure = {0};
OPA_InitTypeDef OPA2_InitStructure = {0};
RCC_ADCCLKConfig(RCC_PCLK2_Div6);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB\
|RCC_APB2Periph_AFIO | RCC_APB2Periph_ADC1\
| RCC_APB2Periph_ADC2, ENABLE);
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 |GPIO_Pin_2 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_5;//CH4 CH5
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init( GPIOB, &GPIO_InitStructure );
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init( GPIOA, &GPIO_InitStructure );
OPA2_InitStructure.OPA_NUM = OPA2;
OPA2_InitStructure.PSEL = CHP1;
OPA2_InitStructure.NSEL = CHN0;
OPA2_InitStructure.Mode = OUT_IO_OUT1;
OPA_Init( &OPA2_InitStructure );
OPA_Cmd( OPA2, ENABLE );
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init( GPIOA, &GPIO_InitStructure );
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init( GPIOB, &GPIO_InitStructure );
OPA1_InitStructure.OPA_NUM = OPA1;
OPA1_InitStructure.PSEL = CHP1;
OPA1_InitStructure.NSEL = CHN1;
OPA1_InitStructure.Mode = OUT_IO_OUT1;
OPA_Init( &OPA1_InitStructure );
OPA_Cmd( OPA1, ENABLE );
ADC_DeInit(ADC1);
ADC_DeInit(ADC2);
ADC_StructInit(&ADC_InitStructure);
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Left;
ADC_InitStructure.ADC_NbrOfChannel = 1;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_Init(ADC2, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC2,ADC_Channel_1, 1, SAMPLING_TIMER_CLOCK );
ADC_RegularChannelConfig(ADC1,ADC_Channel_2, 1, SAMPLING_TIMER_CLOCK );
ADC_Cmd(ADC1, ENABLE);
ADC_Cmd(ADC2, ENABLE);
ADC_BufferCmd(ADC1, DISABLE); //disable buffer
ADC_ResetCalibration(ADC1);
while(ADC_GetResetCalibrationStatus(ADC1));
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1));
ADC_BufferCmd(ADC2, DISABLE); //disable buffer
ADC_ResetCalibration(ADC2);
while(ADC_GetResetCalibrationStatus(ADC2));
ADC_StartCalibration(ADC2);
while(ADC_GetCalibrationStatus(ADC2));
}
/******************************************************************************
* Function Name : ADC_1R_Offset_Reading
* Description : ADC current sampling zero reading
* Input : ADC register pointer, ADC calculation structure pointer, ADC number
* Output : None
* Return : None
******************************************************************************/
void ADC_1R_Offset_Reading(ADC_TypeDef *ADCx, ADCStruc_Type *ADCStruc,u_int8_t ADC_num)
{
uint16_t i;
if(ADC_num ==1)
ADCStruc->OffsetValue1 = 0;
else if (ADC_num ==2)
ADCStruc->OffsetValue2 = 0;
ADC_ITConfig(ADCx, ADC_IT_JEOC, DISABLE);
ADC_ExternalTrigInjectedConvConfig(ADCx, ADC_ExternalTrigInjecConv_None);
ADC_ExternalTrigInjectedConvCmd(ADCx,ENABLE);
ADC_InjectedSequencerLengthConfig(ADCx,1);
if(ADC_num ==1)
ADC_InjectedChannelConfig(ADCx, ADCStruc->AdcChannel1,1,SAMPLING_TIMER_CLOCK);
else if (ADC_num ==2)
ADC_InjectedChannelConfig(ADCx, ADCStruc->AdcChannel2,1,SAMPLING_TIMER_CLOCK);
ADC_ClearFlag(ADCx, ADC_FLAG_JEOC);
ADC_SoftwareStartInjectedConvCmd(ADCx,ENABLE);
for(i=0; i <CURR_OFFSET_READ_NUM_ADC; i++)
{
while(!ADC_GetFlagStatus(ADCx,ADC_FLAG_JEOC));
if(ADC_num ==1)
ADCStruc->OffsetValue1 += (ADC_GetInjectedConversionValue(ADCx,ADC_InjectedChannel_1)>>3);
else if (ADC_num ==2)
ADCStruc->OffsetValue2 += (ADC_GetInjectedConversionValue(ADCx,ADC_InjectedChannel_1)>>3);
ADC_ClearFlag(ADCx, ADC_FLAG_JEOC);
ADC_SoftwareStartInjectedConvCmd(ADCx,ENABLE);
}
ADC_ExternalTrigInjectedConvCmd(ADCx,ENABLE);
}
/******************************************************************************
* Function Name : ADC_1R_Start
* Description : ADC Conversion Start
* Input : Enable command
* Output : None
* Return : None
******************************************************************************/
void ADC_1R_Start (FunctionalState cmd)
{
if (cmd == ENABLE)
{
ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_T1_CC4);
ADC_ExternalTrigInjectedConvConfig(ADC2, ADC_ExternalTrigInjecConv_T3_CC4);
ADC1->STATR = ~(uint32_t)ADC_FLAG_JEOC;
ADC2->STATR = ~(uint32_t)ADC_FLAG_JEOC;
ADC_ITConfig(ADC1, ADC_IT_JEOC, ENABLE);
ADC_ITConfig(ADC2, ADC_IT_JEOC, ENABLE);
TIM_DMACmd(TIM2, TIM_DMA_CC1, ENABLE);
TIM_DMACmd(TIM2, TIM_DMA_CC2, ENABLE);
TIM_DMACmd(TIM2, TIM_DMA_CC3, ENABLE);
TIM_DMACmd(TIM3, TIM_DMA_CC1, ENABLE);
TIM_DMACmd(TIM3, TIM_DMA_CC3, ENABLE);
TIM_DMACmd(TIM4, TIM_DMA_CC2, ENABLE);
}
else
{
ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_None);
ADC_ExternalTrigInjectedConvConfig(ADC2, ADC_ExternalTrigInjecConv_None);
TIM_DMACmd(TIM2, TIM_DMA_CC1, DISABLE);
TIM_DMACmd(TIM2, TIM_DMA_CC2, DISABLE);
TIM_DMACmd(TIM2, TIM_DMA_CC3, DISABLE);
TIM_DMACmd(TIM3, TIM_DMA_CC1, DISABLE);
TIM_DMACmd(TIM3, TIM_DMA_CC3, DISABLE);
TIM_DMACmd(TIM4, TIM_DMA_CC2, DISABLE);
ADC_ExternalTrigInjectedConvCmd(ADC1,DISABLE);
ADC_ExternalTrigInjectedConvCmd(ADC2,DISABLE);
TIM_CtrlPWMOutputs(TIM1, DISABLE);
}
}
/******************************************************************************
* Function Name : DCBUS_Volt_Cal
* Description : Bus Voltage Calculation
* Input : ADC calculation structure pointer, ADC register pointer
* Output : None
* Return : None
******************************************************************************/
void DCBUS_Volt_Cal(ADCStruc_Type *ADCStruc,ADC_TypeDef *ADCx)
{
if((ADCx->STATR & ADC_FLAG_EOC) == ADC_FLAG_EOC)
{
ADCStruc->DCVoltPres=_IQ18toIQ(_IQ18MPY_MACRO(_IQ18(ADCx->RDATAR>>4),ADCStruc->DCVoltRatedADCInv));
ADCStruc->DCVolt_Filter = LPF_1st_Process(&(ADCStruc->VdcLPF1st), ADCStruc->DCVoltPres);
ADCStruc->DCVoltAver = _IQMPY_MACRO(ADCStruc->DCVoltAver,ADCStruc->DCVoltAverSizeInv2)\
+ _IQMPY_MACRO(ADCStruc->DCVoltPres,ADCStruc->DCVoltAverSizeInv1);
}
}
/******************************************************************************
* Function Name : NTCSample
* Description : NTC Sampling Calculation
* Input : Temperature control structure pointer, ADC register pointer
* Output : None
* Return : None
******************************************************************************/
void NTCSample(Temperature_ctl_Type *TempM, ADC_TypeDef *ADCx)
{
if((ADCx->STATR & ADC_FLAG_EOC) == ADC_FLAG_EOC)
{
TempM->TempPres=(_iq24)((u16)ADCx->RDATAR*TempM->TempRatedADCInv);
//¾ùÖµ¼ÆËã
TempM->TempAver =_IQMPY_MACRO(TempM->TempAver,TempM->TempAverSizeInv2)\
+ _IQMPY_MACRO(TempM->TempPres,TempM->TempAverSizeInv1);
}
}
/******************************************************************************
* Function Name : ADC_Trigger_Update
* Description : Update at ADC trigger moment
* Input : PWM correction calculation structure pointer
* Output : None
* Return : None
******************************************************************************/
void ADC_Trigger_Update(PWMCali_Type *PWMCali)
{
TIM1->CH4CVR = PWMCali->ADC_Trig.Trig1;
TIM3->CH4CVR = PWMCali->ADC_Trig.Trig2;
}
/*******************************************************************************
* Function Name : SVPWM_Zerovolt_Output_Immidiate
* Description : 0 voltage output, takes effect immediately
* Input : SVPWM calculation structure pointer
* Output : None
* Return : None
*******************************************************************************/
void SVPWM_Zerovolt_Output_Immediate(SVPWM_1R_Type *SVPWM_Cal)
{
TIM1->CH1CVR = SVPWM_Cal->Quard_T;
TIM1->CH2CVR = SVPWM_Cal->Quard_T;
TIM1->CH3CVR = SVPWM_Cal->Quard_T;
}
/*******************************************************************************
* Function Name : SVPWM_Lowside_Effective
* Description : All lower tubes are fully conductive and take effect immediately
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void SVPWM_Lowside_Effective_Immediate(void)
{
TIM1->CH1CVR = 0;
TIM1->CH2CVR = 0;
TIM1->CH3CVR = 0;
}
@@ -0,0 +1,112 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : M4_SVPWM_ADC1R.h
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __MOTOR_SVPWM_ADC1R_H
#define __MOTOR_SVPWM_ADC1R_H
#define DCBUS_RATED_VOLT _IQ18(311)
#define SYSTEM_CLOCK_FREQ 144000000uL
#define TIMER_PRESCALER_SVPWM 0
#define TIMER_CLOCK_FREQ_SVPWM (SYSTEM_CLOCK_FREQ/(TIMER_PRESCALER_SVPWM+1))
#define TIMER_UPDATE_RATE_SVPWM 1
#define FREQ_SVPWM 30000
#define DEADTIME_SVPWM 1000
#define DEADTIME_CLOCK_SVPWM (uint16_t)((DEADTIME_SVPWM*(SYSTEM_CLOCK_FREQ/1000000))/1000)
#define DEADTIME_CONFIGURE (uint8_t)136
#define BRK_GPIO_M GPIOB
#define BRK_PIN_M GPIO_Pin_12
#define CURR_SAMPLE_RESISTOR_ADC _IQ18(0.1)
#define CURR_AMPLIFIER_ADC _IQ18(3.73333)
#define CURR_SAMPLE_RANGE_ADC _IQ18div(_IQ18(1.65),_IQ18mpy(CURR_SAMPLE_RESISTOR_ADC,CURR_AMPLIFIER_ADC))
#define CURR_OFFSET_READ_NUM_ADC ((uint8_t)16)
#define SAMPLING_TIMER_CLOCK ADC_SampleTime_7Cycles5
#define CONVER_TIME_ADC 750
#define CURR_CONVERT_CLOCK_ADC (uint16_t)((CONVER_TIME_ADC*(SYSTEM_CLOCK_FREQ/1000000))/1000)
#define CURR_RISE_TIME_ADC 900
#define CURR_RISE_CLOCK_ADC (uint16_t)((CURR_RISE_TIME_ADC*(SYSTEM_CLOCK_FREQ/1000000))/1000)
#define CURR_NOISE_TIME_ADC 650
#define CURR_NOISE_CLOCK_ADC (uint16_t)((CURR_NOISE_TIME_ADC*(SYSTEM_CLOCK_FREQ/1000000))/1000)
#if(CURR_RISE_TIME_ADC > CURR_NOISE_TIME_ADC)
#define CURR_MAX_TRTN_CLOCK_ADC CURR_RISE_CLOCK_ADC
#else
#define CURR_MAX_TRTN_CLOCK_ADC CURR_NOISE_CLOCK_ADC
#endif
#define ADC1_CURR_CHANNEL_PHASE_M ADC_Channel_4
#define ADC2_CURR_CHANNEL_PHASE_M ADC_Channel_5
#define DCVOLT_INIT _IQ(1.0)
#define DCVOLT_CONV_RATIO _IQ18(0.006651884)
#define DCVOLT_AVER_SIZE 100
#define DCVOLT_LPF_CF_M 1000
#define DCVOLT_LPF_PERIOD_M LBG_CAL_PERIOD_M
#define DCVOLT_LPF_WcT_M _IQmpyI32(_IQmpy(DCVOLT_LPF_PERIOD_M,PI_2_Q24),DCVOLT_LPF_CF_M)
/* Exported variables -------------------------------------------------------*/
extern SVPWM_1R_Type SVPWM_Cal_M;
extern ADCStruc_Type ADC_M;
extern PWMCali_Type PWMCali_M;
void SVPWM_1R_Paramter_Init(SVPWM_1R_Type *SVPWM_Cal,PWMCali_Type *PWMCali,Motor_Base_Type *Mbase);
void SVPWM_1R_Status_Init_M(SVPWM_1R_Type *SVPWM_Cal,PWMCali_Type *PWMCali);
void ADC_Parameter_Init (ADCStruc_Type *ADCStruc,Motor_Base_Type *Mbase);
void ADC_Status_Init (ADCStruc_Type *ADCStruc);
void SVPWM_1R_Timer_Configure(void);
void ADC_OPA_Configure(ADCStruc_Type *ADCStruc);
void ADC_1R_Offset_Reading(ADC_TypeDef *ADCx, ADCStruc_Type *ADCStruc,u_int8_t ADC_num);
void ADC_1R_Start (FunctionalState cmd);
void SVPWM_Updateup(SVPWM_1R_Type *SVPWM_Cal,PWMCali_Type *PWMCali);
void SVPWM_Updatedown (SVPWM_1R_Type *SVPWM_Cal,PWMCali_Type *PWMCali);
void ADC_Trigger_Update(PWMCali_Type *PWMCali);
void DCBUS_Volt_Cal(ADCStruc_Type *ADCStruc,ADC_TypeDef *ADCx);
void SVPWM_Calculation(SVPWM_1R_Type *SVPWM_Cal, Component_2S_Type *VoltRef);
void SVPWM_Calibration(SVPWM_1R_Type *SVPWM_Cal, PWMCali_Type *PWMCali_Struc);
Component_3S_Type Current_Cal_1R(uint8_t Sector, ADCStruc_Type *ADCStruc);
void SVPWM_Zerovolt_Output(SVPWM_1R_Type *SVPWM_Cal);
void SVPWM_Lowside_Effective(SVPWM_1R_Type *SVPWM_Cal);
void SVPWM_Zerovolt_Output_Immediate(SVPWM_1R_Type *SVPWM_Cal);
void SVPWM_Lowside_Effective_Immediate(void);
void NTCSample(Temperature_ctl_Type *TempM, ADC_TypeDef *ADCx);
#endif
@@ -0,0 +1,252 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : M5_MotorStart.c
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description : Initialization of the motor before starting
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include "M0_Control_Library.h"
InjStart_Type InjStart_M;
/******************************************************************************
* Function Name : Motor_Start_Init
* Description : Motor Start Init
* Input : None
* Output : None
* Return : None
******************************************************************************/
void Motor_Start_Init_M(void)
{
LED_OFF(&LED_M);
KeyandLED_Status_Ini(&Key_M,&LED_M);
Operation_Status_Init(&Operation_M);
Eventmanager_Initial(&Emanager_M);
Speedrampctr_Start_Init_M(&SpeedRamp_M);
Speed_Set(&SpeedRamp_M);
Temp_Set(&Key_M,&SpeedRamp_M,&Triac_ctl);
Protection_and_Emergency_Init();
PID_Output_Init(&Mpid_M);
Motor_Status_Initial_M(&MStruc_M);
Injstart_Status_Init_M(&InjStart_M);
Dcurr_Process_Init(&DCurrProcess_M,1);
SVPWM_1R_Status_Init_M(&SVPWM_Cal_M,&PWMCali_M);
LBG_Status_Init(&MLBG_M,&LBG_Status_M);
Buffer_Clear(&(LBG_SpeedBuffer_M[0]),&(MLBG_M.SpeedBuffPara));
HFVQI_Status_Init_M(&HFVQI_StartStruc_M);
Buffer_Clear(&(HFVQIPosi_CBuff_M[0]),&HFVQIPosi_CBuffPara_M);
Powercom_Status_Init(&Powercom_M);
ADC_1R_Offset_Reading(ADC1,&ADC_M,1);
ADC_1R_Offset_Reading(ADC2,&ADC_M,2);
ADC_Status_Init (&ADC_M);
Triac_Status_Init(&Triac_ctl,&Tempctl_M);
SVPWM_Zerovolt_Output_Immediate(&SVPWM_Cal_M);
TIM_CtrlPWMOutputs(TIM1,ENABLE);
TempLed_Set(&Key_M,&LED_M);
SpeedLed_Set(&SpeedRamp_M,&LED_M);
}
/******************************************************************************
* Function Name : Injstart_Parameter_Define_M
* Description : Definition of Current Injection Start Parameters
* Input : Pointer to motor start control structure
* Output : None
* Return : None
******************************************************************************/
void Injstart_Parameter_Define_M (InjStart_Type *InjStart)
{
InjStart->ForceInjCurrStep = _IQdiv(FORCE_INJ_CURR_M,FORCE_INJ_CURR_RAMP_TIME_M)/FORCE_INJ_FREQ_M;
InjStart->ForceInjCurrTarget = FORCE_INJ_CURR_M;
InjStart->ForceInjCurrAngle = FORCE_INJ_ANGLE_M;
InjStart->ForceInjStage = RAMP_INJ_STAGE_M;
InjStart->RampInjCurrTarget = RAMP_INJ_CURR_FINAL_M;
InjStart->RampInjCurrStep = _IQdiv((RAMP_INJ_CURR_FINAL_M - RAMP_INJ_CURR_INIT_M),\
RAMP_INJ_CURR_RAMP_TIME_M)/RAMP_INJ_FREQ_M;
InjStart->RampInjSpeedTarget = RAMP_INJ_SPEED_M*STARTUP_DIRECTION;
InjStart->RampInjSpeedStep = _IQdiv(RAMP_INJ_SPEED_M,RAMP_INJ_SPEED_RAMP_TIME_M)/RAMP_INJ_FREQ_M;
InjStart->K_WetoPosi = RAMP_INJ_PERIOD_M*RATED_FREQ_M;
InjStart->CurrErrThresh = INJECTION_CURRERR_THRESH_M;
InjStart->RampInjStage1 = RAMP_INJ_STAGE1_M;
InjStart->RampInjStage2 = RAMP_INJ_STAGE2_M;
InjStart->Speedadj = RAMP_INJ_SPEED_ADJ*STARTUP_DIRECTION;
InjStart->Curradj = RAMP_INJ_CURR_ADJ;
InjStart->IF_Vicom.Kcom = IF_VICOM_COEF_M * STARTUP_DIRECTION;
InjStart->IF_Vicom.Wecomupper = IF_VICOM_UPPER_M;
InjStart->IF_Vicom.Wecomlower = IF_VICOM_LOWER_M;
InjStart->IF_Vicom.Power_HPF1st.Input_Coef=_IQdiv(UNIT_Q24,(IF_VICOM_HPF1st_WcT_M + UNIT_Q24));
InjStart->IF_Vicom.Power_HPF1st.Output_Coef=_IQdiv(UNIT_Q24,(IF_VICOM_HPF1st_WcT_M + UNIT_Q24));
}
/******************************************************************************
* Function Name : Injstart_Status_Init_M
* Description : Current injection start-up state initialization
* Input : Pointer to motor start control structure
* Output : None
* Return : None
******************************************************************************/
void Injstart_Status_Init_M(InjStart_Type *InjStart)
{
InjStart->ForceInjCurrRef = _IQ(0);
InjStart->ForceInjCounter = 0;
InjStart->RampInjCurrRef = RAMP_INJ_CURR_INIT_M;
InjStart->RampInjSpeedRef = RAMP_INJ_SPEEDINT_M *STARTUP_DIRECTION;
InjStart->RampInjAngle = _IQ(0);
InjStart->RampInjCounter =0;
InjStart->Curr_2R.cd = _IQ(0);
InjStart->Curr_2R.cq = _IQ(0);
InjStart->VoltRef_2R.cd = _IQ(0);
InjStart->VoltRef_2R.cq = _IQ(0);
InjStart->Status = INITIAL;
InjStart->InjStage=0;
InjStart->IF_Vicom.Powerinst = 0;
InjStart->IF_Vicom.Powerfilter = 0;
InjStart->IF_Vicom.Wecom = 0;
InjStart->IF_Vicom.Power_HPF1st.Out_New = 0;
InjStart->IF_Vicom.Power_HPF1st.Out_Pre = 0;
InjStart->IF_Vicom.Power_HPF1st.In_Pre = 0;
}
/******************************************************************************
* Function Name : Injstart_Process_M
* Description : Injection start, first force positioning, then current closed-loop start
* Input : Pointer to motor start control structure,
* pointer to overall motor status structure,
* pointer to LBG observer structure
* Output : None
* Return : None
******************************************************************************/
void Injstart_Process_M(InjStart_Type *InjStart,Motor_Sructure_Type *MStruc,Motor_LBG_Type *MLBG)
{
switch(InjStart->Status)//Æô¶¯×´Ì¬»ú
{
case INITIAL:
InjStart->Status = INJECTION;
break;
case INJECTION:
if(InjStart->ForceInjCounter < U32_MAX)
InjStart->ForceInjCounter++;
if(InjStart->ForceInjCurrRef < InjStart->ForceInjCurrTarget)
{
InjStart->ForceInjCurrRef += InjStart->ForceInjCurrStep;
if(InjStart->ForceInjCurrRef > InjStart->ForceInjCurrTarget)
InjStart->ForceInjCurrRef = InjStart->ForceInjCurrTarget;
MStruc->CRef2R.cd = InjStart->ForceInjCurrRef;
MStruc->CRef2R.cq = 0;
MStruc->Cossin = TrigonoMetric_Function( InjStart->ForceInjCurrAngle);
}
else
{
if( _IQabs(MStruc->C2R_L.cd)>=_IQMPY_MACRO(InjStart->CurrErrThresh,
_IQabs(MStruc->CRef2R.cd)))
{
if( InjStart->ForceInjCounter >= InjStart->ForceInjStage)
{
InjStart->RampInjCurrRef = InjStart->ForceInjCurrRef;
InjStart->RampInjAngle = InjStart->ForceInjCurrAngle;
InjStart->Status = RAMP;
}
}
else
Protection_SetFault(STARTUP_FAILURE_M);
}
break;
case RAMP:
if(InjStart->RampInjCounter < U32_MAX)
InjStart->RampInjCounter++;
Injstart_Curr_Speed_Ramp(InjStart);
#if defined IF_VIBRATION_COM
IF_Vibration_Com(&(MStruc->VRef2R), &(MStruc->C2R_L), InjStart);
InjStart->RampInjAngle = InjStart->RampInjAngle +\
_IQMPY_MACRO(InjStart->RampInjSpeedRef2,InjStart->K_WetoPosi);
#else
InjStart->RampInjAngle = InjStart->RampInjAngle +\
_IQMPY_MACRO(InjStart->RampInjSpeedRef,InjStart->K_WetoPosi);
#endif
InjStart->RampInjAngle = Round_Circle_Limitation_PU(InjStart->RampInjAngle);
MStruc->Cossin = TrigonoMetric_Function(InjStart->RampInjAngle);
MStruc->CRef2R.cd = InjStart->RampInjCurrRef;
MStruc->CRef2R.cq = 0;
if(InjStart->RampInjCounter >= (InjStart->RampInjStage1))
{
if(_IQabs(MStruc->C2R_L.cd)>=_IQMPY_MACRO(InjStart->CurrErrThresh,\
_IQabs(MStruc->CRef2R.cd)))
{
if(MLBG->Cal_Struc.Inimark == TRUE)
Injstart_Transition_Cal(InjStart,MStruc,MLBG);
else
{
LBG_Cal_Init(InjStart,MStruc,MLBG);
MLBG->Cal_Struc.Inimark = TRUE;
}
}
else
Protection_SetFault(STARTUP_FAILURE_M);
}
else
{
MLBG->Cal_Struc.CalphaPrev = MStruc->C2S.Alpha;
MLBG->Cal_Struc.CbetaPrev = MStruc->C2S.Beta;
}
if (InjStart->RampInjCounter >=InjStart->RampInjStage2)
Protection_SetFault(STARTUP_FAILURE_M);
break;
default:
break;
}
}
@@ -0,0 +1,61 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : M5_MotorStart.h
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description : Initialization of the motor before starting
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __M5_MOTORSTART_H
#define __M5_MOTORSTART_H
#define FORCE_INJ_FREQ_M FREQ_SVPWM
#define FORCE_INJ_CURR_M _IQ(0.3)
#define FORCE_INJ_ANGLE_M _IQ(0.083333*1)
#define FORCE_INJ_CURR_RAMP_TIME_M _IQ(0.2)
#define RAMP_INJ_STAGE_M (uint32_t)(FREQ_SVPWM*3)
#define RAMP_INJ_FREQ_M FREQ_SVPWM
#define RAMP_INJ_PERIOD_M _IQ(1.0)/FREQ_SVPWM
#define RAMP_INJ_CURR_INIT_M _IQ(0.00)
#define RAMP_INJ_CURR_FINAL_M _IQ(0.4)
#define RAMP_INJ_CURR_RAMP_TIME_M _IQ(0.001)
#define RAMP_INJ_SPEEDINT_M _IQ(0.005)
#define RAMP_INJ_SPEED_M _IQ(0.2)
#define RAMP_INJ_SPEED_RAMP_TIME_M _IQ(0.2)
#define RAMP_INJ_STAGE1_M (uint32_t)(FREQ_SVPWM*0.15)
#define RAMP_INJ_STAGE2_M (uint32_t)(FREQ_SVPWM*0.6)
#define INJECTION_CURRERR_THRESH_M _IQ(0.5)
#define RAMP_INJ_SPEED_ADJ _IQ(0.05)
#define RAMP_INJ_CURR_ADJ _IQ(1.1)
#define IF_VICOM_COEF_M _IQ(-0.15)
#define IF_VICOM_UPPER_M _IQ(0.01)
#define IF_VICOM_LOWER_M _IQ(-0.01)
#define IF_VICOM_PERIOD_M _IQ(1.0)/FREQ_SVPWM
#define IF_VICOM_HPF1st_CF_M 10
#define IF_VICOM_HPF1st_WcT_M _IQmpy(_IQmpyI32(IF_VICOM_PERIOD_M,IF_VICOM_HPF1st_CF_M),PI_2_Q24)
/* Exported variables -------------------------------------------------------*/
extern InjStart_Type InjStart_M;
void Motor_Start_Init_M(void);
void Injstart_Parameter_Define_M (InjStart_Type *InjStart);
void Injstart_Status_Init_M(InjStart_Type *InjStart);
void Injstart_Process_M(InjStart_Type *InjStart,Motor_Sructure_Type *MStruc,Motor_LBG_Type *MLBG);
void Controlloop_Initial(InjStart_Type *InjStart,_iq24 Speedact,Motor_Sructure_Type *MStruc,\
Motor_PID_Type *Mpid,Speedrampctr_Type *Speed_Ramp);
void Injstart_Curr_Speed_Ramp(InjStart_Type *InjStart);
void Injstart_Transition_Cal(InjStart_Type *InjStart,Motor_Sructure_Type *MStruc,Motor_LBG_Type *MLBG);
void Speedrampctr_Start_Init_M(Speedrampctr_Type *Speed_Ramp);
#endif
@@ -0,0 +1,152 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : M5_Operation_Cusevent.c
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include "M0_Control_Library.h"
Eventmanager_Type Emanager_M;
uint8_t testcounter =0;
/******************************************************************************
* Function Name : Eventmanager_Initial
* Description : Event manage Init
* Input : Event management structure pointer
* Output : None
* Return : None
******************************************************************************/
void Eventmanager_Initial(Eventmanager_Type *EventM)
{
EventM->Event_10ms= FALSE;
EventM->Event_10ms_cntset = (uint16_t)(EVENT_10ms*EVENT_CHECK_FREQ);
EventM->Event_10ms_cnt = 0;
EventM->Event_1ms= FALSE;
EventM->Event_1ms_cntset = (uint16_t)(EVENT_1ms*EVENT_CHECK_FREQ);
EventM->Event_1ms_cnt = 0;
EventM->Event_2s= FALSE;
EventM->Event_2s_cntset = (uint16_t)(EVENT_2s*EVENT_CHECK_FREQ);
EventM->Event_2s_cnt = 0;
}
/******************************************************************************
* Function Name : Zerocross_Process
* Description : AC input zero-crossing event handling
* Input : Temperature control structure pointer, thyristor control structure pointer, key management structure pointer
* Output : None
* Return : None
******************************************************************************/
void ACZerocross_Process(Temperature_ctl_Type *TempM,Key_Manager_Type *KeyM,TRIAC_ctl_Type *TriacM)
{
if((KeyM->Tkeyeffective==TRUE)||(KeyM->Skeyeffective==TRUE))
TriacM->PeriodCtl.DutychangeFlag=TRUE;
if( (TriacM->Zero.ZcrossEvent==1) && (TriacM->Zero.Zcrosseffective == TRUE) )
{
#ifdef ZEROCROSSOVER_OC
if(TriacM->Zero.Zcrosseffectivecnt<2)
TriacM->Zero.Zcrosseffectivecnt++;
if(TriacM->Zero.Zcrosseffectivecnt>=2)
{
if(TriacM->PeriodCtl.DelayProcess_Flag==0)//
{
TriacM->Zero.ZcrossDelayTrigcnt=TriacM->Zero.ZcrossDelayTrigset;
TriacM->PeriodCtl.DelayProcess_Flag=1;
}
if((TriacM->Zero.ZcrossDelayTrigcnt==0)&&(TriacM->PeriodCtl.DelayProcess_Flag==1))
{
TriacZero_50HZControl_Process(TempM,KeyM,TriacM,&SpeedRamp_M);
TriacM->Zero.Zcrosseffectivecnt=0;
TriacM->Zero.ZcrossEvent=0;
TriacM->PeriodCtl.DelayProcess_Flag=0;
}
}
else
{
TriacM->Zero.ZcrossEvent=0;
TriacM->PeriodCtl.DelayProcess_Flag=0;
}
#else
if(TriacM->PeriodCtl.DelayProcess_Flag==0)//
{
TriacM->Zero.ZcrossDelayTrigcnt=TriacM->Zero.ZcrossDelayTrigset;
TriacM->PeriodCtl.DelayProcess_Flag=1;
}
if((TriacM->Zero.ZcrossDelayTrigcnt==0)&&(TriacM->PeriodCtl.DelayProcess_Flag==1))
{
TriacZero_50HZControl_Process(TempM,KeyM,TriacM,&SpeedRamp_M);
TriacM->Zero.ZcrossEvent=0;
TriacM->PeriodCtl.DelayProcess_Flag=0;
}
#endif
}
}
/******************************************************************************
* Function Name : Event_10ms_Process
* Description : 10ms Event process
* Input : Event management structure pointer
* Output : None
* Return : None
******************************************************************************/
void Event_10ms_Process(Eventmanager_Type *EventM)
{
if(EventM->Event_10ms == TRUE)
{
// testcounter++;
//
// if(testcounter ==2)
// LED_Lighton(&LED_M.YLED);
// if(testcounter ==4)
// {
// LED_Lightoff(&LED_M.YLED);
// testcounter = 0;
// }
EventM->Event_10ms_cnt = EventM->Event_10ms_cntset;
EventM->Event_10ms = FALSE;
}
}
/******************************************************************************
* Function Name : Event_1ms_Process
* Description : 1ms Event Handling
* Input : Event management structure pointer
* Output : None
* Return : None
******************************************************************************/
void Event_1ms_Process(Eventmanager_Type *EventM)
{
//static u8 Event_50ms_cnt;
if(EventM->Event_1ms == TRUE)
{
EventM->Event_1ms_cnt = EventM->Event_1ms_cntset;
EventM->Event_1ms = FALSE;
}
}
/******************************************************************************
* Function Name : Event_1ms_Process
* Description : 2s Event Handling
* Input : Event management structure pointer
* Output : None
* Return : None
******************************************************************************/
void Event_2s_Process(Eventmanager_Type *EventM)
{
if(EventM->Event_2s == TRUE)//¶¨Ê±µ½
{
EventM->Event_2s_cnt = EventM->Event_2s_cntset;
EventM->Event_2s = FALSE;
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,351 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : M5_Operation_and_Display.h
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description : Definition of relevant operation parameters such as buttons and displays
Definition of acceleration and deceleration parameters
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __MOTOR_OPERATION_AND_DISPLAY_H
#define __MOTOR_OPERATION_AND_DISPLAY_H
typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus;
typedef enum {OFF = 0, ON = !OFF} LightStatus;
typedef struct
{
uint8_t FlashExcep;
uint16_t FlashData[2];
volatile uint32_t MemAddress;
volatile FLASH_Status FLASHStatus;
volatile TestStatus MemoryProgramStatus;
} Flash_Operation_Type;
typedef struct
{
GPIO_TypeDef *Group;
uint16_t Pin;
} LEDGPIO_Type;
typedef struct
{
uint16_t FlickInterval;
uint16_t FlickCnt;
uint8_t FlickCtl;
LightStatus LightFlag;
} LED_Type;
typedef struct
{
LED_Type LED4;
LED_Type LED5;
LED_Type LED6;
LED_Type LED7;
LED_Type LED8;
LED_Type LED9;
LEDGPIO_Type Pin1;
LEDGPIO_Type Pin2;
LEDGPIO_Type Pin3;
} Led_Manager_Type;//LED¹ÜÀí
/* Exported constants -------------------------------------------------------*/
/*********************** תËÙ²Ù×÷¶¨Òå ******************************/
#define STARTUP_DIRECTION 1
#define SPEED_ADJUST_STEP _IQ(0.05)
#define MAX_ANGSPEED_POS_M _IQ(1.0)
#define MAX_ANGSPEED_NEG_M _IQ(-1.0)
#define MIN_ANGSPEED_POS_M _IQ(0.025)
#define MIN_ANGSPEED_NEG_M _IQ(-0.025)
#define SPEED_RAMP_FREQ_M SPEED_LOOP_CAL_FREQ
#define ACCE_TIME_M 0.5
#define DECE_TIME_M 0.4
#define POWEROFF_DECE_TIME_M 0.15
#define SPEEDPOINT1 _IQ(0.7965085)
#define SPEEDPOINT2 _IQ(0.8545455)
#define SPEEDPOINT3 _IQ(0.9094380)
//#define SPEEDPOINT3 _IQ(0.92744135)
//#define SPEEDPOINT3 _IQ(0.9383524)
//#define SPEEDPOINT3 _IQ(0.954719)
#define SPEEDPOINT_RANK 3
#define PRECHAGE_TIME 0.05
#define FAST_DECE_SPEED _IQ(0.6)
#define BREAKSPEED _IQ(0.65)
#define BREAKTIME 0.25
#define START_FINISH_SPEED (FAST_DECE_SPEED +_IQ(0.055))
#define LED_PROCESS_FREQ SPEED_LOOP_CAL_FREQ
#define LED_FLICKER_TIME 0.5
#define OPERATION_CAL_FREQ SPEED_LOOP_CAL_FREQ
#define STOP_WAITING_TIME 0.5
#define FAULT_HOLDING_TIME 0.5
#define SYS_RESET_TIME 0.025
#define POWERVERY_FREQ SPEED_LOOP_CAL_FREQ
#define POWERON_VOLT _IQ(0.85)
#define POWERON_TIME 0.1
#define POWEROFF_VOLT1 _IQ(0.7)
#define POWEROFF_VOLT2 _IQ(0.5)
#define POWERVERY_DCVOLTAVERSIZE 4
#define VDCLPF_SPEEDLIM_CF_M 5
#define VDCLPF_SPEEDLIM_PERIOD_M _IQ(1.0)/SPEED_LOOP_CAL_FREQ
#define VDCLPF_SPEEDLIM_WcT_M _IQmpyI32(_IQmpy(VDCLPF_SPEEDLIM_PERIOD_M,PI_2_Q24),VDCLPF_SPEEDLIM_CF_M)
#define VDC_SPEEDLIM_BEGIN _IQ(0.89)
#define VDC_SPEEDLIM_RELEASE _IQ(0.915)
#define VDC_SPEEDLIM_ADJ _IQ(1.1)
#define KEY_CHECK_FREQ SPEED_LOOP_CAL_FREQ
#define EEWRITE_WAITING_TIME 0.005
#define EEWRITE_CYCLE 2
#define SHKEY_CHECK_INTERVAL 0.040
#define SHKEY_EFFECTIVE_TIME 0.010
#define SHKEY_INEFFECTIVE_TIME 0.035
#define TCKEY_EFFECTIVE_TIME 0.010
#define TCKEY_INEFFECTIVE_TIME 0.035
#define SRKEY_EFFECTIVE_TIME 0.1
#define SRKEY_INEFFECTIVE_TIME 0.1
#define TKEY_RANK_SET 3
#define TKEY_SHORT_TIME_UP 0.5
#define TKEY_SHORT_TIME_DOWM 0.1
#define TKEY_LONG_TIME 2
#define ACKEY_CHECK_INTERVAL 0.040
#define ACKEY_EFFECTIVE_TIME 0.005
#define ACKEY_INEFFECTIVE_TIME 0.035
#define ZEROCROSS_FREQ 100
#define ZEROCROSS_VERYFREQ FREQ_SVPWM
#define OC_ZEROCROSS_VERYTIME 5
#define TR_ZEROCROSS_VERYTIME 7
#define ZEROCROSSLOST_VERYTIME 0.05
#define ZEROCROSSLOST_VERYFREQ FREQ_SVPWM
#define EVENT_CHECK_FREQ SPEED_LOOP_CAL_FREQ
#define EVENT_10ms 0.01
#define EVENT_1ms 0.001
#define EVENT_2s 2.00
#define TRIAC_ENABLEWAIT 1.5
#define TRIAC_OFF() (GPIO_SetBits(GPIOB, GPIO_Pin_7))
#define TRIAC_ON() (GPIO_ResetBits(GPIOB, GPIO_Pin_7))
#define TRIAC_TIME 660
#define TRIAC_CONTOROL_PERIOD 20
#ifdef ZEROCROSSOVER_OC
#define TRIAC_TIME_TO_TRIGGER 0.005
#else
#define TRIAC_TIME_TO_TRIGGER 0.003
#endif
#define DUTYMAX_T1S1 13
#define DUTYMIN_T1S1 3
#define DUTYDEFAULT_T1S1 11
#define DUTYMAX_T1S2 17
#define DUTYMIN_T1S2 3
#define DUTYDEFAULT_T1S2 14
#define DUTYMAX_T1S3 19
#define DUTYMIN_T1S3 3
#define DUTYDEFAULT_T1S3 16
#define DUTYMAX_T2S1 20
#define DUTYMIN_T2S1 3
#define DUTYDEFAULT_T2S1 16
#define DUTYMAX_T2S2 20
#define DUTYMIN_T2S2 3
#define DUTYDEFAULT_T2S2 18
#define DUTYMAX_T2S3 23
#define DUTYMIN_T2S3 3
#define DUTYDEFAULT_T2S3 21
#define DUTYMAX_T3S1 22
#define DUTYMIN_T3S1 3
#define DUTYDEFAULT_T3S1 19
#define DUTYMAX_T3S2 24
#define DUTYMIN_T3S2 3
#define DUTYDEFAULT_T3S2 20
#define DUTYMAX_T3S3 27
#define DUTYMIN_T3S3 3
#define DUTYDEFAULT_T3S3 23
#define NUM50HZ_DATA (u8)3
#define NUM100HZ_DATA (u8)6
#define PSC_LED_INTERVAL 0.2
#define PSC_LED_INTERVAL_TOTAL 5.0
#define PSC_LED_INTERVAL_NUM 3
#define PSC_LED_LAST 3.0
#define PSC_FREQ SPEED_LOOP_CAL_FREQ
#define PT_RS _IQ18(10.0)
#define TEMP_AVER_SIZE (u32)8
//34~289
#define DUTY_LIM_TABLE {\
0x00643,0x006D0,0x00766,0x00803,0x008A9,0x00957,0x00A0E,0x00ACE,\
0x00B96,0x00C68,0x00D42,0x00E26,0x00F14,0x0100B,0x0110C,0x01217,\
0x0132B,0x0144A,0x01574,0x016A7,0x017E5,0x0192E,0x01A81,0x01BE0,\
0x01D49,0x01EBD,0x0203C,0x021C6,0x0235C,0x024FD,0x026A9,0x02860,\
0x02A23,0x02BF2,0x02DCC,0x02FB1,0x031A2,0x0339F,0x035A8,0x037BC,\
0x039DB,0x03C07,0x03E3E,0x04081,0x042CF,0x0452A,0x0478F,0x04A01,\
0x04C7E,0x04F06,0x0519B,0x0543A,0x056E5,0x0599C,0x05C5D,0x05F2A,\
0x06202,0x064E5,0x067D4,0x06ACD,0x06DD1,0x070E0,0x073F9,0x0771D,\
0x07A4B,0x07D84,0x080C7,0x08414,0x0876B,0x08ACC,0x08E37,0x091AB,\
0x09529,0x098AF,0x09C3F,0x09FD8,0x0A37A,0x0A725,0x0AAD8,0x0AE93,\
0x0B256,0x0B622,0x0B9F5,0x0BDD0,0x0C1B2,0x0C59B,0x0C98C,0x0CD83,\
0x0D181,0x0D585,0x0D990,0x0DDA0,0x0E1B7,0x0E5D3,0x0E9F4,0x0EE1B,\
0x0F246,0x0F676,0x0FAAB,0x0FEE4,0x10321,0x10762,0x10BA6,0x10FEE,\
0x11439,0x11886,0x11CD7,0x12129,0x1257E,0x129D5,0x12E2D,0x13287,\
0x136E2,0x13B3E,0x13F9B,0x143F8,0x14855,0x14CB3,0x15110,0x1556C,\
0x159C8,0x15E23,0x1627C,0x166D4,0x16B2A,0x16F7E,0x173D0,0x17820,\
0x17C6D,0x180B7,0x184FD,0x18941,0x18D80,0x191BC,0x195F4,0x19A27,\
0x19E56,0x1A280,0x1A6A5,0x1AAC5,0x1AEDF,0x1B2F4,0x1B703,0x1BB0B,\
0x1BF0E,0x1C30A,0x1C6FF,0x1CAED,0x1CED5,0x1D2B5,0x1D68D,0x1DA5E,\
0x1DE27,0x1E1E8,0x1E5A1,0x1E951,0x1ECF9,0x1F098,0x1F42F,0x1F7BC,\
0x1FB40,0x1FEBB,0x2022C,0x20594,0x208F2,0x20C46,0x20F90,0x212D0,\
0x21605,0x21931,0x21C52,0x21F68,0x22273,0x22574,0x2286A,0x22B55,\
0x22E35,0x23109,0x233D3,0x23691,0x23944,0x23BEC,0x23E88,0x24119,\
0x2439E,0x24617,0x24885,0x24AE8,0x24D3E,0x24F89,0x251C9,0x253FC,\
0x25624,0x25841,0x25A51,0x25C56,0x25E4F,0x2603D,0x2621F,0x263F6,\
0x265C1,0x26780,0x26934,0x26ADD,0x26C7A,0x26E0C,0x26F93,0x2710F,\
0x27280,0x273E6,0x27541,0x27691,0x277D6,0x27911,0x27A42,0x27B68,\
0x27C84,0x27D96,0x27E9E,0x27F9C,0x28090,0x2817A,0x2825C,0x28333,\
0x28402,0x284C8,0x28585,0x28639,0x286E5,0x28788,0x28823,0x288B6,\
0x28942,0x289C5,0x28A42,0x28AB7,0x28B25,0x28B8C,0x28BEC,0x28C46,\
0x28C9A,0x28CE7,0x28D2F,0x28D71,0x28DAE,0x28DE6,0x28E18,0x28E46,\
0x28E70,0x28E95,0x28EB6,0x28ED3,0x28EEC,0x28F02,0x28F15,0x28F26};
/* Exported variables -------------------------------------------------------*/
extern Speedrampctr_Type SpeedRamp_M;
extern Powercontrol_Type Powerctr_M;
extern Led_Manager_Type LED_M;
extern Key_Manager_Type Key_M;
extern Eventmanager_Type Emanager_M;
extern Operation_Type Operation_M;
extern Temperature_ctl_Type Tempctl_M;
extern uint8_t Keymembuff[EEWRITE_CYCLE];
extern TRIAC_ctl_Type Triac_ctl;
extern u16 Temp_PhaseDuty[SPEEDPOINT_RANK][TKEY_RANK_SET+1];
/* Exported macro -----------------------------------------------------------*/
/* Exported functions ------------------------------------------------------ */
void Motor_Operation_Process(void);
void Speedrampctr_Parameter_Define(Speedrampctr_Type *Speed_Ramp);
void Speedrampctr_Start_Init_M(Speedrampctr_Type *Speed_Ramp);
void Speed_Set(Speedrampctr_Type *Speed_Ramp);
void Poweroperation_Initial(Powercontrol_Type *PowerOper);
void Poweroperation_Process(Speedrampctr_Type *SpeedRamp,ADCStruc_Type *ADCStruc,Powercontrol_Type *PowerOper,\
Runningstatus_Type *Runningstatus,PID_Structure_Type *Speedpid,_iq24 Speedact);
void KeyandLED_IOInit(void);
void KeyandLED_Parameter_Define(Key_Manager_Type *KeyM,Led_Manager_Type *LEDM);
void KeyandLED_Status_Ini(Key_Manager_Type *KeyM,Led_Manager_Type *LEDM);
void Tempkeycheck(Key_Manager_Type *KeyM);
void Speedkeycheck_Hold(Key_Manager_Type *KeyM,Speedrampctr_Type *Speed_Ramp);
void Speedkeycheck_Recover(Key_Manager_Type *KeyM,Speedrampctr_Type *Speed_Ramp);
void Coldkeycheck(Key_Manager_Type *KeyM);
void Key_Memwrite(Key_Manager_Type *KeyM,Speedrampctr_Type *Speed_Ramp,Flash_Operation_Type *FlashM);
void Key_Memread(Key_Manager_Type *KeyM,Speedrampctr_Type *Speed_Ramp,Flash_Operation_Type *FlashM);
void Fault_LEDflicker(Led_Manager_Type *LED_M);
void Time_Delay_Process(void);
void Time_Wait(uint16_t);
void Time_Delay_Set(uint16_t Delayset, uint16_t *Delaycounter);
Truth_Verify_Type Time_Delay_Elapse(uint16_t Delaycounter);
void Operation_Parameter_Define(Operation_Type *Operastruc);
void Operation_Status_Init(Operation_Type *Operastruc);
void Eventmanager_Initial(Eventmanager_Type *EventM);
void AC_Zerocross_Detect(Key_Manager_Type *KeyM);
void AC_Zerocross_Detect_OC(TRIAC_ctl_Type *TriacM);
void AC_Zerocross_Detect_TR(TRIAC_ctl_Type *TriacM);
void ACZerocross_Process(Temperature_ctl_Type *TempM,Key_Manager_Type *KeyM,TRIAC_ctl_Type *TriacM);
void Event_10ms_Process(Eventmanager_Type *EventM);
void Event_1ms_Process(Eventmanager_Type *EventM);
void Event_2s_Process(Eventmanager_Type *EventM);
void Triac_Parameter_Define(TRIAC_ctl_Type *TriacM,Temperature_ctl_Type *TempM);
void Triac_Status_Init(TRIAC_ctl_Type *TriacM,Temperature_ctl_Type *TempM);
void Temp_Set(Key_Manager_Type *KeyM,Speedrampctr_Type *Speed_Ramp,TRIAC_ctl_Type *TriacM);
void Triac_Control_Process(TRIAC_ctl_Type *TriacM);
void Temp_Ramp_Process(Temperature_ctl_Type *TempM);
void TempInit_Measure(Temperature_ctl_Type *TempM,ADC_TypeDef *ADCx);
void TriacPhAngle_Control_Process(Temperature_ctl_Type *TempM,Key_Manager_Type *KeyM,TRIAC_ctl_Type *TriacM);
void TriacZero_50HZControl_Process(Temperature_ctl_Type *TempM,Key_Manager_Type *KeyM,TRIAC_ctl_Type *TriacM,Speedrampctr_Type *Speed_Ramp);
void Triac_Timeoff(TRIAC_ctl_Type *TriacM);
void ACKEY_CHECK(Key_Manager_Type *KeyM);
void PSC_Process(Operation_Type *Operation);
void Led_Operation(Led_Manager_Type *LEDM);
void SpeedLed_Set(Speedrampctr_Type *Speed_Ramp,Led_Manager_Type *LEDM);
void TempLed_Set(Key_Manager_Type *KeyM,Led_Manager_Type *LEDM);
void LED_OFF(Led_Manager_Type *LEDM);
void LED_Flicker(LED_Type *LedM);
uint16_t Duty_lim(TRIAC_ctl_Type *TriacM,_iq24 value);
#endif
@@ -0,0 +1,425 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : M5_TRIAC_Control.c
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include "M0_Control_Library.h"
TRIAC_ctl_Type Triac_ctl;
//u16 Temp_PhaseDuty[SPEEDPOINT_RANK][TKEY_RANK_SET+1]={{0,85,110,125},{0,110,125,140},{0,125,145,165}};
_iq24 DutyLim_table[256]=DUTY_LIM_TABLE;
/******************************************************************************
* Function Name : Triac_Parameter_Define
* Description : Silicon Controlled Rectifier Control Parameter Initialization
* Input : Thyristor control pointer Temperature control pointer
* Output : None
* Return : None
******************************************************************************/
void Triac_Parameter_Define(TRIAC_ctl_Type *TriacM,Temperature_ctl_Type *TempM)
{
TriacM->PeriodCtl.NumData=NUM50HZ_DATA;
TriacM->PeriodCtl.Period = (uint16_t)(TRIAC_TIME/TRIAC_CONTOROL_PERIOD);
TriacM->PeriodCtl.HalfPeriod = (TriacM->PeriodCtl.Period -1)/2;
TriacM->PeriodCtl.Serial_Nummax=0;
TriacM->PeriodCtl.Serial_Nummin=0;
TriacM->PeriodCtl.Serial_Num=0;
TriacM->PeriodCtl.Duty_TS=0;
TriacM->PeriodCtl.Dutymax_T1S1=DUTYMAX_T1S1;
TriacM->PeriodCtl.Dutymin_T1S1=DUTYMIN_T1S1;
TriacM->PeriodCtl.Dutydefault_T1S1=DUTYDEFAULT_T1S1;
TriacM->PeriodCtl.Dutymax_T2S1=DUTYMAX_T2S1;
TriacM->PeriodCtl.Dutymin_T2S1=DUTYMIN_T2S1;
TriacM->PeriodCtl.Dutydefault_T2S1=DUTYDEFAULT_T2S1;
TriacM->PeriodCtl.Dutymax_T3S1=DUTYMAX_T3S1;
TriacM->PeriodCtl.Dutymin_T3S1=DUTYMIN_T3S1;
TriacM->PeriodCtl.Dutydefault_T3S1=DUTYDEFAULT_T3S1;
TriacM->PeriodCtl.Dutymax_T1S2=DUTYMAX_T1S2;
TriacM->PeriodCtl.Dutymin_T1S2=DUTYMIN_T1S2;
TriacM->PeriodCtl.Dutydefault_T1S2=DUTYDEFAULT_T1S2;
TriacM->PeriodCtl.Dutymax_T2S2=DUTYMAX_T2S2;
TriacM->PeriodCtl.Dutymin_T2S2=DUTYMIN_T2S2;
TriacM->PeriodCtl.Dutydefault_T2S2=DUTYDEFAULT_T2S2;
TriacM->PeriodCtl.Dutymax_T3S2=DUTYMAX_T3S2;
TriacM->PeriodCtl.Dutymin_T3S2=DUTYMIN_T3S2;
TriacM->PeriodCtl.Dutydefault_T3S2=DUTYDEFAULT_T3S2;
TriacM->PeriodCtl.Dutymax_T1S3=DUTYMAX_T1S3;
TriacM->PeriodCtl.Dutymin_T1S3=DUTYMIN_T1S3;
TriacM->PeriodCtl.Dutydefault_T1S3=DUTYDEFAULT_T1S3;
TriacM->PeriodCtl.Dutymax_T2S3=DUTYMAX_T2S3;
TriacM->PeriodCtl.Dutymin_T2S3=DUTYMIN_T2S3;
TriacM->PeriodCtl.Dutydefault_T2S3=DUTYDEFAULT_T2S3;
TriacM->PeriodCtl.Dutymax_T3S3=DUTYMAX_T3S3;
TriacM->PeriodCtl.Dutymin_T3S3=DUTYMIN_T3S3;
TriacM->PeriodCtl.Dutydefault_T3S3=DUTYDEFAULT_T3S3;
#ifdef ZEROCROSSOVER_OC
TriacM->Zero.Zcrossset=(uint16_t)OC_ZEROCROSS_VERYTIME;//光耦过零
#else
TriacM->Zero.Zcrossset=(uint16_t)TR_ZEROCROSS_VERYTIME;//三极管过零
#endif
TriacM->Zero.Zcrosslostset=(uint16_t)(ZEROCROSSLOST_VERYTIME*ZEROCROSSLOST_VERYFREQ);
TriacM->Zero.SecondZcrossSet=(uint16_t)(ZEROCROSSLOST_VERYFREQ/ZEROCROSS_FREQ);
TriacM->Zero.ZcrossDelayTrigset=(uint16_t)(TRIAC_TIME_TO_TRIGGER*SPEED_LOOP_CAL_FREQ);
TriacM->TonEnable_cntset=(uint16_t)(TRIAC_ENABLEWAIT*TIMER_FREQ_SPEED_LOOP);
TempM->TempRatedADCInv=_IQ(1.0)/65536;
TempM->TempAverSizeInv1 = _IQ(1.0)/TEMP_AVER_SIZE;
TempM->TempAverSizeInv2 = _IQ(1.0) - TempM->TempAverSizeInv1;
}
/******************************************************************************
* Function Name : ZeroCross_Status_Ini
* Description : Silicon-controlled rectifier start-up state initialization
* Input : SCR control structure Temperature control structure
* Output : None
* Return : None
******************************************************************************/
void Triac_Status_Init(TRIAC_ctl_Type *TriacM,Temperature_ctl_Type *TempM)
{
TriacM->Zero.Zcrosscnt = 0;
TriacM->Zero.ZcrossEvent=0;
TriacM->Zero.Zcrosslostcnt=0;
TriacM->Zero.Zcrosslost=FALSE;
TriacM->Zero.Zcrosseffective = FALSE;
TriacM->Zero.ZcrossDelayTrigcnt=0;
TriacM->Zero.Zcrosseffectivecnt=0;
TriacM->Zero.SecondZcrossCnt = 0;
TriacM->Zero.Prestatus = 0;
TriacM->Zero.Aftstatus = 0;
TriacM->Zero.Risingseffective =FALSE;
TriacM->Zero.Inittatus =FALSE;
TriacM->Zero.SecondZsseffective=FALSE;
TriacM->TonEnable_cnt=0;
TriacM->TonEnable=0;
TriacM->ACVoltcaliMin=_IQ(1.0);
TriacM->ACVoltcali=_IQ(1.0);
TriacM->ACVoltcaliPrev=_IQ(1.0);
TriacM->ACVoltcali_Square=_IQ(1.0);
TriacM->PeriodCtl.Cnt=TriacM->PeriodCtl.Period;
TriacM->PeriodCtl.Serial_Num=0;
TriacM->PeriodCtl.DelayProcess_Flag=0;
TriacM->PeriodCtl.DutychangeFlag=FALSE;
}
/******************************************************************************
* Function Name : AC_Zerocross_Detect_OC
* Description : Optocoupler AC Input Zero-Crossing Detection
* Input : SCR control structure pointer
* Output : None
* Return : None
******************************************************************************/
void AC_Zerocross_Detect_OC(TRIAC_ctl_Type *TriacM)
{
if(TriacM->Zero.Zcrosseffective == FALSE)
{
if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_3) == 1)
TriacM->Zero.Zcrosscnt++;
else
TriacM->Zero.Zcrosscnt = 0;
if(TriacM->Zero.Zcrosscnt >= TriacM->Zero.Zcrossset)
{
TriacM->Zero.Zcrosseffective = TRUE;
TriacM->Zero.Zcrosscnt=0;
TriacM->Zero.ZcrossEvent=1;
TriacM->Zero.Zcrosslostcnt=0;
TriacM->Zero.Zcrosslost=FALSE;
TriacM->PhaseCtl.Toncnt=0;
TriacM->PhaseCtl.TonStatus=FALSE;
TriacM->PhaseCtl.TonEvent=1;
TriacM->ACVoltcali=TriacM->ACVoltcaliMin;
TriacM->ACVoltcaliMin=ADC_M.DCVoltcali;
}
}
else if((TriacM->Zero.Zcrosseffective == TRUE)&&( TriacM->Zero.ZcrossEvent==0))
{
if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_3) == 0)
TriacM->Zero.Zcrosscnt++;
else
TriacM->Zero.Zcrosscnt = 0;
if(TriacM->Zero.Zcrosscnt >= TriacM->Zero.Zcrossset)
{
TriacM->Zero.Zcrosseffective = FALSE;
TriacM->Zero.Zcrosscnt=0;
}
}
TriacM->Zero.Zcrosslostcnt++;
if(TriacM->Zero.Zcrosslostcnt >= TriacM->Zero.Zcrosslostset)
{
TriacM->Zero.Zcrosslost=TRUE;
TriacM->Zero.Zcrosslostcnt=0;
}
}
/******************************************************************************
* Function Name : AC_Zerocross_Detect_TR
* Description : Transistor AC Input Zero-Crossing Detection
* Input : SCR control structure pointer
* Output : None
* Return : None
******************************************************************************/
void AC_Zerocross_Detect_TR(TRIAC_ctl_Type *TriacM)
{
if(TriacM->Zero.Zcrosseffective == FALSE)
{
if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_3) == 0)
TriacM->Zero.Zcrosscnt++;
else
TriacM->Zero.Zcrosscnt = 0;
if(TriacM->Zero.Zcrosscnt >= TriacM->Zero.Zcrossset)
{
TriacM->Zero.Zcrosseffective = TRUE;
TriacM->Zero.Zcrosscnt=0;
TriacM->Zero.ZcrossEvent=1;
TriacM->Zero.Zcrosslostcnt=0;
TriacM->Zero.Zcrosslost=FALSE;
TriacM->PhaseCtl.Toncnt=0;
TriacM->PhaseCtl.TonStatus=FALSE;
TriacM->PhaseCtl.TonEvent=1;
TriacM->ACVoltcali=TriacM->ACVoltcaliMin;
TriacM->ACVoltcaliMin=ADC_M.DCVoltcali;
}
}
else if((TriacM->Zero.Zcrosseffective == TRUE)&&( TriacM->Zero.ZcrossEvent==0))
{
if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_3) == 1)
TriacM->Zero.Zcrosscnt++;
else
TriacM->Zero.Zcrosscnt = 0;
if(TriacM->Zero.Zcrosscnt >= TriacM->Zero.Zcrossset)
{
TriacM->Zero.Zcrosseffective = FALSE;
TriacM->Zero.Zcrosscnt=0;
}
}
TriacM->Zero.Zcrosslostcnt++;
if(TriacM->Zero.Zcrosslostcnt >= TriacM->Zero.Zcrosslostset)
{
TriacM->Zero.Zcrosslost=TRUE;
TriacM->Zero.Zcrosslostcnt=0;
}
}
/******************************************************************************
* Function Name : TriacZero50HZ_Control_Process
* Description : Thyristor Period Control Processing
* Input : Silicon-controlled rectifier control pointer Temperature gear Temperature control pointer
* Output : None
* Return : None
******************************************************************************/
u_int32_t Triac50hz_Data[30]={0X80100100,0X80804040,0X81020810,0X82084108,0X84422110,0X88888888,0X89122448,0X92249224,\
0XA4924924,0X94949494,0XA4A5294A,0XA92A552A,0XA92B552A,0XAAAAAAAA,0XD5556AAA,0XD5AAD5AA,\
0XB5AD6B5A,0XD6D6D6D6,0XB6DB6DB6,0XDBB6DBB6,0XEDDBB76E,0XEEEEEEEE,0XF77BBDDE,0XF7DEF7DE,\
0XF7DFF7DE,0XFFDFF7DE,0XFFDFFFDE,0XFFFEFFFE,0XFFFFFFFE,0XFFFFFFFF};//占空比9.09%~96.9696%
void TriacZero_50HZControl_Process(Temperature_ctl_Type *TempM,Key_Manager_Type *KeyM,TRIAC_ctl_Type *TriacM,Speedrampctr_Type *Speed_Ramp)
{
_iq24 ACVoltcali;
u32 data=0;
if((TriacM->TonEnable==1)&&(KeyM->Tkey_rank>0)&&( TriacM->Zero.Zcrosslost == FALSE)&&(KeyM->TCkeycold==FALSE)&&\
(TempM->NTCOverStatus==FALSE)&&(TempM->NTCOpenStatus==FALSE)&&\
(RunningStatus_M==RUN)&&(KeyM->Skeystop==FALSE)&&(Operation_M.Faultstop == FALSE))
{
TriacM->PeriodCtl.Cnt++;
if(TriacM->PeriodCtl.Cnt>TriacM->PeriodCtl.Period)
{
TriacM->PeriodCtl.Cnt=1;
if(TriacM->PeriodCtl.DutychangeFlag==TRUE)
{
Temp_Set(KeyM,&SpeedRamp_M,TriacM);
TriacM->PeriodCtl.DutychangeFlag=FALSE;
}
//ACVoltcali= TriacM->ACVoltcali;
ACVoltcali=ADC_M.DCVoltcali;
TriacM->ACVoltcali_Square= _IQmpy(ACVoltcali, ACVoltcali);
TriacM->PeriodCtl.Serial_Num=(u_int8_t)((TriacM->PeriodCtl.Duty_TS*TriacM->ACVoltcali_Square)>>24)-TriacM->PeriodCtl.NumData;
// TriacM->PeriodCtl.Serial_Num=(u_int8_t)(TriacM->PeriodCtl.Duty_TS-TriacM->PeriodCtl.NumData);
if(TriacM->PeriodCtl.Serial_Num>=TriacM->PeriodCtl.Serial_Nummax)
TriacM->PeriodCtl.Serial_Num=TriacM->PeriodCtl.Serial_Nummax;
else if(TriacM->PeriodCtl.Serial_Num<=TriacM->PeriodCtl.Serial_Nummin)
TriacM->PeriodCtl.Serial_Num=TriacM->PeriodCtl.Serial_Nummin;
}
data=Triac50hz_Data[TriacM->PeriodCtl.Serial_Num];
if(TriacM->PeriodCtl.Cnt<TriacM->PeriodCtl.Period)
{
data<<=(TriacM->PeriodCtl.Cnt-1);
if(data&0x80000000)
TRIAC_ON();
else
TRIAC_OFF();
}
else
{
TRIAC_ON();
//TRIAC_OFF();
}
}
else
{
TriacM->PeriodCtl.Cnt=TriacM->PeriodCtl.Period;
TRIAC_OFF();
}
}
u_int32_t Triac100hz_Data1[58]={0X80100100,0X80200802,0X81010100,0X81010402,0X84104080,0X84104104,0X84081041,0X88422081,\
0X21084211,0X22222211,0X11111111,0X22248891,0X88912484,0X92222248,0X89224928,0X92492492,\
0X92492492,0XA9292492,0XA9292492,0XAA924952,0XAA924952,0XA9294AA9,0XAA4954AA,0XAA4AAAAA,\
0XAA4AAAAA,0XAAAAAAAA,0XAAAAAAAA,0X66D55555,0X66D55555,0X66D6D666,0X66D6D666,0X76D6D666,\
0X76D6D666,0X76DB7666,0X76DB7666,0X76DB7766,0X76DB7766,0X776B7767,0X776B7767,0X776B7777,\
0X776B7777,0X77777777,0X77777777,0XF77BDEEE,0XF77BDEEE,0X777F7F77,0X777F7F77,0X777F7F7F,\
0XF77F7F7E,0XF77F7F7F,0XF7FEFEFE,0XF7FFFEFE,0XF7FFFEFE,0XF7FFFEFF,0XFFFEFFFE,0XFFFFFFFE,\
0XFFFFFFFE,0XFFFFFFFF};
/* 6 ~ 13
* 14 ~ 21
* 22 ~ 29
* 30 ~ 37
* 38 ~ 45
* 46 ~ 53
* 54 ~ 61
* 62 ~63
*/
u_int32_t Triac100hz_Data2[58]={0X80100100,0X00804040,0X81010100,0X08041008,0X84104080,0X10404210,0X11041110,0X11041110,\
0X10884442,0X10884442,0X11111111,0X11111111,0X88912444,0X92249224,0X89224928,0X49224928,\
0X92492492,0X92492492,0XA9292492,0XA9292492,0XAA924952,0X29294AAA,0XAA4954AA,0XAA4954AA,\
0XAA4AAAAA,0XAA4AAAAA,0XAAAAAAAA,0X55555555,0X66D55555,0X66D55555,0X66D6D666,0X66D6D666,\
0X76D6D666,0X76D6D666,0X76DB7666,0X76DB7666,0X76DB7766,0X776B5577,0X776B7767,0X776B7767,\
0X776B7777,0X776B7777,0X77777777,0XF777776E,0XF77BDEEE,0X777FDEEE,0X777F7F77,0X777F7F77,\
0XF77F7F7E,0XF77F7F7E,0XF7FEFEFE,0XF7FEFEFE,0XF7FFFEFE,0XF7FFFEFE,0XFFFEFFFE,0XFFFEFFFE,\
0XFFFFFFFE,0XFFFFFFFE};
/******************************************************************************
* Function Name : TriacZero50HZ_Control_Process
* Description : Thyristor Period Control Processing
* Input : Silicon-controlled rectifier control pointer Temperature gear Temperature control pointer
* Output : None
* Return : None
******************************************************************************/
void TriacZero_100HZControl_Process(Temperature_ctl_Type *TempM,Key_Manager_Type *KeyM,TRIAC_ctl_Type *TriacM,Speedrampctr_Type *Speed_Ramp)
{
u32 data=0;
u32 Data1;
u32 Data2;
_iq24 ACVoltcali;
if((TriacM->TonEnable==1)&&(KeyM->Tkey_rank>0)&&( TriacM->Zero.Zcrosslost == FALSE)&&(KeyM->TCkeycold==FALSE)&&\
(TempM->NTCOverStatus==FALSE)&&(TempM->NTCOpenStatus==FALSE)&&\
(RunningStatus_M==RUN)&&(KeyM->Skeystop==FALSE)&&(Operation_M.Faultstop == FALSE))
{
TriacM->PeriodCtl.Cnt++;
if(TriacM->PeriodCtl.Cnt>TriacM->PeriodCtl.Period)//
{
TriacM->PeriodCtl.Cnt=1;
if(TriacM->PeriodCtl.DutychangeFlag==TRUE)
{
Temp_Set(KeyM,&SpeedRamp_M,TriacM);
TriacM->PeriodCtl.DutychangeFlag=FALSE;
}
//根据母线电压峰值矫正占空比
ACVoltcali=ADC_M.DCVoltcali;
TriacM->ACVoltcali_Square= _IQmpy(ACVoltcali, ACVoltcali);
TriacM->PeriodCtl.Serial_Num=(u_int8_t)((TriacM->PeriodCtl.Duty_TS*TriacM->ACVoltcali_Square)>>24)-TriacM->PeriodCtl.NumData;
//TriacM->PeriodCtl.Serial_Num=(u_int8_t)(TriacM->PeriodCtl.Duty_TS-TriacM->PeriodCtl.NumData);
if(TriacM->PeriodCtl.Serial_Num>=TriacM->PeriodCtl.Serial_Nummax)
TriacM->PeriodCtl.Serial_Num=TriacM->PeriodCtl.Serial_Nummax;
else if(TriacM->PeriodCtl.Serial_Num<=TriacM->PeriodCtl.Serial_Nummin)
TriacM->PeriodCtl.Serial_Num=TriacM->PeriodCtl.Serial_Nummin;
}
Data1=Triac100hz_Data1[TriacM->PeriodCtl.Serial_Num];
Data2=Triac100hz_Data2[TriacM->PeriodCtl.Serial_Num];
if(TriacM->PeriodCtl.Cnt<=TriacM->PeriodCtl.HalfPeriod)
{
data=Data1;
data<<=(TriacM->PeriodCtl.Cnt-1);
if(data&0x80000000)
TRIAC_ON();
else
TRIAC_OFF();
}
else if((TriacM->PeriodCtl.Cnt>TriacM->PeriodCtl.HalfPeriod)&&(TriacM->PeriodCtl.Cnt<TriacM->PeriodCtl.Period))//Triac100hz_Data2 1~32 发波
{
data=Data2;
data<<=(TriacM->PeriodCtl.Cnt-1-TriacM->PeriodCtl.HalfPeriod);
if(data&0x80000000)
TRIAC_ON();
else
TRIAC_OFF();
}
else
{
TRIAC_OFF();
}
}
else
{
TriacM->PeriodCtl.Cnt=TriacM->PeriodCtl.Period;
TRIAC_OFF();
}
}
/******************************************************************************
* Function Name : TempInit_Measure
* Description : NTC Temperature Reading
* Input : Temperature Control Body Pointer ADC
* Output : None
* Return : None
******************************************************************************/
void TempInit_Measure(Temperature_ctl_Type *TempM,ADC_TypeDef *ADCx)
{
u8 i;
ADC_ClearFlag(ADCx, ADC_FLAG_JEOC);
ADC_SoftwareStartConvCmd(ADCx, ENABLE);
for(i=0; i <TEMP_AVER_SIZE; i++)
{
while(!ADC_GetFlagStatus(ADCx,ADC_FLAG_EOC));
TempM->TempPres += ((_iq24)((u16)ADCx->RDATAR*(TempM->TempRatedADCInv))>>3);
ADC_ClearFlag(ADCx, ADC_FLAG_JEOC);
ADC_SoftwareStartConvCmd(ADCx,ENABLE);
}
}
@@ -0,0 +1,28 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : M5_Waveform_Configure.c
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include "M0_Control_Library.h"
/******************************************************************************
* Function Name : Waveform_Display
* Description : Waveform Display Variable Settings
* Input : None
* Return : None
******************************************************************************/
void Waveform_Display (void)
{
sendUsbData.sendDataBuf[sendUsbData.head+0] = (uint16_t)(SVPWM_Cal_M.VoltLimMark*1000);
sendUsbData.sendDataBuf[sendUsbData.head+1] = (uint16_t)(MLBG_M.Cal_Struc.Angspeed_Aver2>>10);
sendUsbData.sendDataBuf[sendUsbData.head+2] = (uint16_t)(ADC_M.DCVoltAver>>10);
sendUsbData.sendDataBuf[sendUsbData.head+3] = (uint16_t)(MStruc_M.CRef2R.cq>>10);
sendUsbData.head += MaxUsbDataLen;
}
@@ -0,0 +1,114 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : M6_CurrentLoop.c
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description : ADC sampling result reading, current loop processing, FOC calculation, overcurrent phaseloss protection processing
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include "M0_Control_Library.h"
void ADC1_2_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
extern void FOC_Cal(Motor_Sructure_Type *MStruc,SVPWM_1R_Type *SVPWM_Cal,Motor_PID_Type *Mpid,\
ADCStruc_Type *ADCStruc,Motor_LBG_Type *MLBG,PWMCali_Type *PWMCali);
uint8_t ADC_1Rsample_Counter_test = 0;
uint8_t Observer_countertest = 0;
/******************************************************************************
* Function Name : ADC1_2_IRQHandler
* Description : ADC1&2 Interrupt response function, read current conversion results
* Input : None
* Output : None
* Return : None
******************************************************************************/
void ADC1_2_IRQHandler(void)
{
// ADC_1Rsample_Counter_test++;
if((ADC1->STATR & ADC_FLAG_JEOC) == ADC_FLAG_JEOC)
{
ADC_M.ADC_Result.Value1= (ADC1->IDATAR1)<<1;
ADC1->STATR = ~(uint32_t)ADC_FLAG_JEOC;
}
if((ADC2->STATR & ADC_FLAG_JEOC) == ADC_FLAG_JEOC)
{
// GPIO_SetBits(GPIOB, GPIO_Pin_8);
ADC_M.ADC_Result.Value2= (ADC2->IDATAR1)<<1;
if(SpeedRamp_M.Break == TRUE)
SVPWM_Lowside_Effective(&SVPWM_Cal_M);
else
{
switch(RunningStatus_M)
{
case POSITION:
HFVQI_PosiSearch_Process(&HFVQI_StartStruc_M,&SVPWM_Cal_M,\
&PWMCali_M,&ADC_M,&InjStart_M,SpeedRamp_M.Direction);
if(HFVQI_StartStruc_M.Finish == TRUE)
{
RunningStatus_M = START;
InjStart_M.Status = RAMP;
}
break;
case START:
Injstart_Process_M(&InjStart_M,&MStruc_M,&MLBG_M);
if (LBG_Status_M.Convergence == TRUE)
{
Controlloop_Initial(&InjStart_M, MLBG_M.Cal_Struc.Angspeed_Aver1,&MStruc_M,&Mpid_M,&SpeedRamp_M);
Time_Delay_Set(Triac_ctl.TonEnable_cntset,&Triac_ctl.TonEnable_cnt);
RunningStatus_M = RUN;
}
FOC_Cal(&MStruc_M,&SVPWM_Cal_M,&Mpid_M,&ADC_M,&MLBG_M,&PWMCali_M);
break;
case RUN:
FOC_Cal(&MStruc_M,&SVPWM_Cal_M,&Mpid_M,&ADC_M,&MLBG_M,&PWMCali_M);
if(Triac_ctl.TonEnable==0)
{
if(Time_Delay_Elapse(Triac_ctl.TonEnable_cnt) == TRUE)
Triac_ctl.TonEnable=1;
}
#ifdef ZEROCROSSOVER_OC
AC_Zerocross_Detect_OC(&Triac_ctl);
#else
AC_Zerocross_Detect_TR(&Triac_ctl);
#endif
break;
default:
break;
}
if ( ((RunningStatus_M==START)||(RunningStatus_M==RUN))&&(Powerctr_M.Poweron == TRUE) )
{
if(Phaseloss_Verify(&(MStruc_M.C3S),&Phaseloss_M ,SVPWM_Cal_M.sector))
Protection_SetFault(PHASELOSS_FALUT);
}
}
ADC_Trigger_Update(&PWMCali_M);
SVPWM_Updateup(&SVPWM_Cal_M, &PWMCali_M);
if ((RunningStatus_M==START)||(RunningStatus_M==RUN))
{
if(Phase_Ins_OverCurrent_Verify(&(MStruc_M.C3S),&InstPhaseOC_M) == TRUE)
Protection_SetFault(MOTOR_OVER_CURR_SOFT_M);
}
Break_Verify(&Powerctr_M,&SpeedRamp_M,&RunningStatus_M,&ADC_M);
ADC_SoftwareStartConvCmd(ADC2, ENABLE);
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
ADC2->STATR = ~(uint32_t)ADC_FLAG_JEOC;
// GPIO_ResetBits(GPIOB, GPIO_Pin_8);
}
}
@@ -0,0 +1,20 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : M6_CurrentLoop.h
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description : current loop processing
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __M6_CURRENTLOOP_H
#define __M6_CURRENTLOOP_H
extern uint8_t ADC_1Rsample_Counter_test;
extern uint8_t Observer_countertest;
#endif
@@ -0,0 +1,157 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : M6_SpeedLoop.c
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description : Speed loop processing, related protection treatment, power up and down control processing
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include "M0_Control_Library.h"
void SysTick_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
static uint8_t Speed_Sample_PID_CNT = SPEED_SAMPLE_PID_PERIOD;
/******************************************************************************
* Function Name : SysTick_Handler
* Description : Speed loop processing interrupt
* Input : None
* Output : None
* Return : None
******************************************************************************/
void SysTick_Handler(void)
{
Speed_Sample_PID_CNT --;
Time_Delay_Process();
Led_Operation(&LED_M);
Poweroperation_Process(&SpeedRamp_M,&ADC_M,&Powerctr_M,&RunningStatus_M,&(Mpid_M.Speed),\
MLBG_M.Cal_Struc.Angspeed_Aver2);
NTCSample(&Tempctl_M,ADC1);
Coldkeycheck(&Key_M);
Tempkeycheck(&Key_M);
ACKEY_CHECK(&Key_M);
if(RunningStatus_M == IDLE)
PSC_Process(&Operation_M);
if((Operation_M.PSC.Mark == FALSE)&&(Operation_M.PSC.Process ==TRUE))
Speedkeycheck_Recover(&Key_M,&SpeedRamp_M);
Event_1ms_Process(&Emanager_M);
ACZerocross_Process(&Tempctl_M,&Key_M,&Triac_ctl);
if (Speed_Sample_PID_CNT == 0 )
{
Speed_Sample_PID_CNT = SPEED_SAMPLE_PID_PERIOD;
Buffer_Update(&(LBG_SpeedBuffer_M[0]), &(MLBG_M.SpeedBuffPara), MLBG_M.Cal_Struc.Angspeed_Inst);
MLBG_M.Cal_Struc.Angspeed_Aver1 = LPF_1st_Process(&(MLBG_M.Cal_Struc.SpeedLPF1st_M),\
MLBG_M.Cal_Struc.Angspeed_Inst);
LBG_Status_M.Reliable = Speed_Reliable_Verify(&(MLBG_M.SpeedBuffPara),&LBG_SpeedBuffer_M[0],\
MLBG_M.Cal_Struc.Angspeed_Aver1,LBG_Status_M.VarianceThresh);
switch(RunningStatus_M)
{
case START:
if(_IQabs(InjStart_M.RampInjSpeedTarget)<_IQ(0.2))
LBG_Status_M.Reliable = TRUE;
Speed_Converged_Verify1(InjStart_M.RampInjSpeedRef, &MLBG_M, &LBG_Status_M);
break;
case RUN:
if(SpeedRamp_M.Break == FALSE)
{
if((Key_M.Skeystop == FALSE)&&(Operation_M.Faultstop == FALSE)&&(Powerctr_M.Poweron == TRUE))
{
VDC_Limitspeed(&SpeedRamp_M,&ADC_M,&Powerctr_M);
}
if(Powerctr_M.Poweron == TRUE)
Speed_Ramp_Process(&SpeedRamp_M);
else
Poweroff_Speed_Ramp_Process(&SpeedRamp_M);
if(STARTUP_DIRECTION==1)
SpeedRamp_M.Aftrampcom = SpeedRamp_M.Aftramp + Powercom_M.Speedcom;
else if(STARTUP_DIRECTION==-1)
SpeedRamp_M.Aftrampcom = SpeedRamp_M.Aftramp - Powercom_M.Speedcom;
Speed_Stable_Verify(&LBG_Status_M, MLBG_M.Cal_Struc.Angspeed_Aver1);
if(LBG_Status_M.Stable==FALSE)
Protection_SetFault(SPEED_ABNORMAL_M);
Motor_Stall_Verify1(SpeedRamp_M.Aftramp, &MLBG_M, MStruc_M.CRef2R.cq,&LBG_Status_M);
if(LBG_Status_M.Stall==TRUE)
Protection_SetFault(MOTOR_STALL_M);
MStruc_M.CRef2R.cq = PID_Calculaion_Delta (SpeedRamp_M.Aftrampcom, MLBG_M.Cal_Struc.Angspeed_Aver2, &(Mpid_M.Speed));
if((DCurrProcess_M.Stage == 1)&&(_IQabs(MStruc_M.CRef2R.cd) <= DCurrProcess_M.Target1))
Dcurr_Process_Init(&DCurrProcess_M,2);
MStruc_M.CRef2R.cd = Dcurr_Process(&DCurrProcess_M, MLBG_M.Cal_Struc.Angspeed_Aver1, MStruc_M.CRef2R.cd);
}
break;
default:
break;
}
}
DCOvervolt_Protection(ADC_M.DCVoltAver, &DCBusProtecion_M);
DCUndervolt_Protection1(ADC_M.DCVoltAver, &DCBusProtecion_M,&Powerctr_M);
NTC_Protection(&Tempctl_M,Tempctl_M.TempAver);
SysTick->SR &= ~(1 << 0);
}
/************************************************************************************************************
* Function Name : Systick_Init
* Description : Systick Init
* Input : NewState - ENABLE or DISABLE.
* Output : None
* Return : None
*************************************************************************************************************/
void Systick_Init(void)
{
SysTick->CTLR =0;
SysTick->CMP =0;
SysTick->SR &= ~(1 << 0);
SysTick->CNT = 0;
SysTick->CMP = TIMER_PERIDO_SYSTICK;
SysTick->CTLR |=(1 << 1)|(1 << 3)|(1 << 5);
}
/************************************************************************************************************
* Function Name : SYS_TIM_Cmd
* Description : SysTick Enable
* Input : NewState - ENABLE or DISABLE.
* Output : None
* Return : None
*************************************************************************************************************/
void SYS_TIM_Cmd(FunctionalState NewState)
{
if(NewState != DISABLE)
{
SysTick->CTLR |= TIM_CEN;
}
else
{
SysTick->CTLR &= (uint16_t)(~((uint16_t)TIM_CEN));
}
}
@@ -0,0 +1,32 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : M6_SpeedLoop.h
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description : The speed loop is defined by timer parameters and control counting parameters.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __M6_SPEEDLOOP_H
#define __M6_SPEEDLOOP_H
#define TIMER_CLOCK_FREQ_SPEED 144000000uL
#define TIMER_FREQ_SPEED_LOOP 2000
#define TIMER_PERIDO_SYSTICK TIMER_CLOCK_FREQ_SPEED / (u32)(TIMER_FREQ_SPEED_LOOP*8)
#define TIMER_PRESCALER_SPEED_LOOP 17
#define SPEED_LOOP_CAL_FREQ 2000
#define SPEED_LOOP_CAL_PERIOD _IQ(1.0)/SPEED_LOOP_CAL_FREQ
#define SPEED_SAMPLE_PID_PERIOD TIMER_FREQ_SPEED_LOOP/SPEED_LOOP_CAL_FREQ
#define LED_PERIOD 4
//void Timer4_Init(void);
void Systick_Init(void);
void SYS_TIM_Cmd(FunctionalState NewState);
#endif
@@ -0,0 +1,159 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : M7_Interrupt.c
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description : Interrupt configuration
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include "M0_Control_Library.h"
void TIM1_UP_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void TIM1_BRK_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void NMI_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void HardFault_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void Observer_Calibration(Motor_Sructure_Type *MStruc,SVPWM_1R_Type *SVPWM_Cal,Motor_PID_Type *Mpid,\
ADCStruc_Type *ADCStruc,Motor_LBG_Type *MLBG,PWMCali_Type *PWMCali);
uint8_t Timer1_Interrupt_Count_test = 0;
/******************************************************************************
* Function Name : Interrupt_Configuration
* Description : Interrupt Priority Configuration
* Input : None
* Output : None
* Return : None
******************************************************************************/
void Interrupt_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = ADC_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = TIM1_BRK_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_ClearITPendingBit(TIM1, TIM_IT_Break);
TIM_ITConfig(TIM1, TIM_IT_Break,ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = SysTicK_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/******************************************************************************
* Function Name : TIM1_UP_IRQHandler
* Description : Timer 1 overflow interrupt, processing waveform data output
* Input : None
* Output : None
* Return : None
******************************************************************************/
void TIM1_UP_IRQHandler(void)
{
if( RunningStatus_M ==PRESTART)
{
if(Time_Delay_Elapse(SpeedRamp_M.Precharge_cnt) == TRUE)
{
ADC_1R_Start(ENABLE);
RunningStatus_M = POSITION;
}
}
if((RunningStatus_M == POSITION)||(RunningStatus_M == START)||(RunningStatus_M == RUN))
SVPWM_Updatedown(&SVPWM_Cal_M, &PWMCali_M);
else
{
ADC_SoftwareStartConvCmd(ADC2, ENABLE);
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
DCBUS_Volt_Cal(&ADC_M,ADC2);
ADC_M.DCVoltcali= (_IQdiv(_IQ(1.0),ADC_M.DCVolt_Filter));
if(RunningStatus_M == RUN)
{
if ((ADC_M.DCVoltcali<Triac_ctl.ACVoltcaliPrev)&&(Triac_ctl.ACVoltcaliMin>ADC_M.DCVoltcali))
Triac_ctl.ACVoltcaliMin=ADC_M.DCVoltcali;
}
else
{
Triac_ctl.ACVoltcaliPrev= ADC_M.DCVoltcali;
Triac_ctl.ACVoltcaliMin=ADC_M.DCVoltcali;
}
#ifdef PHASEANGLE_CONTROL
Triac_Control_Process(&Triac_ctl);
#endif
if(SpeedRamp_M.Break == FALSE)
{
if((RunningStatus_M == START)||(RunningStatus_M == RUN))
{
Observer_Calibration(&MStruc_M,&SVPWM_Cal_M,&Mpid_M,&ADC_M,&MLBG_M,&PWMCali_M);
}
}
// Waveform_Display();
//GPIO_SetBits(GPIOD, GPIO_Pin_0);
Powercom_Process(&Powercom_M,&MStruc_M,&Powerctr_M,&SpeedRamp_M);
if(RunningStatus_M == RUN)
{
Triac_ctl.ACVoltcaliPrev= ADC_M.DCVoltcali;
PeakDCOvervolt_Protection(ADC_M.DCVolt_Filter,&DCBusProtecion_M);
}
TIM_ClearFlag(TIM1, TIM_FLAG_Update);
}
/******************************************************************************
* Function Name : TIM1_BRK_IRQHandler
* Description : Brake interruption, set fault
* Input : None
* Output : None
* Return : None
******************************************************************************/
void TIM1_BRK_IRQHandler(void)
{
Protection_SetFault(DC_OVER_CURR_HARD_M);
TIM_ClearITPendingBit(TIM1, TIM_IT_Break);
}
/*******************************************************************************
* Function Name : NMI_Handler
* Description : This function handles NMI exception.
* Input : None
* Return : None
*******************************************************************************/
void NMI_Handler(void)
{
}
/*******************************************************************************
* Function Name : HardFault_Handler
* Description : This function handles Hard Fault exception.
* Input : None
* Return : None
*******************************************************************************/
void HardFault_Handler(void)
{
while (1)
{
//NVIC_SystemReset();
}
}
@@ -0,0 +1,19 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : M7_Interrupt.h
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description : Interrupt configuration, waveform display
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __M7_INTERRUPT_H
#define __M7_INTERRUPT_H
extern uint8_t Timer1_Interrupt_Count_test;
void Interrupt_Configuration(void);//ÖжÏÕûÌåÅäÖÃ
#endif
@@ -0,0 +1,330 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : M8_Protection.c
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description : Protection parameter initialization, protection state setting
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include "M0_Control_Library.h"
InstPhaseOC_Type InstPhaseOC_M;
DCbusProtection_Type DCBusProtecion_M;
OverLoad_Type Overload_M;
LPF_First_Order_Type OverloadLPF1st_M;
Phaseloss_Type Phaseloss_M;
/******************************************************************************
* Function Name : Protection_and_Emergency_Parameter_Define
* Description : Fault protection parameter initialization
* Input : None
* Output : None
* Return : None
******************************************************************************/
void Protection_and_Emergency_Parameter_Define (void)
{
InstPhaseOC_M.Cnt = 0;
InstPhaseOC_M.CurrThreshold = INST_PHASEOC_THRE_M;
InstPhaseOC_M.CntThreshold = INST_PHASEOC_CNT_THRE_M;
DCBusProtecion_M.OverThresh = DCBUS_OVER_VOLT_THRE;
DCBusProtecion_M.UnderThresh = DCBUS_UNDER_VOLT_THRE;
DCBusProtecion_M.OverCntThresh = DCBUS_OVER_VOLT_CNT;
DCBusProtecion_M.UnderCntThresh = DCBUS_UNDER_VOLT_CNT;
DCBusProtecion_M.OverCnt = 0;
DCBusProtecion_M.UnderCnt = 0;
DCBusProtecion_M.Overvolt = FALSE;
DCBusProtecion_M.Undervolt = FALSE;
DCBusProtecion_M.PeakOverCnt=0;
DCBusProtecion_M.PeakOverCntThresh=PEAKDCBUS_OVER_VOLT_CNT;
DCBusProtecion_M.PeakOverDetectiontime=(u_int16_t)(PEAKDCBUS_OVER_VOLT_DETECTIONTIME*FREQ_SVPWM);
DCBusProtecion_M.PeakOverDetectiontCnt=0;
Overload_M.CurrThresh = OVERLOAD_CURR_THRE;
Overload_M.CalCoef = OVERLOAD_CAL_COEF;
Overload_M.CntThresh = (uint16_t)(OVERLOAD_TIME_THRE*OVERLOAD_CAL_FREQ);
Overload_M.Cnt = 0;
Overload_M.CurrCal = 0;
OverloadLPF1st_M.Input_Coef = _IQdiv(OVERLOADLPF_WcT_M,(OVERLOADLPF_WcT_M + UNIT_Q24));
OverloadLPF1st_M.Output_Coef = _IQdiv(UNIT_Q24,(OVERLOADLPF_WcT_M + UNIT_Q24));
Phaseloss_M.CurrThresh = PHASELOSS_CURR_THRE;
Phaseloss_M.CntThresh = (uint16_t)(PHASELOSS_TIME_THRE * PHASELOSS_CAL_FREQ);
Phaseloss_M.MultiphaseCnt = 0;
Phaseloss_M.SiglephaseCntA = 0;
Phaseloss_M.SiglephaseCntB = 0;
Phaseloss_M.SiglephaseCntC = 0;
Phaseloss_M.CurrBuffPara.Length = PHASELOSS_CAL_BUFFSIZE;
Phaseloss_M.CurrBuffPara.Inv1 = _IQ(1.0)/PHASELOSS_CAL_BUFFSIZE;
Phaseloss_M.CurrBuffPara.Inv2 = _IQ(1.0) - Phaseloss_M.CurrBuffPara.Inv1;
Tempctl_M.NTCOverThresh = NTC_OVERTEMP_RATEADC;
Tempctl_M.NTCOpenThresh = NTC_OPENTEMP_RATEADC;
Tempctl_M.NTCOverCntThresh = (uint16_t)(TEMP_OVER_TIME*NTC_VERIFY_FREQ);
Tempctl_M.NTCOpenCntThresh = (uint16_t)(NTC_OPEN_TIME*NTC_VERIFY_FREQ);
Tempctl_M.NTCOverCnt = 0;
Tempctl_M.NTCOpenCnt = 0;
Tempctl_M.NTCOpenStatus =FALSE;
Tempctl_M.NTCOverStatus =FALSE;
}
/******************************************************************************
* Function Name : Protection_and_Emergency_Init
* Description : Fault protection parameter initialization
* Input : None
* Output : None
* Return : None
******************************************************************************/
void Protection_and_Emergency_Init ()
{
InstPhaseOC_M.Cnt = 0;
DCBusProtecion_M.OverCnt = 0;
DCBusProtecion_M.UnderCnt = 0;
DCBusProtecion_M.Overvolt = FALSE;
DCBusProtecion_M.Undervolt = FALSE;
DCBusProtecion_M.PeakOverDetectiontCnt=0;
DCBusProtecion_M.PeakOverCnt=0;
Overload_M.Cnt = 0;
Overload_M.CurrCal = 0;
Phaseloss_M.MultiphaseCnt = 0;
Phaseloss_M.SiglephaseCntA = 0;
Phaseloss_M.SiglephaseCntB = 0;
Phaseloss_M.SiglephaseCntC = 0;
// Tempctl_M.NTCOverCnt = 0;
// Tempctl_M.NTCOpenCnt = 0;
// Tempctl_M.NTCOverHysteresisCnt = 0;
// Tempctl_M.NTCOverRecoverCnt = 0;
// Tempctl_M.NTCOpenStatus =FALSE;
// Tempctl_M.NTCOverStatus =FALSE;
// Tempctl_M.NTCOverHysStatus =FALSE;
Tempctl_M.NTCFlickerStatus =FALSE;
}
/******************************************************************************
* Function Name : Protection_SetFault
* Description : Fault Setting
* Input : Fault type
* Output : None
* Return : None
******************************************************************************/
void Protection_SetFault(uint16_t Fault_type)
{
Time_Delay_Set(Operation_M.FaultHoldingSet,&(Operation_M.FaultHoldingCnt));
TIM_CtrlPWMOutputs(TIM1, DISABLE);
TRIAC_OFF();
RunningStatus_M = FAULT;
System_Status_Global |= Fault_type;
}
/******************************************************************************
* Function Name : Protction_Fault_Reset_M
* Description : Fault Reset
* Input : None
* Output : None
* Return : None
******************************************************************************/
void Protction_Fault_Reset_M(void)
{
if (Time_Delay_Elapse(Operation_M.FaultHoldingCnt))
{
System_Status_Global &= ~STARTUP_FAILURE_M;
System_Status_Global &= ~SPEED_ABNORMAL_M;
LBG_Status_M.Unstable_CNT = 0;
System_Status_Global &= ~MOTOR_OVER_CURR_SOFT_M;
InstPhaseOC_M.Cnt = 0;
System_Status_Global &= ~MOTOR_OVERLOAD_M;
Overload_M.Cnt = 0;
if (GPIO_ReadInputDataBit(BRK_GPIO_M, BRK_PIN_M))
System_Status_Global &= ~DC_OVER_CURR_HARD_M;
System_Status_Global &= ~MOTOR_STALL_M;
LBG_Status_M.Stall_CNT = 0;
System_Status_Global &= ~PHASELOSS_FALUT;
LBG_Status_M.Stall_CNT = 0;
System_Status_Global &= ~NTC_OVER_ERR;
Tempctl_M.NTCOverCnt =0;
Tempctl_M.NTCOverStatus =FALSE;
System_Status_Global &= ~NTC_OPEN_ERR;
Tempctl_M.NTCOpenCnt =0;
Tempctl_M.NTCOpenStatus =FALSE;
if((System_Status_Global&DC_OVER_VOLT)==DC_OVER_VOLT)
{
if(ADC_M.DCVolt_Filter < DCBusProtecion_M.OverThresh)
{
System_Status_Global&= ~DC_OVER_VOLT;
DCBusProtecion_M.OverCnt = 0;
}
}
if((System_Status_Global&DC_OVER_VOLT)==DC_UNDER_VOLT)
{
if(ADC_M.DCVolt_Filter > DCBusProtecion_M.UnderThresh)
{
System_Status_Global&= ~DC_UNDER_VOLT;
DCBusProtecion_M.UnderCnt = 0;
}
}
}
if ( (System_Status_Global & (STARTUP_FAILURE_M |SPEED_ABNORMAL_M | MOTOR_OVER_CURR_SOFT_M | MOTOR_OVERLOAD_M\
| DC_OVER_CURR_HARD_M | MOTOR_STALL_M |PHASELOSS_FALUT|NTC_OVER_ERR|NTC_OPEN_ERR| DC_OVER_VOLT | DC_UNDER_VOLT)) == 0 )
{
RunningStatus_M = IDLE;
System_Status_Global |= FIRST_START_M;
}
}
/******************************************************************************
* Function Name : DCOvervolt_Protection
* Description : Bus Overvoltage Protection
* Input : Detect bus voltage, voltage protection structure pointer
* Output : None
* Return : None
******************************************************************************/
void DCOvervolt_Protection(_iq24 DCVolt, DCbusProtection_Type *DCbusProtec)
{
if (DCVolt >= DCbusProtec->OverThresh)
DCbusProtec->OverCnt++;
else
DCbusProtec->OverCnt = 0;
if(DCbusProtec->OverCnt > DCbusProtec->OverCntThresh)
{
DCBusProtecion_M.Overvolt = TRUE;
Protection_SetFault(DC_OVER_VOLT);//ĸÏß¹ýѹ
}
}
/******************************************************************************
* Function Name : PeakDCOvervolt_Protection
* Description : Peak bus overvoltage protection
* Input : Detect bus voltage, voltage protection structure pointer
* Output : None
* Return : None
******************************************************************************/
void PeakDCOvervolt_Protection(_iq24 DCVolt, DCbusProtection_Type *DCbusProtec)
{
DCbusProtec->PeakOverDetectiontCnt++;
if(DCbusProtec->PeakOverDetectiontCnt<DCbusProtec->PeakOverDetectiontime)
{
if (DCVolt >= DCbusProtec->OverThresh)
DCbusProtec->PeakOverCnt++;
if(DCbusProtec->PeakOverCnt > DCbusProtec->PeakOverCntThresh)
{
DCBusProtecion_M.Overvolt = TRUE;
Protection_SetFault(DC_OVER_VOLT);
}
}
else
{
DCbusProtec->PeakOverCnt=0;
DCbusProtec->PeakOverDetectiontCnt=0;
}
}
/******************************************************************************
* Function Name : DCUndervolt_Protection
* Description : Bus Undervoltage Protection
* Input : Detect bus voltage, voltage protection structure pointerv
* Output : None
* Return : None
******************************************************************************/
void DCUndervolt_Protection(_iq24 DCVolt, DCbusProtection_Type *DCbusProtec)
{
if (DCVolt <= DCbusProtec->UnderThresh)
DCbusProtec->UnderCnt++;
else
DCbusProtec->UnderCnt = 0;
if(DCbusProtec->UnderCnt > DCbusProtec->UnderCntThresh)
{
DCBusProtecion_M.Undervolt = TRUE;
Protection_SetFault(DC_UNDER_VOLT);
}
}
/******************************************************************************
* Function Name : DCUndervolt_Protection
* Description : Bus Undervoltage Protection
* Input : Detect bus voltage, voltage protection structure pointer
* Output : None
* Return : None
******************************************************************************/
void DCUndervolt_Protection1(_iq24 DCVolt, DCbusProtection_Type *DCbusProtec,Powercontrol_Type *PowerOper)
{
if (((DCVolt <= DCbusProtec->UnderThresh)||(PowerOper->Poweron==FALSE))&&(Key_M.ACkey_Poweron == TRUE))
{
if(DCbusProtec->UnderCnt<U16_MAX)
DCbusProtec->UnderCnt++;
}
else
DCbusProtec->UnderCnt = 0;
if(DCbusProtec->UnderCnt > DCbusProtec->UnderCntThresh)
{
Protection_SetFault(DC_UNDER_VOLT);
DCBusProtecion_M.Undervolt = TRUE;
}
}
/******************************************************************************
* Function Name : NTC_Protection
* Description : NTC Protection
* Input : Temperature control structure pointer
* Output : None
* Return : None
******************************************************************************/
void NTC_Protection(Temperature_ctl_Type *Temctl,_iq24 Temp)
{
if(Temp < Temctl->NTCOverThresh)
{
if(Temctl->NTCOverCnt<=U16_MAX)
Temctl->NTCOverCnt ++;
}
else
Temctl->NTCOverCnt =0;
if(Temctl->NTCOverCnt >= Temctl-> NTCOverCntThresh)
{
Temctl->NTCOverStatus = TRUE;
Protection_SetFault(NTC_OVER_ERR);
}
if(Temp > Temctl->NTCOpenThresh)
{
if(Temctl->NTCOpenCnt<=U16_MAX)
Temctl->NTCOpenCnt ++;
}
else
Temctl->NTCOpenCnt =0;
if(Temctl->NTCOpenCnt >= Temctl-> NTCOpenCntThresh)
{
Temctl->NTCOpenStatus = TRUE;
Protection_SetFault(NTC_OPEN_ERR);
}
}
@@ -0,0 +1,95 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : M8_Protection.h
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description : Protection parameter definition
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __M8_PROTECTION_H
#define __M8_PROTECTION_H
#define INST_PHASEOC_THRE_M _IQ(1.3)
#define INST_PHASEOC_CNT_THRE_M (uint16_t)5
#define DCBUS_OVER_VOLT_THRE _IQ(1.175)
#define DCBUS_UNDER_VOLT_THRE _IQ(0.72)
#define DCBUS_OVER_VOLT_CNT (uint16_t)500
#define DCBUS_UNDER_VOLT_CNT (uint16_t)3000
#define PEAKDCBUS_OVER_VOLT_CNT (uint16_t)1500
#define PEAKDCBUS_OVER_VOLT_DETECTIONTIME 0.3
#define NTC_OVERHYSTERESIS_TEMP_TIME 5
#define NTC_OVERTEMP_OHM _IQ18(0.8844)
#define NTC_OVERTEMP_RATEADC _IQ18toIQ(_IQ18div(NTC_OVERTEMP_OHM , NTC_OVERTEMP_OHM + PT_RS))
#define NTC_OPENTEMP_OHM _IQ18(981.5699)
#define NTC_OPENTEMP_RATEADC _IQ18toIQ(_IQ18div(NTC_OPENTEMP_OHM , NTC_OPENTEMP_OHM + PT_RS))
#define NTC_VERIFY_FREQ TIMER_FREQ_SPEED_LOOP
#define TEMP_OVER_TIME 0.1
#define NTC_OPEN_TIME 0.1
#define OVERLOAD_CURR_THRE _IQ(1.1)
#define OVERLOAD_TIME_THRE 0.5
#define OVERLOAD_CAL_FREQ TIMER_FREQ_SPEED_LOOP
#define OVERLOAD_CAL_COEF _IQ(1/1.91)
#define OVERLOADLPF_CF_M 500
#define OVERLOADLPF_WcT_M (PI_2_Q24/OVERLOAD_CAL_FREQ)*OVERLOADLPF_CF_M
#define PHASELOSS_CURR_THRE _IQ(0.1)
#define PHASELOSS_TIME_THRE 0.1
#define PHASELOSS_CAL_FREQ FREQ_SVPWM
#define PHASELOSS_CAL_BUFFSIZE 32
#define PHASELOSS_CNT_THRE 3
/* Exported variables -------------------------------------------------------*/
extern InstPhaseOC_Type InstPhaseOC_M;
extern DCbusProtection_Type DCBusProtecion_M;
extern OverLoad_Type Overload_M;
extern LPF_First_Order_Type OverloadLPF1st_M;
extern Phaseloss_Type Phaseloss_M;
/* Exported macro -----------------------------------------------------------*/
/* Exported functions -------------------------------------------------------*/
void Protection_and_Emergency_Parameter_Define (void);
void Protection_and_Emergency_Init (void);
void Protection_SetFault(uint16_t Fault_type);
void Protction_Fault_Reset_M(void);
Truth_Verify_Type Phase_Ins_OverCurrent_Verify (Component_3S_Type *PhaseABC, InstPhaseOC_Type * InstOC);
void DCOvervolt_Protection(_iq24 DCVolt, DCbusProtection_Type *DCbusProtec);
void DCUndervolt_Protection(_iq24 DCVolt, DCbusProtection_Type *DCbusProtec);
void DCUndervolt_Protection1(_iq24 DCVolt, DCbusProtection_Type *DCbusProtec,Powercontrol_Type *PowerOper);
void Speed_Outrange_Verify(_iq24 Speedref, _iq24 Speedact, Observer_Status_Type *Status);
Truth_Verify_Type Speed_Reliable_Verify(BuffPara_Type *Buffpara,_iq24 *Buffer,_iq24 Averspeed,_iq24 Threshold);
void Speed_Stable_Verify(Observer_Status_Type *Status,_iq24 Speedact);
void Motor_Stall_Verify1(_iq24 Speedref, Motor_LBG_Type *MLBG,_iq24 Iqref, Observer_Status_Type *Status);
void Motor_Stall_Verify2(_iq24 Speedref, _iq24 Speedact , _iq24 Iqref, Observer_Status_Type *Status);
void Motor_Reverse_Verify(_iq24 Speedref, _iq24 Speedact, Observer_Status_Type *Status);
void Speed_Converged_Verify1(_iq24 Speedref,Motor_LBG_Type *MLBG,Observer_Status_Type *Status);
void Speed_Converged_Verify2(_iq24 Speedref,_iq24 Speedact,Observer_Status_Type *Status);
Truth_Verify_Type OverLoad_Verify (Component_3S_Type *PhaseABC, OverLoad_Type * Overload, LPF_First_Order_Type * LPF);
Truth_Verify_Type Phaseloss_Verify (Component_3S_Type *PhaseABC,Phaseloss_Type *Phaseloss, uint8_t PWMsector);
void NTC_Protection(Temperature_ctl_Type *Temctl,_iq24 Temp);
void PeakDCOvervolt_Protection(_iq24 DCVolt, DCbusProtection_Type *DCbusProtec);
#endif
@@ -0,0 +1,110 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : M9_Appication_Blocks.h
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description : Standard application module declaration
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __M9_APPLICATION_BLOCKS_H
#define __M9_APPLICATION_BLOCKS_H
#define POWERCOM_FREQ_M FREQ_SVPWM
#define POWERCOM_PERIOD_M _IQ(1.0)/FREQ_SVPWM
#define POWERCOM_HPF1st_CF_M 10
#define POWERCOM_HPF1st_WcT_M _IQmpy(_IQmpyI32(POWERCOM_PERIOD_M,POWERCOM_HPF1st_CF_M),PI_2_Q24)
#define POWERCOM_LPF1st_CF_M 1000
#define POWERCOM_LPF1st_WcT_M _IQmpy(_IQmpyI32(POWERCOM_PERIOD_M,POWERCOM_LPF1st_CF_M),PI_2_Q24)
#define POWERCOM_STARTTIME_M 0.5
#define POWERCOM_SPEEDCLOSETIME_M 0.1
#define POWERCOM_SPEEDERRTHRE_M _IQ(0.01)
#define POWERCOM_VOLT_THRESHOLD_M _IQ(0.75)
#define POWERCOM_KP _IQ(0.5)
#define POWERCOM_KIT _IQ(0.0)//0.000001
#define POWERCOM_KD _IQ(0.0)
#define POWERCOM_KPADJ1_M _IQ(1.0)
#define POWERCOM_KPADJ2_M _IQ(1.0)
#define POWERCOM_KPADJ3_M _IQ(1.0)
#define POWERCOM_ULIM_M _IQ(0.012)
#define POWERCOM_LLIM_M _IQ(-0.012)
#define POWERCOM_DLIM_M _IQ(0.01)
/* Exported variables -------------------------------------------------------*/
extern Powercom_type Powercom_M;
/* Exported macro -----------------------------------------------------------*/
/* Exported functions--------------------------------------------------------*/
//PID¼ÆËã
_iq24 PID_Calculaion_Delta(_iq24 hReference, _iq24 hFeedback, PID_Structure_Type *PID_Struct);
_iq24 PID_Calculaion_Abs(_iq24 hReference, _iq24 hFeedback, PID_Structure_Type *PID_Struct);
Struct_Cossin_Type TrigonoMetric_Function(_iq24 Angle_PU);
Component_2S_Type Clark_TransForm(Component_3S_Type *Input3s);
Component_2R_Type Park_TransForm(Component_2S_Type *Input2s,Struct_Cossin_Type *Struct_Cossin);
Component_2S_Type Rev_Park_TransForm(Component_2R_Type *Input2r,Struct_Cossin_Type *Struct_Cossin);
Component_2R_Type ComponentLimit_2Ror2S(Component_2R_Type *Input,_iq24 Maxsquare,uint8_t *LimMark, _iq24 *Magtable);
_iq24 Round_Circle_Limitation_Rad(_iq24 Input);
_iq24 Round_Circle_Limitation_PU(_iq24 Input);
_iq24 LPF_1st_Process(LPF_First_Order_Type *LPF_1st, _iq24 input);
_iq24 BPF_2nd_Process(BPF_Second_Order_Type *BPF_2nd,_iq24 input);
_iq24 LPF_2nd_Process(LPF_Second_Order_Type *LPF_2nd, _iq24 input);
_iq24 HPF_1st_Process(HPF_First_Order_Type *HPF_1st, _iq24 input);
_iq24 HPF_2nd_Process(HPF_Second_Order_Type *HPF_2nd,_iq24 input);
void Observer_Adaptor_Process(Observer_Adaptor_type *Adaptor,_iq24 Alpha,_iq24 Beta,_iq24 Angspeed);
_iq24 Speedband_Avoid(_iq24 Speedinput,_iq24 Band,_iq24 Bandwidth);
void Dcurr_Process_Init(DCurrProcess_Type * DCurrProcess,uint8_t Stage);
_iq24 Dcurr_Process(DCurrProcess_Type * DCurrProcess, _iq24 Speedact,_iq24 DCurrRefact);
void Speed_Ramp_Process(Speedrampctr_Type *Speed_Ramp);
void Poweroff_Speed_Ramp_Process(Speedrampctr_Type *Speed_Ramp);
_iq24 AverValue_Cal(_iq24 Input,_iq24 Output, BuffPara_Type *Buffpara);
void Buffer_Clear(_iq24 *Buffer, BuffPara_Type *BuffPara);
void Buffer_Update(_iq24 *Buffer, BuffPara_Type *BuffPara,_iq24 Updatevalue);
void Buffer_Set(_iq24 *Buffer, BuffPara_Type *BuffPara,_iq24 Setvalue);
_iq24 Speed_PLL_Cal(Speed_PLL_Type *SpeedPLL, _iq24 Theta_Err);
void IF_Vibration_Com(Component_2R_Type *Volt, Component_2R_Type *Curr, InjStart_Type *InjStart);
_iq24 IQ24divider(_iq24 dividendin, _iq24 divisorin);
void Saturation(_iq24 *input,_iq24 Upper,_iq24 Lower);
void VDC_Limitspeed(Speedrampctr_Type *Speed_Ramp,ADCStruc_Type *ADCStruc,Powercontrol_Type *PowerOper);
void Break_Verify(Powercontrol_Type *PowerOper,Speedrampctr_Type *Speed_Ramp,\
Runningstatus_Type *Runningstatus,ADCStruc_Type *ADCStruc);
void Powercom_Prameter_Define(Powercom_type *Powercom);
void Powercom_Status_Init(Powercom_type *Powercom);
void Powercom_Process(Powercom_type *Powercom,Motor_Sructure_Type *MStruc,Powercontrol_Type *PowerOper,Speedrampctr_Type *Speed_Ramp);
#endif
@@ -0,0 +1,87 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : M9_Appication_Initl.c
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include "M0_Control_Library.h"
Powercom_type Powercom_M;
/*******************************************************************************
* Function Name : Powercom_Prameter_Define
* Description : Power Compensation Parameter Definition
* Input : Power Fluctuation Suppression Structure
* Output : None
* Return : None
*******************************************************************************/
void Powercom_Prameter_Define(Powercom_type *Powercom)
{
Powercom->Power_HPF1st.Input_Coef = _IQdiv(UNIT_Q24,(POWERCOM_HPF1st_WcT_M+UNIT_Q24));
Powercom->Power_HPF1st.Output_Coef = _IQdiv(UNIT_Q24,(POWERCOM_HPF1st_WcT_M+UNIT_Q24));
Powercom->Power_LPF1st.Input_Coef = _IQdiv(POWERCOM_LPF1st_WcT_M,(POWERCOM_LPF1st_WcT_M+UNIT_Q24));
Powercom->Power_LPF1st.Output_Coef = _IQdiv(UNIT_Q24,(POWERCOM_LPF1st_WcT_M+UNIT_Q24));
Powercom->Kpdefine = POWERCOM_KP;
Powercom->Kidefine = POWERCOM_KIT;
Powercom->Kddefine = POWERCOM_KD;
Powercom->Kpadj1 = POWERCOM_KPADJ1_M;
Powercom->Kpadj2 = POWERCOM_KPADJ2_M;
Powercom->Kpadj3 = POWERCOM_KPADJ3_M;
Powercom->Kpadj = Powercom->Kpadj1;
Powercom->PowerPID.Kp = _IQMPY_MACRO(Powercom->Kpdefine,Powercom->Kpadj);
Powercom->PowerPID.Ki = Powercom->Kidefine;
Powercom->PowerPID.Kd = Powercom->Kddefine;
Powercom->PowerPID.Upper_Lim = POWERCOM_ULIM_M;
Powercom->PowerPID.Lower_Lim = POWERCOM_LLIM_M;
Powercom->PowerPID.Deltalim = POWERCOM_DLIM_M;
Powercom->Startcom_cntset = POWERCOM_FREQ_M*POWERCOM_STARTTIME_M;
Powercom->Speedcolse_cntset = POWERCOM_FREQ_M*POWERCOM_SPEEDCLOSETIME_M;
Powercom->Speederrthre = POWERCOM_SPEEDERRTHRE_M;
Powercom->Voltthre = POWERCOM_VOLT_THRESHOLD_M;
}
/*******************************************************************************
* Function Name : Powercom_Status_Init
* Description : Power Compensation Parameter Initialization
* Input : Power Fluctuation Suppression Structure
* Output : None
* Return : None
*******************************************************************************/
void Powercom_Status_Init(Powercom_type *Powercom)
{
Powercom->Power_HPF1st.In_Pre = 0;
Powercom->Power_HPF1st.Out_Pre = 0;
Powercom->Power_HPF1st.Out_New = 0;
Powercom->Power_LPF1st.Out_Pre = 0;
Powercom->Power_LPF1st.Out_New = 0;
Powercom->PowerPID.Err_New = 0;
Powercom->PowerPID.Err_Prev1 = 0;
Powercom->PowerPID.Err_Prev2 = 0;
Powercom->PowerPID.Differential = 0;
Powercom->PowerPID.Deltaoutput = 0;
Powercom->PowerPID.Output_New = 0;
Powercom->PowerPID.Output_Prev = 0;
Powercom->PowerPID.Difference = 0;
Powercom->Speedcom =0;
Powercom->Power = _IQ(0.0);
Powercom->PowerfilterH = _IQ(0.0);
Powercom->PowerfilterL = _IQ(0.0);
Powercom->Startcom_cnt=0;
Powercom->Speedclose_cnt = 0;
}
@@ -0,0 +1,103 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : MA_HFVQI_Init.c
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include "M0_Control_Library.h"
HFVQI_Start_Type HFVQI_StartStruc_M;
BuffPara_Type HFVQIPosi_CBuffPara_M;
_iq24 HFVQIPosi_CBuff_M[HFVQI_POSI_SECTOR_M];
uint8_t HFVQI_Sectorbuf_M[HFVQI_SECTORBUFF];
/******************************************************************************/
/* Function Name : HFVQI_Parameter_Define
/* Description : HFVQI Parameter define
/* Input: None
/* Output : None
/* Return : None
/******************************************************************************/
void HFVQI_Parameter_Define (HFVQI_Start_Type *HFVQI_Start,SVPWM_1R_Type *SVPWM_Cal,PWMCali_Type *PWMCali)
{
HFVQI_Start->Vmag = HFVQI_POSI_VMAG_M;
HFVQI_Start->Vmagmax = _IQ16((SVPWM_Cal->HALF_T - PWMCali->ADCTimeMin -2)/2);
HFVQI_Start->Vmagmax = _IQ16div(HFVQI_Start->Vmagmax,SVPWM_Cal->coef2) <<8;
HFVQI_Start->Vmagmin = _IQ16div(_IQ16(PWMCali->ADCTimeMin + 2) , SVPWM_Cal->coef2) <<8;
HFVQI_Start->TimeStep = HFVQI_POSI_STEP_M;
HFVQI_Start->TimeEffect = HFVQI_POSI_PULSE_EFFECTIVE_M;
HFVQI_Start->AngleInit = _IQ(-1.0)/12;
HFVQI_Start->AngleStep = _IQ(1.0)/HFVQI_POSI_SECTOR_M;
HFVQI_Start->SectorSet = HFVQI_POSI_SECTOR_M;
HFVQI_Start->Posi_Cali = _IQ(1.0)/(HFVQI_POSI_SECTOR_M*2);
HFVQIPosi_CBuffPara_M.Length = HFVQI_POSI_SECTOR_M;
HFVQI_Start->Sectorbuff = HFVQI_SECTORBUFF;
HFVQI_Start->Cyclemax = HFVQI_CYCLE_MAX;
HFVQI_Start->Phaseloss_Currthre = PHASELOSS_CURR_THRE;
HFVQI_Start->Phaseloss_Cntthre = PHASELOSS_CNT_THRE;
}
/*******************************************************************************/
/* Function Name : HFVQI_PosiSearch_Status_Init_M
/* Description : HFVQI initial positioning state initialization
/* Input: None
/* Output : None
/* Return : None
/******************************************************************************/
void HFVQI_Status_Init_M (HFVQI_Start_Type *HFVQI_Start)
{
HFVQI_Start->Vpolar = _IQ(0.0);
HFVQI_Start->Counter = 0;
HFVQI_Start->Position = 0;
HFVQI_Start->SectorAct = 0;
HFVQI_Start->CurrMax = 0;
HFVQI_Start->SectorMax = 0;
HFVQI_Start->Finish = FALSE;
HFVQI_Start->AngleInit = _IQ(-1.0)/12;//¹Ì¶¨-30¡ã¿ªÊ¼
HFVQI_Start->Curr3S.PhaseA = 0;
HFVQI_Start->Curr3S.PhaseB = 0;
HFVQI_Start->Curr3S.PhaseC = 0;
HFVQI_Start->Curr2S.Alpha = 0;
HFVQI_Start->Curr2S.Beta = 0;
HFVQI_Start->Curr2R.cd = 0;
HFVQI_Start->Curr2R.cq = 0;
HFVQI_Start->VoltRef2R.cd = 0;
HFVQI_Start->VoltRef2R.cq = 0;
HFVQI_Start->VoltRef2RC.cd = 0;
HFVQI_Start->VoltRef2RC.cq = 0;
HFVQI_Start->VoltRef2SC.Alpha = 0;
HFVQI_Start->VoltRef2SC.Beta = 0;
HFVQI_Start->Verifytime =0;
HFVQI_Start->Cycletime =0;
HFVQI_Buffer_Clear();
HFVQI_Start->Phaseloss_Cnt = 0;
}
/*******************************************************************************/
/* Function Name : HFVQI_Buffer_Clear
/* Description : HFVQI Initial Positioning Sector Array Initialization
/* Input: None
/* Output : None
/* Return : None
/******************************************************************************/
void HFVQI_Buffer_Clear(void)
{
u_int8_t i;
for(i=0; i < HFVQI_SECTORBUFF; i++)
{
HFVQI_Sectorbuf_M[i]=0;
}
}
@@ -0,0 +1,50 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : MA_HFVQI_Parameter.h
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef _MA_HFVQI_OBSERVER_H
#define _MA_HFVQI_OBSERVER_H
#define HFVQI_POSI_VMAG_M _IQ(0.25)
#if defined TWELVE_SECTOR_POSITION
#define HFVQI_POSI_SECTOR_M 12
#endif
#if defined SIX_SECTOR_POSITION
#define HFVQI_POSI_SECTOR_M 6
#endif
#define HFVQI_POSI_STEP_M 10
#define HFVQI_POSI_PULSE_EFFECTIVE_M 3
#define HFVQI_SECTORBUFF 2
#define HFVQI_CYCLE_MAX 2
/* Exported variables -------------------------------------------------------*/
extern HFVQI_Start_Type HFVQI_StartStruc_M;
extern BuffPara_Type HFVQIPosi_CBuffPara_M;
extern _iq24 HFVQIPosi_CBuff_M[];
extern uint8_t HFVQI_Sectorbuf_M[];
//HFVQI Init
void HFVQI_Parameter_Define (HFVQI_Start_Type *HFVQI_Start,SVPWM_1R_Type *SVPWM_Cal,PWMCali_Type *PWMCali);
//HFVQI Init
void HFVQI_Status_Init_M (HFVQI_Start_Type *HFVQI_Start);
//HFVQI Init
void HFVQI_Buffer_Clear(void);
//HFVQI Init
void HFVQI_PosiSearch_Process(HFVQI_Start_Type *HFVQI_Start,SVPWM_1R_Type *SVPWM_Cal,\
PWMCali_Type *PWMCali,ADCStruc_Type *ADCStruc,InjStart_Type *Injstart, int8_t Direction);
#endif
@@ -0,0 +1,175 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : MB_Operation_Flash.c
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include "M0_Control_Library.h"
Flash_Operation_Type Flash_M;
/******************************************************************************
* Function Name : SysclkFreq_Change144_48
* Description : Switch system from 144M to 48M
* Input : None
* Output : None
* Return : None
******************************************************************************/
void SysclkFreq_Change144_48(void)
{
RCC->CFGR0&=~(0x3<<0);
RCC->CFGR0&=~(0x3<<2);
RCC->CFGR0|=(RCC_SW_HSI);
RCC->CTLR &=~ RCC_PLLON;
EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE;
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
/* PLL configuration: PLLCLK = HSI * 6 = 48 MHz */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL6);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
/******************************************************************************
* Function Name : SysclkFreq_Change144_48
* Description : Switch system from 48M to 144M
* Input : None
* Output : None
* Return : None
******************************************************************************/
void SysclkFreq_Change48_144(void)
{
RCC->CFGR0&=~(0x3<<0);
RCC->CFGR0&=~(0x3<<2);
RCC->CFGR0|=(RCC_SW_HSI);
RCC->CTLR &=~ RCC_PLLON;
EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE;
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
/* PLL configuration: PLLCLK = HSI * 18 = 144 MHz */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL18);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
/******************************************************************************
* Function Name : Flash_Operation_Init
* Description : Flash Init , Read the Flash value of the 4K Flash after erasing 64K
* Input : operate Flash struct point
* Output : None
* Return : None
******************************************************************************/
void Flash_Operation_Init(Flash_Operation_Type *FlashM)
{
uint32_t Address = 0x0;
FlashM->MemAddress=PAGE_WRITE_START_ADDR;
FlashM->FlashExcep=0;
FlashM->FLASHStatus=FLASH_COMPLETE;
FlashM->MemoryProgramStatus=PASSED;
SysclkFreq_Change144_48();
FLASH_Unlock();
Address = PAGE_WRITE_START_ADDR;
while((Address < (PAGE_WRITE_HALF_END_ADDR-2)) && (FlashM->MemoryProgramStatus != FAILED))
{
FlashM->FlashData[0]=(*(__IO uint16_t*) Address);
if( FlashM->FlashData[0]== 0xe339)
{
FlashM->MemoryProgramStatus=FAILED;
if(Address>PAGE_WRITE_START_ADDR)
{
FlashM->FlashData[0]=(*(__IO uint16_t*) (Address-2));
FlashM->FlashData[1]=(*(__IO uint16_t*) (Address-2+2048));
}
}
else
Address += 2;
}
FlashM->FLASHStatus= FLASH_ErasePage(PAGE_WRITE_START_ADDR);
if(FlashM->FLASHStatus != FLASH_COMPLETE)
{
FlashM->FlashExcep=1;
}
SysclkFreq_Change48_144();
FLASH_Lock();//
}
/******************************************************************************
* Function Name : Flash_ProgramHalfWord
* Description : Flash program Half word
* Input : operate Flash struct point/ address/ data
* Output : None
* Return : None
******************************************************************************/
void Flash_ProgramHalfWord(Flash_Operation_Type *FlashM ,uint32_t Address,uint16_t Data )
{
FLASH_Unlock();
FlashM->FLASHStatus = FLASH_ProgramHalfWord(Address, Data);
if(FlashM->FLASHStatus != FLASH_COMPLETE)
{
FlashM->FlashExcep = 1;
}
FLASH_Lock();
}
@@ -0,0 +1,24 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : MB_Operation_Flash.h
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include "M0_Control_Library.h"
#define PAGE_WRITE_START_ADDR ((uint32_t)0x08010000) /* Start from 64K */
#define PAGE_WRITE_HALF_END_ADDR ((uint32_t)0x08010800) /* End at 66K */
#define PAGE_WRITE_END_ADDR ((uint32_t)0x08011000) /* End at 68K */
#define FLASH_PAGE_SIZE 4096
extern Flash_Operation_Type Flash_M;
void Flash_Operation_Init(Flash_Operation_Type *FlashM);//²Ù×÷Flash³õʼ»¯
void Flash_ProgramHalfWord(Flash_Operation_Type *FlashM ,uint32_t Address,uint16_t Data );
@@ -0,0 +1,220 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : Motor_SPI_USART_MonitorData.c
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description :
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include "Motor_SPI_USART_MonitorData.h"
t_sendUsbData sendUsbData = {0,0,0,0,0,0,0};
const u_int8_t usbFrameByteNum[12] = {0, 32, 32, 28, 28, 24, 28, 32, 20, 22, 24, 26};
const u_int8_t needSendLen[12] = {0, USB_NEEDSEND_LEN1, USB_NEEDSEND_LEN2, USB_NEEDSEND_LEN3, USB_NEEDSEND_LEN4, USB_NEEDSEND_LEN5,
USB_NEEDSEND_LEN6, USB_NEEDSEND_LEN7, USB_NEEDSEND_LEN8, USB_NEEDSEND_LEN9, USB_NEEDSEND_LEN10, USB_NEEDSEND_LEN11};
/******************************************************************************
* Function Name : getUsbBufLen
* Description : get Usb Buf Len
* Input : u_int8_t data
* Output : None
* Return : Return head and tail pointer length
******************************************************************************/
u_int8_t getUsbBufLen(void)
{
u_int8_t reDataLen;
if(sendUsbData.head >= sendUsbData.end)
{
reDataLen = sendUsbData.head - sendUsbData.end;
}
else
{
reDataLen = (u_int16_t)USB_SENDBUF_LEN - sendUsbData.end + sendUsbData.head;
}
return reDataLen;
}
/******************************************************************************
* Function Name : SPI_Deal_sendMonitorData
* Description : SPI send Monitor Data
* Input : None
* Output : None
* Return : None
******************************************************************************/
void SPI_Deal_sendMonitorData(void)
{
u_int16_t data=0;
u_int8_t i=0, frameByteNum=0;
sendUsbData.sendDataLen=7;
// if(sendUsbData.sendDataLen)
// {
if(getUsbBufLen() >= 16)
{
GPIO_ResetBits(GPIOB,GPIO_Pin_6);
__asm volatile ("nop");
while((SPI1->STATR & SPI_I2S_FLAG_TXE) == (uint16_t)RESET);
SPI1->DATAR = 0x55AA;
while((SPI1->STATR & SPI_I2S_FLAG_TXE) == (uint16_t)RESET);
sendUsbData.heartBeat++;
data=sendUsbData.heartBeat<<8;
data|=32;
SPI1->DATAR = data;
while((SPI1->STATR & SPI_I2S_FLAG_TXE) == (uint16_t)RESET);
frameByteNum = 4;
// while(frameByteNum < usbFrameByteNum[sendUsbData.sendDataLen])//{0, 32, 32, 28, 28, 24, 28, 32, 20, 22, 24, 26};
while(frameByteNum < 32)
{
for(i = 0; i < sendUsbData.sendDataLen; i++)
{
SPI1->DATAR=sendUsbData.sendDataBuf[sendUsbData.end+i];
while((SPI1->STATR & SPI_I2S_FLAG_TXE) == (uint16_t)RESET);
frameByteNum+=2;
}
sendUsbData.end += MaxUsbDataLen;
}
while( (SPI1->STATR & SPI_I2S_FLAG_BSY) != (uint16_t)RESET);
__asm volatile ("nop");
GPIO_SetBits(GPIOB,GPIO_Pin_6);
}
// }
}
/******************************************************************************
* Function Name : SPI_FullDuplex_Init
* Description : SPI Init
* Input : None
* Output : None
* Return : None
******************************************************************************/
void SPI_FullDuplex_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure={0};
SPI_InitTypeDef SPI_InitStructure={0};
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB | RCC_APB2Periph_SPI1|RCC_APB2Periph_AFIO, ENABLE );
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;//MOSI
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init( GPIOB, &GPIO_InitStructure );
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init( GPIOB, &GPIO_InitStructure );//SCK
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_PinRemapConfig(GPIO_Remap_SPI1, ENABLE);
GPIO_SetBits(GPIOB,GPIO_Pin_6);
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;//16λ
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;//72/4=16M
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_LSB;
SPI_Init( SPI1, &SPI_InitStructure );
GPIO_ResetBits(GPIOB,GPIO_Pin_6);
SPI_Cmd( SPI1, ENABLE );
}
/******************************************************************************
* Function Name : Usart_Init
* Description : SPI Init
* Input : uint32_t Baud 4000000
* Output : None
* Return : None
******************************************************************************/
void Usart_Init(uint32_t Baud)
{
GPIO_InitTypeDef GPIO_InitStructure={0};
USART_InitTypeDef USART_InitStructure = {0};
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB|RCC_APB2Periph_USART1|RCC_APB2Periph_AFIO, ENABLE );
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_PinRemapConfig(GPIO_Remap_USART1,ENABLE);
USART_InitStructure.USART_BaudRate = Baud;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx ;
USART_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1, ENABLE);
}
/******************************************************************************
* Function Name : Usart_Deal_sendMonitorData
* Description : Usart Send
* Input : None
* Output : None
* Return : None
******************************************************************************/
void Usart_Deal_sendMonitorData(void)
{
u_int8_t i=0, frameByteNum=0;
sendUsbData.sendDataLen=4;
if(sendUsbData.sendDataLen)
{
if(getUsbBufLen() >= needSendLen[sendUsbData.sendDataLen])
{
__asm volatile ("nop");
while((USART1->STATR & USART_FLAG_TXE) == (uint16_t)RESET);
USART1->DATAR=0xAA;
while((USART1->STATR & USART_FLAG_TXE) == (uint16_t)RESET);
USART1->DATAR=0x55;
while((USART1->STATR & USART_FLAG_TXE) == (uint16_t)RESET);
USART1->DATAR=usbFrameByteNum[sendUsbData.sendDataLen];
while((USART1->STATR & USART_FLAG_TXE) == (uint16_t)RESET);
sendUsbData.heartBeat++;
USART1->DATAR=sendUsbData.heartBeat;
while((USART1->STATR & USART_FLAG_TXE) == (uint16_t)RESET);
frameByteNum = 4;
while(frameByteNum < usbFrameByteNum[sendUsbData.sendDataLen])//{0, 32, 32, 28, 28, 24, 28, 32, 20, 22, 24, 26};
{
for(i = 0; i < sendUsbData.sendDataLen; i++)
{
USART1->DATAR = (u_int8_t)((sendUsbData.sendDataBuf[sendUsbData.end+i])&0x00FF);
frameByteNum++;
while((USART1->STATR & USART_FLAG_TXE) == (uint16_t)RESET);
USART1->DATAR = (u_int8_t)((sendUsbData.sendDataBuf[sendUsbData.end+i])>>8);
frameByteNum++;
while((USART1->STATR & USART_FLAG_TXE) == (uint16_t)RESET);
}
sendUsbData.end += MaxUsbDataLen;
}
while((USART1->STATR & USART_FLAG_TXE) == (uint16_t)RESET);
__asm volatile ("nop");
}
}
}
@@ -0,0 +1,45 @@
#ifndef __MOTOR_SPI_USART_MONITORDATA_H_
#define __MOTOR_SPI_USART_MONITORDATA_H_
/* Includes -----------------------------------------------------------------*/
#include "debug.h"
/* Exported constants -------------------------------------------------------*/
#define MaxUsbDataLen 8
#define USB_SENDBUF_LEN (MaxUsbDataLen<<5)
#define USB_NEEDSEND_LEN1 (MaxUsbDataLen*14)
#define USB_NEEDSEND_LEN2 (MaxUsbDataLen*7)
#define USB_NEEDSEND_LEN3 (MaxUsbDataLen*4)
#define USB_NEEDSEND_LEN4 (MaxUsbDataLen*3)
#define USB_NEEDSEND_LEN5 (MaxUsbDataLen*2)
#define USB_NEEDSEND_LEN6 (MaxUsbDataLen*2)
#define USB_NEEDSEND_LEN7 (MaxUsbDataLen*2)
#define USB_NEEDSEND_LEN8 (MaxUsbDataLen)
#define USB_NEEDSEND_LEN9 (MaxUsbDataLen)
#define USB_NEEDSEND_LEN10 (MaxUsbDataLen)
#define USB_NEEDSEND_LEN11 (MaxUsbDataLen)
/* Exported types -----------------------------------------------------------*/
typedef struct
{
u_int8_t heartBeat; //---心跳包---
u_int8_t delayNum; //---延迟传输---
u_int8_t volatile sendDataLen; //----数据长度---
//UINT8 frameByteNum; //---发送包字节序列---
u_int8_t curWriteFrame; //----当前写数据帧---
u_int8_t recDataLen; //----接收上位机数据长度---
u_int8_t end;
u_int8_t volatile head;
u_int8_t recDataBuf[16]; //---接收数据缓冲区---
u_int8_t sendDataType[MaxUsbDataLen]; //---发送数据类型---
u_int16_t sendDataBuf[USB_SENDBUF_LEN]; //---发送数据缓冲区---
}t_sendUsbData;
/* Exported variables -------------------------------------------------------*/
extern t_sendUsbData sendUsbData;
/* Exported functions--------------------------------------------------------*/
extern void Deal_sendMonitorData(void);
extern void SPI_FullDuplex_Init(void);
extern void SPI_Deal_sendMonitorData(void);
extern void Usart_Init(uint32_t Baud);
extern void Usart_Deal_sendMonitorData(void);
#endif
@@ -0,0 +1,41 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : ch32v20x_conf.h
* Author : WCH
* Version : V1.0.0
* Date : 2021/06/06
* Description : Library configuration file.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __CH32V20x_CONF_H
#define __CH32V20x_CONF_H
#include "ch32v20x_adc.h"
#include "ch32v20x_bkp.h"
#include "ch32v20x_can.h"
#include "ch32v20x_crc.h"
#include "ch32v20x_dbgmcu.h"
#include "ch32v20x_dma.h"
#include "ch32v20x_exti.h"
#include "ch32v20x_flash.h"
#include "ch32v20x_gpio.h"
#include "ch32v20x_i2c.h"
#include "ch32v20x_iwdg.h"
#include "ch32v20x_pwr.h"
#include "ch32v20x_rcc.h"
#include "ch32v20x_rtc.h"
#include "ch32v20x_spi.h"
#include "ch32v20x_tim.h"
#include "ch32v20x_usart.h"
#include "ch32v20x_wwdg.h"
#include "ch32v20x_misc.h"
#endif /* __CH32V20x_CONF_H */
@@ -0,0 +1,65 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : main.c
* Author : WCH
* Version : V1.0.0
* Date : 2026/04/23
* Description : Main program body.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include "M0_Control_Library.h"
#include "ch32v20x_conf.h"
#include "IQmath_RV32.h"
#include "debug.h"
/*********************************************************************
* @fn main
*
* @brief Main program.
*
* @return none
*/
int main(void)
{
Delay_Init();
Delay_Ms(100);
Flash_Operation_Init(&Flash_M); //Post 4K FLASH Erase and Read
KeyandLED_IOInit(); //Button and indicator light IO configuration
KeyandLED_Parameter_Define(&Key_M, &LED_M); //Button and indicator parameters definition
Global_Status_Initial(); //Initialization of global state
Triac_Parameter_Define(&Triac_ctl,&Tempctl_M); //SCR State Initialization
Operation_Parameter_Define(&Operation_M); //Operation Parameter Definition
Motor_Prameter_Define(&MBase_M); //Motor Parameter Definition
Motor_FilerPara_Cal_M(&MStruc_M); //Motor Phase Filter Parameter Initialization
Motor_BaseCal_M(&MBase_M); //Base Value Parameter Calculation
PID_Prameter_Define(&Mpid_M); //PID Parameter Definition
DCurrProcess_Parameter_Define(&DCurrProcess_M);
PID_ParaBase_Cal_M(&MBase_M,&Mpid_M); //PID Base Value Parameter Calculation
Injstart_Parameter_Define_M(&InjStart_M); //Current Injection Start-up Parameter Configuration
Protection_and_Emergency_Parameter_Define(); //Protection Parameter Configuration
Speedrampctr_Parameter_Define(&SpeedRamp_M); //Rotational Speed Operation Parameter Configuration
SVPWM_1R_Paramter_Init(&SVPWM_Cal_M,&PWMCali_M ,&MBase_M); //SVPWM Calculation Parameter Configuration
SVPWM_1R_Timer_Configure(); //SVPWM uses timer and GPIO configuration
ADC_Parameter_Init(&ADC_M,&MBase_M); //ADC Calculation Parameter Configuration
ADC_OPA_Configure(&ADC_M); //ADC and OPA configuration
TempInit_Measure(&Tempctl_M,ADC1); //Initial temperature measurement
LBG_Parameter_Define(&MLBG_M,&LBG_Status_M); //LBG Observer Parameter Definition
LBG_Paramter_Cal (&MBase_M,&MLBG_M); //LBG Observer Parameter Calculation
HFVQI_Parameter_Define(&HFVQI_StartStruc_M,&SVPWM_Cal_M,&PWMCali_M); //Pulse Positioning Parameter Configuration
Poweroperation_Initial(&Powerctr_M); //Power On/Off Control Parameter Configuration
Powercom_Prameter_Define(&Powercom_M);
Systick_Init(); //Speed Loop Configuration
Interrupt_Configuration(); //Configure Interrupt
TIM_Cmd(TIM1, ENABLE);
TIM_Cmd(TIM2, ENABLE);
TIM_Cmd(TIM3, ENABLE);
TIM_Cmd(TIM4, ENABLE);
SYS_TIM_Cmd(ENABLE);
while(1)
{
Motor_Operation_Process(); //Motor Operation
}
}
@@ -0,0 +1,964 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : system_ch32v20x.c
* Author : WCH
* Version : V1.0.0
* Date : 2021/06/06
* Description : CH32V20x Device Peripheral Access Layer System Source File.
* For HSE = 32Mhz (CH32V208x/CH32V203RBT)
* For HSE = 8Mhz (other CH32V203x)
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include "ch32v20x.h"
/*
* Uncomment the line corresponding to the desired System clock (SYSCLK) frequency (after
* reset the HSI is used as SYSCLK source).
* If none of the define below is enabled, the HSI is used as System clock source.
*/
//#define SYSCLK_FREQ_HSE HSE_VALUE
//#define SYSCLK_FREQ_48MHz_HSE 48000000
//#define SYSCLK_FREQ_56MHz_HSE 56000000
//#define SYSCLK_FREQ_72MHz_HSE 72000000
//#define SYSCLK_FREQ_96MHz_HSE 96000000
//#define SYSCLK_FREQ_120MHz_HSE 120000000
//#define SYSCLK_FREQ_144MHz_HSE 144000000
//#define SYSCLK_FREQ_HSI HSI_VALUE
//#define SYSCLK_FREQ_48MHz_HSI 48000000
//#define SYSCLK_FREQ_56MHz_HSI 56000000
//#define SYSCLK_FREQ_72MHz_HSI 72000000
//#define SYSCLK_FREQ_96MHz_HSI 96000000
//#define SYSCLK_FREQ_120MHz_HSI 120000000
#define SYSCLK_FREQ_144MHz_HSI 144000000
/* Clock Definitions */
#ifdef SYSCLK_FREQ_HSE
uint32_t SystemCoreClock = SYSCLK_FREQ_HSE; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_48MHz_HSE
uint32_t SystemCoreClock = SYSCLK_FREQ_48MHz_HSE; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_56MHz_HSE
uint32_t SystemCoreClock = SYSCLK_FREQ_56MHz_HSE; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_72MHz_HSE
uint32_t SystemCoreClock = SYSCLK_FREQ_72MHz_HSE; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_96MHz_HSE
uint32_t SystemCoreClock = SYSCLK_FREQ_96MHz_HSE; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_120MHz_HSE
uint32_t SystemCoreClock = SYSCLK_FREQ_120MHz_HSE; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_144MHz_HSE
uint32_t SystemCoreClock = SYSCLK_FREQ_144MHz_HSE; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_48MHz_HSI
uint32_t SystemCoreClock = SYSCLK_FREQ_48MHz_HSI; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_56MHz_HSI
uint32_t SystemCoreClock = SYSCLK_FREQ_56MHz_HSI; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_72MHz_HSI
uint32_t SystemCoreClock = SYSCLK_FREQ_72MHz_HSI; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_96MHz_HSI
uint32_t SystemCoreClock = SYSCLK_FREQ_96MHz_HSI; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_120MHz_HSI
uint32_t SystemCoreClock = SYSCLK_FREQ_120MHz_HSI; /* System Clock Frequency (Core Clock) */
#elif defined SYSCLK_FREQ_144MHz_HSI
uint32_t SystemCoreClock = SYSCLK_FREQ_144MHz_HSI; /* System Clock Frequency (Core Clock) */
#else
uint32_t SystemCoreClock = HSI_VALUE; /* System Clock Frequency (Core Clock) */
#endif
__I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
/* system_private_function_proto_types */
static void SetSysClock(void);
#ifdef SYSCLK_FREQ_HSE
static void SetSysClockToHSE( void );
#elif defined SYSCLK_FREQ_48MHz_HSE
static void SetSysClockTo48_HSE( void );
#elif defined SYSCLK_FREQ_56MHz_HSE
static void SetSysClockTo56_HSE( void );
#elif defined SYSCLK_FREQ_72MHz_HSE
static void SetSysClockTo72_HSE( void );
#elif defined SYSCLK_FREQ_96MHz_HSE
static void SetSysClockTo96_HSE( void );
#elif defined SYSCLK_FREQ_120MHz_HSE
static void SetSysClockTo120_HSE( void );
#elif defined SYSCLK_FREQ_144MHz_HSE
static void SetSysClockTo144_HSE( void );
#elif defined SYSCLK_FREQ_48MHz_HSI
static void SetSysClockTo48_HSI( void );
#elif defined SYSCLK_FREQ_56MHz_HSI
static void SetSysClockTo56_HSI( void );
#elif defined SYSCLK_FREQ_72MHz_HSI
static void SetSysClockTo72_HSI( void );
#elif defined SYSCLK_FREQ_96MHz_HSI
static void SetSysClockTo96_HSI( void );
#elif defined SYSCLK_FREQ_120MHz_HSI
static void SetSysClockTo120_HSI( void );
#elif defined SYSCLK_FREQ_144MHz_HSI
static void SetSysClockTo144_HSI( void );
#endif
/*********************************************************************
* @fn SystemInit
*
* @brief Setup the microcontroller system Initialize the Embedded Flash Interface,
* the PLL and update the SystemCoreClock variable.
*
* @return none
*/
void SystemInit (void)
{
RCC->CTLR |= (uint32_t)0x00000001;
RCC->CFGR0 &= (uint32_t)0xF8FF0000;
RCC->CTLR &= (uint32_t)0xFEF6FFFF;
RCC->CTLR &= (uint32_t)0xFFFBFFFF;
RCC->CFGR0 &= (uint32_t)0xFF80FFFF;
RCC->INTR = 0x009F0000;
SetSysClock();
}
/*********************************************************************
* @fn SystemCoreClockUpdate
*
* @brief Update SystemCoreClock variable according to Clock Register Values.
*
* @return none
*/
void SystemCoreClockUpdate (void)
{
uint32_t tmp = 0, pllmull = 0, pllsource = 0, Pll_6_5 = 0;
tmp = RCC->CFGR0 & RCC_SWS;
switch (tmp)
{
case 0x00:
SystemCoreClock = HSI_VALUE;
break;
case 0x04:
SystemCoreClock = HSE_VALUE;
break;
case 0x08:
pllmull = RCC->CFGR0 & RCC_PLLMULL;
pllsource = RCC->CFGR0 & RCC_PLLSRC;
pllmull = ( pllmull >> 18) + 2;
if(pllmull == 17) pllmull = 18;
if (pllsource == 0x00)
{
if(EXTEN->EXTEN_CTR & EXTEN_PLL_HSI_PRE){
SystemCoreClock = HSI_VALUE * pllmull;
}
else{
SystemCoreClock = (HSI_VALUE >> 1) * pllmull;
}
}
else
{
#if defined (CH32V20x_D8W)
if((RCC->CFGR0 & (3<<22)) == (3<<22))
{
SystemCoreClock = ((HSE_VALUE>>1)) * pllmull;
}
else
#endif
if ((RCC->CFGR0 & RCC_PLLXTPRE) != (uint32_t)RESET)
{
#if defined (CH32V20x_D8) || defined (CH32V20x_D8W)
SystemCoreClock = ((HSE_VALUE>>2) >> 1) * pllmull;
#else
SystemCoreClock = (HSE_VALUE >> 1) * pllmull;
#endif
}
else
{
#if defined (CH32V20x_D8) || defined (CH32V20x_D8W)
SystemCoreClock = (HSE_VALUE>>2) * pllmull;
#else
SystemCoreClock = HSE_VALUE * pllmull;
#endif
}
}
if(Pll_6_5 == 1) SystemCoreClock = (SystemCoreClock / 2);
break;
default:
SystemCoreClock = HSI_VALUE;
break;
}
tmp = AHBPrescTable[((RCC->CFGR0 & RCC_HPRE) >> 4)];
SystemCoreClock >>= tmp;
}
/*********************************************************************
* @fn SetSysClock
*
* @brief Configures the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClock(void)
{
#ifdef SYSCLK_FREQ_HSE
SetSysClockToHSE();
#elif defined SYSCLK_FREQ_48MHz_HSE
SetSysClockTo48_HSE();
#elif defined SYSCLK_FREQ_56MHz_HSE
SetSysClockTo56_HSE();
#elif defined SYSCLK_FREQ_72MHz_HSE
SetSysClockTo72_HSE();
#elif defined SYSCLK_FREQ_96MHz_HSE
SetSysClockTo96_HSE();
#elif defined SYSCLK_FREQ_120MHz_HSE
SetSysClockTo120_HSE();
#elif defined SYSCLK_FREQ_144MHz_HSE
SetSysClockTo144_HSE();
#elif defined SYSCLK_FREQ_48MHz_HSI
SetSysClockTo48_HSI();
#elif defined SYSCLK_FREQ_56MHz_HSI
SetSysClockTo56_HSI();
#elif defined SYSCLK_FREQ_72MHz_HSI
SetSysClockTo72_HSI();
#elif defined SYSCLK_FREQ_96MHz_HSI
SetSysClockTo96_HSI();
#elif defined SYSCLK_FREQ_120MHz_HSI
SetSysClockTo120_HSI();
#elif defined SYSCLK_FREQ_144MHz_HSI
SetSysClockTo144_HSI();
#endif
/* If none of the define above is enabled, the HSI is used as System clock
* source (default after reset)
*/
}
#ifdef SYSCLK_FREQ_HSE
/*********************************************************************
* @fn SetSysClockToHSE
*
* @brief Sets HSE as System clock source and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockToHSE(void)
{
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
RCC->CTLR |= ((uint32_t)RCC_HSEON);
/* Wait till HSE is ready and if Time out is reached exit */
do
{
HSEStatus = RCC->CTLR & RCC_HSERDY;
StartUpCounter++;
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
if ((RCC->CTLR & RCC_HSERDY) != RESET)
{
HSEStatus = (uint32_t)0x01;
}
else
{
HSEStatus = (uint32_t)0x00;
}
if (HSEStatus == (uint32_t)0x01)
{
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV1;
/* Select HSE as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_HSE;
/* Wait till HSE is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x04)
{
}
}
else
{
/* If HSE fails to start-up, the application will have wrong clock
* configuration. User can add here some code to deal with this error
*/
}
}
#elif defined SYSCLK_FREQ_48MHz_HSE
/*********************************************************************
* @fn SetSysClockTo48_HSE
*
* @brief Sets System clock frequency to 48MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo48_HSE(void)
{
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
RCC->CTLR |= ((uint32_t)RCC_HSEON);
/* Wait till HSE is ready and if Time out is reached exit */
do
{
HSEStatus = RCC->CTLR & RCC_HSERDY;
StartUpCounter++;
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
if ((RCC->CTLR & RCC_HSERDY) != RESET)
{
HSEStatus = (uint32_t)0x01;
}
else
{
HSEStatus = (uint32_t)0x00;
}
if (HSEStatus == (uint32_t)0x01)
{
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
/* PLL configuration: PLLCLK = HSE * 6 = 48 MHz */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL6);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
else
{
/*
* If HSE fails to start-up, the application will have wrong clock
* configuration. User can add here some code to deal with this error
*/
}
}
#elif defined SYSCLK_FREQ_56MHz_HSE
/*********************************************************************
* @fn SetSysClockTo56_HSE
*
* @brief Sets System clock frequency to 56MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo56_HSE(void)
{
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
RCC->CTLR |= ((uint32_t)RCC_HSEON);
/* Wait till HSE is ready and if Time out is reached exit */
do
{
HSEStatus = RCC->CTLR & RCC_HSERDY;
StartUpCounter++;
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
if ((RCC->CTLR & RCC_HSERDY) != RESET)
{
HSEStatus = (uint32_t)0x01;
}
else
{
HSEStatus = (uint32_t)0x00;
}
if (HSEStatus == (uint32_t)0x01)
{
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
/* PLL configuration: PLLCLK = HSE * 7 = 56 MHz */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL7);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
else
{
/*
* If HSE fails to start-up, the application will have wrong clock
* configuration. User can add here some code to deal with this error
*/
}
}
#elif defined SYSCLK_FREQ_72MHz_HSE
/*********************************************************************
* @fn SetSysClockTo72_HSE
*
* @brief Sets System clock frequency to 72MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo72_HSE(void)
{
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
RCC->CTLR |= ((uint32_t)RCC_HSEON);
/* Wait till HSE is ready and if Time out is reached exit */
do
{
HSEStatus = RCC->CTLR & RCC_HSERDY;
StartUpCounter++;
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
if ((RCC->CTLR & RCC_HSERDY) != RESET)
{
HSEStatus = (uint32_t)0x01;
}
else
{
HSEStatus = (uint32_t)0x00;
}
if (HSEStatus == (uint32_t)0x01)
{
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
/* PLL configuration: PLLCLK = HSE * 9 = 72 MHz */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE |
RCC_PLLMULL));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL9);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
else
{
/*
* If HSE fails to start-up, the application will have wrong clock
* configuration. User can add here some code to deal with this error
*/
}
}
#elif defined SYSCLK_FREQ_96MHz_HSE
/*********************************************************************
* @fn SetSysClockTo96_HSE
*
* @brief Sets System clock frequency to 96MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo96_HSE(void)
{
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
RCC->CTLR |= ((uint32_t)RCC_HSEON);
/* Wait till HSE is ready and if Time out is reached exit */
do
{
HSEStatus = RCC->CTLR & RCC_HSERDY;
StartUpCounter++;
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
if ((RCC->CTLR & RCC_HSERDY) != RESET)
{
HSEStatus = (uint32_t)0x01;
}
else
{
HSEStatus = (uint32_t)0x00;
}
if (HSEStatus == (uint32_t)0x01)
{
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
/* PLL configuration: PLLCLK = HSE * 12 = 96 MHz */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE |
RCC_PLLMULL));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL12);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
else
{
/*
* If HSE fails to start-up, the application will have wrong clock
* configuration. User can add here some code to deal with this error
*/
}
}
#elif defined SYSCLK_FREQ_120MHz_HSE
/*********************************************************************
* @fn SetSysClockTo120_HSE
*
* @brief Sets System clock frequency to 120MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo120_HSE(void)
{
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
RCC->CTLR |= ((uint32_t)RCC_HSEON);
/* Wait till HSE is ready and if Time out is reached exit */
do
{
HSEStatus = RCC->CTLR & RCC_HSERDY;
StartUpCounter++;
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
if((RCC->CTLR & RCC_HSERDY) != RESET)
{
HSEStatus = (uint32_t)0x01;
}
else
{
HSEStatus = (uint32_t)0x00;
}
if(HSEStatus == (uint32_t)0x01)
{
#if defined (CH32V20x_D8W)
RCC->CFGR0 |= (uint32_t)(3<<22);
/* HCLK = SYSCLK/2 */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV2;
#else
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
#endif
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
/* PLL configuration: PLLCLK = HSE * 15 = 120 MHz */
RCC->CFGR0 &= (uint32_t)((uint32_t) ~(RCC_PLLSRC | RCC_PLLXTPRE |
RCC_PLLMULL));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL15);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t) ~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
else
{
/*
* If HSE fails to start-up, the application will have wrong clock
* configuration. User can add here some code to deal with this error
*/
}
}
#elif defined SYSCLK_FREQ_144MHz_HSE
/*********************************************************************
* @fn SetSysClockTo144_HSE
*
* @brief Sets System clock frequency to 144MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo144_HSE(void)
{
__IO uint32_t StartUpCounter = 0, HSEStatus = 0;
RCC->CTLR |= ((uint32_t)RCC_HSEON);
/* Wait till HSE is ready and if Time out is reached exit */
do
{
HSEStatus = RCC->CTLR & RCC_HSERDY;
StartUpCounter++;
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
if ((RCC->CTLR & RCC_HSERDY) != RESET)
{
HSEStatus = (uint32_t)0x01;
}
else
{
HSEStatus = (uint32_t)0x00;
}
if (HSEStatus == (uint32_t)0x01)
{
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
/* PLL configuration: PLLCLK = HSE * 18 = 144 MHz */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE |
RCC_PLLMULL));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSE | RCC_PLLXTPRE_HSE | RCC_PLLMULL18);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
else
{
/*
* If HSE fails to start-up, the application will have wrong clock
* configuration. User can add here some code to deal with this error
*/
}
}
#elif defined SYSCLK_FREQ_48MHz_HSI
/*********************************************************************
* @fn SetSysClockTo48_HSI
*
* @brief Sets System clock frequency to 48MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo48_HSI(void)
{
EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE;
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
/* PLL configuration: PLLCLK = HSI * 6 = 48 MHz */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL6);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
#elif defined SYSCLK_FREQ_56MHz_HSI
/*********************************************************************
* @fn SetSysClockTo56_HSI
*
* @brief Sets System clock frequency to 56MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo56_HSI(void)
{
EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE;
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
/* PLL configuration: PLLCLK = HSI * 7 = 48 MHz */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL7);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
#elif defined SYSCLK_FREQ_72MHz_HSI
/*********************************************************************
* @fn SetSysClockTo72_HSI
*
* @brief Sets System clock frequency to 72MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo72_HSI(void)
{
EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE;
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
/* PLL configuration: PLLCLK = HSI * 9 = 72 MHz */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL9);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
#elif defined SYSCLK_FREQ_96MHz_HSI
/*********************************************************************
* @fn SetSysClockTo96_HSI
*
* @brief Sets System clock frequency to 96MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo96_HSI(void)
{
EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE;
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
/* PLL configuration: PLLCLK = HSI * 12 = 96 MHz */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL12);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
#elif defined SYSCLK_FREQ_120MHz_HSI
/*********************************************************************
* @fn SetSysClockTo120_HSI
*
* @brief Sets System clock frequency to 120MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo120_HSI(void)
{
EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE;
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
/* PLL configuration: PLLCLK = HSI * 15 = 120 MHz */
RCC->CFGR0 &= (uint32_t)((uint32_t) ~(RCC_PLLSRC | RCC_PLLXTPRE |
RCC_PLLMULL));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL15);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t) ~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
#elif defined SYSCLK_FREQ_144MHz_HSI
/*********************************************************************
* @fn SetSysClockTo144_HSI
*
* @brief Sets System clock frequency to 144MHz and configure HCLK, PCLK2 and PCLK1 prescalers.
*
* @return none
*/
static void SetSysClockTo144_HSI(void)
{
EXTEN->EXTEN_CTR |= EXTEN_PLL_HSI_PRE;
/* HCLK = SYSCLK */
RCC->CFGR0 |= (uint32_t)RCC_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE2_DIV2;
/* PCLK1 = HCLK */
RCC->CFGR0 |= (uint32_t)RCC_PPRE1_DIV2;
/* PLL configuration: PLLCLK = HSI * 18 = 144 MHz */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_PLLSRC | RCC_PLLXTPRE | RCC_PLLMULL));
RCC->CFGR0 |= (uint32_t)(RCC_PLLSRC_HSI_Div2 | RCC_PLLMULL18);
/* Enable PLL */
RCC->CTLR |= RCC_PLLON;
/* Wait till PLL is ready */
while((RCC->CTLR & RCC_PLLRDY) == 0)
{
}
/* Select PLL as system clock source */
RCC->CFGR0 &= (uint32_t)((uint32_t)~(RCC_SW));
RCC->CFGR0 |= (uint32_t)RCC_SW_PLL;
/* Wait till PLL is used as system clock source */
while ((RCC->CFGR0 & (uint32_t)RCC_SWS) != (uint32_t)0x08)
{
}
}
#endif
@@ -0,0 +1,32 @@
/********************************** (C) COPYRIGHT *******************************
* File Name : system_ch32v20x.h
* Author : WCH
* Version : V1.0.0
* Date : 2021/06/06
* Description : CH32V20x Device Peripheral Access Layer System Header File.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#ifndef __SYSTEM_ch32v20x_H
#define __SYSTEM_ch32v20x_H
#ifdef __cplusplus
extern "C" {
#endif
extern uint32_t SystemCoreClock; /* System Clock Frequency (Core Clock) */
/* System_Exported_Functions */
extern void SystemInit(void);
extern void SystemCoreClockUpdate(void);
#ifdef __cplusplus
}
#endif
#endif /*__CH32V20x_SYSTEM_H */