1

Assume we have a 32 bit std_logic_vector of data. I want to add a logic '0' between every 2 bits. Take for example; all ones 11111....1111 is going to be 101010101....1010101.

3
  • how big should be your output, 64 bit? Aug 20, 2019 at 18:48
  • @GiampietroSeu 67 bits total. The last 4 bits(63 through 66) are going to be '0', think it's not big deal but couldn't think how adding '0' between them
    – huytergan
    Aug 20, 2019 at 18:51
  • Your description I wanna add logic '0' to between every 2 bits says you want to add 31 '0's, (between). Is your description erroneous or is the accepted answer?
    – user1155120
    Aug 21, 2019 at 1:49

1 Answer 1

2

You can add the '0' in between with a function:

function add_zeros(std_logic_vector_in : std_logic_vector) return std_logic_vector is
   variable std_logic_vector_out : std_logic_vector(std_logic_vector_in'length*2 -2 downto 0);
begin 
   for i in std_logic_vector_in'range loop
      std_logic_vector_out(i*2) := std_logic_vector_in(i);
      if (i /= std_logic_vector_in'length-1) then
         std_logic_vector_out(i*2+1) := '0';
      end if;
   end loop;
   return std_logic_vector_out;
end function;

For the final '0' you can add them with simple concatenation.

If you have:

signal initial_signal : std_logic_vector(31 downto 0);
signal final_signal   : std_logic_vector(66 downto 0);

Then you can just write:

final_signal   <= '0' & '0' & '0' & '0' & add_zeros(initial_signal);
3
  • I got what you've done, and I wonder that can't be done within a process with one clock? Same for loop inside the process.
    – huytergan
    Aug 20, 2019 at 19:21
  • @huytergan I'm not sure what you are asking, you can use the function inside a clocked process if that is your question Aug 20, 2019 at 19:26
  • I got it, highly appreciated!
    – huytergan
    Aug 20, 2019 at 19:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.