_TOP_MENU

Dec 17, 2015

File Handling in Verilog


The Verilog language has a rich set of system functions to write files ($fdisplay, $fwrite, etc.) but only reads files with a single, fixed format ($readmem). In the past if you wanted to read a file that was not in $readmem format, you would have to learn the Programming Language Interface (PLI) and the C language, write C code to read the file and pass values into Verilog, then debug the combined C and Verilog code. In addition, the Verilog is limited to 32 open files at a time.


To Write into a file -> 

module tb;

integer fl1;

initial begin
  fl1 = $fopen("file.xyz");
  
  forever  begin
    @(posedge clk)
    $fdisplay(fl1, "value to print = %h", value);
 end
 $fclose(fl1);
end 

endmodule


Read a file in Verilog.

file = $fopen("filename");

Reading data for per clock cycle ->  (In System Verilog)

integer data_file ; // file handler
integer scan_file ; // file handler
logic signed [21:0] capture_data;

`define NULL 0

 initial begin
   data_file = $fopen("data_file.txt", "r");
   if (data_file == `NULL) begin
     $display("data_file handle was NULL");
     $finish;
  end
end

always @(posedge clk) begin
  scan_file = $fscanf(data_file, "%d\n", capture_data);
  if (!$feof(data_file)) begin //use capture_data;
 end
end

NEXT

