充能统计添加中间值滤波
修改晶振起振超时时间和flash相关以适应gd32
This commit is contained in:
@@ -103,7 +103,7 @@
|
||||
<bEvRecOn>1</bEvRecOn>
|
||||
<bSchkAxf>0</bSchkAxf>
|
||||
<bTchkAxf>0</bTchkAxf>
|
||||
<nTsel>4</nTsel>
|
||||
<nTsel>6</nTsel>
|
||||
<sDll></sDll>
|
||||
<sDllPa></sDllPa>
|
||||
<sDlgDll></sDlgDll>
|
||||
@@ -114,7 +114,7 @@
|
||||
<tDlgDll></tDlgDll>
|
||||
<tDlgPa></tDlgPa>
|
||||
<tIfile></tIfile>
|
||||
<pMon>Segger\JL2CM3.dll</pMon>
|
||||
<pMon>STLink\ST-LINKIII-KEIL_SWO.dll</pMon>
|
||||
</DebugOpt>
|
||||
<TargetDriverDllRegistry>
|
||||
<SetRegEntry>
|
||||
@@ -381,18 +381,34 @@
|
||||
<Bp>
|
||||
<Number>0</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>185</LineNumber>
|
||||
<LineNumber>291</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>134234652</Address>
|
||||
<Address>134275382</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
<SizeOfObject>0</SizeOfObject>
|
||||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>1</BreakIfRCount>
|
||||
<Filename>.\source\rt_thread\libcpu\arm\cortex-m3\context_rvds.S</Filename>
|
||||
<Filename>D:\work\SVN\鍐夊窛\mcu_program\checker_slave\source\interface\if_can.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression>\\checker_slave_app\source/rt_thread/libcpu/arm/cortex-m3/context_rvds.S\185</Expression>
|
||||
<Expression>\\checker_slave_app\source/interface/if_can.c\291</Expression>
|
||||
</Bp>
|
||||
<Bp>
|
||||
<Number>1</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>22</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>134303466</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
<SizeOfObject>0</SizeOfObject>
|
||||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>1</BreakIfRCount>
|
||||
<Filename>D:\work\SVN\鍐夊窛\mcu_program\checker_slave\source\rt_thread\core_delay.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression>\\checker_slave_app\source/rt_thread/core_delay.c\22</Expression>
|
||||
</Bp>
|
||||
</Breakpoint>
|
||||
<WatchWindow1>
|
||||
@@ -406,7 +422,7 @@
|
||||
<Mm>
|
||||
<WinNumber>1</WinNumber>
|
||||
<SubType>1</SubType>
|
||||
<ItemText>0x20002CE0</ItemText>
|
||||
<ItemText>0x20002a00</ItemText>
|
||||
<AccSizeX>0</AccSizeX>
|
||||
</Mm>
|
||||
</MemoryWindow1>
|
||||
@@ -476,16 +492,6 @@
|
||||
<pszMrulep></pszMrulep>
|
||||
<pSingCmdsp></pSingCmdsp>
|
||||
<pMultCmdsp></pMultCmdsp>
|
||||
<SystemViewers>
|
||||
<Entry>
|
||||
<Name>System Viewer\TIM4</Name>
|
||||
<WinId>35905</WinId>
|
||||
</Entry>
|
||||
<Entry>
|
||||
<Name>System Viewer\TIM5</Name>
|
||||
<WinId>35904</WinId>
|
||||
</Entry>
|
||||
</SystemViewers>
|
||||
<DebugDescription>
|
||||
<Enable>1</Enable>
|
||||
<EnableFlashSeq>1</EnableFlashSeq>
|
||||
@@ -840,7 +846,7 @@
|
||||
|
||||
<Group>
|
||||
<GroupName>stm32lib</GroupName>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
@@ -1204,7 +1210,7 @@
|
||||
|
||||
<Group>
|
||||
<GroupName>dev</GroupName>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
@@ -2008,6 +2014,18 @@
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>9</GroupNumber>
|
||||
<FileNumber>99</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>.\source\soft\filter.c</PathWithFileName>
|
||||
<FilenameWithoutPath>filter.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
</Group>
|
||||
|
||||
<Group>
|
||||
@@ -2018,7 +2036,7 @@
|
||||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>10</GroupNumber>
|
||||
<FileNumber>99</FileNumber>
|
||||
<FileNumber>100</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -2030,7 +2048,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>10</GroupNumber>
|
||||
<FileNumber>100</FileNumber>
|
||||
<FileNumber>101</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -2042,7 +2060,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>10</GroupNumber>
|
||||
<FileNumber>101</FileNumber>
|
||||
<FileNumber>102</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -2054,7 +2072,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>10</GroupNumber>
|
||||
<FileNumber>102</FileNumber>
|
||||
<FileNumber>103</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -2066,7 +2084,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>10</GroupNumber>
|
||||
<FileNumber>103</FileNumber>
|
||||
<FileNumber>104</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -2078,7 +2096,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>10</GroupNumber>
|
||||
<FileNumber>104</FileNumber>
|
||||
<FileNumber>105</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -2090,7 +2108,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>10</GroupNumber>
|
||||
<FileNumber>105</FileNumber>
|
||||
<FileNumber>106</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -2110,7 +2128,7 @@
|
||||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>11</GroupNumber>
|
||||
<FileNumber>106</FileNumber>
|
||||
<FileNumber>107</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -2130,7 +2148,7 @@
|
||||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>12</GroupNumber>
|
||||
<FileNumber>107</FileNumber>
|
||||
<FileNumber>108</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -2142,7 +2160,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>12</GroupNumber>
|
||||
<FileNumber>108</FileNumber>
|
||||
<FileNumber>109</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -2154,7 +2172,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>12</GroupNumber>
|
||||
<FileNumber>109</FileNumber>
|
||||
<FileNumber>110</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -2166,7 +2184,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>12</GroupNumber>
|
||||
<FileNumber>110</FileNumber>
|
||||
<FileNumber>111</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -2178,7 +2196,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>12</GroupNumber>
|
||||
<FileNumber>111</FileNumber>
|
||||
<FileNumber>112</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -2190,7 +2208,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>12</GroupNumber>
|
||||
<FileNumber>112</FileNumber>
|
||||
<FileNumber>113</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -2210,7 +2228,7 @@
|
||||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>13</GroupNumber>
|
||||
<FileNumber>113</FileNumber>
|
||||
<FileNumber>114</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -2230,7 +2248,7 @@
|
||||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>14</GroupNumber>
|
||||
<FileNumber>114</FileNumber>
|
||||
<FileNumber>115</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
@@ -2242,7 +2260,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>14</GroupNumber>
|
||||
<FileNumber>115</FileNumber>
|
||||
<FileNumber>116</FileNumber>
|
||||
<FileType>5</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
|
@@ -2344,6 +2344,113 @@
|
||||
<FileName>huffman.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>.\source\soft\huffman.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>
|
||||
<FileName>filter.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>.\source\soft\filter.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>
|
||||
</Files>
|
||||
</Group>
|
||||
@@ -3980,6 +4087,11 @@
|
||||
<FileType>1</FileType>
|
||||
<FilePath>.\source\soft\huffman.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>filter.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>.\source\soft\filter.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
@@ -5255,6 +5367,11 @@
|
||||
<FileType>1</FileType>
|
||||
<FilePath>.\source\soft\huffman.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>filter.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>.\source\soft\filter.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
|
@@ -416,7 +416,7 @@ class protu(QObject):
|
||||
data_str.clear()
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
# print(recv_str)
|
||||
print(recv_str)
|
||||
# else:
|
||||
# print("len(data)={d1},num_ro_recv={d2}".format(d1=len(data),d2=self.num_to_recv))
|
||||
def send(self,cmd:int,data:bytearray):
|
||||
|
44
python/slave_test.py
Normal file
44
python/slave_test.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import prottcp
|
||||
import time
|
||||
import numpy as np
|
||||
|
||||
|
||||
|
||||
#测试小板功能
|
||||
|
||||
|
||||
|
||||
|
||||
def random():
|
||||
return int(np.random.random_sample()*10000%10000)
|
||||
|
||||
|
||||
|
||||
def numlist_to_str(numlist:list):
|
||||
s=""
|
||||
for i in numlist:
|
||||
s+=str(i)+','
|
||||
return s[:-1]
|
||||
|
||||
|
||||
def randomlist(num:int):
|
||||
l=[]
|
||||
for i in range(num):
|
||||
l.append(random())
|
||||
return l
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
u=prottcp.protu()
|
||||
u.init("com11:38400")
|
||||
u.start_recv()
|
||||
for i in range(10):
|
||||
s='test '+numlist_to_str(randomlist(20))
|
||||
print("send:",s)
|
||||
u.send_str(s)
|
||||
time.sleep(1)
|
||||
u.close()
|
||||
|
||||
|
||||
|
||||
|
@@ -335,3 +335,6 @@
|
||||
在槽任务失败且异常代码不为0时才会导致 CheckerExt_Slot 任务失败
|
||||
2024.1.12
|
||||
添加发送失败信息记录
|
||||
2021.2.3
|
||||
充能统计添加中间值滤波
|
||||
修改晶振起振超时时间和flash相关以适应gd32
|
||||
|
@@ -125,7 +125,7 @@
|
||||
* @brief In the following line adjust the External High Speed oscillator (HSE) Startup
|
||||
Timeout value
|
||||
*/
|
||||
#define HSE_STARTUP_TIMEOUT ((uint16_t)0x0500) /*!< Time out for HSE start up */
|
||||
#define HSE_STARTUP_TIMEOUT ((uint16_t)0xFFFF) /*!< Time out for HSE start up */
|
||||
|
||||
#define HSI_VALUE ((uint32_t)8000000) /*!< Value of the Internal oscillator in Hz*/
|
||||
|
||||
|
@@ -5,6 +5,10 @@
|
||||
#include "hardware/power.h"
|
||||
#include "hardware/timer_cfg.h"
|
||||
#include "hardware/power.h"
|
||||
#include "filter.h"
|
||||
|
||||
|
||||
|
||||
volatile static uint16_t jq_idle_current;
|
||||
|
||||
#define JQ_IDLE_NOISE 100
|
||||
@@ -71,6 +75,40 @@ static void JQ_Sample(uint16_t sample_count)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
@brief 采样总线反馈数据,使用滤波算法
|
||||
@param sample_count 采样次数
|
||||
*/
|
||||
|
||||
|
||||
|
||||
static void JQ_Sample_Filtering(uint16_t sample_count)
|
||||
{
|
||||
uint16_t us_adv = 0;
|
||||
uint16_t ul_count = 0;
|
||||
filter_def f={0};
|
||||
us_adv = GetADC_Fast(ADC_CURR_DE);
|
||||
jq_ad_last_sample=us_adv;
|
||||
filter_init(&f,us_adv);
|
||||
for(ul_count = 0;ul_count < sample_count; ul_count++)
|
||||
{
|
||||
// 保证在adc转换的期间完成滤波算法
|
||||
adc_start(ADC_CURR_DE);
|
||||
filter_insert(&f,us_adv);
|
||||
us_adv=filter_get_mid(&f);
|
||||
JQ_Read_AD_V[ul_count] = us_adv;
|
||||
jq_ad_last_sample = us_adv;
|
||||
us_adv = adc_get_value(ADC_CURR_DE);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
@brief 通信反码信息初始化
|
||||
*/
|
||||
|
@@ -4,6 +4,9 @@
|
||||
#include "timer_cfg.h"
|
||||
#include "base/utility.h"
|
||||
#include "power.h"
|
||||
#include "filter.h"
|
||||
#include "core_delay.h"
|
||||
|
||||
volatile uint16_t ad0_adc_sample[AD_SCAN_SAMPLE*AD_SCAN_COUNT];
|
||||
#define ADC1_SAMPLE_BUF_LEN 200
|
||||
#define ADC1_SAMPLE_BUF_LEN2 20
|
||||
@@ -445,6 +448,71 @@ uint16_t AD_CurMonitor_(uint32_t ul_times)
|
||||
|
||||
|
||||
|
||||
/*rc{
|
||||
使用过滤算法的充能统计
|
||||
这个函数给出的都是adc原始值
|
||||
sample_timeout 单位是0.1ms
|
||||
}*/
|
||||
uint16_t AD_GetChgEnergy(uint16_t sample_timeout, uint16_t end_adv,uint16_t* max_cul,uint16_t *shake_adv)
|
||||
{
|
||||
uint16_t adc_max = 0;
|
||||
uint16_t adc_temp,adc_shake=0;
|
||||
uint16_t adc_value,filter_value;
|
||||
uint16_t time;
|
||||
filter_def f={0};
|
||||
filter_def sort={0};
|
||||
uint32_t tick;
|
||||
|
||||
// 等待开始
|
||||
adc_value = GetADC_Fast(ADC_CURR_DE);
|
||||
filter_init(&f,adc_value);
|
||||
tick=delay_get_us();
|
||||
do{
|
||||
adc_value=adc_get_value(ADC_CURR_DE);
|
||||
adc_start(ADC_CURR_DE);
|
||||
// adc_value = GetADC_Fast(ADC_CURR_DE);
|
||||
filter_insert(&f,adc_value);
|
||||
filter_value=filter_get_head(&f);
|
||||
if(delay_check(tick,1000000)){
|
||||
// 1s超时,未进入充能阶段
|
||||
goto end;
|
||||
}
|
||||
}while(filter_value<end_adv);
|
||||
|
||||
// 等待结束
|
||||
filter_init(&sort,filter_value);
|
||||
// 跳过电流上升期,充电时间不可能低于100us
|
||||
tick=delay_get_us();
|
||||
do{
|
||||
adc_value=adc_get_value(ADC_CURR_DE);
|
||||
adc_start(ADC_CURR_DE);
|
||||
// adc_value = GetADC_Fast(ADC_CURR_DE);
|
||||
filter_insert(&f,adc_value);
|
||||
filter_value=filter_get_mid(&f);
|
||||
//filter_value=adc_value;
|
||||
filter_insert(&sort,filter_value);
|
||||
adc_temp=filter_get_tail(&sort)-filter_get_head(&sort);
|
||||
if(adc_max<filter_value){
|
||||
adc_max=filter_value;
|
||||
}
|
||||
if(adc_shake<adc_temp){
|
||||
adc_shake=adc_temp;
|
||||
}
|
||||
if(delay_check(tick,100*sample_timeout)){
|
||||
// 超时
|
||||
time=sample_timeout+1;
|
||||
goto end;
|
||||
}
|
||||
}while(filter_value>end_adv);
|
||||
time=(delay_get_us()-tick)/100;
|
||||
end:
|
||||
if(max_cul) *max_cul=adc_max;
|
||||
if(shake_adv) *shake_adv=adc_shake;
|
||||
return time;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
@brief 电流降到指定电流下的时间
|
||||
@@ -456,7 +524,7 @@ uint16_t AD_CurMonitor_(uint32_t ul_times)
|
||||
*/
|
||||
|
||||
|
||||
uint16_t AD_GetChgEnergy(uint16_t sample_timeout, uint16_t end_adv,uint16_t* max_cul,uint16_t *shake_adv)
|
||||
uint16_t AD_GetChgEnergy_(uint16_t sample_timeout, uint16_t end_adv,uint16_t* max_cul,uint16_t *shake_adv)
|
||||
{
|
||||
uint16_t aus_adc_v[5];
|
||||
uint16_t aus_adv_shake[20];
|
||||
@@ -466,8 +534,8 @@ uint16_t AD_GetChgEnergy(uint16_t sample_timeout, uint16_t end_adv,uint16_t* max
|
||||
uint16_t us_shake_minadc,us_shake_maxadc;
|
||||
uint8_t start_flag = 0,shake_flag = 0;
|
||||
Get100usCount();
|
||||
ADC_ClearFlag(ADC_CURR_DE,ADC_FLAG_EOC);//清除转换结束标志
|
||||
ADC_SoftwareStartConvCmd(ADC_CURR_DE, ENABLE); //启动转换
|
||||
// ADC_ClearFlag(ADC_CURR_DE,ADC_FLAG_EOC);//清除转换结束标志
|
||||
// ADC_SoftwareStartConvCmd(ADC_CURR_DE, ENABLE); //启动转换
|
||||
aus_adc_v[4] = 0xFFFF;
|
||||
*max_cul = 0;
|
||||
*shake_adv = 0;
|
||||
@@ -478,23 +546,27 @@ uint16_t AD_GetChgEnergy(uint16_t sample_timeout, uint16_t end_adv,uint16_t* max
|
||||
}
|
||||
while(GetCountTimerCnt() < sample_timeout)
|
||||
{
|
||||
time_out = 2000;
|
||||
while((time_out > 0) && ( ADC_GetFlagStatus(ADC_CURR_DE,ADC_FLAG_EOC) == RESET))
|
||||
{
|
||||
time_out--;
|
||||
}
|
||||
aus_adc_v[us_count] = ADC_GetConversionValue(ADC_CURR_DE) & 0x0FFF;
|
||||
// time_out = 2000;
|
||||
// while((time_out > 0) && ( ADC_GetFlagStatus(ADC_CURR_DE,ADC_FLAG_EOC) == RESET))
|
||||
// {
|
||||
// time_out--;
|
||||
// }
|
||||
// aus_adc_v[us_count] = ADC_GetConversionValue(ADC_CURR_DE) & 0x0FFF;
|
||||
aus_adc_v[us_count] = GetADC_Fast(ADC_CURR_DE);
|
||||
aus_adv_shake[us_shake_count] = aus_adc_v[us_count];
|
||||
ADC_ClearFlag(ADC_CURR_DE,ADC_FLAG_EOC);//清除转换结束标志
|
||||
ADC_SoftwareStartConvCmd(ADC_CURR_DE, ENABLE); //启动转换
|
||||
// ADC_ClearFlag(ADC_CURR_DE,ADC_FLAG_EOC);//清除转换结束标志
|
||||
// ADC_SoftwareStartConvCmd(ADC_CURR_DE, ENABLE); //启动转换
|
||||
us_count++;
|
||||
us_shake_count++;
|
||||
us_count %= 5;
|
||||
us_shake_count %= 20;
|
||||
|
||||
// 开始充能之后并且采集到20个值
|
||||
if((us_shake_count == 0) && (start_flag > 0))
|
||||
{
|
||||
shake_flag ++;
|
||||
}
|
||||
// 由于刚开始时采集的20个值有可能还没有开始,这里使用第二个采集值
|
||||
if(shake_flag == 2)
|
||||
{
|
||||
LED1_Out = 1;
|
||||
@@ -514,6 +586,7 @@ uint16_t AD_GetChgEnergy(uint16_t sample_timeout, uint16_t end_adv,uint16_t* max
|
||||
}
|
||||
time_out++;
|
||||
}
|
||||
// 获取波动值,如果波动值太大则处于上升期,忽略波动值
|
||||
us_shake_minadc = us_shake_maxadc - us_shake_minadc;
|
||||
if(us_shake_minadc > 900)
|
||||
{
|
||||
@@ -525,6 +598,7 @@ uint16_t AD_GetChgEnergy(uint16_t sample_timeout, uint16_t end_adv,uint16_t* max
|
||||
}
|
||||
}
|
||||
|
||||
// 采集到5个数据之后
|
||||
if(us_count == 0)
|
||||
{
|
||||
Bubble_Sort_u16(aus_adc_v,5);
|
||||
@@ -747,3 +821,34 @@ uint16_t AD_GetBusCurUp(uint16_t ad_line ,uint16_t time_out)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*rc{
|
||||
开始转换
|
||||
|
||||
}*/
|
||||
void adc_start(ADC_TypeDef *adc){
|
||||
ADC_ClearFlag(adc,ADC_FLAG_EOC);//清除转换结束标志
|
||||
ADC_SoftwareStartConvCmd(adc,ENABLE);//启动转换
|
||||
}
|
||||
/*rc{
|
||||
获取adc值,请先开始转换
|
||||
}*/
|
||||
uint16_t adc_get_value(ADC_TypeDef *adc){
|
||||
uint16_t time_out = 10000;
|
||||
uint16_t temp = 0;
|
||||
while((time_out > 0) && ( ADC_GetFlagStatus(adc,ADC_FLAG_EOC) == RESET))
|
||||
{
|
||||
time_out--;
|
||||
}
|
||||
temp = ADC_GetConversionValue(adc) & 0x0FFF;
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -101,4 +101,11 @@ uint16_t AD_SampleCap(uint16_t delay);
|
||||
@rtv 等待时间
|
||||
*/
|
||||
uint16_t AD_GetBusCurUp(uint16_t ad_line ,uint16_t time_out);
|
||||
|
||||
|
||||
|
||||
void adc_start(ADC_TypeDef *adc);
|
||||
uint16_t adc_get_value(ADC_TypeDef *adc);
|
||||
|
||||
|
||||
#endif
|
||||
|
@@ -6,7 +6,7 @@
|
||||
|
||||
|
||||
|
||||
#define BUILD_DATE "2024-01-18 15:29:08"
|
||||
#define BUILD_DATE "2024-02-03 10:04:08"
|
||||
#define SOFT_VERSION "2.14"
|
||||
|
||||
|
||||
|
@@ -20,6 +20,8 @@
|
||||
#include "dev_backup.h"
|
||||
#include "compiler_info.h"
|
||||
#include "elec_det.h"
|
||||
#include "filter.h"
|
||||
#include "core_delay.h"
|
||||
|
||||
static const uint8_t ALIGN(4) g_bootcode[]={
|
||||
#include "bootcode.txt"
|
||||
@@ -85,18 +87,32 @@ app_init_export(init_wdog)
|
||||
|
||||
|
||||
|
||||
|
||||
static int test(list_def *argv)
|
||||
{
|
||||
if(list_length(argv)<2){
|
||||
cmd_print("param num too less.");
|
||||
return -1;
|
||||
}
|
||||
float num=str_atof(list_get_str(argv,1));
|
||||
cmd_print("test num=%f",num);
|
||||
uint32_t start;
|
||||
uint32_t end;
|
||||
int num;
|
||||
uint16_t value;
|
||||
list_def *table=str_atod_list(list_get_str(argv,1),',');
|
||||
filter_def f={0};
|
||||
filter_init(&f,list_get_int(table,0));
|
||||
num=list_length(table);
|
||||
for(int i=0;i<num;i++){
|
||||
value=list_get_int(table,i);
|
||||
start=delay_get_cnt();
|
||||
filter_insert(&f,value);
|
||||
value=filter_get_mid(&f);
|
||||
end=delay_get_cnt();
|
||||
cmd_print("time_cost=%d,mid=%d",end-start,value);
|
||||
}
|
||||
cmd_print("test num=%d",num);
|
||||
return 0;
|
||||
}
|
||||
//commend_export(test,test,"cmd test")
|
||||
commend_export(test,test,"cmd test")
|
||||
|
||||
|
||||
|
||||
|
@@ -129,6 +129,7 @@ def creat_head(data:bytearray,date:str):
|
||||
head+=arr_from_int(7777)
|
||||
head+=arr_from_str("utcp",8)
|
||||
head+=arr_from_str("slave",12)
|
||||
head+=arr_from_str(time.SOFT_VERION,12)
|
||||
head+=arr_byte_copy(0,128-len(head))
|
||||
# print(head)
|
||||
return head
|
||||
|
@@ -35,7 +35,7 @@ int delay_init(void)
|
||||
}
|
||||
|
||||
|
||||
static uint32_t delay_get_cnt(void)
|
||||
uint32_t delay_get_cnt(void)
|
||||
{
|
||||
return ((uint32_t)DWT_CYCCNT);
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ uint32_t delay_get_us(void);
|
||||
|
||||
int delay_check(uint32_t old,uint32_t wnd);
|
||||
|
||||
|
||||
uint32_t delay_get_cnt(void);
|
||||
|
||||
|
||||
|
||||
|
@@ -106,10 +106,6 @@ void debug_enable(int enable)
|
||||
|
||||
#else
|
||||
|
||||
void debug_enable(int enable)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -67,7 +67,7 @@ void debug_enable(int enable);
|
||||
|
||||
#define debug_init()
|
||||
#define debug_log(...)
|
||||
|
||||
#define debug_enable(s)
|
||||
|
||||
#endif
|
||||
|
||||
|
61
source/soft/filter.c
Normal file
61
source/soft/filter.c
Normal file
@@ -0,0 +1,61 @@
|
||||
|
||||
|
||||
#include "filter.h"
|
||||
|
||||
|
||||
|
||||
// 过滤器
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void filter_init(filter_def *f,uint16_t value){
|
||||
for(int i=0;i<FILTER_ITEM_NUM;i++){
|
||||
f->items[i].data.value = value;
|
||||
f->items[i].data.index = i;
|
||||
}
|
||||
f->index=FILTER_ITEM_NUM;
|
||||
}
|
||||
|
||||
|
||||
// 从指定位置开始排序
|
||||
static void filter_sort(filter_def *f,int index,uint16_t value){
|
||||
int i=index;
|
||||
for(;;){
|
||||
if((i<FILTER_ITEM_NUM-1)&&(value>f->items[i+1].data.value)){
|
||||
f->items[i].item=f->items[i+1].item;
|
||||
i++;
|
||||
// printf("i=%d,to tail\n",i);
|
||||
}else if((i>0)&&(value<f->items[i-1].data.value)){
|
||||
f->items[i].item=f->items[i-1].item;
|
||||
i--;
|
||||
// printf("i=%d,to head\n",i);
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
f->items[i].data.value = value;
|
||||
f->items[i].data.index = f->index;
|
||||
f->index++;
|
||||
}
|
||||
|
||||
|
||||
// 插入数据,小在前,大在后
|
||||
void filter_insert(filter_def *f,uint16_t value)
|
||||
{
|
||||
for(int i=0;i<FILTER_ITEM_NUM;i++){
|
||||
if(f->items[i].data.index==(uint16_t)(f->index-FILTER_ITEM_NUM))
|
||||
{
|
||||
filter_sort(f,i,value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(f->index>0){
|
||||
while(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
55
source/soft/filter.h
Normal file
55
source/soft/filter.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#ifndef filter_h__
|
||||
#define filter_h__
|
||||
|
||||
|
||||
#include "stdint.h"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
|
||||
|
||||
|
||||
// 过滤器
|
||||
|
||||
#define FILTER_ITEM_NUM 5
|
||||
|
||||
|
||||
typedef union {
|
||||
struct
|
||||
{
|
||||
uint16_t value;
|
||||
uint16_t index;
|
||||
}data;
|
||||
uint32_t item;
|
||||
} filter_item;
|
||||
|
||||
|
||||
struct _filter_def{
|
||||
uint16_t index;
|
||||
filter_item items[FILTER_ITEM_NUM];
|
||||
};
|
||||
typedef struct _filter_def filter_def;
|
||||
|
||||
void filter_init(filter_def *f,uint16_t value);
|
||||
|
||||
void filter_insert(filter_def *f,uint16_t value);
|
||||
|
||||
// 返回中间值
|
||||
#define filter_get_mid(f)\
|
||||
(f)->items[FILTER_ITEM_NUM>>1].data.value
|
||||
|
||||
// 返回头
|
||||
#define filter_get_head(f)\
|
||||
(f)->items[0].data.value
|
||||
|
||||
// 返回尾
|
||||
#define filter_get_tail(f)\
|
||||
(f)->items[FILTER_ITEM_NUM-1].data.value
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
@@ -82,8 +82,8 @@
|
||||
#define FLASH_BANK1_END_ADDRESS ((uint32_t)0x807FFFF)
|
||||
|
||||
/* Delay definition */
|
||||
#define EraseTimeout ((uint32_t)0x000B0000)
|
||||
#define ProgramTimeout ((uint32_t)0x00002000)
|
||||
#define EraseTimeout ((uint32_t)0x000FFFFF)
|
||||
#define ProgramTimeout ((uint32_t)0x0000FFFF)
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -632,6 +632,8 @@ FLASH_Status FLASH_EraseOptionBytes(void)
|
||||
/* Authorize the small information block programming */
|
||||
FLASH->OPTKEYR = FLASH_KEY1;
|
||||
FLASH->OPTKEYR = FLASH_KEY2;
|
||||
__NOP();
|
||||
__NOP();
|
||||
|
||||
/* if the previous operation is completed, proceed to erase the option bytes */
|
||||
FLASH->CR |= CR_OPTER_Set;
|
||||
@@ -938,6 +940,8 @@ FLASH_Status FLASH_ProgramOptionByteData(uint32_t Address, uint8_t Data)
|
||||
/* Authorize the small information block programming */
|
||||
FLASH->OPTKEYR = FLASH_KEY1;
|
||||
FLASH->OPTKEYR = FLASH_KEY2;
|
||||
__NOP();
|
||||
__NOP();
|
||||
/* Enables the Option Bytes Programming operation */
|
||||
FLASH->CR |= CR_OPTPG_Set;
|
||||
*(__IO uint16_t*)Address = Data;
|
||||
@@ -995,6 +999,8 @@ FLASH_Status FLASH_EnableWriteProtection(uint32_t FLASH_Pages)
|
||||
/* Authorizes the small information block programming */
|
||||
FLASH->OPTKEYR = FLASH_KEY1;
|
||||
FLASH->OPTKEYR = FLASH_KEY2;
|
||||
__NOP();
|
||||
__NOP();
|
||||
FLASH->CR |= CR_OPTPG_Set;
|
||||
if(WRP0_Data != 0xFF)
|
||||
{
|
||||
@@ -1057,6 +1063,8 @@ FLASH_Status FLASH_ReadOutProtection(FunctionalState NewState)
|
||||
/* Authorizes the small information block programming */
|
||||
FLASH->OPTKEYR = FLASH_KEY1;
|
||||
FLASH->OPTKEYR = FLASH_KEY2;
|
||||
__NOP();
|
||||
__NOP();
|
||||
FLASH->CR |= CR_OPTER_Set;
|
||||
FLASH->CR |= CR_STRT_Set;
|
||||
/* Wait for last operation to be completed */
|
||||
|
Reference in New Issue
Block a user