中心思想:
利用计数器生成目标频率的一半的两个正交相位时钟,然后通过上升沿和下降沿采样后异或得到输出频率
module freq_div #(
parameter N = 7
) (
input clk,
input rst_n,
output clk_out
);
//counter
reg [3:0] cnt ;
always @(posedge clk or negedge rst_n) begin
if (~rst_n) begin
cnt <= 0;
end else if (cnt == 13) begin
cnt <= 0;
end else begin
cnt <= cnt +1;
end
end
//
reg div1, div2;
assign tff_en1 = (cnt < 7) ? 1 : 0;
assign tff_en2 = ((3 < cnt) && (cnt < 11) )? 1 : 0;
always @(posedge clk ) begin
if (~rst_n) begin
div1 <= 0;
end else begin
div1 <= ~tff_en1 ;
end
end
always @(negedge clk ) begin
if (~rst_n) begin
div2 <= 0;
end else begin
div2 <= t