|
本帖最后由 lcytms 于 2016-11-9 19:29 编辑
新建通用分频模块div_freq.v
将通用分频模块div_freq.v设置为顶层模块。
module div_freq (clk, rst_n, clk_out);
input clk, rst_n;
output reg clk_out;
parameter HW = 50,
LW = 50; // HW + LW = 100 times
reg state;
localparam s0 = 1'b0,
s1 = 1'b1;
reg [25:0] cnt;
always @ (posedge clk or negedge rst_n)
begin
if (!rst_n)
begin
cnt <= 0;
clk_out <= 1;
state <= s0;
end
else
begin
case (state)
s0 : begin // HW part
if (cnt < HW - 1)
begin
cnt <= cnt + 26'b1;
clk_out <= 1;
state <= s0;
end
else
begin
cnt <= 0;
clk_out <= 1;
state <= s1;
end
end
s1 : begin // LW part
if (cnt < LW - 1)
begin
cnt <= cnt + 26'b1;
clk_out <= 0;
state <= s1;
end
else
begin
cnt <= 0;
clk_out <= 0;
state <= s0;
end
end
default : state <= s0;
endcase
end
end
endmodule
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?我要注册
x
|