2013-08-30 29 views
-1

我在这里张贴PRBSPRBS发生器模块中的VHDL

的快照

我对PRBS模块代码是

-- Module Name: prbs - Behavioral 
-- Project Name: modulator 

-- Description: 
--To make it of N bit replace existing value of N with desired value of N 
---------------------------------------------------------------------------------- 
library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 
use IEEE.STD_LOGIC_ARITH.ALL; 
use IEEE.STD_LOGIC_UNSIGNED.ALL; 

---- Uncomment the following library declaration if instantiating 
---- any Xilinx primitives in this code. 
--library UNISIM; 
--use UNISIM.VComponents.all; 

entity prbs is 
    Port (pclock : in STD_LOGIC; 
      preset : IN std_logic := '0'; 
      prbsout : out STD_LOGIC); 
end prbs; 

architecture Behavioral of prbs is 

COMPONENT dff is 
    PORT(
     dclock : IN std_logic; 
     dreset : IN std_logic; 
     din : IN std_logic ;   
     dout : OUT std_logic 
     ); 
    END COMPONENT; 


signal dintern : std_logic_vector (4 downto 1); --Change value of N to change size of shift register 
signal feedback : std_logic := '0'; 

begin 

instdff : dff port map (pclock , preset , feedback , dintern(1)); 
genreg : for i in 2 to 4 generate --Change Value of N Here to generate that many instance of d flip flop 
begin 
instdff : dff port map (pclock , preset , dintern(i-1) , dintern(i)); 
end generate genreg; 

main : process(pclock) 

begin 
    if pclock'event and pclock = '1' then 
      if preset = '0' then 
       if dintern /= "0" then 

        feedback <= dintern(1) xor dintern(3); -- For N equals four; 
        --feedback <= dintern(4) xor dintern(5) xor dintern(6) xor dintern(8); -- For N equals eight; 
        --feedback <= dintern(11) xor dintern(13) xor dintern(14) xor dintern(16); -- For N equals sixteen; 
        --feedback <= dintern(1) xor dintern(2) xor dintern(22) xor dintern(32); -- For N equals thirty two      

       else 
       feedback <= '1'; 
       end if; 
      end if;          
    end if; 
end process main; 

prbsout <= dintern(4) ; --Change Value of N Here to take output to top entity 

end Behavioral; 

在这里面我正在实例化的广告触发器模块

d FF模块代码

---------------------------------------------------------------------------------- 
-- Module Name: dff - Behavioral 
-- Project Name: 
-- Description: 
---------------------------------------------------------------------------------- 
library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 
use IEEE.STD_LOGIC_ARITH.ALL; 
use IEEE.STD_LOGIC_UNSIGNED.ALL; 

---- Uncomment the following library declaration if instantiating 
---- any Xilinx primitives in this code. 
--library UNISIM; 
--use UNISIM.VComponents.all; 

entity dff is 
    Port (dclock : in STD_LOGIC ; 
      dreset : in STD_LOGIC ; 
      din : in STD_LOGIC; 
      dout : out STD_LOGIC); 
end dff; 

architecture Behavioral of dff is 

begin 
process(dclock) 

begin 
    if dclock'event and dclock = '1' then 
     if dreset = '0' then 
      dout <= din; 
     else 
      dout <= '1'; 
     end if; 
    end if; 
end process; 


end Behavioral; 

但我没有得到所需的输出。 在顶级实体中,我总是在检测信号时收到1。

当我尝试模拟然后prbsout信号变得不确定。

我失踪了?

回答

3

presetprbs模块复位不适用于feedback信号, 大概是因为目的是使用的0在 分配feedback信号的声明中的初始值。然而,由于dff模块 采用同步复位,并且dintern信号将被未驱动U在启动, 并且由于在一个 XOR使用dintern(1)计算用于feedback然后下一个值,所述反馈将得到开始后未定义正确的,并且可以即使应用冗长的重置,也不会恢复, 。参见下面ModelSim的波形。

Before preset applied to feedback

为复位问题立即解决此问题是为feedback也适用复位在 的main过程:

... 
else -- preset /= '0' 
    feedback <= '0'; 
... 

现在至少复位作品,并且可以使prbs生成序列。见下面的 波形。

After preset applied to feedback

