Read and write from txt in Verilog2019 Community Moderator ElectionRead and write array from txt in VerilogHow do I create a Java string from the contents of a file?How to read all files in a folder from Java?Writing files in Node.jsHow to read a file line-by-line into a list?iterative read data from more than one files in verilogread and write in verilog when having negative numbers and arraySimulation of Modelsim launching from Quartus doesn't work properlyhow to generate vcd file in xilinx ISE for verilog code?fwrite variables from sub-modulesRead and write array from txt in Verilog
Force user to remove USB token
validation vs test vs training accuracy, which one to compare for claiming overfit?
What Happens when Passenger Refuses to Fly Boeing 737 Max?
Humans have energy, but not water. What happens?
US to Europe trip with Montreal layover - is 52 minutes enough?
When two POV characters meet
Why must traveling waves have the same amplitude to form a standing wave?
"One can do his homework in the library"
Can the druid cantrip Thorn Whip really defeat a water weird this easily?
Should QA ask requirements to developers?
Can you reject a postdoc offer after the PI has paid a large sum for flights/accommodation for your visit?
Make a transparent 448*448 image
Best mythical creature to use as livestock?
Am I not good enough for you?
Do Bugbears' arms literally get longer when it's their turn?
Want to switch to tankless, but can I use my existing wiring?
When were linguistics departments first established
What to do when during a meeting client people start to fight (even physically) with each others?
How to deal with a cynical class?
Is King K. Rool's down throw to up-special a true combo?
Can "semicircle" be used to refer to a part-circle that is not a exact half-circle?
Is it ok to include an epilogue dedicated to colleagues who passed away in the end of the manuscript?
Why don't MCU characters ever seem to have language issues?
Should we release the security issues we found in our product as CVE or we can just update those on weekly release notes?
Read and write from txt in Verilog
2019 Community Moderator ElectionRead and write array from txt in VerilogHow do I create a Java string from the contents of a file?How to read all files in a folder from Java?Writing files in Node.jsHow to read a file line-by-line into a list?iterative read data from more than one files in verilogread and write in verilog when having negative numbers and arraySimulation of Modelsim launching from Quartus doesn't work properlyhow to generate vcd file in xilinx ISE for verilog code?fwrite variables from sub-modulesRead and write array 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,"%dn",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.
file save verilog
New contributor
|
show 3 more comments
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,"%dn",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.
file save verilog
New contributor
Possible duplicate of Read and write array from txt in Verilog
– Silicon1602
Mar 7 at 11:10
It's not duplicated, i'ts just another issue!
– davmc
Mar 7 at 11:18
Hi davmc! Yes, but your source code still contains the same issue as the previous question, where Matthew suggested to changepwm_A[i]=$fscanf(file,"%d",j);
tocount = $fscanf(file,"%d",pwm_A[i]);
.
– Silicon1602
Mar 7 at 11:30
1
You declaredpwm_A
as areal
. Did you try to declare it as aninteger
? Based on the error message you provided, this could be the problem. If you actually need to load real numbers instead of integers, you might want to change the%d
specifier. See this reference on the several C specifiers.
– Silicon1602
Mar 7 at 13:21
1
There are differences between C and Verilog-AMS formatted input and output. Go for the Verilog-AMS standard accellera.org/images/downloads/standards/v-ams/VAMS-LRM-2-4.pdf.
– Paul Floyd
Mar 7 at 17:07
|
show 3 more comments
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,"%dn",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.
file save verilog
New contributor
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,"%dn",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.
file save verilog
file save verilog
New contributor
New contributor
edited Mar 7 at 12:52
user1155120
12.3k32228
12.3k32228
New contributor
asked Mar 7 at 10:56
davmcdavmc
204
204
New contributor
New contributor
Possible duplicate of Read and write array from txt in Verilog
– Silicon1602
Mar 7 at 11:10
It's not duplicated, i'ts just another issue!
– davmc
Mar 7 at 11:18
Hi davmc! Yes, but your source code still contains the same issue as the previous question, where Matthew suggested to changepwm_A[i]=$fscanf(file,"%d",j);
tocount = $fscanf(file,"%d",pwm_A[i]);
.
– Silicon1602
Mar 7 at 11:30
1
You declaredpwm_A
as areal
. Did you try to declare it as aninteger
? Based on the error message you provided, this could be the problem. If you actually need to load real numbers instead of integers, you might want to change the%d
specifier. See this reference on the several C specifiers.
– Silicon1602
Mar 7 at 13:21
1
There are differences between C and Verilog-AMS formatted input and output. Go for the Verilog-AMS standard accellera.org/images/downloads/standards/v-ams/VAMS-LRM-2-4.pdf.
– Paul Floyd
Mar 7 at 17:07
|
show 3 more comments
Possible duplicate of Read and write array from txt in Verilog
– Silicon1602
Mar 7 at 11:10
It's not duplicated, i'ts just another issue!
– davmc
Mar 7 at 11:18
Hi davmc! Yes, but your source code still contains the same issue as the previous question, where Matthew suggested to changepwm_A[i]=$fscanf(file,"%d",j);
tocount = $fscanf(file,"%d",pwm_A[i]);
.
– Silicon1602
Mar 7 at 11:30
1
You declaredpwm_A
as areal
. Did you try to declare it as aninteger
? Based on the error message you provided, this could be the problem. If you actually need to load real numbers instead of integers, you might want to change the%d
specifier. See this reference on the several C specifiers.
– Silicon1602
Mar 7 at 13:21
1
There are differences between C and Verilog-AMS formatted input and output. Go for the Verilog-AMS standard accellera.org/images/downloads/standards/v-ams/VAMS-LRM-2-4.pdf.
– Paul Floyd
Mar 7 at 17:07
Possible duplicate of Read and write array from txt in Verilog
– Silicon1602
Mar 7 at 11:10
Possible duplicate of Read and write array from txt in Verilog
– Silicon1602
Mar 7 at 11:10
It's not duplicated, i'ts just another issue!
– davmc
Mar 7 at 11:18
It's not duplicated, i'ts just another issue!
– davmc
Mar 7 at 11:18
Hi davmc! Yes, but your source code still contains the same issue as the previous question, where Matthew suggested to change
pwm_A[i]=$fscanf(file,"%d",j);
to count = $fscanf(file,"%d",pwm_A[i]);
.– Silicon1602
Mar 7 at 11:30
Hi davmc! Yes, but your source code still contains the same issue as the previous question, where Matthew suggested to change
pwm_A[i]=$fscanf(file,"%d",j);
to count = $fscanf(file,"%d",pwm_A[i]);
.– Silicon1602
Mar 7 at 11:30
1
1
You declared
pwm_A
as a real
. Did you try to declare it as an integer
? Based on the error message you provided, this could be the problem. If you actually need to load real numbers instead of integers, you might want to change the %d
specifier. See this reference on the several C specifiers.– Silicon1602
Mar 7 at 13:21
You declared
pwm_A
as a real
. Did you try to declare it as an integer
? Based on the error message you provided, this could be the problem. If you actually need to load real numbers instead of integers, you might want to change the %d
specifier. See this reference on the several C specifiers.– Silicon1602
Mar 7 at 13:21
1
1
There are differences between C and Verilog-AMS formatted input and output. Go for the Verilog-AMS standard accellera.org/images/downloads/standards/v-ams/VAMS-LRM-2-4.pdf.
– Paul Floyd
Mar 7 at 17:07
There are differences between C and Verilog-AMS formatted input and output. Go for the Verilog-AMS standard accellera.org/images/downloads/standards/v-ams/VAMS-LRM-2-4.pdf.
– Paul Floyd
Mar 7 at 17:07
|
show 3 more comments
1 Answer
1
active
oldest
votes
You have declared pwm
as an array of reals whilst using the %d
format specifier to both read and write the file. You need to either
i) change pwm
to be an array of integers or
ii) change the %d
format specifier to %f
in the $fscanf
and $fwrite
system function calls.
The %d
format specifier is expecting to read and will write a decimal integer.
Thanks a lot, works like a charm now. Really appreciate it.
– davmc
Mar 7 at 21:02
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
davmc is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55042142%2fread-and-write-from-txt-in-verilog%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have declared pwm
as an array of reals whilst using the %d
format specifier to both read and write the file. You need to either
i) change pwm
to be an array of integers or
ii) change the %d
format specifier to %f
in the $fscanf
and $fwrite
system function calls.
The %d
format specifier is expecting to read and will write a decimal integer.
Thanks a lot, works like a charm now. Really appreciate it.
– davmc
Mar 7 at 21:02
add a comment |
You have declared pwm
as an array of reals whilst using the %d
format specifier to both read and write the file. You need to either
i) change pwm
to be an array of integers or
ii) change the %d
format specifier to %f
in the $fscanf
and $fwrite
system function calls.
The %d
format specifier is expecting to read and will write a decimal integer.
Thanks a lot, works like a charm now. Really appreciate it.
– davmc
Mar 7 at 21:02
add a comment |
You have declared pwm
as an array of reals whilst using the %d
format specifier to both read and write the file. You need to either
i) change pwm
to be an array of integers or
ii) change the %d
format specifier to %f
in the $fscanf
and $fwrite
system function calls.
The %d
format specifier is expecting to read and will write a decimal integer.
You have declared pwm
as an array of reals whilst using the %d
format specifier to both read and write the file. You need to either
i) change pwm
to be an array of integers or
ii) change the %d
format specifier to %f
in the $fscanf
and $fwrite
system function calls.
The %d
format specifier is expecting to read and will write a decimal integer.
answered Mar 7 at 14:16
Matthew TaylorMatthew Taylor
7,5562832
7,5562832
Thanks a lot, works like a charm now. Really appreciate it.
– davmc
Mar 7 at 21:02
add a comment |
Thanks a lot, works like a charm now. Really appreciate it.
– davmc
Mar 7 at 21:02
Thanks a lot, works like a charm now. Really appreciate it.
– davmc
Mar 7 at 21:02
Thanks a lot, works like a charm now. Really appreciate it.
– davmc
Mar 7 at 21:02
add a comment |
davmc is a new contributor. Be nice, and check out our Code of Conduct.
davmc is a new contributor. Be nice, and check out our Code of Conduct.
davmc is a new contributor. Be nice, and check out our Code of Conduct.
davmc is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55042142%2fread-and-write-from-txt-in-verilog%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible duplicate of Read and write array from txt in Verilog
– Silicon1602
Mar 7 at 11:10
It's not duplicated, i'ts just another issue!
– davmc
Mar 7 at 11:18
Hi davmc! Yes, but your source code still contains the same issue as the previous question, where Matthew suggested to change
pwm_A[i]=$fscanf(file,"%d",j);
tocount = $fscanf(file,"%d",pwm_A[i]);
.– Silicon1602
Mar 7 at 11:30
1
You declared
pwm_A
as areal
. Did you try to declare it as aninteger
? Based on the error message you provided, this could be the problem. If you actually need to load real numbers instead of integers, you might want to change the%d
specifier. See this reference on the several C specifiers.– Silicon1602
Mar 7 at 13:21
1
There are differences between C and Verilog-AMS formatted input and output. Go for the Verilog-AMS standard accellera.org/images/downloads/standards/v-ams/VAMS-LRM-2-4.pdf.
– Paul Floyd
Mar 7 at 17:07