Engineers Garage

  • Electronics Projects and Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

VHDL Tutorial – 22: Designing a 1-bit & an 8-bit comparator by using VHDL

By Ashutosh Bhatt February 17, 2021

Note: it’s recommended to follow this VHDL tutorial series in order, starting with the first tutorial.

In the previous tutorial, VHDL Tutorial – 21, we designed an 8-bit, full-adder circuit by using VHDL.

In this tutorial, we will:

  • Write a VHDL program that builds a 1-bit and an 8-bit comparator circuit
  • Verify the output waveform of the program (digital circuit) with comparator circuit operation

The 1-bit comparator circuit

Truth table

Now, let’s write, compile, and simulate a VHDL program. Then, we’ll get the output in waveform and verify it with the given truth table.

Before starting, be sure to review the step-by-step procedure provided in VHDL Tutorial – 3 to design the project. It will ensure that you properly edit and compile the program and the waveform file, as well as the final output.

VHDL program

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity comparator_1bit is
    Port ( A,B : in std_logic;
           G,S,E: out std_logic);
end comparator_1bit;

architecture comp_arch of comparator_1bit is
  begin
   G <= A and (not B);
   S <= (not A) and B;
   E <= A xnor B;
end comp_arch;

It may help to review the first two VHDL tutorials (1 and 2) of this series to refresh you memory about how this works.

Next, compile the above program, creating and then saving a waveform file with all of the necessary inputs and outputs that are listed (ensuring you apply all of the different input combinations). Then, simulate the project. You should get the following result…

As per this figure, the output of ‘G’ and ‘E’ are highlighted in red and blue, respectively, for A>B and A=B.

Next, let’s expand this from a 1-bit to an 8-bit comparator. To do so using VHDL, we’ll employ a behavioral modeling style because it’s easier than the two other styles.

The 8-bit comparator VHDL program

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity comparator_8bit is
    Port ( A,B : in std_logic_vector(0 to 7);
           G,S,E: out std_logic);
end comparator_8bit;

architecture comp_arch of comparator_8bit is
  begin
   process
     begin
if A=B then
           G <= ‘0’;
           S <= ‘0’;
           E <= ‘1’;
       elsif A>B then
           G <= ‘1’;
           S <= ‘0’;
           E <= ‘0’;
      elsif A<B then
           G <= ‘0’;
           S <= ‘1’;
           E <= ‘0’;
      end if;
    end process;
end comp_arch;

Simulation waveform

As shown in this figure, the three results are highlighted in red, blue, and green, representing A>B, A<B, and A=B.

This is the final tutorial of this VHDL series. You can find additional programs for different digital circuits online and practice them to get more “hands-on” experience with VHDL programming. Keep learning and you’ll keep progressing!

 

You may also like:

  • beginners guide
    Basic Electronics 01 – Beginners guide to setting up an…

  • VHDL Tutorial 18: Design a T flip-flop (with enable and…

  • VHDL Tutorial – 19: Designing a 4-bit binary counter using…

  • VHDL Tutorial – 20: Designing 4-bit binary-to-gray & gray-to-binary code…

Filed Under: Tutorials, VHDL, VHDL

 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • RFsoc 4x2 DAC0/ADC structure behind parameters in code
  • Colpitts oscillator
  • RF-DC rectifier impedance matching
  • GanFet power switch starts burning after 20 sec
  • Four-MOSFET Synchronous Rectification for High-Efficiency LLC Converter

RSS Electro-Tech-Online.com Discussions

  • Need Help Figuring Out the Schematics Of Circuit Board
  • Wish to buy Battery, Charger and Buck converter for 12V , 2A router
  • applying solder paste from a jar
  • Question i-nears headphones magnetic drivers
  • An Update On Tarrifs

Featured – Designing of Audio Amplifiers part 9 series

  • Basics of Audio Amplifier – 1/9
  • Designing 250 Milli Watt Audio Power Amplifier – 2/9
  • Designing 1 Watt Audio Power Amplifier – 3/9
  • Designing a Bass Boost Amplifier – 4/9
  • Designing a 6 Watt Car Audio Amplifier – 5/9
  • Design a low power amplifier for headphones- 6/9

Recent Articles

  • Sienna Semiconductor data converters feature sample rates from 20 to 250 Msps
  • Delta’s 5,500 W power supplies achieve 97.5% energy efficiency for AI servers
  • Novosense Microelectronics releases digital isolators with capacitive-based design
  • MIPI C-PHY adds encoding option to support next-gen image sensor applications
  • Littelfuse gate driver delivers 1.9 A source and 2.3 A sink output current

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronics Projects and Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe