危障的發生和解決方法
消除1-hazard的方法
1.首先先找出hazard發生的點
2.圈出hazard周圍最大的面積的1,3.得到a’b
4.把a’b加入f=a’c’+bc即可解除hazard
消除0-hazard的方法
先把卡諾圖f的0轉成1
f=a’c’+bc+a’b
再由卡諾圖得到f’
f'=ac'+bc'+ab'
把f’再反回來成為(f’)’
=>(f')'=(ac'+b'c+ab')’
=(ac’)’.(b’c)’.(ab’)’
=(a’+c).(b+c’).(a’+b)
=a’ba’+a’bb+a’c’a’+a’c’b+cba’+cbb+cc’a’+c’cb
得到的結果與消除1-hzazrd的方法一樣
=a’c’+bc+a’b
Hazard:
//CODE:
//1-HAZARD
module hazard(cout,a_bar,b,c);
input a_bar,b,c;
output cout;
wire w1,w2,c_bar;
and #5(w2,c,b);
not #5(c_bar,c);
and #5(w1,a_bar,c_bar);
or #5(cout,w1,w2);
endmodule
//消除hazard
module hazard(cout,a_bar,b,c);
input a_bar,b,c;
output cout;
wire w1,w2,w3,c_bar;
and #5(w2,c,b);
not #5(c_bar,c);
and #5(w1,a_bar,c_bar);
and #5(w3,a_bar,b);
or #5(cout,w1,w2,w3);
endmodule
系統時脈:
module top;
wire a_bar,b,c;
wire cout;
system_clock #200 clock1(a_bar);
system_clock #150 clock2(b);
system_clock #100 clock3(c);
hazard a1(cout,a_bar,b,c);
endmodule
//----------------------------------------
module system_clock(clk);
parameter PERIOD = 100;
output clk;
reg clk;
initial
clk = 0;
always
begin
#(PERIOD/2) clk = ~clk;
#(PERIOD/2) clk = ~clk;
#(PERIOD/2) clk = ~clk;
end
always@(posedge clk)
if($time > 1000) #(PERIOD-1)$stop;
endmodule
2008年11月17日 星期一
module Compare_2_str(A_lt_B,A_gt_B,A_eq_B,A0,A1,B0,B1);
input A0,A1,B0,B1;
output A_lt_B,A_gt_B,A_eq_B;
wire w1,w2,w3,w4,w5,w6,w7;
or(A_lt_B,w1,w2,w3);
nor(A_gt_B,A_lt_B,A_eq_B);
and(A_eq_B,w4,w5);
and(w1,w6,B1);
and(w2,w6,w7,B0);
and(w3,w7,B0,B1);
not(w6,A1);
not(w7,A0);
xnor(w4,A1,B1);
xnor(w5,A0,B0);
endmodule
input A0,A1,B0,B1;
output A_lt_B,A_gt_B,A_eq_B;
wire w1,w2,w3,w4,w5,w6,w7;
or(A_lt_B,w1,w2,w3);
nor(A_gt_B,A_lt_B,A_eq_B);
and(A_eq_B,w4,w5);
and(w1,w6,B1);
and(w2,w6,w7,B0);
and(w3,w7,B0,B1);
not(w6,A1);
not(w7,A0);
xnor(w4,A1,B1);
xnor(w5,A0,B0);
endmodule
2008年10月20日 星期一
AOI_4_Unit
module AOI_4_Unit(y_out,x_in1,x_in2,x_in3,x_in4);
input x_in1,x_in2,x_in3,x_in4;
output y_out;
reg y_out,y1,y2;//行為模式接線用reg
always
begin
#1 y1=x_in1 & x_in2;
#1 y2=x_in3 & x_in4;
#1 y_out=~(y1y2);
end
endmodule
/*
結構化模式:
module AOI_4_Unit(y_out,x_in1,x_in2,x_in3,x_in4);
input x_in1,x_in2,x_in3,x_in4;
output y_out;
wire y1,y2;
and #1 (y1,x_in1,x_in2);
and #1 (y2,x_in3,x_in4);
nor #1 (y_out,y1,y2);
end
endmodule
系統時脈:
module top;
wire x_in1,x_in2,x_in3,x_in4;//input
wire y_out;//output
system_clock #200 clock1(x_in1);
system_clock #150 clock2(x_in2);
system_clock #100 clock1(x_in3);
system_clock #50 clock2(x_in4);
//-------------------------------------------
module system_clock(clk);
parameter PERIOD = 100;
output clk;
reg clk;
initial
clk = 0;
always
begin
#(PERIOD/2) clk = ~clk;
#(PERIOD/2) clk = ~clk;
#(PERIOD/2) clk = ~clk;
#(PERIOD/2) clk = ~clk;
end
always@(posedge clk)
if($time > 1000) #(PERIOD-1)$stop;
endmodule
input x_in1,x_in2,x_in3,x_in4;
output y_out;
reg y_out,y1,y2;//行為模式接線用reg
always
begin
#1 y1=x_in1 & x_in2;
#1 y2=x_in3 & x_in4;
#1 y_out=~(y1y2);
end
endmodule
/*
結構化模式:
module AOI_4_Unit(y_out,x_in1,x_in2,x_in3,x_in4);
input x_in1,x_in2,x_in3,x_in4;
output y_out;
wire y1,y2;
and #1 (y1,x_in1,x_in2);
and #1 (y2,x_in3,x_in4);
nor #1 (y_out,y1,y2);
end
endmodule
系統時脈:
module top;
wire x_in1,x_in2,x_in3,x_in4;//input
wire y_out;//output
system_clock #200 clock1(x_in1);
system_clock #150 clock2(x_in2);
system_clock #100 clock1(x_in3);
system_clock #50 clock2(x_in4);
//-------------------------------------------
module system_clock(clk);
parameter PERIOD = 100;
output clk;
reg clk;
initial
clk = 0;
always
begin
#(PERIOD/2) clk = ~clk;
#(PERIOD/2) clk = ~clk;
#(PERIOD/2) clk = ~clk;
#(PERIOD/2) clk = ~clk;
end
always@(posedge clk)
if($time > 1000) #(PERIOD-1)$stop;
endmodule
2008年10月13日 星期一
p.9 Add_half
module Add-half (sum,c_out,a,b);
input a,b;
output sum,c_out;//declaration of port modes
wire c_out_bar;//內部接線 declaration of internal signal
//結構化模式 strutural module
xor(sum,a,b);
nand(c_out,bar,a,b);
not(c_out,c_out_bar);//instatiation of primitive gates
module top;
wire a,b;
wire sum,c_out;
system_clock #100 clock1(a);
system_clock #50 clock2(b);
Add_half AH1(sum,c_out,a,b);
endmodule
module system_clock(clk);
parameter PERIOD = 100;
output clk;
reg clk;
initial
clk = 0;
always
begin
#(PERIOD/2) clk = ~clk;
#(PERIOD/2) clk = ~clk;
end
always@(posedge clk)
if($time > 1000) #(PERIOD-1)$stop;
endmodule
input a,b;
output sum,c_out;//declaration of port modes
wire c_out_bar;//內部接線 declaration of internal signal
//結構化模式 strutural module
xor(sum,a,b);
nand(c_out,bar,a,b);
not(c_out,c_out_bar);//instatiation of primitive gates
module top;
wire a,b;
wire sum,c_out;
system_clock #100 clock1(a);
system_clock #50 clock2(b);
Add_half AH1(sum,c_out,a,b);
endmodule
module system_clock(clk);
parameter PERIOD = 100;
output clk;
reg clk;
initial
clk = 0;
always
begin
#(PERIOD/2) clk = ~clk;
#(PERIOD/2) clk = ~clk;
end
always@(posedge clk)
if($time > 1000) #(PERIOD-1)$stop;
endmodule
2008年10月6日 星期一
Design a verilog textbench
題目:
Design a verilog model
of a half adder and
write a testbench to
verify the designed
verilog model.
CODE:
module Add_half (sum,c_out,a,b);
input a,b;
output sum,c_out;
wire c_out_bar;
xor (sum,a,b);
nand(c_out_bar,a,b);
not(c_out,c_out_bar);
endmodule
Design a verilog model
of a half adder and
write a testbench to
verify the designed
verilog model.
CODE:
module Add_half (sum,c_out,a,b);
input a,b;
output sum,c_out;
wire c_out_bar;
xor (sum,a,b);
nand(c_out_bar,a,b);
not(c_out,c_out_bar);
endmodule
verilog code1
2008/10/6
Verilog code1


//code
module top;
wire a,b;
reg c;
system_clock #100 clock1(a);
system_clock#50 clock2(b);
always
#1 c=a&b;
endmodule
//text_bench
module system_clock(clk);
parameter PERIOD=100;
output clk;
reg clk;
initial
clk=0;
always
begin
#(PERIOD/2) clk = ~clk;
#(PERIOD/2) clk = ~clk;
end
always @ (posedge clk)
if($time>1000)#(PERIOD-1)$stop;
endmodule
module top;
wire a,b;
reg c;
system_clock #100 clock1(a);
system_clock#50 clock2(b);
always
#1 c=a&b;
endmodule
//text_bench
module system_clock(clk);
parameter PERIOD=100;
output clk;
reg clk;
initial
clk=0;
always
begin
#(PERIOD/2) clk = ~clk;
#(PERIOD/2) clk = ~clk;
end
always @ (posedge clk)
if($time>1000)#(PERIOD-1)$stop;
endmodule
code:
波形圖:
訂閱:
文章 (Atom)