Continue to Site

# Connecting STD_LOGIC_VECTOR in different ways (Barrel Shifter)

Status
Not open for further replies.

#### HyperText

##### Junior Member level 2
I am realizing a N-bit Barrel Shifter.

Here it is my component:

Code:
entity barrel_shifter is
Generic ( N : integer := 4);
Port ( data_in : in  STD_LOGIC_VECTOR (N-1 downto 0);
shift : in  STD_LOGIC_VECTOR (integer(ceil(log2(real(N))))-1 downto 0); -- log2 of N => number of inputs for the shift
data_out : out  STD_LOGIC_VECTOR (N-1 downto 0));
end barrel_shifter;
For my purpose I've created an N-bit multiplexer too, and this is its code:

Code:
entity mux is
Generic ( N : integer := 4);
Port ( data_in : in  STD_LOGIC_VECTOR (N-1 downto 0);
sel : in  STD_LOGIC_VECTOR (integer(ceil(log2(real(N))))-1 downto 0); -- log2 of N => number of inputs for the shift
data_out : out  STD_LOGIC);
end mux;

architecture Behavioral of mux is

begin
data_out <= data_in(to_integer(unsigned(sel)));
end Behavioral;
Now to realize a Circular Barrel Shifter I need to connect these N multiplexer in different ways. You can find an example here, page 2, figure 1. As you can see IN0 is connected only one time to the D0 multiplexer input. The next time IN0 is connected to the D1 multiplexer input, and so on... (it's the same logic for the other inputs)

But how can I realize in VHDL something like that? If I hadn't STD_LOGIC_VECTOR as input it would be easy, but I need to make a generic Barrel Shifter (with generic map construct), so I can't manually connect each wire because I don't know the value of the generic N.

In my barrel_shifter entity I tried this:

Code:
architecture Structural of barrel_shifter is

signal q : STD_LOGIC_VECTOR (N-1 downto 0);

begin

connections: for i in 0 to N-1 generate
mux: entity work.mux(Behavioral) generic map(N) port map(std_logic_vector(unsigned(data_in) srl 1), shift, q(i));
end generate connections;

data_out <= q;

end Structural;
But it simply doesn't work ("Actual, result of operator, associated with Formal Signal, Signal 'data_in', is not a Signal. (LRM 2.1.1)"). I've tried using variable and signals, like this:

Code:
data_tmp := data_in(i downto 0) & data_in(N-i downto 1);
But I still couldn't figure out the right way to do these connections.

#### TrickyDicky

you cant use a variable, because the entity instantiation cannot be done inside a process. Try using a temporary signal instead (you can create the temp signal inside the generate):

Code:
connections : for i in 0 to N-1 generate
--you can put signals local to each iteration of the generate here
signal data_temp : std_logic_vector(N-1 downto 0);
begin

data_tmp <= data_in(i downto 0) & data_in(N-i downto 1);

mux: entity work.mux(Behavioral)
generic map( N => N)
port map(
data_in => data_tmp,
shift => shift,
q  => q(i)
);

end generate connections;

HyperText

### HyperText

Points: 2

#### HyperText

##### Junior Member level 2
Thanks, it works!

Last edited:

Status
Not open for further replies.