去除AD7190校准过程,增加超低频抑制,限制零点跟踪范围,优化初始称重传感器倍率,增加含水量含固量湿重率回潮率,限制称重调零范文不大于总称量的4%,修复型号未对应立项书参数bug,提高SPI速率,增加SPI超时退出机制。

This commit is contained in:
Kaiser 2026-03-17 10:33:04 +08:00
parent efcb158126
commit c13a96ff84
12 changed files with 2873 additions and 4835 deletions

File diff suppressed because it is too large Load Diff

View File

@ -103,7 +103,7 @@
<bEvRecOn>1</bEvRecOn> <bEvRecOn>1</bEvRecOn>
<bSchkAxf>0</bSchkAxf> <bSchkAxf>0</bSchkAxf>
<bTchkAxf>0</bTchkAxf> <bTchkAxf>0</bTchkAxf>
<nTsel>4</nTsel> <nTsel>3</nTsel>
<sDll></sDll> <sDll></sDll>
<sDllPa></sDllPa> <sDllPa></sDllPa>
<sDlgDll></sDlgDll> <sDlgDll></sDlgDll>
@ -114,9 +114,29 @@
<tDlgDll></tDlgDll> <tDlgDll></tDlgDll>
<tDlgPa></tDlgPa> <tDlgPa></tDlgPa>
<tIfile></tIfile> <tIfile></tIfile>
<pMon>Segger\JL2CM3.dll</pMon> <pMon>BIN\CMSIS_AGDI.dll</pMon>
</DebugOpt> </DebugOpt>
<TargetDriverDllRegistry> <TargetDriverDllRegistry>
<SetRegEntry>
<Number>0</Number>
<Key>JL2CM3</Key>
<Name>-U941000024 -O78 -S2 -ZTIFSpeedSel5000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103C8$Flash\STM32F10x_128.FLM)</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
<Key>CMSIS_AGDI</Key>
<Name>-X"" -O206 -S8 -C0 -P00000000 -N00("ARM CoreSight SW-DP") -D00(1BA01477) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103C8$Flash\STM32F10x_128.FLM)</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
<Key>UL2CM3</Key>
<Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128 -FS08000000 -FL020000 -FP0($$Device:STM32F103C8$Flash\STM32F10x_128.FLM))</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
<Key>ST-LINKIII-KEIL_SWO</Key>
<Name>-U38FF68063050503448221643 -O206 -SF10000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP (ARM Core") -D00(1BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103C8$Flash\STM32F10x_128.FLM)</Name>
</SetRegEntry>
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
<Key>ARMRTXEVENTFLAGS</Key> <Key>ARMRTXEVENTFLAGS</Key>
@ -135,85 +155,10 @@
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
<Key>DLGUARM</Key> <Key>DLGUARM</Key>
<Name>d</Name> <Name></Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
<Key>JL2CM3</Key>
<Name>-U69400112 -O78 -S5 -ZTIFSpeedSel1000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(1BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO15 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103C8$Flash\STM32F10x_128.FLM)</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
<Key>UL2CM3</Key>
<Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128 -FS08000000 -FL020000 -FP0($$Device:STM32F103C8$Flash\STM32F10x_128.FLM))</Name>
</SetRegEntry> </SetRegEntry>
</TargetDriverDllRegistry> </TargetDriverDllRegistry>
<Breakpoint> <Breakpoint/>
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>127</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>.\Source\USARTHMI.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
<Bp>
<Number>1</Number>
<Type>0</Type>
<LineNumber>109</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134223724</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>.\Source\AD7190.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\Moisture\Source/AD7190.c\109</Expression>
</Bp>
<Bp>
<Number>2</Number>
<Type>0</Type>
<LineNumber>118</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134223738</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>.\Source\AD7190.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\Moisture\Source/AD7190.c\118</Expression>
</Bp>
<Bp>
<Number>3</Number>
<Type>0</Type>
<LineNumber>131</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134223776</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>.\Source\AD7190.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\Moisture\Source/AD7190.c\131</Expression>
</Bp>
</Breakpoint>
<WatchWindow1> <WatchWindow1>
<Ww> <Ww>
<count>0</count> <count>0</count>
@ -248,227 +193,252 @@
<Ww> <Ww>
<count>6</count> <count>6</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>ADvalue2filterOld,0x0A</ItemText> <ItemText>buf</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>7</count> <count>7</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>ADvalue2filter</ItemText> <ItemText>NameBuf</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>8</count> <count>8</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>CalibrateWeight2.WeightZero,0x0A</ItemText> <ItemText>WeightDataBuf</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>9</count> <count>9</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>HeatOutValue</ItemText> <ItemText>DataBufIndex,0x0A</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>10</count> <count>10</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>Percent,0x0A</ItemText> <ItemText>\\Moisture\Source/HMI.c\WeightDataBuf</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>11</count> <count>11</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>Ki</ItemText> <ItemText>CountNochange,0x0A</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>12</count> <count>12</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>ADvalue2,0x0A</ItemText> <ItemText>DifErrCount,0x0A</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>13</count> <count>13</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>kf2</ItemText> <ItemText>lastdata,0x0A</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>14</count> <count>14</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>CountNochange,0x0A</ItemText> <ItemText>UseuLBuf</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>15</count> <count>15</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>ADvalue2,0x0A</ItemText> <ItemText>average</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>16</count> <count>16</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>ADvalue2filter</ItemText> <ItemText>\\Moisture\Source/AD7190.c\UseuLBuf,0x0A</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>17</count> <count>17</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>DataIn</ItemText> <ItemText>UseuLBuf2,0x0A</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>18</count> <count>18</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>DataInbuf</ItemText> <ItemText>center</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>19</count> <count>19</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>NameBuf</ItemText> <ItemText>\\Moisture\Source/AD7190.c\average</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>20</count> <count>20</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>startTime</ItemText> <ItemText>ADvalue2filter</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>21</count> <count>21</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>buf</ItemText> <ItemText>UninstiallRefWeight</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>22</count> <count>22</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>CountDelay,0x0A</ItemText> <ItemText>CalibrateWeight2.WeightZero,0x0A</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>23</count> <count>23</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>Title</ItemText> <ItemText>kf</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>24</count> <count>24</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>DataLogValue</ItemText> <ItemText>alpf</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>25</count> <count>25</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>Set,0x0A</ItemText> <ItemText>ChangeMax,0x0A</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>26</count> <count>26</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>len,0x0A</ItemText> <ItemText>ADvalue2filterOld,0x0A</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>27</count> <count>27</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>ui</ItemText> <ItemText>WeightData2Finally</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>28</count> <count>28</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>f</ItemText> <ItemText>FliterCount,0x0A</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>29</count> <count>29</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>WeightData2Temp</ItemText> <ItemText>WeightData2Finally</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>30</count> <count>30</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>buf</ItemText> <ItemText>WeightData2Temp</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>31</count> <count>31</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>NameBufSelect</ItemText> <ItemText>(WeightData2Temp - WeightRefStart) * ( 1.0f - FliterCount /1100.0f)</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>32</count> <count>32</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>startTimeSelect</ItemText> <ItemText>Set.TempDelta</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>33</count> <count>33</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>StartWeightSelect</ItemText> <ItemText>WeightZeroOld,0x0A</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>34</count> <count>34</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>StopWeightSelect</ItemText> <ItemText>Set,0x0A</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>35</count> <count>35</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>WaterPercentSelect</ItemText> <ItemText>SetZeroCount,0x0A</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>36</count> <count>36</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>NameBuf</ItemText> <ItemText>WeightData2TempOld</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>37</count> <count>37</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>PwdBuf</ItemText> <ItemText>(WeightData2Temp - WeightData2Finally) * ( 1.0f - 0.9f * FliterCount / 1000)</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>38</count> <count>38</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>NameBuf</ItemText> <ItemText>FliterCount,0x0A</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>39</count> <count>39</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>weightChanging</ItemText> <ItemText>WeightData2</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>40</count> <count>40</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>ErrCount</ItemText> <ItemText>WeightOld</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>41</count> <count>41</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>TempI,0x0A</ItemText> <ItemText>WeightDataS</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>42</count> <count>42</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>TemperatureIn</ItemText> <ItemText>weight11g</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>43</count> <count>43</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>lostTick,0x0A</ItemText> <ItemText>ZeroWeightOld</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>44</count> <count>44</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>CountDelay,0x0A</ItemText> <ItemText>ZeroWeightChange</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>45</count> <count>45</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>oneTick,0x0A</ItemText> <ItemText>ADvalue2,0x0A</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>46</count> <count>46</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>LastTick,0x0A</ItemText> <ItemText>WeightData2Finally</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>47</count> <count>47</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>Err,0x0A</ItemText> <ItemText>WeightData2</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>48</count> <count>48</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>buf</ItemText> <ItemText>WeightData2Temp</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>49</count> <count>49</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>PwdBuf</ItemText> <ItemText>ErrCount,0x0A</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>50</count> <count>50</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>NameBuf</ItemText> <ItemText>DifErrCountAdd,0x0A</ItemText>
</Ww>
<Ww>
<count>51</count>
<WinNumber>1</WinNumber>
<ItemText>ErrcountAdd,0x0A</ItemText>
</Ww>
<Ww>
<count>52</count>
<WinNumber>1</WinNumber>
<ItemText>WeightDataBuf</ItemText>
</Ww>
<Ww>
<count>53</count>
<WinNumber>1</WinNumber>
<ItemText>DataBufIndex,0x0A</ItemText>
</Ww>
<Ww>
<count>54</count>
<WinNumber>1</WinNumber>
<ItemText>LCount,0x0A</ItemText>
</Ww>
<Ww>
<count>55</count>
<WinNumber>1</WinNumber>
<ItemText>DataOld,0x0A</ItemText>
</Ww> </Ww>
</WatchWindow1> </WatchWindow1>
<MemoryWindow1> <MemoryWindow1>
@ -547,7 +517,7 @@
<pMultCmdsp></pMultCmdsp> <pMultCmdsp></pMultCmdsp>
<DebugDescription> <DebugDescription>
<Enable>1</Enable> <Enable>1</Enable>
<EnableFlashSeq>1</EnableFlashSeq> <EnableFlashSeq>0</EnableFlashSeq>
<EnableLog>0</EnableLog> <EnableLog>0</EnableLog>
<Protocol>2</Protocol> <Protocol>2</Protocol>
<DbgClock>10000000</DbgClock> <DbgClock>10000000</DbgClock>

