From 43e3cce048cd9bf2dab89d323f29b647001ab1ee Mon Sep 17 00:00:00 2001 From: SikongJueluo Date: Wed, 16 Jul 2025 15:27:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9B=B4=E6=AD=A3=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=88=86=E6=9E=90=E4=BB=AA=E9=A2=91=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LogicAnalyzer/LogicAnalyzerManager.ts | 46 ++++++++++--------- .../LogicAnalyzer/TriggerSettings.vue | 2 +- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/components/LogicAnalyzer/LogicAnalyzerManager.ts b/src/components/LogicAnalyzer/LogicAnalyzerManager.ts index 149a67a..d353ff9 100644 --- a/src/components/LogicAnalyzer/LogicAnalyzerManager.ts +++ b/src/components/LogicAnalyzer/LogicAnalyzerManager.ts @@ -77,6 +77,10 @@ const defaultColors = [ "#8C33FF", ]; +// 添加逻辑分析仪频率常量 +const LOGIC_ANALYZER_FREQUENCY = 5_000_000; // 5MHz +const SAMPLE_PERIOD_NS = 1_000_000_000 / LOGIC_ANALYZER_FREQUENCY; // 采样周期,单位:纳秒 + const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState( () => { const logicData = shallowRef(); @@ -305,10 +309,10 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState( // 5. 解析数据为8个通道的数字信号 const sampleCount = bytes.length; - const timeStep = 0.1; // 假设每个采样点间隔0.1ms + const timeStepNs = SAMPLE_PERIOD_NS; // 每个采样点间隔200ns (1/5MHz) - // 创建时间轴 - const x = Array.from({ length: sampleCount }, (_, i) => i * timeStep); + // 创建时间轴(转换为合适的单位) + const x = Array.from({ length: sampleCount }, (_, i) => i * timeStepNs / 1000); // 转换为微秒 // 创建8个通道的数据 const y: number[][] = Array.from( @@ -329,7 +333,7 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState( const logicData: LogicDataType = { x, y, - xUnit: "ms", + xUnit: "us", // 改为微秒单位 }; setLogicData(logicData); @@ -383,51 +387,51 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState( // 添加生成测试数据的方法 const generateTestData = () => { - const sampleRate = 10000; // 10kHz sampling - const duration = 1; + const sampleRate = LOGIC_ANALYZER_FREQUENCY; // 使用实际的逻辑分析仪频率 + const duration = 0.001; // 1ms的数据 const points = Math.floor(sampleRate * duration); const x = Array.from( { length: points }, - (_, i) => (i / sampleRate) * 1000, - ); // time in ms + (_, i) => (i * SAMPLE_PERIOD_NS) / 1000, // 时间轴,单位:微秒 + ); // Generate 8 channels with different digital patterns const y = [ - // Channel 0: Clock signal 100Hz + // Channel 0: Clock signal 1MHz Array.from( { length: points }, - (_, i) => Math.floor((100 * i) / sampleRate) % 2, + (_, i) => Math.floor((1_000_000 * i) / sampleRate) % 2, ), - // Channel 1: Clock/2 signal 50Hz + // Channel 1: Clock/2 signal 500kHz Array.from( { length: points }, - (_, i) => Math.floor((50 * i) / sampleRate) % 2, + (_, i) => Math.floor((500_000 * i) / sampleRate) % 2, ), - // Channel 2: Clock/4 signal 25Hz + // Channel 2: Clock/4 signal 250kHz Array.from( { length: points }, - (_, i) => Math.floor((25 * i) / sampleRate) % 2, + (_, i) => Math.floor((250_000 * i) / sampleRate) % 2, ), - // Channel 3: Clock/8 signal 12.5Hz + // Channel 3: Clock/8 signal 125kHz Array.from( { length: points }, - (_, i) => Math.floor((12.5 * i) / sampleRate) % 2, + (_, i) => Math.floor((125_000 * i) / sampleRate) % 2, ), // Channel 4: Data signal (pseudo-random pattern) Array.from({ length: points }, (_, i) => - Math.abs(Math.floor(Math.sin(i * 0.01) * 10) % 2), + Math.abs(Math.floor(Math.sin(i * 0.001) * 10) % 2), ), // Channel 5: Enable signal (periodic pulse) Array.from({ length: points }, (_, i) => - Math.floor(i / 50) % 10 < 3 ? 1 : 0, + Math.floor(i / 250) % 10 < 3 ? 1 : 0, ), // Channel 6: Reset signal (occasional pulse) Array.from({ length: points }, (_, i) => - Math.floor(i / 200) % 20 === 0 ? 1 : 0, + Math.floor(i / 1000) % 20 === 0 ? 1 : 0, ), // Channel 7: Status signal (slow changing) - Array.from({ length: points }, (_, i) => Math.floor(i / 1000) % 2), + Array.from({ length: points }, (_, i) => Math.floor(i / 5000) % 2), ]; // 同时更新通道标签为更有意义的名称 @@ -448,7 +452,7 @@ const [useProvideLogicAnalyzer, useLogicAnalyzerState] = createInjectionState( // 设置逻辑数据 enableAllChannels(); - setLogicData({ x, y, xUnit: "ms" }); + setLogicData({ x, y, xUnit: "us" }); // 改为微秒单位 alert?.success("测试数据生成成功", 2000); }; diff --git a/src/components/LogicAnalyzer/TriggerSettings.vue b/src/components/LogicAnalyzer/TriggerSettings.vue index 48e6a83..a4f9d40 100644 --- a/src/components/LogicAnalyzer/TriggerSettings.vue +++ b/src/components/LogicAnalyzer/TriggerSettings.vue @@ -16,7 +16,7 @@
采样率
-
100MHz
+
5MHz
最大采样频率