Compare commits
No commits in common. "7b808be8ebed795469e7ff5d3ec3809c322a272b" and "16d886578a7279ebbb750de37dd71bf3b66e3c18" have entirely different histories.
7b808be8eb
...
16d886578a
|
@ -74,7 +74,7 @@ void PeriphCommonClock_Config(void);
|
||||||
* @retval int
|
* @retval int
|
||||||
*/
|
*/
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
/* USER CODE BEGIN 1 */
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
/* USER CODE END 1 */
|
/* USER CODE END 1 */
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Auto generated Run-Time-Environment Component Configuration File
|
* Auto generated Run-Time-Environment Configuration File
|
||||||
* *** Do not modify ! ***
|
* *** Do not modify ! ***
|
||||||
*
|
*
|
||||||
* Project: 'controller-v2'
|
* Project: 'controller-v2'
|
||||||
|
@ -17,4 +17,5 @@
|
||||||
#define CMSIS_device_header "stm32l4xx.h"
|
#define CMSIS_device_header "stm32l4xx.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* RTE_COMPONENTS_H */
|
#endif /* RTE_COMPONENTS_H */
|
||||||
|
|
|
@ -114,13 +114,13 @@
|
||||||
<tDlgDll></tDlgDll>
|
<tDlgDll></tDlgDll>
|
||||||
<tDlgPa></tDlgPa>
|
<tDlgPa></tDlgPa>
|
||||||
<tIfile></tIfile>
|
<tIfile></tIfile>
|
||||||
<pMon>Segger\JL2CM3.dll</pMon>
|
<pMon>STLink\ST-LINKIII-KEIL_SWO.dll</pMon>
|
||||||
</DebugOpt>
|
</DebugOpt>
|
||||||
<TargetDriverDllRegistry>
|
<TargetDriverDllRegistry>
|
||||||
<SetRegEntry>
|
<SetRegEntry>
|
||||||
<Number>0</Number>
|
<Number>0</Number>
|
||||||
<Key>DLGUARM</Key>
|
<Key>DLGUARM</Key>
|
||||||
<Name>?</Name>
|
<Name>(105=-1,-1,-1,-1,0)</Name>
|
||||||
</SetRegEntry>
|
</SetRegEntry>
|
||||||
<SetRegEntry>
|
<SetRegEntry>
|
||||||
<Number>0</Number>
|
<Number>0</Number>
|
||||||
|
@ -260,26 +260,6 @@
|
||||||
<WinNumber>1</WinNumber>
|
<WinNumber>1</WinNumber>
|
||||||
<ItemText>s_watch,0x0A</ItemText>
|
<ItemText>s_watch,0x0A</ItemText>
|
||||||
</Ww>
|
</Ww>
|
||||||
<Ww>
|
|
||||||
<count>20</count>
|
|
||||||
<WinNumber>1</WinNumber>
|
|
||||||
<ItemText>uDevice.ProcessChange_Flag,0x0A</ItemText>
|
|
||||||
</Ww>
|
|
||||||
<Ww>
|
|
||||||
<count>21</count>
|
|
||||||
<WinNumber>1</WinNumber>
|
|
||||||
<ItemText>Kp_watch</ItemText>
|
|
||||||
</Ww>
|
|
||||||
<Ww>
|
|
||||||
<count>22</count>
|
|
||||||
<WinNumber>1</WinNumber>
|
|
||||||
<ItemText>Ki_watch</ItemText>
|
|
||||||
</Ww>
|
|
||||||
<Ww>
|
|
||||||
<count>23</count>
|
|
||||||
<WinNumber>1</WinNumber>
|
|
||||||
<ItemText>Kd_watch</ItemText>
|
|
||||||
</Ww>
|
|
||||||
</WatchWindow1>
|
</WatchWindow1>
|
||||||
<Tracepoint>
|
<Tracepoint>
|
||||||
<THDelay>0</THDelay>
|
<THDelay>0</THDelay>
|
||||||
|
@ -325,6 +305,7 @@
|
||||||
<pMultCmdsp></pMultCmdsp>
|
<pMultCmdsp></pMultCmdsp>
|
||||||
<DebugDescription>
|
<DebugDescription>
|
||||||
<Enable>1</Enable>
|
<Enable>1</Enable>
|
||||||
|
<EnableFlashSeq>0</EnableFlashSeq>
|
||||||
<EnableLog>0</EnableLog>
|
<EnableLog>0</EnableLog>
|
||||||
<Protocol>2</Protocol>
|
<Protocol>2</Protocol>
|
||||||
<DbgClock>10000000</DbgClock>
|
<DbgClock>10000000</DbgClock>
|
||||||
|
@ -682,7 +663,7 @@
|
||||||
|
|
||||||
<Group>
|
<Group>
|
||||||
<GroupName>Application/MDK-ARM</GroupName>
|
<GroupName>Application/MDK-ARM</GroupName>
|
||||||
<tvExp>0</tvExp>
|
<tvExp>1</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
<cbSel>0</cbSel>
|
<cbSel>0</cbSel>
|
||||||
<RteFlg>0</RteFlg>
|
<RteFlg>0</RteFlg>
|
||||||
|
@ -702,7 +683,7 @@
|
||||||
|
|
||||||
<Group>
|
<Group>
|
||||||
<GroupName>Application/User/Core</GroupName>
|
<GroupName>Application/User/Core</GroupName>
|
||||||
<tvExp>0</tvExp>
|
<tvExp>1</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
<cbSel>0</cbSel>
|
<cbSel>0</cbSel>
|
||||||
<RteFlg>0</RteFlg>
|
<RteFlg>0</RteFlg>
|
||||||
|
@ -1278,7 +1259,7 @@
|
||||||
|
|
||||||
<Group>
|
<Group>
|
||||||
<GroupName>User/system</GroupName>
|
<GroupName>User/system</GroupName>
|
||||||
<tvExp>1</tvExp>
|
<tvExp>0</tvExp>
|
||||||
<tvExpOptDlg>0</tvExpOptDlg>
|
<tvExpOptDlg>0</tvExpOptDlg>
|
||||||
<cbSel>0</cbSel>
|
<cbSel>0</cbSel>
|
||||||
<RteFlg>0</RteFlg>
|
<RteFlg>0</RteFlg>
|
||||||
|
|
|
@ -10,14 +10,14 @@
|
||||||
<TargetName>controller-v2</TargetName>
|
<TargetName>controller-v2</TargetName>
|
||||||
<ToolsetNumber>0x4</ToolsetNumber>
|
<ToolsetNumber>0x4</ToolsetNumber>
|
||||||
<ToolsetName>ARM-ADS</ToolsetName>
|
<ToolsetName>ARM-ADS</ToolsetName>
|
||||||
<pCCUsed>5060061::V5.06 update 1 (build 61)::ARMCC</pCCUsed>
|
<pCCUsed>5060960::V5.06 update 7 (build 960)::.\ARMCC</pCCUsed>
|
||||||
<uAC6>0</uAC6>
|
<uAC6>0</uAC6>
|
||||||
<TargetOption>
|
<TargetOption>
|
||||||
<TargetCommonOption>
|
<TargetCommonOption>
|
||||||
<Device>STM32L476VGTx</Device>
|
<Device>STM32L476VGTx</Device>
|
||||||
<Vendor>STMicroelectronics</Vendor>
|
<Vendor>STMicroelectronics</Vendor>
|
||||||
<PackID>Keil.STM32L4xx_DFP.2.1.0</PackID>
|
<PackID>Keil.STM32L4xx_DFP.2.6.2</PackID>
|
||||||
<PackURL>http://www.keil.com/pack</PackURL>
|
<PackURL>https://www.keil.com/pack/</PackURL>
|
||||||
<Cpu>IRAM(0x20000000,0x00018000) IRAM2(0x10000000,0x00008000) IROM(0x08000000,0x00100000) CPUTYPE("Cortex-M4") FPU2 DSP CLOCK(12000000) ELITTLE</Cpu>
|
<Cpu>IRAM(0x20000000,0x00018000) IRAM2(0x10000000,0x00008000) IROM(0x08000000,0x00100000) CPUTYPE("Cortex-M4") FPU2 DSP CLOCK(12000000) ELITTLE</Cpu>
|
||||||
<FlashUtilSpec></FlashUtilSpec>
|
<FlashUtilSpec></FlashUtilSpec>
|
||||||
<StartupFile></StartupFile>
|
<StartupFile></StartupFile>
|
||||||
|
@ -184,6 +184,8 @@
|
||||||
<hadXRAM>0</hadXRAM>
|
<hadXRAM>0</hadXRAM>
|
||||||
<uocXRam>0</uocXRam>
|
<uocXRam>0</uocXRam>
|
||||||
<RvdsVP>1</RvdsVP>
|
<RvdsVP>1</RvdsVP>
|
||||||
|
<RvdsMve>0</RvdsMve>
|
||||||
|
<RvdsCdeCp>0</RvdsCdeCp>
|
||||||
<hadIRAM2>1</hadIRAM2>
|
<hadIRAM2>1</hadIRAM2>
|
||||||
<hadIROM2>0</hadIROM2>
|
<hadIROM2>0</hadIROM2>
|
||||||
<StupSel>8</StupSel>
|
<StupSel>8</StupSel>
|
||||||
|
@ -350,7 +352,7 @@
|
||||||
<NoWarn>0</NoWarn>
|
<NoWarn>0</NoWarn>
|
||||||
<uSurpInc>0</uSurpInc>
|
<uSurpInc>0</uSurpInc>
|
||||||
<useXO>0</useXO>
|
<useXO>0</useXO>
|
||||||
<uClangAs>0</uClangAs>
|
<ClangAsOpt>4</ClangAsOpt>
|
||||||
<VariousControls>
|
<VariousControls>
|
||||||
<MiscControls></MiscControls>
|
<MiscControls></MiscControls>
|
||||||
<Define></Define>
|
<Define></Define>
|
||||||
|
@ -991,7 +993,7 @@
|
||||||
<NoWarn>2</NoWarn>
|
<NoWarn>2</NoWarn>
|
||||||
<uSurpInc>2</uSurpInc>
|
<uSurpInc>2</uSurpInc>
|
||||||
<useXO>2</useXO>
|
<useXO>2</useXO>
|
||||||
<uClangAs>2</uClangAs>
|
<ClangAsOpt>0</ClangAsOpt>
|
||||||
<VariousControls>
|
<VariousControls>
|
||||||
<MiscControls></MiscControls>
|
<MiscControls></MiscControls>
|
||||||
<Define></Define>
|
<Define></Define>
|
||||||
|
@ -1043,8 +1045,8 @@
|
||||||
<TargetCommonOption>
|
<TargetCommonOption>
|
||||||
<Device>STM32L476VGTx</Device>
|
<Device>STM32L476VGTx</Device>
|
||||||
<Vendor>STMicroelectronics</Vendor>
|
<Vendor>STMicroelectronics</Vendor>
|
||||||
<PackID>Keil.STM32L4xx_DFP.2.1.0</PackID>
|
<PackID>Keil.STM32L4xx_DFP.2.6.2</PackID>
|
||||||
<PackURL>http://www.keil.com/pack</PackURL>
|
<PackURL>https://www.keil.com/pack/</PackURL>
|
||||||
<Cpu>IRAM(0x20000000,0x00018000) IRAM2(0x10000000,0x00008000) IROM(0x08000000,0x00100000) CPUTYPE("Cortex-M4") FPU2 DSP CLOCK(12000000) ELITTLE</Cpu>
|
<Cpu>IRAM(0x20000000,0x00018000) IRAM2(0x10000000,0x00008000) IROM(0x08000000,0x00100000) CPUTYPE("Cortex-M4") FPU2 DSP CLOCK(12000000) ELITTLE</Cpu>
|
||||||
<FlashUtilSpec></FlashUtilSpec>
|
<FlashUtilSpec></FlashUtilSpec>
|
||||||
<StartupFile></StartupFile>
|
<StartupFile></StartupFile>
|
||||||
|
@ -1211,6 +1213,8 @@
|
||||||
<hadXRAM>0</hadXRAM>
|
<hadXRAM>0</hadXRAM>
|
||||||
<uocXRam>0</uocXRam>
|
<uocXRam>0</uocXRam>
|
||||||
<RvdsVP>1</RvdsVP>
|
<RvdsVP>1</RvdsVP>
|
||||||
|
<RvdsMve>0</RvdsMve>
|
||||||
|
<RvdsCdeCp>0</RvdsCdeCp>
|
||||||
<hadIRAM2>1</hadIRAM2>
|
<hadIRAM2>1</hadIRAM2>
|
||||||
<hadIROM2>0</hadIROM2>
|
<hadIROM2>0</hadIROM2>
|
||||||
<StupSel>8</StupSel>
|
<StupSel>8</StupSel>
|
||||||
|
@ -1377,7 +1381,7 @@
|
||||||
<NoWarn>0</NoWarn>
|
<NoWarn>0</NoWarn>
|
||||||
<uSurpInc>0</uSurpInc>
|
<uSurpInc>0</uSurpInc>
|
||||||
<useXO>0</useXO>
|
<useXO>0</useXO>
|
||||||
<uClangAs>0</uClangAs>
|
<ClangAsOpt>4</ClangAsOpt>
|
||||||
<VariousControls>
|
<VariousControls>
|
||||||
<MiscControls></MiscControls>
|
<MiscControls></MiscControls>
|
||||||
<Define></Define>
|
<Define></Define>
|
||||||
|
@ -1880,8 +1884,8 @@
|
||||||
<TargetCommonOption>
|
<TargetCommonOption>
|
||||||
<Device>STM32L476VGTx</Device>
|
<Device>STM32L476VGTx</Device>
|
||||||
<Vendor>STMicroelectronics</Vendor>
|
<Vendor>STMicroelectronics</Vendor>
|
||||||
<PackID>Keil.STM32L4xx_DFP.2.1.0</PackID>
|
<PackID>Keil.STM32L4xx_DFP.2.6.2</PackID>
|
||||||
<PackURL>http://www.keil.com/pack</PackURL>
|
<PackURL>https://www.keil.com/pack/</PackURL>
|
||||||
<Cpu>IRAM(0x20000000,0x00018000) IRAM2(0x10000000,0x00008000) IROM(0x08000000,0x00100000) CPUTYPE("Cortex-M4") FPU2 DSP CLOCK(12000000) ELITTLE</Cpu>
|
<Cpu>IRAM(0x20000000,0x00018000) IRAM2(0x10000000,0x00008000) IROM(0x08000000,0x00100000) CPUTYPE("Cortex-M4") FPU2 DSP CLOCK(12000000) ELITTLE</Cpu>
|
||||||
<FlashUtilSpec></FlashUtilSpec>
|
<FlashUtilSpec></FlashUtilSpec>
|
||||||
<StartupFile></StartupFile>
|
<StartupFile></StartupFile>
|
||||||
|
@ -2048,6 +2052,8 @@
|
||||||
<hadXRAM>0</hadXRAM>
|
<hadXRAM>0</hadXRAM>
|
||||||
<uocXRam>0</uocXRam>
|
<uocXRam>0</uocXRam>
|
||||||
<RvdsVP>1</RvdsVP>
|
<RvdsVP>1</RvdsVP>
|
||||||
|
<RvdsMve>0</RvdsMve>
|
||||||
|
<RvdsCdeCp>0</RvdsCdeCp>
|
||||||
<hadIRAM2>1</hadIRAM2>
|
<hadIRAM2>1</hadIRAM2>
|
||||||
<hadIROM2>0</hadIROM2>
|
<hadIROM2>0</hadIROM2>
|
||||||
<StupSel>8</StupSel>
|
<StupSel>8</StupSel>
|
||||||
|
@ -2214,7 +2220,7 @@
|
||||||
<NoWarn>0</NoWarn>
|
<NoWarn>0</NoWarn>
|
||||||
<uSurpInc>0</uSurpInc>
|
<uSurpInc>0</uSurpInc>
|
||||||
<useXO>0</useXO>
|
<useXO>0</useXO>
|
||||||
<uClangAs>0</uClangAs>
|
<ClangAsOpt>4</ClangAsOpt>
|
||||||
<VariousControls>
|
<VariousControls>
|
||||||
<MiscControls></MiscControls>
|
<MiscControls></MiscControls>
|
||||||
<Define></Define>
|
<Define></Define>
|
||||||
|
@ -2303,7 +2309,7 @@
|
||||||
<NoWarn>2</NoWarn>
|
<NoWarn>2</NoWarn>
|
||||||
<uSurpInc>2</uSurpInc>
|
<uSurpInc>2</uSurpInc>
|
||||||
<useXO>2</useXO>
|
<useXO>2</useXO>
|
||||||
<uClangAs>2</uClangAs>
|
<ClangAsOpt>0</ClangAsOpt>
|
||||||
<VariousControls>
|
<VariousControls>
|
||||||
<MiscControls></MiscControls>
|
<MiscControls></MiscControls>
|
||||||
<Define></Define>
|
<Define></Define>
|
||||||
|
@ -2382,7 +2388,7 @@
|
||||||
<NoWarn>2</NoWarn>
|
<NoWarn>2</NoWarn>
|
||||||
<uSurpInc>2</uSurpInc>
|
<uSurpInc>2</uSurpInc>
|
||||||
<useXO>2</useXO>
|
<useXO>2</useXO>
|
||||||
<uClangAs>2</uClangAs>
|
<ClangAsOpt>0</ClangAsOpt>
|
||||||
<VariousControls>
|
<VariousControls>
|
||||||
<MiscControls></MiscControls>
|
<MiscControls></MiscControls>
|
||||||
<Define></Define>
|
<Define></Define>
|
||||||
|
@ -2506,7 +2512,7 @@
|
||||||
<NoWarn>2</NoWarn>
|
<NoWarn>2</NoWarn>
|
||||||
<uSurpInc>2</uSurpInc>
|
<uSurpInc>2</uSurpInc>
|
||||||
<useXO>2</useXO>
|
<useXO>2</useXO>
|
||||||
<uClangAs>2</uClangAs>
|
<ClangAsOpt>0</ClangAsOpt>
|
||||||
<VariousControls>
|
<VariousControls>
|
||||||
<MiscControls></MiscControls>
|
<MiscControls></MiscControls>
|
||||||
<Define></Define>
|
<Define></Define>
|
||||||
|
@ -2640,7 +2646,7 @@
|
||||||
<NoWarn>2</NoWarn>
|
<NoWarn>2</NoWarn>
|
||||||
<uSurpInc>2</uSurpInc>
|
<uSurpInc>2</uSurpInc>
|
||||||
<useXO>2</useXO>
|
<useXO>2</useXO>
|
||||||
<uClangAs>2</uClangAs>
|
<ClangAsOpt>0</ClangAsOpt>
|
||||||
<VariousControls>
|
<VariousControls>
|
||||||
<MiscControls></MiscControls>
|
<MiscControls></MiscControls>
|
||||||
<Define></Define>
|
<Define></Define>
|
||||||
|
@ -2719,7 +2725,7 @@
|
||||||
<NoWarn>2</NoWarn>
|
<NoWarn>2</NoWarn>
|
||||||
<uSurpInc>2</uSurpInc>
|
<uSurpInc>2</uSurpInc>
|
||||||
<useXO>2</useXO>
|
<useXO>2</useXO>
|
||||||
<uClangAs>2</uClangAs>
|
<ClangAsOpt>0</ClangAsOpt>
|
||||||
<VariousControls>
|
<VariousControls>
|
||||||
<MiscControls></MiscControls>
|
<MiscControls></MiscControls>
|
||||||
<Define></Define>
|
<Define></Define>
|
||||||
|
@ -2808,7 +2814,7 @@
|
||||||
<NoWarn>2</NoWarn>
|
<NoWarn>2</NoWarn>
|
||||||
<uSurpInc>2</uSurpInc>
|
<uSurpInc>2</uSurpInc>
|
||||||
<useXO>2</useXO>
|
<useXO>2</useXO>
|
||||||
<uClangAs>2</uClangAs>
|
<ClangAsOpt>0</ClangAsOpt>
|
||||||
<VariousControls>
|
<VariousControls>
|
||||||
<MiscControls></MiscControls>
|
<MiscControls></MiscControls>
|
||||||
<Define></Define>
|
<Define></Define>
|
||||||
|
@ -2937,7 +2943,7 @@
|
||||||
<NoWarn>2</NoWarn>
|
<NoWarn>2</NoWarn>
|
||||||
<uSurpInc>2</uSurpInc>
|
<uSurpInc>2</uSurpInc>
|
||||||
<useXO>2</useXO>
|
<useXO>2</useXO>
|
||||||
<uClangAs>2</uClangAs>
|
<ClangAsOpt>0</ClangAsOpt>
|
||||||
<VariousControls>
|
<VariousControls>
|
||||||
<MiscControls></MiscControls>
|
<MiscControls></MiscControls>
|
||||||
<Define></Define>
|
<Define></Define>
|
||||||
|
@ -3046,7 +3052,7 @@
|
||||||
<NoWarn>2</NoWarn>
|
<NoWarn>2</NoWarn>
|
||||||
<uSurpInc>2</uSurpInc>
|
<uSurpInc>2</uSurpInc>
|
||||||
<useXO>2</useXO>
|
<useXO>2</useXO>
|
||||||
<uClangAs>2</uClangAs>
|
<ClangAsOpt>0</ClangAsOpt>
|
||||||
<VariousControls>
|
<VariousControls>
|
||||||
<MiscControls></MiscControls>
|
<MiscControls></MiscControls>
|
||||||
<Define></Define>
|
<Define></Define>
|
||||||
|
@ -3225,7 +3231,7 @@
|
||||||
<NoWarn>2</NoWarn>
|
<NoWarn>2</NoWarn>
|
||||||
<uSurpInc>2</uSurpInc>
|
<uSurpInc>2</uSurpInc>
|
||||||
<useXO>2</useXO>
|
<useXO>2</useXO>
|
||||||
<uClangAs>2</uClangAs>
|
<ClangAsOpt>0</ClangAsOpt>
|
||||||
<VariousControls>
|
<VariousControls>
|
||||||
<MiscControls></MiscControls>
|
<MiscControls></MiscControls>
|
||||||
<Define></Define>
|
<Define></Define>
|
||||||
|
@ -3334,7 +3340,7 @@
|
||||||
<NoWarn>2</NoWarn>
|
<NoWarn>2</NoWarn>
|
||||||
<uSurpInc>2</uSurpInc>
|
<uSurpInc>2</uSurpInc>
|
||||||
<useXO>2</useXO>
|
<useXO>2</useXO>
|
||||||
<uClangAs>2</uClangAs>
|
<ClangAsOpt>0</ClangAsOpt>
|
||||||
<VariousControls>
|
<VariousControls>
|
||||||
<MiscControls></MiscControls>
|
<MiscControls></MiscControls>
|
||||||
<Define></Define>
|
<Define></Define>
|
||||||
|
|
Binary file not shown.
|
@ -11,8 +11,12 @@
|
||||||
#define TIME_CYCLE 0.01f // 定义时间周期:10ms
|
#define TIME_CYCLE 0.01f // 定义时间周期:10ms
|
||||||
#define FSM_WAIT(st) BIT_SET(st, BIT7)
|
#define FSM_WAIT(st) BIT_SET(st, BIT7)
|
||||||
#define FSM_IS_WAIT(st) (st & BIT7)
|
#define FSM_IS_WAIT(st) (st & BIT7)
|
||||||
#define DIFF_ADC_MAX 10U
|
#define DIFF_ADC_MAX 6U
|
||||||
|
|
||||||
|
/*阶跃信号大小*/
|
||||||
|
#define FULL_TRIP_SIGNAL 925 // 925 2020
|
||||||
|
#define HALF_TRIP_SIGNAL 753
|
||||||
|
#define SMALL_TRIP_SIGNAL 650
|
||||||
///////////////////////////////////////*算法整定部分宏定义END*///////////////////////////////////////////
|
///////////////////////////////////////*算法整定部分宏定义END*///////////////////////////////////////////
|
||||||
|
|
||||||
#define EXECUTE_PLAN EXECUTE_PLAN_1
|
#define EXECUTE_PLAN EXECUTE_PLAN_1
|
||||||
|
@ -32,13 +36,12 @@ typedef struct
|
||||||
uint8_t tuned_flag; // 是否整定过 1:整定过 0:未整定过
|
uint8_t tuned_flag; // 是否整定过 1:整定过 0:未整定过
|
||||||
uint8_t tuned_state; // 自整定结果
|
uint8_t tuned_state; // 自整定结果
|
||||||
|
|
||||||
uint16_t startup_value; // 阀位启动值
|
uint16_t bleeding; // 放气值
|
||||||
|
uint16_t inflation; // 充气值
|
||||||
uint16_t arr_diff; // 控制区间
|
uint16_t arr_diff; // 控制区间
|
||||||
uint16_t ad_diff; // 磁条区间
|
uint16_t ad_diff; // 磁条区间
|
||||||
uint16_t pwmp_min; // 控制最小值
|
uint16_t pwmp_min; // 控制最小值
|
||||||
uint16_t pwmp_max; // 控制最大值
|
uint16_t pwmp_max; // 控制最大值
|
||||||
uint16_t pwmp_min_origin;// 整定控制最小值
|
|
||||||
uint16_t pwmp_max_origin;// 整定控制最大值
|
|
||||||
uint16_t trip_0; // 磁条0位置AD
|
uint16_t trip_0; // 磁条0位置AD
|
||||||
uint16_t trip_100; // 词条100位置AD
|
uint16_t trip_100; // 词条100位置AD
|
||||||
uint16_t trip_min0; // 小回路行程0位置AD
|
uint16_t trip_min0; // 小回路行程0位置AD
|
||||||
|
@ -108,8 +111,6 @@ typedef enum
|
||||||
PWMP_HD_ADJUST_ACCURATE_POSITION0, // 精调位置0
|
PWMP_HD_ADJUST_ACCURATE_POSITION0, // 精调位置0
|
||||||
PWMP_HD_ADJUST_ROUGH_POSITION100, // 粗调位置100
|
PWMP_HD_ADJUST_ROUGH_POSITION100, // 粗调位置100
|
||||||
PWMP_HD_ADJUST_ACCURATE_POSITION100, // 精调位置100
|
PWMP_HD_ADJUST_ACCURATE_POSITION100, // 精调位置100
|
||||||
PWMP_HD_ADJUST_ALL_CLOSE_TIME, // 全关时间
|
|
||||||
PWMP_HD_ADJUST_ALL_OPEN_TIME, // 全开时间
|
|
||||||
PWMP_HD_ADJUST_CALCULATE, // 阀门参数计算
|
PWMP_HD_ADJUST_CALCULATE, // 阀门参数计算
|
||||||
PWMP_HD_ADJUST_PID_CALCULATE, // PID参数计算
|
PWMP_HD_ADJUST_PID_CALCULATE, // PID参数计算
|
||||||
PWMP_HD_ADJUST_PID_TUNING, // PID参数自整定过程(整定得到K、T、L)
|
PWMP_HD_ADJUST_PID_TUNING, // PID参数自整定过程(整定得到K、T、L)
|
||||||
|
@ -154,9 +155,8 @@ typedef struct
|
||||||
uint16_t arr_record_1; // 最小推动阀门的ad值
|
uint16_t arr_record_1; // 最小推动阀门的ad值
|
||||||
uint16_t arr_record_2; // 最大位置阀门的ad值
|
uint16_t arr_record_2; // 最大位置阀门的ad值
|
||||||
|
|
||||||
uint32_t all_open_time; // 全开时间
|
uint32_t all_open_time; // 全开时间
|
||||||
uint32_t all_open_time_full; // 信号为最大输出时的全开时间
|
uint32_t all_close_time; // 全关时间
|
||||||
uint32_t all_close_time; // 全关时间
|
|
||||||
BOOL all_close_time_flag;
|
BOOL all_close_time_flag;
|
||||||
uint32_t tmp_time; // 临时用来记录全开全关/整定时间
|
uint32_t tmp_time; // 临时用来记录全开全关/整定时间
|
||||||
|
|
||||||
|
|
|
@ -84,9 +84,9 @@ static void pwmp_control_update(filter_e type)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*PID参数获取*/
|
/*PID参数获取*/
|
||||||
static float32 get_pwmp_hd_control_kp(void)
|
static float32 get_pwmp_control_kp(void)
|
||||||
{
|
{
|
||||||
if (mode_pwmp_hd->pwmp_save->storage.kp < 2)
|
if (mode_pwmp_hd->pwmp_save->storage.kp < 1)
|
||||||
{
|
{
|
||||||
return mode_pwmp_hd->pwmp_save->storage.kp * 10;
|
return mode_pwmp_hd->pwmp_save->storage.kp * 10;
|
||||||
}
|
}
|
||||||
|
@ -96,14 +96,14 @@ static float32 get_pwmp_hd_control_kp(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static float32 get_pwmp_hd_control_ki(void)
|
static float32 get_pwmp_control_ki(void)
|
||||||
{
|
{
|
||||||
return mode_pwmp_hd->pwmp_save->storage.ki < 0.001 ? mode_pwmp_hd->pwmp_save->storage.ki * 10 : 0.018;
|
return mode_pwmp_hd->pwmp_save->storage.ki;
|
||||||
}
|
}
|
||||||
|
|
||||||
static float32 get_pwmp_hd_control_kd(void)
|
static float32 get_pwmp_control_kd(void)
|
||||||
{
|
{
|
||||||
return mode_pwmp_hd->pwmp_save->storage.kd < 0.01 ? mode_pwmp_hd->pwmp_save->storage.kd : 0.005;
|
return mode_pwmp_hd->pwmp_save->storage.kd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*将自己结构体变量中的参数保存到公共参数中*/
|
/*将自己结构体变量中的参数保存到公共参数中*/
|
||||||
|
@ -206,7 +206,7 @@ void execute_pid_init(execute_plan_hd_e plan)
|
||||||
case EXECUTE_PLAN_1:
|
case EXECUTE_PLAN_1:
|
||||||
_pid.type = PID_TYPE_CUSTOM_HANGDIAN;
|
_pid.type = PID_TYPE_CUSTOM_HANGDIAN;
|
||||||
pid_constructor(&_pid);
|
pid_constructor(&_pid);
|
||||||
_pid.pid_u.hd.set_ctrl_prm_position(&_pid.pid_u.hd, get_pwmp_hd_control_kp(), get_pwmp_hd_control_ki(), get_pwmp_hd_control_kd());
|
_pid.pid_u.hd.set_ctrl_prm_position(&_pid.pid_u.hd, get_pwmp_control_kp(), get_pwmp_control_ki(), get_pwmp_control_kd());
|
||||||
break;
|
break;
|
||||||
case EXECUTE_PLAN_2:
|
case EXECUTE_PLAN_2:
|
||||||
|
|
||||||
|
@ -352,6 +352,12 @@ static void pid_autotune_way_set(pid_autotune_way_e state)
|
||||||
pid_autotune_hd->autotune_way = state;
|
pid_autotune_hd->autotune_way = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*阶跃信号设定*/
|
||||||
|
static void set_step_signal(uint16_t signal_in)
|
||||||
|
{
|
||||||
|
pdctrl_out(signal_in);
|
||||||
|
}
|
||||||
|
|
||||||
/*判断阀门状态:移动、停止、停止但仍在等待*/
|
/*判断阀门状态:移动、停止、停止但仍在等待*/
|
||||||
static valve_position_change_e pwmp_adjust_hd_valve_position_change(uint8_t *state, uint8_t next_state, uint8_t diff_adc_max)
|
static valve_position_change_e pwmp_adjust_hd_valve_position_change(uint8_t *state, uint8_t next_state, uint8_t diff_adc_max)
|
||||||
{
|
{
|
||||||
|
@ -437,8 +443,8 @@ static void pwmp_adjust_hd_idle(uint8_t *state, mode_pwmp_hd_adjust_state_e next
|
||||||
{
|
{
|
||||||
case POSITION_NO_CHANGE_FOREVER:
|
case POSITION_NO_CHANGE_FOREVER:
|
||||||
// 位置不再改变,记录此时阀门位置AD值
|
// 位置不再改变,记录此时阀门位置AD值
|
||||||
mode_pwmp_hd_adjust->adc_record_1 = pid_autotune_hd->data.adjust_tmp_actual;
|
mode_pwmp_hd_adjust->adc_record_1 = mode_pwmp_hd_adjust->psb_adc;
|
||||||
mode_pwmp_hd_adjust->adc_record_0 = pid_autotune_hd->data.adjust_tmp_actual;
|
mode_pwmp_hd_adjust->adc_record_0 = mode_pwmp_hd_adjust->psb_adc;
|
||||||
break;
|
break;
|
||||||
case POSITION_CHANGE:
|
case POSITION_CHANGE:
|
||||||
*state = PWMP_HD_ADJUST_IDEL;
|
*state = PWMP_HD_ADJUST_IDEL;
|
||||||
|
@ -454,11 +460,13 @@ static void pwmp_adjust_hd_idle(uint8_t *state, mode_pwmp_hd_adjust_state_e next
|
||||||
/*整定粗调0*/
|
/*整定粗调0*/
|
||||||
static void pwmp_adjust_hd_rough_position0(uint8_t *state, mode_pwmp_hd_adjust_state_e next_state)
|
static void pwmp_adjust_hd_rough_position0(uint8_t *state, mode_pwmp_hd_adjust_state_e next_state)
|
||||||
{
|
{
|
||||||
|
// 找最小推动值arr
|
||||||
uint16_t current_adc = 0;
|
uint16_t current_adc = 0;
|
||||||
|
|
||||||
if (!FSM_IS_WAIT(*state))
|
if (!FSM_IS_WAIT(*state))
|
||||||
{
|
{
|
||||||
// 以10%增加,提高DAC输出,找到能推动阀门的最小值
|
// 以10%增加,提高DAC输出,找到能推动阀门的最小值
|
||||||
mode_pwmp_hd_adjust->arr_current = 100;
|
mode_pwmp_hd_adjust->arr_current = 50;
|
||||||
mode_pwmp_hd_adjust->arr_last = mode_pwmp_hd_adjust->arr_current;
|
mode_pwmp_hd_adjust->arr_last = mode_pwmp_hd_adjust->arr_current;
|
||||||
pdctrl_out(mode_pwmp_hd_adjust->arr_current);
|
pdctrl_out(mode_pwmp_hd_adjust->arr_current);
|
||||||
mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 20;
|
mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 20;
|
||||||
|
@ -469,8 +477,8 @@ static void pwmp_adjust_hd_rough_position0(uint8_t *state, mode_pwmp_hd_adjust_s
|
||||||
{
|
{
|
||||||
valve_position_change_e s = pwmp_adjust_hd_valve_position_change(state, next_state, DIFF_ADC_MAX);
|
valve_position_change_e s = pwmp_adjust_hd_valve_position_change(state, next_state, DIFF_ADC_MAX);
|
||||||
|
|
||||||
current_adc = pid_autotune_hd->data.adjust_tmp_actual;
|
current_adc = mode_pwmp_hd_adjust->psb_adc;
|
||||||
if (ABS(current_adc - mode_pwmp_hd_adjust->adc_record_1) >= DIFF_ADC_MAX) // 阀位发生改变
|
if (ABS(current_adc - mode_pwmp_hd_adjust->adc_record_1) >= DIFF_ADC_MAX)
|
||||||
{
|
{
|
||||||
if (mode_pwmp_hd_adjust->arr_last > 4000)
|
if (mode_pwmp_hd_adjust->arr_last > 4000)
|
||||||
{
|
{
|
||||||
|
@ -479,14 +487,14 @@ static void pwmp_adjust_hd_rough_position0(uint8_t *state, mode_pwmp_hd_adjust_s
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/*得到一个粗略的,小于启动量的值*/
|
/*修正因启动值过大而导致的信号增加过大*/
|
||||||
mode_pwmp_hd_adjust->arr_record_1 = mode_pwmp_hd_adjust->arr_last > 1000 ? mode_pwmp_hd_adjust->arr_last * 0.9 : mode_pwmp_hd_adjust->arr_last;
|
mode_pwmp_hd_adjust->arr_record_1 = mode_pwmp_hd_adjust->arr_last > 1000 ? mode_pwmp_hd_adjust->arr_last * 0.9 : mode_pwmp_hd_adjust->arr_last;
|
||||||
/*判断位置反馈磁条是正装还是反装*/
|
/**/
|
||||||
mode_pwmp_hd_adjust->adc_0_100_flag = mode_pwmp_hd_adjust->adc_record_0 < current_adc ? TRUE : FALSE;
|
mode_pwmp_hd_adjust->adc_0_100_flag = mode_pwmp_hd_adjust->adc_record_0 < current_adc ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
*state = next_state;
|
*state = next_state;
|
||||||
}
|
}
|
||||||
else // 阀位未发生变化:继续增大输出
|
else
|
||||||
{
|
{
|
||||||
switch (s)
|
switch (s)
|
||||||
{
|
{
|
||||||
|
@ -499,11 +507,11 @@ static void pwmp_adjust_hd_rough_position0(uint8_t *state, mode_pwmp_hd_adjust_s
|
||||||
mode_pwmp_hd_adjust->arr_last = mode_pwmp_hd_adjust->arr_current;
|
mode_pwmp_hd_adjust->arr_last = mode_pwmp_hd_adjust->arr_current;
|
||||||
if (mode_pwmp_hd_adjust->arr_last < 1000)
|
if (mode_pwmp_hd_adjust->arr_last < 1000)
|
||||||
{
|
{
|
||||||
mode_pwmp_hd_adjust->arr_current = mode_pwmp_hd_adjust->arr_current * 1.05;
|
mode_pwmp_hd_adjust->arr_current = mode_pwmp_hd_adjust->arr_current * 1.1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mode_pwmp_hd_adjust->arr_current = mode_pwmp_hd_adjust->arr_current * 1.02;
|
mode_pwmp_hd_adjust->arr_current = mode_pwmp_hd_adjust->arr_current * 1.05;
|
||||||
}
|
}
|
||||||
/*若输出信号为最大值时认定为整定错误*/
|
/*若输出信号为最大值时认定为整定错误*/
|
||||||
if (mode_pwmp_hd_adjust->arr_current > 4000)
|
if (mode_pwmp_hd_adjust->arr_current > 4000)
|
||||||
|
@ -514,7 +522,7 @@ static void pwmp_adjust_hd_rough_position0(uint8_t *state, mode_pwmp_hd_adjust_s
|
||||||
}
|
}
|
||||||
|
|
||||||
pdctrl_out(mode_pwmp_hd_adjust->arr_current);
|
pdctrl_out(mode_pwmp_hd_adjust->arr_current);
|
||||||
mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 40;
|
mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 20;
|
||||||
*state = PWMP_HD_ADJUST_ROUGH_POSITION0;
|
*state = PWMP_HD_ADJUST_ROUGH_POSITION0;
|
||||||
FSM_WAIT(*state); // 设置等待状态
|
FSM_WAIT(*state); // 设置等待状态
|
||||||
}
|
}
|
||||||
|
@ -538,7 +546,7 @@ static void pwmp_adjust_hd_rough_position0(uint8_t *state, mode_pwmp_hd_adjust_s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*放气值(0信号)的整定*/
|
/*不充不放值(0信号)的整定*/
|
||||||
static void pwmp_adjust_hd_bleeding_position0(uint8_t *state, mode_pwmp_hd_adjust_state_e next_state)
|
static void pwmp_adjust_hd_bleeding_position0(uint8_t *state, mode_pwmp_hd_adjust_state_e next_state)
|
||||||
{
|
{
|
||||||
BOOL flag = FALSE;
|
BOOL flag = FALSE;
|
||||||
|
@ -552,41 +560,32 @@ static void pwmp_adjust_hd_bleeding_position0(uint8_t *state, mode_pwmp_hd_adjus
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// if (mode_pwmp_hd_adjust->adc_0_100_flag)
|
if (mode_pwmp_hd_adjust->adc_0_100_flag)
|
||||||
// {
|
|
||||||
// if (mode_pwmp_hd_adjust->psb_adc <= mode_pwmp_hd_adjust->last_adc)
|
|
||||||
// {
|
|
||||||
// if (ABS(mode_pwmp_hd_adjust->psb_adc - mode_pwmp_hd_adjust->last_adc) > DIFF_ADC_MAX)
|
|
||||||
// {
|
|
||||||
// mode_pwmp_hd_adjust->arr_record_0 = mode_pwmp_hd_adjust->arr_last + DIFF_ADC_MAX;
|
|
||||||
// flag = TRUE;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// if (mode_pwmp_hd_adjust->psb_adc >= mode_pwmp_hd_adjust->last_adc)
|
|
||||||
// {
|
|
||||||
// if (ABS(mode_pwmp_hd_adjust->psb_adc - mode_pwmp_hd_adjust->last_adc) > DIFF_ADC_MAX)
|
|
||||||
// {
|
|
||||||
// mode_pwmp_hd_adjust->arr_record_0 = mode_pwmp_hd_adjust->arr_last + DIFF_ADC_MAX;
|
|
||||||
// flag = TRUE;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (ABS(mode_pwmp_hd_adjust->psb_adc - mode_pwmp_hd_adjust->adc_record_1) < 6)
|
|
||||||
{
|
{
|
||||||
mode_pwmp_hd_adjust->arr_record_0 = mode_pwmp_hd_adjust->arr_current;
|
if (mode_pwmp_hd_adjust->psb_adc <= mode_pwmp_hd_adjust->last_adc)
|
||||||
flag = TRUE;
|
{
|
||||||
|
if (ABS(mode_pwmp_hd_adjust->psb_adc - mode_pwmp_hd_adjust->last_adc) > DIFF_ADC_MAX)
|
||||||
|
{
|
||||||
|
mode_pwmp_hd_adjust->arr_record_0 = mode_pwmp_hd_adjust->arr_last + DIFF_ADC_MAX;
|
||||||
|
flag = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (mode_pwmp_hd_adjust->psb_adc >= mode_pwmp_hd_adjust->last_adc)
|
||||||
|
{
|
||||||
|
if (ABS(mode_pwmp_hd_adjust->psb_adc - mode_pwmp_hd_adjust->last_adc) > DIFF_ADC_MAX)
|
||||||
|
{
|
||||||
|
mode_pwmp_hd_adjust->arr_record_0 = mode_pwmp_hd_adjust->arr_last + DIFF_ADC_MAX;
|
||||||
|
flag = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flag == TRUE)
|
if (flag == TRUE)
|
||||||
{
|
{
|
||||||
mode_pwmp_hd_adjust->arr_record_2 = 4095; // 给定最大值输出
|
|
||||||
*state = next_state;
|
*state = next_state;
|
||||||
pdctrl_out(0); // 这里要先放气5秒然后计算全开时间
|
|
||||||
mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 50;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -598,13 +597,13 @@ static void pwmp_adjust_hd_bleeding_position0(uint8_t *state, mode_pwmp_hd_adjus
|
||||||
mode_pwmp_hd_adjust->arr_current = last - 4;
|
mode_pwmp_hd_adjust->arr_current = last - 4;
|
||||||
|
|
||||||
pdctrl_out(mode_pwmp_hd_adjust->arr_current);
|
pdctrl_out(mode_pwmp_hd_adjust->arr_current);
|
||||||
if (ABS(mode_pwmp_hd_adjust->psb_adc - mode_pwmp_hd_adjust->last_adc) > 6)
|
if (ABS(mode_pwmp_hd_adjust->psb_adc - mode_pwmp_hd_adjust->last_adc) > 4)
|
||||||
{
|
{
|
||||||
mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 10;
|
mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 10;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 30;
|
mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 30;
|
||||||
}
|
}
|
||||||
|
|
||||||
mode_pwmp_hd_adjust->last_adc = mode_pwmp_hd_adjust->psb_adc;
|
mode_pwmp_hd_adjust->last_adc = mode_pwmp_hd_adjust->psb_adc;
|
||||||
|
@ -613,69 +612,68 @@ static void pwmp_adjust_hd_bleeding_position0(uint8_t *state, mode_pwmp_hd_adjus
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// /*启动值细调*/
|
/*启动值细调*/
|
||||||
// static void pwmp_adjust_hd_accurate_position0(uint8_t *state, mode_pwmp_hd_adjust_state_e next_state)
|
static void pwmp_adjust_hd_accurate_position0(uint8_t *state, mode_pwmp_hd_adjust_state_e next_state)
|
||||||
// {
|
{
|
||||||
// uint16_t current_adc = 0;
|
// 精确的找到最小推动值
|
||||||
// if (!FSM_IS_WAIT(*state))
|
uint16_t current_adc = 0;
|
||||||
// {
|
if (!FSM_IS_WAIT(*state))
|
||||||
// mode_pwmp_hd_adjust->arr_current = mode_pwmp_hd_adjust->arr_record_1;
|
{
|
||||||
// mode_pwmp_hd_adjust->arr_last = mode_pwmp_hd_adjust->arr_current;
|
mode_pwmp_hd_adjust->arr_current = mode_pwmp_hd_adjust->arr_record_1;
|
||||||
// mode_pwmp_hd_adjust->adjust_state = (mode_pwmp_hd_adjust_state_e)*state;
|
mode_pwmp_hd_adjust->arr_last = mode_pwmp_hd_adjust->arr_current;
|
||||||
// FSM_WAIT(mode_pwmp_hd_adjust->adjust_state);
|
mode_pwmp_hd_adjust->adjust_state = (mode_pwmp_hd_adjust_state_e)*state;
|
||||||
// *state = PWMP_HD_ADJUST_BLEEDING;
|
FSM_WAIT(mode_pwmp_hd_adjust->adjust_state);
|
||||||
// }
|
*state = PWMP_HD_ADJUST_BLEEDING;
|
||||||
// else
|
}
|
||||||
// {
|
else
|
||||||
// valve_position_change_e s = pwmp_adjust_hd_valve_position_change(state, next_state, DIFF_ADC_MAX);
|
{
|
||||||
|
valve_position_change_e s = pwmp_adjust_hd_valve_position_change(state, next_state, DIFF_ADC_MAX * 10);
|
||||||
|
|
||||||
// current_adc = pid_autotune_hd->data.adjust_tmp_actual;
|
current_adc = mode_pwmp_hd_adjust->psb_adc;
|
||||||
// /*执行器发生动作*/
|
/*执行器发生动作*/
|
||||||
// if (ABS(current_adc - mode_pwmp_hd_adjust->adc_record_1) >= DIFF_ADC_MAX)
|
if (ABS(current_adc - mode_pwmp_hd_adjust->adc_record_1) >= DIFF_ADC_MAX)
|
||||||
// {
|
{
|
||||||
// mode_pwmp_hd_adjust->arr_record_1 = mode_pwmp_hd_adjust->arr_last;
|
mode_pwmp_hd_adjust->arr_record_1 = mode_pwmp_hd_adjust->arr_last;
|
||||||
// mode_pwmp_hd_adjust->arr_record_2 = 4095; // 给定最大值输出
|
mode_pwmp_hd_adjust->arr_record_2 = mode_pwmp_hd_adjust->arr_last + 100 < 4000 ? mode_pwmp_hd_adjust->arr_last + 100 : 100;
|
||||||
// *state = next_state;
|
*state = next_state;
|
||||||
// pdctrl_out(0); // 这里要先放气5秒然后计算全开时间
|
pdctrl_out(0); // 这里要先放气5秒然后计算全开时间
|
||||||
// mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 50;
|
mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 50;
|
||||||
// }
|
}
|
||||||
// else
|
else
|
||||||
// {
|
{
|
||||||
// switch (s)
|
switch (s)
|
||||||
// {
|
{
|
||||||
// case POSITION_NO_CHANGE_FOREVER: // 位置不再改变
|
case POSITION_NO_CHANGE_FOREVER: // 位置不再改变
|
||||||
// {
|
{
|
||||||
// /*若执行器在0位置*/
|
if (ABS(current_adc - mode_pwmp_hd_adjust->adc_record_1) <= DIFF_ADC_MAX)
|
||||||
// if (ABS(current_adc - mode_pwmp_hd_adjust->adc_record_1) <= DIFF_ADC_MAX)
|
{
|
||||||
// {
|
// 没有发生变化
|
||||||
// // 阀位没有发生变化,以每6增大信号输出
|
mode_pwmp_hd_adjust->arr_last = mode_pwmp_hd_adjust->arr_current;
|
||||||
// mode_pwmp_hd_adjust->arr_last = mode_pwmp_hd_adjust->arr_current;
|
mode_pwmp_hd_adjust->arr_current = mode_pwmp_hd_adjust->arr_current + DIFF_ADC_MAX;
|
||||||
// mode_pwmp_hd_adjust->arr_current = mode_pwmp_hd_adjust->arr_current + 6;
|
pdctrl_out(mode_pwmp_hd_adjust->arr_current);
|
||||||
// pdctrl_out(mode_pwmp_hd_adjust->arr_current);
|
mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 5;
|
||||||
// mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 30;
|
*state = PWMP_HD_ADJUST_ACCURATE_POSITION0;
|
||||||
// *state = PWMP_HD_ADJUST_ACCURATE_POSITION0;
|
FSM_WAIT(*state); // 设置等待状态
|
||||||
// FSM_WAIT(*state); // 设置等待状态
|
}
|
||||||
// }
|
else
|
||||||
// else
|
{
|
||||||
// {
|
DBG_ASSERT(FALSE __DBG_LINE);
|
||||||
// DBG_ASSERT(FALSE __DBG_LINE);
|
}
|
||||||
// }
|
break;
|
||||||
// break;
|
}
|
||||||
// }
|
case POSITION_CHANGE:
|
||||||
// case POSITION_CHANGE:
|
DBG_ASSERT(FALSE __DBG_LINE);
|
||||||
// DBG_ASSERT(FALSE __DBG_LINE);
|
break;
|
||||||
// break;
|
default:
|
||||||
// default:
|
break;
|
||||||
// break;
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
/*粗略整定得到满位置adc位置反馈*/
|
/*粗略整定冲顶值*/
|
||||||
static void pwmp_adjust_hd_rough_position100(uint8_t *state, mode_pwmp_hd_adjust_state_e next_state)
|
static void pwmp_adjust_hd_rough_position100(uint8_t *state, mode_pwmp_hd_adjust_state_e next_state)
|
||||||
{
|
{
|
||||||
uint16_t current_adc = 0;
|
|
||||||
// 找最大推动值arr
|
// 找最大推动值arr
|
||||||
if (!FSM_IS_WAIT(*state))
|
if (!FSM_IS_WAIT(*state))
|
||||||
{
|
{
|
||||||
|
@ -687,25 +685,24 @@ static void pwmp_adjust_hd_rough_position100(uint8_t *state, mode_pwmp_hd_adjust
|
||||||
}
|
}
|
||||||
|
|
||||||
sys_millis_reset();
|
sys_millis_reset();
|
||||||
mode_pwmp_hd_adjust->all_open_time_full = sys_millis(); // 记录全开起始时间
|
mode_pwmp_hd_adjust->all_open_time = sys_millis(); // 记录全开起始时间
|
||||||
mode_pwmp_hd_adjust->tmp_time = 0;
|
mode_pwmp_hd_adjust->tmp_time = 0;
|
||||||
|
|
||||||
pdctrl_out(mode_pwmp_hd_adjust->arr_record_2); // 以最大值进行输出
|
pdctrl_out(mode_pwmp_hd_adjust->arr_record_2); // 以上一步求出的冲顶值进行输出
|
||||||
mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 50; // 等待时间设置为5s
|
mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 100;
|
||||||
mode_pwmp_hd_adjust->adjust_state = (mode_pwmp_hd_adjust_state_e)*state;
|
mode_pwmp_hd_adjust->adjust_state = (mode_pwmp_hd_adjust_state_e)*state;
|
||||||
FSM_WAIT(*state); // 设置等待状态
|
FSM_WAIT(*state); // 设置等待状态
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
valve_position_change_e s = pwmp_adjust_hd_valve_position_change(state, next_state, DIFF_ADC_MAX);
|
valve_position_change_e s = pwmp_adjust_hd_valve_position_change(state, next_state, DIFF_ADC_MAX);
|
||||||
current_adc = pid_autotune_hd->data.adjust_tmp_actual;
|
|
||||||
|
|
||||||
switch (s)
|
switch (s)
|
||||||
{
|
{
|
||||||
case POSITION_NO_CHANGE_FOREVER:
|
case POSITION_NO_CHANGE_FOREVER:
|
||||||
// 位置不再改变,记录此时阀门位置AD值
|
// 位置不再改变,记录此时阀门位置AD值
|
||||||
mode_pwmp_hd_adjust->adc_record_2 = current_adc;
|
mode_pwmp_hd_adjust->adc_record_2 = mode_pwmp_hd_adjust->psb_adc;
|
||||||
mode_pwmp_hd_adjust->all_open_time_full = mode_pwmp_hd_adjust->tmp_time - mode_pwmp_hd_adjust->all_open_time_full;
|
mode_pwmp_hd_adjust->all_open_time = mode_pwmp_hd_adjust->tmp_time - mode_pwmp_hd_adjust->all_open_time;
|
||||||
break;
|
break;
|
||||||
case POSITION_CHANGE:
|
case POSITION_CHANGE:
|
||||||
mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 50;
|
mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 50;
|
||||||
|
@ -726,10 +723,13 @@ static void pwmp_adjust_hd_rough_position100(uint8_t *state, mode_pwmp_hd_adjust
|
||||||
/*精调冲顶值*/
|
/*精调冲顶值*/
|
||||||
static void pwmp_adjust_hd_accurate_position100(uint8_t *state, mode_pwmp_hd_adjust_state_e next_state)
|
static void pwmp_adjust_hd_accurate_position100(uint8_t *state, mode_pwmp_hd_adjust_state_e next_state)
|
||||||
{
|
{
|
||||||
|
// 精确找最大推动值arr
|
||||||
|
uint16_t current_adc = 0;
|
||||||
if (!FSM_IS_WAIT(*state))
|
if (!FSM_IS_WAIT(*state))
|
||||||
{
|
{
|
||||||
mode_pwmp_hd_adjust->all_close_time_flag = TRUE;
|
mode_pwmp_hd_adjust->all_close_time_flag = TRUE;
|
||||||
mode_pwmp_hd_adjust->arr_current = mode_pwmp_hd_adjust->arr_record_1; // 初始值为前一步整定出的最小启动值
|
|
||||||
|
mode_pwmp_hd_adjust->arr_current = mode_pwmp_hd_adjust->arr_record_1;
|
||||||
mode_pwmp_hd_adjust->arr_last = mode_pwmp_hd_adjust->arr_current;
|
mode_pwmp_hd_adjust->arr_last = mode_pwmp_hd_adjust->arr_current;
|
||||||
mode_pwmp_hd_adjust->adjust_state = (mode_pwmp_hd_adjust_state_e)*state;
|
mode_pwmp_hd_adjust->adjust_state = (mode_pwmp_hd_adjust_state_e)*state;
|
||||||
mode_pwmp_hd_adjust->preheat = TRUE;
|
mode_pwmp_hd_adjust->preheat = TRUE;
|
||||||
|
@ -739,10 +739,9 @@ static void pwmp_adjust_hd_accurate_position100(uint8_t *state, mode_pwmp_hd_adj
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
valve_position_change_e s = pwmp_adjust_hd_valve_position_change(state, next_state, DIFF_ADC_MAX);
|
valve_position_change_e s = pwmp_adjust_hd_valve_position_change(state, next_state, DIFF_ADC_MAX);
|
||||||
mode_pwmp_hd_adjust->psb_adc = pid_autotune_hd->data.adjust_tmp_actual;
|
|
||||||
|
|
||||||
/*当前反馈AD值与最大位置AD值的差值*/
|
current_adc = mode_pwmp_hd_adjust->psb_adc;
|
||||||
uint16_t adc_diff = ABS(mode_pwmp_hd_adjust->psb_adc - mode_pwmp_hd_adjust->adc_record_2);
|
uint16_t adc_diff = ABS(current_adc - mode_pwmp_hd_adjust->adc_record_2);
|
||||||
|
|
||||||
if (mode_pwmp_hd_adjust->arr_current == 0 && mode_pwmp_hd_adjust->preheat == TRUE)
|
if (mode_pwmp_hd_adjust->arr_current == 0 && mode_pwmp_hd_adjust->preheat == TRUE)
|
||||||
{
|
{
|
||||||
|
@ -776,7 +775,7 @@ static void pwmp_adjust_hd_accurate_position100(uint8_t *state, mode_pwmp_hd_adj
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 20;
|
mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
mode_pwmp_hd_adjust->last_adc = mode_pwmp_hd_adjust->psb_adc;
|
mode_pwmp_hd_adjust->last_adc = mode_pwmp_hd_adjust->psb_adc;
|
||||||
|
@ -797,7 +796,7 @@ static void pwmp_adjust_hd_accurate_position100(uint8_t *state, mode_pwmp_hd_adj
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 20;
|
mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -807,100 +806,19 @@ static void pwmp_adjust_hd_accurate_position100(uint8_t *state, mode_pwmp_hd_adj
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*计算控制的全关时间:以ATO类型角度命名*/
|
|
||||||
static void pwmp_adjust_hd_all_close_time(uint8_t *state, mode_pwmp_hd_adjust_state_e next_state)
|
|
||||||
{
|
|
||||||
if (!FSM_IS_WAIT(*state))
|
|
||||||
{
|
|
||||||
mode_pwmp_hd_adjust->arr_current = mode_pwmp_hd_adjust->arr_record_0 - 100; // 此处的输入信号大小根据实际控制的最小值来设定
|
|
||||||
|
|
||||||
/*记录起始的全开时间*/
|
|
||||||
sys_millis_reset();
|
|
||||||
mode_pwmp_hd_adjust->all_close_time = sys_millis();
|
|
||||||
mode_pwmp_hd_adjust->tmp_time = 0;
|
|
||||||
|
|
||||||
pdctrl_out(mode_pwmp_hd_adjust->arr_current);
|
|
||||||
FSM_WAIT(*state); // 设置等待状态
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mode_pwmp_hd_adjust->psb_adc = get_actual_travel_adc();
|
|
||||||
if (abs(mode_pwmp_hd_adjust->psb_adc - mode_pwmp_hd_adjust->adc_record_0) < DIFF_ADC_MAX)
|
|
||||||
{
|
|
||||||
if (uDevice.eAirAction == ATO) // 若调节阀为气开阀
|
|
||||||
{
|
|
||||||
mode_pwmp_hd_adjust->tmp_time = sys_millis();
|
|
||||||
mode_pwmp_hd_adjust->all_close_time = mode_pwmp_hd_adjust->tmp_time - mode_pwmp_hd_adjust->all_close_time;
|
|
||||||
}
|
|
||||||
else // 若调节阀为气关阀
|
|
||||||
{
|
|
||||||
mode_pwmp_hd_adjust->tmp_time = sys_millis();
|
|
||||||
mode_pwmp_hd_adjust->all_open_time = mode_pwmp_hd_adjust->tmp_time - mode_pwmp_hd_adjust->all_close_time;
|
|
||||||
}
|
|
||||||
*state = next_state;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*计算控制的全开时间*/
|
|
||||||
static void pwmp_adjust_hd_all_open_time(uint8_t *state, mode_pwmp_hd_adjust_state_e next_state)
|
|
||||||
{
|
|
||||||
if (!FSM_IS_WAIT(*state))
|
|
||||||
{
|
|
||||||
mode_pwmp_hd_adjust->arr_current = mode_pwmp_hd_adjust->arr_record_2 + 100; // 此处的输入信号大小根据实际控制的最大值来设定
|
|
||||||
|
|
||||||
/*记录起始的全开时间*/
|
|
||||||
sys_millis_reset();
|
|
||||||
mode_pwmp_hd_adjust->all_open_time = sys_millis();
|
|
||||||
mode_pwmp_hd_adjust->tmp_time = 0;
|
|
||||||
|
|
||||||
pdctrl_out(mode_pwmp_hd_adjust->arr_current);
|
|
||||||
FSM_WAIT(*state); // 设置等待状态
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mode_pwmp_hd_adjust->psb_adc = get_actual_travel_adc();
|
|
||||||
if (abs(mode_pwmp_hd_adjust->psb_adc - mode_pwmp_hd_adjust->adc_record_2) < DIFF_ADC_MAX)
|
|
||||||
{
|
|
||||||
if (uDevice.eAirAction == ATO)
|
|
||||||
{
|
|
||||||
mode_pwmp_hd_adjust->tmp_time = sys_millis();
|
|
||||||
mode_pwmp_hd_adjust->all_open_time = mode_pwmp_hd_adjust->tmp_time - mode_pwmp_hd_adjust->all_open_time;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mode_pwmp_hd_adjust->tmp_time = sys_millis();
|
|
||||||
mode_pwmp_hd_adjust->all_close_time = mode_pwmp_hd_adjust->tmp_time - mode_pwmp_hd_adjust->all_open_time;
|
|
||||||
}
|
|
||||||
*state = next_state;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*计算阀门自整定参数*/
|
/*计算阀门自整定参数*/
|
||||||
static void pwmp_adjust_hd_calculate(uint8_t *state, mode_pwmp_hd_adjust_state_e next_state)
|
static void pwmp_adjust_hd_calculate(uint8_t *state, mode_pwmp_hd_adjust_state_e next_state)
|
||||||
{
|
{
|
||||||
if (!FSM_IS_WAIT(*state))
|
if (!FSM_IS_WAIT(*state))
|
||||||
{
|
{
|
||||||
/*行程上下限*/
|
|
||||||
mode_pwmp_hd->pwmp_save->storage.trip_0 = mode_pwmp_hd_adjust->adc_record_0;
|
mode_pwmp_hd->pwmp_save->storage.trip_0 = mode_pwmp_hd_adjust->adc_record_0;
|
||||||
mode_pwmp_hd->pwmp_save->storage.trip_100 = mode_pwmp_hd_adjust->adc_record_2;
|
mode_pwmp_hd->pwmp_save->storage.trip_100 = mode_pwmp_hd_adjust->adc_record_2;
|
||||||
mode_pwmp_hd->pwmp_save->storage.ad_diff = ABS(mode_pwmp_hd->pwmp_save->storage.trip_0 - mode_pwmp_hd->pwmp_save->storage.trip_100);
|
mode_pwmp_hd->pwmp_save->storage.ad_diff = ABS(mode_pwmp_hd->pwmp_save->storage.trip_0 - mode_pwmp_hd->pwmp_save->storage.trip_100);
|
||||||
|
|
||||||
/*控制区间*/
|
mode_pwmp_hd->pwmp_save->storage.pwmp_max = mode_pwmp_hd_adjust->arr_record_2;
|
||||||
mode_pwmp_hd->pwmp_save->storage.pwmp_max_origin = mode_pwmp_hd_adjust->arr_record_2;
|
mode_pwmp_hd->pwmp_save->storage.pwmp_min = mode_pwmp_hd_adjust->arr_record_0;
|
||||||
mode_pwmp_hd->pwmp_save->storage.pwmp_min_origin = mode_pwmp_hd_adjust->arr_record_0;
|
mode_pwmp_hd->pwmp_save->storage.arr_diff = ABS(mode_pwmp_hd->pwmp_save->storage.pwmp_max - mode_pwmp_hd->pwmp_save->storage.pwmp_min);
|
||||||
mode_pwmp_hd->pwmp_save->storage.arr_diff = ABS(mode_pwmp_hd_adjust->arr_record_2 - mode_pwmp_hd_adjust->arr_record_0);
|
|
||||||
mode_pwmp_hd->pwmp_save->storage.pwmp_max = mode_pwmp_hd_adjust->arr_record_2 + (mode_pwmp_hd->pwmp_save->storage.arr_diff * 0.2);
|
|
||||||
mode_pwmp_hd->pwmp_save->storage.pwmp_min = mode_pwmp_hd_adjust->arr_record_0 - (mode_pwmp_hd->pwmp_save->storage.arr_diff * 0.2);
|
|
||||||
|
|
||||||
/*启动值*/
|
|
||||||
mode_pwmp_hd->pwmp_save->storage.startup_value = mode_pwmp_hd_adjust->adc_record_1;
|
|
||||||
|
|
||||||
/*全开及全关时间*/
|
|
||||||
mode_pwmp_hd->pwmp_save->storage.all_open_time = mode_pwmp_hd_adjust->all_open_time;
|
|
||||||
mode_pwmp_hd->pwmp_save->storage.all_close_time = mode_pwmp_hd_adjust->all_close_time;
|
|
||||||
/*判断调节阀类型(气开/气关),对最低行程和最高行程进行标定*/
|
|
||||||
if (uDevice.eAirAction == ATO)
|
if (uDevice.eAirAction == ATO)
|
||||||
{
|
{
|
||||||
mode_pwmp_hd->pwmp_save->storage.trip_100 = mode_pwmp_hd->pwmp_save->storage.trip_100;
|
mode_pwmp_hd->pwmp_save->storage.trip_100 = mode_pwmp_hd->pwmp_save->storage.trip_100;
|
||||||
|
@ -941,8 +859,15 @@ static void pwmp_adjust_hd_calculate(uint8_t *state, mode_pwmp_hd_adjust_state_e
|
||||||
/*排气状态*/
|
/*排气状态*/
|
||||||
static void pwmp_adjust_hd_bleeding(uint8_t *state)
|
static void pwmp_adjust_hd_bleeding(uint8_t *state)
|
||||||
{
|
{
|
||||||
|
uint16_t current_adc = 0;
|
||||||
if (!FSM_IS_WAIT(*state))
|
if (!FSM_IS_WAIT(*state))
|
||||||
{
|
{
|
||||||
|
if (mode_pwmp_hd_adjust->all_close_time_flag == TRUE)
|
||||||
|
{
|
||||||
|
sys_millis_reset();
|
||||||
|
mode_pwmp_hd_adjust->all_close_time = sys_millis(); // 记录全关起始时间
|
||||||
|
mode_pwmp_hd_adjust->tmp_time = 0;
|
||||||
|
}
|
||||||
mode_pwmp_hd_adjust->arr_current = mode_pwmp_hd_adjust->arr_default;
|
mode_pwmp_hd_adjust->arr_current = mode_pwmp_hd_adjust->arr_default;
|
||||||
mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 80;
|
mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 80;
|
||||||
pdctrl_out(0);
|
pdctrl_out(0);
|
||||||
|
@ -951,17 +876,22 @@ static void pwmp_adjust_hd_bleeding(uint8_t *state)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
valve_position_change_e s = pwmp_adjust_hd_valve_position_change(state, mode_pwmp_hd_adjust->adjust_state, DIFF_ADC_MAX);
|
valve_position_change_e s = pwmp_adjust_hd_valve_position_change(state, mode_pwmp_hd_adjust->adjust_state, DIFF_ADC_MAX);
|
||||||
mode_pwmp_hd_adjust->psb_adc = mode_pwmp_hd_adjust->psb_adc;
|
current_adc = mode_pwmp_hd_adjust->psb_adc;
|
||||||
switch (s)
|
switch (s)
|
||||||
{
|
{
|
||||||
case POSITION_NO_CHANGE_FOREVER:
|
case POSITION_NO_CHANGE_FOREVER:
|
||||||
mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 50; // 排气状态结束后在跳转后的状态中等待5s
|
mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 30; // 排气状态结束后在跳转后的状态中等待3s
|
||||||
mode_pwmp_hd_adjust->arr_current = 0;
|
mode_pwmp_hd_adjust->arr_current = 0;
|
||||||
// if (mode_pwmp_hd_adjust->psb_adc != mode_pwmp_hd_adjust->adc_record_1)
|
if (current_adc != mode_pwmp_hd_adjust->adc_record_1)
|
||||||
// {
|
{
|
||||||
// mode_pwmp_hd_adjust->adc_record_1 = mode_pwmp_hd_adjust->psb_adc;
|
mode_pwmp_hd_adjust->adc_record_1 = current_adc;
|
||||||
// mode_pwmp_hd->pwmp_save->storage.trip_0 = mode_pwmp_hd_adjust->psb_adc;
|
mode_pwmp_hd->pwmp_save->storage.trip_0 = current_adc;
|
||||||
// }
|
}
|
||||||
|
if (mode_pwmp_hd_adjust->all_close_time_flag == TRUE)
|
||||||
|
{
|
||||||
|
mode_pwmp_hd_adjust->all_close_time = mode_pwmp_hd_adjust->tmp_time - mode_pwmp_hd_adjust->all_close_time;
|
||||||
|
mode_pwmp_hd_adjust->all_close_time_flag = FALSE;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case POSITION_CHANGE:
|
case POSITION_CHANGE:
|
||||||
if (mode_pwmp_hd_adjust->adc_record_0 == 0)
|
if (mode_pwmp_hd_adjust->adc_record_0 == 0)
|
||||||
|
@ -975,6 +905,18 @@ static void pwmp_adjust_hd_bleeding(uint8_t *state)
|
||||||
mode_pwmp_hd_adjust->tmp_time = 0;
|
mode_pwmp_hd_adjust->tmp_time = 0;
|
||||||
break;
|
break;
|
||||||
case POSITION_NO_CHANGE:
|
case POSITION_NO_CHANGE:
|
||||||
|
if (mode_pwmp_hd_adjust->all_close_time_flag == TRUE)
|
||||||
|
{
|
||||||
|
if (mode_pwmp_hd_adjust->tmp_time == 0)
|
||||||
|
{
|
||||||
|
mode_pwmp_hd_adjust->tmp_time = sys_millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ABS(current_adc - mode_pwmp_hd_adjust->adc_record_0) > 50)
|
||||||
|
{
|
||||||
|
mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 80;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
*state = PWMP_HD_ADJUST_STOP;
|
*state = PWMP_HD_ADJUST_STOP;
|
||||||
|
@ -1025,9 +967,8 @@ static void pwmp_adjust_hd_PID_tuning(uint8_t *state, mode_pwmp_hd_adjust_state_
|
||||||
/*整定方法选择*/
|
/*整定方法选择*/
|
||||||
pid_autotune_way_set(PID_AUTOTUNE_WAY_ZN);
|
pid_autotune_way_set(PID_AUTOTUNE_WAY_ZN);
|
||||||
/*阶跃信号设置*/
|
/*阶跃信号设置*/
|
||||||
pid_autotune_hd->data.step_signal = mode_pwmp_hd_adjust->arr_record_2;
|
set_step_signal(FULL_TRIP_SIGNAL);
|
||||||
pdctrl_out(pid_autotune_hd->data.step_signal);
|
mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 40; // 等待八秒
|
||||||
mode_pwmp_hd_adjust->wait_count = mode_pwmp_hd->wait_count_max * 40; // 等待四秒
|
|
||||||
FSM_WAIT(*state); // 设置等待状态
|
FSM_WAIT(*state); // 设置等待状态
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1046,6 +987,8 @@ static void pwmp_adjust_hd_PID_tuning(uint8_t *state, mode_pwmp_hd_adjust_state_
|
||||||
{
|
{
|
||||||
pid_autotune_hd->data.slope = pid_autotune_hd->data.actual_error / TIME_CYCLE;
|
pid_autotune_hd->data.slope = pid_autotune_hd->data.actual_error / TIME_CYCLE;
|
||||||
}
|
}
|
||||||
|
/*K的计算*/
|
||||||
|
pid_autotune_hd->k_hd = 1;
|
||||||
/*记录下变化率最大点值及行程坐标、时间*/
|
/*记录下变化率最大点值及行程坐标、时间*/
|
||||||
if (pid_autotune_hd->data.slope > pid_autotune_hd->data.slope_Max)
|
if (pid_autotune_hd->data.slope > pid_autotune_hd->data.slope_Max)
|
||||||
{
|
{
|
||||||
|
@ -1071,9 +1014,6 @@ static void pwmp_adjust_hd_PID_tuning(uint8_t *state, mode_pwmp_hd_adjust_state_
|
||||||
pid_autotune_hd->l_hd = get_time_tangent(0);
|
pid_autotune_hd->l_hd = get_time_tangent(0);
|
||||||
/*求得时间系数T*/
|
/*求得时间系数T*/
|
||||||
pid_autotune_hd->t_hd = get_time_tangent(pid_autotune_hd->data.actual_stable) - pid_autotune_hd->l_hd;
|
pid_autotune_hd->t_hd = get_time_tangent(pid_autotune_hd->data.actual_stable) - pid_autotune_hd->l_hd;
|
||||||
/*K的计算*/
|
|
||||||
pid_autotune_hd->k_hd = ((pid_autotune_hd->data.actual_stable) / (mode_pwmp_hd_adjust->adc_record_2 - mode_pwmp_hd_adjust->adc_record_0)) / ((pid_autotune_hd->data.step_signal) / (mode_pwmp_hd_adjust->arr_record_2 - mode_pwmp_hd_adjust->arr_record_0));
|
|
||||||
|
|
||||||
*state = next_state;
|
*state = next_state;
|
||||||
break;
|
break;
|
||||||
case POSITION_CHANGE:
|
case POSITION_CHANGE:
|
||||||
|
@ -1122,9 +1062,9 @@ static void pwmp_adjust_hd_pid_calculate(uint8_t *state, mode_pwmp_hd_adjust_sta
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
mode_pwmp_hd->pwmp_save->storage.kp = fabs(pid_autotune_hd->p_auto_hd);
|
mode_pwmp_hd->pwmp_save->storage.kp = pid_autotune_hd->p_auto_hd;
|
||||||
mode_pwmp_hd->pwmp_save->storage.ki = fabs(pid_autotune_hd->i_auto_hd);
|
mode_pwmp_hd->pwmp_save->storage.ki = pid_autotune_hd->i_auto_hd;
|
||||||
mode_pwmp_hd->pwmp_save->storage.kd = fabs(pid_autotune_hd->d_auto_hd);
|
mode_pwmp_hd->pwmp_save->storage.kd = pid_autotune_hd->d_auto_hd;
|
||||||
*state = next_state; // 将状态切换
|
*state = next_state; // 将状态切换
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1163,22 +1103,16 @@ void pwmp_adjust(uint8_t *state)
|
||||||
pwmp_adjust_hd_rough_position0(state, PWMP_HD_ADJUST_BLEEDING_POSITION0);
|
pwmp_adjust_hd_rough_position0(state, PWMP_HD_ADJUST_BLEEDING_POSITION0);
|
||||||
break;
|
break;
|
||||||
case PWMP_HD_ADJUST_BLEEDING_POSITION0:
|
case PWMP_HD_ADJUST_BLEEDING_POSITION0:
|
||||||
pwmp_adjust_hd_bleeding_position0(state, PWMP_HD_ADJUST_ROUGH_POSITION100);
|
pwmp_adjust_hd_bleeding_position0(state, PWMP_HD_ADJUST_ACCURATE_POSITION0);
|
||||||
|
break;
|
||||||
|
case PWMP_HD_ADJUST_ACCURATE_POSITION0:
|
||||||
|
pwmp_adjust_hd_accurate_position0(state, PWMP_HD_ADJUST_ROUGH_POSITION100);
|
||||||
break;
|
break;
|
||||||
// case PWMP_HD_ADJUST_ACCURATE_POSITION0:
|
|
||||||
// pwmp_adjust_hd_accurate_position0(state, PWMP_HD_ADJUST_ROUGH_POSITION100);
|
|
||||||
// break;
|
|
||||||
case PWMP_HD_ADJUST_ROUGH_POSITION100:
|
case PWMP_HD_ADJUST_ROUGH_POSITION100:
|
||||||
pwmp_adjust_hd_rough_position100(state, PWMP_HD_ADJUST_ACCURATE_POSITION100);
|
pwmp_adjust_hd_rough_position100(state, PWMP_HD_ADJUST_ACCURATE_POSITION100);
|
||||||
break;
|
break;
|
||||||
case PWMP_HD_ADJUST_ACCURATE_POSITION100:
|
case PWMP_HD_ADJUST_ACCURATE_POSITION100:
|
||||||
pwmp_adjust_hd_accurate_position100(state, PWMP_HD_ADJUST_ALL_CLOSE_TIME);
|
pwmp_adjust_hd_accurate_position100(state, PWMP_HD_ADJUST_CALCULATE);
|
||||||
break;
|
|
||||||
case PWMP_HD_ADJUST_ALL_CLOSE_TIME:
|
|
||||||
pwmp_adjust_hd_all_close_time(state, PWMP_HD_ADJUST_ALL_OPEN_TIME);
|
|
||||||
break;
|
|
||||||
case PWMP_HD_ADJUST_ALL_OPEN_TIME:
|
|
||||||
pwmp_adjust_hd_all_open_time(state, PWMP_HD_ADJUST_CALCULATE);
|
|
||||||
break;
|
break;
|
||||||
case PWMP_HD_ADJUST_CALCULATE:
|
case PWMP_HD_ADJUST_CALCULATE:
|
||||||
pwmp_adjust_hd_calculate(state, PWMP_HD_ADJUST_PID_TUNING);
|
pwmp_adjust_hd_calculate(state, PWMP_HD_ADJUST_PID_TUNING);
|
||||||
|
@ -1196,7 +1130,7 @@ void pwmp_adjust(uint8_t *state)
|
||||||
pwmp_adjust_hd_bleeding(state);
|
pwmp_adjust_hd_bleeding(state);
|
||||||
break;
|
break;
|
||||||
case PWMP_HD_ADJUST_IDEL:
|
case PWMP_HD_ADJUST_IDEL:
|
||||||
pwmp_adjust_hd_idle(state, PWMP_HD_ADJUST_ROUGH_POSITION0);
|
pwmp_adjust_hd_idle(state, PWMP_HD_ADJUST_PID_TUNING);
|
||||||
break;
|
break;
|
||||||
case PWMP_HD_ADJUST_STOP:
|
case PWMP_HD_ADJUST_STOP:
|
||||||
pwmp_adjust_hd_stop(state);
|
pwmp_adjust_hd_stop(state);
|
||||||
|
@ -1269,7 +1203,7 @@ void mode_pwmp_hd_process(void)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sprintf(ble_data, "%f,%f,%f\r\n", mode_pwmp_hd->control.ctrl_feedback, mode_pwmp_hd->control.ctrl_target, mode_pwmp_hd->control.real_error);
|
sprintf(ble_data, "%f\r\n", mode_pwmp_hd->control.ctrl_feedback);
|
||||||
}
|
}
|
||||||
ble_len = osel_mstrlen((unsigned char *)ble_data);
|
ble_len = osel_mstrlen((unsigned char *)ble_data);
|
||||||
if (ble_len != 0)
|
if (ble_len != 0)
|
||||||
|
@ -1355,34 +1289,25 @@ void mode_pwmp_hd_init(uint16_t positioner_model, mode_pwmp_hd_params_u *params,
|
||||||
mode_pwmp_hd->pwmp_save = params;
|
mode_pwmp_hd->pwmp_save = params;
|
||||||
mode_pwmp_hd->params_save_cb = params_save_cb;
|
mode_pwmp_hd->params_save_cb = params_save_cb;
|
||||||
/*设定PWMP方式的工作模式*/
|
/*设定PWMP方式的工作模式*/
|
||||||
pwmp_hd_process_state_set(PWMP_HD_PROCESS_CONTROL);
|
pwmp_hd_process_state_set(PWMP_HD_PROCESS_TEST);
|
||||||
/*PID初始化*/
|
/*PID初始化*/
|
||||||
execute_pid_init(EXECUTE_PLAN);
|
execute_pid_init(EXECUTE_PLAN);
|
||||||
/*计数最大值*/
|
/*计数最大值*/
|
||||||
mode_pwmp_hd->wait_count_max = 100 / ((MODE_DEFAULT_AUTOLOAD + 1) * 0.1); // (=10,每减一消耗10ms,总消耗时间100ms)
|
mode_pwmp_hd->wait_count_max = 100 / ((MODE_DEFAULT_AUTOLOAD + 1) * 0.1); // (=10,每减一消耗10ms)
|
||||||
#if 0 // 手动控制接口
|
|
||||||
/*临时参数设置(后续整定)*/
|
/*临时参数设置(后续整定)*/
|
||||||
mode_pwmp_hd->pwmp_save->storage.trip_0 = 2579;
|
mode_pwmp_hd->pwmp_save->storage.trip_0 = 2583;
|
||||||
mode_pwmp_hd->pwmp_save->storage.trip_100 = 1727;
|
mode_pwmp_hd->pwmp_save->storage.trip_100 = 1722;
|
||||||
#if VIP_H_EN_HD == 1
|
#if VIP_H_EN_HD == 1
|
||||||
// /*大电流输出模式控制范围(fisher)*/
|
mode_pwmp_hd->pwmp_save->storage.pwmp_min = 500;
|
||||||
// mode_pwmp_hd->pwmp_save->storage.pwmp_min = 500;
|
mode_pwmp_hd->pwmp_save->storage.pwmp_max = 925;
|
||||||
// mode_pwmp_hd->pwmp_save->storage.pwmp_max = 925;
|
|
||||||
/*大电流输出模式控制范围(自制)*/
|
|
||||||
mode_pwmp_hd->pwmp_save->storage.pwmp_min = 518;
|
|
||||||
mode_pwmp_hd->pwmp_save->storage.pwmp_max = 716;
|
|
||||||
#else
|
#else
|
||||||
/*小电流输出模式控制范围*/
|
|
||||||
mode_pwmp_hd->pwmp_save->storage.pwmp_min = 1025;
|
mode_pwmp_hd->pwmp_save->storage.pwmp_min = 1025;
|
||||||
mode_pwmp_hd->pwmp_save->storage.pwmp_max = 2050;
|
mode_pwmp_hd->pwmp_save->storage.pwmp_max = 2050;
|
||||||
#endif
|
#endif
|
||||||
mode_pwmp_hd->pwmp_save->storage.valve_type = ATO; // 气开阀
|
mode_pwmp_hd->pwmp_save->storage.valve_type = ATO; // 气开阀
|
||||||
#if INTEGRAL_SEPARATION == 1
|
#if INTEGRAL_SEPARATION == 1
|
||||||
#if 1
|
#if 1
|
||||||
// mode_pwmp_hd->pwmp_save->storage.kp = 5;
|
mode_pwmp_hd->pwmp_save->storage.kp = 5;
|
||||||
// mode_pwmp_hd->pwmp_save->storage.ki = 0.02;
|
|
||||||
// mode_pwmp_hd->pwmp_save->storage.kd = 0.005;
|
|
||||||
mode_pwmp_hd->pwmp_save->storage.kp = 0.9;
|
|
||||||
mode_pwmp_hd->pwmp_save->storage.ki = 0.02;
|
mode_pwmp_hd->pwmp_save->storage.ki = 0.02;
|
||||||
mode_pwmp_hd->pwmp_save->storage.kd = 0.005;
|
mode_pwmp_hd->pwmp_save->storage.kd = 0.005;
|
||||||
#else
|
#else
|
||||||
|
@ -1395,9 +1320,8 @@ void mode_pwmp_hd_init(uint16_t positioner_model, mode_pwmp_hd_params_u *params,
|
||||||
mode_pwmp_hd->pwmp_save->storage.ki = 0.5619;
|
mode_pwmp_hd->pwmp_save->storage.ki = 0.5619;
|
||||||
mode_pwmp_hd->pwmp_save->storage.kd = 0.5504;
|
mode_pwmp_hd->pwmp_save->storage.kd = 0.5504;
|
||||||
#endif
|
#endif
|
||||||
|
/*阀门参数校准*/
|
||||||
#endif
|
// calib_parapos_perent();
|
||||||
/*保存参数*/
|
|
||||||
mode_pwmp_hd->params_save_cb();
|
mode_pwmp_hd->params_save_cb();
|
||||||
|
|
||||||
/*更新公共参数*/
|
/*更新公共参数*/
|
||||||
|
|
|
@ -3,8 +3,6 @@
|
||||||
|
|
||||||
float32 out_pos; // 位置式pid输出
|
float32 out_pos; // 位置式pid输出
|
||||||
float32 Kp_watch; // 观测Kp的大小
|
float32 Kp_watch; // 观测Kp的大小
|
||||||
float32 Ki_watch; // 观测Kp的大小
|
|
||||||
float32 Kd_watch; // 观测Kp的大小
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 杭电:设置增量式PID参数
|
/// 杭电:设置增量式PID参数
|
||||||
|
@ -18,11 +16,6 @@ static void _set_ctrl_prm_position(struct PID_HD *self, float32 kp, float32 ki,
|
||||||
pid_hd_position_t *pri = &self->pri_u.position;
|
pid_hd_position_t *pri = &self->pri_u.position;
|
||||||
osel_memset((uint8_t *)pri, 0, sizeof(pid_hd_position_t));
|
osel_memset((uint8_t *)pri, 0, sizeof(pid_hd_position_t));
|
||||||
|
|
||||||
/*观测传进来的Kp、Ki、Kd*/
|
|
||||||
Kp_watch = kp;
|
|
||||||
Ki_watch = ki;
|
|
||||||
Kd_watch = kd;
|
|
||||||
|
|
||||||
pri->kp = kp;
|
pri->kp = kp;
|
||||||
pri->ki = ki;
|
pri->ki = ki;
|
||||||
pri->kd = kd;
|
pri->kd = kd;
|
||||||
|
|
|
@ -95,11 +95,6 @@
|
||||||
*/
|
*/
|
||||||
#define FL_SEM_RELEASE(sem) FLOW_SEM_RELEASE((sem))
|
#define FL_SEM_RELEASE(sem) FLOW_SEM_RELEASE((sem))
|
||||||
|
|
||||||
/**
|
|
||||||
* 检测一个信号量是否被释放
|
|
||||||
*/
|
|
||||||
#define FL_SEM_IS_RELEASE(fl ,sem) FLOW_SEM_IS_RELEASE((fl), (sem))
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化一个软件定时器
|
* 初始化一个软件定时器
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -33,8 +33,6 @@
|
||||||
--(s)->count; \
|
--(s)->count; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define FLOW_SEM_RELEASE(s) (++(s)->count)
|
#define FLOW_SEM_RELEASE(s) (++(s)->count) // 释放信号量s的计数值
|
||||||
|
|
||||||
#define FLOW_SEM_IS_RELEASE(f, s) (flow_tick - (f)->time) < ((s)->time)
|
|
||||||
|
|
||||||
#endif /* __FLOW_SEM_H__ */
|
#endif /* __FLOW_SEM_H__ */
|
||||||
|
|
|
@ -21,8 +21,7 @@
|
||||||
#define __IO volatile
|
#define __IO volatile
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef unsigned char BOOL; /* boolean data */
|
typedef unsigned char BOOL; /* boolean data */
|
||||||
typedef unsigned char bool_t; /* boolean data */
|
|
||||||
|
|
||||||
#if !defined(__stdint_h) && !defined(_GCC_WRAP_STDINT_H)
|
#if !defined(__stdint_h) && !defined(_GCC_WRAP_STDINT_H)
|
||||||
typedef unsigned char uint8_t;
|
typedef unsigned char uint8_t;
|
||||||
|
|
|
@ -33,12 +33,12 @@ typedef struct
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint16_t size; // 滑动窗口大小
|
uint16_t size; // 滑动窗口大小
|
||||||
float32 *window; // 滑动窗口
|
float32 *window; // 滑动窗口
|
||||||
volatile float32 sum; // 滑动窗口和
|
float32 out; // 滤波结果
|
||||||
volatile float32 out; // 滤波结果
|
uint16_t index; // 滑动窗口索引
|
||||||
uint16_t index; // 滑动窗口索引
|
uint16_t sum;
|
||||||
} lpf_window_t; // 滑动窗口滤波器
|
} lpf_window_t; // 滑动窗口滤波器
|
||||||
|
|
||||||
void kalman_init(kalman_t *cfg);
|
void kalman_init(kalman_t *cfg);
|
||||||
void kalman_reset(kalman_t *cfg);
|
void kalman_reset(kalman_t *cfg);
|
||||||
|
|
|
@ -60,15 +60,14 @@ extern uint16_t crc16_compute(const uint8_t *const uc_ptr, uint16_t uc_len); //
|
||||||
extern uint8_t xor_compute(const uint8_t *const uc_ptr, uint16_t uc_len); // 异或校验
|
extern uint8_t xor_compute(const uint8_t *const uc_ptr, uint16_t uc_len); // 异或校验
|
||||||
extern uint8_t get_bit_num(uint8_t bit); // 获取bit位的值
|
extern uint8_t get_bit_num(uint8_t bit); // 获取bit位的值
|
||||||
extern BOOL is_bit_set(int x, int k); // 判断x的第k位是否为1
|
extern BOOL is_bit_set(int x, int k); // 判断x的第k位是否为1
|
||||||
extern uint8_t isLeap(uint16_t year); // 检查是否是闰年
|
extern uint8_t isLeap(uint16_t year); // 检查是否是闰年
|
||||||
extern uint16_t dayOfyear(uint16_t year, uint8_t month, uint8_t day); // 计算一年中的第几天
|
extern uint16_t dayOfyear(uint16_t year, uint8_t month, uint8_t day); // 计算一年中的第几天
|
||||||
extern uint16_t weekOfyear(uint16_t year, uint8_t month, uint8_t day); // 计算一年中的第几周
|
extern uint16_t weekOfyear(uint16_t year, uint8_t month, uint8_t day); // 计算一年中的第几周
|
||||||
extern uint8_t get_weekday(uint16_t year, uint8_t month, uint8_t day); // 获取今天星期几
|
extern uint8_t get_weekday(uint16_t year, uint8_t month, uint8_t day); // 获取今天星期几
|
||||||
extern uint8_t hex_format_dec(uint8_t hex); // 十六进制转十进制
|
extern uint8_t hex_format_dec(uint8_t hex); // 十六进制转十进制
|
||||||
extern uint8_t dec_format_hex(uint8_t dec); // 十进制转十六进制
|
extern uint8_t dec_format_hex(uint8_t dec); // 十进制转十六进制
|
||||||
extern void quicksort(uint16_t arr[], int low, int high); // 快速排序
|
|
||||||
|
|
||||||
extern uint32_t time2Stamp(rtc_date_t date, rtc_time_t time); // 北京时间转时间戳
|
uint32_t time2Stamp(rtc_date_t date, rtc_time_t time); // 北京时间转时间戳
|
||||||
extern void stamp2Time(uint32_t stamp, rtc_date_t *date, rtc_time_t *time); // 时间戳转北京时间
|
extern void stamp2Time(uint32_t stamp, rtc_date_t *date, rtc_time_t *time); // 时间戳转北京时间
|
||||||
|
|
||||||
#endif //__LIB_H
|
#endif //__LIB_H
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
// mem1内存参数设定.mem1完全处于内部SRAM里面.(设置内部SARM的内存池和内存表的参数)
|
// mem1内存参数设定.mem1完全处于内部SRAM里面.(设置内部SARM的内存池和内存表的参数)
|
||||||
#define MEM1_BLOCK_SIZE 32 // 一个内存块大小为32字节
|
#define MEM1_BLOCK_SIZE 32 // 一个内存块大小为32字节
|
||||||
#define MEM1_MAX_SIZE 20 * 1024 // 最大管理内存 1K (我们这个内存管理系统的内部SRAM可控制的内存大小)
|
#define MEM1_MAX_SIZE 30 * 1024 // 最大管理内存 1K (我们这个内存管理系统的内部SRAM可控制的内存大小)
|
||||||
#define MEM1_ALLOC_TABLE_SIZE MEM1_MAX_SIZE / MEM1_BLOCK_SIZE // 内存表大小(有多少块内存块)
|
#define MEM1_ALLOC_TABLE_SIZE MEM1_MAX_SIZE / MEM1_BLOCK_SIZE // 内存表大小(有多少块内存块)
|
||||||
|
|
||||||
// mem2内存参数设定.mem2的内存池处于外部SRAM里面
|
// mem2内存参数设定.mem2的内存池处于外部SRAM里面
|
||||||
|
|
|
@ -15,28 +15,16 @@
|
||||||
#define hal_int_state_t char
|
#define hal_int_state_t char
|
||||||
#ifdef STM32
|
#ifdef STM32
|
||||||
#include "stm32l4xx.h"
|
#include "stm32l4xx.h"
|
||||||
#define HAL_ENTER_CRITICAL(__HANDLE__) \
|
|
||||||
do \
|
|
||||||
{ \
|
|
||||||
if ((__HANDLE__)->Lock == HAL_LOCKED) \
|
|
||||||
{ \
|
|
||||||
return HAL_BUSY; \
|
|
||||||
} \
|
|
||||||
else \
|
|
||||||
{ \
|
|
||||||
(__HANDLE__)->Lock = HAL_LOCKED; \
|
|
||||||
} \
|
|
||||||
} while (0U)
|
|
||||||
|
|
||||||
#define HAL_EXIT_CRITICAL(__HANDLE__) \
|
#define HAL_ENTER_CRITICAL(s) \
|
||||||
do \
|
s = s; \
|
||||||
{ \
|
__ASM volatile("cpsid i");
|
||||||
(__HANDLE__)->Lock = HAL_UNLOCKED; \
|
#define HAL_EXIT_CRITICAL(s) \
|
||||||
} while (0U)
|
__ASM volatile("cpsie i");
|
||||||
#else
|
#else
|
||||||
#define HAL_ENTER_CRITICAL(__HANDLE__)
|
#define HAL_ENTER_CRITICAL(s)
|
||||||
|
|
||||||
#define HAL_EXIT_CRITICAL(__HANDLE__)
|
#define HAL_EXIT_CRITICAL(s)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -51,6 +39,7 @@
|
||||||
#define osel_mem_free2 _free2
|
#define osel_mem_free2 _free2
|
||||||
|
|
||||||
#define osel_mstrlen _mstrlen
|
#define osel_mstrlen _mstrlen
|
||||||
|
#define osel_quick_sort _quick_sort
|
||||||
|
|
||||||
static inline void *_malloc(uint32_t size)
|
static inline void *_malloc(uint32_t size)
|
||||||
{
|
{
|
||||||
|
@ -138,4 +127,32 @@ static inline unsigned int _mstrlen(const unsigned char *s)
|
||||||
return ss - s;
|
return ss - s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 快速排序
|
||||||
|
static inline void _quick_sort(uint16_t *array, int left, int right)
|
||||||
|
{
|
||||||
|
if (left >= right)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int i = left;
|
||||||
|
int j = right;
|
||||||
|
uint16_t key = array[left];
|
||||||
|
while (i < j)
|
||||||
|
{
|
||||||
|
while (i < j && array[j] > key)
|
||||||
|
{
|
||||||
|
j--;
|
||||||
|
}
|
||||||
|
array[i] = array[j];
|
||||||
|
while (i < j && array[i] <= key)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
array[j] = array[i];
|
||||||
|
}
|
||||||
|
array[i] = key;
|
||||||
|
_quick_sort(array, left, i - 1);
|
||||||
|
_quick_sort(array, i + 1, right);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // __OSEL_ARCH_H__
|
#endif // __OSEL_ARCH_H__
|
||||||
|
|
|
@ -81,8 +81,8 @@ static GUI_CONST_STORAGE unsigned char ac0032[60] = {
|
||||||
________, ______XX, XXX_____,
|
________, ______XX, XXX_____,
|
||||||
________, _______X, XX______};
|
________, _______X, XX______};
|
||||||
|
|
||||||
/* char: code:0x0033 */
|
/* char: code:0x0034 */
|
||||||
static GUI_CONST_STORAGE unsigned char ac0033[60] = {
|
static GUI_CONST_STORAGE unsigned char ac0034[60] = {
|
||||||
________, ________, ________,
|
________, ________, ________,
|
||||||
________, ________, ________,
|
________, ________, ________,
|
||||||
________, ________, ________,
|
________, ________, ________,
|
||||||
|
@ -104,90 +104,24 @@ static GUI_CONST_STORAGE unsigned char ac0033[60] = {
|
||||||
________, ________, ________,
|
________, ________, ________,
|
||||||
________, ________, ________};
|
________, ________, ________};
|
||||||
|
|
||||||
/* char: code:0x0034 */
|
static GUI_CONST_STORAGE GUI_CHARINFO Cinfo[4] = {
|
||||||
static GUI_CONST_STORAGE unsigned char ac0034[60] = {
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, _______X, ________,
|
|
||||||
___X____, _X____X_, X_______,
|
|
||||||
__X_X___, X_X__X__, ________,
|
|
||||||
___X____, _X____X_, X_______,
|
|
||||||
________, _______X, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________};
|
|
||||||
|
|
||||||
/* char: code:0x0035 */
|
|
||||||
static GUI_CONST_STORAGE unsigned char ac0035[60] = {
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
___X____, ________, ________,
|
|
||||||
__X_XX__, _X_____X, ________,
|
|
||||||
_____X__, X_X___X_, X_______,
|
|
||||||
__X_XX__, _X_____X, ________,
|
|
||||||
___X____, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________};
|
|
||||||
|
|
||||||
/* char: code:0x0036 */
|
|
||||||
static GUI_CONST_STORAGE unsigned char ac0036[60] = {
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, _X______, ________,
|
|
||||||
___X____, X_X____X, ________,
|
|
||||||
__X_X__X, ___X__X_, X_______,
|
|
||||||
___X____, X_X____X, ________,
|
|
||||||
________, _X______, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________,
|
|
||||||
________, ________, ________};
|
|
||||||
|
|
||||||
static GUI_CONST_STORAGE GUI_CHARINFO Cinfo[7] = {
|
|
||||||
{19, 19, 3, (unsigned char *)&ac0030}, /*0: */
|
{19, 19, 3, (unsigned char *)&ac0030}, /*0: */
|
||||||
{20, 20, 3, (unsigned char *)&ac0031}, /*1: */
|
{20, 20, 3, (unsigned char *)&ac0031}, /*1: */
|
||||||
{20, 20, 3, (unsigned char *)&ac0032}, /*2: */
|
{20, 20, 3, (unsigned char *)&ac0032}, /*2: */
|
||||||
{19, 19, 3, (unsigned char *)&ac0033}, /*3: */
|
{19, 19, 3, (unsigned char *)&ac0034}, /*3: */
|
||||||
{17, 17, 3, (unsigned char *)&ac0034}, /*4: */
|
|
||||||
{17, 17, 3, (unsigned char *)&ac0035}, /*5: */
|
|
||||||
{17, 17, 3, (unsigned char *)&ac0036}, /*6: */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static GUI_CONST_STORAGE GUI_FONT_PROP Prop2 = {
|
||||||
|
0x0034, /*start :*/
|
||||||
|
0x0034, /*end :, len=1*/
|
||||||
|
&Cinfo[3],
|
||||||
|
(void *)0};
|
||||||
|
|
||||||
static GUI_CONST_STORAGE GUI_FONT_PROP Prop1 = {
|
static GUI_CONST_STORAGE GUI_FONT_PROP Prop1 = {
|
||||||
0x0030, /*start :*/
|
0x0030, /*start :*/
|
||||||
0x0036, /*end :, len=7*/
|
0x0032, /*end :, len=3*/
|
||||||
&Cinfo[0],
|
&Cinfo[0],
|
||||||
(void *)0};
|
&Prop2};
|
||||||
|
|
||||||
GUI_CONST_STORAGE GUI_FONT GUI_FontHZ20x20 = {
|
GUI_CONST_STORAGE GUI_FONT GUI_FontHZ20x20 = {
|
||||||
GUI_FONTTYPE_PROP_SJIS,
|
GUI_FONTTYPE_PROP_SJIS,
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
定位器功能菜单介绍无江苏巨石数字技术有限公司实际行程目标报警提示自动手校验整详细设置备调试气作用电流输入范围开关显正常反类型直角速率增加
|
定位器功能菜单介绍无江苏巨石数字技术有限公司实际行程目标报警提示自动手校验整详细设置备调试气作用电流输入范围开关显正常反类型直角速率增加
|
||||||
减小下上供压力阀门特性信号切除值线等于快义闭使方式触发处理错误死区连续暂停待时间源次累计温度摩擦弹驱逻辑禁其他排量高级控制参准积分激活出传感选择语言中文向恢复厂否是诊断全允许移或启结束差最大混合滞后簧欢迎智版本主执机构地址日期编息双曲节通讯模块屏幕英工磁条在离确认保持完成存失败载取消进故障超规格检查要求维护测重算法变频平衡当前已域℃○●↑↓√
|
减小下上供压力阀门特性信号切除值线等于快义闭使方式触发处理错误死区连续暂停待时间源次累计温度摩擦弹驱逻辑禁其他排量高级控制参准积分激活出传感选择语言中文向恢复厂否是诊断全允许移或启结束差最大混合滞后簧欢迎智版本主执机构地址日期编息双曲节通讯模块屏幕英工磁条在离确认保持完成存失败载取消进故障超规格检查要求维护测重℃○●↑↓√
|
||||||
*/
|
*/
|
||||||
#ifndef __LCDS_H__
|
#ifndef __LCDS_H__
|
||||||
#define __LCDS_H__
|
#define __LCDS_H__
|
||||||
|
|
Binary file not shown.
|
@ -93,20 +93,20 @@ void lpf_reset(lpf_t *cfg)
|
||||||
/**
|
/**
|
||||||
* 滑动平均窗口滤波
|
* 滑动平均窗口滤波
|
||||||
*/
|
*/
|
||||||
lpf_window_t *lpf_window_init(uint16_t size)
|
lpf_window_t* lpf_window_init(uint16_t size)
|
||||||
{
|
{
|
||||||
lpf_window_t *cfg = (lpf_window_t *)osel_mem_alloc(sizeof(lpf_window_t));
|
lpf_window_t* cfg = (lpf_window_t*)osel_mem_alloc(sizeof(lpf_window_t));
|
||||||
DBG_ASSERT(cfg != NULL __DBG_LINE);
|
DBG_ASSERT(cfg != NULL __DBG_LINE);
|
||||||
osel_memset((uint8_t *)cfg, 0, sizeof(lpf_window_t));
|
osel_memset((uint8_t*)cfg, 0, sizeof(lpf_window_t));
|
||||||
cfg->size = size;
|
cfg->size = size;
|
||||||
cfg->window = (float32 *)osel_mem_alloc(sizeof(float32) * size);
|
cfg->window = (float32*)osel_mem_alloc(sizeof(float32) * size);
|
||||||
DBG_ASSERT(cfg->window != NULL __DBG_LINE);
|
DBG_ASSERT(cfg->window != NULL __DBG_LINE);
|
||||||
cfg->index = 0;
|
cfg->index = 0;
|
||||||
cfg->sum = 0;
|
cfg->sum = 0;
|
||||||
return cfg;
|
return cfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lpf_window_dinit(lpf_window_t *cfg)
|
void lpf_window_dinit(lpf_window_t* cfg)
|
||||||
{
|
{
|
||||||
if (cfg != NULL)
|
if (cfg != NULL)
|
||||||
{
|
{
|
||||||
|
@ -119,14 +119,14 @@ void lpf_window_dinit(lpf_window_t *cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 滑动平均窗口重置
|
// 滑动平均窗口重置
|
||||||
void lpf_window_reset(lpf_window_t *cfg)
|
void lpf_window_reset(lpf_window_t* cfg)
|
||||||
{
|
{
|
||||||
cfg->index = 0;
|
cfg->index = 0;
|
||||||
cfg->sum = 0;
|
cfg->sum = 0;
|
||||||
// osel_memset((uint8_t *)cfg->window, 0, sizeof(float32) * cfg->size);
|
// osel_memset((uint8_t *)cfg->window, 0, sizeof(float32) * cfg->size);
|
||||||
}
|
}
|
||||||
|
|
||||||
float32 lpf_window_update(lpf_window_t *cfg, float32 input)
|
float32 lpf_window_update(lpf_window_t* cfg, float32 input)
|
||||||
{
|
{
|
||||||
cfg->sum = 0;
|
cfg->sum = 0;
|
||||||
// 如果窗口未满,直接添加新值到当前索引位置
|
// 如果窗口未满,直接添加新值到当前索引位置
|
||||||
|
@ -152,3 +152,4 @@ float32 lpf_window_update(lpf_window_t *cfg, float32 input)
|
||||||
cfg->out = cfg->sum / cfg->index;
|
cfg->out = cfg->sum / cfg->index;
|
||||||
return cfg->out;
|
return cfg->out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -327,37 +327,3 @@ void stamp2Time(uint32_t stamp, rtc_date_t *date, rtc_time_t *time)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************排序**************************/
|
|
||||||
static void swap(uint16_t *a, uint16_t *b)
|
|
||||||
{
|
|
||||||
uint16_t t = *a;
|
|
||||||
*a = *b;
|
|
||||||
*b = t;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int partition(uint16_t arr[], int low, int high)
|
|
||||||
{
|
|
||||||
uint16_t pivot = arr[high];
|
|
||||||
int i = (low - 1);
|
|
||||||
for (int j = low; j <= high - 1; j++)
|
|
||||||
{
|
|
||||||
if (arr[j] < pivot)
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
swap(&arr[i], &arr[j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
swap(&arr[i + 1], &arr[high]);
|
|
||||||
return (i + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void quicksort(uint16_t arr[], int low, int high)
|
|
||||||
{
|
|
||||||
if (low < high)
|
|
||||||
{
|
|
||||||
int pi = partition(arr, low, high);
|
|
||||||
quicksort(arr, low, pi - 1);
|
|
||||||
quicksort(arr, pi + 1, high);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -76,28 +76,6 @@ void adc_init(adcs_e num, ADC_TypeDef *adc, DMA_TypeDef *dma, uint32_t dma_chann
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief ADC反初始化
|
|
||||||
* @param {adcs_e} num ADC编号
|
|
||||||
* @return {*}
|
|
||||||
* @note
|
|
||||||
*/
|
|
||||||
void adc_dinit(adcs_e num)
|
|
||||||
{
|
|
||||||
DBG_ASSERT(num < ADCS_MAX __DBG_LINE);
|
|
||||||
adcs_t *p = &adcs[num];
|
|
||||||
LL_ADC_REG_StopConversion(p->adc);
|
|
||||||
LL_DMA_DisableChannel(p->dma, p->dma_channel);
|
|
||||||
LL_ADC_Disable(p->adc);
|
|
||||||
if (p->adc_value != NULL)
|
|
||||||
{
|
|
||||||
#if defined(SRAM2_BASE)
|
|
||||||
osel_mem_free2(p->adc_value);
|
|
||||||
#else
|
|
||||||
osel_mem_free(p->adc_value);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* @brief 获取ADC转换结果,只需要第一个值
|
* @brief 获取ADC转换结果,只需要第一个值
|
||||||
* @param {adcs_e} num
|
* @param {adcs_e} num
|
||||||
|
@ -114,6 +92,10 @@ uint16_t adc_result_only_one(adcs_e num, uint8_t chan)
|
||||||
return gram[0][chan];
|
return gram[0][chan];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序方法
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 中位值平均滤波,获取ADC转换结果
|
* @brief 中位值平均滤波,获取ADC转换结果
|
||||||
* @param {adcs_e} num ADC编号
|
* @param {adcs_e} num ADC编号
|
||||||
|
@ -125,18 +107,35 @@ uint16_t adc_result_median_average(adcs_e num, uint8_t chan)
|
||||||
{
|
{
|
||||||
DBG_ASSERT(num < ADCS_MAX __DBG_LINE);
|
DBG_ASSERT(num < ADCS_MAX __DBG_LINE);
|
||||||
uint16_t res = 0;
|
uint16_t res = 0;
|
||||||
|
uint16_t temp = 0;
|
||||||
|
uint16_t *value = NULL;
|
||||||
adcs_t *p = &adcs[num];
|
adcs_t *p = &adcs[num];
|
||||||
DBG_ASSERT(p != NULL __DBG_LINE);
|
DBG_ASSERT(p != NULL __DBG_LINE);
|
||||||
uint16_t adc_temp[p->adc_cct];
|
uint16_t adc_temp[p->adc_cct];
|
||||||
uint32_t adc_sum = 0;
|
uint32_t adc_sum = 0;
|
||||||
|
|
||||||
|
value = (uint16_t *)osel_mem_alloc(sizeof(uint16_t) * p->adc_sum);
|
||||||
|
DBG_ASSERT(value != NULL __DBG_LINE);
|
||||||
|
osel_memcpy((uint8_t *)value, (uint8_t *)p->adc_value, sizeof(uint16_t) * p->adc_sum);
|
||||||
|
uint16_t(*gram)[p->adc_chans_count] = (uint16_t(*)[p->adc_chans_count])value;
|
||||||
for (uint8_t i = 0; i < p->adc_cct; i++)
|
for (uint8_t i = 0; i < p->adc_cct; i++)
|
||||||
{
|
{
|
||||||
adc_temp[i] = p->adc_value[i * p->adc_chans_count + chan];
|
adc_temp[i] = gram[i][chan];
|
||||||
}
|
}
|
||||||
|
osel_mem_free(value);
|
||||||
|
|
||||||
quicksort(adc_temp, 0, p->adc_cct - 1);
|
for (uint8_t i = 0; i < p->adc_cct - 1; i++)
|
||||||
|
{
|
||||||
|
for (uint8_t j = 0; j < p->adc_cct - 1 - i; j++)
|
||||||
|
{
|
||||||
|
if (adc_temp[j] > adc_temp[j + 1])
|
||||||
|
{
|
||||||
|
temp = adc_temp[j];
|
||||||
|
adc_temp[j] = adc_temp[j + 1];
|
||||||
|
adc_temp[j + 1] = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
for (uint8_t i = 0; i < p->adc_cct; i++) // 遍历所有ADC通道
|
for (uint8_t i = 0; i < p->adc_cct; i++) // 遍历所有ADC通道
|
||||||
{
|
{
|
||||||
adc_sum += adc_temp[i]; // 将每个ADC通道的数据累加到adc_sum中
|
adc_sum += adc_temp[i]; // 将每个ADC通道的数据累加到adc_sum中
|
||||||
|
@ -157,14 +156,32 @@ uint16_t adc_result_median(adcs_e num, uint8_t chan)
|
||||||
{
|
{
|
||||||
DBG_ASSERT(num < ADCS_MAX __DBG_LINE);
|
DBG_ASSERT(num < ADCS_MAX __DBG_LINE);
|
||||||
uint16_t res = 0;
|
uint16_t res = 0;
|
||||||
|
uint16_t temp = 0;
|
||||||
|
uint16_t *value = NULL;
|
||||||
adcs_t *p = &adcs[num];
|
adcs_t *p = &adcs[num];
|
||||||
uint16_t adc_temp[p->adc_cct];
|
uint16_t adc_temp[p->adc_cct];
|
||||||
|
value = (uint16_t *)osel_mem_alloc(sizeof(uint16_t) * p->adc_sum);
|
||||||
|
DBG_ASSERT(p != NULL __DBG_LINE);
|
||||||
|
DBG_ASSERT(value != NULL __DBG_LINE);
|
||||||
|
osel_memcpy((uint8_t *)value, (uint8_t *)p->adc_value, sizeof(uint16_t) * p->adc_sum);
|
||||||
|
uint16_t(*gram)[p->adc_chans_count] = (uint16_t(*)[p->adc_chans_count])value;
|
||||||
for (uint8_t i = 0; i < p->adc_cct; i++)
|
for (uint8_t i = 0; i < p->adc_cct; i++)
|
||||||
{
|
{
|
||||||
adc_temp[i] = p->adc_value[i * p->adc_chans_count + chan];
|
adc_temp[i] = gram[i][chan];
|
||||||
|
}
|
||||||
|
osel_mem_free(value);
|
||||||
|
for (uint8_t i = 0; i < p->adc_cct - 1; i++)
|
||||||
|
{
|
||||||
|
for (uint8_t j = 0; j < p->adc_cct - 1 - i; j++)
|
||||||
|
{
|
||||||
|
if (adc_temp[j] > adc_temp[j + 1])
|
||||||
|
{
|
||||||
|
temp = adc_temp[j];
|
||||||
|
adc_temp[j] = adc_temp[j + 1];
|
||||||
|
adc_temp[j + 1] = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 使用快速排序
|
|
||||||
quicksort(adc_temp, 0, p->adc_cct - 1);
|
|
||||||
res = adc_temp[p->adc_cct / 2];
|
res = adc_temp[p->adc_cct / 2];
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -179,20 +196,20 @@ uint16_t adc_result_median(adcs_e num, uint8_t chan)
|
||||||
uint16_t adc_result_average(adcs_e num, uint8_t chan)
|
uint16_t adc_result_average(adcs_e num, uint8_t chan)
|
||||||
{
|
{
|
||||||
DBG_ASSERT(num < ADCS_MAX __DBG_LINE);
|
DBG_ASSERT(num < ADCS_MAX __DBG_LINE);
|
||||||
|
uint16_t res = 0;
|
||||||
adcs_t *p = &adcs[num];
|
adcs_t *p = &adcs[num];
|
||||||
DBG_ASSERT(p != NULL __DBG_LINE);
|
DBG_ASSERT(p != NULL __DBG_LINE);
|
||||||
DBG_ASSERT(p->adc_cct != 0 __DBG_LINE); // 避免除以零的错误
|
|
||||||
uint32_t adc_sum = 0;
|
uint32_t adc_sum = 0;
|
||||||
uint16_t(*gram)[p->adc_chans_count] = (uint16_t(*)[p->adc_chans_count])p->adc_value;
|
|
||||||
|
|
||||||
|
uint16_t(*gram)[p->adc_chans_count] = (uint16_t(*)[p->adc_chans_count])p->adc_value;
|
||||||
for (uint8_t i = 0; i < p->adc_cct; i++)
|
for (uint8_t i = 0; i < p->adc_cct; i++)
|
||||||
{
|
{
|
||||||
uint32_t next_sum = adc_sum + gram[i][chan];
|
adc_sum += gram[i][chan];
|
||||||
DBG_ASSERT(next_sum >= adc_sum __DBG_LINE); // 避免溢出
|
|
||||||
adc_sum = next_sum;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return adc_sum / p->adc_cct;
|
res = adc_sum / p->adc_cct;
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -207,18 +224,26 @@ uint16_t adc_result_n_average(adcs_e num, uint8_t chan)
|
||||||
DBG_ASSERT(num < ADCS_MAX __DBG_LINE);
|
DBG_ASSERT(num < ADCS_MAX __DBG_LINE);
|
||||||
uint16_t res = 0;
|
uint16_t res = 0;
|
||||||
uint32_t adc_sum = 0;
|
uint32_t adc_sum = 0;
|
||||||
|
uint16_t *value = NULL;
|
||||||
adcs_t *p = &adcs[num];
|
adcs_t *p = &adcs[num];
|
||||||
DBG_ASSERT(p != NULL __DBG_LINE);
|
DBG_ASSERT(p != NULL __DBG_LINE);
|
||||||
uint16_t adc_temp[p->adc_cct];
|
uint16_t adc_temp[p->adc_cct];
|
||||||
uint8_t n = p->adc_cct / 4;
|
uint8_t n = p->adc_cct / 4;
|
||||||
uint8_t count = p->adc_cct > (2 * n) ? n : 0;
|
uint8_t count = p->adc_cct > (2 * n) ? n : 0;
|
||||||
|
value = (uint16_t *)osel_mem_alloc(sizeof(uint16_t) * p->adc_sum);
|
||||||
|
DBG_ASSERT(value != NULL __DBG_LINE);
|
||||||
|
osel_memcpy((uint8_t *)value, (uint8_t *)p->adc_value, sizeof(uint16_t) * p->adc_sum);
|
||||||
|
uint16_t(*gram)[p->adc_chans_count] = (uint16_t(*)[p->adc_chans_count])value;
|
||||||
for (uint8_t i = 0; i < p->adc_cct; i++)
|
for (uint8_t i = 0; i < p->adc_cct; i++)
|
||||||
{
|
{
|
||||||
adc_temp[i] = p->adc_value[i * p->adc_chans_count + chan];
|
adc_temp[i] = gram[i][chan];
|
||||||
}
|
}
|
||||||
|
osel_mem_free(value);
|
||||||
quicksort(adc_temp, 0, p->adc_cct - 1);
|
for (uint8_t i = 0; i < p->adc_cct; i++)
|
||||||
|
{
|
||||||
|
adc_temp[i] = gram[i][chan];
|
||||||
|
}
|
||||||
|
osel_quick_sort(adc_temp, 0, p->adc_cct - 1);
|
||||||
|
|
||||||
for (uint8_t i = count; i < p->adc_cct - count; i++)
|
for (uint8_t i = count; i < p->adc_cct - count; i++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -84,7 +84,6 @@ typedef struct
|
||||||
} adcs_t;
|
} adcs_t;
|
||||||
|
|
||||||
extern void adc_init(adcs_e num, ADC_TypeDef *adc, DMA_TypeDef *dma, uint32_t dma_channel, uint8_t adc_cct, uint32_t channels);
|
extern void adc_init(adcs_e num, ADC_TypeDef *adc, DMA_TypeDef *dma, uint32_t dma_channel, uint8_t adc_cct, uint32_t channels);
|
||||||
extern void adc_dinit(adcs_e num); // ADC反初始化
|
|
||||||
|
|
||||||
extern uint16_t adc_result_only_one(adcs_e num, uint8_t chan); // 获取ADC转换结果,只需要第一个值
|
extern uint16_t adc_result_only_one(adcs_e num, uint8_t chan); // 获取ADC转换结果,只需要第一个值
|
||||||
extern uint16_t adc_result_median_average(adcs_e num, uint8_t chan); // 中位值平均滤波,获取ADC转换结果
|
extern uint16_t adc_result_median_average(adcs_e num, uint8_t chan); // 中位值平均滤波,获取ADC转换结果
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "eeprom.h"
|
#include "eeprom.h"
|
||||||
#include "spis.h"
|
#include "spis.h"
|
||||||
#include "i2cs.h"
|
#include "i2cs.h"
|
||||||
|
#include "iwdgs.h"
|
||||||
|
|
||||||
#define DMA_ClEAR_FLAG(DMAX, CHx, Flag) \
|
#define DMA_ClEAR_FLAG(DMAX, CHx, Flag) \
|
||||||
do \
|
do \
|
||||||
|
|
|
@ -1,530 +0,0 @@
|
||||||
/**
|
|
||||||
* @file flash.c
|
|
||||||
* @author xxx
|
|
||||||
* @date 2024-02-07 11:49:34
|
|
||||||
* @brief
|
|
||||||
* @copyright Copyright (c) 2024 by xxx, All Rights Reserved.
|
|
||||||
* @attention
|
|
||||||
*
|
|
||||||
* ST 的官方驱动 LL 库并没有 flash 驱动。这里自己实现。
|
|
||||||
*
|
|
||||||
* 1. 由于在 stm32l4xx_ll_system.h 中存在部分 FLASH 操作函数(ACR寄存器的处理)且不全面
|
|
||||||
* 因此这里需要额外处理(重命名)
|
|
||||||
*
|
|
||||||
* 2. Main memory
|
|
||||||
* (1) FLASH_ACR 完成
|
|
||||||
* (2) FLASH_PDKEYR 完成
|
|
||||||
* (3) FLASH_KEYR 完成
|
|
||||||
* (4) FLASH_OPTKEYR 完成
|
|
||||||
* (5) FLASH_SR 完成
|
|
||||||
* (6) FLASH_CR 完成
|
|
||||||
* (7) FLASH_ECCR 完成
|
|
||||||
* (8) FLASH_OPTR 未完成
|
|
||||||
* (9) FLASH_PCROP1SR 未完成
|
|
||||||
* 后续寄存器 均未完成
|
|
||||||
* 3. Information block
|
|
||||||
* - System memory
|
|
||||||
* - OTP area
|
|
||||||
* - Option bytes
|
|
||||||
* 4. 根据 HAL 库的实现,相比于与手册的推荐流程,擦写的执行序列还有其他操作。
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
******************************************************************************
|
|
||||||
*/
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
|
||||||
#include "flash.h"
|
|
||||||
#include "stm32l4xx_ll_rcc.h"
|
|
||||||
#include "stm32l4xx_ll_system.h"
|
|
||||||
#include "stm32l4xx_ll_pwr.h"
|
|
||||||
#ifdef USE_FULL_ASSERT
|
|
||||||
#include "stm32_assert.h"
|
|
||||||
#else
|
|
||||||
#define assert_param(expr) ((void)0U)
|
|
||||||
#endif /* USE_FULL_ASSERT */
|
|
||||||
|
|
||||||
#define WHILE_MAX 10000U
|
|
||||||
/** @addtogroup STM32L4xx_LL_Driver
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @addtogroup FLASH_LL
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Private types -------------------------------------------------------------*/
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
|
||||||
/* Private constants ---------------------------------------------------------*/
|
|
||||||
/** @addtogroup FLASH_LL_Private_Constants
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Private macros ------------------------------------------------------------*/
|
|
||||||
/** @addtogroup FLASH_LL_Private_Macros
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define IS_LL_FLASH_WRITE_ADDR(__ADDR__) ((__ADDR__) % LL_FLASH_ALIGNMENT_MIN_SIZE == 0)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
|
||||||
/** @defgroup FLASH_LL_Private_Functions FLASH Private functions
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Exported functions --------------------------------------------------------*/
|
|
||||||
/** @addtogroup FLASH_LL_Exported_Functions
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* @brief Clear All Error in SR
|
|
||||||
* @param FLASHx FLASH Instance
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void LL_FLASH_ClearAllErrorFlag(void)
|
|
||||||
{
|
|
||||||
LL_FLASH_ClearFlag_OPTVERR(FLASH);
|
|
||||||
LL_FLASH_ClearFlag_RDERR(FLASH);
|
|
||||||
LL_FLASH_ClearFlag_FASTERR(FLASH);
|
|
||||||
LL_FLASH_ClearFlag_MISERR(FLASH);
|
|
||||||
LL_FLASH_ClearFlag_PGSERR(FLASH);
|
|
||||||
LL_FLASH_ClearFlag_SIZERR(FLASH);
|
|
||||||
LL_FLASH_ClearFlag_PGAERR(FLASH);
|
|
||||||
LL_FLASH_ClearFlag_WRPERR(FLASH);
|
|
||||||
LL_FLASH_ClearFlag_PROGERR(FLASH);
|
|
||||||
LL_FLASH_ClearFlag_OPERR(FLASH);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Flush the instruction and data caches.
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void LL_FLASH_FlushCaches(void)
|
|
||||||
{
|
|
||||||
/* Flush instruction cache */
|
|
||||||
if (LL_FLASH_IsEnabledInstructionCache(FLASH))
|
|
||||||
{
|
|
||||||
LL_FLASH_DisableInstructionCache(FLASH);
|
|
||||||
/* Reset instruction cache */
|
|
||||||
LL_FLASH_InstructionCacheReset(FLASH);
|
|
||||||
/* Enable instruction cache */
|
|
||||||
LL_FLASH_EnableInstructionCache(FLASH);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Flush data cache */
|
|
||||||
if (LL_FLASH_IsEnabledDataCache(FLASH))
|
|
||||||
{
|
|
||||||
LL_FLASH_ZCS_DisableDataCache(FLASH);
|
|
||||||
/* Reset data cache */
|
|
||||||
LL_FLASH_DataCacheReset(FLASH);
|
|
||||||
/* Enable data cache */
|
|
||||||
LL_FLASH_ZCS_EnableDataCache(FLASH);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Erase Page
|
|
||||||
* @param pageno Page number
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
ErrorStatus LL_FLASH_ErasePage(uint32_t pageno)
|
|
||||||
{
|
|
||||||
uint16_t count = 0;
|
|
||||||
/* Check that no Flash memory operation is ongoing by checking the BSY bit */
|
|
||||||
while (LL_FLASH_IsActiveFlag_BSY(FLASH))
|
|
||||||
{
|
|
||||||
if (count++ > WHILE_MAX)
|
|
||||||
{
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
count = 0;
|
|
||||||
|
|
||||||
/* Check and clear all error programming flags due to a previous programming. If not, PGSERR is set. */
|
|
||||||
LL_FLASH_ClearAllErrorFlag();
|
|
||||||
|
|
||||||
/* Set the PER bit and select the page you wish to erase (PNB) with the associated bank (BKER) in the Flash control register (FLASH_CR). */
|
|
||||||
LL_FLASH_EnablePageErase(FLASH);
|
|
||||||
|
|
||||||
if (pageno >= LL_FLASH_BANK1_PAGE_NUM)
|
|
||||||
{
|
|
||||||
pageno -= LL_FLASH_BANK1_PAGE_NUM;
|
|
||||||
LL_FLASH_SetErasePageBank(FLASH, LL_FLASH_BANK2);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LL_FLASH_SetErasePageBank(FLASH, LL_FLASH_BANK1);
|
|
||||||
}
|
|
||||||
|
|
||||||
LL_FLASH_SetErasePageNo(FLASH, pageno);
|
|
||||||
|
|
||||||
/* Set the STRT bit in the FLASH_CR register. */
|
|
||||||
LL_FLASH_EraseStart(FLASH);
|
|
||||||
|
|
||||||
/* Wait for the BSY bit to be cleared in the FLASH_SR register. */
|
|
||||||
while (LL_FLASH_IsActiveFlag_BSY(FLASH))
|
|
||||||
{
|
|
||||||
if (count++ > WHILE_MAX)
|
|
||||||
{
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
count = 0;
|
|
||||||
|
|
||||||
/* 完成只有需要清除擦除标志. */
|
|
||||||
LL_FLASH_DisablePageErase(FLASH);
|
|
||||||
|
|
||||||
/* Flush the caches to be sure of the data consistency */
|
|
||||||
LL_FLASH_FlushCaches();
|
|
||||||
|
|
||||||
return SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Erase bank
|
|
||||||
* @param bank This parameter can be one of the following values:
|
|
||||||
* @arg @ref LL_FLASH_BANK1
|
|
||||||
* @arg @ref LL_FLASH_BANK2
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
ErrorStatus LL_FLASH_EraseBank(uint32_t bank)
|
|
||||||
{
|
|
||||||
uint16_t count = 0;
|
|
||||||
/* Check that no Flash memory operation is ongoing by checking the BSY bit */
|
|
||||||
while (LL_FLASH_IsActiveFlag_BSY(FLASH))
|
|
||||||
{
|
|
||||||
if (count++ > WHILE_MAX)
|
|
||||||
{
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
count = 0;
|
|
||||||
|
|
||||||
/* Check and clear all error programming flags due to a previous programming. If not, PGSERR is set. */
|
|
||||||
LL_FLASH_ClearAllErrorFlag();
|
|
||||||
|
|
||||||
/* Set the MER1 bit or/and MER2 (depending on the bank) in the Flash control register (FLASH_CR).
|
|
||||||
Both banks can be selected in the same operation. */
|
|
||||||
if (bank == LL_FLASH_BANK1)
|
|
||||||
{
|
|
||||||
LL_FLASH_EnableBank1Erase(FLASH);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LL_FLASH_EnableBank2Erase(FLASH);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set the STRT bit in the FLASH_CR register. */
|
|
||||||
LL_FLASH_EraseStart(FLASH);
|
|
||||||
|
|
||||||
/* Wait for the BSY bit to be cleared in the FLASH_SR register. */
|
|
||||||
while (LL_FLASH_IsActiveFlag_BSY(FLASH))
|
|
||||||
{
|
|
||||||
if (count++ > WHILE_MAX)
|
|
||||||
{
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
count = 0;
|
|
||||||
|
|
||||||
/* 完成只有需要清除擦除标志. */
|
|
||||||
LL_FLASH_DisableBank1Erase(FLASH);
|
|
||||||
LL_FLASH_DisableBank2Erase(FLASH);
|
|
||||||
|
|
||||||
/* Flush the caches to be sure of the data consistency */
|
|
||||||
LL_FLASH_FlushCaches();
|
|
||||||
return SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Erase Chip
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
ErrorStatus LL_FLASH_EraseChip(void)
|
|
||||||
{
|
|
||||||
uint16_t count = 0;
|
|
||||||
/* Check that no Flash memory operation is ongoing by checking the BSY bit */
|
|
||||||
while (LL_FLASH_IsActiveFlag_BSY(FLASH))
|
|
||||||
{
|
|
||||||
if (count++ > WHILE_MAX)
|
|
||||||
{
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
count = 0;
|
|
||||||
|
|
||||||
/* Check and clear all error programming flags due to a previous programming. If not, PGSERR is set. */
|
|
||||||
LL_FLASH_ClearAllErrorFlag();
|
|
||||||
|
|
||||||
/* Set the MER1 bit or/and MER2 (depending on the bank) in the Flash control register (FLASH_CR).
|
|
||||||
Both banks can be selected in the same operation. */
|
|
||||||
LL_FLASH_EnableBank1Erase(FLASH);
|
|
||||||
LL_FLASH_EnableBank2Erase(FLASH);
|
|
||||||
|
|
||||||
/* Set the STRT bit in the FLASH_CR register. */
|
|
||||||
LL_FLASH_EraseStart(FLASH);
|
|
||||||
|
|
||||||
/* Wait for the BSY bit to be cleared in the FLASH_SR register. */
|
|
||||||
while (LL_FLASH_IsActiveFlag_BSY(FLASH))
|
|
||||||
{
|
|
||||||
if (count++ > WHILE_MAX)
|
|
||||||
{
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
count = 0;
|
|
||||||
|
|
||||||
/* 完成只有需要清除擦除标志. */
|
|
||||||
LL_FLASH_DisableBank1Erase(FLASH);
|
|
||||||
LL_FLASH_DisableBank2Erase(FLASH);
|
|
||||||
|
|
||||||
/* Flush the caches to be sure of the data consistency */
|
|
||||||
LL_FLASH_FlushCaches();
|
|
||||||
return SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Program Double Word
|
|
||||||
* @param address specifies the address to be programmed.
|
|
||||||
* @param data specifies the data to be programmed.
|
|
||||||
* @retval An ErrorStatus enumeration value:
|
|
||||||
* - SUCCESS: Write successfully
|
|
||||||
* - ERROR: error
|
|
||||||
*/
|
|
||||||
ErrorStatus LL_FLASH_ProgramDoubleWord(uint32_t address, uint64_t data)
|
|
||||||
{
|
|
||||||
assert_param(!IS_LL_FLASH_WRITE_ADDR(address));
|
|
||||||
uint16_t count = 0;
|
|
||||||
/* Check that no Flash memory operation is ongoing by checking the BSY bit */
|
|
||||||
while (LL_FLASH_IsActiveFlag_BSY(FLASH))
|
|
||||||
{
|
|
||||||
if (count++ > WHILE_MAX)
|
|
||||||
{
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
count = 0;
|
|
||||||
/* Check and clear all error programming flags due to a previous programming. If not, PGSERR is set. */
|
|
||||||
LL_FLASH_ClearAllErrorFlag();
|
|
||||||
|
|
||||||
/* Set the PG bit in the Flash control register (FLASH_CR). */
|
|
||||||
LL_FLASH_EnableProgram(FLASH);
|
|
||||||
|
|
||||||
/* Perform the data write operation at the desired memory address, inside main memory
|
|
||||||
block or OTP area. Only double word can be programmed. */
|
|
||||||
/* Program the double word */
|
|
||||||
*(__IO uint32_t *)address = (uint32_t)data;
|
|
||||||
*(__IO uint32_t *)(address + 4U) = (uint32_t)(data >> 32);
|
|
||||||
|
|
||||||
/* Check that no Flash memory operation is ongoing by checking the BSY bit */
|
|
||||||
while (LL_FLASH_IsActiveFlag_BSY(FLASH))
|
|
||||||
{
|
|
||||||
if (count++ > WHILE_MAX)
|
|
||||||
{
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
count = 0;
|
|
||||||
/* Check that EOP flag is set in the FLASH_SR register (meaning that the programming
|
|
||||||
operation has succeed), and clear it by software. */
|
|
||||||
if (LL_FLASH_IsActiveFlag_EOP(FLASH))
|
|
||||||
{
|
|
||||||
LL_FLASH_ClearFlag_EOP(FLASH);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Clear the PG bit in the FLASH_CR register if there no more programming request anymore. */
|
|
||||||
LL_FLASH_DisableProgram(FLASH);
|
|
||||||
|
|
||||||
/* Flush the caches to be sure of the data consistency */
|
|
||||||
LL_FLASH_FlushCaches();
|
|
||||||
|
|
||||||
return SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Program
|
|
||||||
* @param address specifies the address to be programmed.
|
|
||||||
* @param data specifies the data to be programmed.
|
|
||||||
* @param num specifies the data number
|
|
||||||
* @retval An ErrorStatus enumeration value:
|
|
||||||
* - SUCCESS: Write successfully
|
|
||||||
* - ERROR: error
|
|
||||||
*/
|
|
||||||
ErrorStatus LL_FLASH_Program(uint32_t address, uint8_t data[], uint32_t num)
|
|
||||||
{
|
|
||||||
static uint64_t DataT = 0;
|
|
||||||
uint32_t T = 0, S = 0;
|
|
||||||
uint16_t count = 0;
|
|
||||||
assert_param(!IS_LL_FLASH_WRITE_ADDR(address));
|
|
||||||
|
|
||||||
if (num == 0)
|
|
||||||
{
|
|
||||||
return SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check that no Flash memory operation is ongoing by checking the BSY bit */
|
|
||||||
while (LL_FLASH_IsActiveFlag_BSY(FLASH))
|
|
||||||
{
|
|
||||||
if (count++ > WHILE_MAX)
|
|
||||||
{
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
count = 0;
|
|
||||||
/* Check and clear all error programming flags due to a previous programming. If not, PGSERR is set. */
|
|
||||||
LL_FLASH_ClearAllErrorFlag();
|
|
||||||
|
|
||||||
/* Set the PG bit in the Flash control register (FLASH_CR). */
|
|
||||||
LL_FLASH_EnableProgram(FLASH);
|
|
||||||
|
|
||||||
/* Perform the data write operation at the desired memory address, inside main memory
|
|
||||||
block or OTP area. Only double word can be programmed. */
|
|
||||||
T = num;
|
|
||||||
while (num > 0)
|
|
||||||
{
|
|
||||||
DataT = 0;
|
|
||||||
if (num >= 8)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < LL_FLASH_ALIGNMENT_MIN_SIZE; i++)
|
|
||||||
{
|
|
||||||
DataT = DataT << 8;
|
|
||||||
DataT |= data[S + 7 - i];
|
|
||||||
}
|
|
||||||
S += LL_FLASH_ALIGNMENT_MIN_SIZE;
|
|
||||||
num -= LL_FLASH_ALIGNMENT_MIN_SIZE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (int i = 0; i < num; i++)
|
|
||||||
{
|
|
||||||
DataT = DataT << 8;
|
|
||||||
DataT |= data[T - 1 - i];
|
|
||||||
}
|
|
||||||
num = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Program the double word */
|
|
||||||
*(__IO uint32_t *)address = (uint32_t)DataT;
|
|
||||||
*(__IO uint32_t *)(address + 4U) = (uint32_t)(DataT >> 32);
|
|
||||||
|
|
||||||
/* Check that no Flash memory operation is ongoing by checking the BSY bit */
|
|
||||||
while (LL_FLASH_IsActiveFlag_BSY(FLASH))
|
|
||||||
{
|
|
||||||
if (count++ > WHILE_MAX)
|
|
||||||
{
|
|
||||||
return ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
count = 0;
|
|
||||||
|
|
||||||
/* Check that EOP flag is set in the FLASH_SR register (meaning that the programming
|
|
||||||
operation has succeed), and clear it by software. */
|
|
||||||
if (LL_FLASH_IsActiveFlag_EOP(FLASH))
|
|
||||||
{
|
|
||||||
LL_FLASH_ClearFlag_EOP(FLASH);
|
|
||||||
}
|
|
||||||
|
|
||||||
address += LL_FLASH_ALIGNMENT_MIN_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Clear the PG bit in the FLASH_CR register if there no more programming request anymore. */
|
|
||||||
LL_FLASH_DisableProgram(FLASH);
|
|
||||||
|
|
||||||
/* Flush the caches to be sure of the data consistency */
|
|
||||||
LL_FLASH_FlushCaches();
|
|
||||||
|
|
||||||
return SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @addtogroup FLASH_LL_Private_Functions
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* @brief Fast program a row double-word (64-bit) at a specified address.
|
|
||||||
* @param address: specifies the address to be programmed.
|
|
||||||
* @param DataAddress: specifies the address where the data are stored.
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void LL_FLASH_ProgramFast(uint32_t address, uint32_t DataAddress)
|
|
||||||
{
|
|
||||||
uint8_t row_index = (2 * LL_FLASH_ROW_SIZE);
|
|
||||||
__IO uint32_t *dest_addr = (__IO uint32_t *)address;
|
|
||||||
__IO uint32_t *src_addr = (__IO uint32_t *)DataAddress;
|
|
||||||
|
|
||||||
/* Check the parameters */
|
|
||||||
assert_param(IS_FLASH_MAIN_MEM_ADDRESS(address));
|
|
||||||
|
|
||||||
/* Set FSTPG bit */
|
|
||||||
LL_FLASH_EnableFastProgram(FLASH);
|
|
||||||
|
|
||||||
/* Disable interrupts to avoid any interruption during the loop */
|
|
||||||
__disable_irq();
|
|
||||||
|
|
||||||
/* Program the double word of the row */
|
|
||||||
do
|
|
||||||
{
|
|
||||||
*dest_addr = *src_addr;
|
|
||||||
dest_addr++;
|
|
||||||
src_addr++;
|
|
||||||
row_index--;
|
|
||||||
} while (row_index != 0U);
|
|
||||||
|
|
||||||
/* Re-enable the interrupts */
|
|
||||||
__enable_irq();
|
|
||||||
|
|
||||||
LL_FLASH_DisableFastProgram(FLASH);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Fast program a row double-word (64-bit) at a specified address.
|
|
||||||
* @param address: specifies the address to be programmed.
|
|
||||||
* @param data: specifies the data to be programmed.
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
ErrorStatus LL_FLASH_Read(uint32_t address, uint8_t data[], uint32_t num)
|
|
||||||
{
|
|
||||||
if (num == 0)
|
|
||||||
{
|
|
||||||
return SUCCESS;
|
|
||||||
}
|
|
||||||
for (uint32_t i = 0; i < num; i++)
|
|
||||||
{
|
|
||||||
data[i] = *(__IO uint8_t *)(address + i);
|
|
||||||
}
|
|
||||||
|
|
||||||
return SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
|
File diff suppressed because it is too large
Load Diff
|
@ -287,7 +287,7 @@ static BOOL _read_mem_dma(i2c_t *handle, uint16_t mem_address, uint16_t mem_adds
|
||||||
{
|
{
|
||||||
i2c_reset(handle->i2c); // xsh:重置I2C,修复一段时间后无法读写的问题
|
i2c_reset(handle->i2c); // xsh:重置I2C,修复一段时间后无法读写的问题
|
||||||
}
|
}
|
||||||
uint16_t count = 5000;
|
uint16_t count = 10000;
|
||||||
handle->txsize = 0;
|
handle->txsize = 0;
|
||||||
handle->tx_dma_ok = FALSE;
|
handle->tx_dma_ok = FALSE;
|
||||||
handle->rx_dma_ok = FALSE;
|
handle->rx_dma_ok = FALSE;
|
||||||
|
@ -301,7 +301,7 @@ static BOOL _read_mem_dma(i2c_t *handle, uint16_t mem_address, uint16_t mem_adds
|
||||||
LL_DMA_EnableChannel(handle->dma, handle->dma_tx_channel);
|
LL_DMA_EnableChannel(handle->dma, handle->dma_tx_channel);
|
||||||
|
|
||||||
LL_I2C_HandleTransfer(handle->i2c, handle->w_address, LL_I2C_ADDRSLAVE_7BIT, handle->txsize, LL_I2C_MODE_SOFTEND, LL_I2C_GENERATE_START_WRITE);
|
LL_I2C_HandleTransfer(handle->i2c, handle->w_address, LL_I2C_ADDRSLAVE_7BIT, handle->txsize, LL_I2C_MODE_SOFTEND, LL_I2C_GENERATE_START_WRITE);
|
||||||
count = 5000;
|
count = 10000;
|
||||||
while (!handle->tx_dma_ok)
|
while (!handle->tx_dma_ok)
|
||||||
{
|
{
|
||||||
if (count-- == 0)
|
if (count-- == 0)
|
||||||
|
@ -311,7 +311,7 @@ static BOOL _read_mem_dma(i2c_t *handle, uint16_t mem_address, uint16_t mem_adds
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
count = 5000;
|
count = 10000;
|
||||||
while (LL_I2C_IsActiveFlag_TC(handle->i2c) != 1)
|
while (LL_I2C_IsActiveFlag_TC(handle->i2c) != 1)
|
||||||
{
|
{
|
||||||
if (count-- == 0)
|
if (count-- == 0)
|
||||||
|
|
|
@ -46,8 +46,8 @@ struct I2CS
|
||||||
uint16_t txsize;
|
uint16_t txsize;
|
||||||
uint8_t w_address; // 7位地址
|
uint8_t w_address; // 7位地址
|
||||||
uint8_t r_address; // 7位地址
|
uint8_t r_address; // 7位地址
|
||||||
__IO BOOL rx_dma_ok; // 接收DMA完成标志
|
volatile BOOL rx_dma_ok; // 接收DMA完成标志
|
||||||
__IO BOOL tx_dma_ok; // 发送DMA完成标志
|
volatile BOOL tx_dma_ok; // 发送DMA完成标志
|
||||||
|
|
||||||
i2cs_dma_callback *dma_rx_cb; // DMA接收完成回调函数
|
i2cs_dma_callback *dma_rx_cb; // DMA接收完成回调函数
|
||||||
i2cs_dma_callback *dma_tx_cb; // DMA发送完成回调函数
|
i2cs_dma_callback *dma_tx_cb; // DMA发送完成回调函数
|
||||||
|
|
|
@ -25,7 +25,8 @@ BOOL check_watchdog_reset(void)
|
||||||
*/
|
*/
|
||||||
void debug_freeze_watchdog(void)
|
void debug_freeze_watchdog(void)
|
||||||
{
|
{
|
||||||
LL_DBGMCU_APB1_GRP1_FreezePeriph(LL_DBGMCU_APB1_GRP1_IWDG_STOP);
|
// LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_DBGMCU);
|
||||||
|
SET_BIT(DBGMCU->APB1FZR1, DBGMCU_APB1FZR1_DBG_IWDG_STOP);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,5 +36,5 @@ void debug_freeze_watchdog(void)
|
||||||
*/
|
*/
|
||||||
void debug_unfreeze_watchdog(void)
|
void debug_unfreeze_watchdog(void)
|
||||||
{
|
{
|
||||||
LL_DBGMCU_APB1_GRP1_UnFreezePeriph(LL_DBGMCU_APB1_GRP1_IWDG_STOP);
|
CLEAR_BIT(DBGMCU->APB1FZR1, DBGMCU_APB1FZR1_DBG_IWDG_STOP);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,3 @@
|
||||||
/**
|
|
||||||
* @file iwdgs.h
|
|
||||||
* @author xxx
|
|
||||||
* @date 2023-12-27 14:44:03
|
|
||||||
* @brief 独立看门狗
|
|
||||||
* @copyright Copyright (c) 2024 by xxx, All Rights Reserved.
|
|
||||||
*/
|
|
||||||
#ifndef __IWDGS_H__
|
#ifndef __IWDGS_H__
|
||||||
#define __IWDGS_H__
|
#define __IWDGS_H__
|
||||||
|
|
||||||
|
|
|
@ -121,8 +121,8 @@ struct SPIS
|
||||||
DMA_TypeDef *dma; // 外部设置
|
DMA_TypeDef *dma; // 外部设置
|
||||||
uint32_t dma_rx_channel; // 外部设置
|
uint32_t dma_rx_channel; // 外部设置
|
||||||
uint32_t dma_tx_channel; // 外部设置
|
uint32_t dma_tx_channel; // 外部设置
|
||||||
__IO BOOL rx_dma_ok;
|
volatile BOOL rx_dma_ok;
|
||||||
__IO BOOL tx_dma_ok;
|
volatile BOOL tx_dma_ok;
|
||||||
spis_dma_callback *dma_rx_cb; // DMA接收回调函数
|
spis_dma_callback *dma_rx_cb; // DMA接收回调函数
|
||||||
spis_dma_callback *dma_tx_cb; // DMA发送回调函数
|
spis_dma_callback *dma_tx_cb; // DMA发送回调函数
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,12 +9,6 @@ typedef void (*rx_interupt_cb_t)(uint8_t uart_index, uint8_t *data, uint16_t len
|
||||||
//
|
//
|
||||||
typedef void (*tx_complete_cb_t)(void);
|
typedef void (*tx_complete_cb_t)(void);
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
UART_OK = 0x00u, /**< The action was successful. */
|
|
||||||
UART_ERROR = 0xFFu /**< Generic error. */
|
|
||||||
} uart_status_e;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
@ -33,7 +27,7 @@ typedef struct
|
||||||
BOOL tx_dma_en;
|
BOOL tx_dma_en;
|
||||||
uint8_t *txbuf;
|
uint8_t *txbuf;
|
||||||
uint16_t txsize;
|
uint16_t txsize;
|
||||||
__IO BOOL tx_dma_ok; // 发送DMA完成标志
|
volatile BOOL tx_dma_ok; // 发送DMA完成标志
|
||||||
|
|
||||||
// 接收中断回调
|
// 接收中断回调
|
||||||
rx_interupt_cb_t rx_interupt_cb;
|
rx_interupt_cb_t rx_interupt_cb;
|
||||||
|
|
|
@ -9,10 +9,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "sys.h"
|
#include "sys.h"
|
||||||
__IO uint32_t uwTick;
|
volatile uint32_t uwTick;
|
||||||
__IO uint32_t scheduler_start_time; // 调度器开始时间
|
volatile uint32_t scheduler_start_time; // 调度器开始时间
|
||||||
__IO uint32_t scheduler_end_time; // 调度器结束时间
|
volatile uint32_t scheduler_end_time; // 调度器结束时间
|
||||||
__IO uint32_t scheduler_occupancy_time = 0; // 调度器占用时间
|
volatile uint32_t scheduler_occupancy_time = 0; // 调度器占用时间
|
||||||
/**
|
/**
|
||||||
* @brief 设置中断向量表偏移地址
|
* @brief 设置中断向量表偏移地址
|
||||||
* @param baseaddr : 基址
|
* @param baseaddr : 基址
|
||||||
|
@ -32,7 +32,7 @@ void sys_nvic_set_vector_table(uint32_t baseaddr, uint32_t offset)
|
||||||
*/
|
*/
|
||||||
void sys_wfi_set(void)
|
void sys_wfi_set(void)
|
||||||
{
|
{
|
||||||
__ASM __IO("wfi");
|
__ASM volatile("wfi");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,7 +42,7 @@ void sys_wfi_set(void)
|
||||||
*/
|
*/
|
||||||
void sys_intx_disable(void)
|
void sys_intx_disable(void)
|
||||||
{
|
{
|
||||||
__ASM __IO("cpsid i");
|
__ASM volatile("cpsid i");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,7 +52,7 @@ void sys_intx_disable(void)
|
||||||
*/
|
*/
|
||||||
void sys_intx_enable(void)
|
void sys_intx_enable(void)
|
||||||
{
|
{
|
||||||
__ASM __IO("cpsie i");
|
__ASM volatile("cpsie i");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -125,7 +125,7 @@ void sys_millis_reset(void)
|
||||||
*/
|
*/
|
||||||
uint32_t sys_to_seconds(uint32_t start_time)
|
uint32_t sys_to_seconds(uint32_t start_time)
|
||||||
{
|
{
|
||||||
return (sys_millis() - start_time) / 1000;
|
return (uwTick - start_time) / 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Reference in New Issue