Professional Documents
Culture Documents
SN EXPERIMENT TITLES
1 INTRODUCTION TO XILINX WITH RESPECT TO FAULTS, ERRORS & FAILURES
2 FAULT MODELING ON BASIC GATES (AND-OR-NOT)
3 FAULT MODELING USING ADDERS AND DECODERS
4 PERFORMANCE EVALUATIONS (MTTF, MTTR ETC.) OF MULTIPLEXERS AND
DEMULTIPLEXERS
5 APPLYING REDUNDANCY TO COMBINATIONAL & SEQUENTIAL CIRCUITS AND TESTING
THEM
6 APPLYING PATH SENSITIZATION TECHNIQUES ON DIFFERENT CIRCUITS FOR PERMANENT
& TRANSIENT FAULTS
7 TEST PATTERN GENERATION FOR DIFFERENT FAULT MODELS
8 DETECTING & TESTING FAULTS IN 8-BIT ALU & 3 TO 8-BIT DECODER
9 DESIGNING LINEAR FEEDBACK SHIFT REGISTERS (LFSR COUNTERS)
10 IMPLEMENTATION AND TESTING ON MEALY MACHINE & MOORE MACHINE
11 DESIGNING A FAULT DETECTABLE ODD PARITY GENERATOR & PULSE GENERATOR
12 DESIGN OF FAULT DETECTING AND CORRECTING PRIORITY ENCODER & BCD-TO-7
SEGMENT DECODER
13 IMPLEMENTING THE HAMMING CODE AND TESTING IT ON MEALY MACHINE & MOORE
MACHINE
14 DESIGN IMPLICATIONS FAULT MODELS OF MEALY MACHINES
1
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
2
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
LAB # 01
Introduction to Xilinx With Respect to Faults, Errors & Failures
Objective:
To simulate the AND gate logic through VHDL coding.
Using Xilinx
Create a New Project
Create a new IS project which will target the FPGA device on Spartan-3 start up kit
demo board.
i) Select File –>New Project…. The New Project Wizard appears.
3
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
vii) Click NEXT to proceed to create new source window in the New Project Wizard. At
the end of the next section, your new project will be complete.
4
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
vi) Declare the ports for the gate design by filling in the port information as shown
below:
vii) Click Next , then Finish in the New Source Wizard – summary dialog box to complete
the New Source file template appears.
5
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
The source file containing the entity/ architecture pair displays in the Workspace,
and the counter displays in the Source tab, as shown below.
The newly created .vhd file has the skeleton code. Add the line Y <= A and B; below
the first begin and the code is complete for AND gate. The complete code is shown
below:
6
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
When the source files are complete, check the syntax of the design to find errors and typos.
7
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
Create a test bench waveform containing input stimulus you can use to verify the
functionality of the counter module. The test bench waveform is a graphical view of a test bench.
Create the test bench waveform as follows:
iii) In the New Source wizard, select VHDL TESTBENCH as a source type and type
basicgates_tbw in the File Name field.
iv) Click Next.
8
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
v) The associated Source page shows that you are associating the test bench waveform
with the source file basicgates. Click Next.
vi) The summary page shows that the source will be added to the project, and it
displays the source directory, type, and name. Click Finish.
Verify that the counter design functions as you expect by performing behaviour simulation
as follows:
9
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
i) Verify that Behavioural Simulation and basicgates_tbw are selected in the Source
Window.
ii) In the Process Window, click the ‘+’ to expand the Xilinx ISim Simulator process and
double-click the Simulate Behavioral Model process.
The ISE Simulator opens and runs the simulation to the end of the test bench.
iii) To view your simulation results, select the Simulation tab.
iv) The simulation waveform results will look like the following.
10
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
VHDL Program
--import std_logic from the IEEE library
library ieee;
use ieee.std_logic_1164.all;
process
--variable to track errors
variable errCnt : integer := 0;
begin
--TEST 1
inA <= '0';
inB <= '0';
wait for 15 ns;
11
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
--TEST 2
inA <= '0';
inB <= '1';
wait for 15 ns;
assert(outF = '0') report "Error 2" severity error;
if(outF /= '0') then
errCnt := errCnt + 1;
end if;
--TEST 3
inA <= '1';
inB <= '1';
wait for 15 ns;
assert(outF = '1') report "Error 3" severity error;
if(outF /= '1') then
errCnt := errCnt + 1;
end if;
end process;
end tb;
--------------------------------------------
configuration cfg_tb of andGate_tb is
for tb
end for;
end cfg_tb;
---------------------------------------------------------END
---------------------------------------------------------END
12
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
Objectives/Outcomes
Understand the Xilinx ISE software.
Learn to VHDL module for code and testbench.
Write a basic Xilinx code for AND gate.
Time Boxing
Activity Name Activity Time Total Time
Login Systems + Setting up Xilinx ISE 3 mints + 7 mints 10 mints
Walk through Theory & Tasks 60 mints 60 mints
Implement Tasks 80 mints 80 mints
Evaluation Time 30 mints 30 mints
Total Duration 180 mints
13
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
14
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
LAB # 02
Fault Modelling on Basic Gates (AND-OR-NOT)
Introduction
A logic gate is an idealized or physical device implementing a Boolean function; that is, it
performs a logical operation on one or more binary inputs and produces a single binary output.
Depending on the context, the term may refer to an ideal logic gate, one that has for instance zero
rise time and unlimited fan-out, or it may refer to a non-ideal physical device
Logic gates are primarily implemented using diodes or transistors acting as electronic switches, but
can also be constructed using vacuum tubes, electromagnetic relays (relay logic), fluidic logic,
pneumatic logic, optics, molecules, or even mechanical elements. With amplification, logic gates can
be cascaded in the same way that Boolean functions can be composed, allowing the construction of
a physical model of all Boolean logic, and therefore, all of the algorithms and mathematics that can
be described with Boolean logic.
And-Gate
The AND gate is a basic digital logic gate that implements logical conjunction - it behaves
according to the truth table shown. A HIGH output (1) results only if all the inputs to the AND gate
are HIGH (1). If none or not all inputs to the AND gate is HIGH, a LOW output results. The function
can be extended to any number of inputs.
INPUT OUTPUT
A B A AND B
0 0 0
0 1 0
1 0 0
1 1 1
VHDL Program
--import std_logic from the IEEE library
library ieee;
use ieee.std_logic_1164.all;
15
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
process
--variable to track errors
variable errCnt : integer := 0;
begin
--TEST 1
inA <= '0';
inB <= '0';
wait for 15 ns;
assert(outF = '0') report "Error 1" severity error;
if(outF /= '0') then
errCnt := errCnt + 1;
end if;
--TEST 2
inA <= '0';
inB <= '1';
wait for 15 ns;
assert(outF = '0') report "Error 2" severity error;
if(outF /= '0') then
16
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
errCnt := errCnt + 1;
end if;
--TEST 3
inA <= '1';
inB <= '1';
wait for 15 ns;
assert(outF = '1') report "Error 3" severity error;
if(outF /= '1') then
errCnt := errCnt + 1;
end if;
end process;
end tb;
--------------------------------------------
configuration cfg_tb of andGate_tb is
for tb
end for;
end cfg_tb;
---------------------------------------------------------END
---------------------------------------------------------END
Or-Gate
The OR gate is a digital logic gate that implements logical disjunction – it behaves according
to the truth table shown. A HIGH output (1) results if one or both the inputs to the gate are HIGH (1).
If neither input is high, a LOW output (0) results. In another sense, the function of OR effectively finds
the maximum between two binary digits, just as the complementary AND function finds the
minimum.
INPUT OUTPUT
A B A AND B
0 0 0
0 1 1
1 0 1
1 1 1
17
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
VHDL Program
--import std_logic from the IEEE library
library ieee;
use ieee.std_logic_1164.all;
process
--variable to track errors
variable errCnt : integer := 0;
begin
--TEST 1
inA <= '0';
inB <= '0';
wait for 15 ns;
18
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
--TEST 2
inA <= '0';
inB <= '1';
wait for 15 ns;
assert(outF = '0') report "Error 2" severity error;
if(outF /= '0') then
errCnt := errCnt + 1;
end if;
--TEST 3
inA <= '1';
inB <= '1';
wait for 15 ns;
assert(outF = '1') report "Error 3" severity error;
if(outF /= '1') then
errCnt := errCnt + 1;
end if;
end process;
end tb;
--------------------------------------------
configuration cfg_tb of orGate_tb is
for tb
end for;
end cfg_tb;
---------------------------------------------------------END
---------------------------------------------------------END
Not-Gate
In digital logic, an inverter or NOT gate is a logic gate which implements logical negation.
The truth table is shown.
INPUT OUTPUT
A NOT A
0 1
1 0
19
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
VHDL Program
--import std_logic from the IEEE library
library ieee;
use ieee.std_logic_1164.all;
process
--variable to track errors
variable errCnt : integer := 0;
begin
--TEST 1
inA <= '0';
20
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
--TEST 2
inA <= '1';
wait for 15 ns;
assert(outF = '0') report "Error 2" severity error;
if(outF /= '0') then
errCnt := errCnt + 1;
end if;
end process;
end tb;
--------------------------------------------
configuration cfg_tb of notGate_tb is
for tb
end for;
end cfg_tb;
---------------------------------------------------------END
---------------------------------------------------------END
21
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
Objectives/Outcomes
Understand logic gates.
Write basic VHDL codes for implementing gates.
Simulate each gate and see the result.
Time Boxing
Activity Name Activity Time Total Time
Login Systems + Setting up Xilinx ISE 3 mints + 7 mints 10 mints
Walk through Theory & Tasks 60 mints 60 mints
Implement Tasks 80 mints 80 mints
Evaluation Time 30 mints 30 mints
Total Duration 180 mints
22
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
23
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
LAB # 03
Fault Modelling Using Adders and Decoders
Adders
An adder is a digital circuit that performs addition of numbers. In many computers and other kinds of
processors adders are used in the arithmetic logic units or ALU. They are also utilized in other parts
of the processor, where they are used to calculate addresses, table indices, increment and decrement
operators, and similar operations. Although adders can be constructed for many number
representations, such as binary-coded decimal or excess-3, the most common adders operate on
binary numbers. In cases where two's complement or ones' complement is being used to represent
negative numbers, it is trivial to modify an adder into an adder–subtractor. Other signed number
representations require more logic around the basic adder.
Half Adder
The half adder 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. The value of the sum in decimal
system is 2C + S. The simplest half-adder design, pictured on the right, incorporates an XOR gate for S and
an AND gate for C. The Boolean logic for the sum (in this case S) will be A'B+AB' whereas for carry (C) will
be AB. With the addition of an OR gate to combine their carry outputs, two half adders can be combined
to make a full adder. The half adder adds two input bits and generates a carry and sum, which are the two
outputs of a half adder. The input variables of a half adder are called the augend and addend bits. The
output variables are the sum and carry.
Full Adder
A full adder adds binary numbers and accounts for values carried in as well as out. A one-bit full-adder
adds three one-bit numbers, often written as A, B, and Cin; A and B are the operands, and Cin is a bit
carried in from the previous less-significant stage. The full adder is usually a component in a cascade
of adders, which add 8, 16, 32, etc. bit binary numbers. The circuit produces a two-bit output.
24
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
VHDL Program
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;
ENTITY Testbench_full_adder IS
END Testbench_full_adder;
COMPONENT full_adder_vhdl_code
25
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
PORT(
A : IN std_logic;
B : IN std_logic;
Cin : IN std_logic;
S : OUT std_logic;
Cout : OUT std_logic
);
END COMPONENT;
--Inputs
signal A : std_logic := '0';
signal B : std_logic := '0';
signal Cin : std_logic := '0';
--Outputs
signal S : std_logic;
signal Cout : std_logic;
BEGIN
-- Stimulus process
stim_proc: process
begin
-- hold reset state for 100 ns.
wait for 100 ns;
A <= '0';
B <= '1';
Cin <= '0';
wait for 10 ns;
A <= '1';
B <= '1';
Cin <= '0';
wait for 10 ns;
A <= '0';
26
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
B <= '0';
Cin <= '1';
wait for 10 ns;
A <= '1';
B <= '0';
Cin <= '1';
wait for 10 ns;
A <= '0';
B <= '1';
Cin <= '1';
wait for 10 ns;
A <= '1';
B <= '1';
Cin <= '1';
wait for 10 ns;
end process;
END;
Decoders
In digital electronics, a binary decoder is a combinational logic circuit that converts binary information
from the n coded inputs to a maximum of 2n unique outputs. They are used in a wide variety of
applications, including data demultiplexing, seven segment displays, and memory address decoding.
There are several types of binary decoders, but in all cases a decoder is an electronic circuit with
multiple input and multiple output signals, which converts every unique combination of input states
to a specific combination of output states. In addition to integer data inputs, some decoders also have
one or more "enable" inputs. When the enable input is negated (disabled), all decoder outputs are
forced to their inactive states.
VHDL Program
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity decoder is
port(
a : in STD_LOGIC_VECTOR(1 downto 0);
b : out STD_LOGIC_VECTOR(3 downto 0)
);
end decoder;
architecture bhv of decoder is
27
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
begin
process(a)
begin
case a is
when "00" => b <= "0001"; when "01" => b <= "0010"; when "10" => b <= "0100"; when "11" => b <= "1000";
end case;
end process;
end bhv;
ENTITY tb_decoder IS
END tb_decoder;
COMPONENT decoder
PORT(
a : IN std_logic_vector(1 downto 0);
b : OUT std_logic_vector(3 downto 0)
);
END COMPONENT;
--Inputs
signal a : std_logic_vector(1 downto 0) := (others => '0');
--Outputs
signal b : std_logic_vector(3 downto 0);
-- appropriate port name
BEGIN
-- Stimulus process
stim_proc: process
begin
-- hold reset state for 100 ns.
wait for 100 ns;
a <= "00";
28
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
a <= "01";
a <= "10";
a <= "11";
wait;
end process;
END;
29
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
Objectives/Outcomes
Understand decoders and adders.
Learn the code for their implementation.
Observe how faults effect the performance of these devices.
Time Boxing
Activity Name Activity Time Total Time
Login Systems + Setting up Xilinx ISE 3 mints + 7 mints 10 mints
Walk through Theory & Tasks 60 mints 60 mints
Implement Tasks 80 mints 80 mints
Evaluation Time 30 mints 30 mints
Total Duration 180 mints
30
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
31
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
LAB # 04
Performance Evaluations (MTTF, MTTR) of Multiplexers and
Demultiplexers
Multiplexer
In electronics, a multiplexer (or mux) is a device that selects one of several analog or digital
input signals and forwards the selected input into a single line. A multiplexer of 2n inputs has n select
lines, which are used to select which input line to send to the output. Multiplexers are mainly used
to increase the amount of data that can be sent over the network within a certain amount of time
and bandwidth. A multiplexer is also called a data selector. Multiplexers can also be used to
implement Boolean functions of multiple variables. An electronic multiplexer makes it possible for
several signals to share one device or resource, for example, one A/D converter or one
communication line, instead of having one device per input signal.
Demultiplexer
A demultiplexer (or demux) is a device taking a single input signal and selecting one of many
data-output-lines, which is connected to the single input. A multiplexer is often used with a
complementary demultiplexer on the receiving end. An electronic multiplexer can be considered as
a multiple-input, single-output switch, and a demultiplexer as a single-input, multiple-output switch.
The schematic symbol for a multiplexer is an isosceles trapezoid with the longer parallel side
containing the input pins and the short parallel side containing the output pin. The schematic on the
right shows a 2-to-1 multiplexer on the left and an equivalent switch on the right. The sel wire
connects the desired input to the output.
VHDL Program
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity mux_4to1 is
port(
A,B,C,D : in STD_LOGIC;
S0,S1: in STD_LOGIC;
Z: out STD_LOGIC
);
end mux_4to1;
32
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
begin
if (S0 ='0' and S1 = '0') then
Z <= A;
elsif (S0 ='1' and S1 = '0') then
Z <= B;
elsif (S0 ='0' and S1 = '1') then
Z <= C;
else
Z <= D;
end if;
end process;
end bhv;
ENTITY tb_mux IS
END tb_mux;
COMPONENT mux_4to1
PORT(
A : IN std_logic;
B : IN std_logic;
C : IN std_logic;
D : IN std_logic;
S0 : IN std_logic;
S1 : IN std_logic;
Z : OUT std_logic
);
END COMPONENT;
--Inputs
signal A : std_logic := '0';
signal B : std_logic := '0';
signal C : std_logic := '0';
signal D : std_logic := '0';
signal S0 : std_logic := '0';
signal S1 : std_logic := '0';
--Outputs
33
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
signal Z : std_logic;
BEGIN
-- Stimulus process
stim_proc: process
begin
-- hold reset state for 100 ns.
wait for 100 ns;
A <= '1';
B <= '0';
C <= '1';
D <= '0';
end process;
END;
34
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
Objectives/Outcomes
Studying the multiplexers and demultiplexers.
Understanding the VHDL coding for MUX and DEMUX.
Time Boxing
Activity Name Activity Time Total Time
Login Systems + Setting up Xilinx ISE 3 mints + 7 mints 10 mints
Walk through Theory & Tasks 60 mints 60 mints
Implement Tasks 80 mints 80 mints
Evaluation Time 30 mints 30 mints
Total Duration 180 mints
35
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
36
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
LAB # 05
Applying Redundancy to Combinational & Sequential Circuits and
Testing
Description
Redundancy occurs in a digital gate network containing circuitry that does not affect the static
logic function. There are several reasons why logic redundancy may exist. One reason is that it may
have been added deliberately to suppress transient glitches (thus causing a race condition) in the
output signals by having two or more product terms overlap with a third one.
Another reason for logic redundancy is poor design practices which unintentionally result in logically
redundantly terms. This causes an unnecessary increase in network complexity, and possibly
hampering the ability to test manufactured designs using traditional test methods (single stuck-at
fault models).
VHDL Program
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity demux_1to4 is
port(
F : in STD_LOGIC;
S0,S1: in STD_LOGIC;
A,B,C,D: out STD_LOGIC
);
end demux_1to4;
end process;
37
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
end bhv;
ENTITY tb_demux IS
END tb_demux;
COMPONENT demux_1to4
PORT(
F : IN std_logic;
S0 : IN std_logic;
S1 : IN std_logic;
A : OUT std_logic;
B : OUT std_logic;
C : OUT std_logic;
D : OUT std_logic
);
END COMPONENT;
--Inputs
signal F : std_logic := '0';
signal S0 : std_logic := '0';
signal S1 : std_logic := '0';
--Outputs
signal A : std_logic;
signal B : std_logic;
signal C : std_logic;
signal D : std_logic;
-- No clocks detected in port list. Replace <clock> below with
-- appropriate port name
BEGIN
38
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
D => D
);
-- Stimulus process
stim_proc: process
begin
-- hold reset state for 100 ns.
wait for 100 ns;
F <= '1';
wait;
end process;
END;
39
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
Objectives/Outcomes
Studying the PIR HC-SR-501 sensor.
Learning about the pins, modes, sensitivity controls.
Understanding the detecting mechanism.
Time Boxing
Activity Name Activity Time Total Time
Login Systems + Setting up Xilinx ISE 3 mints + 7 mints 10 mints
Walk through Theory & Tasks 60 mints 60 mints
Implement Tasks 80 mints 80 mints
Evaluation Time 30 mints 30 mints
Total Duration 180 mints
40
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
41
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
LAB # 06
Applying Path Sensitization Techniques on Different Circuits for
Permanent & Transient Faults
Parallel Adder
A single full adder performs the addition of two 1-bit numbers and an input carry. But a
Parallel Adder is a digital circuit capable of finding the arithmetic sum of two binary numbers that is
greater than one bit in length by operating on corresponding pairs of bits in parallel. It consists of full
adders connected in a chain where the output carry from each full adder is connected to the carry
input of the next higher order full adder in the chain. A n bit parallel adder requires n full adders to
perform the operation. So, for the two-bit number, two adders are needed while for 4-bit number,
four adders are needed and so on. Parallel adders normally incorporate carry lookahead logic to
ensure that carry propagation between subsequent stages of addition does not limit addition speed.
VHDL Program
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
42
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
entity pa1 is
Port ( a : in std_logic_vector(3 downto 0);
b : in std_logic_vector(3 downto 0);
s : out std_logic_vector(3 downto 0);
c : out std_logic;
cin : in std_logic);
end pa1;
begin
process(a,b,cin)
variable u:std_logic;
begin
u:=cin;
for i in 0 to 3 loop
s(i)<=a(i) xor b(i) xor u;
u:=(a(i) and b(i))or(b(i) and u) or(u and a(i));
end loop;
c<=u;
end process;
end pa11;
Universal Gates
A universal gate is a gate which can implement any Boolean function without need to use any other
gate type. The NAND and NOR gates are universal gates. In practice, this is advantageous since NAND
and NOR gates are economical and easier to fabricate and are the basic gates used in all IC digital
logic families. In fact, an AND gate is typically implemented as a NAND gate followed by an inverter
not the other way around. Likewise, an OR gate is typically implemented as a NOR gate followed by
an inverter not the other way around.
43
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
Objectives/Outcomes
Studying the parallel adders and universal gates.
Understanding about the sequential combination of adders.
Learning how it can be programmed.
Time Boxing
Activity Name Activity Time Total Time
Login Systems + Setting up Xilinx ISE 3 mints + 7 mints 10 mints
Walk through Theory & Tasks 60 mints 60 mints
Implement Tasks 80 mints 80 mints
Evaluation Time 30 mints 30 mints
Total Duration 180 mints
44
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
45
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
LAB # 07
Test Pattern Generation for Different Fault Models
Description
A fault model is an engineering model of something that could go wrong in the construction
or operation of a piece of equipment. From the model, the designer or user can then predict the
consequences of this fault. Fault models can be used in almost all branches of engineering. Basic fault
models include:
stuck-at fault
bridging fault
transistor faults
open fault
delay fault.
VHDL Program
-- Architecture definition for the SimpleFSM entity
Architecture RTL of SimpleFSM is
TYPE State_type IS (A, B, C, D); -- Define the states
SIGNAL State : State_Type; -- Create a signal that uses
-- the different states
BEGIN
PROCESS (clock, reset)
BEGIN
If (reset = ‘1’) THEN -- Upon reset, set the state to A
State <= A;
46
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
-- to a new state.
CASE State IS
47
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
Objectives/Outcomes
Studying the Finite State Machines.
Understanding how to code and implement.
Time Boxing
Activity Name Activity Time Total Time
Login Systems + Setting up Xilinx ISE 3 mints + 7 mints 10 mints
Walk through Theory & Tasks 60 mints 60 mints
Implement Tasks 80 mints 80 mints
Evaluation Time 30 mints 30 mints
Total Duration 180 mints
48
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
49
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
LAB # 08
Detecting & Testing Faults In 8-Bit ALU & 3 To 8-Bit Decoder
VHDL Program
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use ieee.NUMERIC_STD.all;
entity ALU is
generic (
);
Port (
);
end ALU;
50
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
begin
process(A,B,ALU_Sel)
begin
case(ALU_Sel) is
ALU_Result <= A + B ;
ALU_Result <= A - B ;
ALU_Result <= A or B;
51
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
if(A>B) then
else
end if;
if(A=B) then
else
end if;
end case;
end process;
end Behavioral;
52
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
USE ieee.std_logic_1164.ALL;
use IEEE.std_logic_unsigned.all;
-- Uncomment the following library declaration if using arithmetic functions with Signed or Unsigned values
--USE ieee.numeric_std.ALL;
ENTITY tb_ALU IS
END tb_ALU;
COMPONENT ALU
PORT(
);
END COMPONENT;
--Inputs
--Outputs
53
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
signal i:integer;
BEGIN
A => A,
B => B,
);
-- Stimulus process
stim_proc: process
begin
A <= x"0A";
B <= x"02";
for i in 0 to 15 loop
end loop;
A <= x"F6";
B <= x"0A";
wait;
end process;
END;
54
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
Objectives/Outcomes
Studying the 8-bit ALU.
Understanding about how it works and processes data.
Learning how to code a ALU and a decoder.
Time Boxing
Activity Name Activity Time Total Time
Login Systems + Setting up Xilinx ISE 3 mints + 7 mints 10 mints
Walk through Theory & Tasks 60 mints 60 mints
Implement Tasks 80 mints 80 mints
Evaluation Time 30 mints 30 mints
Total Duration 180 mints
55
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
56
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
LAB # 09
Designing Linear Feedback Shift Registers (LFSR Counters)
Introduction
A linear feedback shift register takes a linear function, typically an exclusive OR, as an input. An LSFR,
like other shift registers, is a cascade of flip-flop circuits. The bits that change state for the others in
the cascade are called taps. Two of the major schemes for connecting taps are Fibonacci and Galois.
In the Fibonacci configuration, the taps are cascaded and fed into the leftmost bit. In a Galois
configuration, named after the French mathematician Évariste Galois, each tap is XOR'd to the output
stream. LSFRs are used in cryptography for pseudo-random number generation, pseudo-noise
sequences and whitening sequences. They are also often used for digital counters because they are
so fast.
VHDL Program
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity lfsr is
rst : in STD_LOGIC;
end lfsr;
begin
57
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
process (clk,rst)
begin
if (rst='1') then
end if;
end process;
end Behavioral;
entity lfsr_tb is
-- Port ( );
end lfsr_tb;
component lfsr is
Port ( clk : in STD_LOGIC;
rst : in STD_LOGIC;
outp : out STD_LOGIC_VECTOR (3 downto 0));
end component;
begin
process
begin
clk_tb <= not clk_tb;
wait for clk_period/2;
end process;
process
58
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
begin
rst_tb <= '1';
wait for 6 ns;
end Behavioral;
59
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
Objectives/Outcomes
Studying the force and load sensors.
Learning about how force changes the resistance of the sensors.
Basic python coding for the sensor.
Time Boxing
Activity Name Activity Time Total Time
Login Systems + Setting up Xilinx ISE 3 mints + 7 mints 10 mints
Walk through Theory & Tasks 60 mints 60 mints
Implement Tasks 80 mints 80 mints
Evaluation Time 30 mints 30 mints
Total Duration 180 mints
60
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
61
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
LAB # 10
Implementation and Testing on Mealy Machine & Moore Machine
Mealy Machine
In the theory of computation, a Mealy machine is a finite-state machine whose output values
are determined both by its current state and the current inputs. A Mealy machine is a deterministic
finite-state transducer: for each state and input, at most one transition is possible.
Moore Machine
A Moore machine is a finite-state machine whose output values are determined only by its
current state.
VHDL Program
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity moore is
din : in STD_LOGIC;
rst : in STD_LOGIC;
end moore;
begin
62
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
begin
if rising_edge(clk) then
else
end if;
end if;
end process;
begin
else
else
else
else
63
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
next_state <= st0; end case; end process; next_state_decoder : process(present_state) begin case (present_state)
is when st0 =>
end case;
end process;
end Behavioral;
ENTITY tb_moore IS
END tb_moore;
COMPONENT moore
PORT(
clk : IN std_logic;
din : IN std_logic;
rst : IN std_logic;
dout : OUT std_logic
);
END COMPONENT;
--Inputs
signal clk : std_logic := '0';
signal din : std_logic := '0';
signal rst : std_logic := '0';
--Outputs
signal dout : std_logic;
64
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
BEGIN
-- Stimulus process
stim_proc: process
begin
65
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
END;
66
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
Objectives/Outcomes
Studying the GSM-900A module.
Learning about Arduino and its interfacing.
Understanding how to send and receive SMS.
Time Boxing
Activity Name Activity Time Total Time
Login Systems + Setting up Xilinx ISE 3 mints + 7 mints 10 mints
Walk through Theory & Tasks 60 mints 60 mints
Implement Tasks 80 mints 80 mints
Evaluation Time 30 mints 30 mints
Total Duration 180 mints
67
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
68
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
LAB # 11
Designing a Fault Detectable Odd Parity Generator & Pulse Generator
Odd Parity Generator
In asynchronous communication systems, odd parity refers to parity checking modes, where
each set of transmitted bits has an odd number of bits. If the total number of ones in the data plus
the parity bit is an odd number of ones, it is called odd parity. A system that generates odd parity is
called an Odd Parity Generator.
Pulse Generator
A pulse generator is either an electronic circuit or a piece of electronic test equipment used
to generate rectangular pulses. Pulse generators are used primarily for working with digital circuits,
related function generators are used primarily for analog circuits.
VHDL Program
package anu is
end anu;
library ieee;
use ieee.std_logic_1164.all ;
use Work.anu.all;
entity Parity_Generator1 is
clk : in std_logic ;
end Parity_Generator1;
69
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
begin
P1: process
begin
odd := '0';
end loop;
end process;
end odd;
71
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
Objectives/Outcomes
Studying the Parity and Pulse Generator.
Understanding about its working and specifications.
Learning how to code an odd parity generator.
Time Boxing
Activity Name Activity Time Total Time
Login Systems + Setting up Xilinx ISE 3 mints + 7 mints 10 mints
Walk through Theory & Tasks 60 mints 60 mints
Implement Tasks 80 mints 80 mints
Evaluation Time 30 mints 30 mints
Total Duration 180 mints
72
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
73
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
LAB # 12
Design of Fault Detecting and Correcting Priority Encoder
Priority Encoder
A priority encoder is a circuit or algorithm that compresses multiple binary inputs into a
smaller number of outputs. The output of a priority encoder is the binary representation of the
original number starting from zero of the most significant input bit. They are often used to control
interrupt requests by acting on the highest priority encoder. If two or more inputs are given at the
same time, the input having the highest priority will take precedence. An example of a single bit 4 to
2 encoder is shown, where highest-priority inputs are to the left and "x" indicates an irrelevant value
- i.e. any input value there yields the same output since it is superseded by higher-priority input. The
output V indicates if the input is valid.
Priority encoders can be easily connected in arrays to make larger encoders, such as one 16-
to-4 encoder made from six 4-to-2 priority encoders - four 4-to-2 encoders having the signal source
connected to their inputs, and the two remaining encoders take the output of the first four as input.
The priority encoder is an improvement on a simple encoder circuit, in terms of handling all possible
input configurations.
VHDL Program
entity priority is
end priority;
architecture v1 of priority is
begin
process (I)
begin
A <= "000";
A <= "111";
A <= "110";
A <= "101";
A <= "100";
A <= "011";
A <= "010";
A <= "001";
A <= "000";
else
GS <= '0';
end if;
end process;
end v1;
entity enco8x3_seq_tst is
end enco8x3_seq_tst;
architecture beh of enco8x3_seq_tst is
component enco8x3_seq
port (
i: in std_logic_vector(7 downto 0); -- inputs
o: out std_logic_vector(2 downto 0)); -- outputs
end component;
signal i_s : std_logic_vector(7 downto 0); -- signals
signal o_s : std_logic_vector(2 downto 0); -- output signals
75
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
begin -- beh
tst_p: process
begin
i_s<="00000001";
wait for 100 ns;
i_s<="00000010";
wait for 100 ns;
i_s<="00000100";
wait for 100 ns;
i_s<="00001000";
wait for 100 ns;
i_s<="00010000";
wait for 100 ns;
i_s<="00100000";
wait for 100 ns;
i_s<="01000000";
wait for 100 ns;
i_s<="10000000";
wait for 100 ns;
end process;
end beh;
76
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
Objectives/Outcomes
Studying the priority encoder.
Understanding its functions.
Learning how to code a priority encoder in VHDL.
Time Boxing
Activity Name Activity Time Total Time
Login Systems + Setting up Xilinx ISE 3 mints + 7 mints 10 mints
Walk through Theory & Tasks 60 mints 60 mints
Implement Tasks 80 mints 80 mints
Evaluation Time 30 mints 30 mints
Total Duration 180 mints
77
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
78
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
LAB # 13
Implementing the Hamming Code and Testing It on Mealy Machine &
Moore Machine
Hamming Code
Hamming codes are a family of linear error-correcting codes. Hamming codes can detect up
to two-bit errors or correct one-bit errors without detection of uncorrected errors. By contrast, the
simple parity code cannot correct errors, and can detect only an odd number of bits in error.
Hamming codes are perfect codes, that is, they achieve the highest possible rate for codes with their
block length and minimum distance of three. Richard Hamming invented Hamming codes in 1950 as
a way of automatically correcting errors introduced by punched card readers. In his original paper,
Hamming elaborated his general idea, but specifically focused on the Hamming (7,4) code which adds
three parity bits to four bits of data.
VHDL Program
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
ENTITY hamming_encoder IS
END hamming_encoder;
BEGIN
79
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
--connect up outputs
END beh;
80
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
Objectives/Outcomes
Studying the Hamming codes.
Understanding its operation and fault correcting ability.
Learning how to implement Hamming codes on VHDL.
Time Boxing
Activity Name Activity Time Total Time
Login Systems + Setting up Xilinx ISE 3 mints + 7 mints 10 mints
Walk through Theory & Tasks 60 mints 60 mints
Implement Tasks 80 mints 80 mints
Evaluation Time 30 mints 30 mints
Total Duration 180 mints
81
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
82
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
LAB # 14
Design Implication Fault Models of Mealy Machines
Mealy Machine
A Mealy Machine is an FSM whose output depends on the present state as well as the
present input.
VHDL Program
-- A Mealy machine has outputs that depend on both the state and
-- the inputs. When the inputs change, the outputs are updated
-- can be written more than once per state or per clock cycle.
library ieee;
use ieee.std_logic_1164.all;
entity mealy_4s is
port
clk : in std_logic;
data_in : in std_logic;
reset : in std_logic;
);
83
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
end entity;
begin
begin
case state is
when s0=>
else
end if;
when s1=>
else
84
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
end if;
when s2=>
else
end if;
when s3=>
else
end if;
end case;
end if;
end process;
begin
case state is
when s0=>
else
end if;
85
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
when s1=>
else
end if;
when s2=>
else
end if;
when s3=>
else
end if;
end case;
end process;
end rtl;
86
Computer Engineering Department
Bahria University (Karachi Campus)
Lab Manual: Fault Tolerant Systems
Objectives/Outcomes
Studying the fault models of Mealy Machine.
Learning how to work on FSMs and Mealy Machines together.
Time Boxing
Activity Name Activity Time Total Time
Login Systems + Setting up Xilinx ISE 3 mints + 7 mints 10 mints
Walk through Theory & Tasks 60 mints 60 mints
Implement Tasks 80 mints 80 mints
Evaluation Time 30 mints 30 mints
Total Duration 180 mints
87
Computer Engineering Department
Bahria University (Karachi Campus)