题解 | #时钟分频(偶数)#
时钟分频(偶数)
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
);
//*************code***********//
//级联触发器就行,不用想的太复杂。
reg clk_out2_r,clk_out4_r,clk_out8_r;
assign clk_out2 = clk_out2_r ;
assign clk_out4 = clk_out4_r;
assign clk_out8 = clk_out8_r;
//先来个二分频
always@(posedge clk_in or negedge rst)begin
if(~rst)begin
clk_out2_r <= 0;
end
else begin
clk_out2_r <= ~clk_out2_r;
end
end
always@(posedge clk_out2_r or negedge rst)begin
if(~rst)begin
clk_out4_r <= 0;
end
else begin
clk_out4_r <= ~clk_out4_r;
end
end
always@(posedge clk_out4_r or negedge rst)begin
if(~rst)begin
clk_out8_r <= 0;
end
else begin
clk_out8_r <= ~clk_out8_r;
end
end
//*************code***********//
endmodule
做法很多,可能是这几天刷题刷呆了,第一想法居然是用三个计数器,后面改成一个计数器,再后面发现不用计数器也行,呆了呆了,要观察出规律,多思考,多思考。
