inout problem

C

csosza3

Hi,

I made a simple ram model to test inout but the testbench result not as
I expected.

If I remove the two last line
data <= "0011";
rw <= '0';
it is ok but if I add them the result is wrong. How can be modified
this design and the testbench to read and write data in normal way? I'd
like a simple ram model with working testbench.


library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity ram is port (
data : INOUT std_logic_vector( 3 downto 0 );
rw : IN std_logic );
end ram;

architecture arch of ram is
begin
process (rw)
variable data_s: std_logic_vector( 3 downto 0 ) := "0000";
begin
if ( rw = '0') then
data_s := data;
elsif ( rw = '1') then
data <= data_s;
end if;
end process;
end arch;

library ieee;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_1164.all;

entity ram_tb is
end ram_tb;

architecture TB_ARCHITECTURE of ram_tb is
component ram
port(
data : inout std_logic_vector(3 downto 0);
rw : in std_logic );
end component;

signal rw : std_logic;
signal data : std_logic_vector(3 downto 0);

begin

UUT : ram
port map (
data => data,
rw => rw
);

stm: process
begin
wait for 300 ns;

rw <= '1';
wait for 1300 ns;

data <= "0011";
rw <= '0';

wait;

end process;
end TB_ARCHITECTURE;


Thanks
Attila
 
A

Andy Peters

I made a simple ram model to test inout but the testbench result not as
I expected.

If I remove the two last line
data <= "0011";
rw <= '0';
it is ok but if I add them the result is wrong. How can be modified
this design and the testbench to read and write data in normal way? I'd
like a simple ram model with working testbench.

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

Why the std_logic_unsigned?????
entity ram is port (
data : INOUT std_logic_vector( 3 downto 0 );
rw : IN std_logic );
end ram;

architecture arch of ram is
begin
process (rw)
variable data_s: std_logic_vector( 3 downto 0 ) := "0000";
begin
if ( rw = '0') then
data_s := data;
elsif ( rw = '1') then
data <= data_s;
end if;
end process;
end arch;

library ieee;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_1164.all;

entity ram_tb is
end ram_tb;

architecture TB_ARCHITECTURE of ram_tb is
component ram
port(
data : inout std_logic_vector(3 downto 0);
rw : in std_logic );
end component;

signal rw : std_logic;
signal data : std_logic_vector(3 downto 0);

begin
UUT : ram
port map (
data => data,
rw => rw
);
stm: process
begin
wait for 300 ns;

rw <= '1';
wait for 1300 ns;

data <= "0011";
rw <= '0';

wait;

end process;
end TB_ARCHITECTURE;

Your problem is that you have two assignments to the same signal
(data). One assignment is in the RAM and the other's in the test
bench.

You need to tristate the RAM data, just like you'd do if you had a RAM
chip.

The testbench should tristate the data signal when it is doing a RAM
read.

Similarly, the RAM entity should tristate the data signal when you
write to the RAM.

-a
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top