Professional Documents
Culture Documents
Microsoft Word - HDLMANUAL - NEW2017
Microsoft Word - HDLMANUAL - NEW2017
Microsoft Word - HDLMANUAL - NEW2017
BANGALORE-560019
B.E., V Semester
[As per Choice Based Credit System (CBCS) scheme]
PROGRAMS:
PART-A
3. Write a VHDL and Verilog Code to describe the functions of a full adder using three modeling styles
4. Write a Verilog code to model 32 - BIT ALU using the schematic diagram shown below:
ALU should use combinational logic to calculate an output based on the four bit op-code input.
ALU should pass the result to the out bus when enable line is high and tri-state the out bus when the
enable line is low.
ALU should decode the 4-bit op-code according to the example given below:
5. Develop a Verilog code for the following flip-flops: SR, D, JK & T flip-flops.
6. Design a 4-bit Binary, BCD Counters (Synchronous Reset and Asynchronous Reset) and Any Sequence
Counters, using Verilog code.
PART-B
INTERFACING
2. Write VHDL/Verilog code to interface Hex key Pad and display the key code on seven segment display.
4. Write VHDL/Verilog code to accept analog signal, Temperature sensor and display the data on LCD or
Seven segment displays.
5. Write VHDL/Verilog code to generate different waveforms (Sine, Square, Triangle, Ramp etc.,) using
DAC – Change the frequency.
6. Click on Create File, select the target language, simulator language and source type as
Verilog.
7. Enter the name for the source file to be created. Click Next.
8. Select the board details as mentioned in the above slide to implement the application
code on the Artix-7 Board. Click Next.
9. Define a module, module name is the name of the source file created (step 7)
10. Give the name for the I/O port to use in the source file. Choose the direction as input
or output or inout.
11. If the I/O ports are vector select bus, specify the the size of the vector by specifying
the LSB and MSB value. For ex: for an input of 4-bits LSB=0 and MSB=3.
12. In the Sources pane, double-click the gates.v entry to open the file in text mode on
13. Click on Run Simulation > Run Behavioral Simulation under the Project Manager tasks of
the Flow Navigator pane. You will see a simulator output similar to the one shown below
14. Synthesize the Design Step. Synthesize the design with the Vivado synthesis tool and
analyze the Project Summary output. Click on Run Synthesis under the Synthesis tasks of the
Flow Navigator pane. The synthesis process will be run on the counter.v file (and all its
hierarchical files if they exist). When the process is completed a Synthesis Completed dialog
will appear. In The Flow Navigator, under Synthesis (expand Synthesized Design if
necessary), click on Schematic to view the synthesized design in a schematic view.
Fig: Synthesized design’s schematic view
15. In the Sources pane, open the Constraints folder and double-click the basys3.xdc entry to
open the file in text mode. Click on I/O ports in Schematic to view the pin design in a
schematic view define the pin locations of the input switches and lines the pin locations of
the output LEDs
16. Implement the Design Implement the design with Default settings and analyze the
Project Summary output. Click on Run Implementation under the Implementation tasks of
the Flow Navigator pane. The implementation process will be run on the synthesized design.
When the process is completed an Implementation Completed dialog box with three options
will be displayed.
a. Select Open implemented design and click OK as we want to look at the implemented
design in a Device view tab. In the Netlist pane, select one of the nets and notice that the
net displayed in the X1Y1 clock region in the Device view tab (you may have to zoom in
to see it).
b. When the Implementation process is completed Select Generate the Bitstream. The
bitstream generation process will be run on the implemented design.
17. When the process is completed a Bitstream Generation Completed dialog box with
three options will be displayed.
[Generate the Bitstream and Verify Functionality Connect the board and power it ON. Make
sure that the Micro-USB cable is connected to the JTAG PROG connector and Make sure
that the board is set to use USB power (via the Power Select jumper)]
a. Select the Open Hardware Manager option and click OK. The Hardware Manager
Window will open indicating “unconnected” status. Click on the Open target link.
b. Click Next to see the Hardware Server Settings form
c. Click Next with the Hardware Target selected. The JTAG cable which uses the Xilinx_tcf
should be detected and identified as a hardware target. It will also show the hardware devices
detected in the chain
19. Select the device and verify that the counter.bit is selected as the programming file in the
General tab.
Dept of Electronics and Communication Engg. V-Sem, HDL-Lab
23. Close the hardware session by selecting File > Close Hardware Manager.
25. Close the Vivado program by selecting File > Exit and click OK
PART-A
EXPERIMENT NO. 1
Write a Verilog code to realize all the logic gates
THEORY: The gate is a digital circuit with one or more input voltages but only one output
voltage. By connecting the different gates in different ways, we can build circuits that
perform arithmetic and other functions. Logic gates are the basic elements that make up a
digital system. The Electronic gate is a circuit that is able to operate on a number of binary
inputs in order to perform a particular logic function. The types of gates available are the
NOT, AND, OR, NAND, NOR, EXCLUSIVE-OR, and EXCLUSIVE-NOR.
a a a
a a h=a^b
f=~(a&b) g=~(a!b)
a
d=a&b e=a!b 7400 b
7402
b 7486
c=~a 7408
7404 b b 7432 b
1 0 0 0 1 1 0 1
1 1 0 1 1 0 0 0
VERILOG CODE
UCF File
NET "a" LOC = "<input pin numbers>" ;(to be referred from datasheet)
NET "b" LOC = "<input pin numbers>" ;
NET "c" LOC = "<output pin numbers>" ;
NET "d" LOC = "<output pin numbers>";
NET "e" LOC = "<output pin numbers>" ;
NET "f" LOC = "<output pin numbers>";
NET "g" LOC = "<output pin numbers>";
NET "h" LOC = "<output pin numbers>";
EXPERIMENT NO. 2
Write a Verilog program for the following Combinational logic designs
2 (a) 2 to 4 DECODER
AIM: To write a Verilog Code to realize 2 to 4 DECODER.
THEORY:
A decoder is a combinational circuit that converts binary information from n input
lines to a maximum of 2n unique output lines. A binary code of n bits is capable of
representing up to 2n distinct elements of the coded information.
A 2-to-4-line decoder, the two inputs are decoded into four outputs, each output
representing one of the minterms of the 2-input variables. A 2-to-4 decoder can be used for
decoding any 2 –bit code to provide 4-outputs, one for each element of the code.
BLOCK DIAGRAM
LOGIC DIAGRAM
Selector Output
0 X X Z Z Z Z
1 0 0 0 0 0 1
1 0 1 0 0 1 0
1 1 0 0 1 0 0
1 1 1 1 0 0 0
VERILOG CODE
module decoder2to4(x,enable,y);
input enable;
input [1:0] x;
output reg [3:0] y;
always @(x,enable)
begin
if (enable==1'b1)
begin
case(x)
2'b00:y = 4'b0001;
2'b01:y = 4'b0010;
2'b10:y = 4'b0100;
2'b11:y = 4'b1000;
endcase
end
else
y=4'bZZZZ;
end
endmodule
2 (b) 8 to 3 ENCODER
AIM: To write a Verilog Code to realize 8 to 3 Encoder (Encoder with and without
Priority)
THEORY:
An encoder is a digital function that produces a reverse operation from that of
decoder. An encoder has 2n (or less) input lines and n output lines. The output lines generate
the binary code for 2n input variables. The encoder assumes that only one input line can be
equal to 1 at any time. Otherwise the circuit has no meaning. If the encoder has 8 inputs and
could have 28 = 256 possible input combinations.
PRIORITY ENCODER:
These encoders establish an input priority to ensure that only the highest priority line
is encoded. For example 8-to-3-line priority encoder the inputs are a(0) ,a(1) ,…….a(7).
If the priority is given to an input with higher subscript number over one with a lower
subscript number, then if both a(2) and a(5) are logic-1 simultaneously , the output will be
101 because a(5) has higher priority over a(2).
BLOCK DIAGRAM
TRUTH TABLE
Inputs Output
En a0 a1 a2 a3 a4 a5 a6 a7 b0 b1 b2
0 x X X x x x x x z z z
1 0 0 0 0 0 0 0 1 1 1 1
1 0 0 0 0 0 0 1 0 1 1 0
1 0 0 0 0 0 1 0 0 1 0 1
1 0 0 0 0 1 0 0 0 1 0 0
1 0 0 0 1 0 0 0 0 0 1 1
1 0 0 1 0 0 0 0 0 0 1 0
1 0 1 0 0 0 0 0 0 0 0 1
1 1 0 0 0 0 0 0 0 0 0 0
VERILOG CODE
module encoder_without(en,a,b);
input en;
input[0:7]a;
output reg[2:0]b;
always @ (en,a)
begin
if (en==1'b1)
begin
Inputs Output
en a0 a1 a2 a3 a4 a5 a6 a7 b0 b1 b2
0 x x x x x x x x z z z
1 X X X X X X X 1 1 1 1
1 X X X X X X 1 0 1 1 0
1 X X X X X 1 0 0 1 0 1
1 X X X X 1 0 0 0 1 0 0
1 X X X 1 0 0 0 0 0 1 1
1 X X 1 0 0 0 0 0 0 1 0
1 X 1 0 0 0 0 0 0 0 0 1
1 1 0 0 0 0 0 0 0 0 0 0
VERILOG CODE
module encoder_with(en,a,b);
input en;
input [0:7] a;
else
b=3'dZZZ;
end
endmodule
2 (c) 8 to 1 MULTIPLEXER
AIM: To write a Verilog Code to realize 8 to 1 Multiplexer
I(0)
Selector O/P
I(1) S2 S1 S0 Y
I(2)
0 0 0 I(0)
I(3)
y 0 0 1 I(1)
I(4) 8:1 0 1 0 I(2)
MUX
I(5) 0 1 1 I(3)
I(6) 1 0 0 I(4)
I(7) 1 0 1 I(5)
1 1 0 I(6)
s(2) s(0) 1 1 1 I(7)
s(1)
THEORY: A Gray code represents each number in the sequence of integers as a binary
string of length N in an order such that adjacent integers have Gray code representations that
differ in only one bit position. The advantage of the gray code is that only one bit will change
as it proceeds from one number to the next. To obtain gray code, one can start with any bit
combination by changing only one bit from 0 to 1 or 1 to 0 in any desired random fashion, as
long as two numbers do not have identical code assignments.
CIRCUIT DIAGRAM
g(2)
7486
g(1)
7486
g(0)
7486
BCD-I/P Gray-Code-O/P
b(3) b(2) b(1) b(0) g(3) g(2) g(1) g(0)
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
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
VERILOG CODE
module bintogrey(b,g);
input [3:0] b;
output [3:0] g;
wire [3:0] g;
THEORY: Multiplexer (MUX) is a digital switch which connects data from one of n sources
to the output. A number of select inputs determine which data source is connected to the
output.
A 2 to 1 line multiplexer is shown in figure below, A & B are two inputs. En is enable.
Enable is used to enable or disable the multiplexer. Selection line S are decoded to select a
particular input. Y is a output which selects any one of the input depending on the select
lines. The truth table for the 2:1 mux is given in the table below.
En
Input Output
A SEL En Y
2:1
Y X 1 0
MUX
0 0 A
B
1 0 B
SEL
VERILOG CODE
2(e) 1: 8 DE-MULTIPLEXER
THEORY: A de-multiplexer is a circuit that receives the information on a single line and
transmits this information on one of 2n possible output lines. The selection of specific output
lines is controlled by the values of n selection lines. For 1: 8 de-multiplexers, the single input
variable has a path to all the eight outputs, but the input information is directed to only one of
the 8 output lines.
BLOCK DIAGRAM
TRUTH TABLE
Selector Output
I S2 S1 S0 y7 y6 y5 y 4 y3 y2 y1 y0
1/0 X X X Z Z Z Z Z Z Z Z
1/0 0 0 0 Z Z Z Z Z Z Z 1/0
1/0 0 0 1 Z Z Z Z Z Z 1/0 Z
1/0 0 1 0 Z Z Z Z Z 1/0 Z Z
1/0 0 1 1 Z Z Z Z 1/0 Z Z Z
1/0 1 0 0 Z Z Z 1/0 Z Z Z Z
1/0 1 0 1 Z Z 1/0 Z Z Z Z Z
1/0 1 1 0 Z 1/0 Z Z Z Z Z Z
1/0 1 1 1 1/0 Z Z Z Z Z Z Z
VERILOG CODE
COMPARATOR TABLE
VERILOG CODE
module comparator(a,b,x,y,z);
input [3:0] a, b;
output reg x, y, z;
always @(a , b)
begin
x = 1'b0;
y = 1'b0;
z = 1'b0;
if(a < b)
x = 1'b1; //when a is less than b then x is high
else if(a == b)
y = 1'b1; //when a is equal to b then y is high
else if(a > b)
z = 1'b1; //when a is greater than b then z is high
end
endmodule
EXPERIMENT NO. 3
Write a VHDL and Verilog Code to describe the functions of a full adder using three
modeling styles
AIM: Write a VHDL/ Verilog code to describe the functions of a FULL ADDER using
Following modeling styles.
i) Dataflow description
ii) Behavioral description
iii) Structural description
THEORY: A combinational circuit that performs the addition of two bits is called a half
adder. One that performs the addition of three bits (two significant bits and a previous carry)
is a Full adder.
The most basic arithmetic operation is the addition of two binary digits. This simple
addition consists of four possible elementary operations namely 0 + 0 = 0, 0 + 1 = 1, 1 + 0 =
1, 1 + 1 = 10.The first three operations produce a sum whose length is one digit, but when
both augend and addend bits are equal to 1, the binary sum consists of two digits. The higher
significant bit is called carry.
q
7408
7408
s2 carry
r
carry
7432
Cin
q
s3
Truth Table:
Inputs output
VHDL CODE:
library ieee;
use ieee.std_logic_1164.all;
entity fa_dataflow is
port (a,b,cin : in bit;
sum, carry : out bit );
end fa_dataflow;
end Behavioral;
VERILOG CODE:
VHDL CODE:
library ieee;
use ieee.std_logic_1164.all;
entity fa_behav is
Port ( a,b,cin : in std_logic;
sum,carry : out std_logic);
end fa_behav;
VERILOG CODE :
VHDL CODE:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity full_adder is
Port ( a, b, cin : in std_logic;
sum, cout : out std_logic);
end full_adder;
signal s1,s2,s3:std_logic;
begin
ECE Dept. BMS Evening College of Engineering 16
Dept of Electronics and Communication Engg. V-Sem, HDL-Lab
u0:xor_3 port map(a,b,cin,sum);
u1:and_2 port map(a,b,s1);
u2:and_2 port map(b,cin,s2);
u3:and_2 port map(cin,a,s3);
u4:or_3 port map(s1,s2,s3,cout);
end structural;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity and_2 is
Port ( x,y : in std_logic;
z : out std_logic);
end and_2;
architecture Behavioral of and_2 is
begin
z<=x and y;
end Behavioral;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity or_3 is
Port ( x,y,z : in std_logic;
Cout : out std_logic);
end or_3;
architecture Behavioral of or_3 is
begin
cout<=x or y or z;
end Behavioral;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
VHDL CODE :
library ieee;
use ieee.std_logic_1164.all;
entity full_adder_struct is
port ( a,b,cin : in bit;
sum, carry : out bit);
end full_adder_struct;
end Behavioral;
entity or_gate is
Port ( a : in std_logic;
b : in std_logic;
e : out std_logic);
end or_gate;
VERILOG CODE:
EXPERIMENT NO. 4
Write a Verilog code to model 32 - BIT ALU
AIM: Write a model for 32bit ALU using schematic diagram shown below
THEORY: The arithmetic logic unit (ALU) is a digital circuit that calculates an arithmetic
operation (like an addition, subtraction, etc.) and logic operations (like XOR, AND, NOT
etc.,) between two numbers. The ALU is a fundamental building block of the central
processing unit of a computer.
Many types of electronic circuits need to perform some type of arithmetic operation,
so even the circuit inside a digital watch will have a tiny ALU that keeps adding 1 to the
current time, and keeps checking if it should beep the timer, etc...
b (32) a( 32)
Enable Opcode- Input- a (32) Input- b (32) output -y
(4) (32)
0 X X X Z…….ZZZZ
1 0000 …….00001000 …….00000001 …….0000
op (4)
1001
Arithmetic y
(32) -Logic 1 0001 …….00001000 …….00000001 …….0000
0111
Unit
Enable (ALU) 1 0010 …….00001000 …….00000001 …….0000
1000
1 0011 …….00001000 …….00000001 …….1111
0111
1 0100 …….00001000 …….00000001 …….0000
0000
1 Others …….00001000 …….00000001 …….XXXX
XXXX
VERILOG CODE
4-bit ALU
Verilog code
module alu(a,b,opcode,enable,y, prod);
input [3:0] a,b;
input enable;
input [3:0] opcode;
output reg [4:0] y;
output reg [7:0] prod;
always @ (a,b,enable,opcode)
begin
if(enable==1)
begin
case(opcode)
4'b0000 : y=a+b;
4'b0001 : y=a-b;
4'b0010 : prod=a[3:0]*b[3:0];
4'b0011 : y=~a;
4'b0100 : y=a&b;
4'b0101 : y=a|b;
4'b0110 :y=~(a&b);
4'b0111 :y=~(a|b);
4'b1000 :y=(a^b);
default :y=5'bx;
endcase
end
else
y=5'bz;
EXPERIMENT NO. 5
Develop a Verilog code for the following flip-flops: SR, D, JK & T flip-flops.
5 (a) SR FLIP-FLOP
s s1
3 clk S R Q Qbar
1 q
1 0 0 Hold
clk 1 1 0 1 0
1 0 1 0 1
2 qn 1 1 1 z z
4
r r1 0 x x Hold
VERILOG CODE
THEORY: A flip-flop is a binary cell capable of storing one bit of information. A flip-flop
circuit has two outputs, one for the normal value and one for the compliment of bit stored in
it. A flip-flop circuit can maintain a binary state indefinitely until directed by an input signal
to switch states. The major difference between various flip-flops is in number of inputs they
possess and in the manner in which the inputs affect the binary state.
The D flip-flop receives the designation from its ability to transfer data into a flip-
flop. It’s basically an RS flip-flop with an inverter in the R input. This type of flip-flop
sometimes called as D- latch.
Clk D Q Qb
D D-Flip q 1 1 1 0
Flop 1 0 0 1
0 X X Hold
clk qb
VERILOG CODE
always @ (d,clk)
begin
if(clk==1)
begin
q=d;
qb=~d;
end
end
endmodule
THEORY: The T flip-flop is a single input version of the JK flip-flop. The T flip-flop is
obtained from JK flip-flop if both the inputs are tied together. The designation T comes from
the ability of the flip-flop to toggle. Regardless of the present state, it assumes the
complement state when the clock pulse occurs while input T is logic is 1.
T Q Qn
0 0 1
D Q 0 1 0
T 1 0 0
T-FF
1 1 1
CLK
Qn
VERILOG CODE
always @ (posedge(clk))
begin
clkdiv= clkdiv+1;
end
assign sclk= clkdiv[22];
always @ (posedge sclk)
begin
case(t)
1'b0 : q = q;
1'b1 : q =~q;
endcase
qb=~q;
end
endmodule
CLK J K Q Qb
J
Q 1 0 0 Hold
1 0 1 0 1
CLK J K- FF
1 1 0 1 0
Qb
K 1 1 1 Qb Q
VERILOG CODE
module jkff(jk,q,qb,clk);
input [1:0]jk;
input clk;
output reg q,qb;
wire sclk;
reg [22:0]clkdiv;
always @ (posedge(clk))
begin
clkdiv= clkdiv+1;
end
assign sclk= clkdiv[22];
always @ (posedge(sclk))
begin
case (jk)
2'b00:q=q;
2'b01:q=0;
2'b10:q=1;
2'b11:q=~q;
endcase
qb=~q;
end
endmodule
EXPERIMENT NO. 6
Design a 4-bit Binary, BCD Counters (Synchronous Reset and Asynchronous
Reset) and Any Sequence Counters, using Verilog code.
AIM: Design a 4-bit BCD COUNTER with synchronous reset and asynchronous
Reset.
THEORY: A counter is a register capable of counting the number of clock pulses arriving at
its clock input. There are two types of counters, synchronous and asynchronous. In
synchronous counter the common clock input is used to connect all the flip-flops and they are
clocked simultaneously. In Asynchronous counters the external clock pulse clocks the first
flip-flop and then each successive flip-flop is clocked by the output of previous flip-flop.
BCD stands for Binary Coded Decimal. A BCD counter has four outputs usually
labeled A, B, C, D. By convention A is the least significant bit, or LSB. In other words, the
counter outputs follow a binary sequence representing the decimal numbers 0-9.... this is why
its called as binary coded decimal counter.
VERILOG
module count(sclk,reset,q);
input sclk;
output reg [3:0]q;
module count(sclk,reset,q);
input sclk;
output reg [3:0]q;
wire clk;
reg [20:0]clkdiv;
always @ (posedge(sclk))
begin
clkdiv=clkdiv+1;
end
assign clk= clkdiv[20];
always @ (posedge(clk) or posedge(reset))
begin
if (reset==1)
q = 4'b0000;
else if (q==4'b1001)
q = 4'b0000;
else
q=q+1;
end
endmodule
VERILOG
module count(sclk,reset,q);
input sclk;
output reg [3:0]q;
VERILOG CODE
module count(sclk,reset,q);
input sclk;
output reg [3:0]q;
wire clk;
reg [20:0]clkdiv;
always @ (posedge(sclk))
begin
clkdiv=clkdiv+1;
end
assign clk= clkdiv[20];
always @ (posedge(clk))
begin
if (reset==1)
q = 4'b0000;
else
q=q+1;
VERILOG CODE
module count(sclk,reset,q);
input sclk;
output reg [3:0]q = 4’d3; //counter is inialized to starting value i,e 3
wire clk;
reg [20:0]clkdiv;
always @ (posedge(sclk))
begin
clkdiv=clkdiv+1;
end
assign clk= clkdiv[20];
always @ (posedge(clk))
begin
if (reset==1)
q = 4'b0000;
else
begin
case (q)
4’d3: q = 4’d4;
4’d4: q = 4’d8;
4’d8: q = 4’d9;
4’d9: q = 4’d11;
4’d11: q = 4’d15;
4’d15: q = 4’d3;
default: q = 4’d3;
endcase
end
end
endmodule
UP/DOWN COUNTER WITH SYNCHRONOUS RESET
Verilog
module count(sclk,ud,reset,q);
input sclk,ud;
output reg [3:0]q;
wire clk;
reg [20:0]clkdiv;
always @ (posedge(sclk))
ECE Dept. BMS Evening College of Engineering 30
Dept of Electronics and Communication Engg. V-Sem, HDL-Lab
begin
clkdiv=clkdiv+1;
end
assign clk= clkdiv[20];
always @ (posedge(clk))
begin
if (reset==1)
q = 4'b0000;
else if (ud==1)
q=q+1;
else
q=q-1;
end
endmodule
PART-B
INTERFACING EXPERIMENTS
EXPERIMENT NO. 1
SEVEN-SEGMENT DISPLAY INTERFACE
THEORY: 7-Segment display can display the digits 0-9 and the hex extension (A-F). A
signal-character displays bring out leads for 7-segments & the common elect code (Common
cathode & common anode). Here in FPGA/CPLD board to interface one 7-segment LED
display whose elements are connected to any I/O pins of the FPGA/CPLD.
Here we can consider common-anode 7-segment LED displays. The user can then ON by
driving associated signal low.
TRUTH TABLE:
INPUT OUTPUT
BCD LED
0000 1111110
0001 0110000
0010 1101101
0011 1111001
0100 0110011
0101 1011011
0110 1011111
0111 1110000
1000 1111111
1001 1111011
1010 1110111
1011 0011111
1100 1001110
1101 0111101
1110 1001111
1111 1000111
EXPERIMENT NO. 1A
PROGRAM TO DISPLAY HDLH ON SEVEN SEGMENT
VHDL
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity segment1 is
port ( header6 : out std_logic_vector(3 downto 0);
header7 : out std_logic_vector(6 downto 0);
sclk : in std_logic );
end segment1;
architecture prp of segment1 is
signal clkdiv : std_logic_vector(20 downto 0):="000000000000000000000";
signal state : std_logic_vector(1 downto 0);
signal clk1 : std_logic;
begin
process(sclk)
begin
if( rising_edge(sclk)) then
clkdiv <= clkdiv + 1;
end if;
clk1 <= clkdiv(13);
end process ;
process (clk1)
begin
if( rising_edge(clk1)) then
state <= state + 1;
end if;
end process ;
process (state)
begin
case state is
when "00" => header7<="1110110"; header6 <= "1110"; -- 'H'
when "01" => header7 <="1011110";header6 <= "1101"; -- 'D'
when "10" => header7 <="0111000";header6 <= "1011"; -- 'L'
when others => header7 <="1110110";header6 <= "1110"; --‘H’
end case ;
end process;
end prp;
ECE Dept. BMS Evening College of Engineering 33
Dept of Electronics and Communication Engg. V-Sem, HDL-Lab
EXPERIMENT NO. 1B
PROGRAM FOR BCD TO SEVEN SEGMENT DISPLAY
VHDL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity SEVSEG is
Port ( sclk : in std_logic;
q : inout std_logic_vector(3 downto 0);
header6 :out std_logic_vector(3 downto 0);
led : out bit_vector(6 downto 0));
end SEVSEG;
if (rising_edge(clk1)) then
if (count="1001") then
count<="0000";
else
count<=count+1;
end if;
end if;
end process;
q<=count;
process(q)
begin
case q is
when "0000"=>led<="0111111";
when "0001"=>led<="0000110";
ECE Dept. BMS Evening College of Engineering 34
Dept of Electronics and Communication Engg. V-Sem, HDL-Lab
when "0010"=>led<="1011011";
when "0011"=>led<="1001111";
when "0100"=>led<="1100110";
when "0101"=>led<="1101101";
when "0110"=>led<="1111100";
when "0111"=>led<="0000111";
when "1000"=>led<="1111111";
when "1001"=>led<="1100111";
when others=>led<="0000000";
end case;
header6<="0000";
end process;
end Behavioral;
EXPERIMENT NO. 2A
STEPPER MOTOR
AIM: Write the VHDL code to control speed and direction of Stepper Motor
THEORY: Stepper motors are electromechanical devices, which convert a digital pulses in
mechanical rotation, that provide accurate incremental rotation. The most common stepper
motor uses four windings for a four-phase operation. A typical four-phase motor driving
circuit is shown in Figure using an FPGA to generate the sequence logic. The clock (CLK)
input synchronizes the logic and determines the speed of rotation. The motor advances one
step per clock period; the angle of rotation of the shaft will depend on the particular motor.
To determine the clock period, consider that the stepper motor torque increases as frequency
decreases. The direction (DIR) control input changes the sequence at the outputs (PH1 to
PH4) to reverse the motor direction.
CIRCUIT DIAGRAM:
VDD
A
B
C
D
VHDL
entity stepmot1 is
port(dir : in std_logic;
rst : in std_logic;
step_signal : inout std_logic_vector(3 downto 0);
sclk : in std_logic);
end stepmot1;
process(sclk)
begin
if(rising_edge(sclk)) then
ECE Dept. BMS Evening College of Engineering 36
Dept of Electronics and Communication Engg. V-Sem, HDL-Lab
clkdiv <= clkdiv+1;
end if;
step_clk <= clkdiv(12);
end process;
process(step_clk,rst,dir)
begin
EXPERIMENT NO. 2b
DC MOTOR INTERFACE
VHDL
entity dcmotor is
Port ( str,dir : in STD_LOGIC;
pwm_out : out STD_LOGIC;
out_dc : out STD_LOGIC_VECTOR (1 downto 0));
end dcmotor;
EXPERIMENT NO. 3
VHDL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity elevator is
Port ( fl_req : in STD_LOGIC_VECTOR (2 downto 0);
Clk : in STD_LOGIC;
fl_disp : out STD_LOGIC_VECTOR (7 downto 0));
end elevator;
process(clk)
variable x :STD_LOGIC_VECTOR (22 downto 0);
begin
if rising_edge(clk) then
x:=x+1;
end if;
clk1<=x(22);
end process;
process(fl_req,curr_fl,clk1)
begin
if rising_edge(clk1) then
if (fl_req<curr_fl) then
curr_fl<=curr_fl-1;
elsif (fl_req>curr_fl) then
curr_fl<=curr_fl+1;
else
curr_fl<=curr_fl;
end if;
end if;
end process;
process(curr_fl)
What is FPGA :Field Programmable Gate Array, an array of logic gates whose configuration
can be programmed by the customer.
VHDL, intended as a specification langauge, is very exact in its nature and hence very
verbose.
Verilog, intended as a simulation langauge, it much closer to C in style, in that it is terse and
elegant to write but requires much more care to avoid nasty bugs. VHDL doesn't let you get
away with much; Verilog assumes that whatever you wrote was exactly what you intended to
write. If you get a VHDL architecture to compile, it's probably going to approximate to the
function you wanted. For Verilog, successful compilation merely indicates that the syntax
rules were met, nothing more. VHDL has some features that make it good for system-level
modelling, whereas Verilog is much better than VHDL at gate-level simulation.
Yes, there is a VHDL Analogue and Mixed Signal language (VHDL-AMS), based on VHDL
93, which allows modeling of both analogue and digital in the same language.
"A Complex Programmable Logic Device (CPLD) is a Programmable Logic Device with
complexity between that of PALs (Programmable Array Logic) and FPGAs, and architectural
features of both. The building block of a CPLD is the macro cell, which contains logic
implementing disjunctive normal form expressions and more specialized logic operations".
FPGA have special routing resources to implement binary counters,arithmetic functions like
adders, comparators and RAM. CPLD don't have special features like this.
FPGA can contain very large digital designs, while CPLD can contain small designs only.The
limited complexity (<500>
Speed: CPLDs offer a single-chip solution with fast pin-to-pin delays, even for wide input
functions. Use CPLDs for small designs, where "instant-on", fast and wide decoding, ultra-
low idle power consumption, and design security are important (e.g., in battery-operated
equipment).
Power: The high static (idle) power consumption prohibits use of CPLD in battery-operated
equipment. FPGA idle power consumption is reasonably low, although it is sharply
increasing in the newest families.
FIELD PROGRAMABLE GATE ARRAY. These ICs have programmable logic circuit
inside it. So it can be programmed in field itself according to the requirement of application.
No prior knowledge of application is required. Nowadays FPGAs are more popular than
ASIC.
What is Synthesis?
Synthesis is the stage in the design flow which is concerned with translating your VHDL
code into gates - and that's putting it very simply! First of all, the VHDL must be written in a
particular way for the target technology that you are using. Of course, a synthesis tool doesn't
actually produce gates - it will output a netlist of the design that you have synthesised that
represents the chip which can be fabricated through an ASIC or FPGA vendor.
Function always returns a value. Procedure may or may not return a value.
Functions can be called in SQL statements. Procedure can not be called in an SQL statement.
D-latch is level Triggering and D Flip Flop is Edge triggering. latch can have a clock.
difference is that for a latch the output can follow input(like a buffer) if latch is in "pass"
state, else if the clock input is such that the its in "latch"state then output is preserved.
Whereas, flip-flop output only changes at the clock edge(rising or falling depending upon
type of flop)
latch-it consists of both enable and clock.flip flop-it consists of only clock and no enable is
present for flip
flop.
mealy
it has less number of states.
it more prone to noise.
moore
it has more number of states.
it is less prone to noise.
just put a T FF. if u put a T FF u reduce the freq by half. if u put 2 power n FF, u reduce
the frequency by n times.
Whenever the simulator need storage to evaluate the value a registe is used. It is obvious
when you sample relative to clock. But combinatorial logic within an always process need to
be declared as process as well.
Nets, which connect modules use wire declaration. Same is for combinatorial, which are
assigned values by the assign value.
delay any pulse of small width is propagated to the output. The transport delay is especially
useful for modeling delay line drivers, wire delays on PC board, and on path delays on ASIC.
The inertial delay, which is the default delay type for VHDL, is used to model propagation
delay of gates and other devices. Inertial delay do not propagate short pulses from the input to
the output i.e. if a gate has an ideal inertial delay T, the input signal is delayed by time T, but
any pulse with a width less than T is rejected.
What are the different State machine Styles ? Which is better ? Explain disadvantages and
advantages.
Expand UCF?
What is the difference between compiled, interpreted, event based and cycle based
simulators?
What is code coverage and what are the different types of code coverage that one does ?
What is CPLD: CPLD are known to have short pin-to-pin delays, and can accept wide i/p’s,
but have relatively high power consumption and fewer f/f’s compared to FPGA’s
What is JTAG :Joint Test Action Group, older name for IEEE1149.1 Boundary scan, a
method to test PC board and ICs
K-map :a graphical tool for minimizing SOP or POS logic functions( useful for upto 6 logic
variables)