file - Read and write from txt in Verilog
问题描述
First of all I want to say that I'm running the simulation in ADS (Advanced Design System 2017) through a Verilog model compiled in ModelSim.
My objective is loading data from a .txt file into the testbench as input in order to run the simulation, and afterwards save the results of this simulation in another .txt file.
Here is the content for the input test .txt file called "param.txt":
1
2
3
4
5
And here is my Verilog testbench code:
`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
The simulation throws this error:
Error: Incorrect target supplied to integer-valued $fscanf field.
May anyone spot the problem?
Thanks in advance.
解决方案
您已声明pwm
为实数数组,同时使用%d
格式说明符读取和写入文件。你需要要么
i) 更改pwm
为整数数组或
ii) 将%d
格式说明符更改%f
为$fscanf
and$fwrite
系统函数调用。
格式说明%d
符期望读取并将写入十进制整数。
推荐阅读
- php - 使用 Instagram 在服务器中获取数据时出现问题?__a=1 url
- c++ - 每次用户在 5 秒不活动后与 GUI 交互时,QTimer 重置为 60 秒
- android - Android 应用程序不回到最前面
- laravel - 无法使用 Laravel 从控制器方法中的路由获取 $user
- c# - 如何以及在何处存储工具箱工具(C# Visual Studio 2013 Ultimate)?
- python-3.x - Python中的返回函数
- authentication - 尝试使用 CakePHP 3.8 构建一个简单的 Auth
- javascript - 按地震名称(或 ID)过滤抖动图
- pdf - PdfBox 2.0.20 将签名字段添加到签名文档并将 NeedAppearances 设置为 true 会破坏现有签名
- python - 如何将函数的变量存储在列表中?