Fabrication industrielle
Internet des objets industriel | Matériaux industriels | Entretien et réparation d'équipement | Programmation industrielle |
home  MfgRobots >> Fabrication industrielle >  >> Industrial programming >> Verilog

Conception efficace de LFSR en FPGA avec VHDL et Verilog

LFSR dans un FPGA – Code VHDL & Verilog

Fonctionnement d'un registre à décalage à rétroaction linéaire dans un FPGA

LFSR signifie Linear Feedback Shift Register (registre à décalage à rétroaction linéaire), une structure utile dans les FPGA. Les LFSR sont simples à synthétiser : ils consomment peu de ressources et fonctionnent à des fréquences d'horloge très élevées. Applications bénéfiques :

Un LFSR s'implémente comme une série de bascules (flip-flops) câblées en registre à décalage. Plusieurs « taps » (prises) sur la chaîne sont entrés dans une porte XOR ou XNOR. La sortie de cette porte est réinjectée en feedback au début de la chaîne, d'où « Feedback » dans LFSR.

LFSR 5 bits utilisant des portes XNOR

En fonctionnement, le motif généré par les bascules est pseudo-aléatoire : proche de l'aléatoire, mais déterministe. Depuis n'importe quel état, on peut prédire l'état suivant. Propriétés importantes :

Les LFSR plus longs mettent plus de temps à parcourir toutes les itérations. Le maximum pour N bits est 2N-1. Sur 2N motifs possibles pour N bits, un seul ne peut être exprimé : tout à 0 (XOR) ou tout à 1 (XNOR).

Le code VHDL et Verilog crée un LFSR de largeur N bits paramétrable. Il utilise les polynômes (mathématiques du LFSR) pour obtenir la longueur maximale pour chaque largeur. Basé sur une implémentation XNOR pour permettre au FPGA de démarrer à l'état tout-zéro. Voici le tableau complet des motifs LFSR publié par Xilinx.

Implémentation VHDL :

LFSR.vhd

------------------------------------------------------------------------------- -- File downloaded from https://www.nandland.com ------------------------------------------------------------------------------- -- Description: -- A LFSR or Linear Feedback Shift Register is a quick and easy -- way to generate pseudo-random data inside of an FPGA. The LFSR can be used -- for things like counters, test patterns, scrambling of data, and others. -- This module creates an LFSR whose width gets set by a generic. The -- o_LFSR_Done will pulse once all combinations of the LFSR are complete. The -- number of clock cycles that it takes o_LFSR_Done to pulse is equal to -- 2^g_Num_Bits-1. For example, setting g_Num_Bits to 5 means that o_LFSR_Done -- will pulse every 2^5-1 = 31 clock cycles. o_LFSR_Data will change on each -- clock cycle that the module is enabled, which can be used if desired. -- -- Generics: -- g_Num_Bits - Set to the integer number of bits wide to create your LFSR. ------------------------------------------------------------------------------- library ieee; use ieee.std_logic_1164.all; entity LFSR is generic ( g_Num_Bits : integer := 5 ); port ( i_Clk : in std_logic; i_Enable : in std_logic; -- Optional Seed Value i_Seed_DV : in std_logic; i_Seed_Data : in std_logic_vector(g_Num_Bits-1 downto 0); o_LFSR_Data : out std_logic_vector(g_Num_Bits-1 downto 0); o_LFSR_Done : out std_logic ); end entity LFSR; architecture RTL of LFSR is signal r_LFSR : std_logic_vector(g_Num_Bits downto 1) := (others => '0'); signal w_XNOR : std_logic; begin -- Purpose: Load up LFSR with Seed if Data Valid (DV) pulse is detected. -- Othewise just run LFSR when enabled. p_LFSR : process (i_Clk) is begin if rising_edge(i_Clk) then if i_Enable = '1' then if i_Seed_DV = '1' then r_LFSR 

Testbench (LFSR_TB.vhd)

