Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Problem with encoder

Reply
Thread Tools

Problem with encoder

 
 
xcellx xcellx is offline
Junior Member
Join Date: Oct 2008
Posts: 3
 
      10-02-2008
I'm trying to describe an encoder in behavioral style. This is my vhdl code:

Code:
entity encoder is
	generic(N: integer:=3);
	port(i1:  in bit_vector(2**N-1 downto 0);
		 o1: out bit_vector(N-1 downto 0));
end encoder;

architecture behavioral of encoder is
begin
	process(i1)
		variable k: integer;
	begin
		k:=0;
		while k<2**N and i1(k)='0' loop
			k:=k+1;
		end loop;
		if k=2**N then
			o1 <= (others => '0') after 5 ns;
		else
			for i in 0 downto N-1 loop
				if (k mod 2)=1 then
					o1(i) <= '1' after 5 ns;
				else
					o1(i) <= '0' after 5 ns;
				end if;
				k:=k/2;
			end loop;
		end if;
	end process;
end behavioral;

This is my testbench:


Code:
entity encoder_tb is
		generic(
		N : INTEGER := 3 );
end encoder_tb;

architecture TB_ARCHITECTURE of encoder_tb is
	component encoder
		generic(
		N : INTEGER := 3 );
	port(
		i1 : in BIT_VECTOR(2**N-1 downto 0);
		o1 : out BIT_VECTOR(N-1 downto 0) );
	end component;


	signal i1 : BIT_VECTOR(2**N-1 downto 0);
	signal o1 : BIT_VECTOR(N-1 downto 0);


begin

	UUT : encoder
		generic map (
			N => N
		)

		port map (
			i1 => i1,
			o1 => o1
		);

	i1 <= "00000000",
		  "10000000" after 100 ns,
		  "01000000" after 200 ns,
		  "00100000" after 300 ns,
		  "00010000" after 400 ns,
		  "00001000" after 500 ns,
		  "00000100" after 600 ns,
		  "00000010" after 700 ns,
		  "00000001" after 800 ns,
		  "10100100" after 900 ns,
		  "00001000" after 1000 ns,
		  "00100111" after 1100 ns,
		  "11111111" after 1200 ns;

end TB_ARCHITECTURE;

configuration TESTBENCH_FOR_encoder of encoder_tb is
	for TB_ARCHITECTURE
		for UUT : encoder
			use entity work.encoder(behavioral);
		end for;
	end for;
end TESTBENCH_FOR_encoder;

When I simulate the output is always "000". Debugging my code I saw that when the condition in the "if" is false, the "for" in the "else" doesn't execute, but I don't understand the reason!
Why doesn't it work?

 

Last edited by xcellx; 10-02-2008 at 04:28 PM..
Reply With Quote
 
 
 
 
xcellx xcellx is offline
Junior Member
Join Date: Oct 2008
Posts: 3
 
      10-07-2008
Nobody can help me?
 
Reply With Quote
 
 
 
 
jeppe jeppe is offline
Senior Member
Join Date: Mar 2008
Location: Denmark
Posts: 348
 
      10-07-2008
I believe the DOWNTO should be TO

Code:
entity encoder is
	generic(N: integer:=3);
	port(i1:  in bit_vector(2**N-1 downto 0);
		 o1: out bit_vector(N-1 downto 0));
end encoder;

architecture behavioral of encoder is
begin
	process(i1)
		variable k: integer;
	begin
		k:=0;
		while k<2**N and i1(k)='0' loop
			k:=k+1;
		end loop;
		if k=2**N then
			o1 <= (others => '0') after 5 ns;
		else
			for i in 0 TO N-1 loop
				if (k mod 2)=1 then
					o1(i) <= '1' after 5 ns;
				else
					o1(i) <= '0' after 5 ns;
				end if;
				k:=k/2;
			end loop;
		end if;
	end process;
end behavioral;
 
Reply With Quote
 
xcellx xcellx is offline
Junior Member
Join Date: Oct 2008
Posts: 3
 
      10-07-2008
Aaaaaaaaaaaaaaahhhhhhhhhhhhhhhhhh..........





Thank you very much............ you are right! Sorry for the stupid mistake......

Now I'm happy because i don't think yet my simulator is stupid but only I.
 

Last edited by xcellx; 10-07-2008 at 09:54 PM..
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Encoder counter problem samith VHDL 1 08-22-2009 07:31 AM
Bit stuffing in a Crc encoder jpereira VHDL 4 05-31-2005 04:57 AM
Pipelined binary encoder Fred Bartoli VHDL 1 11-10-2004 12:33 AM
N_bit decoder/encoder Gietek VHDL 4 12-04-2003 03:20 PM
manchester encoder Ronny Hengst VHDL 4 08-08-2003 01:23 PM



Advertisments