7.priority Encoderronak
7.priority Encoderronak
Practical No. 07
Aim: Design 8:3 priority Encoder using generate statement and also write test bench for
same.
AIM: Design 8:3 priority Encoder using generate statement and also write test bench for
same.
OBJECTIVE:
• Use the generate statement to implement a scalable 8:3 priority encoder, optimizing
the selection of the highest-priority bit while reducing redundant logic.
• Implement a parameterized priority encoder using the generate block, allowing
flexibility to extend the design to different input sizes in future applications.
• Develop a comprehensive testbench that applies various input combinations to verify
that the priority encoder correctly encodes the highest-priority bit.
THEORY:-
A priority encoder is a digital combinational circuit that encodes multiple binary inputs into a
smaller number of output bits. Unlike a normal encoder, which assigns binary codes based on
input position, a priority encoder assigns priority to the highest-order active input (i.e., the
input with the highest index).
Functionality
An 8-to-3 priority encoder takes 8 input lines and produces a 3-bit output, encoding the
position of the highest-priority bit.
• The entity defines the module name and its input/output ports.
• An 8-bit input (in_bits) and a 3-bit output (out_bits) are required.
• The architecture contains the logic to determine the highest-priority active input.
• Use if-elsif or case statements to implement priority logic.
• The logic should check inputs from the highest (7) to the lowest (0) priority.
• If multiple inputs are active, the highest-priority input dictates the output.
• A test bench applies different input values and verifies if the output matches
expectations.
• It includes stimulus processes, clock (if required), and monitoring of results.
VHDL CODE:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Priority_Encoder_8to3 is
Port (
in_bits : in STD_LOGIC_VECTOR(7 downto 0); -- 8-bit input
out_bits : out STD_LOGIC_VECTOR(2 downto 0) -- 3-bit encoded output
);
end Priority_Encoder_8to3;
TESTBENCH:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity TB_Priority_Encoder is
end TB_Priority_Encoder;
begin
uut: Priority_Encoder_8to3 port map (in_bits => in_bits, out_bits => out_bits);
-- Stimulus process
process
begin
-- Apply test cases
in_bits <= "00000000"; wait for 10 ns; -- No active input
in_bits <= "00000001"; wait for 10 ns; -- Priority at bit 0
in_bits <= "00000100"; wait for 10 ns; -- Priority at bit 2
in_bits <= "10000000"; wait for 10 ns; -- Priority at bit 7
in_bits <= "01100000"; wait for 10 ns; -- Priority at bit 6 (highest)
in_bits <= "00010010"; wait for 10 ns; -- Priority at bit 4
WAVEFORM:
RESULT:-
Conclusion
A priority encoder is an essential component in digital electronics that efficiently selects the
highest-priority active input. It is widely used in digital systems where multiple signals need
to be prioritized for further processing.