HDL Lab 37
HDL Lab 37
Total pages = 28
Circuit Diagram:
Boolean Expression:
VHDL Code:
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity decoder_38 is
Port ( a : in STD_LOGIC_VECTOR(2 DOWNTO 0);
a1 : out STD_LOGIC_VECTOR(7 DOWNTO 0));
end decoder_38;
Output:
Circuit:
Boolean Expression:
VHDL Code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity mux_8to1 is
Port ( s : in STD_LOGIC_VECTOR (2 downto 0);
x : in STD_LOGIC_VECTOR (7 downto 0);
y : out STD_LOGIC);
end mux_8to1;
Output:
VHDL Code:
Behavioral Modelling
library ieee;
use ieee.std_logic_1164.all;
entity demux is
port(x:IN STD_LOGIC;
s:IN STD_LOGIC_VECTOR(2 DOWNTO 0);
y:OUT STD_LOGIC_VECTOR(7 DOWNTO 0));
end demux;
end Behavioral;
Output:
Resources Required:
Hardware Requirement: Computer
Software Requirement: GHDL, GTKwave, Notepad++
Theory:
A full adder is a combinational circuit that forms the arithmetic sum of three bits. It consists of three inputs and
two outputs. Two of the inputs variables represent the two significant bits to be added. The third input
represents the carry from the previous lower significant position. The two outputs are designated by the symbols
S for sum and C for carry. The binary variable S gives the value of the least significant bit of the sum. The
binary variable C gives the output carry. The output variables are determined from the arithmetic sum of the
input bits. A binary adder is a digital circuit that produces the arithmetic sum of two binary numbers. It can be
constructed with full adder connected in cascade, the output carry from each full adder connected to the input
carry of the next full adder in the chain. Figure below shows the interconnection of four full adder (FA) circuits
to provide a 4-bit binary ripple carry adder. The augend bits of A and addend bits of B are designated by
subscript numbers from right to left, with subscript 0denoting the least significant bit. The carries are connected
in the chain through the full adders. The input carry to the adder is C0 and it ripples through the full adder to the
output carry C4.The S output generate the required sum bits.
Application:
1) The ALU (arithmetic logic circuitry) of a computer uses half adder to compute the binary addition operation
on two bits.
2) Half adder is used to make full adder as a full adder requires 3 inputs, the third input being an input carry i.e.
we will be able to cascade the carry bit from one adder to the other.
3) Ripple carry adder is possible to create a logical circuit using multiple full adders to add N-bit numbers. Each
full adder inputs a C(in), which is the C(out) of the previous adder. This kind of adder is called RIPPLE
CARRY ADDER, since each carry bit "ripples" to the next full adder. Note that the first full adder (and only the
first) may be replaced by a half adder.
VHDL Code:
Behavioral Modelling
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity full_adder_vhdl_code is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
Cin : in STD_LOGIC;
S : out STD_LOGIC;
Cout : out STD_LOGIC);
end full_adder_vhdl_code;
begin
end gate_level;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Ripple_Adder is
Port ( A : in STD_LOGIC_VECTOR (3 downto 0);
B : in STD_LOGIC_VECTOR (3 downto 0);
Cin : in STD_LOGIC;
S : out STD_LOGIC_VECTOR (3 downto 0);
Cout : out STD_LOGIC);
end Ripple_Adder;
component full_adder_vhdl_code
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
Cin : in STD_LOGIC;
S : out STD_LOGIC;
Cout : out STD_LOGIC);
end component;
begin
FA1: full_adder_vhdl_code port map( A(0), B(0), Cin, S(0), c1);
FA2: full_adder_vhdl_code port map( A(1), B(1), c1, S(1), c2);
FA3: full_adder_vhdl_code port map( A(2), B(2), c2, S(2), c3);
FA4: full_adder_vhdl_code port map( A(3), B(3), c3, S(3), Cout);
end Behavioral;
Output:
It can be used to compare two four-bit words. The two 4-bit numbers are A = A3 A2 A1 A0 and B3 B2 B1 B0
where A3 and B3 are the most significant bits.
It compares each of these bits in one number with bits in that of other number and produces one of the
following outputs as A = B, A < B and A>B. The output logic statements of this converter are
Boolean Expression
• If A3 = 1 and B3 = 0, then A is greater than B (A>B). Or
• If A3 and B3 are equal, and if A2 = 1 and B2 = 0, then A > B. Or
• If A3 and B3 are equal & A2 and B2 are equal, and if A1 = 1, and B1 = 0, then A>B. Or
• If A3 and B3 are equal, A2 and B2 are equal and A1 and B1 are equal, and if A0 = 1 and B0 = 0, then A
> B.
• the output A > B logic expression can be written as
• The equal output is produced when all the individual bits of one number are exactly coincides with
corresponding bits of another number. Then the logical expression for A=B output can be written as
• E = (A3 Ex-NOR B3) (A2 Ex-NOR B2) (A1 Ex-NOR B1) (A0 Ex-NOR B0)
Application: Comparators are used in central processing unit s (CPUs) and microcontrollers (MCUs).
Examples of digital comparator include the CMOS 4063 and 4585 and the TTL 7485 and 74682-'89.
VHDL Code:
Behavioral Modelling
Library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity COMPARATOR_SOURCE is
port ( A,B : in std_logic_vector(3 downto 0);
greater, equal, smaller : out std_logic);
end COMPARATOR_SOURCE ;
architecture bhv of COMPARATOR_SOURCE is
begin
greater <= '1' when (A > B)
else '0';
equal <= '1' when (A = B)
else '0';
smaller <= '1' when (A < B)
else '0';
end bhv;
Output:
Resource Required:
Hardware Requirement: Computer
Software Requirement: GHDL, GTKwave, Notepad++
Theory:
Counters are sequential logic devices that follow a predetermined sequence of counting states which are
triggered by an external clock (CLK) signal. The number of states or counting sequences through which a
particular counter advances before returning once again back to its original first state is called
the modulus (MOD). In other words, the modulus (or just modulo) is the number of states the counter counts
and is the dividing number of the counter. The decade counter has four outputs producing a 4-bit binary
number, it receives an input clock pulse, one by one, and counts up from 0 to 9 repeatedly.
VHDL code:
Behavioral Modelling
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity upcounter is
Port ( clk : in STD_LOGIC;
C : inout integer:=0);
end upcounter;
Resources Required:
Hardware Requirement: Computer
Software Requirement: GHDL, GTKwave, Notepad++
Theory:
The objective of this experiment is to introduce the use of sequential logic. The sequence is a sequential circuit.
In sequential logic the output depends on the current input values and also the previous inputs. When describing
the behaviour of a sequential logic circuit we talk about the state of the circuit. The state of a sequential circuit
is a result of all previous inputs and determines the circuit’s output and future behaviour. This is why sequential
circuits are often referred to as state machines. Most sequential circuits (including our sequence detector) use a
clock signal to control when the circuit changes states. The inputs of the circuit along with the circuit’s current
state provide the information to determine the circuit’s next state. The clock signal then controls the passing of
this information to the state memory. The output depends only on the circuit’s state, this is known as a Moore
Machine. Figure 7.1 shows the schematic of a Moore Machine.
A sequential circuit’s behaviour can be shown in a state diagram. The state diagram for our sequence detector is
shown in figure 7.2. Each circle represents a state and the arrows show the transitions to the next state. Inside
each circle are the state name and the value of the output. Along each arrow is the input value that corresponds
to that transition.
State Diagram:
1/0
0/0 1/0
0/0 1/0
S0 S1 S2 S3
1/0
0/1
0/0
Fig. Sequence Detector state diagram.
A sequence detector accepts as input a string of bits: either 0 or 1. Its output goes to 1 when a target sequence
has been detected. There are two basic types: overlap and non-overlap. In a sequence detector that allows
overlap, the final bits of one sequence can be the start of another sequence.
Example:
11011 detector with overlap X 11011011011
Z 00001001001
11011 detector with no overlap Z 00001000001
Applications:
In a computer network like Ethernet, digital data is sent one bit at a time, at a very high rate. Such a movement
of data is commonly called a bit stream. One characteristic is unfortunate, particularly that any one bit in a bit
stream looks identical to many other bits. Clearly it is important that a receiver can identify important features
in a bit stream. As an example, it is important to identify the beginning and ending of a message. This is the
job of special bit sequences called flags. A flag is simply a bit sequence that serves as a marker in the bit
stream. To detect a flag in a bit stream a sequence detector is used.
VHDL code:
Behavioral Modelling
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity seq_det is
port( clk : in std_logic;
reset : in std_logic;
input : in std_logic; --input bit sequence
output : out std_logic );
end seq_det;
Output:
Results: Thus, the VHDL code for the 1010 sequence detector circuit was simulated and verified.
EXPERIMENT - 8
Objective: Write a VHDL code to implement serial to parallel of 4-bit binary number.
Resources Required:
Hardware Requirement: Computer
Software Requirement: GHDL, GTKwave, Notepad++
Theory:
Note that after the fourth clock pulse has ended the 4-bits of data ( 0-0-0-1 ) are stored in the register and will
remain there provided clocking of the register has stopped. In practice the input data to the register may consist
of various combinations of logic “1” and “0”. Commonly available SIPO IC’s include the standard 8-bit
74LS164.
VHDL Code:
Behavioral Modelling
library ieee;
use ieee.std_logic_1164.all;
entity sipo is
port( res: in std_logic;
sin: in std_logic;
clk: in std_logic;
pout: out std_logic_vector(3 downto 0));
end sipo;
architecture beh of sipo is
signal temp: std_logic_vector( 3 downto 0);
begin
process( clk, res) begin
if(res='1') then
temp<="0000";
elsif (clk'event and clk ='1') then
temp(3)<=sin;
temp(2)<=temp(3);
temp(1)<=temp(2);
temp(0)<=temp(1);
end if;
end process;
pout<=temp;
end beh;
Output:
Results: VHDL code to implement serial to parallel of 4 bit binary number is simulated and verified.
EXPERIMENT-9
Objective: Write a VHDL program to perform parallel to serial transfer of 4 bit binary number
Resources Required:
Hardware Requirement: Computer
Software Requirement: GHDL, GTKwave, Notepad++
Theory:
Parallel-in/ serial-out shift registers do everything that the previous serial-in/ serial-out shift registers do plus
input data to all stages simultaneously. The parallel-in/ serial-out shift register stores data, shifts it on a clock
by clock basis, and delays it by the number of stages times the clock period. In addition, parallel-in/ serial-out
really means that we can load data in parallel into all stages before any shifting ever begins. This is a way to
convert data from a parallel format to a serial format. By parallel format we mean that the data bits are
present simultaneously on individual wires, one for each data bit as shown below. By serial format we mean
that the data bits are presented sequentially in time on a single wire or circuit as in the case of the “data out”
on the block diagram below.
.
Application:
1. Bit serial operations can be performed quickly through device iteration
2. Iteration (a purely combinational approach) is expensive (in terms of # of transistors, chip area, power,
etc).
3. A sequential approach allows the reuse of combinational functional units throughout the multi-cycle
operation
VHDL Code:
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity piso is
port(
clk : in STD_LOGIC;
reset : in STD_LOGIC;
load : in STD_LOGIC;
din : in STD_LOGIC_VECTOR(3 downto 0);
dout : out STD_LOGIC);
end piso;
architecture piso_arc of piso is
begin
piso1 : process (clk,reset,load,din) is
variable temp : std_logic_vector (din'range);
begin
if (reset='1') then
temp := (others=>'0');
elsif (load='1') then
if (rising_edge (clk)) then
temp := din ;
end if;
elsif (rising_edge (clk)) then
dout <= temp(3);
temp(3 downto 1) := temp(2 downto 0);
end if;
end process piso1;
end piso_arc;
Output:
Results: VHDL program to perform parallel to serial transfer of 4 bit binary number is simulated and verified.
EXPERIMENT–10
Objective: Write a program to design a 2-bit ALU containing 4 arithmetic & 4 logic operations.
Resources Required:
Hardware Requirement: Computer
Software Requirement: GHDL, GTKwave, Notepad++
Theory:
An ALU stands for arithmetic logic unit ALU is a digital circuit used to perform arithmetic and logic
operations. It represents the fundamental building block of the central processing unit of CPU. Modern CPUs
contains very powerful and complex ALUs. In some processors ALU is divided into two units an arithmetic unit
and a logic unit.
VHDL Code:
Behavioral Modelling
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ALU is
port(
inputA,inputB:IN STD_LOGIC_VECTOR(3 DOWNTO 0);
output:OUT STD_LOGIC_VECTOR(3 DOWNTO 0);
sel:IN STD_LOGIC_VECTOR(2 DOWNTO 0)
);
end ALU;
Output:
Results: Design of 2-bit ALU containing 4 arithmetic & 4 logic operations is simulated and verified.