2×1 Multiplexer Verilog code Using Vivado @ Xilinx Basys3 FPGA

2x1 Multiplexer

2×1 Multiplexer (mux) is a fundamental building block used to select one of multiple input signals and route it to the output based on a control signal. This is one of the simplest forms of mux and is widely used in digital circuits. In this blog post, we’ll explore how to implement a it using Verilog code.

What is of 2×1 Mux

A 2×1 multiplexer (2×1 Mux) is similar to a digital switch that selects one of two input signals and forwards the selected input to a single output line.

A 2×1 Mux has two data inputs (i0 and i1), one select input (s), and one output (out). The select input s determines which input (i0 or i1) is passed to the output out

The Truth Table

To understand the operation, look at its truth table:

2x1 multiplexer symbol
2x1 multiplexer truth table

Verilog Code: 2×1 MUX

Code Explanation

  1. Module Declaration and Ports:
    • input [7:0] i0: 8-bit data input 0.
    • input [7:0] i1: 8-bit data input 1.
    • input s: Select input (control signal).
    • output [7:0] out: 8-bit output.
  2. Internal Signal:
    • wire [7:0] w;: Wire to store the 8-bit control signal.
  3. Control Signal Generation:
    • assign w = {8{s}};: Generates an 8-bit control signal w based on the select input s. This is achieved by replicating the value of s across all bits of w.
  4. Multiplexer Logic:
    • assign out = (i0 & ~w) | (i1 & w);: Performs the mux operation. If s is 0, w is all zeros, so i0 is selected (out = i0). If s is 1, w is all ones, so i1 is selected (out = i1).

Verilog testbench code : 2×1 mux

Constraints file : Basys3 board

Modify this file when you are preparing for synthesis, implementation, and bitstream generation. Be sure to activate the necessary properties when using it. You can ignore this file for simulation purposes.

Schematic : 2×1 mux

2x1 mux schematic diagram

Simulation: 2×1 mux

2x1 mux simulation diagram

Conclusion

The 2×1 Multiplexer is a versatile and essential component in digital design. It allows us to efficiently select between two data sources based on a control signal. Verilog provides a straightforward way to implement this behavior, making it a powerful tool in FPGA and ASIC designs.

In this blog post, we explored the Verilog implementation of a 2×1 Mux, highlighting its structure, operation, and example usage. Understanding and mastering the 2×1 Mux will enable you to design more complex digital systems with ease.

Stay tuned for more insights into digital design and Verilog programming!

<—Prev

8-bit Full Adder Verilog code

Next —->

3 thoughts on “2×1 Multiplexer Verilog code Using Vivado @ Xilinx Basys3 FPGA”

  1. assign w = {8{s}};The notation {8{s}} is Verilog’s replication operator. It replicates the single bit s 8 times to create an 8-bit wide signal. For example:If s = 0, then w = 8’b00000000.If s = 1, then w = 8’b11111111.

  2. This module can be further optimise. But I want it to be used only digital logic gates and circuit rather than using other methods.
    In upcoming model, I will use only flip-flops and other digital logic gates. This will help to better understand the actual implementation of circuit component rather than using loops for the same.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top