工業製造
産業用モノのインターネット | 工業材料 | 機器のメンテナンスと修理 | 産業プログラミング |
home  MfgRobots >> 工業製造 >  >> Industrial programming >> Verilog

VHDL と Verilog を使用した FPGA での効率的な LFSR 設計

FPGA の LFSR – VHDL および Verilog コード

FPGA 内でリニア フィードバック シフト レジスタがどのように動作するか

LFSR は Linear Feedback Shift Register の略で、FPGA 内で役立つ設計です。 LFSR は合成が簡単です。つまり、必要なリソースが比較的少なく、FPGA 内で非常に高いクロック レートで実行できます。 LFSR を使用することで恩恵を受けるアプリケーションは数多くあります。

線形フィードバック シフト レジスタは、シフト レジスタとして配線された FPGA 内の一連のフリップフロップとして実装されます。シフト レジスタ チェーンからのいくつかのタップは、XOR への入力として使用されます。 またはXNOR 門。このゲートの出力はフィードバックとして使用されます。 シフト レジスタ チェーンの先頭に移動するため、LFSR でのフィードバックが行われます。

XNOR ゲートを使用した 5 ビット LFSR

LFSR の実行中、個々のフリップフロップによって生成されるパターンは擬似ランダム、つまりランダムに近いものになります。 LFSR パターンのどの状態からでも次の状態を予測できるため、完全にランダムではありません。シフト レジスタには注意すべき重要なプロパティがいくつかあります。

LFSR が長いと、すべての反復を実行するのに時間がかかります。 N ビットの LFSR で可能な最長の反復回数は 2N-1 です。考えてみると、N ビット長のものの考えられるパターンはすべて 2N です。したがって、LFSR を使用して表現できないパターンは 1 つだけです。そのパターンは、XOR ゲートを使用する場合はすべて 0、XNOR ゲートをフィードバック ゲートとして使用する場合はすべて 1 です。

VHDL および Verilog コードは、必要な N ビット幅の LFSR を作成します。多項式 (LFSR の背後にある計算) を使用して、ビット幅ごとに可能な最大の LFSR 長を作成します。したがって、3 ビットの場合、考えられるすべての組み合わせを実行するには 23-1=7 クロックかかります。4 ビットの場合:24-1=15、5 ビットの場合:25-1=31 などです。私はこれを XNOR 実装に基づいて、FPGA が LFSR 上でオール ゼロの状態で起動できるようにしました。以下は、ザイリンクスが公開しているすべての LFSR パターンの完全な表です。

VHDL の実装:

LFSR.vhd

-------------------------------------------------------------------------------
-- File downloaded from http://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 

テストベンチ (LFSR_TB.vhd)

-------------------------------------------------------------------------------
-- File downloaded from http://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;

Verilog の実装:

LFSR.v

///////////////////////////////////////////////////////////////////////////////
// File downloaded from http://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 

テストベンチ (LFSR_TB.v)

///////////////////////////////////////////////////////////////////////////////
// File downloaded from http://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. Verilog 初期ブロック
  2. D フリップフロップ非同期リセット
  3. Verilog 階層参照スコープ
  4. Verilog 配列とメモリ
  5. 4ビットカウンター
  6. 抽象化レイヤーの設計
  7. VHDL と Verilog を使用した FPGA での効率的な LFSR 設計
  8. ASIC デザイン フロー
  9. Verilog スケジューリング セマンティクス
  10. Verilog ケース ステートメント
  11. Verilog タスク