题解 | #时钟分频(偶数)#
时钟分频(偶数)
https://www.nowcoder.com/practice/49a7277c203a4ddd956fa385e687a72e
`timescale 1ns/1ns
module even_div
(
input wire rst ,
input wire clk_in,
output wire clk_out2,
output wire clk_out4,
output wire clk_out8
);
reg [2:0] clk_cnt;
//有题目的波形图可知,复位后从0直接跳变到了111
//因此该计数器的逻辑是-1,而不是+1
always@(posedge clk_in or negedge rst)begin
if(!rst)
clk_cnt <= 1'b0;
else
clk_cnt <= clk_cnt - 1'b1;
end
assign clk_out2 = clk_cnt[0];
assign clk_out4 = clk_cnt[1];
assign clk_out8 = clk_cnt[2];
endmodule

查看8道真题和解析