VHDL: how to set a value on an inout port?
Asked Answered
H

4

10

I am trying to test a VHDL component, but I can't seem to get this one inout port to give me any behaviour. I've tried setting the port to everything from '1' to '-', but it still comes up as 'U' in simulation. Any sugestions what might be wrong?

Hornbook answered 2/10, 2009 at 16:32 Comment(1)
setting it explicitly to Z made the port give me the data, but now i cant seem to get the internal signals to read from the port :(Hornbook
D
21

For Inout port (for example in RAM):

....
port(
    data    :inout std_logic_vector (DATA_WIDTH-1 downto 0);
....
-- Memory Write Block
-- Write Operation : When we = 1, cs = 1
  MEM_WRITE: process (address, cs, we, data, address_1, cs_1, we_1, data_1) begin
    if (cs = '1' and we = '1') then
       mem(conv_integer(address)) <= data;
    end if;
  end process;

 -- Tri-State Buffer control
  data <= data_out when (cs = '1' and oe = '1' and we = '0') else (others=>'Z');

 -- Memory Read Block
  MEM_READ: process (address, cs, we, oe, mem) begin
    if (cs = '1' and we = '0' and oe = '1') then
      data_out <= mem(conv_integer(address));
    else
      data_out <= (others=>'0');
    end if;
  end process;

You assign data read and write for inout with a condition. When data is read, it is driven by another module. When it writes, it is driven by internal.

  • When driven by another module (as in signal), data is resolved between all 'Z' and a vector "0101010" for example. The data will driven as "0101010".
  • In the other case: the other module must drive data by all "Z" and then the internal signal can put its value to data.
Dictatorial answered 4/7, 2012 at 4:44 Comment(0)
N
9

You need an explicit driver to 'Z'.

Noman answered 2/10, 2009 at 17:30 Comment(1)
i realise this is the case, but i dont know what it means in vhdl codeHornbook
M
2

I've tried setting the port to everything from '1' to '-', but it still comes up as 'U' in simulation.

As an aside to the good answer on assigning/reading inout ports, the above quoted text could be related to the port being assigned to in two separate places, so it's resolved as 'U'.

Maxillary answered 3/7, 2013 at 20:11 Comment(0)
T
0

When using an inout port, I've been bitten by a synthesis tool instantiating an OBUF instead of an IOBUF when the VHDL statements were apparently too complicated for synthesis to infer the IOBUF. The following is a simplified example (assume all signals are std_logic) of the situation that bit me:

data_a <= '1' when assert_a = '1' else '0';
data_b <= 'Z' when float_b = '1' else '0';  
data_inout <= data_a when choose_a = '1' else data_b;

In my failure case, synthesis generated an OBUF for data_inout. I would have expected an IOBUF to handle the case of choose_a='0' and float_b='1' because that should have assigned 'Z' to data_inout, but that's not what I got.

Terza answered 3/1, 2019 at 18:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.