BEC302_Lab_Manual
BEC302_Lab_Manual
BEC302_Lab_Manual
DEPARTMENT
OF
ELECTRONICS AND TELECOMMUNICATION ENGINEERING
SIR M VISVESVARAYA INSTITUTE OF TECHNOLOGY
Krishnadevaraya Nagar, Off Internation Airport Road, Bengaluru – 64
DEPARTMENT OF
ELECTRONICS AND TELECOMMUNICATION ENGINEERING
PRACTICAL COMPONENT OF IPCC (Experiments can be conducted either using any circuit simulation
software or discrete components)
Sl.N Experiments
1 To simplify the given Boolean expressions and realize using Verilog program
2 To realize Adder/Subtractor(Full/half)circuits using Verilog data flow description.
3 To realize 4-bit ALU using Verilog program.
4 To realize the following Code converters using Verilog Behavioral description
a)Gray to binary and vice versa b)Binary to excess3 and vice versa
5 To realize using Verilog Behavioral description:8:1mux, 8:3encoder, Priority encoder
6 To realize using Verilog Behavioral description:1:8Demux, 3:8 decoder,2 –bit Comparator
7 To realize using Verilog Behavioral description:
Flip-flops: a)JK type b)SR type c)T type and d)D type
8 To realize Counters-up/down (BCD and binary)using Verilog Behavioral description.
Demonstration Experiments (For CIE only–not to be included for SEE)
Use FPGA/CPLD kits for down loading Verilog codes and check the output for interfacing
experiments.
9 Verilog Program to interface a Stepper motor to the FPGA/CPLD and rotate the motor
in the specified direction (by N steps).
10 Verilog programs to interface Switches and LEDs to the FPGA/CPLD and demonstrate
its working.
Course outcomes (Course Skill Set):
At the end of the course the student will be able to:
1. Simplify Boolean functions using K-map and Quine-McCluskey minimization technique.
2. Analyze and design for combinational logic circuits.
3. Analyze the concepts of Flip Flops(SR, D,T and JK) and to design the synchronous sequential
circuits using Flip Flops.
4. Model Combinational circuits (adders, subtractors, multiplexers) and sequential circuits using
Verilog descriptions.
The theory portion of the IPCC shall be for both CIE and SEE, whereas the practical portion
will have a CIE component only. Questions mentioned in the SEE paper may include questions
from the practical component.
The minimum marks to be secured in CIE to appear for SEE shall be 10 (40% of maximum
marks-25) in the theory component and 10 (40% of maximum marks -25) in the practical
component. The laboratory component of the IPCC shall be for CIE only. However, in SEE,
the questions from the laboratory component shall be included. The maximum of 04/05 sub-
questions are to be set from the practical component of IPCC, the total marks of all questions
should not be more than 20 marks.
SEE will be conducted for 100 marks and students shall secure 35% of the maximum marks to
qualify for the SEE. Marks secured will be scaled down to 50.
The student is declared as a pass in the course if he/she secures a minimum of 40% (40 marks
out of 100) in the sum total of the CIE (Continuous Internal Evaluation) and SEE (Semester
End Examination) taken together.
Suggested Learning Resources:
Books
1. Digital Logic Applications and Design by John MYarbrough,Thomson Learning,2001.
2. Digital Principles and Design by Donald DGivone,McGrawHill, 2002.
3. HDL Programming VHDL and Verilog by Nazeih M Botros, 2009 reprint, Dream techpress.
ReferenceBooks:
1. Fundamentals of logic design, by Charles H Roth Jr., Cengage Learning
2. Logic Design, by Sudhakar Samuel, Pearson/Sanguine, 2007
3. Fundamentals of HDL,by Cyril PR, Pearson/Sanguine2010
Web links and Video Lectures (e-Resources):
1. Algorithmic level [much like ‘C’ with if, case and logic statements]
2. Register Transfer level [RTL use registers connected by Boolean equations]
3. Gate level [Interconnected AND, NAND, OR Gates, etc.]
4. Switch level [The switches are MOS transistors inside gates]
More recently, Verilog is used as an input for synthesis programs which will generate
a GATE level description for the circuit.
FLOW CHART
PROCUDURE
Xilinx ISE Design Suite is one of most popular software tools used to synthesize
HDL code. This tool includes many steps. To make user feel comfortable with the tool
the steps are given below –
• Double click on Project navigator. (Assumed icon is present on desktop).
• Select NEW PROJECT in FILE MENU. Enter following details as per your
convenience.
Project name : sample
Project location : C:\example Top level module: HDL
route of your design. Also, generate program file by double clicking on it, intern
that will create .bit file.
• Connect JTAG cable between your kit and parallel pot of your computer.
• Double click on configure device and select mode in which you want to configure
your device. For ex: select slave serial mode in configuration window and finish
your configuration.
• Right click on device and select ‘program’. Verify your design giving appropriate
inputs and check for the output.
• Also, verify the actual working of the circuit using pattern generator & logic
analyzer.
EXPERIMENT – 1
Boolean Expression
AIM:
To simplify the given Boolean expressions and realize using Verilog program.
̅𝑩
𝑭(𝑨, 𝑩, 𝑪) = 𝑨 ̅𝑪
̅+𝑨
̅ 𝑩𝑪
̅+𝑨
̅ 𝑩𝑪 + 𝑨𝑩
̅𝑪̅ + 𝑨𝑩
̅𝑪
TRUTH TABLE:
INPUTS OUTPUT
A B C F
0 0 0 1
0 0 1 0
0 1 0 1
0 1 1 1
1 0 0 1
1 0 1 1
1 1 0 0
1 1 1 0
K – MAP SIMPLIFICATION:
𝑭 = 𝑨𝑪 + (𝑨 ⨁ 𝑩)
VERILOG CODE
RESULT:
The given Boolean expression is realized and simulated using Verilog. Simulated results
are verified with the truth table.
EXPERIMENT – 2 (a)
Half Adder
AIM:
THEORY:
It is a type of Adder which adds two binary bits and producers to outputs sum and
carry respectively. The two inputs are A and B. The output carry is designed as C and the
normal output is designed as S which is the sum.
Stimulus can be written with respect to the truth table given aside for logic gates
using half adder.
DIAGRAM:
TRUTH TABLE:
VERILOG CODE
RESULT:
The half adder is realized and simulated using Verilog. Simulated results are verified with
the truth table.
EXPERIMENT – 2 (b)
Full Adder
AIM:
THEORY:
Full Adder is the adder that adds three inputs and produces two outputs. The first
two inputs are A and B and the third input is an input carry as C-IN. The output carry is
designated as C-OUT and the normal output is designated as S which is SUM. The C-OUT
is also known as the majority 1’s detector, whose output goes high when more than one
input is high.
DIAGRAM:
TRUTH TABLE:
VERILOG CODE
module full_adder_d (
input a, b, cin,
output sum, carry
);
assign sum = a ^ b ^ cin;
assign carry = (a & b) | (b & cin) | (cin & a);
endmodule
initial begin
a = 0; b = 0; cin = 0;
#10
a = 0; b = 0; cin = 1;
#10
a = 0; b = 1; cin = 0;
#10
a = 0; b = 1; cin = 1;
#10
a = 1; b = 0; cin = 0;
#10
a = 1; b = 0; cin = 1;
#10
a = 1; b = 1; cin = 0;
#10
a = 1; b = 1; cin = 1;
end
endmodule
RESULT:
The full adder is realized and simulated using Verilog. Simulated results are verified with
the truth table.
EXPERIMENT – 2 (c)
Half Subtractor
AIM:
THEORY:
It is a type of Subtractor which Subtract two binary bits and producers to outputs
difference and borrow respectively. The two inputs are A and B. The output borrow is
designed as B and the normal output is designed as D which is the difference.
Stimulus can be written with respect to the truth table given aside for logic gates
using half subtractor.
DIAGRAM:
TRUTH TABLE:
VERILOG CODE
initial begin
P = 0; Q = 0;
#1;
P = 0; Q = 1;
#1;
P = 1; Q = 0;
#1;
P = 1; Q = 1;
end
endmodule
RESULT:
The half subtractor is realized and simulated using Verilog. Simulated results are verified
with the truth table.
EXPERIMENT – 2 (d)
Full Subtractor
AIM:
THEORY:
A full subtractor is designed to accommodate the extra borrow bit from the
previous stage. Thus it has three single-bit inputs and produces two single-bit outputs.
Consider that we want to subtract three 1-bit numbers. The numbers are X, Y and Z
then a difference bit (D) and a borrow bit (B) will get generated.
DIAGRAM:
TRUTH TABLE:
VERILOG CODE
#1 X = 1; Y = 1; Z = 0;
#1 X = 1; Y = 1; Z = 1;
end
endmodule
RESULT:
The full subtractor is realized and simulated using Verilog. Simulated results are verified
with the truth table.
EXPERIMENT – 3
Arithmetic and Logic Unit [ALU]
AIM:
Verilog 4-bit ALU shown in figure and verify the functionality of ALU by selecting
appropriate test patterns. The functionality of the ALU is presented in Table 1.
a. Write test bench to verify the functionality of the ALU considering all possible
input patterns
b. The enable signal will set the output to required functions if enabled, if disabled all
the outputs are set to tri-state
c. The acknowledge signal is set high after every operation is completed
THEORY:
The ALU has 4-bit inputs ‘A’ and ‘B’ and produces one 4-bit output by performing
a specified arithmetic or logical functions on A and B inputs. The particular function to be
performed is specified by a 3-bit control input. ALU (arithmetic and logic unit) is a
combinational digital circuit that performs arithmetic and bitwise operations on integer
binary numbers.
DIAGRAM:
OPERATION TABLE:
VERILOG CODE
if (en == 1'b0)
aluout = 4'dz;
else
begin
aluout = 4'b0;
case(opcode)
3'd0: begin aluout = a + b; ack = 1; end
3'd1: begin aluout = a - b; ack = 1; end
3'd2: begin aluout = a + 1; ack = 1; end
3'd3: begin aluout = a - 1; ack = 1; end
3'd4: begin aluout = !a; ack = 1; end
module alu32_tb;
reg [3:0] a;
reg [3:0] b;
reg [2:0] opcode;
reg en;
wire [3:0] aluout;
wire ack;
alu32 uut (.a(a), .b(b), .opcode(opcode), .en(en), aluout(aluout),
.ack(ack));
initial
begin
a = 0; b = 0; en = 0; opcode = 0;
#100;
a = 4'd5; b = 4'd5; en = 1; opcode = 3'b000;
#100
opcode = 3'b001;
#100
opcode = 3'b010;
#100
opcode = 3'b011;
#100
opcode = 3'b100;
#100
opcode = 3'b101;
#100
opcode = 3'b110;
#100
opcode = 3'b111;
end
endmodule
RESULT:
The functionality of a 4-bit ALU, as given, were verified considering all possible input
patterns and the given task was performed with Verilog code and Test bench.
EXPERIMENT – 4 (a)
Binary to Gray
AIM:
THEORY:
Binary Number is the default way to store numbers, but in many applications,
binary numbers are difficult to use and a variety of binary numbers is needed. This is
where Gray codes are very useful.
Gray code has a property that two successive numbers differ in only one
bit because of this property gray code does the cycling through various states with
minimal effort and is used in K-maps, error correction, communication, etc.
DIAGRAM:
TRUTH TABLE:
VERILOG CODE
module Binary_to_Gray(
input [3:0] b,
output reg[3:0] g
);
always@(b)
begin
g[0]=b[1]^b[0];
g[1]=b[2]^b[1];
g[2]=b[3]^b[2];
g[3]=b[3];
end
endmodule
initial begin
b=4'b0000;
#10 b=4'b0001;
#10 b=4'b0010;
#10 b=4'b0011;
#10 b=4'b0100;
#10 b=4'b0101;
#10 b=4'b0110;
#10 b=4'b0111;
#10 b=4'b1000;
#10 b=4'b1001;
#10 b=4'b1010;
#10 b=4'b1011;
#10 b=4'b1100;
#10 b=4'b1101;
#10 b=4'b1110;
#10 b=4'b1111;
end
endmodule
Fig. 1.3. Output Waveform of 4-bit binary to gray converter generated by Isim Simulator
RESULT:
The binary to gray converter is realized and simulated using Verilog. Simulated results are
verified with the truth table.
EXPERIMENT – 4 (b)
Gray to Binary
AIM:
DIAGRAM:
TRUTH TABLE:
module Binary_to_Gray(
input [3:0] b,
output reg[3:0] g
);
always@(b)
begin
b[0]=b[1]^g[0];
b[1]=b[2]^g[1];
b[2]=g[3]^g[2];
b[3]=g[3];
end
endmodule
initial begin
g=4'b0000;
#10 g=4'b0001;
#10 g=4'b0010;
#10 g=4'b0011;
#10 g=4'b0100;
#10 g=4'b0101;
#10 g=4'b0110;
#10 g=4'b0111;
#10 g=4'b1000;
#10 g=4'b1001;
#10 g=4'b1010;
#10 g=4'b1011;
#10 g=4'b1100;
#10 g=4'b1101;
#10 g=4'b1110;
#10 g=4'b1111;
end
endmodule
Fig. 1.3. Output Waveform of Gray to Binary converter generated by Isim Simulator
RESULT:
The 4-bit gray to binary converter is realized and simulated using Verilog. Simulated
results are verified with the truth table.
EXPERIMENT – 4 (c)
Binary to Excess-3
AIM:
THEORY:
DIAGRAM:
TRUTH TABLE:
0 0 0 0 0 0 1 1
0 0 0 1 0 1 0 0
0 0 1 0 0 1 0 1
0 0 1 1 0 1 1 0
0 1 0 0 0 1 1 1
0 1 0 1 1 0 0 0
0 1 1 0 1 0 0 1
0 1 1 1 1 0 1 0
1 0 0 0 1 0 1 1
1 0 0 1 1 1 0 0
1 0 1 0 1 1 0 1
1 0 1 1 1 1 1 0
1 1 0 0 1 1 1 1
1 1 0 1 x x x x
1 1 1 0 x x x x
1 1 1 1 x x x x
VERILOG CODE
end
endmodule
#100 B = 4'b0000;
#100 B = 4'b0001;
#100 B = 4'b0010;
#100 B = 4'b0011;
#100 B = 4'b0100;
#100 B = 4'b0101;
#100 B = 4'b0110;
#100 B = 4'b0111;
#100 B = 4'b1000;
#100 B = 4'b1001;
#100 B = 4'b1010;
#100 B = 4'b1011;
#100 B = 4'b1100;
#100 B = 4'b1101;
#100 B = 4'b1110;
#100 B = 4'b1111;
end
endmodule
RESULT:
The binary to excess-3 converter is realized and simulated using Verilog. Simulated results
are verified with the truth table.
EXPERIMENT – 4 (d)
Excess-3 to Binary
AIM:
DIAGRAM:
TRUTH TABLE:
0 0 0 0 x x x x
0 0 0 1 x x x x
0 0 1 0 x x x x
0 0 1 1 0 0 0 0
0 1 0 0 0 0 0 1
0 1 0 1 0 0 1 0
0 1 1 0 0 0 1 1
0 1 1 1 0 1 0 0
1 0 0 0 0 1 0 1
1 0 0 1 0 1 1 0
1 0 1 0 0 1 1 1
1 0 1 1 1 0 0 0
1 1 0 0 1 0 0 1
1 1 0 1 1 0 1 0
1 1 1 0 1 0 1 1
1 1 1 1 1 1 0 0
VERILOG CODE
begin
#100 E = 4'b0000;
#100 E = 4'b0001;
#100 E = 4'b0010;
#100 E = 4'b0011;
#100 E = 4'b0100;
#100 E = 4'b0101;
#100 E = 4'b0110;
#100 E = 4'b0111;
#100 E = 4'b1000;
#100 E = 4'b1001;
#100 E = 4'b1010;
#100 E = 4'b1011;
#100 E = 4'b1100;
#100 E = 4'b1101;
#100 E = 4'b1110;
#100 E = 4'b1111;
end
endmodule
RESULT:
The excess-3 to binary converter is realized and simulated using Verilog. Simulated results
are verified with the truth table.
EXPERIMENT – 5 (a)
Multiplexer
AIM:
To realize 8:1 multiplexer circuit using Verilog behavioural description.
THEORY:
Multiplexer is a digital switch. It allows digital information from several sources to
be rooted on to a single output line. The basic multiplexer has several data input lines and
a single output line. The selection of a particular input line is controlled by a set of
selection lines. Normally there are 2N input lines and N selection lines whose bit
combinations determine which input is selected. Therefore, multiplexer is many into one
and it provides the digital equivalent of an analog selector switch.
DIAGRAM:
TRUTH TABLE:
VERILOG CODE
I = 8'b01010101;
S = 3'b000;
#100 S = 3'b001;
#100 S = 3'b010;
#100 S = 3'b011;
#100 S = 3'b100;
#100 S = 3'b101;
#100 S = 3'b110;
#100 S = 3'b111;
end
endmodule
RESULT:
EXPERIMENT – 5 (b)
Encoder
AIM:
To realize 8:3 encoder circuit using Verilog behavioural description.
THEORY:
An encoder is a digital circuit which performs the inverse of decoder. An encoder
has 2N input lines and N output lines. In encoder the output lines generate the binary code
corresponding to input value. The decimal to bcd encoder usually has 10 input lines and 4
output lines. The decoder decimal data as an input for decoder an encoded bcd output is
available at 4 output lines.
DIAGRAM:
TRUTH TABLE:
Table 5.2. Truth Table of 8:3 Encoder
INPUTS OUTPUTS
E D[7] D[6] D[5] D[4] D[3] D[2] D[1] D[0] Y[2] Y[1] Y[0]
1 x x x x x x x x 0 0 0
0 0 0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 1 0 0 0 1
0 0 0 0 0 0 1 0 0 0 1 0
0 0 0 0 0 1 0 0 0 0 1 1
0 0 0 0 1 0 0 0 0 1 0 0
0 0 0 1 0 0 0 0 0 1 0 1
0 0 1 0 0 0 0 0 0 1 1 0
0 1 0 0 0 0 0 0 0 1 1 1
VERILOG CODE
module encoder8_3_tb;
reg [7:0] D;
reg E;
wire [2:0] Y;
E = 1;
D = 8'b00000001;
#100;
E = 0;
D = 8'b00000001;
#100;
D = 8'b00000010;
#100;
D = 8'b00000100;
#100;
D = 8'b00001000;
#100;
D = 8'b00010000;
#100;
D = 8'b00100000;
#100;
D = 8'b01000000;
#100;
D = 8'b10000000;
end
endmodule
RESULT:
The 8 to 3 encoder is realized and simulated using Verilog. Simulated results are verified
with the truth table.
EXPERIMENT – 5 (c)
Priority Encoder
AIM:
To realize 8:3 priority encoder circuit using Verilog behavioural description.
THEORY:
In case of an ordinary encoder, one and only one decimal input can be activated at
any given time. But in the case of some practical digital systems, two or more decimal
inputs can unintentionally become active at the same time that might cause a confusion. In
digital electronics, a combinational logic circuit which produces outputs in response to
only one input among all those that may be activated at the same time is called a priority
encoder. For this, it uses a priority system, and hence it is named so.
DIAGRAM:
TRUTH TABLE:
INPUTS OUTPUTS
E D[7] D[6] D[5] D[4] D[3] D[2] D[1] D[0] Y[2] Y[1] Y[0]
1 x x x x x x x x 0 0 0
0 0 0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 1 x 0 0 1
0 0 0 0 0 0 1 x x 0 1 0
0 0 0 0 0 1 x x x 0 1 1
0 0 0 0 1 x x x x 1 0 0
0 0 0 1 x x x x x 1 0 1
0 0 1 x x x x x x 1 1 0
0 1 x x x x x x x 1 1 1
VERILOG CODE
module encoder_pri8_3_tb;
reg [7:0] D;
reg E;
wire [2:0] Y;
encoder_pri8_3 uut (.Y(Y), .D(D), .E(E));
initial
begin
E = 1;
D = 8'b00000001;
#100;
E = 0;
D = 8'b00000001;
#100;
D = 8'b0000001x;
#100;
D = 8'b000001xx;
#100;
D = 8'b00001xxx;
#100;
D = 8'b0001xxxx;
#100;
D = 8'b001xxxxx;
#100;
D = 8'b01xxxxxx;
#100;
D = 8'b1xxxxxxx;
end
endmodule
RESULT:
The 8 to 3 priority encoder is realized and simulated using Verilog. Simulated results are
verified with the truth table.
EXPERIMENT – 6 (a)
Demultiplexer
AIM:
THEORY:
DIAGRAM:
TRUTH TABLE:
VERILOG CODE
module demux_1_8(y,s,a);
output reg [7:0]y;
input [2:0]s;
input a;
always @(*)
begin
y=0;
case(s)
3'd0: y[0]=a;
3'd1: y[1]=a;
3'd2: y[2]=a;
3'd3: y[3]=a;
3'd4: y[4]=a;
3'd5: y[5]=a;
3'd6: y[6]=a;
3'd7: y[7]=a;
endcase
end
endmodule
RESULT:
The 1:8 Demultiplexer is realized and simulated using Verilog. Simulated results
are verified with the truth table.
EXPERIMENT – 6 (b)
Decoder
AIM:
THEORY:
A decoder is a combinational logic circuit that change the binary information into
2N output lines is known as Decoders. The binary information is passed in the form of N
input lines. The output lines define the 2N-bit code for the binary information. In simple
words, the Decoder performs the reverse operation of the Encoder. At a time, only one
input line is activated for simplicity. The produced 2N-bit output code is equivalent to the
binary information.
DIAGRAM:
TRUTH TABLE:
Table 6.2. Truth Table of 3:8 Decoder
VERILOG CODE
EXPERIMENT – 6 (c)
Comparator
AIM:
THEORY:
DIAGRAM:
TRUTH TABLE:
VERILOG CODE
module 2_Mag_Comp(
input [1:0]a,b,
output equal, greater, lower
);
reg greater, equal, lower;
initial greater = 0, equal = 0, lower = 0;
always @ (a or b)
begin
if (a < b)
begin
greater = 0; equal = 0; lower = 1;
end
else if (a == b)
begin
greater = 0; equal = 1; lower = 0;
end
else
begin
greater = 1; equal = 0; lower = 0;
end
end
endmodule
EXPERIMENT – 7 (a)
AIM:
THEORY:
The SR flipflop is a 1-bit memory by stable device which stands for “Set-Reset”
flipflop having two inputs, i.e., SET and RESET. The SET input ‘S’ sets the device or
produces the output 1 and the RESET input ‘R’ resets the device or produces the output 0.
The reset input is used to get back the flip flop into its original state from the current state
within input ‘Q’. This output depends on the set and reset conditions, which is either at the
logic ‘0’ or ‘1’.
DIAGRAM:
TRUTH TABLE:
Clk sr q qb
00 0 0
01 0 1
10 1 0
11 z z
VERILOG CODE
module srff (q, qb, sr, clk);
output q, qb;
input clk;
input [1:0] sr;
reg q = 0, qb = 1;
always@ (posedge clk)
begin
case(sr)
2'b00 : q = q;
2'b01 : q = 0;
2'b10 : q = 1;
2'b11 : q = 1'bx;
endcase
qb = ~q;
end
endmodule
#100;
sr = 2'b10;
#100;
sr = 2'b00;
#100;
sr = 2'b11;
end
endmodule
RESULT:
The Verilog Code for SR flipflop was realized and the output is verified.
EXPERIMENT – 7 (b)
AIM:
THEORY:
The JK flipflop is basically gated SR flipflop with the addition of a clock input
circuitry, that prevents the illegal or invalid output condition that can occur when both
input S and R are equal to logic level “1”. Due to this additional clock input, a JK flipflop
has four possible input combinations, “logic 1”, “logic 0”, “No Change” and “Toggle” as
shown in the truth table for JK flipflop.
JK flip flop is called Universal flipflop because the other flip flops like a D, SR, T
can be derived from it. The “racing or race around condition” takes place in a JK flip flop
when J = 1 and K = 1 and clock = 1
DIAGRAM:
TRUTH TABLE:
clk jk q qb
00 0 1
01 0 1
10 1 0
11 𝑞̅ 𝑞𝑏
̅̅̅
VERILOG CODE
module jkff(q, qb, jk, clk);
output q, qb;
input clk;
input [1:0] jk;
reg q=0, qb=1;
always@(posedge clk)
begin
case (jk)
2'b00:q=q;
2'b01:q=0;
2'b10:q=1;
2'b11:q=~q;
endcase
qb=~q;
end
endmodule
begin
#100;
jk = 2'b00;
#100;
jk = 2'b01;
#100;
jk = 2'b10;
#100;
jk = 2'b00;
#100;
jk = 2'b11;
end
endmodule
RESULT:
The Verilog Code for JK flipflop was realized and the output is verified.
EXPERIMENT – 7 (c)
AIM:
THEORY:
D flipflop stands for Delay flipflop or Data flipflop. In this flipflop, the single input
“D” is referred to as the “Data” input. When the data input is set to 1, the flipflop would be
set and when it is set to 0, the flipflop would change and become reset. When the clock
input is set to true, the D input is only copied to the output ‘Q’ as shown in the truth table.
DIAGRAM:
TRUTH TABLE:
clk d q qb
0 0 1
1 1 0
VERILOG CODE
module dff(q, qb, d, clk);
output q, qb;
input d, clk;
reg q=0, qb=1;
always@ (posedge clk)
begin
q= d;
qb=~q;
end
endmodule
RESULT:
The Verilog Code for D flipflop was realized and the output is verified.
EXPERIMENT – 8
AIM:
Write a Verilog Code and Test Bench for 4-bit BCD synchronous counter.
THEORY:
In a synchronous counter, the clock input of all the individual flipflops within the
counter are all clocked together at the same time by the same clock signal. The result of
this synchronization is that all the individual output bits changing starts at exactly the same
time in response to the common clock signal with no ripple effect and therefore, no
propagation delay.
When a 4-bit BCD synchronous counter counts upwards from 0 (0000) to 9 (1001),
it is called a 4-bit BCD synchronous up counter and when the counter start with 9 (1001)
and count downward to 0 (0000) then it is called a 4-bit BCD synchronous down counter.
DIAGRAM:
TRUTH TABLE:
VERILOG CODE
Fig. 8.2. Output Waveform of 4-bit BCD Up Counter generated by Isim Simulator
RESULT:
The 4-bit synchronous up counter is designed and implemented using Verilog code.
TRUTH TABLE:
VERILOG CODE
endmodule
Fig. 8.3. Output Waveform of 4-bit BCD Down Counter generated by Isim Simulator
RESULT:
The 4-bit synchronous down counter is designed and implemented using Verilog code.
DEMONSTRATION EXPERIMENT
Interface a Stepper motor to FPGA and write Verilog code to control the stepper motor
rotation.
AIM:
Write a Verilog code to design a digital circuit that controls the speed and direction of
the Stepper motor interfaced to FPGA.
DIAGRAM:
VERILOG CODE
module step_motor(
input p_clk,
output reg[3:0] p_stp
);
reg [20:0] count = 0;
reg [16:0] dur = 0;
reg [3:0] stpval = 'b0001;
reg dir = 0;
if (count == speed)
begin
count = 0;
p_stp = stpval;
if (dir == 0)
begin
stpval = stpval << 1;
if (stpval == 'b0000) stpval = 'b0001;
end
else
begin
stpval = stpval >> 1;
if (stpval == 'b0000) stpval = 'b1000;
end
OBSERVATION:
200 Steps for one full rotation i.e., 3600
3600
1 𝑠𝑡𝑒𝑝 = = 1. 80
200
1000
= 5 𝑟𝑜𝑡𝑎𝑡𝑖𝑜𝑛𝑠
200
PIN ASSOCIATION:
NET "p_clk" LOC = P56;
NET "p_stp[0]" LOC = P29;
NET "p_stp[1]" LOC = P30;
NET "p_stp[2]" LOC = P32;
NET "p_stp[3]" LOC = P33;
RESULT:
Stepper Motor is interfaced to a FPGA and its speed and direction is verified.