Subject Code HDL 2003
Subject Code HDL 2003
INTERFACING
1.Write VHDL code to display messages on the given seven segment display and LCD and
accepting Hex key pad input data.
2 .Write a VHDL code to accept 8 channel Analog signal, Temperature sensors and display the
data on LCD panel or Seven segment display.
3. Write VHDL code to simulate elevator operations.
4. Write VHDL code to control external lights using relays.
5. Write VHDL codes to control speed, direction of DC and Stepper motor.
6. Write VHDL Code to generate different waveforms (Sine square Triangle, Ramp etc) using DAC
change the frequency and amplitude.
ABSTRACT
INTRODUCTION
There are now two industry standard hardware description languages, VHDL and
Verilog. The complexity of ASIC and FPGA designs has meant an increase in the number of
specialist design consultants with specific tools and with their own libraries of macro and mega
cells written in either VHDL or Verilog. As a result, it is important that designers know both
VHDL and Verilog and that EDA tools vendors provide tools that provide an environment
allowing both languages to be used in unison. For example, a designer might have a model of a
PCI bus interface written in VHDL, but wants to use it in a design with macros written in
Verilog.
VHDL is a hardware description language that offers a broad set of constructs for
describing even the most complicated logic in a compact fashion. The VHDL language is
designed to fill a number of requirements throughout the design process:
Allows the description of the structure of a system — how it is decomposed into
subsystems, and how those subsystems are interconnected.
Allows the specification of the function of a system using familiar programming
language forms.
BACKGROUND
VHDL (Very high speed integrated circuit Hardware Description Language) became
IEEE standard 1076 in 1987. It was updated in 1993 and is known today as "IEEE standard 1076
1993". The Verilog hardware description language has been used far longer than VHDL and has
been used extensively since it was launched by Gateway in 1983. Cadence bought Gateway in
1989 and opened Verilog to the public domain in 1990. It became IEEE standard 1364 in
December 1995.
There are two aspects to modeling hardware that any hardware description language
facilitates; true abstract behavior and hardware structure. This means modeled hardware behavior
is not prejudiced by structural or design aspects of hardware intent and that hardware structure is
capable of being modeled irrespective of the design's behavior.
PROCEDURE:
Software part:
1. Click on the Project navigator icon on the desktop of your PC. Go to Create New
Project, give project Name.
2. Set Spartan 2, xc2s100, tq144. -5 and ISE Simulator / Modelsim for FPGA Family.
3. Go to Create new source in process View, Select VHDL MODULE and give name(it
should be other than the project name). i.e. Entity name and give the inputs, outputs
and select the architecture name. Then click on next icon & Finish Icon.
4. Then Write the VHDL code and save the file.
5. Then click on Check syntax in Synthesis-XST in Process view, and if there is any
error in the code debug it.
6. To see output in Test Bench Waveform(ISE Simulator / Modelsim):
Go to Create new source, select TEST BENCH WAVEFORM and give a
different file name and select COMBINATIONAL for combination circuits and
SINGLE CLOCK for Sequential Circuits. Then set the corresponding inputs &
outputs, then save and then click on simulate Behavioral model/ Modelsim simulator
i.e. depending upon the module.
7. To see output in VHDL kit:
Go to Create new source, select IMPLENTATION CONSTRAINTS FILE
and Open a new UCF(User Constraint File) file and assign the pins of the design with
FPGA/CPLD I/O pins(for Clock input always P18) and save the file.
8. Implement the design in process view by double clicking on the Implement Design
and View Pad Report to verify the pin numbers.
9. Click on Generate Programming File in Process View and then click on Configure
Device.
10. Now check the cable connections and select mode as SLAVE SERIAL MODE and
then verify the output at LEDS.
11. To see output in Pattern Generator / Logic Analyser:
Repeat steps from 1 to 10 except step 6, then choose appropriate Baud Rate,and then
click on save and see the output.
Hardware part:
1. Connect the FPGA kit to the parallel port of the PC through the cable provided along
with the Kit. Connect the FRC cable provided with the kit to the Bit Pattern generator
and logic analyzer.
2. For all the combinational experiments Use FRC1&FRC2 for sending bit patterns to
FPGA (pattern generator) and use FRC3 &FRC4 for receiving the logic from FPGA
(logic Analysis).
3. For all sequential circuits Use FRC 1 for sending bit patterns to FPGA (pattern
generator) and use last input pin as the clock for the design and connect it to the FPGA
clock pin through the jumper provided on the Kit. Use FRC2 for receiving the logic
from FPGA (logic Analysis).
4. For interfacing the cards connect the required part of the interfacing card to the FRC
connector Provided on the FPGA kit.
PART-A
1. Write VHDL code to realize all the logic gates.
Block Diagram:
Op_not
A Op_or
Op_and
Op_nor
Truth Table:
INPUT OUTPUTS
S
A B Op_not Op_or Op_and Op_nor Op_nand Op_xor Op_xnor
(Considering
input A)
0 0 1 0 0 1 1 0 1
0 1 1 1 0 0 1 1 0
1 0 0 1 0 0 1 1 0
1 1 0 1 1 0 0 0 1
Program:
1) Using VHDL
Library IEEE;
Use IEEE.STD_LOGIC_1164.ALL;
Use IEEE.STD_LOGIC_ARITH.ALL;
Use IEEE.STD_LOGIC_UNSIGNED.ALL;
Entity gate is
Port ( A : in std_logic; -- First Input
B : in std_logic; -- Second Input
Op_not : out std_logic;
Op_or : out std_logic;
Op_and : out std_logic;
Op_nor : out std_logic;
Op_nand : out std_logic;
Op_xor : out std_logic;
Op_xnor : out std_logic);
End gate;
module gates(a,b,op_not,op_or,op_nor,op_xor,op_xnor,op_and,op_nand);
input a,b;
output op_not,op_or,op_nor,op_xor,op_xnor,op_and,op_nand;
assign op_not=~a;
assign op_or= a| b;
assign op_nor= ~(a|b);
assign op_xor= a^ b;
assign op_xnor= ~(a^ b);
assign op_and= a &b;
assign op_nand= ~(a&b);
endmodule
2. Write a VHDL program for 2 to 4 Decoder
Block Diagram:
Enable
D_OUT (3:0)
DECODRE 2_4
D_IN (1:0)
Truth Table:
INPUTS OUTPUTS
E D_IN(0) D_IN(1) D_OUT(3) D_OUT(2) D_OUT(1) D_OUT(0)
0 0 0 0 0 0 1
0 0 1 0 0 1 0
0 1 0 0 1 0 0
0 1 1 1 0 0 0
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
Entity Decoder2_4 is
port (Enable: in STD_LOGIC;
D_IN: in STD_LOGIC_VECTOR (1 downto 0); -- Two Bit Input for the
Decoder
D_OUT: out STD_LOGIC_VECTOR (3 downto 0)); -- Four Bit Output for
the Decoder
End Decoder2_4;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
Entity Decoder2_4 is
port ( Enable: in STD_LOGIC);
D_IN: in STD_LOGIC_VECTOR (1 downto 0); -- Two Bit Input for the
Decoder
D_OUT: out STD_LOGIC_VECTOR (3 downto 0)); -- Four Bit Output
for the Decoder
End Decoder2_4;
Using Verilog:
Block Diagram:
Enable
D_OUT (2:0)
ENCODER 8_4
D_IN (7:0)
INPUTS OUTPUTS
D_IN(7
D_IN(6) D_IN(5) D_IN(4) D_IN(3) D_IN(2) D_IN(1) D_IN(0) D_OUT(2) D_OUT(1) D_OUT(0)
)
1 0 0 0 0 0 0 0 1 1 1
0 1 0 0 0 0 0 0 1 1 0
0 0 1 0 0 0 0 0 1 0 1
0 0 0 1 0 0 0 0 1 0 0
0 0 0 0 1 0 0 0 0 1 1
0 0 0 0 0 1 0 0 0 1 0
0 0 0 0 0 0 1 0 0 0 1
0 0 0 0 0 0 0 1 0 0 0
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
Entity Encoder8_3 is
Port ( ENABLE: in STD_LOGIC; --Enable Pin to Enable the Encoder
D_IN: in STD_LOGIC_VECTOR(7 downto 0); --Eight Input Lines of the
Encoder
D_OUT: out STD_LOGIC_VECTOR(2 downto 0) ); --Three Output Lines
of Encoder
End Encoder8_3;
endmodule
4. Write a VHDL program for 8 to 3 Encoder with
Priority.
Entity pri_Encoder is
Port ( ENABLE: in STD_LOGIC; --Enable Pin to Enable the Encoder
D_IN: in STD_LOGIC_VECTOR(7 downto 0); --Eight Input Lines of the Encoder
D_OUT: out STD_LOGIC_VECTOR(2 downto 0) ); --Three Output Lines of Encoder
End pri_Encoder;
TRUTH TABLE
INPUTS OUTPUTS
D_IN(7
D_IN(6) D_IN(5) D_IN(4) D_IN(3) D_IN(2) D_IN(1) D_IN(0) D_OUT(2) D_OUT(1) D_OUT(0)
)
1 x x x x x x x 1 1 1
x 1 x x x x x x 1 1 0
x x 1 x x x x x 1 0 1
x x x 1 x x x x 1 0 0
x x x x 1 x x x 0 1 1
x x x x x 1 x x 0 1 0
x x x x x x 1 x 0 0 1
x x x x x x x 1 0 0 0
Using veilog
module priority (code, valid_data, data);
output[2:0] code;
output valid_data;
input[7:0]data;
reg[2:0]code;
assign valid_data= |data; // “reduction or” operator
always @ (data)
casex(data)
BLOCK DIAGRAM
D MUX_OUT
F 8:1 MUX
G
SEL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
Entity Mux8_1 is
Port ( SEL: in STD_LOGIC_VECTOR(2 downto 0); -- Select Lines
A,B,C,D,E,F,G,H :in STD_LOGIC; -- Inputs of the Mux.
MUX_OUT: out STD_LOGIC ); -- OutPut of the Mux.
End Mux8_1;
Using Verilog
Module mux8x1(I0,I1,I2, I3,I4,I5,I6,I7,y,sel);
input I0,I1,I2, I3,I4,I5,I6,I7;
input [2:0]sel;
output y;
reg y;
always @ (I0,I1,I2, I3,I4,I5,I6,I7,sel)
begin
case (sel)
3'b000 : y=I0;
3'b001 : y=I1;
3'b010 : y=I2;
3'b011 : y=I3;
3'b100 : y=I4;
3'b101 : y=I5;
3'b110 : y=I6;
3'b111 : y=I7;
endcase
end
endmodule
Boolean Equation:
G3=B3;
G 2= B 3 xor B 2;
G1= B2 xor B 1;
G0= B1 xor B0;
BLOCK DIAGRAM
Truth Table:
Binary Input Gray output
B3 B2 B1 B0 G3 G2 G1 G0
0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 1
0 0 1 0 0 0 1 1
0 0 1 1 0 0 1 0
0 1 0 0 0 1 1 0
0 1 0 1 0 1 1 1
0 1 1 0 0 1 0 1
0 1 1 1 0 1 0 0
0 1 0 0 0 1 1 0
1 0 0 0 1 1 0 0
1 0 0 1 1 1 0 1
1 0 1 0 1 1 1 1
1 0 1 1 1 1 1 0
1 1 0 0 1 0 1 0
1 1 0 1 1 0 1 1
1 1 1 0 1 0 0 1
1 1 1 1 1 0 0 0
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
Entity Binary_Gray is
port( B_IN: in std_logic_vector(3 downto 0); --Binary Input
G_OUT: out std_logic_vector(3 downto 0)); --Gray Output
End binary_gray;
Using Verilog
4
Y
D_in
1:4
DEMUX
2
S
entity Demux1_4 is
port ( d_in: in STD_LOGIC; --Input For Demultiplexer
sel: in STD_LOGIC_VECTOR (1 downto 0); --Select Line
of Demux
d_out: out STD_LOGIC_VECTOR (3 downto 0)); --Output
Lines of Demux
end Demux1_4;
Using Verilog
8.Write a VHDL program for N Bit Comparator.
BLOCK DIAGRAM
A A =B
A <B
N Bit
B Comparator
A >B
TRUTH TABLE
INPUTS OUTPUTS
A B A=B A<B A>B
0 0 1 0 0
0 1 0 1 0
1 0 0 0 1
1 1 1 0 0
PROGRAM
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity comparator is
Generic (N: integer := N); --- Generalizing the Inputs
Port( A,B: in STD_LOGIC_VECTOR(N downto 0); -- Inputs for
Comparison
ALB,AGB,AEB: out STD_LOGIC); -- Output Signals to show
Less than,Greater than and Equal.
end comparator;
Using Verilog
9. Write a VHDL program for the implementation of Half
Adder.
BLOCK DIAGRAM
A SUM
Half
Adder CARRY
B
TRUTH TABLE
Input Output
A B Sum Carry
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
entity Halfadder is
Port ( A, B : in std_logic; --2Bit Input
Sum, Carry : out std_logic); --sum& carry
end Halfadder;
Using Verilog
BLOCK DIAGRAM
A
SUM
B
Truth Table:-
Ci C ou
A B S
n t
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
entity FullAdder is
Port ( Ain : in std_logic; --Input One
Bin : in std_logic; --Input Two
Cin : in std_logic; --Carry Input
Cout : out std_logic; --Carry Output
Sum : out std_logic); --Sum Output
end FullAdder;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity FullAdder is
Port ( Ain : in std_logic; --Input One
Bin : in std_logic; --Input Two
Cin : in std_logic; --Carry Input
Carry : out std_logic; --Carry Output
Sum : out std_logic); --Sum Output
end FullAdder;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity FullAdder is
Port ( Ain : in std_logic; --Input One
Bin : in std_logic; --Input Two
Cin : in std_logic; --Carry Input
Cout : out std_logic; --Carry Output
Sum : out std_logic); --Sum Output
end FullAdder;
entity halfadder is
Port ( Ain,Bin : in STD_LOGIC;
sum, carry : out STD_LOGIC);
end halfadder;
end Behavioral;
entity or1 is
Port ( p,q : in STD_LOGIC;
r : out STD_LOGIC);
end or1;
Block Diagram
A [3:0]
B [3:0]
Y [7:0]
Enable ALU
opcode [2:0]
Truth Table
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ALU is
Port ( a,b : in STD_LOGIC_VECTOR (3 downto 0);
y : out STD_LOGIC_VECTOR (7 downto 0);
e: in std_logic;
opc : in STD_LOGIC_VECTOR (2 downto 0));
end ALU;
begin
process(opc,e)
begin
if (e ='0')then
y <="00000000";
\elsif (e = '1')then
case opc is
when "000" => y<= “0000” & (a + b);
when "001" => y<= “0000” & (a – b);
when "010" => y<= “0000” & (not a) ;
when "011" => y<= a * b;
when "100" => y<= “0000” & (a and b);
when "101" => y<= “0000” & (a or b);
when "110" => y<= “0000” & (a nand b);
when "111" => y<= “0000” & (a xor b);
when others => null;
end case;
end if;
end process;
end Behavioral;
Sequential circuits:
11. Write a VHDL program for SR F/F
Block diagram
S
CLK Q
SR
R FLIP-FLOP
RESET
entity rsff is
Port ( r,s,reset,clk : in std_logic;
q,qb : out std_logic);
end rsff;
Clock Reset S R Q Qb
1 1 x x 0 1
1 0 0 0 No change No change
1 0 0 1 Reset Set
1 0 1 0 Set Reset
1 0 1 1 Illegal Illegal
Using verilog
D Q
FLIP-FLOP
CLK
RESET
Truth Table
INPUT OUTPUT
CLK RESET D Q
1 0 1 0
1 1 0 0
1 1 1 1
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity dff is
Port ( d,rst,clk : in STD_LOGIC;
q : out STD_LOGIC);
end dff;
Using Verilog
Block Diagram
CLK Q
JK
K FLIP-FLOP
Reset
Truth Table
INPUTS OUTPUTS
CLK J K Q
1 0 0 No change
1 0 1 Reset
1 1 0 set
1 1 1 Toggle
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity jk is
Port ( s,r, j,k,clk : in STD_LOGIC;
q : inout STD_LOGIC;
qn : out STD_LOGIC := '1');
end jk;
architecture Behavioral of jk is
begin
process(s,r,clk)
begin
if r = '0' then q<= '0';
elsif s = '0' then q <= '1';
elsif clk = '0' and clk'event then
q <= ((j and (not q)) or ((not k) and q));
end if;
end process;
end Behavioral;
Block Diagram
T Q
T
FLIP-FLOP
CLK Qb
RESET
Truth Table
INPUTS OUTPUT
CLK Reset T Q
1 0 0 0
1 1 0 0
1 1 1 Toggle
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity tff is
Port ( rst,clk,t : in STD_LOGIC;
q : inout STD_LOGIC);
end tff;
end Behavioral;
Using Verilog