View File

@ -17,8 +17,8 @@
<TargetCommonOption> <TargetCommonOption>
<Device>STM32F103C8</Device> <Device>STM32F103C8</Device>
<Vendor>STMicroelectronics</Vendor> <Vendor>STMicroelectronics</Vendor>
<PackID>Keil.STM32F1xx_DFP.2.4.1</PackID> <PackID>Keil.STM32F1xx_DFP.2.2.0</PackID>
<PackURL>https://www.keil.com/pack/</PackURL> <PackURL>http://www.keil.com/pack/</PackURL>
<Cpu>IRAM(0x20000000,0x00005000) IROM(0x08000000,0x00010000) CPUTYPE("Cortex-M3") CLOCK(12000000) ELITTLE</Cpu> <Cpu>IRAM(0x20000000,0x00005000) IROM(0x08000000,0x00010000) CPUTYPE("Cortex-M3") CLOCK(12000000) ELITTLE</Cpu>
<FlashUtilSpec></FlashUtilSpec> <FlashUtilSpec></FlashUtilSpec>
<StartupFile></StartupFile> <StartupFile></StartupFile>
@ -139,7 +139,7 @@
</Flash1> </Flash1>
<bUseTDR>1</bUseTDR> <bUseTDR>1</bUseTDR>
<Flash2>BIN\UL2CM3.DLL</Flash2> <Flash2>BIN\UL2CM3.DLL</Flash2>
<Flash3>"" ()</Flash3> <Flash3></Flash3>
<Flash4></Flash4> <Flash4></Flash4>
<pFcarmOut></pFcarmOut> <pFcarmOut></pFcarmOut>
<pFcarmGrp></pFcarmGrp> <pFcarmGrp></pFcarmGrp>
@ -177,7 +177,7 @@
<GenPPlst>0</GenPPlst> <GenPPlst>0</GenPPlst>
<AdsCpuType>"Cortex-M3"</AdsCpuType> <AdsCpuType>"Cortex-M3"</AdsCpuType>
<RvctDeviceName></RvctDeviceName> <RvctDeviceName></RvctDeviceName>
<mOS>0</mOS> <mOS>1</mOS>
<uocRom>0</uocRom> <uocRom>0</uocRom>
<uocRam>0</uocRam> <uocRam>0</uocRam>
<hadIROM>1</hadIROM> <hadIROM>1</hadIROM>
@ -191,7 +191,7 @@
<hadIRAM2>0</hadIRAM2> <hadIRAM2>0</hadIRAM2>
<hadIROM2>0</hadIROM2> <hadIROM2>0</hadIROM2>
<StupSel>8</StupSel> <StupSel>8</StupSel>
<useUlib>0</useUlib> <useUlib>1</useUlib>
<EndSel>0</EndSel> <EndSel>0</EndSel>
<uLtcg>0</uLtcg> <uLtcg>0</uLtcg>
<nSecure>0</nSecure> <nSecure>0</nSecure>
@ -424,6 +424,57 @@
<FileName>CS5552.c</FileName> <FileName>CS5552.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>.\Source\CS5552.c</FilePath> <FilePath>.\Source\CS5552.c</FilePath>
<FileOption>
<CommonProperty>
<UseCPPCompiler>2</UseCPPCompiler>
<RVCTCodeConst>0</RVCTCodeConst>
<RVCTZI>0</RVCTZI>
<RVCTOtherData>0</RVCTOtherData>
<ModuleSelection>0</ModuleSelection>
<IncludeInBuild>0</IncludeInBuild>
<AlwaysBuild>2</AlwaysBuild>
<GenerateAssemblyFile>2</GenerateAssemblyFile>
<AssembleAssemblyFile>2</AssembleAssemblyFile>
<PublicsOnly>2</PublicsOnly>
<StopOnExitCode>11</StopOnExitCode>
<CustomArgument></CustomArgument>
<IncludeLibraryModules></IncludeLibraryModules>
<ComprImg>1</ComprImg>
</CommonProperty>
<FileArmAds>
<Cads>
<interw>2</interw>
<Optim>0</Optim>
<oTime>2</oTime>
<SplitLS>2</SplitLS>
<OneElfS>2</OneElfS>
<Strict>2</Strict>
<EnumInt>2</EnumInt>
<PlainCh>2</PlainCh>
<Ropi>2</Ropi>
<Rwpi>2</Rwpi>
<wLevel>0</wLevel>
<uThumb>2</uThumb>
<uSurpInc>2</uSurpInc>
<uC99>2</uC99>
<uGnu>2</uGnu>
<useXO>2</useXO>
<v6Lang>0</v6Lang>
<v6LangP>0</v6LangP>
<vShortEn>2</vShortEn>
<vShortWch>2</vShortWch>
<v6Lto>2</v6Lto>
<v6WtE>2</v6WtE>
<v6Rtti>2</v6Rtti>
<VariousControls>
<MiscControls></MiscControls>
<Define></Define>
<Undefine></Undefine>
<IncludePath></IncludePath>
</VariousControls>
</Cads>
</FileArmAds>
</FileOption>
</File> </File>
<File> <File>
<FileName>AD7190.c</FileName> <FileName>AD7190.c</FileName>
@ -477,12 +528,12 @@
<filter> <filter>
<targetInfos/> <targetInfos/>
</filter> </filter>
<package name="CMSIS-Compiler" vendor="ARM"> <package name="CMSIS-RTX" vendor="ARM">
<targetInfos> <targetInfos>
<targetInfo name="Moisture"/> <targetInfo name="Moisture"/>
</targetInfos> </targetInfos>
</package> </package>
<package name="CMSIS-RTX" vendor="ARM"> <package name="CMSIS-RTX" schemaVersion="1.7.36" url="https://www.keil.com/pack/" vendor="ARM" version="5.9.0">
<targetInfos> <targetInfos>
<targetInfo name="Moisture"/> <targetInfo name="Moisture"/>
</targetInfos> </targetInfos>
@ -492,7 +543,12 @@
<targetInfo name="Moisture" versionMatchMode="fixed"/> <targetInfo name="Moisture" versionMatchMode="fixed"/>
</targetInfos> </targetInfos>
</package> </package>
<package name="STM32F1xx_DFP" vendor="Keil" version="2.4.1"> <package name="ARM_Compiler" vendor="Keil">
<targetInfos>
<targetInfo name="Moisture"/>
</targetInfos>
</package>
<package name="STM32F1xx_DFP" schemaVersion="1.4.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.2.0">
<targetInfos> <targetInfos>
<targetInfo name="Moisture" versionMatchMode="fixed"/> <targetInfo name="Moisture" versionMatchMode="fixed"/>
</targetInfos> </targetInfos>
@ -520,49 +576,49 @@
</targetInfos> </targetInfos>
</component> </component>
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="1.0.0" condition="STM32F1xx CMSIS"> <component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="1.0.0" condition="STM32F1xx CMSIS">
<package name="STM32F1xx_DFP" schemaVersion="1.7.2" url="http://www.keil.com/pack/" vendor="Keil" version="2.4.0"/> <package name="STM32F1xx_DFP" schemaVersion="1.4.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.2.0"/>
<targetInfos> <targetInfos>
<targetInfo name="Moisture"/> <targetInfo name="Moisture"/>
</targetInfos> </targetInfos>
</component> </component>
<component Cclass="Device" Cgroup="StdPeriph Drivers" Csub="ADC" Cvendor="Keil" Cversion="3.6.0" condition="STM32F1xx STDPERIPH RCC"> <component Cclass="Device" Cgroup="StdPeriph Drivers" Csub="ADC" Cvendor="Keil" Cversion="3.5.0" condition="STM32F1xx STDPERIPH RCC">
<package name="STM32F1xx_DFP" schemaVersion="1.7.2" url="http://www.keil.com/pack/" vendor="Keil" version="2.4.0"/> <package name="STM32F1xx_DFP" schemaVersion="1.4.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.2.0"/>
<targetInfos> <targetInfos>
<targetInfo name="Moisture"/> <targetInfo name="Moisture"/>
</targetInfos> </targetInfos>
</component> </component>
<component Cclass="Device" Cgroup="StdPeriph Drivers" Csub="Framework" Cvendor="Keil" Cversion="3.6.0" condition="STM32F1xx STDPERIPH"> <component Cclass="Device" Cgroup="StdPeriph Drivers" Csub="Framework" Cvendor="Keil" Cversion="3.5.1" condition="STM32F1xx STDPERIPH">
<package name="STM32F1xx_DFP" schemaVersion="1.7.2" url="http://www.keil.com/pack/" vendor="Keil" version="2.4.0"/> <package name="STM32F1xx_DFP" schemaVersion="1.4.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.2.0"/>
<targetInfos> <targetInfos>
<targetInfo name="Moisture"/> <targetInfo name="Moisture"/>
</targetInfos> </targetInfos>
</component> </component>
<component Cclass="Device" Cgroup="StdPeriph Drivers" Csub="GPIO" Cvendor="Keil" Cversion="3.6.0" condition="STM32F1xx STDPERIPH RCC"> <component Cclass="Device" Cgroup="StdPeriph Drivers" Csub="GPIO" Cvendor="Keil" Cversion="3.5.0" condition="STM32F1xx STDPERIPH RCC">
<package name="STM32F1xx_DFP" schemaVersion="1.7.2" url="http://www.keil.com/pack/" vendor="Keil" version="2.4.0"/> <package name="STM32F1xx_DFP" schemaVersion="1.4.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.2.0"/>
<targetInfos> <targetInfos>
<targetInfo name="Moisture"/> <targetInfo name="Moisture"/>
</targetInfos> </targetInfos>
</component> </component>
<component Cclass="Device" Cgroup="StdPeriph Drivers" Csub="RCC" Cvendor="Keil" Cversion="3.6.0" condition="STM32F1xx STDPERIPH"> <component Cclass="Device" Cgroup="StdPeriph Drivers" Csub="RCC" Cvendor="Keil" Cversion="3.5.0" condition="STM32F1xx STDPERIPH">
<package name="STM32F1xx_DFP" schemaVersion="1.7.2" url="http://www.keil.com/pack/" vendor="Keil" version="2.4.0"/> <package name="STM32F1xx_DFP" schemaVersion="1.4.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.2.0"/>
<targetInfos> <targetInfos>
<targetInfo name="Moisture"/> <targetInfo name="Moisture"/>
</targetInfos> </targetInfos>
</component> </component>
<component Cclass="Device" Cgroup="StdPeriph Drivers" Csub="SPI" Cvendor="Keil" Cversion="3.6.0" condition="STM32F1xx STDPERIPH RCC"> <component Cclass="Device" Cgroup="StdPeriph Drivers" Csub="SPI" Cvendor="Keil" Cversion="3.5.0" condition="STM32F1xx STDPERIPH RCC">
<package name="STM32F1xx_DFP" schemaVersion="1.7.2" url="http://www.keil.com/pack/" vendor="Keil" version="2.4.0"/> <package name="STM32F1xx_DFP" schemaVersion="1.4.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.2.0"/>
<targetInfos> <targetInfos>
<targetInfo name="Moisture"/> <targetInfo name="Moisture"/>
</targetInfos> </targetInfos>
</component> </component>
<component Cclass="Device" Cgroup="StdPeriph Drivers" Csub="TIM" Cvendor="Keil" Cversion="3.6.0" condition="STM32F1xx STDPERIPH RCC"> <component Cclass="Device" Cgroup="StdPeriph Drivers" Csub="TIM" Cvendor="Keil" Cversion="3.5.0" condition="STM32F1xx STDPERIPH RCC">
<package name="STM32F1xx_DFP" schemaVersion="1.7.2" url="http://www.keil.com/pack/" vendor="Keil" version="2.4.0"/> <package name="STM32F1xx_DFP" schemaVersion="1.4.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.2.0"/>
<targetInfos> <targetInfos>
<targetInfo name="Moisture"/> <targetInfo name="Moisture"/>
</targetInfos> </targetInfos>
</component> </component>
<component Cclass="Device" Cgroup="StdPeriph Drivers" Csub="USART" Cvendor="Keil" Cversion="3.6.0" condition="STM32F1xx STDPERIPH RCC"> <component Cclass="Device" Cgroup="StdPeriph Drivers" Csub="USART" Cvendor="Keil" Cversion="3.5.0" condition="STM32F1xx STDPERIPH RCC">
<package name="STM32F1xx_DFP" schemaVersion="1.7.2" url="http://www.keil.com/pack/" vendor="Keil" version="2.4.0"/> <package name="STM32F1xx_DFP" schemaVersion="1.4.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.2.0"/>
<targetInfos> <targetInfos>
<targetInfo name="Moisture"/> <targetInfo name="Moisture"/>
</targetInfos> </targetInfos>
@ -580,7 +636,7 @@
<file attr="config" category="header" name="RTE_Driver\Config\RTE_Device.h" version="1.1.2"> <file attr="config" category="header" name="RTE_Driver\Config\RTE_Device.h" version="1.1.2">
<instance index="0">RTE\Device\STM32F103C8\RTE_Device.h</instance> <instance index="0">RTE\Device\STM32F103C8\RTE_Device.h</instance>
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="1.0.0" condition="STM32F1xx CMSIS"/> <component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="1.0.0" condition="STM32F1xx CMSIS"/>
<package name="STM32F1xx_DFP" schemaVersion="1.7.2" url="https://www.keil.com/pack/" vendor="Keil" version="2.4.1"/> <package name="STM32F1xx_DFP" schemaVersion="1.4.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.2.0"/>
<targetInfos> <targetInfos>
<targetInfo name="Moisture"/> <targetInfo name="Moisture"/>
</targetInfos> </targetInfos>
@ -588,15 +644,15 @@
<file attr="config" category="source" condition="STM32F1xx MD ARMCC" name="Device\Source\ARM\startup_stm32f10x_md.s" version="1.0.1"> <file attr="config" category="source" condition="STM32F1xx MD ARMCC" name="Device\Source\ARM\startup_stm32f10x_md.s" version="1.0.1">
<instance index="0">RTE\Device\STM32F103C8\startup_stm32f10x_md.s</instance> <instance index="0">RTE\Device\STM32F103C8\startup_stm32f10x_md.s</instance>
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="1.0.0" condition="STM32F1xx CMSIS"/> <component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="1.0.0" condition="STM32F1xx CMSIS"/>
<package name="STM32F1xx_DFP" schemaVersion="1.7.2" url="https://www.keil.com/pack/" vendor="Keil" version="2.4.1"/> <package name="STM32F1xx_DFP" schemaVersion="1.4.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.2.0"/>
<targetInfos> <targetInfos>
<targetInfo name="Moisture"/> <targetInfo name="Moisture"/>
</targetInfos> </targetInfos>
</file> </file>
<file attr="config" category="source" name="Device\StdPeriph_Driver\templates\stm32f10x_conf.h" version="3.6.0"> <file attr="config" category="source" name="Device\StdPeriph_Driver\templates\stm32f10x_conf.h" version="3.6.0">
<instance index="0">RTE\Device\STM32F103C8\stm32f10x_conf.h</instance> <instance index="0">RTE\Device\STM32F103C8\stm32f10x_conf.h</instance>
<component Cclass="Device" Cgroup="StdPeriph Drivers" Csub="Framework" Cvendor="Keil" Cversion="3.6.0" condition="STM32F1xx STDPERIPH"/> <component Cclass="Device" Cgroup="StdPeriph Drivers" Csub="Framework" Cvendor="Keil" Cversion="3.5.1" condition="STM32F1xx STDPERIPH"/>
<package name="STM32F1xx_DFP" schemaVersion="1.7.2" url="https://www.keil.com/pack/" vendor="Keil" version="2.4.1"/> <package name="STM32F1xx_DFP" schemaVersion="1.4.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.2.0"/>
<targetInfos> <targetInfos>
<targetInfo name="Moisture"/> <targetInfo name="Moisture"/>
</targetInfos> </targetInfos>
@ -604,7 +660,7 @@
<file attr="config" category="source" name="Device\Source\system_stm32f10x.c" version="1.0.1"> <file attr="config" category="source" name="Device\Source\system_stm32f10x.c" version="1.0.1">
<instance index="0">RTE\Device\STM32F103C8\system_stm32f10x.c</instance> <instance index="0">RTE\Device\STM32F103C8\system_stm32f10x.c</instance>
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="1.0.0" condition="STM32F1xx CMSIS"/> <component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="1.0.0" condition="STM32F1xx CMSIS"/>
<package name="STM32F1xx_DFP" schemaVersion="1.7.2" url="https://www.keil.com/pack/" vendor="Keil" version="2.4.1"/> <package name="STM32F1xx_DFP" schemaVersion="1.4.0" url="http://www.keil.com/pack/" vendor="Keil" version="2.2.0"/>
<targetInfos> <targetInfos>
<targetInfo name="Moisture"/> <targetInfo name="Moisture"/>
</targetInfos> </targetInfos>

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/* /*
* UVISION generated file: DO NOT EDIT! * UVISION generated file: DO NOT EDIT!
* Generated by: uVision version 5.40.0.0 * Generated by: uVision version 5.42.0.0
* *
* Project: 'Moisture' * Project: 'Moisture'
* Target: 'Moisture' * Target: 'Moisture'
@ -17,20 +17,20 @@
/* ARM::CMSIS:RTOS:Keil RTX@4.82.0 */ /* ARM::CMSIS:RTOS:Keil RTX@4.82.0 */
#define RTE_CMSIS_RTOS /* CMSIS-RTOS */ #define RTE_CMSIS_RTOS /* CMSIS-RTOS */
#define RTE_CMSIS_RTOS_RTX /* CMSIS-RTOS Keil RTX */ #define RTE_CMSIS_RTOS_RTX /* CMSIS-RTOS Keil RTX */
/* Keil::Device:StdPeriph Drivers:ADC@3.6.0 */ /* Keil::Device:StdPeriph Drivers:ADC@3.5.0 */
#define RTE_DEVICE_STDPERIPH_ADC #define RTE_DEVICE_STDPERIPH_ADC
/* Keil::Device:StdPeriph Drivers:Framework@3.6.0 */ /* Keil::Device:StdPeriph Drivers:Framework@3.5.1 */
#define RTE_DEVICE_STDPERIPH_FRAMEWORK #define RTE_DEVICE_STDPERIPH_FRAMEWORK
/* Keil::Device:StdPeriph Drivers:GPIO@3.6.0 */ /* Keil::Device:StdPeriph Drivers:GPIO@3.5.0 */
#define RTE_DEVICE_STDPERIPH_GPIO #define RTE_DEVICE_STDPERIPH_GPIO
/* Keil::Device:StdPeriph Drivers:RCC@3.6.0 */ /* Keil::Device:StdPeriph Drivers:RCC@3.5.0 */
#define RTE_DEVICE_STDPERIPH_RCC #define RTE_DEVICE_STDPERIPH_RCC
/* Keil::Device:StdPeriph Drivers:SPI@3.6.0 */ /* Keil::Device:StdPeriph Drivers:SPI@3.5.0 */
#define RTE_DEVICE_STDPERIPH_SPI #define RTE_DEVICE_STDPERIPH_SPI
/* Keil::Device:StdPeriph Drivers:TIM@3.6.0 */ /* Keil::Device:StdPeriph Drivers:TIM@3.5.0 */
#define RTE_DEVICE_STDPERIPH_TIM #define RTE_DEVICE_STDPERIPH_TIM
/* Keil::Device:StdPeriph Drivers:USART@3.6.0 */ /* Keil::Device:StdPeriph Drivers:USART@3.5.0 */
#define RTE_DEVICE_STDPERIPH_USART #define RTE_DEVICE_STDPERIPH_USART

