集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 2191|回复: 5

Altera推荐的 Verilog HDL Clock Multiplexing Design to Avoid Glitches

[复制链接]
陈飞龙 发表于 2017-10-31 20:40:03 | 显示全部楼层 |阅读模式
module clock_mux (clk,clk_select,clk_out);
parameter num_clocks = 4;
input [num_clocks-1:0] clk;
input [num_clocks-1:0] clk_select; // one hot
output clk_out;
genvar i;
reg [num_clocks-1:0] ena_r0;
reg [num_clocks-1:0] ena_r1;
reg [num_clocks-1:0] ena_r2;
wire [num_clocks-1:0] qualified_sel;
// A look-up-table (LUT) can glitch when multiple inputs
// change simultaneously. Use the keep attribute to
// insert a hard logic cell buffer and prevent
// the unrelated clocks from appearing on the same LUT.
wire [num_clocks-1:0] gated_clks /* synthesis keep */;
initial begin
ena_r0 = 0;
ena_r1 = 0;
ena_r2 = 0;
end
generate
for (i=0; i<num_clocks; i=i+1)
begin : lp0
wire [num_clocks-1:0] tmp_mask;
assign tmp_mask = {num_clocks{1'b1}} ^ (1 << i);
assign qualified_sel[i] = clk_select[i] & (~|(ena_r2 & tmp_mask));
always @(posedge clk[i]) begin
ena_r0[i] <= qualified_sel[i];
ena_r1[i] <= ena_r0[i];
end
always @(negedge clk[i]) begin
ena_r2[i] <= ena_r1[i];
end
assign gated_clks[i] = clk[i] & ena_r2[i];
end
endgenerate
// These will not exhibit simultaneous toggle by construction
assign clk_out = |gated_clks;
endmodule
 楼主| 陈飞龙 发表于 2017-10-31 20:40:22 | 显示全部楼层
循环设计避免毛刺
芙蓉王 发表于 2017-11-1 09:03:21 | 显示全部楼层
Altera推荐的 Verilog HDL Clock Multiplexing Design to Avoid Glitches
zhangyukun 发表于 2017-11-1 09:32:11 | 显示全部楼层
Altera推荐的 Verilog HDL Clock Multiplexing Design to Avoid Glitches
晓灰灰 发表于 2017-11-1 13:46:27 | 显示全部楼层
endgenerate
fpga_feixiang 发表于 2017-11-1 16:34:42 | 显示全部楼层
不错,谢谢分享~~~~~~~~~~
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|fpga论坛|fpga设计论坛 ( 京ICP备20003123号-1 )

GMT+8, 2025-5-3 06:09 , Processed in 0.062376 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表