现象:约束分频出来的时钟编译后:建立时间或保持时间违例。
原因:分频器关键路径过长。
解决方案:使用流水线优化。
XML
// 流水线化分频器
module pipelined_divider (
input wire clk_in,
input wire rst_n,
output reg clk_out
);
reg [7:0] counter_pipe1, counter_pipe2;
reg clk_out_pipe;
// 第一级流水线
always @(posedge clk_in or negedge rst_n) begin
if (!rst_n) begin
counter_pipe1 <= 0;
end else begin
counter_pipe1 <= counter_pipe1 + 1;
end
end
// 第二级流水线
always @(posedge clk_in or negedge rst_n) begin
if (!rst_n) begin
counter_pipe2 <= 0;
clk_out_pipe <= 0;
end else begin
counter_pipe2 <= counter_pipe1;
clk_out_pipe <= (counter_pipe2 == 255);
end
end
// 输出寄存器
always @(posedge clk_in or negedge rst_n) begin
if (!rst_n) begin
clk_out <= 0;
end else begin
clk_out <= clk_out_pipe;
end
end
endmodule