Professional Documents
Culture Documents
C. Byregowda Institute of Technology: HDL Lab Manual
C. Byregowda Institute of Technology: HDL Lab Manual
C. Byregowda Institute of Technology: HDL Lab Manual
Byregowda Institute Of
Technology
Subject HDL
Code: 15ECL58
15EC
L37 LAB MANUAL
2018
C. BYRE GOWDA INSTITUTE OF TECHNOLOGY KOLAR
Department of
Electronics & Communication Engineering
V Semester
HDL LAB MANUAL
(15ECL58)
Contents
prog Page no
Name of the experiment
no.
01 Realize all the logic gates 1
01 Stepper motor 29
02 DC Motor 31
03
DAC 34
04
Seven segment display 44
05
Elevator operation. 46
06.07
Extra program 49
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Program1 Date:___/____/_______
The AND gate is so named because, if 0 is called "false" and 1 is called "true," the gate acts in the same way as
the logical "and" operator.
The OR gate gets its name from the fact that it behaves after the fashion of the logical inclusive "or."
The XOR (exclusive-OR) gate acts in the same way as the logical "either/or."
A logical inverter , sometimes called a NOT gate, has only one input. It reverses the logic state.
The NAND gate operates as an AND gate followed by a NOT gate
The NOR gate is a combination OR gate followed by an inverter.
The XNOR (exclusive-NOR) gate is a combination XOR gate followed by an inverter.
Block Diagram
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Truth table
a b c d e f g h i
0 0 0 0 1 1 1 0 1
0 1 0 1 1 1 0 1 0
1 0 0 1 0 1 0 1 0
1 1 1 1 0 0 0 0 1
BOOLEAN EXPRESSIONS:
C = AB , D = A+B
E = A', F = (AB)'
G = (A+B)' H = A B
I=A B
PROGRAM:
module basic_gates (a,b,c,d,e,f,g,h);
input a,b;
output c,d,e,f,g,h;
assign e= ~a;
assign c=a&b;
assign d=a|b;
assign f=~(a&b);
assign g=~(a|b);
assign h=a^b;
assign i=~ (a^b);
endmodule
SIMULATION OUTPUT:
RESULT: The logic gates designs have been realized and simulated using HDL codes.
APPLICATIONS :
In practice, the gates are made from field-effect transistors (FETs), particularly MOSFETs (metal–oxide–
semiconductor field-effect transistors).
Logic circuits include devices such as multiplexers, registers, arithmetic logic units (ALUs), and computer
memory, all the way up through complete microprocessors, which may contain more than 100 million
gates.
Compound logic gates AND-OR-Invert (AOI) and OR-AND-Invert (OAI) are often employed in circuit design
because their construction using MOSFETs is simpler and more efficient than the sum of the individual
gates.Every digital product, like computers, mobile, calculators even digital watches, contain logic gates
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Program2a Date:___/____/_______
2 to 4 decoder
Aim: Write a Verilog code to to realize 2 to 4 decoder and simulate.
Theory:
A n-to-2n decoder takes an n-bit input and produces 2n outputs. The n inputs represent a binary
number that determines which of the 2n outputs is uniquely true.
A 2-to-4 decoder operates according to the following truth table.
The 2-bit input is called a & b, and the four outputs are y0-y3.
If the input is the binary number i, then output Qi is uniquely true.
For instance, if the input a & b = 10 (decimal 2), then output y2 is true, and y0, y1, y3 are all false
This circuit decodes a binary number into a one-of-four code
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Wave form:
RESULT: The 2 to 4 decoder design have been realized and simulated using Verilog code.
APPLICATIONS:
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Program2b Date:___/____/_______
8 TO 3 ENCODER
Aim: Write a Verilog code to to realize 8 to 3 Encoder.
Theory:
An encoder is a device, circuit, transducer, software program, algorithm or person that
converts information from one format or code to another, for the purposes of standardization,
speed, secrecy, security, or saving space by shrinking size.
Encoders are combinational logic circuits and they are exactly opposite of decoders. They accept one
or more inputs and generate a multi bit output code.
An encoder has M input and N output lines. Out of M input lines only one is activated at a time and
produces equivalent code on output N lines. If a device output code has fewer bits than the input
code has, the device is usually called an encoder.
Octal-to-Binary take 8 inputs and provides 3 outputs. At any one time, only one input line has a value
of 1
8 3
y Enc_wop a
WITHOUT PRIORITY
Truth Table: Boolean Expression:
a0 = y1 + y3 + y5 + y7
a1 = y2 + y3 + y6 + y7
a2 = y4 + y5 + y6 + y7
WITH PRIORITY
Truth Table: Boolean Expression:
a0 = y1 + y3 + y5 + y7
a1 = y2 + y3 + y6 + y7
a2 = y4 + y5 + y6 + y7
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Wave form:
RESULT : The 8 to 3 encoder design have been realized and simulated using Verilog code..
APPLICATIONS:
Encoding is used in most wireless control systems to prevent interference. It is useful in web
processes, handling and inspection systems that use conveyors and simple speed or position
control in high vibration environments.
.
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Program2c Date:___/____/_______
MULTIPLEXER (8 TO 1)
Aim: Write a Verilog code to to realize 8 to 1 Multiplexer and simulate.
Theory:
A multiplexer has many input lines and one output line. The signal from one input line will be directed
to the output line. The input line is chosen based on the signals which are carried to the multiplexer on another
set of input lines called control lines. Multiplexers are sometimes called selectors because they choose or select
one of their inputs.
The number of control lines needed depends on the number of input lines. A multiplexer with 2 control
lines can select from 4 input lines, a multiplexer with 3 control lines can select from 8 input lines. In general, a
multiplexer with n control lines can select from up to 2ninput lines.
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
RESULT: The 8 to 1 multiplexer design have been realized and simulated using Verilog code.
APPLICATIONS:
Multiplexers are used in building digital semiconductors such as central processing units (CPUs) and
graphics controllers. They are also used in communications. cross bar switch, cellphone systems,
instrumentation, and any other function where only one transmission channel (e.g a radio transmitter) is
available. They mostly find in numerous and varied applications in digital systems of all types such as data
selection, data routing, operation sequencing, parallel -to-serial conversion, waveform generation and logic-
function generation
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Program2d Date:___/____/_______
DE-MULTIPLEXER (1 TO 4)
Aim: Write a Verilog code to to realize 1 to 4 De-Multiplexer.
Theory:
The de-multiplexer takes one single input data line and then switches it to any one of the number of
individual output lines one at a time. The de-multiplexer converts a serial data signal at the input to a parallel
data at its output lines. The function of the 1 : 4 De-multiplexer is to switch one common data input line to any
one of the 4 output data lines.
Verilog Code
module demux (s2,s1,I,E,y0,y1,y2,y3)
input s2,s1,I,E;
output y0,y1,y2,y3;
assign y0=(~s2)&(~s1)& I& E;
assign y1=(~s2)& s1& I& E;
assign y2=s2&(~s1)& I & E;
assign y3=s2& s1 & I & E;
endmodule
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Wave form:
RESULT: The 1 to 4 De-multiplexer design have been realized and simulated using Verilog code.
APPLICATIONS:
De-multiplexers are used in Clock de-multiplexer, Security monitoring system, Synchronous data
transmission system
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Program2e Date:___/____/_______
module bin_gray(b,g);
input [3:0]b;
output [3:0]g;
reg [3:0]g;
always@ ( b)
begin
g[3]=b[3];
g[2]=b[2]^b[3];
g[1]=b[1]^b[2];
g[0]=b[0]^b[1];
end
endmodule
Wave form:
RESULT: The 4 bit binary to gray converter design have been realized and simulated using Verilog
code.
APPLICATIONS:
Gray codes are widely used to facilitate error correction in digital communications such as digital
terrestrial television and some cable TV systems.
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Program2f Date:___/____/_______
BIT COMPARATOR
Aim: Write a Verilog code to to realize 2bit comparator.
Theory:
A digital comparator is a hardware electronic device that compares two numbers in binary form and
generates a one or a zero at its output depending on whether they are the same or not. A 2 bit comparator
compares two 2-bit binary, BCD, or other monotonic codes and presents the three possible magnitude results
at the outputs i.e., a>b, a<b, a=b.
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Wave form:
RESULT: The 2 bit comparator design have been realized and simulated using Verilog code.
APPLICATIONS:
In mass production, where components are to be checked at a very fast rate. In selective assembly of
parts, where parts are graded in three or more groups depending upon their tolerance.
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Program3 Date:___/____/_______
ALU
Aim: Write Verilog code describe the functions of a Arithmetic Logical Unit .
Theory:
The Arithmetic Logic Unit is the section of the CPU that actually performs add, subtract, multiply,
divide, and, or, floating point and other operations. The range of integer values that can be stored in 32 bits
is 0 through 4,294,967,295. Hence, a processor with 32-bit memory addresses can directly access 4 GiB of
byte-addressable memory.
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
RESULT: 32 bit ALU operations have been realized and simulated using Verilog code.
APPLICATIONS:
Arithmetic Logic Unit is used extensively for Signal Processing and Control. It can be used in many
applications involving arithmetic operations. Many DSP and control applications require a small subset of
arithmetic operations that must be computed efficiently.
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Program4 Date:___/____/_______
Flip Flop
Aim: Write Verilog code describe the functions of a flip flop .
Theory:
Block Diagram: (S,R Flip flop) Block Diagram: (J,K Flip flop)
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
endmodule endmodule
Wave form: SR Flip Flop
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
qb=~q; q = 1'b0;
end qb=~q;
else end
begin else
q = d; if (t)
qb=~q;
end
begin
endmodule q = ~q;
qb = ~q;
end
endmodule
Wave form:D Flip Flop
RESULT: Fliflop operations have been realized and simulated using Verilog code.
APPLICATIONS:
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Program5 Date:___/____/_______
COUNTERS
Aim: Write Verilog code describe the functions of a Counter.
Theory:
Block Diagram: Block Diagram:
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
2. Many automation systems use PC and laptops to monitor different parameters of machines and production data.
Counters may count parameters such as the number of pieces produced, the production batch number, and
measurements of the amounts of material used.
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Program6 Date:___/____/_______
FULL ADDER
Aim: Write HDL code to describe the functions of a full Adder Using three modeling styles..
Theory: A Full Adder is a combinational circuit that performs the arithmetic sum of three input bits.
It consists of three inputs and two outputs. Three of the input variables can be defined as a, b, c and
the two output variables can be defined as Sum, Cout. The two input variables that we defined earlier
A and B represents the two significant bits to be added. The third input ‘c’ represents the carry bit.
Two digits arte to be used because the arithmetic sum of the three binary digits needs two digits.
The two outputs represents Sum for sum and Cout for carry.For designing a full adder circuit, two
half adder circuits and an OR gate is required. It is the simplest way to design a full adder circuit. For
this two XOR gates, two AND gates, one OR gate is required.
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
RESULT : Three modeling styles of full adder have been realized and
simulated using HDL codes.
APPLICATIONS :
Adders are basically used in calculators. They are used in all processors –
micrprocessors and microcontrollers and also DSP processors.
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Part –B
Interfacing Programs
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
VHDL CODING
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity STEPPERnew is
Port ( dout : out std_logic_vector(3 downto 0);
clk,reset: in std_logic;
row:in std_logic_vector(1 downto 0);
dir:in std_logic);
end STEPPERnew;
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
end process;
clk_int<=clk_div(21) when row="00"else
clk_div(19) when row="01"else
clk_div(17) when row="10"else
clk_div(15) ;
process(reset,clk_int,dir)
begin
if reset='0' then
shift_reg <= "1001";
elsif rising_edge(clk_int) then
if dir='0' then
shift_reg <= shift_reg(0) & shift_reg(3 downto 1);
else
shift_reg<=shift_reg(2 downto 0) & shift_reg(3); end if;
end if;
end process;
dout <= shift_reg;
end Behavioral;
UCF file (User constraint File)
NET "clk" LOC = "p52" ;
NET "dir" LOC = "p76" ;
NET "dout<0>" LOC = "p141" ;
NET "dout<1>" LOC = "p2" ;
NET "dout<2>" LOC = "p4" ;
NET "dout<3>" LOC = "p5" ;
NET "reset" LOC = "p74" ;
NET "row<0>" LOC = "p77" ;
NET "row<1>" LOC = "p79" ;
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
VHDL CODING
library IEEE;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity dc_motor is
port(clk,rst,dir:in std_logic;
rly:out std_logic;
begin
process(clk) is
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
begin
if (rising_edge (clk)) then
div<=div+1;
end if;
end process;
clkdiv<=div(12);
process(tick) is
begin
if (falling_edge (tick)) then
case (keys) is
when "1110"=>dc<=50;
when "1101"=>dc<=20;
when "1011"=>dc<=10;
when "0111"=>dc<=5;
when others=>dc<=5;
end case;
end if;
end process;
process (clkdiv,rst) is
begin
if dir='1' then
if( rst='1') then
counter<="00000000";
pwm<="01";
elsif (rising_edge(clkdiv)) then
counter<=counter+1;
if (counter >=dc)then
pwm(1)<='0';
else
pwm(1)<='1';
end if;
end if;
else
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
end if;
end process;
rly<=dir;
end Behavioral;
//ucf file
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
3a. Write a VHDL code to generate Sine waveforms using DAC change the
frequency and amplitude.
Aim: To generate Sine wave using DAC change the frequency and amplitude.
Procedure:
1. Make the connection between FRC5 of the FPGA board to the DAC connector
of
the VTU card2.
2. Make the connection between FRC1 of the FPGA board to the Dip switch
connector of the
VTU card2.
3. Connect the downloading cable and power supply to the FPGA board.
4. Then open the Xilinx iMPACT software (refer ISE flow) select the slave serial
mode and
select the respective BIT file and click program.
5. Make the reset switch on (active low) and analyze the data.
VHDL CODING
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity digital_sine_wave is
Port ( clk : in std_logic;
rst : in std_logic;
dac_out : out std_logic_vector(0 to 7));
end digital_sine_wave ;
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
3.b Write a VHDL code to generate Square waveforms using DAC change the
frequency and amplitude.
Aim: To generate Square wave using DAC change the frequency and amplitude.
Procedure:
1. Make the connection between FRC5 of the FPGA board to the DAC connector
of
the VTU card2.
2. Make the connection between FRC1 of the FPGA board to the Dip switch
connector of the VTU card2.
3. Connect the downloading cable and power supply to the FPGA board.
4. Then open the Xilinx iMPACT software (refer ISE flow) select the slave serial
mode and select the respective BIT file and click program.
5. Make the reset switch on (active low) and analyze the data.
VHDL CODING
entity DAC_Square is
Port ( clk : in STD_LOGIC; -- 4MHz XTL_CLK
rst : in STD_LOGIC;
dac_out : out STD_LOGIC_VECTOR ( 7 downto 0 ));
end DAC_Square;
begin
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
end Behavioral;
ucf File
NET "clk" LOC = "p52" ;
NET "dac_out<0>" LOC = "p21" ;
NET "dac_out<1>" LOC = "p18" ;
NET "dac_out<2>" LOC = "p17" ;
NET "dac_out<3>" LOC = "p15" ;
NET "dac_out<4>" LOC = "p14" ;
NET "dac_out<5>" LOC = "p13" ;
NET "dac_out<6>" LOC = "p12" ;
NET "dac_out<7>" LOC = "p1" ;
NET "rst" LOC = "p74" ;
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
3c. Write a VHDL code to generate Traingular waveforms using DAC change the
frequency and amplitude.
Aim: To generate Triangular wave using DAC change the frequency and
amplitude.
Procedure:
1. Make the connection between FRC5 of the FPGA board to the DAC connector
of
the VTU card2.
2. Make the connection between FRC1 of the FPGA board to the Dip switch
connector of the VTU card2.
3. Connect the downloading cable and power supply to the FPGA board.
4. Then open the Xilinx iMPACT software (refer ISE flow) select the slave serial
mode and select the respective BIT file and click program.
5. Make the reset switch on (active low) and analyze the data.
VHDL CODING
----triangular wave
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity triangular_wave is
Port ( clk : in std_logic;
rst : in std_logic;
dac_out : out std_logic_vector(0 to 7));
end triangular_wave ;
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
end if;
end process;
process(div(3))
begin
if rst='1' then
counter <= "000000000";
elsif rising_edge(div(3)) then
counter <= counter + 1 ;
if counter(0)='1' then
dac_out <=counter(1 to 8);
else
dac_out <=not(counter(1 to 8));
end if;
end if;
end process;
end Behavioral;
//ucf
NET "clk" LOC = "p52" ;
NET "dac_out<0>" LOC = "p21" ;
NET "dac_out<1>" LOC = "p18" ;
NET "dac_out<2>" LOC = "p17" ;
NET "dac_out<3>" LOC = "p15" ;
NET "dac_out<4>" LOC = "p14" ;
NET "dac_out<5>" LOC = "p13" ;
NET "dac_out<6>" LOC = "p12" ;
NET "dac_out<7>" LOC = "p1" ;
NET "rst" LOC = "p74" ;
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
3d. Write a VHDL code to generate Ramp waveforms using DAC change the
frequency and amplitude.
Aim: To generate Ramp wave using DAC change the frequency and amplitude.
Procedure:
1. Make the connection between FRC5 of the FPGA board to the DAC connector
of
the VTU card2.
2. Make the connection between FRC1 of the FPGA board to the Dip switch
connector of the VTU card2.
3. Connect the downloading cable and power supply to the FPGA board.
4. Then open the Xilinx iMPACT software (refer ISE flow) select the slave serial
mode and select the respective BIT file and click program.
5. Make the reset switch on (active low) and analyze the data.
VHDL CODING
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ramp_wave is
Port ( clk : in std_logic;
rst : in std_logic;
dac_out : out std_logic_vector(0 to 7));
end ramp_wave;
begin
process(clk)
begin
if rising_edge(clk) then
div<= div+ '1' ;
end if;
end process;
process(div)
begin
if rst='1' then
counter <= "00000000";
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
3e. Write a VHDL code to generate Sawtooth waveforms using DAC change the
frequency and amplitude.
.
Procedure:
1. Make the connection between FRC5 of the FPGA board to the DAC connector of
the VTU card2.
2. Make the connection between FRC1 of the FPGA board to the Dip switch connector
of the VTU card2.
3. Connect the downloading cable and power supply to the FPGA board.
4. Then open the Xilinx iMPACT software (refer ISE flow) select the slave serial mode
and
select the respective BIT file and click program.
5. Make the reset switch on (active low) and analyze the data.
VHDL CODING
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity swatooth_wave is
Port ( clk : in std_logic;
rst : in std_logic;
dac_out : out std_logic_vector(0 to 7));
end swatooth_wave;
architecture Behavioral of swatooth_wave is
signal temp : std_logic_vector(3 downto 0);
signal counter : std_logic_vector(0 to 7);
signal en :std_logic;
begin
process(clk)
begin
if rising_edge(clk) then
temp <= temp + '1' ;
end if;
end process;
process(temp(3))
begin
if rst='1' then
counter <= "00000000";
elsif rising_edge(temp(3)) then
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
4. Write VHDL code to display messages on the given seven segment display
accepting Hex key pad input data.
Write VHDL code to display messages on the given seven segment display accepting Hex key pad input
data.
Aim: To Display the message on the Seven Segment Display by accepting HEX key pad input Data.
Procedure:
1. Make the connection between FRC5 of the FPGA board to the Seven Segment connector of the VTU card1.
2. Make the connection between FRC4 of the FPGA board to the Key board connector of the VTU card1.
3. Make the connection between FRC6 of the FPGA board to the Dip switch connector of the VTU card1.
4. Connect the downloading cable and power supply to the FPGA board.
5. Then open the Xilinx iMPACT software (refer ISE flow) select the slave serial mode and select the respective
BIT file and click program.
6. Make the reset switch on (active low).
7. Press the HEX keys and analyze the data.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity keypad_led_display is
Port ( clk : in STD_LOGIC;
key_rl : in BIT_VECTOR (3 downto 0);
key_sc : out BIT_VECTOR (3 downto 0);
seg_out : out STD_LOGIC_VECTOR (6 downto 0));
end keypad_led_display;
architecture Behavioral of keypad_led_display is
signal clk_div:std_logic_vector(12 downto 0); -- 2 msec delay, 4Mhz clock source / 8 KHz = 500Hz ( = 2
msec)
signal key_sc_temp :bit_vector(3 downto 0):="0001"; -- 2 ^ 13 = 8KHz, 12 downto 0
begin
process(clk)
begin
if(clk'event and clk = '1') then
clk_div <= clk_div + '1';
end if;
end process;
process(clk_div(12))
begin
if (clk_div(12)'event and clk_div(12) = '1') then
key_sc_temp <= key_sc_temp rol 1;
end if;
key_sc <= key_sc_temp;
end process;
process(key_rl,clk_div(12))
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
begin
if (clk_div(12)'event and clk_div(12) = '1') then
if (key_sc_temp="0001" and key_rl="0001") then seg_out <= "1111110"; --1
elsif (key_sc_temp="0001" and key_rl="0010") then seg_out <= "0110011";
elsif (key_sc_temp="0001" and key_rl="0100") then seg_out <= "1111111";
elsif (key_sc_temp="0001" and key_rl="1000") then seg_out <= "1001110";
elsif (key_sc_temp="0010" and key_rl="0001") then seg_out <= "0110000";
elsif (key_sc_temp="0010" and key_rl="0010") then seg_out <= "1011011";
elsif (key_sc_temp="0010" and key_rl="0100") then seg_out <= "1111011";
elsif (key_sc_temp="0010" and key_rl="1000") then seg_out <= "0111101";
elsif (key_sc_temp="0100" and key_rl="0001") then seg_out <= "1101101";
elsif (key_sc_temp="0100" and key_rl="0010") then seg_out <= "1011111"; --A
elsif (key_sc_temp="0100" and key_rl="0100") then seg_out <= "1110111";
elsif (key_sc_temp="0100" and key_rl="1000") then seg_out <= "1001111";
elsif (key_sc_temp="1000" and key_rl="0001") then seg_out <= "1111001";
elsif (key_sc_temp="1000" and key_rl="0010") then seg_out <= "1110000";
elsif (key_sc_temp="1000" and key_rl="0100") then seg_out <= "0011111";
elsif (key_sc_temp="1000" and key_rl="1000") then seg_out <= "1000111"; --0
end if;
end if;
end process;
end Behavioral;
UCF file (User constraint file)
NET "clk" LOC = "p52";
NET "disp_cnt<0>" LOC = "p23";
NET "disp_cnt<1>" LOC = "p24";
NET "disp_cnt<2>" LOC = "p26";
NET "disp_cnt<3>" LOC = "p27";
NET "disp<0>" LOC = "p18";
NET "disp<1>" LOC = "p17";
NET "disp<2>" LOC = "p15";
NET "disp<3>" LOC = "p14";
NET "disp<4>" LOC = "p13";
NET "disp<5>" LOC = "p12";
NET "disp<6>" LOC = "p1";
NET "read_l_in<0>" LOC = "p112";
NET "read_l_in<1>" LOC = "p116";
NET "read_l_in<2>" LOC = "p119";
NET "read_l_in<3>" LOC = "p118";
NET "scan_l<0>" LOC = "p123";
NET "scan_l<1>" LOC = "p131";
NET "scan_l<2>" LOC = "p130";
NET "scan_l<3>" LOC = "p137";
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
VHDL CODING
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity elev is
port(floor: in std_logic_vector(7 downto 0);
clk:in std_logic;
led_out: out std_logic_vector(7 downto 0):="00000000";
seg:out std_logic_vector(6 downto 0):="1111110";
dis:out std_logic_vector(3 downto 0));
end elev;
if(floor>nxt ) then
case nxt is
when "00000001" => nxt:= "00000010";seg<="0110000";
when "00000010" => nxt:= "00000100";seg<="1101101";
when "00000100" => nxt:= "00001000";seg<="1111001";
when "00001000" => nxt:= "00010000";seg<="0110011";
when "00010000" => nxt:= "00100000";seg<="1011011";
when "00100000" => nxt:= "01000000";seg<="1011111";
when "01000000" => nxt:= "10000000";seg<="1110000";
when others => null;
end case;
temp := nxt;
led_out <= temp;
end if;
if(floor < nxt)then
nxt:= temp;
case nxt is
when "10000000" => nxt:= "01000000";seg<="1011111";
when "01000000" => nxt:= "00100000";seg<="1011011";
when "00100000" => nxt:= "00010000";seg<="0110011";
when "00010000" => nxt:= "00001000";seg<="1111001";
when "00001000" => nxt:= "00000100";seg<="1101101";
when "00000100" => nxt:= "00000010";seg<="0110000";
when "00000010" => nxt:= "00000001";seg<="1111110";
when others => null;
end case;
temp := nxt;
led_out <= temp;
end if;
end if;
end process;
end elev_arch;
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Extra programs
6. Write VHDL code to display messages on the given seven segment display
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity msg is
port(clk:in std_logic;
seg:out std_logic_vector(6 downto 0);
disp: out std_logic_vector( 3 downto 0));
end msg;
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
VHDL CODING
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity extlight is
Port ( cntrl1,cntrl2 : in std_logic;
light : out std_logic);
end extlight;
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
Viva Quetions
BASIC GATES
1. What is HDL & What are the types of HDL’S.
2. Mention the different basic gates.
3. Mention the different Universal gates.
4. Mention the different Application gates.
5. What is De-Morgan's Law?
6. What is the practical application of the De-Morgan's Law
7. Write a program to realize the behavior of Xor gate using nand gates only.
8. What is the difference between Buffer and Inverter?
9. Expand VHDL & Verilog.
10. What is the difference between std_logic & bit data type.
11. What is the combinatorial circuit?
12. Representation of Different gates in VHDL & Verilog.
13. What is the difference between Keyword & a Identifier.
DECODER
1. What is a Decoder?
2. Difference between Decoder & encoder.
3. What is the use of designing Decoder using Logic gates?
4. Write a program to design Decoder in Data Flow description
5. Write a program to design Decoder with enable input and mention its advantages.
ENCODER
1. What is a Encoder?
2. What are the disadvantages of Encoder without Priority?
3. What are the types of Encoders.
4. What is Shaft Encoding?
5. Design a 16-4 line HEX keypad encoder to output 0000 when key 0 is pressed, 0001
when key 2 is pressed , 1010 when key A is pressed 101 when key B is pressed and so on.
6. Write the VHDL& Verilog program to design a 4:2 encoder with Data flow description.
MULIPLEXER
1. What is a Multiplexer?
2. What are the applications of Multiplexer?
3. Write the VHDL& Verilog program to design 2:1 Multiplexer with Data flow description.
4. What is the practical application of a Multiplexer?
5. How a Multiplexer can be used in a Communication systems?
DE-MULIPLEXER
1. What is a De-Multiplexer?
2. What are the applications of De-Multiplexer?
3. Write the VHDL& Verilog program to design 1:4 Multiplexer with Data flow description.
4. What is the practical application of a De-Multiplexer?
5. How a De-Multiplexer can be used in a Communication systems?
COMPARATOR
1. What is a Comparator?
2. What are the applications of Comparator?
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
3. Write the VHDL& Verilog program to design 2-bit Comparator with Data flow description.
4. What are the types of Comparators?
5. What is the use of Magnitude Comparator.
CODE CONVERTERS
ADDERS
FLIP-FLOP
1. What are Combinational Circuits and Sequential Circuits and their differences.
2. Define Synchronous Sequential circuits & Asynchronous Sequential circuits
3. What is the Latch?
4. What is the FLIP-FLOP?
5. What are the types of FLIP-FLOP?
6. Draw the functional table for SR, JK, T & D flip flops.
7. How to avoid race around condition using MS-JK flip flop?
8. Draw the circuit of SR Latch.
1. Explain it.
2. Truth Table, Characteristic Table, Excitation Table - SR Flip-Flop, JK Flip Flop
3. Implement D-Latch by JK Flip Flop. Explain the circuit.
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
COUNTERS
1. What is a Counter? What are the different types of Counters?
2. Explain Synchronous Counter & Asynchronous Counter.
3. What is a decade counter? What are the uses of it?
4. What are the applications of Synchronous Counter& Asynchronous Counter.
5. Explain the difference between Melay Model & Moore Model.
6. What are the advantages of Melay Model & Moore Model?
7. What is Sequence generator? Where it is used?
8. What is Register? Mention Classification of Shift Registers.
Appendix
1. Write the VHDL representation of Half-Subtractor in Behavioral & Structural models.
entity half_sub is
Port ( a,b : in std_logic;
diff,borrow : out std_logic);
end half_sub;
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
Entity and2 is
Port(i1,i2: in std_logic;
o1: out std_logic);
end and2;
Architecture and2_0 of and2 is
Begin
o1<= i1 and i2;
end and2_0;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
Entity inv is
Port(i1: in std_logic;
o1: out std_logic);
end inv;
Architecture inv_0 of inv is
Begin
o1<= not i1;
end inv_0;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
Entity xor2 is
Port(i1,i2: in std_logic;
o1: out std_logic);
end xor2;
Architecture xor2_0 of xor2 is
Begin
o1<= i1 xor i2;
end xor2_0;
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
2. Write the VHDL & Verilog representation of Full Adder using 2 Half-adders in Structural
model.
entity full_struct is
Port ( a,b,c : in std_logic;
x,y,z : inout std_logic;
sum, cout : out std_logic);
end full_struct;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
Entity ha is
Port(i1,i2: in std_logic;
o1,o2: out std_logic);
end ha;
Architecture ha_0 of ha is
Begin
o1<= i1 xor i2;
o2<= i1 and i2;
end ha_0;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
Entity or2 is
Port(i1,i2: in std_logic;
o1: out std_logic);
end or2;
Architecture or2_0 of or2 is
Begin
o1<= i1 or i2;
end or2_0;
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
module ha (a,b,sum,cout) ;
input a,b;
output sum,cout;
assign sum= a ^ b;
assign cout= a & b;
endmodule
3. Write the VHDL & Verilog representation of Full Subtractor using 2 Half-Subtractors in
Structural model.
entity full_sub is
Port ( a,b,c : in std_logic;
x,y,z : inout std_logic;
diff,bor : out std_logic);
end full_sub;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
Entity hs is
Port(i1,i2: in std_logic;
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
Entity or2 is
Port(i1,i2: in std_logic;
o1: out std_logic);
end or2;
Architecture or2_0 of or2 is
Begin
o1<= i1 or i2;
end or2_0;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
Entity inv is
Port(i1: in std_logic;
o1: out std_logic);
end inv;
Architecture inv_0 of inv is
Begin
o1<= not i1;
end inv_0;
4. Write a VHDL & Verilog Program to solve the following Boolean expressions.
1.f1(a,b,c)=∑(2,4,5,6,7)
2.f2(a,b,c)=Π(1,4,5,6)
module fun1_v(a,b,c,f) ;
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
input a,b,c;
output f;
assign f= a |( ~b& c);
endmodule
entity fun2 is
port(a,b,c: in Std_logic;
f:out std_logic);
end fun2;
module fun2_v(a,b,c,f) ;
input a,b,c;
output f;
assign f= (~a& ~c) |( b& c);
endmodule
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
module mod_syn_v(clk,reset,p,q,d);
input clk,reset,p;
input [2:0]d;
output [2:0]q;
reg [2:0]q;
always@(posedge(clk))
begin
if (reset==1)
q=3'b000;
else if (p==1)
begin
if(q==3'b101)
q=3'b000;
else
q=q+1;
end
else
begin
if(q==3'b000)
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
q=3'b101;
else
q=q+1;
end
end
endmodule
7. Write the VHDL & Verilog representation of 4-bit Magnitude comparator Behavioral model.
entity question2 is
port(
a,b :in integer range 0 to 31;
a2,b2,c2,d2,e2,f2,g2: out std_logic);
end question2;
architecture compare of question2 is
signal compares : std_logic_vector(2 downto0);
signal outputs : std_logic_vector(6 downto0);
begin
process (a,b)
begin
if a<b then
compares <= "001";
elsifa=b then
compares <= "010";
elsifa>b then
compares <= "100";
else
compares <= "000";
end if;
end process;
with compares select outputs <=
"1110001" when "001”
"0110110" when "010",
"0001001" when "100",
"1111111" when others;
a2 <= outputs(6);
b2 <= outputs(5);
c2 <= outputs(4);
d2 <= outputs(3);
e2 <= outputs(2);
f2 <= outputs(1);
g2 <= outputs(0);
end compare;
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
8. Write the VHDL representation of 4-bit Ripple carry Adder in Behavioral model.
entity RCA is
port(a, b : in std_logic_vector(3 downto 0);
cout : out std_logic;
sum : out std_logic_vector(3 downto 0));
end entity RCA;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity FA is
port(a, b : in std_logic;
c: in std_logic;
cout : out std_logic;
sum : out std_logic);
end entity FA;
architecture df_FA of FA is
begin
cout <= (a and b) or (b and c) or (c and a);
sum <= a xor b xor c;
end architecture df_FA;
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar
5th SEM , (CBCS Scheme) HDL LAB [15ECL58]
module jk_ff(clk,j,k,reset,q,qb);
input clk,j,k,reset;
output reg q,qb;
always@(posedge clk)
begin
if(reset)
q=1'b0;
else
case({j,k})
2'b00:q=q;
2'b01:q=0;
2'b10:q=1;
2'b11:q=~q;
endcase
qb=~q;
end
endmodule
Prepared By: BHASAKR S VBE, M.Tech, LMISTE Dept. Of ECE, CBIT Kolar