------------------------------------------------------------------------------- -- File downloaded from https://www.nandland.com ------------------------------------------------------------------------------- -- Description: Simple Testbench for LFSR.vhd. Set c_NUM_BITS to different -- values to verify operation of LFSR ------------------------------------------------------------------------------- library ieee; use ieee.std_logic_1164.all; entity LFSR_TB is end entity LFSR_TB; architecture behave of LFSR_TB is constant c_NUM_BITS : integer := 5; constant c_CLK_PERIOD : time := 40 ns; -- 25 MHz signal r_Clk : std_logic := '0'; signal w_LFSR_Data : std_logic_vector(c_NUM_BITS-1 downto 0); signal w_LFSR_Done : std_logic; begin r_Clk c_NUM_BITS) port map ( i_Clk => r_Clk, i_Enable => '1', i_Seed_DV => '0', i_Seed_Data => (others => '0'), o_LFSR_Data => w_LFSR_Data, o_LFSR_Done => w_LFSR_Done ); end architecture behave; 

Implémentation Verilog :

LFSR.v

/////////////////////////////////////////////////////////////////////////////// // File downloaded from https://www.nandland.com /////////////////////////////////////////////////////////////////////////////// // Description: // A LFSR or Linear Feedback Shift Register is a quick and easy way to generate // pseudo-random data inside of an FPGA. The LFSR can be used for things like // counters, test patterns, scrambling of data, and others. This module // creates an LFSR whose width gets set by a parameter. The o_LFSR_Done will // pulse once all combinations of the LFSR are complete. The number of clock // cycles that it takes o_LFSR_Done to pulse is equal to 2^g_Num_Bits-1. For // example setting g_Num_Bits to 5 means that o_LFSR_Done will pulse every // 2^5-1 = 31 clock cycles. o_LFSR_Data will change on each clock cycle that // the module is enabled, which can be used if desired. // // Parameters: // NUM_BITS - Set to the integer number of bits wide to create your LFSR. /////////////////////////////////////////////////////////////////////////////// module LFSR #(parameter NUM_BITS) ( input i_Clk, input i_Enable, // Optional Seed Value input i_Seed_DV, input [NUM_BITS-1:0] i_Seed_Data, output [NUM_BITS-1:0] o_LFSR_Data, output o_LFSR_Done ); reg [NUM_BITS:1] r_LFSR = 0; reg r_XNOR; // Purpose: Load up LFSR with Seed if Data Valid (DV) pulse is detected. // Othewise just run LFSR when enabled. always @(posedge i_Clk) begin if (i_Enable == 1'b1) begin if (i_Seed_DV == 1'b1) r_LFSR 

Testbench (LFSR_TB.v)

/////////////////////////////////////////////////////////////////////////////// // File downloaded from https://www.nandland.com /////////////////////////////////////////////////////////////////////////////// // Description: Simple Testbench for LFSR.v. Set c_NUM_BITS to different // values to verify operation of LFSR /////////////////////////////////////////////////////////////////////////////// module LFSR_TB (); parameter c_NUM_BITS = 4; reg r_Clk = 1'b0; wire [c_NUM_BITS-1:0] w_LFSR_Data; wire w_LFSR_Done; LFSR #(.NUM_BITS(c_NUM_BITS)) LFSR_inst (.i_Clk(r_Clk), .i_Enable(1'b1), .i_Seed_DV(1'b0), .i_Seed_Data(}), // Replication .o_LFSR_Data(w_LFSR_Data), .o_LFSR_Done(w_LFSR_Done) ); always @(*) #10 r_Clk 

Verilog

  1. Comprendre les affectations Verilog : Types, Syntaxe et Bonnes Pratiques
  2. Verilog basique : concevoir votre première porte ET
  3. Maîtriser les blocs generate Verilog : Instanciation dynamique et conception conditionnelle
  4. Conception et Implémentation d'un Compteur Ripple Asynchrone en Verilog
  5. Comprendre les Tasks Verilog : Fonctions vs Tasks, Syntaxe et Utilisation
  6. Maîtriser les blocs d'instructions Verilog : Exécution séquentielle et parallèle
  7. Verilog Essentiel : Aperçu concis
  8. Maîtriser Verilog : Tutoriel complet pour la conception de circuits numériques
  9. Module Compteur Anneau en Verilog : Conception et Exemple de Testbench