Exp 6
Exp 6
Exp 6
Aim
To design, simulate and implement decoder and priority encoder in FPGA using Verilog HDL
Software Required
Vivado 2014.4
Hardware Required
Nexys A7: FPGA Trainer Board
Theory
Decoder
A decoder is a device which does the reverse of an encoder, undoing the encoding so that
the original information can be retrieved. The same method is used to encode and just reversed in
order to get decoder.
Program Program
module decoder_2_to_4( module decoder_2_to_4(
input a0, input a0,
input a1, input a1,
output d0, input e,
output d1, output d0,
output d2, output d1,
output d3 ); output d2,
wire an0, an1; output d3 );
not n1(an0,a0); assign d0= (~a1) & (~a0) & en;
n2 (an1,a1); assign d1= (~a1) & a0 & en;
and a1 (d0,an0,an1); assign d2= a1 & (~ a0) & en;
a2 (d1,a0,an1); assign d3= a1 & a0 & en;
a3 (d2,an0,a1); end module
a4 (d3,a0,a1);
endmodule
Priority Encoder
A priority encoder is a circuit or algorithm that compresses multiple binary inputs into a
smaller number of outputs. The output of a priority encoder is the binary representation of the
ordinal number starting from zero of the most significant input bit. They are often used to control
interrupt requests by acting on the highest priority request. It includes priority function. If two or
more inputs are equal to 1 at the same time, the input having the highest priority will take
precedence. Internal hardware will check this condition and priority is set.
Test bench Program Test bench Program
module tb_decoder_2_to_4(); module tb_decoder_2_to_4();
reg tb_a0, tb_a1; reg tb_a0, tb_a1, tb_en;
wire tb_d0,tb_d1,tb_d2,tb_d3; wire tb_d0,tb_d1,tb_d2,tb_d3;
decoder_2_to_4 dut decoder_2_to_4 dut
(.a0(tb_a0),.a1(tb_a1),.d0(tb_d0), (.a0(tb_a0),.a1(tb_a1),.en(tb_en),
.d1(tb_d1),.d2(tb_d2),.d3(tb_d3)); .d0(tb_d0),.d1(tb_d1),.d2(tb_d2),.d3(tb_d3));
initial begin initial begin
tb_a0=0; tb_a1=0; #10 tb_a0=0; tb_a1=0; tb_en=1; #10
tb_a0=0; tb_a1=1; #10 tb_a0=0; tb_a1=1; tb_en=1; #10
tb_a0=1; tb_a1=0; #10 tb_a0=1; tb_a1=0; tb_en=1; #10
tb_a0=1; tb_a1=1; #10 tb_a0=1; tb_a1=1; tb_en=1; #10
$stop; $stop;
end end
endmodule endmodule
Logic Diagram
Truth Table
Input Output
Enable In[2] In[1] In[0] Out[7] Out[6] Out[5] Out[4] Out[3] Out[2] Out[1] Out[0]
1 0 0 0 0 0 0 0 0 0 0 1
1 0 0 1 0 0 0 0 0 0 1 0
1 0 1 0 0 0 0 0 0 1 0 0
1 0 1 1 0 0 0 0 1 0 0 0
1 1 0 0 0 0 0 1 0 0 0 0
1 1 0 1 0 0 1 0 0 0 0 0
1 1 1 0 0 1 0 0 0 0 0 0
1 1 1 1 1 0 0 0 0 0 0 0
0 X X X 0 0 0 0 0 0 0 0
Procedure
RTL Schematics
Output
Steps for Test bench creation
18. Goto project manager right click on Simulation SourcesSelect Add or create simulation sources,
19. Click on Create File Select your file type as Verilog
20. Enter your “file name” and click Finish.,
21. Goto project manager and click your verilog file under Simulation Sources.,
22. Enter your program and save file.,
23. Click on”run synthesis”Running synthesis.,
Priority Encoder
Truth Table
D[0] D[1] D[2] D[3] Y[1] Y[0] V
0 0 0 0 X X 0
1 0 0 0 0 0 1
X 1 0 0 0 1 1
X X 1 0 1 0 1
X X X 1 1 1 1
24. After successful synthesis completion, close the pop-up window and select Simulation Run
Behavioural Simulation is enough to see output waveform If we run through testbench program.
25. Else After the Run Behavioral Simulation, Force the value for inputs by Force Constant option and
save the waveform
26. Run the simulation by clicking on Run for amount of time previously set
Output of simulation is verified with the help of waveform
RTL Schematic
Output
Output : 0100
Input en: 1
in: 10
en input
Steps for Implementation
Output : 00100000
Input enable: 1
binary_in: 101
en input
Implemented Priority
Encoder in Nexys A7: FPGA
Trainer Board
Output : 11
Input En: 1
binary_in: 1XXX
en input
Result
Thus the simulation of decoder and priority encoder were done, implemented in Nexys A7 FPGA
Trainer Board and outputs were verified
Practice Question