3-Encoder and Decoder
3-Encoder and Decoder
College of Engineering
Computer Engineering Department
EXPERIMENT NO. 3
Binary Encoder Decoder
Learning Outcomes:
At the end of the experiment, the student should be able to:
1. Develop VHDL programs for Combinational Circuit Binary Encoder and Decoder.
2. Construct an EPWave of a Binary Encoder and Decoder.
Discussion:
Binary encoder has 2n input lines and n-bit output lines. It can be 4-to-2, 8-to-3,
and 16-to-4-line configurations. VHDL Code for 4-to-2 encoder can be designed
both in structural and behavioral modeling. Save and Run the Program.
Block Diagram
Schematic Diagram
Truth Table of 4 to 2 Encoder
INPUT OUTPUT
A3 A2 A1 A0 B1 B0
0 0 0 1 0 0
0 0 1 0 0 1
0 1 0 0 1 0
1 0 0 0 1 1
The std_logic_vector type can be used for creating signal buses in VHDL. The
std_logic is the most used type in VHDL, and the std_logic_vector is the array
version of it.
While the std_logic is great for modeling the value that can be carried by a single
wire, it’s not very practical for implementing collections of wires going to or from
components. The std_logic_vector is a composite type, which means that it’s a
collection of sub-elements. Signals or variables of the std_logic_vector type can
contain an arbitrary number of std_logic elements.
The syntax for declaring std_logic_vector signals is:
entity ENCODER_SOURCE is
Port (
I: in std_logic_vector (3 downto 0);
Y: out std_logic_vector (1 downto 0));
end ENCODER_SOURCE;
begin
end dataflow;
Copy and paste the given code below on the testbench area and save.
library IEEE;
use IEEE.std_logic_1164.all;
entity encoder_tb is
end entity;
architecture tb of encoder_tb is
component ENCODER_SOURCE is
Port (
I: in std_logic_vector (3 downto 0);
Y: out std_logic_vector (1 downto 0));
end component;
begin
stim: process
begin
I <= "0001";
wait for 20 ns;
I <= "0010";
wait for 20 ns;
I <= "0100";
wait for 20 ns;
I <= "1000";
wait for 20 ns;
wait;
end process;
end tb;
Save and Run the Program.
Take note of the following coding errors:
• One possible mistake is incorrect spacing.
• Always log out of your EDAPlayground account after completing a program.
• Always alter the top entity's and title's names because the top entity's and title's
names must be the same. Furthermore, testbench names like SampleCode1 must
be the same as the top entity name.
• The design's name must be the same as the design's name after beginning
architecture (for example, Design or_
• There must be no spaces in the design's name.
• You must input all the codes, or an error will occur.
Activity:
1. Create the VHDL Module of the 2 to 4 Decoder.
2. Produce the EPWave of the 2 to 4 Decoder in the space provided.
3. Write the design code. (Separate page)
4. Screenshot of EPWave for Decoder. (Separate page)
Question:
1. What are your observations from using EDA Playground in describing the code
for Encoder and Decoder?