VHDL语言中的PRBS生成模块
这里我发布了一个PRB的快照 我的prbs模块代码为VHDL语言中的PRBS生成模块,vhdl,Vhdl,这里我发布了一个PRB的快照 我的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 ----------------------------------------------------------------
-- 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;
--模块名称:prbs-行为
--工程名称:调制器
--说明:
--要使其为N位,请将现有的N值替换为所需的N值
----------------------------------------------------------------------------------
图书馆IEEE;
使用IEEE.STD_LOGIC_1164.ALL;
使用IEEE.STD_LOGIC_ARITH.ALL;
使用IEEE.STD_LOGIC_UNSIGNED.ALL;
----如果正在实例化,请取消对以下库声明的注释
----此代码中的任何Xilinx原语。
--UNISIM图书馆;
--使用UNISIM.VComponents.all;
实体prbs是
端口(pclock:标准_逻辑中;
预设:在标准逻辑中:='0';
prbsout:输出标准逻辑);
结束PRB;
prbs的体系结构是
组件dff是
港口(
dclock:标准逻辑中;
dreset:标准逻辑中;
din:标准逻辑;
dout:输出标准逻辑
);
端部元件;
信号单元:标准逻辑向量(4到1)--改变N的值以改变移位寄存器的大小
信号反馈:标准逻辑:='0';
开始
instdff:dff端口映射(pclock、预置、反馈、dintern(1));
genreg:对于2到4中的i生成——在这里更改N的值以生成这么多的d触发器实例
开始
instdff:dff端口图(pclock、预设、dintern(i-1)、dintern(i));
端生成genreg;
主:进程(pclock)
开始
如果pclock'事件和pclock='1',则
如果预设值为“0”,则
如果dintern/=“0”,则
反馈看起来您从未将内部状态(dintern)设置为已知值。由于所有后续状态都是根据初始dintern值计算的,因此它们也是未知的。尝试将初始状态分配给dintern,或修复预设代码,以便在预设值较高时实际执行某项操作(然后在测试台开始时进行断言)。预设时的prbs
模块重置不适用于反馈信号,
可能是因为其目的是使用中指定的初始值0
反馈信号的声明。但是,由于dff
模块
使用同步复位,启动时,dintern
信号将被解除驱动U
,
从那时起,反馈的下一个值
是使用dintern(1)
在
xor,启动后反馈将被取消定义,无法恢复,
即使应用了长时间的重置。请参见下面ModelSim的波形
重置问题的一个即时解决方案是对反馈
也在中应用重置
main
过程:
...
else -- preset /= '0'
feedback <= '0';
...
对“prbs_新”模块的评论
- 添加了通用位,因此可以从相同代码中生成不同的LFSR长度
- 端口以“_i”命名表示输入,以“_o”命名表示输出,因为此命名
当在具有多个参数的顶层跟踪信号时,约定非常有用
模块
- 使用VHDL标准包ieee.numeric_std
代替
非标准包ieee.std\u logic\u unsigned
使用异步重置代替中的同步重置和初始值
信号声明
- 与同步重置相比,异步重置的优点是
适用于FPGA和ASIC中触发器的专用输入
技术,而不是潜在的时间关键数据路径
设计可以更快
- 与初始值相比,FPGA和
ASIC技术更有可能实现这一点;有
不支持初始值的情况。还有功能复位
使在试验台上重新启动成为可能,而无需重新加载
模拟器
在此过程中,没有检查lfsr
信号的all-0值,
因为如果正确的最大长度轻敲,lfsr
将永远不会得到全0值
使用,并且将lfsr
信号重置为非0值
...
else -- preset /= '0'
feedback <= '0';
...
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;