Engineers Garage

  • Electronic Projects & 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

Verilog Tutorial 13: How to design a 3×8 decoder and an 8×3 encoder in VHDL

By Ashutosh Bhatt June 5, 2025

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

In the previous Verilog Tutorial – 12, we learned how to design half and full-subtractor circuits in Verilog.

In this tutorial, we’ll:

  1. Write a Verilog program for building circuits for a 3×8 decoder and an 8×3 encoder
  2. Verify the output waveform of the program (digital circuit) with the given truth tables for the encoder and decoder circuits

The 3×8 decoder circuit:

Truth table

Next, let’s write the Verilog program, compile and simulate it, and get the output in a waveform. We’ll also verify the output waveforms with the given truth table.

First, it’s important to review the step-by-step procedure provided in VHDL Tutorial – 3. In that tutorial, we learn how to design a project, edit and compile a program, create a waveform file, simulate the program, and generate the final output waveforms.

Verilog program

Gate-level modeling:

module decoder3x8(a,b,c,d);
  input a,b,c;
   output [0:7] d;
   wire a_not,b_not,c_not;
     not(a_not,a);
     not(b_not,b);
     not(c_not,c);
     and(d[0],a_not,b_not,c_not);
     and(d[1],a,b_not,c_not);
and(d[2],a_not,b,c_not);
     and(d[3],a,b,c_not);
     and(d[4],a_not,b_not,c);
     and(d[5],a,b_not,c);
     and(d[6],a_not,b,c);
     and(d[7],a,b,c);
   endmodule

Dataflow modeling:

 module decoder3x8(a,b,c,d);
  input a,b,c;
  output [0:7] d;
     assign d[0] = ~a & ~b & ~c;
     assign d[1] = a & ~b & ~c;
     assign d[2] = ~a & b & ~c;
     assign d[3] = a & b & ~c;
     assign d[4] = ~a & ~b & c;
     assign d[5] = a & ~b & c;
     assign d[6] = ~a & b & c;
assign d[7] = a & b & c;
  endmodule

Now, compile the above program, creating a waveform file with all of the necessary inputs and outputs that are listed, and simulate the project. 

Here are the results…

Waveform simulation

Be sure to verify the D0-D7 output. You’ll note that only one output is high at a time. All of the others are then low, as per the given input A0-A1-A2 combinations from ‘000’ to ‘111.’

Next, let’s build the 8×3 encoder circuit.

The 8×3 encoder circuit:

Truth table

Verilog program

Gate-level modeling:

module encoder8x3(a,b,c,d);
  input [0:7] d;
  output a,b,c;
     or(c, d[1], d[3], d[5], d[7]);
     or(b, d[2], d[3], d[6], d[7]);
     or(a, d[4], d[5], d[6], d[7]);
endmodule

Dataflow modeling

module encoder8x3(a,b,c,d);
  input [0:7] d;
  output a,b,c;
     assign c = d[1] | d[3] | d[5] | d[7]);
     assign b = d[2] | d[3] | d[6] | d[7]);
     assign a = d[4] | d[5] | d[6] | d[7]);
endmodule

Simulation waveforms

As shown above, the input output waveforms looks similar to those of the decoder. This is because the encoder is simply the reverse of the decoder. So the input becomes output, and vice versa.

In the encoder example, when D7’s input is ‘1,’ the outputs are ‘a = 1,’ ‘b=1,’ and ‘c=1.’ You can verify other combinations based on the truth table.

In next tutorial, we’ll design circuits for an 8×1 multiplexer and a 1×8 de-multiplexer by using Verilog.

 

You may also like:


  • Verilog Tutorial 12: How to design 8-bit parity generator and…

  • Verilog Tutorial 11: How to design half and full-subtractor circuits…

  • Verilog Tutorial 10: How to design half and full-adder circuits…

  • Verilog Tutorial 9: How to design a digital circuit for…

  • How to use NOR as the universal gate in Verilog

  • How to design, simulate, and verify all digital gates in…

  • How to compile, simulate, and verify a Verilog program using…

  • What is Verilog, its features, and design flow?- Part 2

  • What are the fundamentals of Verilog programs?-Part 1

  • How to use NAND as a universal gate in Verilog

  • How to design a digital circuit using VHDL

Filed Under: Tutorials
Tagged With: circuit, decoder, encoder, tutorial, verilog, VHDL
 

Next Article

← Previous Article
Next Article →

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



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

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

  • 21V keeps getting shorted to my UART line.
  • Voltage mode pushpull is a nonsense SMPS?
  • Voltage mode push pull with extra DC blocking capacitor
  • NXP library issue in awr
  • Confused About Atomicity

RSS Electro-Tech-Online.com Discussions

  • Is AI making embedded software developers more productive?
  • Why can't I breadboard this oscillator?
  • using a RTC in SF basic
  • Parts required for a personal project
  • Cataract Lens Options?

Featured – RPi Python Programming (27 Part)

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol
  • RPi Python Programming 26 – Interfacing ADXL345 accelerometer sensor with Raspberry Pi

Recent Articles

  • GigaDevice launches GD32C231 MCU series with 48MHz Cortex-M23 core and 64KB Flash
  • Advanced Energy releases 425 W CF-rated medical power supply in 3.5 x 6 x 1.5-inch format”
  • LEM combines shunt and Hall effect sensing in 2000 A current measurement unit
  • What is AWS IoT Core and when should you use it?
  • AC-DC power supply extends voltage range to 800 V DC

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

  • Electronic Projects & 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