Advertisement
Guest User

CA-L5

a guest
Oct 25th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ================================================================================
  2. =[filename] cnt.v===============================================================
  3. ================================================================================
  4.  
  5. module cnt #(
  6.   parameter w = 3
  7. )(
  8.   input clk,
  9.   input clr,
  10.   input c_up,
  11.   input neg,
  12.   output reg [w-1:0] q
  13. );
  14.  
  15. always @ (posedge clk)
  16.   if (clr)
  17.     q <= {w{1'd1}};
  18.   else if (neg)
  19.     q <= ~q;
  20.   else if (c_up)
  21.     q <= q+1;
  22.  
  23. endmodule
  24.  
  25. ================================================================================
  26. =[filename] cnt_tb.v============================================================
  27. ================================================================================
  28.  
  29.  
  30. module cnt_tb(
  31.   output reg clk, clr, c_up, neg,
  32.   output [3:0] q
  33. );
  34.  
  35. cnt #(
  36.   .w(4)
  37. )   con1 (
  38.       .clk(clk),
  39.       .clr(clr),
  40.       .c_up(c_up),
  41.       .neg(neg)
  42. );  
  43.  
  44. initial begin
  45.   clk = 1'd0;
  46.   forever #25 clk = ~clk;
  47. end
  48.  
  49. initial begin
  50.   clr = 1'd1;
  51.   c_up = 1'd1;
  52.   neg = 1'd0;
  53.   #50 clr = 1'd0;
  54.   #50 neg = 1'd1;
  55.   #50 neg = 1'd0;
  56.   #50 clr = 1'd1;
  57.   #50 clr = 1'd0;
  58. end
  59. endmodule
  60.  
  61. ================================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement