Advertisement
1WaKa_WaKa1

count_free_tb

Apr 6th, 2023
1,189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `timescale 1ns / 1ps
  2.  
  3. module count_free_tb;
  4.  
  5. reg clock, reset, start_req, start_data, ready;
  6. wire res_resp, busy;
  7.  
  8. reg [31:0] time_to_start;
  9.  
  10. count_free cfree(
  11.     .clk(clock),
  12.     .rst(reset),
  13.     .start_req_i(start_req),
  14.     .start_data_i(start_data),
  15.     .ready_i(ready),
  16.     .result_rsp_o(res_resp),
  17.     .busy_o(busy)
  18. );
  19.  
  20. integer i;
  21.  
  22. initial begin
  23.     i = 0;
  24.    
  25.     start_req = 0;
  26.     start_data = 0;
  27.     ready = 0;
  28.     clock = 0;
  29.    
  30.     reset = 1;    
  31.     #5 clock = ~clock;
  32.     #5 reset = 0;
  33.     #5 clock = ~clock;
  34.     #5
  35.    
  36.     while (!res_resp) begin
  37.         i = i + 1;
  38.        
  39.         if (i == 15) begin
  40.             time_to_start = i;
  41.             start_req = 1;
  42.         end
  43.        
  44.         if (start_req && i != 15) begin
  45.             if (time_to_start != 0) begin
  46.                 start_data <= time_to_start[0];
  47.                 time_to_start <= time_to_start >> 1;
  48.             end else begin
  49.                 start_req = 0;
  50.                 start_data = 0;
  51.             end
  52.         end
  53.        
  54.         if (cfree.count_of_ticks == 15) begin
  55.             ready = 1;
  56.         end else begin
  57.             ready = 0;
  58.         end
  59.        
  60.         $display("Current state: %d", cfree.state);
  61.         $display("Cur data to send: %b", time_to_start);  
  62.         $display("Read data: %d", cfree.data);
  63.         $display("--------------------------------");
  64.  
  65.         #5 clock = ~clock;
  66.         #5 clock = ~clock;
  67.     end
  68.    
  69.    
  70.     $display("Read data: %d", cfree.data);
  71.     $stop;
  72. end
  73. endmodule
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement