Final DDCOLab Manual
Final DDCOLab Manual
Final DDCOLab Manual
LabManual
SL. Contents
No.
Design a 4 bit full adder and subtractor and simulate the same using
2 basic gates.
XilinxISE:
Xilinx ISE (Integrated Synthesis Environment) is a software tool produced by Xilinx for
synthesis and analysis of HDL designs, enabling the developer to synthesize ("compile") their
designs, perform timing analysis, examine RTL diagrams, simulate a design's reaction to
different stimuli, and configure the target device with the programmer.
In electronics ,a hardware description language (HDL) is a specialized computer language used
to describe the structure and behavior of electronic circuits ,and most commonly ,digital logic
circuits.
Register-transfer-level abstraction is used in hardware description languages (HDLs) like
Verilog and VHDL to create high-level representations of a circuit, from which lower-level
representations and ultimately actual wiring can be derived.Design at the RTL level is typical
practice in modern digital design.
Verilog, standardized as IEEE 1364, is a hardware description language (HDL) used to model
electronic systems. It is most commonly used in the design and verification of digital circuits at
the register-transfer level of abstraction. It is also used in the verification of on a log circuits and
mixed-signal circuits, as well as in the design of genetic circuits
AND GATE:
The AND gate performs logical multiplication known as AND function .if any one of the
input is low then output will be low. When the output is high means two inputs are high.
OR GATE:
The OR gate performs a logical addition commonly known as OR function. The output is high,
when any one of the input is high .The output is low when both the inputs are low.
Fig: Symbol & truth table Fig: Pin diagram Fig: Timing diagram
NOTGATE:
The NOT gate is called an inverter. The output is high when the input is low. The output is
low when the input is high.
Fig: Symbol & truth table Fig: Pin diagram Fig: Timing diagram
NAND GATE:
The NAND gate is a contraction of AND-NOT. The output is high when both inputs are low and
any one of the input is low .The output is low level when both inputs are high. The Nand-gate is
an and-gate with an inverter on the output .So instead of drawing several gates like this:
We draw a single and-gate with a little ring on the output like this:
The Nand-gate, like the and-gate can take an arbitrary number of inputs. The truth table for the
Nand-gate is like the one for the and-gate, except that all output values have been inverted:
Fig: Symbol & truth table Fig: Pin diagram Fig: Timing diagram
NORGATE:
The nor-gate is an or-gate with an inverter on the output. So instead of drawing several gates we
can write like this:
We draw a single or-gate with a little ring on the output like this:
The nor-gate, like the or-gate can take an arbitrary number of inputs. The truth table for the nor-
gate is like the one for the or-gate, except that all output values have been inverted:
Fig: Symbol & truth table Fig: Pin diagram Fig: Timing diagram
Exclusive-ORGATE:
The “Exclusive OR Gate” is another type of digital logic gate commonly used in arithmetic
operations since it can be used to give the sum of two binary numbers as well as error-detection and
correction circuits.
Fig: Symbol & truth table Fig: Pin diagram Fig: Timing diagram
4. Double click on synthesis. If error occurs edit and correct VHDL code
5. Double click on Lunch model sim (or any equivalent simulator if you are using) for
functional simulation of your design.
6.Right click on sample.VHD in source window, select new
source
Select source: Implementation constraints file.
Filename: sample
This will create sample. UCF constraints file.
7. Double click on Edit constraint (Text) in process
window. Edit and enter pin constraints with syntax:
NET“NETNAME”LOC=“PINNAME”
8. Double click on Implement, which will carry out translate, mapping, place and route of your
design. Also generate program file by double clicking on it, intern which will create .bit file.
9. Connect JTAG cable between your kit and parallel pot of your computer.
10. 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
11. Right click on device and select ‘program ’. Verify your design giving appropriate inputs and
check for the output.
12. Also verify the actual working of the circuit using pattern generator &logic analyzer.
1. Given a 4-variable logic expression, simplify it using appropriate technique and simulate the
same using basic gates.
Aim: To simulate the 4 variable expressions realized using basic gates.
Theory: Boolean algebra is a branch of mathematics that deals with operations on logical values
with binary variables. The Boolean variables are represented as binary numbers to represent truths:
1 = true and 0 = false. Elementary algebra deals with numerical operations whereas Boolean algebra
deals with logical operations.
Boolean algebra is the category of algebra in which the variable’s values are the truth values, true
and false, ordinarily denoted 1 and 0 respectively. It is used to analyze and simplify digital circuits
or digital gates. It is also called Binary Algebra or logical Algebra. It has been fundamental in the
development of digital electronics and is provided for in all modern programming languages. It is
also used in set theory and statistics.
The important operations performed in Boolean algebra are – conjunction (∧), disjunction (∨) and
negation (¬). Hence, this algebra is far way different from elementary algebra where the values of
variables are numerical and arithmetic operations like addition, subtraction is been performed on
them.
Assume that the 4-variable Boolean function Y = F(A,B,C,D) = ∑ (2, 4, 5, 7, 10, 14)
INPUT OUTPUT
A B C D Y
0 0 0 0 0
0 0 0 1 0
0 0 1 0 1
0 0 1 1 0
0 1 0 0 1
0 1 0 1 1
0 1 1 0 0
0 1 1 1 1
1 0 0 0 0
1 0 0 1 0
1 0 1 0 1
1 0 1 1 0
1 1 0 0 0
1 1 0 1 0
1 1 1 0 1
1 1 1 1 0
2. Design a 4 bit full adder and Subtractor and simulate the same using basic gates.
Input 0 (I0) is A
Input 1 (I1) is A
that has control input D that is also connected to the initial carry, then the modified adder performs
addition when D = 0, or
subtraction when D = 1.
This works because when D = 1 the A input to the adder is really A and the carry in is 1.
Adding B to A and 1 yields the desired subtraction of B − A.
A way you can mark number A as positive or negative without using a multiplexer on each bit is to
use an XOR gate to precede each bit instead.
The first input to the XOR gate is the actual input bit
The second input for each XOR gate is the control input D
This produces the same truth table for the bit arriving at the adder as the multiplexer solution does
since the XOR gate output will be what the input bit is when D = 0 and the inverted input bit
when D = 1.
cin A3 A2 A1 A0 B3 B2 B1 B0 D3 D2 D1 D0 BO
1 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 1 0 0 0 1 0 0 0 0 1
1 0 0 1 0 0 0 0 1 0 0 0 1 1
1 0 0 1 1 0 0 0 1 0 0 1 0 1
1 0 1 0 0 0 0 1 1 0 0 0 1 1
1 1 0 0 0 0 0 1 0 0 1 1 0 1
1 1 0 1 0 0 1 1 0 0 1 0 0 1
1 0 1 1 1 0 1 1 1 0 0 0 0 1
1 0 0 1 0 0 1 0 0 1 1 1 0 0
1 1 0 0 1 1 0 1 1 1 1 0 1 0
1 1 0 1 0 1 0 1 1 1 1 1 1 0
1 0 1 1 1 1 0 1 1 1 1 0 0 0
1 0 1 1 0 1 1 0 0 1 0 1 0 0
1 1 0 0 1 1 1 1 1 1 0 1 0 0
1 1 0 1 0 1 1 1 0 1 1 0 0 0
1 1 1 1 0 1 1 1 1 1 1 1 1 0
3. Design Verilog HDL to implement simple circuit using structural, Data flow and behavioural
model.
Aim: To implement simple circuit using Structural, Data flow and Behavioural model.
Theory: Verilog HDL composed of a text using keywords. Keywords are identifiers that defines
the language constrains like module, endmodule, input, output, wire, not,or etc.
Verilg HDL describes the digital circuits as a set of modules, a module is basic building block of a
Verilog HDL. It is declared by the keyword module and always terminated by the keyword
endmodule. Each of this module has an interface to other module to describe how they are
interconnected.
Behavioural:
module simple_circuit(A,B,C,D);
input A,B,C;
output D;
reg D;
wire w1,w2,w3,w4;
always@(A,B,C)
begin
w1=(!B);
w2=(!C);
w3=(A && w1);
w4=(A && w2);
w3=(w3 && w4);
endmodule
Structural:
module simple_circuit(A,B,C,D);
input A,B,C;
output D;
wire w1,w2,w3,w4;
not (w1,B);
not (w2,C);
and (w3,A,w1);
and (w4,A,w2);
or (D,w3,w4);
endmodule
4. Design Verilog HDL to implement Binary Adder-Subtractor – Half and Full Adder, Half
and Full Subtractor.
Aim: To simulate half adder, full adder, half subtractor and full subtractor in VHDL
Theory: Adder circuit is a combinational digital circuit that is used for adding numbers. A
typical adder circuit produces a sum bit (denoted by S) and a carry bit (denoted by C) as
the output. Adders are used in the arithmetic logic units, in other parts of the processor, where
they are used to calculate addresses, table indices, increment and decrement operators.
Half-Adder: A combinational logic circuit that adds two single binary digits A and B. It has
two outputs, sum (S) and carry (C). The carry signal represents an overflow into the next
digit of a multi-digit addition.
Full-Adder: The half-adder does not take the carry bit from its previous stage into account.
This carry bit from its previous stage is called carry-in bit (Cin). A combinational logic
circuit that adds two data bits A, B, and a carry-in bit Cin, is called a full-adder. It has
two outputs, sum (S) and carry (C).
Subtractor circuit is a combinational digital circuit that is used for subtracting numbers.
A typical subtractor circuit produces a diffrence bit (denoted by D) and a brrow bit
(denoted by B) as the output.
PROCEDURE:
1. Check all the components for their working.
2. Insert the appropriate IC into the IC base.
OBSERVATION TABLE:
Truth Table for Half Adder: Truth Table for Half Subtractor:
Truth Table for Full Adder: Truth Table for Full Subtractor:
SIMULATION:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity FullSubtractor is
Port ( A,B,C : in STD_LOGIC;
Diff,Borrow : out STD_LOGIC);
end FullSubtractor;
architecture equation of FullSubtractor is begin
Diff <= (((not A)and(not b)and c)or((not A)and B and(not C))or(a and(not B)and(not
C))or(A and B and C));
Borrow <= (A and B)or(B and C)or(A and C);
end equation;
1. The truth table of half adder, half subtractor, full adder and full subtractor is verified.
2. The output waveform of half adder, half subtractor, full adder and full subtractor is
simulated and verified
Truth table
//declare the inputs and outputs of the module with their sizes.
input [3:0] a,b;
input carry_in;
output [3:0] sum;
output carry;
//Internal variables
reg [4:0] sum_temp;
reg [3:0] sum;
reg carry;
begin
sum_temp = sum_temp+6; //add 6, if result is more than 9.
carry = 1; //set the carry output
sum = sum_temp[3:0];
end
else begin
carry = 0;
sum = sum_temp[3:0];
end
end
endmodule
Output waveform
6. Design Verilog program to implement different types of multiplexer like 2:1, 4:1 and 8:1.
Aim: To simulate 2:1, 4:1 and 8:1 multiplexer in VHDL
Theory: A multiplexer (or mux; spelled sometimes as multiplexor), also known as a data selector,
is a device that selects between several analog or digital input signals and forwards the selected
input to a single output line.[1] The selection is directed by a separate set of digital inputs known as
select lines. A multiplexer of inputs has select lines, which are used to select which input line to
send to the output.
A multiplexer makes it possible for several input signals to share one device or resource, for
example, one analog-to-digital converter or one communications transmission medium, instead of
having one device per input signal. Multiplexers can also be used to implement Boolean
functions of multiple variables.
4:1 MULTIPLEXER
8:1 MULTIPLEXER
//1:8 Demultiplexer
//1:4 Demultiplexer
module Demultiplexer1_4(in,s0,s1,d0,d1,d2,d3);
Prof. Malashree M S, Dept of CSE, MIT, Mysore Page 23
MAHARAJA INSTITUTE OF TECHNOLOGY MYSORE
Behind Belawadi, KRMills, Srirangapatna(T), Mandya-571477
input in,s0,s1;
output d0,d1,d2,d3;
assign d0=(in & ~s1 & ~s0 ),
d1=(in & ~s1 &s0),
d2=(in & s1 &~s0),
d3=(in & s1 &s0),
endmodule
OR
module demux1_4(a_in,sel,y_out)
input[1:0]sel;
output[3:0]y_out;
reg[3:0]y_out;
always@(a_in,sel)
begin
case(sel)
2’b00:beginy_out[0]=a_in;y_out[1]=1’b0;
y_out[2]=1’b0;y_out[3]=1’b0;
end
2’b01:beginy_out[0]=1’b0;y_out[1]=a_in;
y_out[2]=1’b0;y_out[3]=1’b0;
end
2’b10:begin y_out[0]=1’b0;y_out[1]=1’b0;
y_out[2]=a_in;y_out[3]=1’b0;
end
2;b11:begin y_out[0]=1’b0;y_out=1’b0;
y_out[2]=1’b0;y_out[3]=a_in;
end
default:y_out=3’b000;
endcase
end
endmodule
1:2 Demultiplexer
8. Design Verilog program for implementing various types of Flip-Flops such as SR, JK and D.
Aim: To simulate SR, JK and D Flipflop in VHDL
Theory: In electronics, flip-flops and latches are circuits that have two stable states that can store
state information – a bistable multivibrator. The circuit can be made to change state
by signals applied to one or more control inputs and will output its state (often along with its logical
complement too). It is the basic storage element in sequential logic. Flip-flops and latches are
fundamental building blocks of digital electronics systems used in computers, communications, and
many other types of systems.
Flip-flops and latches are used as data storage elements to store a single bit (binary digit) of data;
one of its two states represents a "one" and the other represents a "zero". Such data storage can be
used for storage of state, and such a circuit is described as sequential logic in electronics. When
used in a finite-state machine, the output and next state depend not only on its current input, but
also on its current state (and hence, previous inputs). It can also be used for counting of pulses, and
for synchronizing variably-timed input signals to some reference timing signal.
SR Flip-flop:
The SR Flip-Flop is also known as the gated or clocked SR latch. The clocked SR latch or SR flip-
flop temporarily stores or holds the information until it is needed in digital circuits. ‘S’ and ‘R’ are
the two inputs to the SR flip-flop. It has two outputs, the main output ‘Q’ and the complements of
the main output ‘ Q’ ‘. The SR Flip-Flop is a storage element with only one bit.
The SR flip-flop is a gated SR flip-flop with a clock input circuitry that does not prevent the illegal
or invalid output state that can arise when both inputs S and R are equal to logic level “1”. The SR
latch is constructed using two cross-coupled NAND gates. Let us discuss in detail about these in the
upcoming sections.
Circuit Diagram:
Simulation:
module srff(clk,s,r,q,qb);
input clk,s,r;
output reg q,qb;
q <= q;
endcase
end
JK Flip-flop:
JK Flip Flop is one of the most used flip-flops in digital circuits. The universal flip flop has two
inputs, ‘J’ and ‘K.’ The JK Flip Flop is a gated SR Flip-Flop with a clock input circuitry that
prevents the illegal or invalid output when both inputs S and R are equal to logic level “1.”
In the SR Flip-Flop, the ‘S’ and ‘R’ are the shortened abbreviated letters for the Set and Reset, but J
and K are not. Instead, the J and K are autonomous letters chosen to distinguish the flip flop design
from other types. Let us discuss in detail JK Flip-Flop in the upcoming sections.
Circuit Diagram:
Simulation:
module jkff(clk,j,k,q,qb);
input clk,j,k;
output reg q,qb;
endmodule
D Flip-flop:
D flip-flop is a two-input flip-flop. The inputs are the data (D) input and a clock (CLK) input. The
clock is a timing pulse generated by the equipment to control operations. The D flip-flop is used to
store data at a predetermined time and hold it until it is needed. This circuit is sometimes called a
delay flip-flop. In other words, the data input is delayed up to one clock pulse before it is seen in the
output.
The simplest form of a D flip-flop is shown in the figure below, view A. Now, follow the
explanation of the circuit using the truth table and the timing diagram shown in the figure,
Circuit diagram:
Simulation:
module RisingEdge_DFlipFlop_SyncReset(D,clk,sync_reset,Q);
input D;
input clk;
input sync_reset;
output reg Q;
always @(posedge clk)
begin
if(sync_reset==1'b1)
Q <= 1'b0;
else
Q <= D;
end
endmodule
Output waveform:
The truth table of half adder, half subtractor, full adder and full subtractor is verified
The output waveform of half adder, half subtractor, full adder and full subtractor is
simulated and verified