MPTSheff
Newbie level 3
- Joined
- Aug 14, 2013
- Messages
- 4
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 47
I'm trying to read in a data file to a spartan 3E starter kit using verilog. The file is simply a list of 8bit binary numbers (eg.11000011). I wish to read each line in one at a time, in order to activate the appropriate LEDs. The code I've written is listed below and uses $fscanf to read in the data. However, when I try to generate the programming file I get the error: "File argument of function $fscanf is not constant."
I am also unsure where exactly to physically place my data file. From the examples I've found eg. "in = $fopen("data.txt","r");" presumably this should be in the same directory as the verilog module file?
Any help would be greatly appreciated.
I am also unsure where exactly to physically place my data file. From the examples I've found eg. "in = $fopen("data.txt","r");" presumably this should be in the same directory as the verilog module file?
Any help would be greatly appreciated.
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 module inputdata( output reg [7:0] leds, input wire clock, input reset ); integer in, line; reg [47:0] din; reg [23:0] state; initial begin in = $fopen("data.txt","r"); end always @( posedge clock or negedge reset) begin if( reset == 1'b0 ) begin state <= 24'b0; // Allows the change in LEDs to be seen leds <= 8'b0; end else begin state <= state + 24'b1; if( state == 24'hFFFFFE ) begin line = $fscanf(in, "%b",din); // reads in value to be set to LED end if( state == 24'hFFFFFF ) begin leds <= line; // sets LED value end end end endmodule
Last edited: