Saturday, 2 May 2015

verilog code for mejority detector

MEJORITY DETECTOR

module majority
(input v1,v2,v3,
output reg m);
always@(v1 or v2 or v3)
begin
            if((v1&&v2)|(v2&&v3)|(v3&&v1))
            m=1;
            else
            m=0;
end
endmodule

TESTBENCH

module majority_tb;
reg v1,v2,v3;
wire m;
majority m1(v1,v2,v3,m);
initial
begin
v1=0;v2=0;v3=0;
$monitor($time, ,,v1,v2,v3,,"m=%d",m);
#2 v1=0;v2=0;v3=0;
#2 v1=0;v2=0;v3=1;
#2 v1=0;v2=1;v3=1;
#2 v1=1;v2=0;v3=0;
#2 v1=1;v2=0;v3=1;
#2 v1=1;v2=1;v3=0;
#2 v1=1;v2=1;v3=1;
end
endmodule

You can also check more verilog code on

http://kaneriadhaval.blogspot.in/2013/11/all-besic-verilog-code.html

No comments:

Post a Comment