EmbDev.net

Forum: FPGA, VHDL & Verilog Implement FIR filter in verilog using FDA tool


Author: Usman Ashraf (Company: LUMS) (usmanashraf678)
Posted on:
Attached files:

Rate this post
0 useful
not useful
Dear Members,

I need help with simulating a filter I have designed using the FDA tool 
of Matlab.

I need to read data (hexadecimal format, 10 bit each) from a text file 
and write the filter output to another file. I am not able to modify the 
original testbench (generated by FDA tool in Matlab) to implement this. 
It would much relief for me if anyone could help me on this.

The filter .fda file, HDL module and test bench generated by Matlab are 
uploaded on the google drive link.

Thanks in advance.

Author: ElKo (Guest)
Posted on:

Rate this post
1 useful
not useful
May you please be more specific in "I am not able to modify the original 
testbench"?

Does it mean
- the file is write protected?
- you are not aware of text editors?
- you don't know the procedure to read in a file in 
verilog/systemverilog? ($fopen, $fscanf)
- this file-read procedure fails at any point?
- you already copied the data from this file into 
filter_in_data_log_force and filter_out_expected, but it doesn't work as 
intented, as the result is X instead of Y?
- there is a problem in including the datafile into matlab?

How can we help, if we don't know, at which point you struggle? Please 
provide us more information.

Author: Usman Ashraf (Company: LUMS) (usmanashraf678)
Posted on:
Attached files:

Rate this post
0 useful
not useful
Thanks EIKo for such an elaborate reply. Actually, I am new to Verilog 
and I don't know how to use the $fread, $fwrite commands to write a test 
bench. After much efforts, I have made one (filter_tb2.v). Can you just 
review it to tell if I have done it correctly?

Currently, I am testing it with the attached HEX file (P28hex200.txt)

Author: ElKo (Guest)
Posted on:
Attached files:

Rate this post
1 useful
not useful
Basically thats the way to go. The code you provided had some issues. 
After removing them, it is reading the content of the file, doing 
something, and writing it to an output file.
You find the reworked version attached to the post.

The testbench was prooven in modelsim alter 15. The tcl-commands are 
included in the testbench.

You have to check, whether the procedure and timing of applying the data 
and reading it from the filter is done right. Also you have to proove 
the filter output.
[...]
initial begin
    // open files, read input Memory
        $readmemh("P28hex200.txt", IN_MEM);
        filter_output_file = $fopen("Filter_Output.txt", "w");
        
    // Initialize Inputs
        [...]
        
    // Wait 100 ns for global reset to finish
        #100
    
    // release reset
        [...]
    
    // apply data to the filter and read result
        for (i = 0; i < 199; i=i+1) begin
            #1 
            filter_in = IN_MEM[i];
            #8
            $fwrite(filter_output_file, "%h\n" , filter_out);
            #1
            $display("          in %u - out %u", filter_in, filter_out);
        end

    // close file
        $fclose(filter_output_file);
    
    // stop simulation
        #1 $finish;
[...]

Author: Usman Ashraf (Company: LUMS) (usmanashraf678)
Posted on:
Attached files:

Rate this post
0 useful
not useful
Hey, EIKo thanks so much for such an elaborate answer. Your solution 
worked out. I have verified the output using matlab as well. So, that's 
a sigh of relief. I thought it was important to thank you.

Moreover, I would like to upload the files that I have used for everyone 
else.

Author: ElKo (Guest)
Posted on:

Rate this post
0 useful
not useful
Glad to hear, that it helped you. Thanks for the feedback!

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig