首先我想说的是,我是通过在 ModelSim 中编译的 Verilog 模型在 ADS(Advanced Design System 2017)中运行仿真的。
我的目标是将 .txt 文件中的数据作为输入加载到测试平台中,以便运行模拟,然后将此模拟的结果保存在另一个 .txt 文件中。
以下是名为“param.txt”的输入测试 .txt 文件的内容:
1
2
3
4
5
这是我的 Verilog 测试平台代码:
`include "disciplines.vams"
module resistor(p,n);
electrical p,n;
parameter real R=50.0;
integer file;
integer out;
real pwm_A[0:10];
integer i;
integer count;
analog begin
@(initial_step) // Initial Conditions
begin
////////////// Read
file=$fopen("param.txt","r");
if (file) $display("File was opened successfully : %0d", file);
else $display("File was NOT opened successfully : %0d", file);
for (i=1; i<=5; i=i+1) begin
count = $fscanf(file,"%d",pwm_A[i]);
end
////////////// Write
out=$fopen("out.txt","w");
for (i=1; i<=5; i=i+1) begin
$fwrite(out,"%d\n",pwm_A[i]);
end
$fclose(file);
$fclose(out);
end
// Simulation (doesnt matter)
V(p,n) <+ R * I(p,n);
end
endmodule
模拟抛出此错误:
Error: Incorrect target supplied to integer-valued $fscanf field.
有人可以发现问题吗?
提前致谢。
您已声明pwm
为实数数组,同时使用%d
格式说明符读取和写入文件。你需要要么
i) 更改pwm
为整数数组或
ii) 将%d
格式说明符更改为%f
in$fscanf
和$fwrite
系统函数调用。
该%d
格式说明期待读取和会写一个十进制整数。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句