Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
18 years ago

std_logic to std_logic_vector in port map

I am newbie in VHDL design and reading literature did not help ...

I created entity to sync signal(s) to clk. I would like to have it generic and use it for both single signals (n=1) and vectors (n>1). The entity is declared as:

entity sync2 is
    generic (
        n           : positive := 2      -- width
    );
    port (
        -- inputs
        d           : in  std_logic_vector (n-1 downto 0);
        clk         : in  std_logic;     -- clock
        reset       : in  std_logic;     -- asynchronous reset
        -- outputs
        q           : out std_logic_vector (n - 1 downto 0)
    );
end entity sync2;

It works perfectly for vectors but I do not know, how to connect std_logic signal to the input vector, which is in this case std_logic_vector(0 downto 0);

Or is it possible to overload the declaration so the d is std_logic?

signal sig1    : std_logic;
signal sig2    : std_logic;
-------------------------------------------------------------------------------
-- Instantiation of entity
-------------------------------------------------------------------------------
    sync : entity work.sync2
        generic map ( n => 1 )
        port map (
            d              => sig1,
            q              => sig2,
            reset          => reset,
            clk            => clk
        );

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    If n is say 2 and you want just put a std logic signal into d you have to do something like

    d => '0' & sig1,

    which fills up the other spaces with zero.

    If n = 3 it'll be

    d => "00" & sig1,

    notice the double quotation marks this time.

    & is used for concatination in VHDL.

    Cheers
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Yes, but what if n = 1. How do I code it? In meantime i found i can use following syntax:

        sync : entity work.sync2
            generic map ( n => 2 )
            port map (
                d(0)          => sig1,
                q(0)           => sig2,
                reset          => reset,
                clk            => clk
            );