您的位置:首页 > 其它

数字电路设计之低功耗设计方法五:门控

2014-06-30 12:57 465 查看
Clock-gating:在时钟频率加快的同时,有时候会产生不必要的跳转。有的时候输入并没有改变,但是由于时钟的跳转,寄存器的值会被一遍一遍的刷新。可能输入才更改一次,结果时钟已经跳了几万次,这样的差距是可怕的。每次时钟上升沿,输出就要重新计算一遍,这样带来的功耗是巨大的。如果使用门控的话,我们就可以增加一个逻辑,就是只有在满足某种条件之下,时钟的上升沿才会对使得整个电路重新计算。(比如这个条件就是输入发生变化)这样的话就可大大降低功耗。

没有门控的代码:

module clock(

a,

b,

c,

clock,

rst

);

input wire clock;

input wire rst;

input wire [31:0]a;

input wire [31:0]b;

output reg [63:0]c;

always@(posedge clock,posedge rst)

begin

if(rst)

c = 0;

else

c = a*b + a + b;

end

endmodule

有门控的代码:

module clk_gating(

clk,

a,

b,

c,

clr

);

input wire [31:0]a;

input wire [31:0]b;

input wire clk;

input wire clr;

output reg [63:0]c;

reg [31:0]temp_a;

reg [31:0]temp_b;

wire gating;

assign gating = (temp_a==a) & (temp_b==b);

always@(posedge clk,posedge clr)

begin

if(clr)

begin

temp_a <= 0;

temp_b <= 0;

end

else

begin

temp_a <= a;

temp_b <= b;

end

end

always@(posedge clr,posedge clk)

begin

if(clr)

c <= 0;

else if(clk&(~gating))

c <= a*b + a + b;

else;

end

endmodule

仿真代码:

module test;

// Inputs

reg [31:0] a;

reg [31:0] b;

reg clock;

reg rst;

// Outputs

wire [63:0] c;

// Instantiate the Unit Under Test (UUT)

clock uut (

.a(a),

.b(b),

.c(c),

.clock(clock),

.rst(rst)

);

always #1 clock = ~clock;

parameter DELAY = 200;

integer k;

initial begin

// Initialize Inputs

$dumpfile("clock.vcd");

$dumpvars(1,test.uut);

a = 0;

b = 0;

rst = 1;

clock = 0;

#100;

rst = 0;

// Wait 200 ns for global reset to finish

for(k = 0;k < 100;k=k+1)

begin

a <= ~a;

b <= ~b;

#DELAY;

end

// Add stimulus here

$finish;

end



endmodule
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: