산업 제조
산업용 사물 인터넷 | 산업자재 | 장비 유지 보수 및 수리 | 산업 프로그래밍 |
home  MfgRobots >> 산업 제조 >  >> Industrial programming >> verilog

Verilog 연결

다중 비트 Verilog 와이어 및 변수는 연결을 사용하여 더 큰 다중 네트워크 와이어 또는 변수를 형성하기 위해 함께 묶일 수 있습니다. 연산자 {} 쉼표로 구분. 연결은 또한 와이어 및 변수 외에도 표현식 및 크기 상수를 피연산자로 가질 수 있습니다.

연결의 전체 크기를 계산하려면 각 피연산자의 크기를 알아야 합니다.

Verilog 연결 예

  
  
	wire 		a, b; 		// 1-bit wire
	wire [1:0]  res; 		// 2-bit wire to store a and b
	
	// res[1] follows a, and res[0] follows b
	assign res = {a, b}; 	
	
	
	wire [2:0]  c;
	wire [7:0] 	res1;
	
	// res[0]   follows c[2]
	// res[2:1] is always 0
	// res[4:3] follows c[1:0]
	// res[5]   follows a
	// res[6]   follows b
	assign res1 = {b, a, c[1:0], 2'b00, c[2]};

  

다음은 다른 출력을 형성하기 위해 입력을 연결하는 작업 설계 예입니다. 연결된 표현식은 출력이 아닌 모든 와이어 또는 변수에 간단히 표시하거나 할당할 수 있습니다.

  
  
module des (input [1:0] 	a,
            input [2:0] 	b,
            output [4:0]	out1,
            output [3:0] 	out2            
           );
  
  assign out1 = {a, b};
  assign out2 = {a[1], 2'b01, b[2]};
  
endmodule  

module tb;
  reg [1:0] a;
  reg [2:0] b;
  wire [4:0] out1;
  wire [3:0] out2;
  
  des u0 (a, b, out1, out2);
  
  initial begin
    a <= 0;
    b <= 0;
    
    $monitor("[%0t] a=%b b=%b, out1=%b out2=%b", $time, a, b, out1, out2);
    
    #10 a <= 3;
    #5  b <= 5;
    #10 a <= 2;
    #5  b <= 1;
    
    #10 $finish;
  end
endmodule

  

out2[2:1]는 항상 상수 2'b01입니다.

시뮬레이션 로그
xcelium> run
[0] a=00 b=000, out1=00000 out2=0010
[10] a=11 b=000, out1=11000 out2=1010
[15] a=11 b=101, out1=11101 out2=1011
[25] a=10 b=101, out1=10101 out2=1011
[30] a=10 b=001, out1=10001 out2=1010
Simulation complete via $finish(1) at time 40 NS + 0

복제 연산자

동일한 표현식을 여러 번 반복해야 하는 경우 복제 상수 음수가 아닌 숫자여야 하고 X, Z 또는 어떤 변수도 될 수 없는 값이 사용됩니다. 이 상수는 원래 연결 연산자와 함께 중괄호로 묶이며 표현식이 반복되는 총 횟수를 나타냅니다.

  
  
	wire a;
	wire [6:0] res;
	
	assign res = {7{a}};
	
	{2'bz{2'b0}}         // Illegal to have Z as replication constant
	{2'bx{2'b0}}         // Illegal to have X as replication constant

  

복제 표현식은 할당의 왼쪽에 나타날 수 없으며 output에 연결할 수 없습니다. 또는 inout 포트.

  
  
module des;
  reg [1:0] a;
  reg [2:0] b;
  
  initial begin
    a <= 2;
    b <= 4;
    
    #10;
    $display("a=%b b=%b res=%b", a, b, {{2{a}}, {3{b}}});
  end
  
endmodule

  

get은 두 번 반복되고 b는 세 번 반복됩니다.

시뮬레이션 로그
xcelium> run
a=10 b=100 res=1010100100100
xmsim: *W,RNQUIE: Simulation is complete.

피연산자는 상수가 0인 경우에도 복제 표현식이 실행될 때 한 번만 평가됩니다.

중첩 복제

복제 표현식은 정규 연결 표현식 내에서 사용할 수 있습니다. 위의 예를 기준으로 a와 b가 결합된 전체 표현식에 포함되었습니다.

  
  
module des;
  reg [1:0] a;
  reg [2:0] b;
  
  initial begin
    a <= 2;
    b <= 4;
    
    #10;
    $display("a=%b b=%b res=%b", a, b, {a, b, 3'b000, {{2{a}}, {3{b}}}});
  end
  
endmodule

  
시뮬레이션 로그
xcelium> run
a=10 b=100 res=101000001010100100100
xmsim: *W,RNQUIE: Simulation is complete.

불법 사용

  
  
  module des;
    reg [1:0] a;
    reg [2:0] b;
    reg [3:0] _var;

    initial begin
      a <= 2;
      b <= 4;
      _var <= 3;

      // This is illegal because variables cannot be used
      // as replication constant
      $display("a=%b b=%b res=%b", a, b, {_var{a}});
    end
  endmodule

  

이로 인해 아래와 같이 컴파일 오류가 발생합니다.

시뮬레이션 로그
	Top level design units:
		des
      $display("a=%b b=%b res=%b", a, b, {_var{a}});
                                             |
xmelab: *E,NOTPAR (./testbench.sv,12|45): Illegal operand for constant expression [4(IEEE)].


verilog

  1. Verilog 튜토리얼
  2. Verilog 할당
  3. Verilog 차단 및 비 차단
  4. Verilog 기능
  5. Verilog 작업
  6. Verilog 클록 생성기
  7. Verilog 수학 함수
  8. Verilog 시간 형식
  9. Verilog 타임스케일 범위
  10. Verilog 파일 IO 작업