Hi. I am trying to write generic VHDL code for FIR filter. generic parametars should be word_length, filter_order. Can anybody help me how to input filter coeficients. I tought something like, read coeficitients from file and write it in some LUT table. Could it be done (or something similar)?
Thanks for help
Didn't find your answer? Ask the community — no account required.
R
Ray Andraka
If it is synthesizable code, it can't go and read files. What you can do though is have a helper function that converts your coefficient file into a VHDL package containing the coefficient constants. Write that package to a file, and then include that file with the rest of the design when you compile the design. The helper function can be non-synthesizable VHDL, C, Matlab or any other programming language you feel like using. Alternatively, you can cut and paste your coefficients into a VHDL package or directly into a constant array in your code.
You can also pass the coefficients into the entity through a generic by defining an integer_array type in a top level package, referring to that package in the library declarations, and then putting the int_array in the generics like this:
Leaving the integer array unconstrained allows you to put in an arbitrary number of coefficients (must be more than 1).
Z
Zorjak
Thanks for your answer Ray
I am using Altera Quartus|| software and I've seen there thet some
*.mif files are using for ram initialization so I thought could I do something similar with my FIR filter. Can you help me with that helper function if it isnt to much that I am asking. I am VHDL beginer and I am not very familiar with it so any lkind of help would used me.
If is to much that I asking, sory. Thanks again
R
Ray Andraka
The *.MIF files are tie-ins to the altera tools, and have nothing to do with the VHDL. You don't have the hooks you need to get inside the place and route tools to bring in your own custom initialization.
The helper program I talked about just has to write out a text file containing a VHDL package. The package contains a constant containing your coefficients.
Z
Zorjak
I think I understand you. I'll try to do that
Thanks again, Ray
J
Jiri Plasil
You can use e.g. std.textio.all package. The coeffs can be stored in the regular text file. In case std.textio.all the content of the file is binary string like
-- file.dat
0010000
0010001 ...
(there is also possibility to use hex representation but different
package has to be used - from IEEE....)
Then just define ROM (distributed or block RAM) by array statement. E. g.
TYPE ROM IS ARRAY (N_COEFF - 1 DOWNTO 0) OF SIGNED(N_BITS - 1 DOWNTO 0);
Define function "init_function" to be able read data from file by means
of "readline" and "read" statement from textio package.
And finally initiate e. g. constant of coeffs.
CONSTANT coeff : ROM := init_function("file.dat");
It works in XST. I don't have any experience with Quartus. Check in the
Quartus documentation how is possible define initial value of registers
an memories.
R
Ray Andraka
It may work in some tools, but it isn't standard. Generally speaking file i/o is not currently allowed in synthesizable code. It is allowed in behavioral code (e.g. testbenches) that is not intended to be synthesized, but I wasn't aware that any synthesizers supported file i/o. I've asked for years for support of file i/o and reals for filling constants. I think some are supporting reals in functions for generating constants now.
Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required
Report Content
You are reporting this content to the moderators. They will look at it
ASAP.