Kraklog

[Verilog_LAB1] Part2 본문

[Harman] 하만 반도체 설계/CPU설계

[Verilog_LAB1] Part2

Krakens 2023. 12. 18. 15:40
728x90

프로그램 : Quaturs Prime lite edition 18.1

사용문법 : Verilog 2001

보드 : DE1-SOC

 

 

 

 

 

목표 : 4bit output을 갖는 Multiplexer를 설계

topmodule

`define BUS_SIZE 4
`define SL_SIZE 10
`define USE_GEN

/*`ifedf MUX1
module mux_2x1 (
  input         [3:0] x   ,  //side switch 0~3
  input         [3:0] y   , //slide switch 4~9
  input               s   ,
  output  reg   [3:0] m    //redLEDs
);

	always @ (*)
	if (!s)
		m = x;
	else
		m = y;
`else
		*/

module part2 (SW,LEDR);
	input  [`SL_SIZE-1:0] SW;
	output [`SL_SIZE-1:0] LEDR;

	wire[`BUS_SIZE-1:0] x	= SW[3:0];
	wire[`BUS_SIZE-1:0] y = SW[7:4];
	wire[`BUS_SIZE-1:0] m;
	wire	s=SW[`SL_SIZE-1];

	assign LEDR [`SL_SIZE-1:`BUS_SIZE] = {(`SL_SIZE-`BUS_SIZE){1'b0}};

	assign LEDR [`BUS_SIZE-1:0] = m;

`ifdef USE_GEN
genvar i;

generate
	for (i=0; i<`BUS_SIZE; i=i+1)begin : MUX_2X1
	mux_2x1 uMux_2x1(
	.x(x[i]),
	.y(y[i]),
	.s(s	),
	.m(m[i])
);
	end
	endgenerate

`else
mux_2x1 uMux_2x1_3(
	.x(x[3]),
	.y(y[3]),
	.s(s	),
	.m(m[3])
);

mux_2x1 uMux_2x1_2(
	.x(x[2]),
	.y(y[2]),
	.s(s	),
	.m(m[2])
);

mux_2x1 uMux_2x1_1(
	.x(x[1]),
	.y(y[1]),
	.s(s	),
	.m(m[1])
);

mux_2x1 mux_2x1_0(
	.x(x[0]),
	.y(y[0]),
	.s(s	),
	.m(m[0])
);
*/
`endif
//`endif
endmodule

 

mux 2x1을 설계하여 top에 넣어주었다.

module mux_2x1 (
  input x,
  input y,
  input s,
  output  m
);
  assign m = (~s & x)|(s&y);
endmodule

 

assign 문에 or 연산을 넣었는데, selector (s) 의 값에 따라 출력이 각각 X와 Y로 결정된다.

 

728x90

'[Harman] 하만 반도체 설계 > CPU설계' 카테고리의 다른 글

[Verilog_LAB2] Part1  (0) 2023.12.19
[Verilog_LAB1] Part5  (0) 2023.12.18
[Verilog_LAB1] Part4  (1) 2023.12.18
[Verilog_LAB1] Part3  (1) 2023.12.18
[Verilog_LAB1] Part1  (0) 2023.12.18