verilog-problem read decimal value in text file

Status
Not open for further replies.

jalal.baba

Junior Member level 1
Joined
Feb 5, 2018
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
118
Can anyone please help me read decimal(just) values from a text file
my text is a.text :
Code:
3 4 14 3 24 5
my code is :

Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
`define Lenght 6
integer p,r,c;
    integer file,stat,out,i;
    reg [7:0] face[0:`Lenght-1];
    initial
        begin
            file=$fopen("a.txt","r");
            $display ("reading file....."); 
                        i=0;
            while (! $feof(file))
                begin
                    
                    stat=$fscanf(file,"%d\n",face[i]);
                            i=i+1;
                end
            $fclose(file);
             for(i=0;i<`Lenght;i=i+1) 
                begin  
                    $display("face[i]=%d",face[i]);
                end
        end


and my results is:
3
4
1
4
3
2
thanks
 

What are you using to run it?

I get the following results using both Vivado and Modelsim...
Code:
reading file.....
face[i]=  3
face[i]=  4
face[i]= 14
face[i]=  3
face[i]= 24
face[i]=  5

As this doesn't match your output shown, I suspect you are running the simulation with an older version of the file.
 
I get wrong result with ModelSim SE-64 10.5 .Which version do you use?
I check code with ISE2014 results are true.
 

Modelsim 10.5b and Vivado 2017.2
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…