Ripple chain logic in VHDL

Joined
Aug 2, 2007
Messages
7
Reaction score
0
Hi,

What is the best way to write a vhdl code for the following encoded logic?

If there is a 4 bit register and you only need to select the first '1' in that register starting from LSB and set all others to zero, how can that be written up in VHDL? I need to do this for a 32 bit register and I cant believe writing up the whole logic (one huge concurrent statement for each bit, especially the MSBs) is the best way to do it. Can anyone here suggest any alternatives?

eg: 1011 needs to be 0001
1100 needs to be 0100
1110 needs to be 0010 etc.


Thanks a lot- any help would be greatly appreciated.

Govinda
 
Joined
Mar 10, 2008
Messages
348
Reaction score
0
Ok try this

PHP:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity logic_test1 is
    Port ( A : in  std_logic_vector(5 downto 0);
           Y : out std_logic_vector(5 downto 0));
end logic_test1;

architecture Behavioral of logic_test1 is

begin
   process( A)
	   variable i,j: integer;
   begin
	   Y <= (others => '0'); 
	   i := 1;
		j := 0;
	   while i < 2**5 loop
		 	if A(j)='1' then
			   Y <= Conv_std_logic_vector(i,6);
				exit;
         end if;
			i := i * 2;
			j := j + 1;
		end loop; 
	end process;

end Behavioral;
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top