Vous êtes sur la page 1sur 8

Half adder

module ha_df(a,b,sum,carry);
input a,b;
output sum,carry;
assign sum = a^b;
assign carry = a&b;
endmodule
full adder
module fa_df(a,b,c,sum,carry);
input a,b,c;
output sum,carry;
assign sum = a^b^c;
assign carry = (a&b) | (b&c) | (c&a);
endmodule
addition in autocorrelation and variance
module addition(a,b,s,cout,x);
input [23:0]a,b;
output [23:0]s;
output [24:0]x;
output cout;
assign x={cout,s};
wire [22:0]c;
ha_df a1(a[0],b[0],s[0],c[0]);
fa_df a2(a[1],b[1],c[0],s[1],c[1]);
fa_df a3(a[2],b[2],c[1],s[2],c[2]);
fa_df a4(a[3],b[3],c[2],s[3],c[3]);
fa_df a5(a[4],b[4],c[3],s[4],c[4]);
fa_df a6(a[5],b[5],c[4],s[5],c[5]);
fa_df a7(a[6],b[6],c[5],s[6],c[6]);
fa_df a8(a[7],b[7],c[6],s[7],c[7]);
fa_df a9(a[8],b[8],c[7],s[8],c[8]);
fa_df a10(a[9],b[9],c[8],s[9],c[9]);
fa_df a11(a[10],b[10],c[9],s[10],c[10]);
fa_df a12(a[11],b[11],c[10],s[11],c[11]);
fa_df a13(a[12],b[12],c[11],s[12],c[12]);
fa_df a14(a[13],b[13],c[12],s[13],c[13]);
fa_df a15(a[14],b[14],c[13],s[14],c[14]);
fa_df a16(a[15],b[15],c[14],s[15],c[15]);
fa_df a17(a[16],b[16],c[15],s[16],c[16]);

fa_df a18(a[17],b[17],c[16],s[17],c[17]);
fa_df a19(a[18],b[18],c[17],s[18],c[18]);
fa_df a20(a[19],b[19],c[18],s[19],c[19]);
fa_df a21(a[20],b[20],c[19],s[20],c[20]);
fa_df a22(a[21],b[21],c[20],s[21],c[21]);
fa_df a23(a[22],b[22],c[21],s[22],c[22]);
fa_df a24(a[23],b[23],c[22],s[23],cout);
endmodule
multiplier
module multiplier(rst,clk,a,b,c);
input clk,rst;
input [11:0]a,b;
output [23:0]c;
reg [23:0]c;
always@(posedge clk)
if(rst)
begin
c=24'h000000;
c[11:0] = b;
case(c[0])
1'b1:begin
c[23:12] = c[23:12]+a;
c = c>>1;
end
1'b0:begin
c = c>>1;
end
endcase
end
else
begin case(c[0])
1'b1:begin
c[23:12] = c[23:12]+a;
c = c>>1;
end
1'b0:begin
c = c>>1;
end
endcase
end
endmodule

ram
module ram_da(clk,address_0,data_0,r_0,w_0,data_0_out,cs_0,
op,address_1,data_1,r_1,w_1,data_1_out,cs_1,td);
output reg [11:0] data_0_out,data_1_out;
input [7:0] address_0,address_1,td;
input [11:0] data_0,data_1;
input w_0,cs_0,clk,r_0,w_1,r_1,cs_1,op;
reg [11:0] memory [0:255];
always @(posedge clk)
if(op)
begin
if (w_0 && cs_0) begin
memory[address_0] <= data_0;end
if (r_0 && cs_0) begin
data_0_out = memory[address_0-td];end
if (w_1 && cs_1) begin
memory[address_1] <= data_1;end
if (r_1 && cs_1) begin
data_1_out = memory[address_1-td];end
end
endmodule

increment of address
module inc1(clk,en,inc,a,b);
input clk,en,inc;
output [7:0]a,b;
reg

[7:0]a,b;

always@(posedge clk)
if(en)
begin

a = 8'h00;
b = 8'h10;
end
else
if(inc)
begin
a <= a+1;
b <= b+1;
end
else
begin
a <= a;
b <= b;
end
endmodule

autocorrelation block
module autocorrelation(xr,xi,td,rc,cout);
input [11:0]xr,xi;
input [7:0]td;
output [23:0]rc;
output cout;
wire [7:0]address_0,address_1;
wire [11:0]data_0_out,data_1_out;
wire [23:0]f1,f2;
wire en,rst,op;
inc1
ram_da

a0(clk,en,inc,address_0,address_1);
a1(clk,address_0,xr,r_0,w_0,data_0_out,cs_0,
op,address_1,xi,r_1,w_1,data_1_out,cs_1,td);

multiplier a2(rst,clk,xr,data_0_out,f1);

multiplier a3(rst,clk,xi,data_1_out,f2);
addition a4(f1,f2,ac,cout,rc);
endmodule

variance
module variance(xr,xi,v,cout);
input [11:0]xr,xi;
output [23:0]v;
output cout;
wire [23:0]m1,m2;
multiplier a0(rst,clk,xr,xr,m1);
multiplier a1(rst,clk,xi,xi,m2);
addition a2(m1,m2,v1,cout,v);
endmodule

