2008年12月15日 星期一

vlog


module top;
wire a,b,c,d,f;
system_clock #400 clock(a);
system_clock #200 clock(b);
system_clock #100 clock(c);
system_clock #50 clock(d);
unit u1(f,a,b,c,d);
endmodule


module unit(f,a,b,c,d);
input a,b,c,d;
output f;
wire w1,w2,w3;
wire a_bar,b_bar,c_bar,d_bar;
not (a_bar,a);
not (b_bar,b);
not (c_bar,c);
not (d_bar,d);


and (w1,a_bar,b_bar,d);
and (w2,b,d_bar);
and (w3,a,b_bar,c);

or (f,w1,w2,w3);
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年12月8日 星期一

冷!

天氣好冷
沒長袖只有短袖能穿
冷死人

2008年11月24日 星期一

電路危障

If a circuit has a hazard it could exhibit a glitch certain conditions.

2008年11月17日 星期一

2位元比較器行為模式:

2位元比較器行為模式:

module compare_2_algo(A_lt_B,A_gt_B,A_eq_B);
input [1:0] A,B; //四位元則改成[3:0]
output
reg A_lt_B,A_gt_B,A_eq_B;
always@(A or B)
begin
A_lt_B=0;
A_gt_B=0;
A_eq_B=0;
if (A==B) A_eq_B=1;
else if (A>B) A_gt_B=1;
else A_lt_B=1;
end
endmodule

2位元比較器

module compare_2_str(A_lt_B,A_gt_b,A_eq_B,A0,A1,Bo,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




Verilog RTL model (Register Transfer Level):

module compare_2a(A_lt_B,A_gt_b,A_eq_B,A0,A1,Bo,B1);
input A0,A1,B0,B1;
output A_lt_B,A_gt_B,A_eq_B;
assign A_lt_B=(~A1)&B1(A1)&(~A0)&B0(~A0)&B1B0;

assign A_gt_B=A1&(B1)A0&(~B1)&(~B0)A1&A0&(~B0);
assign A_eq_B=......;
endmodule

2008年11月2日 星期日

陳珮容你有種!

每次都在期中期末的時候才要吵我!下禮拜換我去中壢找你玩!咱們不醉不歸阿!

2008年10月27日 星期一

1位元全加法器


module top;
wire a,b,c_in;
wire sum,c_out;
system_clock #100 clock1(a);
system_clock #200 clock2(b);
system_clock #400 clock3(c_in);
test AH1(sum,c_out,a,b,c_in);

endmodule

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

module test(sum,c_out,a,b,c_in);
input a,b,c_in;
output sum,c_out;
wire w1,w2,w3;
add_half M1(w1,w2,a,b);
add_half M2(sum,w3,w1,c_in);
or (c_out,w2,w3);
endmodule

module system_clock(clk);
parameter PERIOD = 100;
output clk;
reg clk;
initial
clk = 0;
always
begin
#(PERIOD/3) clk = ~clk;
#(PERIOD/3) clk = ~clk;
#(PERIOD/3) clk = ~clk;

end
always@(posedge clk)
if($time > 1000) #(PERIOD-1)$stop;
endmodule

2008年10月20日 星期一

practice5




module top;
wire x_in1,x_in2,x_in3,x_in4;
wire y_out;
system_clock #100 clock1(x_in1);
system_clock #200 clock2(x_in2);
system_clock #400 clock3(x_in3);
system_clock #800 clock4(x_in4);
test AH1(y_out,x_in1,x_in2,x_in3,x_in4);

endmodule

module test(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);
endmodule

module system_clock(clk);
parameter PERIOD = 100;
output clk;
reg clk;
initial
clk = 0;
always
begin
#(PERIOD/4) clk = ~clk;
#(PERIOD/4) clk = ~clk;
#(PERIOD/4) clk = ~clk;
#(PERIOD/4) clk = ~clk;
end
always@(posedge clk)
if($time > 1000) #(PERIOD-1)$stop;
endmodule

2008年10月13日 星期一

PRACTICE4-全加法器

module Add_full(sum,c_out,a,b,c_in);

input a,b,c_in;
output sum_c_out;
wire w1,w2,w3;

Add_half M1(w1,w2,a,b);
Add_half M2(sum,w3,w1,c_in);
or (c_out,w2,w3);

endmodule;

練習3-半加法器

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 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


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日 星期一

課堂練習2

題目:Design a verilog model of a adder and write a testbench to verify the designed verilog model


p.q:
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

練習

上禮拜練習的作業
今天上課又練習了一次
發現寫程式真的要很細心
少一個分號都不行
或是任何一個大小寫沒有統一也會發生錯誤
所以
寫程式還真的需要更多的耐心和細心

2008年9月22日 星期一

上課作業































module top;
wire a,b;
reg c;
system_clock #100 clock1(a);
system_clock #50 clock2(b);
always
#1 c=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年9月15日 星期一

選課選的真不爽

去年大三選課名額都保留給大四
今年升大四系辦卻改成把名額留給大三
搞什麼!這樣大四選什麼!
害我現在只有8學分!