Industriële fabricage
Industrieel internet der dingen | Industriële materialen | Onderhoud en reparatie van apparatuur | Industriële programmering |
home  MfgRobots >> Industriële fabricage >  >> Industrial programming >> Verilog

Verilog Math Functions beheersen voor efficiënt Hardware-ontwerp

Verilog wiskundige functies kunnen gebruikt worden in plaats van constante expressies en ondersteunen zowel integer als real wiskunde.

Integer Wiskundige Functies

De functie $clog2 retourneert de ceiling van log2 van het gegeven argument. Dit wordt typisch gebruikt om de minimale breedte te berekenen die nodig is om een geheugen van gegeven grootte te adresseren.

Als het ontwerp bijvoorbeeld 7 parallelle optellers heeft, is het minimale aantal bits dat nodig is om alle 7 optellers weer te geven $clog2 van 7 wat 3 oplevert.

module des #(parameter NUM_UNITS = 7)
  // Gebruik van deze systeemfunctie helpt om het
  // aantal input-draden aan deze module te verminderen
  (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

Let op dat het signaal active_unit 3-bits heeft om totaal 5 units op te slaan.

Simulatie-log

xcelium> run
active_unit = 001
active_unit = 111
active_unit = 000
xmsim: *W,RNQUIE: Simulation is complete.

Real Wiskundige Functies

Deze systeemfuncties accepteren real argumenten en geven een real getal terug.

Functie Beschrijving
$ln(x) Natuurlijke logaritme log(x)
$log10(x) Decimale logaritme log10(x)
$exp(x) Exponentiële van x (ex) waar e=2.718281828...
$sqrt(x) Vierkantswortel van x
$pow(x, y) xy
$floor(x) Afgerond naar beneden (floor)
$ceil(x) Afgerond naar boven (ceiling)
$sin(x) Sinus van x waar x in radialen is
$cos(x) Cosinus van x waar x in radialen is
$tan(x) Tangens van x waar x in radialen is
$asin(x) Boogsinus van x
$acos(x) Boogcosinus van x
$atan(x) Boogtangens van x
$atan2(x, y) Boogtangens van x/y
$hypot(x, y) Hypotenusa van x en y: sqrt(x2 + y2)
$sinh(x) Hyperbolische Sinus van x
$cosh(x) Hyperbolische Cosinus van x
$tanh(x) Hyperbolische Tangens van x
$asinh(x) Hyperbolische Boogsinus van x
$acosh(x) Hyperbolische Boogcosinus van x
$atanh(x) Hyperbolische Boogtangens van 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; // 30 graden omrekenen naar radialen
    $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

Simulatie-log

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 beheersen: Complete tutorial voor digitale schakelingontwerp
  2. Verilog concatenatie beheersen: Een praktische gids
  3. Verilog-toewijzingen begrijpen: types, syntax en best practices
  4. Verilog Blocking vs. Non-Blocking: belangrijkste verschillen uitgelegd
  5. Verilog-functies beheersen voor efficiënt RTL-ontwerp
  6. Verilog Tasks begrijpen: Functions vs Tasks, Syntax en Gebruik
  7. Verilog Clock Generator: Ontwerp & Implementatie Gids
  8. Verilog $timeformat beheersen: Precisie en Weergave-controle
  9. Verilog Timescales begrijpen en printen in elke Scope
  10. Verilog File I/O onder de knie: Openen, Lezen, Schrijven en Sluiten
  11. Beginner's Guide to Verilog: Hello World Voorbeeld