View File

@ -1,6 +1,8 @@
#include "spi.h" #include "spi.h"
#include "APPDEF.H" #include "APPDEF.H"
#include "math.h" #include "math.h"
#include "string.h"
#include "stdio.h"
// AD7190寄存器地址定义 // AD7190寄存器地址定义
#define AD7190_REG_COMM 0x00 << 3 #define AD7190_REG_COMM 0x00 << 3
#define AD7190_REG_STAT 0x00 << 3 #define AD7190_REG_STAT 0x00 << 3
@ -15,26 +17,39 @@
#define AD7190_CMD_RD 0x40 #define AD7190_CMD_RD 0x40
// AD7190配置寄存器位掩码 // AD7190配置寄存器位掩码
#define AD7190_CONF_CH_MASK 0x000F #define AD7190_CONF_CHOP 0x800000
#define AD7190_CONF_BURNOUT 0x0800 #define AD7190_CONF_REFSEL2 0x100000
#define AD7190_CONF_REFSEL 0x0400 // AD7190配置寄存器通道选择
#define AD7190_CONF_GAIN_MASK 0x0038 #define AD7190_CONF_CH7 0x008000
#define AD7190_CONF_MODE_MASK 0x0C00 #define AD7190_CONF_CH6 0x004000
#define AD7190_CONF_CH5 0x002000
#define AD7190_CONF_CH4 0x001000
#define AD7190_CONF_CH3 0x000800
#define AD7190_CONF_CH2 0x000400
#define AD7190_CONF_CH1 0x000200
#define AD7190_CONF_CH0 0x000100
// AD7190配置寄存器
#define AD7190_CONF_BURNOUT 0x000080
#define AD7190_CONF_REFDET 0x000040
#define AD7190_CONF_BUF 0x000010
#define AD7190_CONF_UB 0x000008
// AD7190配置寄存器增益定义 // AD7190配置寄存器增益定义
#define AD7190_CONF_GAIN_1 0x00 #define AD7190_CONF_GAIN_1 0x000000
#define AD7190_CONF_GAIN_8 0x08 #define AD7190_CONF_GAIN_8 0x000003
#define AD7190_CONF_GAIN_16 0x10 #define AD7190_CONF_GAIN_16 0x000004
#define AD7190_CONF_GAIN_32 0x18 #define AD7190_CONF_GAIN_32 0x000005
#define AD7190_CONF_GAIN_64 0x20 #define AD7190_CONF_GAIN_64 0x000006
#define AD7190_CONF_GAIN_128 0x28 #define AD7190_CONF_GAIN_128 0x000007
#define AD7190_CONF_GAIN_256 0x30
// AD7190配置寄存器工作模式定义 // AD7190配置寄存器工作模式定义
#define AD7190_CONF_MODE_CONT 0x000000 #define AD7190_CONF_MODE_CONT 0x000000
#define AD7190_CONF_MODE_ZEROSEL 0x800000 #define AD7190_CONF_MODE_ZEROSEL 0x800000
#define AD7190_CONF_MODE_FullSEL 0xA00000 #define AD7190_CONF_MODE_FullSEL 0xA00000
#define AD7190_CONF_MODE_FS9_0 0x0003FF #define AD7190_CONF_MODE_FS9_0 0x0003FF // 4.7Hz
#define AD7190_CONF_MODE_FS9_02 0x0001E0//10Hz
#define AD7190_CONF_MODE_FS9_03 0x000096//50Hz
#define AD7190_CONF_MODE_InCLK 0x080000// 4.92 MHz内部时钟 MCLK2引脚为三态
// AD7190 电桥开关 // AD7190 电桥开关
#define AD7190_GPOCON_BDPSW 0x40 #define AD7190_GPOCON_BDPSW 0x40
@ -71,11 +86,7 @@ uint8_t AD7190_ReadRegisterOnce(uint8_t regAddr)
bool AD7190_WaitForReady(uint32_t timeout) bool AD7190_WaitForReady(uint32_t timeout)
{ {
uint32_t count = 0; uint32_t count = 0;
// SPI1_ReadWrite(AD7190_CMD_RD | AD7190_REG_STAT);
// while ((SPI1_ReadWrite(0xFF) & 0x80) && (count < timeout)) {
// delay_us(1);
// count++;
// }
while (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_6) && (count < timeout)) while (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_6) && (count < timeout))
{ {
delay_us(1); delay_us(1);
@ -98,24 +109,89 @@ bool AD7190_WaitForReady(uint32_t timeout)
// // 获取 ADC 参考电压值(一般为 3.3V // // 获取 ADC 参考电压值(一般为 3.3V
// float Vref = 3.3; // 参考电压值(V) // float Vref = 3.3; // 参考电压值(V)
//float TemperatureIn; //float TemperatureIn;
uint8_t ErrCount; uint8_t ErrCount;
uint32_t AD7190_ReadData() uint16_t DifErrCount;
uint32_t lastdata = 0;
uint32_t UseuLBuf[20];
uint32_t UseuLBuf2[20];
uint16_t BufIndex = 0;
// 计算一组数字的平均值
float calculateAverage(uint32_t arr[], int size)
{
double sum = 0.0;
// 计算总和
int i;
for (i = 0; i < size; i++)
{
sum += arr[i];
}
// 计算平均值
double average = sum / size;
return average;
}
void bubbleSort(uint32_t *arr, int n) {
int i, j, temp;
for (i = 0; i < n-1; i++) {
for (j = 0; j < n-i-1; j++) {
if (arr[j] > arr[j+1]) {
// 交换 arr[j] 和 arr[j+1]
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}
/**
***********************************************************
* @brief printf函数默认打印输出到显示器
fputc函数
* @param
* @return
***********************************************************
*/
int fputc(int ch, FILE *f)
{
while (!(READ_BIT(USART1->SR, USART_SR_TXE))) {
delay_us(100);
}
USART1->DR = ch;
return ch;
}
float average;
float center;
int ErrcountAdd = 0;
int DifErrCountAdd = 0;
uint32_t AD7190_ReadData( void )
{ {
uint32_t data = 0; uint32_t data = 0;
//uint16_t TempI;
if(AD7190_WaitForReady(50000)) if(AD7190_WaitForReady(50000))
{ {
data = AD7190_ReadRegister(AD7190_REG_DATA); data = AD7190_ReadRegister(AD7190_REG_DATA);
// TempI = Read_Internal_Temperature(); if(fabs((int)data - (int)lastdata) > 100000 )
// // 将 ADC 值转换为电压值 {
// float V_ADC = (TempI * Vref) / 4095; DifErrCount ++;
DifErrCountAdd++;
// // 计算温度值(摄氏度) }
// TemperatureIn = ((V25 - V_ADC)*1000 / Avg_Slope) + 25.0; else
if(data > 15000000) {
DifErrCount = 0;
}
lastdata = data;
if((data > 8388608) || (data < 100 ))
{ {
ErrCount++; ErrCount++;
ErrcountAdd++;
} }
else else
{ {
@ -125,76 +201,53 @@ uint32_t AD7190_ReadData()
else else
{ {
ErrCount++; ErrCount++;
ErrcountAdd++;
} }
if(ErrCount > 10) if(ErrCount > 3 || DifErrCount > 20)
{ {
uint32_t modeReg;
SPI1_Configuration(); SPI1_Configuration();
SPI1_ReadWrite(0xFF); SPI1_ReadWrite(0xFF);
SPI1_ReadWrite(0xFF); SPI1_ReadWrite(0xFF);
SPI1_ReadWrite(0xFF); SPI1_ReadWrite(0xFF);
SPI1_ReadWrite(0xFF); SPI1_ReadWrite(0xFF);
SPI1_ReadWrite(0xFF); SPI1_ReadWrite(0xFF); // 40个脉冲复位ADC
osDelay(50); osDelay(50);
uint32_t modeReg;
// 配置寄存器:通道选择、参考电压源、增益和工作模式 // 配置寄存器:通道选择、参考电压源、增益和工作模式
// 打开PSW // 打开PSW
uint8_t GPOC = AD7190_ReadRegisterOnce(AD7190_REG_GPOC); uint8_t GPOC = AD7190_ReadRegisterOnce(AD7190_REG_GPOC);
GPOC |= AD7190_GPOCON_BDPSW; GPOC |= AD7190_GPOCON_BDPSW;
AD7190_WriteRegisterOnce(AD7190_REG_GPOC, GPOC); AD7190_WriteRegisterOnce(AD7190_REG_GPOC, GPOC);
osDelay(5); osDelay(5);
uint32_t config = 0x0000011F; uint32_t config = AD7190_CONF_GAIN_128 | AD7190_CONF_UB | AD7190_CONF_BUF | AD7190_CONF_CH0;// 0x0000011F;
AD7190_WriteRegister(AD7190_REG_CONF, config); AD7190_WriteRegister(AD7190_REG_CONF, config);
osDelay(5); osDelay(5);
modeReg |= AD7190_CONF_MODE_FS9_0; // 滤波器最低速率输出
AD7190_WriteRegister(AD7190_REG_MODE, modeReg); // 连续转换模式
osDelay(5); modeReg = AD7190_CONF_MODE_FS9_0 | AD7190_CONF_MODE_InCLK;
// 执行上电校准
modeReg = AD7190_ReadRegister(AD7190_REG_MODE);
modeReg &= ~0x00E00000;
modeReg |= AD7190_CONF_MODE_ZEROSEL;
AD7190_WriteRegister(AD7190_REG_MODE, modeReg);
osDelay(5);
AD7190_WaitForReady(1000000);
modeReg &= ~0x00E00000;
modeReg |= AD7190_CONF_MODE_FullSEL;
AD7190_WriteRegister(AD7190_REG_MODE, modeReg);
osDelay(5);
AD7190_WaitForReady(1000000);
// 校准完成 切换回连续转换模式
modeReg = 0x000803FF;
AD7190_WriteRegister(AD7190_REG_MODE, modeReg); AD7190_WriteRegister(AD7190_REG_MODE, modeReg);
ErrCount = 0; ErrCount = 0;
osDelay(500); osDelay(500);
if(AD7190_WaitForReady(50000)) if(AD7190_WaitForReady(50000))
{ {
data = AD7190_ReadRegister(AD7190_REG_DATA); data = AD7190_ReadRegister(AD7190_REG_DATA);
} }
} }
return data; return data;
} }
// AD7190函数读取AD转换结果并转换为实际电压值
// static void bubbleSort2(float *num) // 定义卡尔曼滤波器的参数结构体
//{
// float temp;
// int i, j;
// for (i = 0; i < 5; i++) {
// for (j = 0; j < 5 - i; j++) {
// if (num[j] > num[j + 1]) {
// // 交换相邻元素的值
// temp = num[j];
// num[j] = num[j + 1];
// num[j + 1] = temp;
// }
// }
// }
//} // 定义卡尔曼滤波器的参数结构体
typedef struct typedef struct
{ {
float x; // 状态估计值 double x; // 状态估计值
float P; // 状态协方差 double P; // 状态协方差
float Q; // 过程噪声协方差 double Q; // 过程噪声协方差
float R; // 观测噪声协方差 double R; // 观测噪声协方差
float K; // 卡尔曼增益 double K; // 卡尔曼增益
} KalmanFilter; } KalmanFilter;
KalmanFilter kf2; KalmanFilter kf2;
@ -220,27 +273,50 @@ void kalman_filter_update2(KalmanFilter *kf, float measurement)
kf->P = (1 - kf->K) * P_pred; // 更新状态协方差 kf->P = (1 - kf->K) * P_pred; // 更新状态协方差
} }
float WeightData2 = 0.0f;
float ADvalue2filter = 0.0f; uint8_t FollowCount = 0; // 零点跟踪计数
// static float bufferdata2[5]; uint8_t TimeCount = 0; // 蠕变时间计数
// static float dataout2[5]; uint32_t FliterCount = 0; // 长期抑制计数
static float WeightData2Temp = 0.0f; uint16_t SetZeroCount = 0; // 卸载归零计数
int32_t ADvalue2filterOld = 0;
int32_t ADvalue2 = 0; int32_t ADvalue2 = 0; // ADC采样原始值
uint8_t ic2 = 0;
double ADvalue2filter = 0.0f; // ADC采样卡尔曼滤波值
double ADvalue2filterOld = 0; // 上次ADC采样卡尔曼滤波值
double WeightData2Temp = 0.0f; // 本次ADvalue2filter计算重量值
double WeightData2TempOld; // 上次ADvalue2filter计算重量值
double WeightData2Finally = 0.0f; // 最终输出前重量值
double UninstiallRefWeight= 0.0f; // 卸载重物时的重量值
double WeightZeroOld = 0; // 上次稳定状态时零点值
struct uCalibrateWeight CalibrateWeight2; //传感器 斜率 零点
double WeightData2 = 0.0f; // 最终输出重量值
bool weightChanging = false; // 传感器稳定标志
bool weight11g = false; // 传感器稳定标志
float ZeroWeightOld;
float ZeroWeightChange;
float LowFecAlpha = 0.95f; // 超低频波动抑制系数,发生突变时偏向跟踪新值,相对稳定时跟踪旧值
float WeightRefStart = 0;
uint8_t i; uint8_t i;
int32_t data2 = 0;
struct uCalibrateWeight CalibrateWeight2; #define ChangeMax 10
uint8_t FollowCount = 0; #define ZeroTrackMax 0.050f
uint8_t TimeCount = 0; #define FollowMax 0.030f
int32_t WeightZeroOld = 0; #define FliterCountMax 200
uint32_t modeRega; #define FollowDlteaMax 0.001f
uint32_t configa; #define FollowAlpha 0.9999f // 长期数据跟踪系数
uint32_t configao;
bool weightChanging = false;
#include "APPDEF.H"
void AD7190_Run(const void *p_arg) void AD7190_Run(const void *p_arg)
{ {
uint8_t FilterQOld, SensorQOld, ZeroTrackOld, RuBianLiangOld, ruBianTimeOld;
int8_t RubianLiang, RubianTime;
float ZeroTrackTime, ZeroTrackRange;
osDelay(600); osDelay(600);
ADvalue2 = AD7190_ReadData(); ADvalue2 = AD7190_ReadData();
osDelay(200); osDelay(200);
@ -248,16 +324,12 @@ void AD7190_Run(const void *p_arg)
ADvalue2filterOld = ADvalue2filter = ADvalue2; ADvalue2filterOld = ADvalue2filter = ADvalue2;
kalman_filter_init2(&kf2, ADvalue2, 1.0, 0.001, 0.1); kalman_filter_init2(&kf2, ADvalue2, 1.0, 0.001, 0.1);
WeightZeroOld = CalibrateWeight2.WeightZero; WeightZeroOld = CalibrateWeight2.WeightZero;
uint8_t FilterQOld, SensorQOld, ZeroTrackOld, RuBianLiangOld, ruBianTimeOld;
int8_t RubianLiang, RubianTime;
float ZeroTrackTime, ZeroTrackRange;
for (;;) for (;;)
{ {
if (FilterQOld != Set.FilterQ) if (FilterQOld != Set.FilterQ)
{ {
FilterQOld = Set.FilterQ; FilterQOld = Set.FilterQ;
switch (Set.FilterQ) // 滤波器信任度 信任度越高 反应越慢数据显示越稳定 switch (Set.FilterQ) // 滤波器信任度 信任度越高 反应越慢数据显示越稳定
{ {
case 0: case 0:
kf2.Q = 0.1; kf2.Q = 0.1;
@ -296,7 +368,7 @@ void AD7190_Run(const void *p_arg)
if (SensorQOld != Set.SensorQ) if (SensorQOld != Set.SensorQ)
{ {
SensorQOld = Set.SensorQ; SensorQOld = Set.SensorQ;
switch (Set.SensorQ) // 传感器信任度 信任度越高 反应越迅速,数据波动越大 显示越不稳定 switch (Set.SensorQ) // 传感器信任度 信任度越高 反应越迅速,数据波动越大 显示越不稳定
{ {
case 0: case 0:
kf2.R = 0.5; kf2.R = 0.5;
@ -332,14 +404,14 @@ void AD7190_Run(const void *p_arg)
break; break;
} }
} }
if (ZeroTrackOld != Set.ZeroTrack) // 零点跟踪 跟踪级别越高 原始数据发生缓慢变化时,最终数据不会发生变化的可能性越大。例如 当跟踪级别设置为9时那么如果原始数据在4秒内变化小于2.5mg那么最终数据不会发生变化。原理是cpu会将这4秒内变化的数据叠加到零点上相当于动态调零了。 if (ZeroTrackOld != Set.ZeroTrack) // 零点跟踪 跟踪级别越高 原始数据发生缓慢变化时,最终数据不会发生变化的可能性越大。例如 当跟踪级别设置为9时那么如果原始数据在4秒内变化小于2.5mg那么最终数据不会发生变化。原理是cpu会将这4秒内变化的数据叠加到零点上相当于动态调零了。
{ {
ZeroTrackOld = Set.ZeroTrack; ZeroTrackOld = Set.ZeroTrack;
switch (ZeroTrackOld) switch (ZeroTrackOld)
{ {
case 0: case 0:
ZeroTrackTime = 20; ZeroTrackTime = 20; // 连续20秒
ZeroTrackRange = 0; ZeroTrackRange = 0; // 相邻两次采样数据小于0.000g
break; break;
case 1: case 1:
ZeroTrackTime = 15; ZeroTrackTime = 15;
@ -381,7 +453,7 @@ void AD7190_Run(const void *p_arg)
break; break;
} }
} }
if (ruBianTimeOld != Set.RuBianTime) // 蠕变时间 级别越高 蠕变时间越短,蠕变越快 零为不蠕变 if (ruBianTimeOld != Set.RuBianTime) // 蠕变时间 级别越高 蠕变时间越短,蠕变越快 零为不蠕变
{ {
ruBianTimeOld = Set.RuBianTime; ruBianTimeOld = Set.RuBianTime;
switch (Set.RuBianTime) switch (Set.RuBianTime)
@ -420,7 +492,7 @@ void AD7190_Run(const void *p_arg)
break; break;
} }
} }
if (RuBianLiangOld != Set.RuBianLiang) //蠕变量 可分正向蠕变和反向蠕变 零为不蠕变 当零点跟踪为0时 调零后观察一段时间的数据变化 如果数据持续变化为负数 则为负蠕变。反之为正蠕变。 负蠕变调整蠕变量为负数级别(谨慎调整 建议不调整) if (RuBianLiangOld != Set.RuBianLiang) //蠕变量 可分正向蠕变和反向蠕变 零为不蠕变 当零点跟踪为0时 调零后观察一段时间的数据变化 如果数据持续变化为负数 则为负蠕变。反之为正蠕变。 负蠕变调整蠕变量为负数级别(谨慎调整 建议不调整)
{ {
RuBianLiangOld = Set.RuBianLiang; RuBianLiangOld = Set.RuBianLiang;
switch (Set.RuBianLiang) switch (Set.RuBianLiang)
@ -463,13 +535,74 @@ void AD7190_Run(const void *p_arg)
} }
} }
osDelay(190);
ADvalue2 = AD7190_ReadData();
kalman_filter_update2(&kf2, ADvalue2); // 更新步骤
ADvalue2filter = kf2.x;
WeightData2Temp = CalibrateWeight2.WeightSlope * ((int32_t)ADvalue2filter - (int32_t)CalibrateWeight2.WeightZero); osDelay(200);
if( RubianLiang != 0 ) ADvalue2 = AD7190_ReadData(); //4.7Hz 213ms
kalman_filter_update2(&kf2, ADvalue2); // 更新步骤
if(fabs(ADvalue2filter - kf2.x) < ChangeMax )
{
LowFecAlpha = 0.95; // 数据处于稳定状态 未有重量突变或小幅度连续单向改变时信任上次值
}
else
{
LowFecAlpha = 0.5; // 数据处于较大波动状态 有重量突变或小幅度连续单向改变时信任本次值
}
ADvalue2filter = kf2.x *(1-LowFecAlpha)+ADvalue2filter*LowFecAlpha;
// if(pageNum != 1)
// {
// if(WeightData2TempOld - WeightData2Temp > 0.500f) // 卸载重物
// {
// if(UninstiallRefWeight < 0.005f) // 如果未触发归零条件
// {
// UninstiallRefWeight = WeightData2TempOld;
// WeightZeroOld = CalibrateWeight2.WeightZero; // 备份零点原始值,以备不稳定状态下重新加载重物导致数据不准确
// }
// }
// else if(WeightData2TempOld - WeightData2Temp < -0.500f)//加载重物
// {
// UninstiallRefWeight = 0.0f;
// if( WeightZeroOld != CalibrateWeight2.WeightZero)
// {
// CalibrateWeight2.WeightZero = WeightZeroOld; // 置零未完成或零点跟踪未完成,恢复至改变前零点值,防止数据不准确
// }
// SetZeroCount = 0;
// }
// if(UninstiallRefWeight > 0.005f) // 卸载重物后接近归零时进行归零操作
// {
// if(SetZeroCount++ > 50 ) // 归零后重置触发归零条件
// {
//
// UninstiallRefWeight = 0.0f;
// WeightZeroOld = CalibrateWeight2.WeightZero;
// SetZeroCount = 0;
// }
// if(fabs(WeightData2Temp) < 0.100f && fabs(WeightData2Temp) > 0.004f) // 符合归零区间范围则缓慢归零
// {
// SetZeroCount = 0;
// CalibrateWeight2.WeightZero += WeightData2Temp / CalibrateWeight2.WeightSlope / 10;
// ZeroWeightChange = CalibrateWeight2.WeightSlope * (ADvalue2filter - CalibrateWeight2.WeightZero);
// }
// ZeroWeightOld = CalibrateWeight2.WeightSlope * (ADvalue2filter - WeightZeroOld);
// if( fabs(ZeroWeightOld) <= fabs(ZeroWeightChange) )
// {
// weight11g=0;
// CalibrateWeight2.WeightZero = WeightZeroOld;
// }
// else
// {
// weight11g=1;
// }
// }
// }
WeightData2TempOld = WeightData2Temp;
WeightData2Temp = CalibrateWeight2.WeightSlope * (ADvalue2filter - CalibrateWeight2.WeightZero);
// printf("%f,%f,%f,%.4f\n",Temperature,ADvalue2filter,WeightData2Temp,WeightData2Finally);
if( RubianLiang != 0 ) // 蠕变
{ {
if (TimeCount++ > 4 * RubianTime) // 动态称重时蠕变跟踪 if (TimeCount++ > 4 * RubianTime) // 动态称重时蠕变跟踪
{ {
@ -482,13 +615,14 @@ void AD7190_Run(const void *p_arg)
} }
} }
if (fabs(WeightData2 - WeightData2Temp) < ZeroTrackRange) if (fabs(WeightData2TempOld - WeightData2Temp) < ZeroTrackRange && fabs(WeightData2Temp) < ZeroTrackMax && ( pageNum != 1)) // 符合跟踪范围 型评 当示值为零或相当于毛重为0时 负的净重值,且未运行,且水分测定仪处于平衡稳定状态 才允许运行
{ {
if (FollowCount++ > 4 * ZeroTrackTime) // 零点动态跟踪 if (FollowCount++ > 4 * ZeroTrackTime) // 零点动态跟踪
{ {
FollowCount = 0; FollowCount = 0;
TimeCount = 0; TimeCount = 0;
CalibrateWeight2.WeightZero += ADvalue2filter - ADvalue2filterOld; CalibrateWeight2.WeightZero += ADvalue2filter - ADvalue2filterOld;
WeightZeroOld = CalibrateWeight2.WeightZero;
ADvalue2filterOld = ADvalue2filter; ADvalue2filterOld = ADvalue2filter;
} }
} }
@ -497,7 +631,23 @@ void AD7190_Run(const void *p_arg)
FollowCount = 0; FollowCount = 0;
ADvalue2filterOld = ADvalue2filter; ADvalue2filterOld = ADvalue2filter;
} }
if (fabs(WeightData2 - WeightData2Temp) > 0.01f)
if ( fabs(WeightData2Temp) > ZeroTrackMax && fabs(WeightData2TempOld - WeightData2Temp) < FollowDlteaMax && fabs(WeightData2Temp - WeightRefStart) < FollowMax && ( pageNum != 1)) //重量不变且大于零点跟踪范围未加热进行长期数据跟踪
{
if(FliterCount < FliterCountMax)
FliterCount++;
else
FliterCount = FliterCountMax;
WeightData2Finally = WeightData2Finally + (WeightData2Temp - WeightData2Finally) * ( 1.00000f - FollowAlpha * FliterCount / FliterCountMax);
}
else
{
WeightData2Finally = WeightRefStart = WeightData2Temp;
FliterCount = 0;
}
if (fabs(WeightData2 - WeightData2Finally) > 0.006f) // 变化大于50mg/s 置位传感器不稳定标志
{ {
weightChanging = 1; weightChanging = 1;
} }
@ -505,12 +655,17 @@ void AD7190_Run(const void *p_arg)
{ {
weightChanging = 0; weightChanging = 0;
} }
if (fabs(WeightData2 - WeightData2Temp) > 0.001f) // 数据滤波
{
WeightData2Temp = (int32_t)(WeightData2Temp * 10000) / 10000.0f;
WeightData2 = WeightData2Temp; if (fabs(WeightData2 - WeightData2Finally) > 0.0002f) // 数据滤波
{
WeightData2 = (int32_t)(WeightData2Finally * 10000) / 10000.0f;
} }
else if(fabs(WeightData2Finally) < 0.001f)
{
WeightData2 = (int32_t)(WeightData2Finally * 10000) / 10000.0f;
}
} }
} }
@ -518,44 +673,33 @@ osThreadDef(AD7190_Run, osPriorityNormal, 1, 0);
// AD7190函数初始化AD7190 // AD7190函数初始化AD7190
void AD7190_Init() void AD7190_Init()
{ {
uint32_t modeReg;
SPI1_Configuration(); SPI1_Configuration();
SPI1_ReadWrite(0xFF); SPI1_ReadWrite(0xFF);
SPI1_ReadWrite(0xFF); SPI1_ReadWrite(0xFF);
SPI1_ReadWrite(0xFF); SPI1_ReadWrite(0xFF);
SPI1_ReadWrite(0xFF); SPI1_ReadWrite(0xFF);
SPI1_ReadWrite(0xFF); SPI1_ReadWrite(0xFF); // 40个脉冲复位ADC
osDelay(50); osDelay(50);
uint32_t modeReg;
// 配置寄存器:通道选择、参考电压源、增益和工作模式 // 配置寄存器:通道选择、参考电压源、增益和工作模式
// 打开PSW // 打开PSW
uint8_t GPOC = AD7190_ReadRegisterOnce(AD7190_REG_GPOC); uint8_t GPOC = AD7190_ReadRegisterOnce(AD7190_REG_GPOC);
GPOC |= AD7190_GPOCON_BDPSW; GPOC |= AD7190_GPOCON_BDPSW;
AD7190_WriteRegisterOnce(AD7190_REG_GPOC, GPOC); AD7190_WriteRegisterOnce(AD7190_REG_GPOC, GPOC);
osDelay(5); osDelay(5);
uint32_t config = 0x0000011F; uint32_t config = AD7190_CONF_GAIN_128 | AD7190_CONF_UB | AD7190_CONF_BUF | AD7190_CONF_CH0;// 0x0000011F;
AD7190_WriteRegister(AD7190_REG_CONF, config); AD7190_WriteRegister(AD7190_REG_CONF, config);
osDelay(5); osDelay(5);
modeReg |= AD7190_CONF_MODE_FS9_0; // 滤波器最低速率输出 modeReg = AD7190_CONF_MODE_FS9_0 ;// 滤波器最低速率输出 执行上电校准
AD7190_WriteRegister(AD7190_REG_MODE, modeReg); AD7190_WriteRegister(AD7190_REG_MODE, modeReg);
osDelay(5); osDelay(5);
// 执行上电校准 //连续转换模式
modeReg = AD7190_ReadRegister(AD7190_REG_MODE); modeReg = AD7190_CONF_MODE_FS9_0 | AD7190_CONF_MODE_InCLK;
modeReg &= ~0x00E00000;
modeReg |= AD7190_CONF_MODE_ZEROSEL;
AD7190_WriteRegister(AD7190_REG_MODE, modeReg);
osDelay(5);
AD7190_WaitForReady(1000000);
modeReg &= ~0x00E00000;
modeReg |= AD7190_CONF_MODE_FullSEL;
AD7190_WriteRegister(AD7190_REG_MODE, modeReg);
osDelay(5);
AD7190_WaitForReady(1000000);
// 校准完成 切换回连续转换模式
modeReg = 0x000803FF;
AD7190_WriteRegister(AD7190_REG_MODE, modeReg); AD7190_WriteRegister(AD7190_REG_MODE, modeReg);
CalibrateWeight2.WeightSlope = 0.0000818f; CalibrateWeight2.WeightSlope = 0.0001530345f;
CalibrateWeight2.WeightZero = 745430; // CalibrateWeight2.WeightZero = 745430;
osThreadCreate(osThread(AD7190_Run), NULL); osThreadCreate(osThread(AD7190_Run), NULL);
} }

View File

@ -52,21 +52,7 @@ extern uint8_t ucRegCoilsBuf[];
*******************************************************************************/ *******************************************************************************/
extern void delay_us(uint32_t us); extern void delay_us(uint32_t us);
/******************************** 功能说明 *************************************
*
*******************************************************************************/
extern float UltrasoundData;
extern float H, S, V;
extern int sR, sG, sB;
struct ColorH {
float A; // 三次方
float B; // 二次方
float C; // 一次方
float D; // 常数
};
extern struct ColorH ColorHSV;
extern float ColorOut;
/******************************** 功能说明 ************************************* /******************************** 功能说明 *************************************
* *
*******************************************************************************/ *******************************************************************************/
@ -80,18 +66,22 @@ extern void AD7190_Init(void);
extern void AD7190_ReadVoltage(void); extern void AD7190_ReadVoltage(void);
extern void WeightCtrl_Init(void); extern void WeightCtrl_Init(void);
extern uint8_t pageNum;
struct uCalibrateWeight { struct uCalibrateWeight {
double WeightSlope; // 斜率 double WeightSlope; // 斜率
int32_t WeightZero; // 零点 double WeightZero; // 零点
}; };
extern struct uCalibrateWeight CalibrateWeight; extern struct uCalibrateWeight CalibrateWeight;
extern struct uCalibrateWeight CalibrateWeight2; extern struct uCalibrateWeight CalibrateWeight2;
extern uint32_t HX711Data; // 原始数据 extern uint32_t HX711Data; // 原始数据
extern uint32_t HX711Zero; // 原始数据 extern uint32_t HX711Zero; // 原始数据
extern float WeightData; // 重量数据 extern float WeightData; // 重量数据
extern float WeightData2; // 重量数据 extern double WeightData2; // 重量数据
extern float ADvalue2filter; extern double ADvalue2filter;
extern double WeightZeroOld;
extern double WeightData2Finally;
extern float Temperature;
extern void MAX6675_Init(void); extern void MAX6675_Init(void);
extern void USARTHMIInit(void); extern void USARTHMIInit(void);
@ -130,7 +120,7 @@ struct Pset {
bool SW0; // 自定义开关1 bool SW0; // 自定义开关1
bool SW1; // 自定义开关2 bool SW1; // 自定义开关2
bool SW2; // 自定义开关3 bool SW2; // 自定义开关3
bool PercentChange; // 含水量含固量 uint8_t PercentType; // 含水量含固量
uint8_t Title[32]; // 标题 uint8_t Title[32]; // 标题
uint8_t TitleOne[32]; // 标题1 uint8_t TitleOne[32]; // 标题1
uint8_t TitleTwo[32]; // 标题2 uint8_t TitleTwo[32]; // 标题2
@ -147,7 +137,7 @@ extern void FM24_Write(uint16_t addr, uint8_t *data, uint8_t len);
extern void FM24_Read(uint16_t addr, uint8_t *data, uint8_t len); extern void FM24_Read(uint16_t addr, uint8_t *data, uint8_t len);
#define CalibrateWeight2Set 0x0140u #define CalibrateWeight2Set 0x0140u
#define RW_Set 0x0200u #define RW_Set 0x0200u
#define CRCHead 0x55AAu #define CRCHead 0x5A5Au
// #define RW_WeightSlope 0x0104u // #define RW_WeightSlope 0x0104u
// #define RW_WeightZero 0x0108u // #define RW_WeightZero 0x0108u
// #define RW_ColorHSV_A 0x010Cu // #define RW_ColorHSV_A 0x010Cu

File diff suppressed because it is too large Load Diff

View File

@ -22,7 +22,6 @@ int main(void)
// INIT_CS555X(); // INIT_CS555X();
osDelay(1000); // 3Ãë osDelay(1000); // 3Ãë
AD7190_Init(); AD7190_Init();
CalibrateWeight2.WeightZero = ADvalue2filter;
switch (InstrumentTypeRead()) { switch (InstrumentTypeRead()) {
case 0x01: // ¹ú²ú 40-180 ÂÁ 0.005-50 0.02 case 0x01: // ¹ú²ú 40-180 ÂÁ 0.005-50 0.02
MaxWeight = 50; MaxWeight = 50;
@ -37,7 +36,7 @@ int main(void)
MaxTemp = 180; MaxTemp = 180;
break; break;
case 0x03: // ¹ú²ú 40-180 ÂÁ 0.001-100 0.01 case 0x03: // ¹ú²ú 40-180 ÂÁ 0.001-100 0.01
MaxWeight = 100; MaxWeight = 120;
Resolution = 0.001; Resolution = 0.001;
ResolutionWater = 0.01; ResolutionWater = 0.01;
MaxTemp = 180; MaxTemp = 180;
@ -85,6 +84,7 @@ int main(void)
MaxTemp = 0; MaxTemp = 0;
break; break;
} }
USARTHMIInit(); USARTHMIInit();
HMICMDInit(); HMICMDInit();
while (1) { while (1) {

View File

@ -80,7 +80,7 @@ void DataPrint(uint8_t *buffer, uint8_t lenth)
UART1_Send(*buffer++); UART1_Send(*buffer++);
while (!READ_BIT(USART1->SR, USART_SR_TC)) while (!READ_BIT(USART1->SR, USART_SR_TC))
delay_us(50u); delay_us(5u);
} }
// SET_BIT(USART1->CR1, USART_CR1_RXNEIE); // SET_BIT(USART1->CR1, USART_CR1_RXNEIE);
osMutexRelease(USART_Mutex_ID); osMutexRelease(USART_Mutex_ID);

View File

@ -129,9 +129,9 @@ void SPI1_Configuration(void)
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7; // SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI1, &SPI_InitStructure); SPI_Init(SPI1, &SPI_InitStructure);
// 使能SPI1 // 使能SPI1
@ -176,16 +176,32 @@ uint8_t bus_SPIxShift1(uint8_t OutByte)
// 定义SPI读取函数 // 定义SPI读取函数
uint8_t SPI1_ReadWrite(uint8_t data) uint8_t SPI1_ReadWrite(uint8_t data)
{ {
uint16_t retry = 0;
// 等待发送缓冲区为空 // 等待发送缓冲区为空
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET) while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET)
; {
retry++;
if(retry>=0XFFFE)
return 0; //超时退出
}
retry = 0;
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET)
{
retry++;
if(retry>=0XFFFE)
return 0; //超时退出
}
// 通过SPI发送数据 // 通过SPI发送数据
SPI_I2S_SendData(SPI1, data); SPI_I2S_SendData(SPI1, data);
retry = 0;
// 等待接收缓冲区非空 // 等待接收缓冲区非空
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET) while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET)
; {
retry++;
if(retry>=0XFFFE)
return 0; //超时退出
}
// 从SPI接收数据 // 从SPI接收数据
return SPI_I2S_ReceiveData(SPI1); return SPI_I2S_ReceiveData(SPI1);