Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ================================================================================
- =[filename] cnt.v===============================================================
- ================================================================================
- module cnt #(
- parameter w = 3
- )(
- input clk,
- input clr,
- input c_up,
- input neg,
- output reg [w-1:0] q
- );
- always @ (posedge clk)
- if (clr)
- q <= {w{1'd1}};
- else if (neg)
- q <= ~q;
- else if (c_up)
- q <= q+1;
- endmodule
- ================================================================================
- =[filename] cnt_tb.v============================================================
- ================================================================================
- module cnt_tb(
- output reg clk, clr, c_up, neg,
- output [3:0] q
- );
- cnt #(
- .w(4)
- ) con1 (
- .clk(clk),
- .clr(clr),
- .c_up(c_up),
- .neg(neg)
- );
- initial begin
- clk = 1'd0;
- forever #25 clk = ~clk;
- end
- initial begin
- clr = 1'd1;
- c_up = 1'd1;
- neg = 1'd0;
- #50 clr = 1'd0;
- #50 neg = 1'd1;
- #50 neg = 1'd0;
- #50 clr = 1'd1;
- #50 clr = 1'd0;
- end
- endmodule
- ================================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement