2009年12月28日 星期一

4合1多工器


system_clk #200 clk1(a);
system_clk #100 clk2(b);
system_clk #50 clk3(c);
system_clk #25 clk4(d);
all n1(f,a,b,c,d);
endmodule



module all(f,a,b,c,d);
input a,b,c,d;
output f;
wire a1,b1,c1,d1,x,y,z,k;
not(a1,a);
not(b1,b);
not(c1,c);
not(d1,d);
and(x,a1,b1,c);
and(y,b,c,d1);
and(z,a,c,d);
and(k,a,b1,c1,d1);
or(f,x,y,z,k);
endmodule



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

4_in_1

module top;
system_clk #200 clk1(a);
system_clk #100 clk2(b);
system_clk #50 clk3(c);
system_clk #25 clk4(d);
4_in_1 n1(f,a,b,c,d);
endmodule

module 4_in_1(f,a,b,c,d);
input a,b,c,d;
output f;
wire a1,b1,c1,d1,x,y,z,k;
not(a1,a);
not(b1,b);
not(c1,c);
not(d1,d);
and(x,a1,b1,c);
and(y,a1,d);
and(z,b,c1,d);
and(k,a,c,d1);
or(f,x,y,z,k);
endmodule

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

2009年12月7日 星期一

and not


module top;
reg A,B;
wire D;
nand_f n1(C,A,B);
not_f n1(D,C);

initial begin
#10 A=1'b1;B=1'b0;
#10 A=1'b1;B=1'b0;
#10 A=1'b1;B=1'b1;
#2 A=1'b0;
#10$finish;
end
endmodule


module nand_f(C,A,B);
input A,B;
output C;
nand(C,A,B);
specify
specparam
tpd_0_1=3.0:3.0:3.0,
tpd_1_0=3.0:3.0:3.0;
(A=>C)=(tpd_0_1,tpd_1_0);
(B=>C)=(tpd_0_1,tpd_1_0);
endspecify
endmodule

module not_f(D,C);
input C;
output D;
not(D,C);
specify
specparam
tpd_0_1=2.0:2.0:2.0,
tpd_1_0=2.0:2.0:2.0;
(C=>D)=(tpd_0_1,tpd_1_0);
endspecify
endmodule