用verilog hdl编写同步模5计数器程序,有进位输出和异步复位端

用verilog hdl编写同步模5计数器程序,有进位输出和异步复位端,第1张

module test_cnt5(clk,reset,car,out)

input clk,reset//reset为异步复位信毁喊悔号

output car,out/渗衡/car为进位信号

reg[2:0]cnt//cnt为计数器

reg car

wire[2:0]out

assign out=cnt

always@(posedge clk or negedge reset)

begin

if(!reset)begin

cnt<=3'b000

car<=0

end

else begin

if(cnt==3'b100)begin

car<=3'b001

cnt<=3'b000

end

else begin

cnt<=cnt+3'b001

car<纤正=3'b000

end

end

end

endmodule

module CNT10 (CLK, RST, EN, CQ, COUT)

input CLK,RST,EN

output[3:0] CQ

output COUT

reg[3:0] CQ,CQI

reg COUT

always @(posedge CLK)//好锋检测时钟上升沿

begin : u1

if (RST == 1'b1)//计数器复位友颂晌

begin

CQI={4{1'b0}}

end

begin

if(EN==1'b1)//检测是否允许计数

begin

if (CQI<9)

begin

CQI=CQI+1//允许计数

end

else

begin

CQI={4{1'b0}}//大于9,计数值清零

end

end

end

if (CQI==9)

begin

COUT<=1'b1 //计数大于9,输出进位信号

end

else

begin

COUT<=1'b0

end

CQ<=CQI //将计数值樱兄向端口输出

end

endmodule


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12313841.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存