In the world of digital design, multiplexers (often referred to as Mux) play a crucial role in selecting one out of multiple input signals and routing it to a single output line. These versatile devices are extensively used in Field-Programmable Gate Arrays (FPGAs) and come in various sizes and configurations, such as 2-to-1, 4-to-1, and 8-to-1 multiplexers. In this tutorial, we’ll explore the fundamentals of multiplexers and walk you through the process of designing and implementing 2-to-1 and 4-to-1 multiplexers using VHDL (VHSIC Hardware Description Language).

What is a Multiplexer?

A multiplexer acts like a data selector, allowing you to choose between different input sources and forwarding the chosen input to an output line. Imagine it as a digital switch that can connect one of its input lines to the output line based on a control signal. This is incredibly useful in various digital circuits, such as routing data from multiple sources to a single destination or selecting between multiple operations.

Basics of a 2-to-1 Multiplexer

Let’s begin by understanding the basic structure of a 2-to-1 multiplexer. Here’s a simplified block diagram:

Multiplexers block

In this diagram, “A” and “B” are the input data lines, and “Select” is the control signal that determines which input to forward to the output. The result of the selection is sent to the “Output” line.

VHDL Implementation: 2-to-1 Multiplexer

Now, let’s dive into the VHDL implementation of a 2-to-1 multiplexer. Below is the VHDL code that defines a 2-to-1 multiplexer:

library IEEE;

entity Mux_2_to_1 is
    port (
        i_Select : in  std_logic;
        i_Data1  : in  std_logic;
        i_Data2  : in  std_logic;
        o_Data   : out std_logic
end Mux_2_to_1;

architecture Behavioral of Mux_2_to_1 is
    o_Data <= i_Data1 when i_Select = '0' else i_Data2;
end Behavioral;

In this VHDL code, we define an entity named Mux_2_to_1 with input signals i_Select, i_Data1, and i_Data2, and an output signal o_Data. The architecture block, named Behavioral, specifies the logic of the multiplexer. When i_Select is ‘0’, the output o_Data will be the value of i_Data1; otherwise, it will be the value of i_Data2.

Extending to Width Parameter and 4-to-1 Multiplexer

To increase the flexibility of our multiplexer, we can introduce a width parameter to handle different data widths. Additionally, we’ll demonstrate how to implement a 4-to-1 multiplexer. Here’s the VHDL code for both:

-- Mux with Width Parameter
entity Mux_2_To_1_Width is
    generic (
        g_WIDTH : integer := 8
    port (
        i_Select : in  std_logic;
        i_Data1  : in  std_logic_vector(g_WIDTH-1 downto 0);
        i_Data2  : in  std_logic_vector(g_WIDTH-1 downto 0);
        o_Data   : out std_logic_vector(g_WIDTH-1 downto 0)
end Mux_2_To_1_Width;

architecture Behavioral of Mux_2_To_1_Width is
    with i_Select select
        o_Data <=
            i_Data1 when '0',
            i_Data2 when others;
end Behavioral;

-- 4-to-1 Multiplexer
entity Mux_4_To_1 is
    port (
        i_Select : in  std_logic_vector(1 downto 0);
        i_Data1  : in  std_logic;
        i_Data2  : in  std_logic;
        i_Data3  : in  std_logic;
        i_Data4  : in  std_logic;
        o_Data   : out std_logic
end Mux_4_To_1;

architecture Behavioral of Mux_4_To_1 is
    case i_Select is
        when "00" =>
            o_Data <= i_Data1;
        when "01" =>
            o_Data <= i_Data2;
        when "10" =>
            o_Data <= i_Data3;
        when others =>
            o_Data <= i_Data4;
    end case;
end Behavioral;

In the above code, the Mux_2_To_1_Width entity introduces a generic parameter g_WIDTH for handling different data widths. The Mux_4_To_1 entity implements a 4-to-1 multiplexer with four input lines and a two-bit select signal.

Download Source Code

Related Post

Notify of

Inline Feedbacks
View all comments
Search Tutorial
Tutorial Categories