码迷,mamicode.com
首页 > 其他好文 > 详细

[Verilog]任意整数(奇数,整数)分频器设计, 50%占空比

时间:2014-07-31 09:50:36      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:fpga verilog

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

[Verilog]任意整数(奇数,整数)分频器设计, 50%占空比,布布扣,bubuko.com

[Verilog]任意整数(奇数,整数)分频器设计, 50%占空比

标签:fpga verilog

原文地址:http://blog.csdn.net/yrj/article/details/38311449

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!