91 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete
  5. This comment has been removed by a blog administrator.

    ReplyDelete
  6. This comment has been removed by a blog administrator.

    ReplyDelete
  7. This comment has been removed by a blog administrator.

    ReplyDelete
  8. This comment has been removed by a blog administrator.

    ReplyDelete
  9. This comment has been removed by a blog administrator.

    ReplyDelete
  10. This comment has been removed by a blog administrator.

    ReplyDelete
  11. This comment has been removed by a blog administrator.

    ReplyDelete
  12. This comment has been removed by a blog administrator.

    ReplyDelete
  13. This comment has been removed by a blog administrator.

    ReplyDelete
  14. This comment has been removed by a blog administrator.

    ReplyDelete
  15. This comment has been removed by a blog administrator.

    ReplyDelete
  16. This comment has been removed by a blog administrator.

    ReplyDelete
  17. This comment has been removed by a blog administrator.

    ReplyDelete
  18. This comment has been removed by a blog administrator.

    ReplyDelete
  19. This comment has been removed by a blog administrator.

    ReplyDelete
  20. This comment has been removed by a blog administrator.

    ReplyDelete
  21. This comment has been removed by a blog administrator.

    ReplyDelete
  22. This comment has been removed by a blog administrator.

    ReplyDelete
  23. This comment has been removed by a blog administrator.

    ReplyDelete
  24. This comment has been removed by a blog administrator.

    ReplyDelete
  25. This comment has been removed by a blog administrator.

    ReplyDelete
  26. This comment has been removed by a blog administrator.

    ReplyDelete
  27. This comment has been removed by a blog administrator.

    ReplyDelete
  28. This comment has been removed by a blog administrator.

    ReplyDelete
  29. This comment has been removed by a blog administrator.

    ReplyDelete
  30. This comment has been removed by a blog administrator.

    ReplyDelete
  31. This comment has been removed by a blog administrator.

    ReplyDelete
  32. This comment has been removed by a blog administrator.

    ReplyDelete
  33. This comment has been removed by a blog administrator.

    ReplyDelete
  34. This comment has been removed by a blog administrator.

    ReplyDelete
  35. This comment has been removed by a blog administrator.

    ReplyDelete
  36. This comment has been removed by a blog administrator.

    ReplyDelete
  37. This comment has been removed by a blog administrator.

    ReplyDelete
  38. This comment has been removed by a blog administrator.

    ReplyDelete
  39. This comment has been removed by a blog administrator.

    ReplyDelete
  40. This comment has been removed by a blog administrator.

    ReplyDelete
  41. This comment has been removed by a blog administrator.

    ReplyDelete
  42. This comment has been removed by a blog administrator.

    ReplyDelete
  43. This comment has been removed by a blog administrator.

    ReplyDelete
  44. This comment has been removed by a blog administrator.

    ReplyDelete
  45. This comment has been removed by a blog administrator.

    ReplyDelete
  46. This comment has been removed by a blog administrator.

    ReplyDelete
  47. This comment has been removed by a blog administrator.

    ReplyDelete
  48. This comment has been removed by a blog administrator.

    ReplyDelete
  49. This comment has been removed by a blog administrator.

    ReplyDelete
  50. This comment has been removed by a blog administrator.

    ReplyDelete
  51. Aw, this was a really nice post. Finding the time and actual
    effort to create a top notch article… but what can I
    say… I put things off a whole lot and never seem to get nearly anything done.

    ReplyDelete
  52. I wanted to thank you for this very good read!! I absolutely loved every little bit of
    it. I have you book-marked to look at new stuff you
    post…

    ReplyDelete
  53. When I initially left a comment I seem to have clicked on the -Notify me when new comments are added- checkbox and from now on every
    time a comment is added I get 4 emails with the same
    comment. There has to be a means you are able to remove me from that service?
    Thank you!

    ReplyDelete
  54. You need to take part in a contest for one of
    the best sites on the net. I will recommend this web site!

    ReplyDelete
  55. I’m amazed, I must say. Rarely do I come across a blog that’s equally educative and interesting, and
    without a doubt, you've hit the nail on the head. The problem is something that too few people are speaking intelligently about.

    I am very happy that I stumbled across this during my search
    for something regarding this.

    ReplyDelete
  56. You are so awesome! I do not suppose I've truly read a single thing like this before.
    So nice to find someone with a few unique thoughts on this
    topic. Really.. many thanks for starting
    this up. This web site is one thing that's needed on the internet, someone
    with a bit of originality!

    ReplyDelete
  57. Can I simply just say what a relief to discover an individual who truly understands what they're talking
    about online. You actually understand how to bring a problem
    to light and make it important. More and more people have to check this out and understand this side of your story.

    It's surprising you're not more popular because you most certainly
    possess the gift.

    ReplyDelete
  58. Hi, I do think this is a great site. I stumbledupon it ;
    ) I will return yet again since i have bookmarked it. Money
    and freedom is the best way to change, may you be rich
    and continue to guide others.

    ReplyDelete
  59. I was more than happy to find this site. I need to to thank you for your time for this particularly wonderful read!!

    I definitely loved every little bit of it and I have you saved as a favorite to check out
    new things on your website.

    ReplyDelete
  60. I’m impressed, I must say. Rarely do I encounter a blog
    that’s equally educative and amusing, and without a doubt, you have hit the nail on the head.

    The issue is an issue that too few folks are
    speaking intelligently about. Now i'm very happy that I stumbled across this during my
    search for something relating to this.

    ReplyDelete
  61. I wanted to thank you for this wonderful read!!
    I certainly enjoyed every little bit of it. I've got you book marked to look
    at new things you post…

    ReplyDelete
  62. Great post. I'm dealing with many of these issues as well..

    ReplyDelete
  63. I’m amazed, I have to admit. Seldom do I encounter a blog that’s equally educative and engaging, and let me tell you,
    you have hit the nail on the head. The problem is something not enough people are
    speaking intelligently about. I am very happy I came across this in my search for something
    regarding this.

    ReplyDelete
  64. Excellent web site you have here.. It’s hard to find quality writing
    like yours nowadays. I honestly appreciate individuals like
    you! Take care!!

    ReplyDelete
  65. An outstanding share! I have just forwarded this onto a friend
    who was conducting a little research on this. And
    he in fact ordered me breakfast due to the fact that I
    found it for him... lol. So allow me to reword
    this.... Thank YOU for the meal!! But yeah, thanks for spending the time to discuss this topic here on your web site.

    ReplyDelete
  66. It’s hard to find educated people for this topic, but
    you sound like you know what you’re talking about!
    Thanks

    ReplyDelete
  67. Great post! We are linking to this particularly great post on our site.

    Keep up the good writing.

    ReplyDelete
  68. This is a topic which is close to my heart... Take care!
    Exactly where are your contact details though?

    ReplyDelete
  69. Right here is the perfect webpage for anybody who really wants to understand this topic.
    You know so much its almost hard to argue with you (not that I actually will need to…HaHa).

    You definitely put a fresh spin on a subject that's been written about for many years.
    Wonderful stuff, just great!

    ReplyDelete
  70. Howdy! This blog post could not be written any better!
    Reading through this post reminds me of my previous roommate!
    He constantly kept preaching about this. I most certainly will
    send this post to him. Fairly certain he's going to have a very good read.
    Thank you for sharing!

    ReplyDelete
  71. This excellent website definitely has all of
    the info I wanted about this subject and didn’t know who to ask.

    ReplyDelete
  72. This is the perfect webpage for anybody who really wants to understand this topic.

    You know so much its almost tough to argue with you (not that I personally will need to…HaHa).
    You certainly put a new spin on a subject which has been written about
    for ages. Great stuff, just excellent!

    ReplyDelete
  73. Very good article. I certainly love this website.
    Stick with it!

    ReplyDelete
  74. You are so awesome! I don't think I've truly read through anything
    like this before. So great to discover somebody with some original thoughts on this subject.

    Really.. thank you for starting this up. This web site is
    one thing that's needed on the internet, someone with some
    originality!

    ReplyDelete
  75. I absolutely love your blog.. Pleasant colors & theme. Did you
    build this amazing site yourself? Please reply back as I’m looking to create my own site and would like to find out where you got this from or exactly what the theme is called.
    Thank you!

    ReplyDelete
  76. It’s hard to find educated people about this topic, however, you sound
    like you know what you’re talking about! Thanks

    ReplyDelete
  77. The next time I read a blog, Hopefully it won't disappoint me as much as this particular one.
    After all, I know it was my choice to read through, nonetheless I truly thought you
    would have something interesting to talk about. All I hear is a bunch of complaining about something
    you could fix if you weren't too busy looking for attention.

    ReplyDelete
  78. I would like to thank you for the efforts you've put in writing this website.
    I am hoping to see the same high-grade blog posts from you
    later on as well. In fact, your creative writing
    abilities has motivated me to get my own, personal
    website now ;)

    ReplyDelete
  79. Hello! I simply want to offer you a huge thumbs up for the excellent info
    you have got right here on this post. I am returning to your
    web site for more soon.

    ReplyDelete
  80. You should take part in a contest for one of the
    best sites on the net. I most certainly will highly recommend this web site!

    ReplyDelete
  81. This is the right web site for anyone who really wants to
    find out about this topic. You know a whole lot its almost hard
    to argue with you (not that I personally would
    want to…HaHa). You definitely put a new spin on a topic that has
    been discussed for years. Excellent stuff, just wonderful!

    ReplyDelete
  82. Hi there! I simply want to offer you a huge thumbs up for your excellent info you've got right here on this post.
    I'll be coming back to your blog for more soon.

    ReplyDelete
  83. Greetings! Very helpful advice in this particular article!
    It's the little changes that will make the most important
    changes. Many thanks for sharing!

    ReplyDelete
  84. After checking out a number of the blog posts on your site,
    I seriously appreciate your technique of blogging. I saved it
    to my bookmark webpage list and will be checking back in the near future.

    Please visit my web site too and tell me your
    opinion.

    ReplyDelete
  85. Greetings! Very helpful advice in this particular post!
    It is the little changes which will make the greatest changes.
    Thanks for sharing!

    ReplyDelete
  86. There is definately a lot to learn about this
    issue. I really like all of the points you made.

    ReplyDelete
  87. This is a really good tip particularly to those fresh
    to the blogosphere. Short but very precise information… Thanks for sharing this one.
    A must read post!

    ReplyDelete
  88. Howdy! This article couldn’t be written any better!

    Reading through this post reminds me of my previous roommate!
    He constantly kept preaching about this. I am going to forward this article
    to him. Pretty sure he's going to have a good read.

    Many thanks for sharing!

    ReplyDelete
  89. Saved as a favorite, I really like your site!

    ReplyDelete
  90. Hi, I do believe this is an excellent web site. I stumbledupon it ;
    ) I'm going to come back yet again since i have book marked it.
    Money and freedom is the greatest way to change, may you be rich
    and continue to help other people.

    ReplyDelete
  91. Aw, this was a really good post. Finding the time and actual effort to create
    a good article… but what can I say… I procrastinate a lot and never manage to get nearly anything done.

    ReplyDelete