私はVHDLを学んでおり、プロジェクトを含めるよりも学ぶのに良い方法があります。したがって、私のプロジェクトの一部は、小さなメモリコンポーネントを作成することです。
これが私の完全なコードです:
entity memory is
port(
Address: in std_logic_vector(15 downto 0); --memory address
Write: in std_logic; --write or read
UseTopBits: in std_logic; --if 1, top 8 bits of data is ignored and not written to memory
Clock: in std_logic;
DataIn: in std_logic_vector(15 downto 0);
DataOut: out std_logic_vector(15 downto 0);
Reset: in std_logic
);
end memory;
architecture Behavioral of memory is
constant SIZE : integer := 4096;
type memorytype is array(0 to (size-1)) of std_logic_vector(7 downto 0);
signal mem: memorytype;
begin
resetmem: process(Clock, Reset) --this process is the troublemaker
begin
if(Reset ='1' and rising_edge(Clock)) then
mem <= (others => "00000000");
end if;
end process;
writemem: process(Reset,Write, Address, UseTopBits, Clock)
variable addr: integer;
begin
addr := conv_integer(Address);
if(addr>size-1) then
addr:=0;
end if;
if(Write='1' and Reset='0') then
if(rising_edge(clock)) then
mem(conv_integer(addr)) <= DataIn(7 downto 0);
if(UseTopBits='1') then
mem(conv_integer(addr)+1) <= DataIn(15 downto 8);
end if;
end if;
end if;
end process;
readmem: process(Reset,Address,Write,Clock)
variable addr: integer;
begin
addr := conv_integer(Address);
if(addr>size-1) then
addr:=0;
end if;
if(Reset='1') then
DataOut <= (others => '0');
elsif(Write='0') then
DataOut <= mem(conv_integer(addr)+1) & mem(conv_integer(addr));
else
DataOut <= (others => '0');
end if;
end process;
end Behavioral;
リセットプロセスを追加する前は、テストベンチに従ってコードは正常に機能していました。今それを追加した後、私はにあらゆる種類の奇妙さを得るDataOut
。一見ランダムなビットは、またはのX
代わりにの論理状態になり、これにより、すべてのテストベンチが失敗します(そうあるべきです)0
1
writemem
次のようにコードをプロセスに入れることで修正しました。
begin
--where resetmem process was
writemem: process(Reset,Write, Address, UseTopBits, Clock)
variable addr: integer;
begin
addr := conv_integer(Address);
if(addr>size-1) then
addr:=0;
end if;
if(Reset ='1' and rising_edge(Clock)) then --code is now here
mem <= (others => "00000000");
elsif(Write='1' and Reset='0') then
if(rising_edge(clock)) then
mem(conv_integer(addr)) <= DataIn(7 downto 0);
if(UseTopBits='1') then
mem(conv_integer(addr)+1) <= DataIn(15 downto 8);
end if;
end if;
end if;
end process;
そのため、この問題は現在修正されていますが、resetmemを別のプロセスとして使用すると、これらの奇妙な問題がすべて発生した理由がわかりません。誰かがこれがどのように起こったかについていくつかの光を当てることができますか?