首页 > 代码库 > [Verilog]任意整数(奇数,整数)分频器设计, 50%占空比
[Verilog]任意整数(奇数,整数)分频器设计, 50%占空比
module div_clk(clk_in, divisor, clk_out);
input clk_in;input divisor;
output clk_out;
reg clk_out = 0;
wire clk_in;
reg [7 : 0] count = 0;
wire [7 : 0] divisor;
wire odd;
assign odd = divisor & 1;
always @(clk_in)
begin
if (count == 0 && clk_in)
clk_out = 1;
else if (count == ((divisor >> 1) + odd) && (odd == !clk_in))
clk_out = 0;
if (clk_in)
begin
count = count + 1;
if (count >= divisor)
count = 0;
end
end
endmodule
TestBench:
module div_tb;
reg clk_in;
wire clk_out;
initial
begin
#0 clk_in = 1;
#10 clk_in = 0;
#10 clk_in = 1;
#10 clk_in = 1;
#10 clk_in = 0;
#10 clk_in = 1;
#10 clk_in = 0;
#10 clk_in = 1;
#10 clk_in = 0;
#10 clk_in = 1;
#10 clk_in = 0;
10 clk_in = 1;
#10 clk_in = 0;
10 clk_in = 1;
#10 clk_in = 0;
#10 clk_in = 1;
#10 clk_in = 0;
#10 clk_in = 1;
#10 clk_in = 0;
#10 clk_in = 1;
#10 clk_in = 0;
#10 clk_in = 1;
#10 clk_in = 0;
#10 clk_in = 1;
#10 clk_in = 0;
#10 clk_in = 1;
#10 clk_in = 0;
#10 clk_in = 1;
#10 clk_in = 0;
#10 clk_in = 1;
#10 clk_in = 0;
#10 clk_in = 1;
end
wire [7 : 0] divisor = 3;
div_clk dc(.clk_in(clk_in),.clk_out(clk_out), .divisor(divisor));
endmodule
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。