- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I need to import a text file into my VHDL code. I have binary/hex values written in that file and I have to put these values into registers. Is there a simple, automatic way to do that (besides copy-paste)? ThanksLink Copied
10 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Dvido,
1) you can read in text files into VHDL descriptions using VHDL FILE IO. With the text I/O in VHDL can can work with files like in a regular programming language. You can open and close multiple files, read lines, parse lines etc. For this you use the VHDL "file" data type. The textio package which is available in the standard library includes several more features. 2) in case you want to initialize built in memories generated by the MegaWizard, you can also generate the memory contents by .hex or .mif files. Hope this helps...- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi sanmao,
Thanks for the help. Any idea where I can find some list of the relevant VHDL functions and a description of that textio package?- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please bare in mind that textio functions cannot be synthesised - they can only be used for getting data into/out of a testbench (eg. a stimulus file) and works in Xilinx to set up initial memory values (doesnt work in quartus).
I found this link which seems to have something on textio from about slide 13 onwards http://www.people.vcu.edu/~rhklenke/tutorials/vhdl/modules/m13_23/sld014.htm there are 2 main libraries, std.textio which contains read/write functions for writing basic types (integer, string, character, bit etc) and then theres ieee.std_logic_textio which allows you to read/write std_logic and std_logic_vector. For the latter, you can read/write binary, octal or hex Any more questions, just fire away.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Dvido,
the remark by Tricky is correct. a good introduction to VHDL is the book by Peter Ashenden, "The Designer's Guide to VHDL", Academic Press.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the help guys. I am not a VHDL expert, so my question might sound stupid...
Let me explain my problem and maybe you can help me more: I have some files with lots of binary data, divided into 64-bit lines. I have to put each line into a 64-bit register. I can do it by copy-paste, but it will take ages. How can I do it automatically? Which exact functions should I use?- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When you say you are trying to put them in a register, do you mean
1.load the values into a register under simulation 2. load the values into the registers on actual hardware 3. do you mean set up the reset/powerup values of the registers? Answers: 1. text io is what you need, along with a well controlled process. This can be done with the textio functions 2. you'll need to have some mechanism of reading the file in the processor and transmitting the values to your hardware. textio wont help you here. 3. You have 2 options. 1. create a function that uses Textio to read the values in from the file that is called when the reset path of the register occurs. 2. Use a script to create a VHDL package full of constants that you then reference in the reset process. Given that quartus apparently wont let you use textio functions during synthesis, you may have to manually copy/paste them as you worry, or use the a script to generate the VHDL.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What I need as load the data to the register before the compilation and then burn it on the FPGA with the data hardcoded (so the registers will be constant).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In that case you can't use TextIO, it is not recognized by Quartus during synthesis.
If your registers are in a memory block instantiated with the megawizard, you can specify a .hex file to initialize the memory contents. It is an option in the megawizard itself. It is the easiest method I think. If you need to load FPGA registers, the only way I can think of is to write a tool that reads your binary data and generates VHDL code from it.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dvido, can you post some of your code so i can see the registers?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- What I need as load the data to the register before the compilation and then burn it on the FPGA with the data hardcoded (so the registers will be constant). --- Quote End --- if they are constants, why not just declare a big constant array of values in the code?

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page