我是这个网站的新手,我有一个问题,我希望得到帮助。我正在编写一个 LFSR 的VHDL代码,它包含一个发送器和接收器。 发送器应该生成一个随机二进制数(前导码,它做),然后必须连接这个二进制数,但我首先需要将它放在STD_LOGIC_VECTOR中,这就是我遇到的问题。
这是我的testbench代码,其中必须进行此分配,感谢您提前提供的任何帮助:
library ieee;
use ieee.std_logic_1164.all;
entity testbench is --definig the entity
end testbench;
architecture tb1 of testbench is
component transmitter is port(
clk :in std_logic;
reset:in std_logic;
enable:in std_logic;
output :out std_logic);--output is the random generated binary which i need to pass to a vector
end component;
--type bit_vector is array (natural range <>) of bit; --this is so that we can define the whole thing otherwise bit can
--only be 1 or 0 this allows to define them as vectors
constant SOF: std_logic_vector(0 to 15) := "0101010100001010";
constant trailer: std_logic_vector(0 to 7) := "10111110";
constant payload: std_logic_vector(0 to 7) := "01110010";
constant L: std_logic_vector(0 to 7) := "00101110";
signal preamble: std_logic_vector(0 to 95);
signal clk , reset, enable : std_logic;--output signal
signal data_packet: std_logic_vector(0 to 135);
signal output: std_logic;
begin
--problem is here
--my attempt
get_preamble: process
variable i: std_logic;--this will be used to walk through the preamble vector and put the out put values in
--variable j: std_logic;
begin
n1: for i in 0 to 95 loop
if output = '1' then
preamble(i) <= '1';
end if;
end loop;
if output = '0' then
for i in 0 to 95 loop
preamble(i) <= '0';
end loop;
end if;
wait;
end process;--end of get_preamble
concatenation :process
begin
data_packet <= preamble & SOF & L & payload & trailer;
wait;
end process;
END tb1;
答案 0 :(得分:0)
for i in 0 to 95 loop
wait until rising_edge(clk);
preamble(i) <= output;
end loop;
data_packet <= preamble & SOF & L & payload & trailer;
答案 1 :(得分:0)
根据您的问题,您说您正在尝试将值output
与preamble
向量的其余部分连接起来。你应该改变这个:
n1: for i in 0 to 95 loop
if output = '1' then
preamble(i) <= '1';
end if;
end loop;
if output = '0' then
for i in 0 to 95 loop
preamble(i) <= '0';
end loop;
end if;
到此:
n1: for i in 0 to 95 loop
wait until clk'EVENT and clk = '1';
preamble(i) <= output
end loop;
由于你有一个时钟,当你的时钟有一个上升沿时,尝试获取每个值。您不需要每次都检查该值,您可以立即将其添加到矢量中。
编辑:您应该在其他进程中等待相同的事情,或者等待preamble
完成加载其96个值,具体取决于您要完成的任务。< / p>