Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Multiple Image read in testbench

Status
Not open for further replies.

kissmoh

Junior Member level 1
Junior Member level 1
Joined
Jan 17, 2013
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,443
hi

im trying to make an image processor using virtex5, and im using modelsim for simulation tool.
my question is,

in testbench file, how to read multiple sequential images?
i can open and read 1 frame image but dont know how to do when the next frame is needed.


this is part of my test bench code

....


Code VHDL - [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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
initial begin
        // Initialize Inputs
        nRESET = 0;
        CL0_CLK = 0;
        CL0_DATA = 0;
        IN_SW1 = 1;
        
 
        read_image_point = $fopen("address/a.raw","rb+");
        read_image_point2 = $fread(read_reg, read_image_point);     
        write_image_point = $fopen("address/b.raw","wb+");
        ...
        
        // Wait 100 ns for global reset to finish
        #100;
      nRESET = 1;
        // Add stimulus here
    end
    
    always begin
      #20 CL0_CLK <= ~CL0_CLK;                                      //25MHz
    end
 
 
 
    
    always@(posedge CL0_CLK or negedge nRESET) begin                                                // CL0_DATA : 2 latency
        
        if(!nRESET) begin           
            ...
            read_count <= 0;
            read_data <= 0;
            ...
        end
        
        else begin
            
            if(DVAL) begin  
                
                if(read_count == width*height - 1)  begin   
                    
                    read_data <= read_reg[read_count];
                    ...
                    read_count <= 0;
                end
                
                else begin
                    
                    read_data <= read_reg[read_count];                                          
                    ... 
                    read_count <= read_count + 1'b1;
                end
            end
            
            else begin
                
            ...
            end
        end
    end

 
Last edited:

Not exactly sure what you want to do.

Are you trying to open a different file for each frame? You could make the file names something like file1.dat file2.dat file3.dat etc. and build the file name up using strings so you would have something like:
Code:
module temp;
  integer i;
  integer file;

  initial begin
    for (i=0;i<4;i=i+1) begin
      file = $fopen({"file", i+48, ".dat"}, "w");
      $fwrite (file, "%d\n", i);
      $fclose (file);
    end
  end

endmodule


Regards
 
yes, different files are needed for next frame.
it seems what i wanted, i didnt know that the '{}' is can be used like that way,
ty, i'll try it
 
Last edited:

i tried it but the 'i+48'(is there any reason for adding 48?) couldnt be recognized as string,

so i used $sformat,

Code:
integer cnt = 2;
string_0 = "addr";	
string_1 = ".raw";	
$sformat (string_cnt,"%s",cnt);
$sformat (string,"%s%s%s",string_0,cnt,string_1);

like this and it worked
 
Last edited by a moderator:

48 is the ASCII code for the number 0. The code I posted worked using Vivado's xsim.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top