Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
17254 Discussions

Importing a text file

Altera_Forum
Honored Contributor II
3,393 Views

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)?  

 

Thanks
0 Kudos
10 Replies
Altera_Forum
Honored Contributor II
2,412 Views

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...
0 Kudos
Altera_Forum
Honored Contributor II
2,412 Views

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?
0 Kudos
Altera_Forum
Honored Contributor II
2,412 Views

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.
0 Kudos
Altera_Forum
Honored Contributor II
2,412 Views

@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.
0 Kudos
Altera_Forum
Honored Contributor II
2,412 Views

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?
0 Kudos
Altera_Forum
Honored Contributor II
2,412 Views

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.
0 Kudos
Altera_Forum
Honored Contributor II
2,412 Views

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).

0 Kudos
Altera_Forum
Honored Contributor II
2,412 Views

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.
0 Kudos
Altera_Forum
Honored Contributor II
2,412 Views

Dvido, can you post some of your code so i can see the registers?

0 Kudos
Altera_Forum
Honored Contributor II
2,412 Views

 

--- 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?
0 Kudos
Reply