xianyufpga

要求:

  用 Verilog 实现 glitch free 时钟切换电路。输入 sel,clka,clkb,sel 为 1 输出 clka,sel 为 0 输出 clkb。

module Change_Clk_Source
(
    input   rst_n,
    input   clk_a,
    input   clk_b,
    input   sel,
    output  clk_o
);

 

一、有毛刺写法

assign clk_o = sel ? clk_a : clk_b;

 

二、两个时钟是倍数关系

reg clk_a_vld;
reg clk_b_vld;

always @(negedge clk_a or negedge rst_n)begin
    if(!rst_n)begin
        clk_a_vld <= 0;
    end
    else begin
        clk_a_vld <= sel & ~clk_b_vld;
    end
end

always @(negedge clk_b or negedge rst_n)begin
    if(!rst_n)begin
        clk_b_vld <= 0;
    end
    else begin
        clk_b_vld <= ~sel & ~clk_a_vld;
    end
end

assign clk_o = (clk_a_vld & clk_a) | (clk_b_vld & clk_b);

 

三、两个时钟是异步关系

reg clk_a_vld;
reg clk_b_vld;
reg clk_a_vld_r;
reg clk_b_vld_r;

always @(posedge clk_a or negedge rst_n)begin
    if(!rst_n)begin
        clk_a_vld   <= 0;
        clk_a_vld_r <= 0;
    end
    else begin
        clk_a_vld   <= sel & ~clk_b_vld_r;
        clk_a_vld_r <= clk_a_vld;
    end
end

always @(posedge clk_b or negedge rst_n)begin
    if(rst_n == 1\'b0)begin
        clk_b_vld   <= 0;
        clk_b_vld_r <= 0;
    end
    else begin
        clk_b_vld   <= ~sel & ~clk_a_vld_r;
        clk_b_vld_r <= clk_b_vld;
    end
end

assign clk_o = (clk_a_vld_r & clk_a) | (clk_b_vld_r & clk_b);

endmodule

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-09-23
  • 2022-12-23
  • 2021-07-08
  • 2021-11-14
  • 2021-10-16
  • 2021-10-16
  • 2021-12-27
猜你喜欢
  • 2021-10-16
  • 2021-12-27
  • 2021-06-10
  • 2021-08-28
  • 2021-12-15
  • 2021-07-04
  • 2021-11-30
相关资源
相似解决方案