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

Verilog 수학 함수

Verilog 수학 함수는 상수 표현식 대신 사용할 수 있으며 정수 그리고 진짜 수학.

정수 수학 함수

함수 $clog2 log2의 상한선을 반환합니다. 주어진 인수의. 이것은 일반적으로 주어진 크기의 메모리를 처리하는 데 필요한 최소 너비를 계산하는 데 사용됩니다.

예를 들어 디자인에 7개의 병렬 가산기가 있는 경우 7개의 가산기를 모두 나타내는 데 필요한 최소 비트 수는 $clog2입니다. 7 중 3을 산출합니다.

  
  
module des 
  #(parameter NUM_UNITS = 7) 
  
  // Use of this system function helps to reduce the 
  // number of input wires to this module
  (input [$clog2(NUM_UNITS)-1:0] active_unit);
  
  initial 
    $monitor("active_unit = %d", active_unit);
endmodule

`define NUM_UNITS 5

module tb;
  integer i;
  reg [`NUM_UNITS-1:0] 	active_unit;
  
  des #(.NUM_UNITS(`NUM_UNITS)) u0(active_unit);
  
  initial begin
    active_unit     = 1;     
	#10 active_unit = 7;
    #10 active_unit = 8;    
  end
endmodule

  

active_unit 신호는 총 5개 단위를 저장할 수 있는 3비트를 가지고 있습니다.

시뮬레이션 로그
xcelium> run
active_unit = 001
active_unit = 111
active_unit = 000
xmsim: *W,RNQUIE: Simulation is complete.

실제 수학 함수

이러한 시스템 기능은 실제 인수 및 반환 실제 번호.

함수 설명
$ln(x) 자연 로그 로그(x)
$log10(x) 십진 로그 log10(x)
exp(x) x의 지수(e x ) 여기서 e=2.718281828...
제곱(x) x의 제곱근
$pow(x, y) x y
$floor(x) 바닥 x
$ceil(x) 천장 x
$sin(x) x의 사인(여기서 x는 라디안 단위)
$cos(x) x의 코사인 여기서 x는 라디안입니다.
$tan(x) x가 라디안 단위인 x의 탄젠트
$asin(x) x의 아크-사인
$acos(x) x의 아크-코사인
$atan(x) x의 아크 탄젠트
$atan2(x, y) x/y의 아크 탄젠트
$hypot(x, y) x와 y의 빗변 :sqrt(x x + y y )
$sinh(x) x의 쌍곡선 사인
$cosh(x) x의 쌍곡선-코사인
$tanh(x) x의 쌍곡선 탄젠트
$asinh(x) x의 쌍곡선 사인
$acosh(x) x의 쌍곡선 코사인
$atanh(x) x의 쌍곡선 탄젠트
  
  

module tb;
  real x, y;
  
  initial begin
    x = 10000;
    $display("$log10(%0.3f) = %0.3f", x, $log10(x));
    
    x = 1;
    $display("$ln(%0.3f) = %0.3f", x, $ln(x));
    
    x = 2;
    $display("$exp(%0.3f) = %0.3f", x, $exp(x));
    
    x = 25;
    $display("$sqrt(%0.3f) = %0.3f", x, $sqrt(x));
    
    x = 5;
    y = 3;
    $display("$pow(%0.3f, %0.3f) = %0.3f", x, y, $pow(x, y));
    
    x = 2.7813;
    $display("$floor(%0.3f) = %0.3f", x, $floor(x));
    
    x = 7.1111;
    $display("$ceil(%0.3f) = %0.3f", x, $ceil(x));
    
    x = 30 * (22.0/7.0) / 180;   // convert 30 degrees to radians
    $display("$sin(%0.3f) = %0.3f", x, $sin(x));
    
    x = 90 * (22.0/7.0) / 180;
    $display("$cos(%0.3f) = %0.3f", x, $cos(x));
    
    x = 45 * (22.0/7.0) / 180;
    $display("$tan(%0.3f) = %0.3f", x, $tan(x));
    
    x = 0.5;
    $display("$asin(%0.3f) = %0.3f rad, %0.3f deg", x, $asin(x), $asin(x) * 7.0/22.0 * 180);
    
    x = 0;
    $display("$acos(%0.3f) = %0.3f rad, %0.3f deg", x, $acos(x), $acos(x) * 7.0/22.0 * 180);
    
    x = 1;
    $display("$atan(%0.3f) = %0.3f rad, %f deg", x, $atan(x), $atan(x) * 7.0/22.0 * 180);    
  end
endmodule


  
시뮬레이션 로그
xcelium> run
$log10(10000.000) = 4.000
$ln(1.000) = 0.000
$exp(2.000) = 7.389
$sqrt(25.000) = 5.000
$pow(5.000, 3.000) = 125.000
$floor(2.781) = 2.000
$ceil(7.111) = 8.000
$sin(0.524) = 0.500
$cos(1.571) = -0.001
$tan(0.786) = 1.001
$asin(0.500) = 0.524 rad, 29.988 deg
$acos(0.000) = 1.571 rad, 89.964 deg
$atan(1.000) = 0.785 rad, 44.981895 deg
xmsim: *W,RNQUIE: Simulation is complete.


verilog

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