Build a decade counter that counts from 0 through 9, inclusive, with a period of 10. The reset input is synchronous, and should reset the counter to 0. We want to be able to pause the counter rather than always incrementing every clock cycle, so the slowena input indicates when the counter should increment.、

module top_module (
input clk,
input slowena,
input reset,
output [3:0] q);
always@ (posedge clk)
if(reset)
q <= 4'd0;
else if(q == 4'd9 && slowena == 1'b1)
q <= 4'd0;
else if(slowena == 1'b1)
q <= q + 1'b1;
else q <= q;
endmodule
该模块创建了一个从0到9的计数器,具有10的周期。当接收到同步重置信号时,计数器复位为0。慢速使能输入(slowena)控制计数器是否递增,仅在slowena为高时,计数器在每个时钟周期才会增加。否则,计数器保持当前状态。
7581

被折叠的 条评论
为什么被折叠?



