|
发表于 2021-7-19 19:05:14
|
显示全部楼层
module upDownCounter ( input clk,
input rst_n,
output reg [ 2 : 0 ] counterOut );
reg up, down;
always @( * ) begin
up <= ~|counterOut;
down <= ~&counterOut;
end
always @( posedge clk or negedge rst_n ) begin
if( ! rst_n ) begin
counterOut <= 3'b000;
end
else begin
case( { up, down } )
2'b01: counterOut <= counterOut - 1'b1;
2'b10: counterOut <= counterOut + 1'b1;
default: counterOut <= counterOut;
endcase
end
end
endmodule |
|