只是为了代码的一些补充意见,而在它:

  • 相反的dclock'event and dclock = '1'可以使用rising_edge(dclock), 我认为必须读者会发现更容易理解,并它少了 容易出错

  • 对于大多数工具,没有必要为制作一个separte模块触发器,就像dff模块一样,因为即使高级表达式用于信号 使用分配,工具也可直接从该过程推断触发器 。

,我不认为输出是你真正想要的东西。根据您的设计以及选定的LFSR抽头,看起来您要生成最大长度的LFSR序列,即长度为2 ** N - 1 的序列,对于长度为N位的LFSR寄存器。

LFSR的原理和用于反馈生成的抽头在Wikipedia上描述为 :Linear feedback shift register

然而,由于feedback信号作为触发器产生的,它成为LSFR移位寄存器的 部分,从而增加了一个位于该长度,但抽头 值基于LFSR的dintern部分只有,水龙头将是 错误。选择错误的位会导致LFSR序列比最大序列少 ,并且您还可以看到,在模拟输出中, 其中序列只有6个周期长,即使通过dintern(4 downto 1) + feedback在一起也会产生一个5位寄存器。

所以prbs模块进行更彻底的重写是必需的,如果你想要什么 是产生最大长度PRBS序列,以下是如何 的prbs模块可以写一个例子:

library ieee; 
use ieee.std_logic_1164.all; 

entity prbs_new is 
    generic(
    BITS : natural); 
    port(
    clk_i : in std_logic; 
    rst_i : in std_logic; 
    prbs_o : out std_logic); 
end entity; 


library ieee; 
use ieee.numeric_std.all; 

architecture syn of prbs_new is 

    signal lfsr : std_logic_vector(BITS downto 1); -- Flip-flops with LFSR state 

    function feedback(slv : std_logic_vector) return std_logic is -- For maximum length LFSR generation 
    begin 
    case slv'length is 
     when 3  => return slv(3) xor slv(2); 
     when 4  => return slv(4) xor slv(3); 
     when 8  => return slv(8) xor slv(6) xor slv(5) xor slv(4); 
     when 16  => return slv(16) xor slv(15) xor slv(13) xor slv(4); 
     when 32  => return slv(32) xor slv(22) xor slv(2) xor slv(1); 
     when others => report "feedback function not defined for slv'lenght as " & integer'image(slv'length) 
        severity FAILURE; 
        return 'X'; 
    end case; 
    end function; 

begin 

    process (clk_i, rst_i) is 
    begin 
    if rising_edge(clk_i) then 
     if unsigned(lfsr) /= 0 then 
     lfsr <= lfsr(lfsr'left - 1 downto lfsr'right) & feedback(lfsr); -- Left shift with feedback in 
     end if; 
    end if; 
    if rst_i = '1' then -- Asynchronous reset 
     lfsr <= std_logic_vector(to_unsigned(1, BITS)); -- Reset assigns 1 to lfsr signal 
    end if; 
    end process; 

    prbs_o <= lfsr(BITS); -- Drive output 

end architecture; 

评论到'prbs_new'模块

  • 通用BITS加入如此不同势LFSR长度可以从相同的代码进行。

  • 端口被命名为“_i”输入和“_O”用于输出的,因为在与多个 模块顶层跟踪信号时这个命名 convension是非常有用的。

  • 使用VHDL标准包ieee.numeric_std代替 非标准包ieee.std_logic_unsigned

  • 异步复位用于代替同步复位和初始值在 的信号声明。

    • 在同步复位的优点是,异步复位典型 适用于在FPGA和ASIC 技术,而不是在潜在时序关键数据路径,由此 设计可以触发器专用输入快点。

    • 信号衰减的初始值优势在于FPGA和ASIC技术更有可能实现这一点;有 情况下,不支持初始值。功能重置 可以在测试平台上重新启动,而无需重新加载 模拟器。

  • 没有检查的过程中lfsr信号的全0值, 因为lfsr永远如果适当的最大长度水龙头 用于获得全0值,lfsr信号被重置为非0值。

+0

太棒了。 –

0

它看起来像你永远不会将你的内部状态(dintern)设置为已知值。由于所有后来的状态都是从你的初始时间值计算出来的,所以它们也是未知的。尝试为dintern分配一个初始状态,或者修改预设代码,以便在预设为高时实际执行某些操作(然后在测试台启动时将其断言)。