크리에이티브 커먼즈 라이선스
Creative Commons License
MUX using procedure
module mux(
	iA,				// input 0
	iB,				// input 1
	iSel,			        // select 1 bit
	oC				// output
);		

/////////////////////// Port declaration///////////////////////
input			iA;
input			iB;
input			iSel;

output			oC;	
////////////////// Port data type declaration ///////////////////
reg			oC;

////////////////// Code Start here!           ///////////////////
always @(iA or iB or iSel) begin
    if(iSel == 1'b1) begin
	oC = iA;
    end else begin
	oC = iB;
    end		
end

endmodule


MUX using case
module mux(
	iA,				// input 0
	iB,				// input 1
	iSel,			        // select 1 bit
	oC				// output
);		

/////////////////////// Port declaration///////////////////////
input			iA;
input			iB;
input			iSel;

output			oC;	
////////////////// Port data type declaration ///////////////////
reg			oC;

////////////////// Code Start here!           ///////////////////
always @(iA or iB or iSel) begin
    case(iSel) 
	1'b1: oC = iA;
	1'b0: oC = iB;	
    endcase	
end

endmodule


Testbench
//`include "mux_using_procedure.v"
`include "mux_using_case.v"

module testbench();
reg		a;				// input 0
reg		b;				// input 1
reg		s;				// input select
wire		c;				// output

initial begin
	$dumpfile("sim.vcd");
	$dumpvars(0, testbench);
	
	$monitor("TIME=%d A=%b B=%b SEL=%b C=%b", $time, a, b, s, c);
	// test scenario
		a <= 1'b0;	b <= 1'b0;	s <= 1'b0;
	#2	a <= 1'b0;	b <= 1'b0;	s <= 1'b1;
	#2	a <= 1'b0;	b <= 1'b1;	s <= 1'b0;
	#2	a <= 1'b0;	b <= 1'b1;	s <= 1'b1;
	#2	a <= 1'b1;	b <= 1'b0;	s <= 1'b0;
	#2	a <= 1'b1;	b <= 1'b0;	s <= 1'b1;
	#2	a <= 1'b1;	b <= 1'b1;	s <= 1'b0;
	#2	a <= 1'b1;	b <= 1'b1;	s <= 1'b1;
	#2	$finish();
end

// connect DUT to testbench
mux dut_mux(
	.iA(a),
	.iB(b),
	.iSel(s),
	.oC(c)
);		

endmodule


Simulation Result

Waveform

할말업ㅂ음
읭여읭여
저작자 표시 비영리 동일 조건 변경 허락
TAG ,

댓글을 달아 주세요

  1. ememoho 2010/06/28 21:33  댓글주소  수정/삭제  댓글쓰기

    MUX using case 21번 line
    1'b0: oC = iA; -> 1'b0: oC = iB;
    오타 수정 요망... ^^

  2. 형들아 2010/10/27 21:27  댓글주소  수정/삭제  댓글쓰기

    아 이 코드 생각나네요 ㅋㅋㅋ 예전에 제가 막 징징거리니까
    이게 기본인데... 라고 하셨었는데 이제야 이해가 ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ
    아 좀 막연히 겁먹지 말고 봤었으면 그때 그렇게 징징거리지도않았을텐데 ㅋㅋㅋㅋㅋㅋㅋ