FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > VHDL

VHDL comp.lang.vhdl newsgroup / Usenet

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-02-2007, 06:35 PM
[email protected]
Guest
 
Posts: n/a
Default Generic multiplexer

Hello everybody,
I want to make generic multiplexer. I am using FOR/GENERATE to make
multiple code lines and conditional generate to make last line
(without ELSE). Please, suggest what to do and why my code doesn't
work. Thank you in advance.
----------------------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity gen_mux1 is
generic(n: integer:=3);
port (input : in std_logic_vector(2**n-1 downto 0);
sell : in std_logic_vector(n-1 downto 0);
output: out std_logic);
end gen_mux1;

architecture Behavioral of gen_mux1 is
begin

a: FOR i IN 0 TO 2**n-1 GENERATE
b1: IF i /= 2**n-1 GENERATE
output <= input(i) WHEN i = conv_integer(sel) ELSE
END GENERATE;
b2: IF i = 2**n-1 GENERATE
output <= input(i) WHEN OTHERS
END GENERATE;
END GENERATE;
end Behavioral;
-----------------------------------------------------------------------------------------------------------------
P.S. I want code to be concurrent.

Reply With Quote
  #2 (permalink)  
Old 10-02-2007, 09:34 PM
Andy
Guest
 
Posts: n/a
Default Re: Generic multiplexer

Use ieee.numeric_std instead of std_logic_[arith, unsigned].

Multiple concurrent assignments to the same signal (created by the
generate loop) create multiple drivers for that signal. Your attempt
could be modified to create a tristate mux (bus), but that is probably
not what you want either:

output <= input(i) when i = to_integer(unsigned(sel)) else 'Z';

Not sure what you're trying to do with 2nd If-generate...

You don't need the generate statements (loop or if) anyway:

-- since sel is constrained to be within input'range:
use ieee.numeric_std.all;
architecture concurrent of gen_mux1 is
begin
output <= input(to_integer(unsigned(sel)));
end architecture;

-- or this will work if value of sel could be
-- outside of input'range:
use ieee.numeric_std.all;
architecture sequential of gen_mux1 is
begin
process (input, sel) is
begin
output <= '0'; -- default assignment
for i in input'range loop
if i = to_integer(unsigned(sel)) then
output <= input(i);
end if;
end loop;
end process;
end architecture;

Andy

Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiplexer john VHDL 20 06-22-2006 09:03 PM
Multiplexer Index woko VHDL 2 08-05-2005 08:04 AM
Big multiplexer? bxbxb3 VHDL 5 04-19-2005 07:55 AM
Multiplexer... Julian Verilog 4 09-10-2004 11:53 AM
problems with 4 to 1 multiplexer Lily VHDL 6 04-29-2004 01:37 AM


All times are GMT +1. The time now is 03:00 AM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved