Advertisement
kekellner

Lab09 - Ej01 - Código y Testbench

Nov 7th, 2021
2,407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module contador (input clk, reset, en, load, input [3:0] loadValue, output reg [3:0] Q);
  2.  
  3.     always @ (posedge clk or posedge reset) begin
  4.         if (reset)
  5.             Q <= 4'b0000;
  6.         else if (load)
  7.             Q <= loadValue;
  8.         else if (en)
  9.             Q <= Q + 1;
  10.     end
  11.  
  12. endmodule
  13.  
  14. /*
  15. module testbench();
  16.  
  17.     reg clk, reset, en, load;
  18.     reg [3:0] loadValue;
  19.     wire [3:0] Q;
  20.  
  21.     contador U1(clk, reset, en, load, loadValue, Q);
  22.  
  23.     initial begin
  24.         clk = 0; reset = 0; en = 0; load = 0; loadValue = 4'b0000;
  25.         #2
  26.         reset = 1;
  27.         #1
  28.         reset = 0;
  29.         #10
  30.         en = 1;
  31.         #50
  32.         loadValue = 4'b1100;
  33.         load = 1;
  34.         #10
  35.         load = 0;
  36.         #50
  37.         en = 0;
  38.     end
  39.  
  40.     initial
  41.         #150 $finish;
  42.  
  43.     initial begin
  44.         $dumpfile("timing.vcd");
  45.         $dumpvars(0, testbench);
  46.     end
  47.  
  48.     always
  49.         #5 clk = ~clk;
  50.  
  51. endmodule
  52. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement