200 字
1 分钟
FPGA使用sv生成虚拟单音测试数据
2024-08-07
2026-03-30

FPGA使用sv生成虚拟单音数据

之前一直使用matlab生成虚拟的数据,导出到txt或是coe文件中,再导入到fpga中进行仿真测试。

复杂的数据这样操作自然是必要的,但是平日使用正弦数据进行测试的话,这样的操作不免复杂,今日尝试使用systemverilog虚拟单音数据,并存入到txt文件。

module top_tb(
);
localparam FRACTIONAL_BITS = 7; // 7位小数,1位符号
localparam SCALE = 1<<FRACTIONAL_BITS;
logic signed [7:0] fixed_sin[0:9];
real float_sin;
int file;
initial
begin
// 生成正弦数据
for (int i = 0;i<10;i++)
begin
float_sin = $sin(2*3.1415926 *i/10);
fixed_sin[i] = $rtoi(float_sin*SCALE);
$display("i=%d, float_sin=%f, fixed_sin=%d",i,float_sin,fixed_sin[i]);
end
// 写入文件
file = $fopen("../../../../fixed_sin.txt","w");
$fdisplay(file,"虚拟生成的正弦数据:");
for (int i = 0;i<10;i++)
begin
$fdisplay(file,"%d",fixed_sin[i]);
end
$fclose(file);
end
endmodule

本地txt文件

tcl观察display

FPGA使用sv生成虚拟单音测试数据
/posts/fpga使用sv生成虚拟单音测试数据/
作者
唐承乾
发布于
2024-08-07
许可协议
CC BY-NC-SA 4.0

部分信息可能已经过时

Personal Site
唐承乾
Profile Image of the Author
技术笔记、长期专题与电子书草稿

嵌入式 & AI 工作流。螺旋式学习,把踩过的坑整理成以后还能复用的东西。

GitHub 知乎
CSDN