Hex to 7 segment decoder Verilog code Using Vivado @ Xilinx Basys3 FPGA

Hex to 7 segment decoder common anode circuit

In this blog post, we will create a Verilog module named Hex to 7 segment decoder that performs this conversion. The module takes a 4-bit input and produces a 7-bit output to drive a 7-segment display.

Converting a 4-bit hexadecimal value to a 7-segment display output is a common task in digital design, especially when working with embedded systems and FPGA projects.

What is Hex to 7 segment decoder

A Hex to 7-segment decoder is a digital circuit that converts a 4-bit hexadecimal input (ranging from 0 to F) into signals that can drive a 7-segment display. The 7-segment display is commonly used in digital clocks, calculators, and other devices to display numerical digits.

Understanding the 7-Segment Display

For this project, we are using a 7-segment display with a common anode configuration. In a common anode display, all the anodes of the LEDs are connected together while the cathodes are individually connected to the controller.

In the common-anode case, an output 0 will turn on a segment and an output 1 will turn it off.

For a better understanding of the connection and total number of segments available on the basys3 FPGA board, please refer to this Document.

To get the most optimal boolean logic expression, refer to Chapter 9 of this Document. This will help you solve the K-map and further reduce the expression.

7 segment display
7 segment display connection diagram
7 segment truth table

Verilog Code: Hex to 7 segment decoder

Code Explanation

The hex7seg module accepts a 4-bit input (i) representing a hexadecimal digit and producing a 7-bit output (seg) that drives a 7-segment display to show the corresponding hexadecimal value.

Detailed Explanation

  1. Module Declaration:
    • module hex7seg(input [3:0] i, output [6:0] seg);
    • The module has a 4-bit input (i) and a 7-bit output (seg).
  2. Input Bit Assignment:
    • For clarity, each bit of the input i is assigned to a separate wire (i3, i2, i1, i0).
  3. Segment Logic:
    • Each segment (seg[0] to seg[6]) is driven by a combination of the input bits. The logic for each segment is derived from the truth table of a 7-segment display for hexadecimal digits.

Functionality

The 7-segment display has 7 segments, labeled a to g, which are mapped to seg[6] to seg[0] respectively. The segments are controlled based on the input value i (ranging from 0 to 15 in hexadecimal). The logic equations ensure that the correct segments are lit up to display the hexadecimal digit

Verilog testbench code : Hex to 7 segment decoder

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 : Hex to 7 segment decoder

hex to seven segment decoder

Simulation: Hex to 7 segment decoder

hex to seven segment decoder schematic

Conclusion

In this post, we designed a Verilog module to convert a 4-bit hexadecimal input to a 7-segment display output, specifically for a common anode 7-segment display. This module is particularly useful in various digital design applications where hexadecimal numbers need to be displayed on 7-segment displays, such as in FPGA-based projects.

We also provided a testbench to verify the functionality of the hex7seg module. Using the Basys3 FPGA, you can easily integrate this module into your projects to display hexadecimal values on the onboard 7-segment display. Feel free to adapt and modify this module as needed for your specific requirements. Happy coding with your Basys3 FPGA!

Stay tuned for more insightful articles on digital design and Verilog programming!

<—Prev

sign changer Verilog code

Next —->

Leave a Comment

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

Scroll to Top