1

I'm generating frames from a video file, which I then read from my testbench. What I'm doing so far is to load the same memory "mem" with different memory image file every time the task is called, which works perfectly fine:

task play_frame(input [31:0] total_pixels, input [12:0] pic_num);  
begin
    @(posedge clk);
    case (pic_num)
        0: $readmemh("img_data/1920x1080/video_frame_1.mem", mem); 
        1: $readmemh("img_data/1920x1080/video_frame_2.mem", mem); 
        2: $readmemh("img_data/1920x1080/video_frame_3.mem", mem);
        ...
        ...
        ...

    endcase

    repeat (total_pixels) begin
        .
        .
        .
    end
    end
endtask

Now the problem is that I want to call this task 1000 times. Which means that I have to write down for each case the name of the file that I want to load into the memory mem_s.

Is there a way to automate this?

Maybe something like:

task play_frame(input [31:0] total_pixels, input [12:0] pic_num);  
begin
    @(posedge clk);
     $readmemh("img_data/1920x1080/video_frame_*$(pic_num)*.mem", mem);

    repeat (total_pixels) begin
        .
        .
        .
    end
    end
endtask
perror
  • 7,071
  • 16
  • 58
  • 85
Goled
  • 13
  • 3

1 Answers1

3

Use $sformatf

 $readmemh($sformatf("img_data/1920x1080/video_frame_%0d.mem",pic_num), mem);
dave_59
  • 39,096
  • 3
  • 24
  • 63