fix: 更正逻辑分析仪频率
This commit is contained in:
parent
bcdefb2779
commit
43e3cce048
|
@ -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<LogicDataType>();
|
||||
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
<div class="stat">
|
||||
<div class="stat-title">采样率</div>
|
||||
<div class="stat-value text-info">100MHz</div>
|
||||
<div class="stat-value text-info">5MHz</div>
|
||||
<div class="stat-desc">最大采样频率</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue