我正在为我的设计中的一些 latch 和逻辑提供时钟。我在合成和地方方面没有太多经验。路线。在RTL中实现时钟门控的正确方法是什么?
例1:
always_comb begin
gated_clk = clk & latch_update_en;
end
always_latch begin
if(gated_clk) begin
latch_data <= new_data;
end
end
例2: 在对RTL时钟门控的良好实践进行一些研究时,我偶然发现了一个RTL示例。该示例实现了上述代码:
clock_gator cg_cell (.clk(clk), .en(latch_update_en), .scan_en(scan_en_in), .gated_clk(gated_clk));
always_latch begin
if(gated_clk) begin
latch_data <= new_data;
end
end
使用自定义时钟门控单元的目的是什么?如果clk在带有另一个使能信号的always_comb块中直接“和”处理,那么该工具是否在合成中有困难时间?我感觉使用特殊时钟门控单元是生成门控时钟信号的标准方法。我试图理解为什么会这样。
答案 0 :(得分:12)
时钟门控信号应仅在闩锁闭合时切换,否则可能出现毛刺和亚稳态问题。对于有效的高锁存器,门控信号应在时钟的下降沿切换。有源低锁存器的上升沿。
通常情况下,边缘敏感的触发器会保持latch_update_en
以防止门控信号上的噪声。
always_ff @(negedge clk)
latch_update_en <= next_latch_update_en;
always_comb
gated_clk = (* clock_gating = "clk" *) clk & latch_update_en;
always_latch
if(gated_clk)
latch_data <= new_data;
提醒:如果你只有一个锁存器设计:边沿触发器只是主/从锁存器
always_latch
if (clk)
sync_latch_update_en <= next_latch_update_en;
always_latch
if (!clk)
latch_update_en <= sync_latch_update_en;
大多数综合确实存在直接和时钟相关的问题。如何使用门控并不总是直观的。合成器通常在库中有许多AND门可供选择,每个都有不同的转换,偏斜和加载,非常适合输入组合。虽然功能相同,A & B
会得到不同的时间结果B & A
。
从合成器库中实例化显式单元格可以缩小知道和预期行为的可能性。预定义的时钟门控单元还具有合成器使用的属性。属性包括用于平衡时钟树的时序信息(用于管理负载和寄生的设计中的缓冲器放置)。
某些合成器支持在RTL中设置属性标记(例如:// synthesis attributes
或(* attributes *)
),而不需要显式实例化单元格。这里没有标准,请参阅您的用户手册。
自定义单元格是合成库中的每个定义单元格,具有已知的时序信息,负载平衡和其他属性。有了这些信息,合成器就知道在时钟树中添加或校准缓冲延迟的位置和方法。这样可以确保非门控触发器在门控翻转之前没有看到时钟边沿。
_____ _____
IN -------------|D Q|-----|D Q|--- OUT
| | | |
|\ |\ | | | |
+-| >| >---|> | +-|> |
| |/ |/ |_____| | |_____|
| ___ |
CLK -+-| \ |
| & )-------------+ BALANCED CLOCK : correct data sampled
GATE --|___/
如果没有指导,门控翻牌可以获得延迟时钟。偏斜会导致错误的数据被采样。
_____ _____
IN -------------|D Q|-----|D Q|--- OUT
| | | |
| | | |
+----------|> | +-|> |
| |_____| | |_____|
| ___ |
CLK -+-| \ |\ |\ |
| & )---| >| >----+ UNBALANCED CLOCK : wrong data sampled
GATE --|___/ |/ |/
答案 1 :(得分:0)
阅读Yu-Yun Dai thesis : Verification and Synthesis of Clock-Gated Circuits,其中说:
时钟门控电路的顺序等效检查(SEC)为 必填
此外,尝试粘贴代码的https://github.com/YosysHQ/yosys-bigsim/blob/master/openmsp430/rtl/omsp_clock_gate.v如下:
//----------------------------------------------------------------------------
// Copyright (C) 2009 , Olivier Girard
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of the authors nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
// THE POSSIBILITY OF SUCH DAMAGE
//
//----------------------------------------------------------------------------
//
// *File Name: omsp_clock_gate.v
//
// *Module Description:
// Generic clock gate cell for the openMSP430
//
// *Author(s):
// - Olivier Girard, olgirard@gmail.com
//
//----------------------------------------------------------------------------
// $Rev: 103 $
// $LastChangedBy: olivier.girard $
// $LastChangedDate: 2011-03-05 15:44:48 +0100 (Sat, 05 Mar 2011) $
//----------------------------------------------------------------------------
module omsp_clock_gate (
// OUTPUTs
gclk, // Gated clock
// INPUTs
clk, // Clock
enable, // Clock enable
scan_enable // Scan enable (active during scan shifting)
);
// OUTPUTs
//=========
output gclk; // Gated clock
// INPUTs
//=========
input clk; // Clock
input enable; // Clock enable
input scan_enable; // Scan enable (active during scan shifting)
//=============================================================================
// CLOCK GATE: LATCH + AND
//=============================================================================
// Enable clock gate during scan shift
// (the gate itself is checked with the scan capture cycle)
wire enable_in = (enable | scan_enable);
// LATCH the enable signal
reg enable_latch;
always @(clk or enable_in)
if (~clk)
enable_latch <= enable_in;
// AND gate
assign gclk = (clk & enable_latch);
endmodule // omsp_clock_gate