addition in integrator
module addition1(a,b,s,cout);
input [24:0]a,b;
output [24:0]s;
output cout;
wire [23:0]c;
ha_df a1(a[0],b[0],s[0],c[0]);
fa_df a2(a[1],b[1],c[0],s[1],c[1]);
fa_df a3(a[2],b[2],c[1],s[2],c[2]);
fa_df a4(a[3],b[3],c[2],s[3],c[3]);
fa_df a5(a[4],b[4],c[3],s[4],c[4]);
fa_df a6(a[5],b[5],c[4],s[5],c[5]);
fa_df a7(a[6],b[6],c[5],s[6],c[6]);
fa_df a8(a[7],b[7],c[6],s[7],c[7]);
fa_df a9(a[8],b[8],c[7],s[8],c[8]);
fa_df a10(a[9],b[9],c[8],s[9],c[9]);
fa_df a11(a[10],b[10],c[9],s[10],c[10]);
fa_df a12(a[11],b[11],c[10],s[11],c[11]);
fa_df a13(a[12],b[12],c[11],s[12],c[12]);
fa_df a14(a[13],b[13],c[12],s[13],c[13]);
fa_df a15(a[14],b[14],c[13],s[14],c[14]);
fa_df a16(a[15],b[15],c[14],s[15],c[15]);

fa_df a17(a[16],b[16],c[15],s[16],c[16]);
fa_df a18(a[17],b[17],c[16],s[17],c[17]);
fa_df a19(a[18],b[18],c[17],s[18],c[18]);
fa_df a20(a[19],b[19],c[18],s[19],c[19]);
fa_df a21(a[20],b[20],c[19],s[20],c[20]);
fa_df a22(a[21],b[21],c[20],s[21],c[21]);
fa_df a23(a[22],b[22],c[21],s[22],c[22]);
fa_df a24(a[23],b[23],c[22],s[23],c[23]);
fa_df a25(a[24],b[24],c[23],s[24],cout);
endmodule

d ff
module dff(clk,rst,d,q,qbar);
input clk,rst;
input [24:0]d;
output [24:0]q,qbar;
reg [24:0]q;
assign qbar=~q;
always @(posedge clk or negedge rst)
begin
if(rst==0)
q=25'h00000;
else
q=d;
end
endmodule

control counter

module counter(clk,load_td,d_st,q);
input clk,load_td;
input [3:0]d_st;
output [3:0]q;
reg [3:0] tmp;
always @(posedge clk or posedge load_td)
begin
if (load_td)
tmp <= d_st;

else
tmp <= tmp + 1'b1;
end
assign q = tmp;
endmodule

half subtractor
module hs_df(p,q,d,b);
input p,q;
output d,b;
assign d=p^q;
assign b=(~p)&q;
endmodule

full subtractor
module fs_df(x,y,z,d,b);
input x,y,z;
output d,b;
assign d=x^y^z;
assign b=(z&(~(x^y)))|((~x)&y);
endmodule
subtraction
module subtraction(x,y,d,b);
input [23:0]x,y;
output [23:0]d,b;
hs_df a0(x[0],y[0],d[0],b[0]);
hs_df a1(x[1],y[1],d[1],b[1]);
hs_df a2(x[2],y[2],d[2],b[2]);
hs_df a3(x[3],y[3],d[3],b[3]);
hs_df a4(x[4],y[4],d[4],b[4]);
hs_df a5(x[5],y[5],d[5],b[5]);
hs_df a6(x[6],y[6],d[6],b[6]);
hs_df a7(x[7],y[7],d[7],b[7]);
hs_df a8(x[8],y[8],d[8],b[8]);

hs_df a9(x[9],y[9],d[9],b[9]);
hs_df a10(x[10],y[10],d[10],b[10]);
hs_df a11(x[11],y[11],d[11],b[11]);
hs_df a12(x[12],y[12],d[12],b[12]);
hs_df a13(x[13],y[13],d[13],b[13]);
hs_df a14(x[14],y[14],d[14],b[14]);
hs_df a15(x[15],y[15],d[15],b[15]);
hs_df a16(x[16],y[16],d[16],b[16]);
hs_df a17(x[17],y[17],d[17],b[17]);
hs_df a18(x[18],y[18],d[18],b[18]);
hs_df a19(x[19],y[19],d[19],b[19]);
hs_df a20(x[20],y[20],d[20],b[20]);
hs_df a21(x[21],y[21],d[21],b[21]);
hs_df a22(x[22],y[22],d[22],b[22]);
hs_df a23(x[23],y[23],d[23],b[23]);
endmodule

adder in dc offset compensation


module addition1(a,b,s,cout);
input [11:0]a,b;
output [11:0]s;
output cout;
wire [10:0]c;
ha_df a1(a[0],b[0],s[0],c[0]);
fa_df a2(a[1],b[1],c[0],s[1],c[1]);
fa_df a3(a[2],b[2],c[1],s[2],c[2]);
fa_df a4(a[3],b[3],c[2],s[3],c[3]);
fa_df a5(a[4],b[4],c[3],s[4],c[4]);
fa_df a6(a[5],b[5],c[4],s[5],c[5]);
fa_df a7(a[6],b[6],c[5],s[6],c[6]);
fa_df a8(a[7],b[7],c[6],s[7],c[7]);
fa_df a9(a[8],b[8],c[7],s[8],c[8]);
fa_df a10(a[9],b[9],c[8],s[9],c[9]);
fa_df a11(a[10],b[10],c[9],s[10],c[10]);
fa_df a12(a[11],b[11],c[10],s[11],cout);
endmodule

Vous aimerez peut-être aussi