Kraklog

Day17. Mux4, Shifter 본문

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

Day17. Mux4, Shifter

Krakens 2023. 7. 25. 22:07
728x90

.프로그램 : Quaturs Prime lite edition 18.1

사용문법 : Verilog 2001

 

module mux4 (
  input     [3:0]     mux_in_a ,
  input     [3:0]     mux_in_b ,
  input               mux_sel  ,
  output  reg [3:0]   mux_out   
);

always @(*) begin
  if (mux_sel) 
    mux_out = mux_in_a;
  else
    mux_out = mux_in_b;  
end
  
endmodule

`timescale 1 ns/1 ns

module tb_mux4();
  reg [3:0]   mux_in_a  ;
  reg [3:0]   mux_in_b  ;
  reg         mux_sel   ;
  wire [3:0]  mux_out   ;    

  mux4 uMux4 (
		.mux_in_a	(mux_in_a),  
		.mux_in_b (mux_in_b),
		.mux_sel  (mux_sel ),
		.mux_out  (mux_out ) 
  );
	initial begin
		mux_in_a = 4'd0;  	
		mux_in_b = 4'd2;	
	end


	initial begin
		mux_sel = 1'b1;
		forever
			#50 mux_sel = (mux_sel ? 1'b0 : 1'b1);
	end

endmodule
 

Mux(multiplexer)는 Selector의 입력값에 따라 인풋 데이터의 출력을 정해주는 모듈이다.
테스트 벤치에서 보이듯, Selector 의 클락 동작에 따라 인풋데이터인 0과 2가 출력됨을 볼 수 있다.

 

module shifter (
  input		  	  [7:0]     inp         ,
  input 		  [1:0]     shift_cntrl ,
  output	reg   [15:0]    shift_out    
);

  always @(*) begin
    if (shift_cntrl == 2'd1) 
      shift_out = inp << 4;
    else if (shift_cntrl == 2'd2)
      shift_out = inp << 8; 
    else
      shift_out = inp;
  end
  
endmodule

module tb_shifter();
  reg   [7:0]   inp         ;        
  reg   [1:0]   shift_cntrl ;
  wire  [15:0]  shift_out   ;

  shifter uShifter(
    .inp         (inp        ),
    .shift_cntrl (shift_cntrl),
    .shift_out   (shift_out  )    
  );

  initial begin
    shift_cntrl = 4'd0;
    inp = 8'hf4;
    forever
    #50 shift_cntrl = shift_cntrl +1 ;
  end

endmodule

Shifter는 곱셈으로 볼 수 있다. (링크)
설명은 따로 정리한 게시글을 링크함으로 대체하겠음.

Shifter는 자릿수를 변경시킴으로써 곱셈과 같은 역할을 하는데 ( shift와 add) 
출력 데이터의 자릿수가 이동 됨을 볼 수 이다.

728x90

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

Day21. 4bit 7-segment, 16bit register, 2bit Counter  (0) 2023.07.28
Day20. 7-segment  (0) 2023.07.28
Day19. Function Counter  (0) 2023.07.28
Day18. my_rotate  (0) 2023.07.28
Day15~16. Verilog 시작 /Adder, 4x4 mult  (0) 2023.07.25