Esrt Lab Manual Update 2022
Esrt Lab Manual Update 2022
CONTENTS
1. Mission and Vision.
2. Guiding Principles and PEO’s.
3. Overview.
4. Faculties
5. Academic Programs
6. Grading Policy
7. Instructions for Lab Reports
8. Resources
9. Experiments with 8086 Microprocessor
10. Introduction to 8051 Microcontroller
11. Experiments with 8051 Microcontroller
12. FPGA based experiments
13. XA Zynq UltraScale+ MPSoC Data Sheet: Overview
14. Xilinx Artix Nexys4 DDR™ FPGA Board Reference
Manual
15. TM4C123G LaunchPad Evaluation Kit
2
National Institute of Technology Rourkela
Copyright ©2022, Embedded System & Real Time Lab, Dept., Of EE, Nit Rourkela
3
4
Guiding Principles
• Build an environment that is conductive to academic
pursuit, nurturing creative thoughts and inculcating a spirit
of inquiry.
• Promote free exchange of knowledge and experience with
others, while respecting each other’s right to intellectual
property.
• Ensure quality, speech, economy and transparency in all
spheres of our activities.
• Create a truly multicultural community and promote
cultural bonding and teamwork among all.
• Provide opportunity to every member of the lab for
achieving academic excellence, developing all round
personality and realizing his or her full potential.
• Adopt state of the art technology in all endeavors.
5
1. 6
2.
7
Academic Programs
Course Objectives:
To expose the students in order to
1. Learn to use modern circuit design tools, software, and equipment to develop digital circuit in
embedded systems
2. Learn coding in VHDL/Verilog, simulation and testing
3. Learn to design and implement embedded system with optimal computational complexity
Experiment Modules
Essential Reading:
1. Douglas L. Perry, VHDL: Programming by Example, Tata McGraw-Hill, 4th Ed., 2002 or latest Ed.
2. D. M. Harris & S. L. Harris, Digital Design and Computer Architecture, Morgan Kaufmann, 2007 or latest Ed.
Supplementary Reading:
1. Anonymous, Data Sheets of Various components by respective manufacturer, latest release
2. M. Morris Mano, Computer System Architecture, PHI, 3rd Ed., 2007 or latest Ed.
8
Course Outcomes:
CO1: Learn modern EDA Tools for Design and Simulation of Real-time Embedded
System
CO2: Learn VHDL/Verilog code for developing basic digital circuit components
CO4: Design, implement, and test the Digital Filters like FIR, IIR, and Adaptive Filters
CO5: Learn reporting the performance analysis of the embedded systems effectively
Program Outcomes:
PO1: An ability to independently carry out research /investigation and development work
to solve practical problems
PO2: An ability to write and present a substantial technical report/document
PO3: Students should be able to demonstrate a degree of mastery over the area as per
the specialization of the program. The mastery should be at a level higher than the
requirements in the appropriate bachelor program
PO4: Students will be able to independently carry out system design, testing, verification
and realization under real-time constraints in the field of communication systems,
signal and image processing, and embedded system.
PO5: Students will be competent to serve different industries and able to take up
challenging problems in the field of electronic systems and communication.
PO6: Students will be broadly educated and will have an understanding of the impact of
engineering on society and demonstrate awareness of contemporary issues. They
also understand and commit to professional ethics and responsibilities and norms
of engineering technology and practice.
9
Following courses are conducted in ESRT Lab,(For UG)
Subject {L-T-P / C} : EE3704 : Embedded Systems Laboratory {0-0-2 / 1}
Subject Nature : Practical
Coordinator : Dr. Supratim Gupta
Course Objectives:
Prepare students ,
1. To understand extraction of information from datasheets
2. To develop circuits with processor in an Integrated Development Environment (IDE)
3. To able to design digital filters with software tool
4. To debug hardware and firmware of a digital filter in a simulator
5. To realize hardware and test digital filters with embedded system
Syllabus:
10
Module 5: Hardware realization
Hardware realization of either of the filters designed in Tasks 2-5 on system developed in Task 1 on bread
boards
Essential Reading:
Course Outcomes:
CO-PO&PSO mapping:
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 PSO3
CO1 3 0 0 0 3 0 0 2 2 0 0 0 3 1 1
CO2 2 0 0 0 3 0 0 2 2 1 0 0 3 1 1
CO3 3 3 3 0 3 0 0 2 2 0 0 0 3 1 1
CO4 3 3 3 3 3 0 0 2 2 1 0 0 3 1 1
CO5 3 3 3 0 3 0 0 2 3 1 1 0 3 1 1
CO 3 2 2 1 3 0 0 2 3 1 1 0 3 1 1
11
Grading policy
Total grade consists of Mid- Semester grade (50%) and End-Semester grade (50%).
Grading for the course will be based primarily on the results of the laboratory projects and
the quality of the lab reports (20%). Lecture attendance with active participation will
account for 10% of the course grade, and the remaining 20% of the grade will be based
on the student’s viva voce performance.
Structure of Report:
12
Template & Instruction For Each Design Problem: -
General Style
13
Resources
Xilinx Artix 7 Nexys 4 DDR Board
The Nexys4 DDR board is a complete, ready-to-use
digital circuit development platform based on the latest Artix-7™
Field Programmable Gate Array (FPGA) from Xilinx®. With its
large, high-capacity FPGA (Xilinx part number XC7A100T-
1CSG324C), generous external memories, and collection of
USB, Ethernet, and other ports, the Nexys4 DDR can host
designs ranging from introductory combinational circuits to
powerful embedded processors. Several built-in peripherals,
including an accelerometer, temperature sensor, MEMs digital
microphone, a speaker amplifier, and several I/O devices allow
the Nexys4 DDR to be used for a wide range of designs without
needing any other components.
14
TM4C123G LaunchPad Evaluation Kit
15
Xilinx Zynq UltraScale+ MPSoC ZCU104
Evaluation kit.
Mojo is an FPGA board which lets you FPGA will start talking to the
get the pleasure of configuring the digital microcontroller; giving you access to the
circuits on Mojo v3 to your own serial port and the analog inputs.
specifications. What separates this FPGA
from the others is the ease of use. The
goal of Mojo v3 is to get you up and
running with FPGA as easily as
possible.The Mojo v3 FPGA Board uses
the Spartan 6 and a high performance
ATmega32U4 microcontroller. This board
has high processing power. The
ATmega32U4 microcontroller comes with
a USB (DFU) bootloader which allows
you to install new versions of the
firmware without the need for a
programmer. Once the board is powered
on, the ATmega32U4 configures the
FPGA from the flash memory. After the
FPGA is successfully configured, your
16
Arduino Mega
Resistors Thermistors
Capacitors Diodes
Transistors 20 pin flat cable connectors
ADC/DAC Bread boards
Microcontrollers Signal Generators
Op-Amp’s DSOs
Rectifiers Power suppliesUSB cables
LEDs & Timers Voltage Regulators Stepper motors
Heat sinks Relay, Buzzers,
Crystal Oscillators,
Pushbuttons, LDR,
LCD’s
17
EXPERIMENT WITH MICROPROCESSOR
(8085)/MICROCONTROLLER (8051)
18
19
National Institute of Technology, Rourkela
Department of Electrical Engineering,
B.Tech Programme
Embedded Systems Laboratory (EE 3704)
TASK 1:-
Cutoff frequencies for LP is last 4-digit of lowest Roll number of your group in Hz..
Develop RTOS–with FIFO structure for signal access–to realize the filters in the circuit developed in
Task-1.
Consider integer, fixed point precision for computation.
Tabulate readings for each of the occasions and each type of filters to get frequency response and
compare it with the frequency responses obtained in MATLAB FDA tool.
Measure latency of your system i.e. time delay between occurrence i/p to o/p.
Analyze and comment if the filter specification is met.
Draw RTL schematic for this design.
TASK 4 :-
Design Low pass (LP) with IIR structure of order higher than 4
Cutoff frequencies for LP is last 4-digit of lowest Roll number of your group in Hz.
Develop RTOS–with FIFO structure for signal access–to realize the filters in the circuit developed in
Experiment-1-2.
Consider integer, fixed point precision for computation.
Consider full order realization & cascaded 2nd order filters
realization
Tabulate read.ings for each of the occasions of filter precision and structure (full & cascaded) to get
frequency response and compare it with the frequency responses obtained in MATLAB FDA tool
Measure latency of your system i.e. time delay between occurrence i/p to o/p
Analyze your system if the filter specification is met and is stable, what is the minimum precision
required, if the stability depends on order.
Draw RTL schematic for this design.
TASK 5 :-
Hardware realization of either of the filters designed in Tasks 2-5 on system developed in Task 1.
20
TASK 1
21
TASK - 1
Aim: Learn proteus environment for simulation of circuits with microcontroller and learn FDA
toolbox of matlab
Theory:
Proteus:
Proteus is used to simulate design and drawing of electronic circuits, it was invented by lab
center electronics.
By using Proteus we can prepare two-dimensional Circuit design as well.
With the use of this emerging software, we can construct and simulate different electrical and
electronic circuits on our PC.
There are numerous benefits to simulate circuits on proteus before making them practically.
Designing of circuit on proteus take much less time.
The electronic tool that are very expensive can easily get in proteus such as Oscilloscope.
Using proteus we can find different parents of a circuit such as current and voltage value of any
component and resistance at any instant which is very difficult in a practical circuit.
Features of Proteus:
There are two main parts of proteus first is used to design and draw different circuits and
second is for designing of PCB layout.
The first is ‘ISIS’ that is used to design and simulate circuit and second is ‘ARES’ that is used for
designing of a printed circuit board.
It also provides features related to the three-dimensional view of a design in PCB.
It contains a panel to write source code if we are simulating microcontroller related tasks.
Proteus layout:
22
Layouts of Proteus:
FDA Tool:
The filter design and analysis tool FDA tool is a powerful user interface for designing and
analysing filters quickly appropriate tools enable us to design digital FIR or IR filter by setting
required filter specifications by importing filters from matlab workspace or why adding moving or
deleting poles and zeros
FDA tool also provide tools for analysing filters such as magnitude and phase response and
pole-zero plot
When we type FD a tool or filter designer at the MATLAB Command Prompt the GUI displays
with a default filter
24
Fig.4 GUI of FDA tool in MATLAB
25
Fig.5 Filter Specifications window
26
Fig.8 Phase Response
27
TASK 2
28
TASK-2
AIM:
To develop an Embedded system in Proteus interfacing ADC-0808 and DAC-0808 with
8051-MC. Structured RTOS code is developed to measure the input & output (after DAC).
Components used: -
1. 8051 microcontrollers (AT89C52)
2. Crystal oscillator (11.059 MHz)
3. DAC (DAC0808)
4. ADC (ADC0808)
5. Op-Amp (LF347)
6. Sine wave generator
7. Not gate
8. Digital oscilloscope
9. Resistors
10. capacitors
11. Resistors packs
12. DC source
Description of lables used in circuit diagram:
1. ADCO - ADC outputs
2. DACI - DAC inputs
Circuit Diagram:
29
Assembly Code:
;====================================================================
; Main.asm file generated by New Project wizard
; Created: Mon Jan 24 2022
; Processor: AT89C52
; Compiler: ASEM-51 (Proteus)
;====================================================================
$NOMOD51
$INCLUDE (80C52.MCU)
;====================================================================
; DEFINITIONS
;====================================================================
ADop equ P0 ;Port 0 as ADC output
ALE equ P1.2 ; Port 1.2 as ALE for ADC
SOC equ P1.3 ; Port 1.3 as Start conversion (SC) for ADC
EOC equ P3.3 ; external interrupt 0
DAip equ P2 ; Port 2 as DAC input
Exedge equ TCON.2 ; setting external interrupt 1 as edge
trigger OE equ P3.0
;====================================================================
; VARIABLES
;====================================================================
IEvalue equ 84h ;Enabling interrupts globally and external interrupt 1
T2modval equ 02h ;to set as up programmable clock output and T2OE enable
RCAP_L equ 0FCh ;lower byte of count value for 640kHz clock out at T2 pin with 11.059MHz clock
RCAP_H equ 0FFh ;higher byte of count value
;====================================================================
; RESET and INTERRUPT VECTORS
;====================================================================
; Reset Vector
org 0000h
jmp Start
;====================================================================
; CODE SEGMENT
;====================================================================
Start:
mov RCAP2H, #RCAP_H ;higher byte of count value for 640kHz clock out at T2 pin with 11.059MHz
clock
mov RCAP2L, #RCAP_L ;lower byte of count value
mov T2MOD , #T2modval ;to set as up programmable clock output and T2OE
enable
clr T2CON.0 ;setting timer 2 in 16bit Autoreload mode
clr T2CON.1 ;In timer mode
setb TR2 ;Start the timer
30
mov R1, #0FFh ;Initialise R1 to compare and check the maximum value
mov R0 , #00h ;Initialise R0 to store maximum value
Loop:
jmp Loop
READ_ADC ISR:
cjne A, B, Back
mov R0,B
mov DAip ,B ;Send data to DAC
Back:
31
Readings:
2. 1V 30Hz 5V 30Hz
32
Waveforms:
Input Amplitude =
1V Offset = 1V
1. At 50Hz
Fig.1
At 100 Hz
Fig.3
33
2. At 200Hz
Fig.4
3. At 400 Hz
Fig.5
34
Input Amplitude = 0.5V
Offset = 0.5V
4. At 50Hz
Fig.6
5. At 100 Hz
35
6. At 200Hz
Fig.8
7. At 400 Hz
Fig.9
36
TASK -3
37
TASK -3
AIM: To Design Low pass (LP) with FIR structure of 2nd order for a given Cut-off frequency.
RTOS Structured code is developed with FIFO structure for signal access–to realize the filters
in the circuit developed in Task-1. Latency of designed system is determined.
Components used: -
1. 8051 microcontrollers (AT89C52)
2. Crystal oscillator (11.059 MHz)
3. DAC (DAC0808)
4. ADC (ADC0808)
5. Op-Amp (LF347)
6. Sine wave generator
7. Not gate
8. Digital oscilloscope
9. Resistors
10. capacitors
11. Resistors packs
12. DC source
Description of lables used in circuit diagram:
Circuit Diagram:
38
Circuit Diagram in Proteus
39
Cut off frequency = 638 Hz
Sampling frequency = 4000 Hz
Filter specifications:
Filter Coefficients:
40
Assembly Code:
;====================================================================
$NOMOD51
$INCLUDE (80C52.MCU)
;====================================================================
; DEFINITIONS
;====================================================================
ADOP EQU P0 ;port 0 as adc output
ALE EQU P1.2 ;port 1.2 as ale for adc
SOC EQU P1.3 ;port 1.3 as start conversion (sc) for ADC
EOC EQU P3.3 ; external interrupt 0
DAIP EQU P2 ;port 2 as dac input
EXEDGE EQU TCON.2 ; setting external interrupt 1 as edge trigger
OE EQU p3.0
;====================================================================
; VARIABLES
;====================================================================
IEVALUE equ 84h
T2MODVAl equ 02h ;to set as up programmable clock output and T2OE enable
RCAP_L equ 0FCh ;lower byte of count value for 640kHz clock out at T2 pin with 11.059MHz clock
RCAP_H equ 0FFh ;higher byte of count value
;====================================================================
; FILTER COEFFICIENTS
;=====================================================
=====An equ 4Eh ; 0.30629553*2^(8)
An_1 equ 63h ; 0.38740894*2^(8)
An_2 equ 4Eh ; 0.30629553*2^(8)
;====================================================================
; RESET and INTERRUPT VECTORS
;====================================================================
; Reset Vector
ORG 0000h
JMP Start
;====================================================================
; CODE SEGMENT
;====================================================================
Start:
MOV RCAP2H, #RCAP_H ; higher byte of count value for 640kHz clock out at T2 pin with 11.059MHz clock
MOV RCAP2L, #RCAP_L ; lower byte of count value
MOV T2MOD , #T2modval ;to set as up programmable clock output and T2OE enable
CLR T2CON.0 ;16bit Autoreload
CLR T2CON.1 ;In timer mode
SETB TR2 ;Start the timer
41
MOV R0 ,#00H ;
MOV R1 , #00H
MOV R2 , #00H
MOV R3 , #00H
MOVR5, #00H
SETB EXEDGE ; setting external interrupt 1 as edge trigger
READ_ADC_ISR:
PUSH ACC
PUSH PSW
SETB OE ;set Output Enable to take the data
MOV A , ADOP ;Store data in B register to check whether the coming data is maximum value or
not
MOV R3,A ;storing current sample in R3
MOV A,R1 ;storing the previous x[n-1] In A
MOV R0,A ;shifting the previous x[n-1] in R0
MOV A,R2 ;Store the previous x[n] in A
MOV R1,A ;Store it in R1
MOV A,R3;Store current sample value in A
MOV R2,A ;Store current sample in R2
MOVA,R0
MOVB,#n
MUL AB ;performing An*x[n]
MOV R5,B ;Storing in R5
MOV A,R1
MOV B,#An_1
MUL A_B ;performing An_1*x[n-1]
MOV A,B
ADD A,R5 ;Adding and storing in R5
MOV R5,A
MOV A,R2
MOVB,#A2
MUL AB ;performing An_2*x[n-2]
MOV A,B
ADD A,R5
MOV R5,A ;storing An*x[n] + An_1*x[n-1] + An_2*x[n-2] in R5
MOV DAip,R5 ;To send the contents to DAC
Start ADC conversion for next sample
SETB ALE
SETB SOC
CLR ALE
CLR SOC
POP PSW
POP ACC
RETI
END
42
Readings:
43
Frequency response using above table:
Fig.2
Fig.3
44
Waveforms:
Input Amplitude = 1V
Offset = 1V
1. At 50Hz
Fig.4
At 100 Hz
Fig.5
45
2. At 200Hz
Fig.6
3. At 400 Hz
Fig.7
46
4. At 600 Hz
Fig.8
5. At 1000Hz
Fig.9
Conclusion:
From the above waveforms, it is clear that with the increase in frequency of input sinusoid,
there is decrease in amplitude of output waveforms is significant above cutoff frequency. As it
is a low pass FIR filter, decrease in the amplitude is justified and the frequency response of
output is also similar to that of response obtained in FDA tool. The output waveforms become
more distorted as we increase the frequency closer to 2000Hz.
47
TASK 4-5
48
TASK - (4-5)
AIM:
To Design Low pass (LP) with IIR structure of order 5 for a given Cut-off frequency. RTOS
Structured code is developed with FIFO structure for signal access–to realize the filters in the
circuit developed in Task-1-2. Latency of designed system is determined.
Components used: -
49
Circuit Diagram:
Fig.1 Circuit Diagram in Proteus
RP1
RESPACK-8
2
3
4
5
6
7
8
9
Vcc
ADCO0
ADCO1
ADCO2
ADCO3
ADCO4
ADCO5
ADCO6
ADCO7
ADCIP
GND Vcc U2
10 26 ADCIP
C3 CLOCK IN0
6 27
START IN1
28
IN2
7 1
EOC IN3
33uF 2
U1 IN4
ADCO7 21 3
1
OUT1 IN5
19 39 ADCO0 ADCO6 20 4
XTAL1 P0.0/AD0 OUT2 IN6
X1 38 ADCO1 ADCO5 19 5
P0.1/AD1 OUT3 IN7
37 ADCO2 ADCO4 18
CRYSTAL P0.2/AD2 OUT4
18 36 ADCO3 ADCO3 8 25
XTAL2 P0.3/AD3 OUT5 ADD A
2
U5:A
4 A
GND 3
1
B
2
C
11
R3 LF347 +88.8 D
AC Volts
5k
U5:A(V-)
Filter specifications:
50
Filter Coefficients (Full order realization):
51
Assembly Code:
;====================================================================
$NOMOD51
$INCLUDE (80C52.MCU)
;====================================================================
; DEFINITIONS
;====================================================================
ADOP equ P0 ;Port 0 as ADC output
ALE equ P1.2 ;Port 1.2 as ALE for ADC
SOC equ P1.3 ;Port 1.3 as Start conversion (SC) for ADC
;====================================================================
; CODE SEGMENT
;====================================================================
Start:
MOV RCAP2H, #RCAP_H ;higher byte of count value for 640kHz clock out at T2 pin with
11.059MHz clock
MOV RCAP2L, #RCAP_L ;lower byte of count value
MOV T2MOD , #T2modval ;to set as up programmable clock output and T2OE enable
CLR T2CON.0 ;16bit Autoreload
CLR T2CON.1 ;In timer mode
SETB TR2 ;Start the timer
52
Loop:
JMP LOOP
Section 2:-
MOV A,R0 ;taking x[n] in A from R0
MOV B,#80H ;storing Ao in B (1 * 128 = 80H)
MUL AB ;performing Ao*x[n]
MOV R5,B ;Storing Ao*x[n] in R5
MOV A,R1 ;Taking x[n-1] in A
MOV B,#0FFH ;Storing A1 ( 2*128 = 0FFh)
MUL AB ;Performing A1*x[n-1]
MOV R6,B ;Storing it in R6
MOV A,R6 ;move from R6 to A
ADD A,R5 ; Ao*x[n]+A1*x[n-1]
MOV R5,A ;Storing it in R5
MOV A,R2 ;R2 has x[n-2]
MOV B,#80H ;taking A2 in B (1 * 128 = 80H)
53
MUL AB ;Performing A2*x[n-2]
MOV R6,B
MOV A,R6
ADD A,R5
MOV R5,A ; performing Ao*x[n]+A1*x[n-1]+A2*x[n-2]
MOV A,R3 ; Taking y[n-1] in A
MOV B,#3EH ;Storing b1(0.48448035 * 128 = 3EH)
MUL AB ;performing b1*y[n-1]
MOV R6,B
MOV A,R5 ;moving it to A
SUBB A,R6 ;Performing Ao*x[n]+A1*x[n-1]+A2*x[n-2]-b1*y[n-1]
MOV R5,A ;Storing it in R5
MOV A,R4
MOV B,#13H ;Storing b2 in B (0.15328925*128 = 13H)
MUL AB ;performing b2*y[n-2]
MOV R6,B ;
MOV A,R5
Section 3:-
54
; Start ADC conversion for next sample
SETB ALE
SETB SOC
CLR ALE
CLR SOC
POP PSW
POP ACC
RETI
;====================================================================
END
Readings:
55
Frequency response using above table:
Fig.2
Fig.3
56
Waveforms:
Input Amplitude = 1V
Offset = 1V
1. At 50 Hz
Fig.4
2.At 200 Hz
Fig.5
57
3.At 400Hz
Fig.6
2. At 600Hz
Fig.7
58
3.At 800Hz
Fig.8
Conclusion:
All the Coefficients of the IIR filter were obtained from FDA tool of MATLAB for Cascade and
2nd order section realisation. By using the value of samples and coefficients the output was calculated
and send to DAC .With increase in frequency, it was observed that the amplitude of the output
decreased and distortion increased with increasing input frequency beyond cut-off frequency (638
Hz). Since it is a LPF the decrement in output amplitude is justified and the output frequency
response is also quite similar to that of response obtained in FDA tool of MATLAB. From graphs we
observed that as the frequency reached half of the sampling frequency (1.0KHz), the distortion
increased very rapidly by satisfying Nyquist theorem (f s >2fm).
59
TASK 6
60
Interfacing 8051 with ADC and DAC
Learning outcome
Learn to implement regulated power supply and square wave generator
using 555 timer
Understand specifications of ADC and DAC
Learn to write code for interfacing 8051 with ADC and DAC
Learn how to implement the interfacing circuit
Aim
Theory
In most of the digital system micro controller needs to take input from analog sensor or
transducer. Analog signal are most common input signal for embedded system. Hence before
feeding to microcontroller the analog input has to be converted to digital data by using an Analog to
Digital Converter(ADC).The digital data is converted back to analog using a digital to analog
converter.
61
Square wave generation using 555 timer.
ADC 0808 is an 8-bit analog to digital converter which is of successive approximation type. Its
important specifications are:
Resolution is 8-bit
Conversion time is 100 us
Clock frequency range is 10 kHz to 1 MHz
It has 8 analog data channels, which are selected using A, B and C. The control signals are:
ALE (Address Latch Enable) – with a high pulse it selects the corresponding data channel
according to the address in A,B and C
START – a high pulse starts the conversion
EOC (End of Conversion) - There is a low to high transition when the conversion is done
OE (Output Enable) – Setting it latches the output to its output channel
62
Fig. – Timing diagram for ADC0808
Minimum start pulse width = 100 ns
Minimum ALE pulse width = 100ns
Minimum address set up time = 50 ns
Minimum address hold time = 50 ns
DAC0808 :-
DAC 0808 is an 8-bit digital to analog converter. The analog output is sinking current.
Important specifications are
Resolution – 8-bit
Slew rate – 8mA/us
63
Procedure :-
64
Hardware Implementation:-
65
FPGA BASED EXPERIMENTS
66
National Institute of Technology, Rourkela
Department of Electrical Engineering,
M. Tech Programme
Real-Time Systems Laboratory (EE 6174)
MODULE 1 (TASK 1)
Introduction / Practice Session
Realize the AND, OR & NOT gate by using dataflow and behavioural modelling with VHDL and
Verilog HDL.
MODULE 4 (TASK 8)
Finite State Machine for Sequence Detection
MODULE 5 (TASK 9)
ADC-DAC Interface with FPGA/SoC
67
Task-1
Realization of AND, OR & NOT gates
Aim: Realize the AND, OR & NOT gates by using behavioural modelling using VHDL.
THEORY:
AND gate is a digital logic gate with two or more inputs and one output that performs logical
conjunction. The output of an AND gate is true only when all of the inputs are true.
library IEEE;
use IEEE.std_logic_1164.all; entity and_gate is
port(
a: in std_logic;
b: in std_logic;
q: out std_logic);
end and_gate;
architecture rtl of and_gate is begin
process(a,b) is
begin
q<=a and b;
end process;
end rtl
--Test Bench:
library IEEE;
use IEEE.std_logic_1164.all; entity testbench is
-- empty
end testbench;
architecture tb of testbench is
-- DUT component component and_gate is port(
a: in std_logic; b: in std_logic; q: out std_logic);
end component;
signal a_in, b_in, q_out: std_logic; begin
-- Connect DUT
DUT: and_gate port map(a_in, b_in, q_out); process
begin
68
a_in <= '0';
b_in <= '0'; wait for 20 ns;
assert(q_out='0') report "Fail 0/0" severity error;
Result:
69
OR GATE :
Theory:
OR gate is a digital logic gate with two or more inputs and one output that performs logical
OR. The output of an OR gate is true when either or all of the inputs are true.
pin diagram:
Truth table:
process(a, b) is
begin
q <= a or b;
end process;
end rtl;
Test bench:
library IEEE;
use IEEE.std_logic_1164.all; entity testbench is
-- empty
end testbench;
architecture tb of testbench is
-- DUT component component or_gate is port(
a: in std_logic; b: in std_logic; q: out std_logic);
end component;
signal a_in, b_in, q_out: std_logic; begin
70
-- Connect DUT
DUT: or_gate port map(a_in, b_in, q_out); process
begin
a_in <= '0';
b_in <= '0'; wait for 1 ns;
assert(q_out='0') report "Fail 0/0" severity error; a_in <= '0';
b_in <= '1'; wait for 1 ns;
assert(q_out='1') report "Fail 0/1" severity error; a_in <= '1';
b_in <= '0'; wait for 1 ns;
assert(q_out='1') report "Fail 1/0" severity error; a_in <= '1';
b_in <= '1'; wait for 1 ns;
assert(q_out='1') report "Fail 1/1" severity error;
-- Clear inputs a_in <= '0';
b_in <= '0';
assert false report "Test done." severity note; wait;
end process;
end tb;
RESULT:
NOT Gate:
Theory:
71
Pin Diagram:
a: in std_logic;
q: out std_logic);
end not_gate;
architecture rtl of not_gate is
begin
process(a ) is
begin
q<=not a;
end process;
end rtl;
Test bench:
library IEEE;
use IEEE.std_logic_1164.all; entity testbench is
-- empty
end testbench;
architecture tb of testbench is
-- DUT component
component not_gate is
( a: in std_logic; q: out std_logic);
end component;
signal a_in, q_out: std_logic;
begin
-- Connect DUT
DUT:
not_gate port map(a_in, q_out);
process
begin
a_in <= '0'; wait for 20 ns;
assert(q_out='1') report "Fail 0/1" severity error;
a_in <= '1';
wait for 20 ns;
assert(q_out='0') report "Fail 1/0" severity error;
-- Clear inputs a_in <= '0';
assert false report "Test done." severity note; wait;
end process;
end tb;
Result:
72
Task-2
Realization of following circuits using Verilog and VHDL
1. 4:1 MUX by using 2:1 MUX
2. JK Flip-flop
Aim of the experiment:
Realization of the above circuits using Verilog and VHDL.
Software used:
Xilinx Vivado 2020.2
Theory:
JK flip flop:
When clock pulse is not given the output of the JK flip-flop remains as the previous
output value. When clock pulse is given the JK flip-flop behaves as in the truth table.
73
(2:1 mux block diagram)
4:1 multiplexer:
A 4-to-1 multiplexer consists four input lines D0 to D3, two select lines as S0 and S1 and
a output line Y. The select lines S1 and S2 select one of the four input lines to connect the
output line.
74
4:1 MUX truth table.
The output Y for 2:1 mux can be written as
75
temp<=1'b0;
else if(J==1'b1 & K==1'b1) //J=1 and K=0
temp<=1'b1;
else //J=1 and K=1
temp<=~Q;
end
assign Q=temp; //Storing Q(n+1) values
assign Qb=~temp;
endmodule
Test bench code:
module JK_ff_tb;
-------------------------------Inputs
reg J;
reg K;
reg CLK;
---------------------------------Outputs
wire Q;
wire Qb;
--------------------------------- Instantiate the Unit Under Test (UUT)
JK_FF uut (
.J(J),
.K(K),
.CLK(CLK),
.Q(Q),
.Qb(Qb)
);
initial begin
-----------------------------------Initialize Inputs
J = 0;
K = 1'b1;
CLK = 0;
#100;
J=1'b1;
K=1'b0;
#100;
J=1'b0;
#100;
J=1'b1;
K=1'b1;
end
always #25 CLK=~CLK;
endmodule
In VHDL:
Top module:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity JKFF is
Port ( J : in STD_LOGIC;
K : in STD_LOGIC;
CLOCK : in STD_LOGIC;
Q : inout STD_LOGIC;
Qb : inout STD_LOGIC);
end JKFF;
architecture Behavioral of JKFF is
begin
process (CLOCK) //Check rising edge
begin
76
if(J='0' and K='0') then //J=0 and K=0
Q<=Q;
Qb<=Qb;
elsif (J='0' and K='1') then //J=0 and K=1
Q<='0';
Qb<='1';
elsif (J='1' and K='0') then //J=1 and K=0
Q<='1'
Qb<='0';
else //J=1 and K=1
Q<=not Q;
Qb<=not Qb;
end if;
end process;
end Behavioral;
Test bench code:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY JKFF_vhdl_TB IS
END JKFF_vhdl_TB;
ARCHITECTURE behavior OF JKFF_vhdl_TB IS
-------------------------------Component Declaration for the Unit Under Test (UUT)
COMPONENT JKFF
PORT(
J : IN std_logic;
K : IN std_logic;
CLOCK : IN std_logic;
Q : INOUT std_logic;
Qb : INOUT std_logic
);
END COMPONENT;
--------------------------------------------Inputs
signal J : std_logic := '0';
signal K : std_logic := '1';
signal CLOCK : std_logic := '0';
---------------------------------------------BiDirs
signal Q : std_logic;
signal Qb : std_logic;
-------------------------------------------- Clock period definitions
constant CLOCK_period : time := 50 ns;
BEGIN
---------------------------------------------- Instantiate the Unit Under Test (UUT)
uut: JKFF PORT MAP (
J => J,
K => K,
CLOCK => CLOCK,
Q => Q,
Qb => Qb
);
-- -------------------------------------------Clock process definitions
CLOCK_process :process
begin
CLOCK <= '0';
wait for CLOCK_period/2;
CLOCK <= '1';
wait for CLOCK_period/2;
end process;
77
------------------------------------------Stimulus process
stim_proc: process
begin
-----------------------------------------hold reset state for 100 ns.
wait for 100 ns;
J<='1';
K<='0';
wait for 100 ns;
J<='0';
wait for 100 ns;
J<='1';
K<='1';
wait;
end process;END;
Output:
RTL diagram:
78
RTL diagram for JK flipflop in VHDL language.
4:1 Multiplexer:
In Verilog:
Top module 2:1 mux:
module Mux2x1(
input [3:0] a,
input [3:0] b,
input s,
output [3:0] y
);
assign y=s?b:a; //Ternary Operator to select channel
endmodule
4:1 Mux:
module Mux4x1(
input [3:0] IN1, //Input
input [3:0] IN2, //Channels
input [3:0] IN3,
input [3:0] IN4,
input S0, //Select line 1
input S1, //Select line 2
output [3:0] OUT //Output selected channels
);
wire [3:0] t1,t2; //Creating temporary variable
Mux2x1 mux1(IN1,IN2,S0,t1); //Creating Mux1
Mux2x1 mux2(IN3,IN4,S0,t2); //Creating Mux2
Mux2x1 mux3(t1,t2,S1,OUT); //Creating Mux3
Endmodule
Test bench:
module Mux4x1_tb;
-------------------------------------- Inputs
reg [3:0] IN1;
reg [3:0] IN2;
reg [3:0] IN3;
reg [3:0] IN4;
reg S0;
reg S1;
------------------------------------- Outputs
wire [3:0] OUT;
------------------------------------- Instantiate the Unit Under Test (UUT)
Mux4x1 uut (
.IN1(IN1),
.IN2(IN2),
.IN3(IN3),
.IN4(IN4),
79
.S0(S0),
.S1(S1),
.OUT(OUT)
);
initial begin
-----------------------------------------Initialize Inputs
IN1 = 4'b1100;
IN2 = 4'b1101;
IN3 = 4'b1110;
IN4 = 4'b1111;
S0 = 1'b0;
S1 = 1'b0;
#100;
S0 = 1'b0;
S1 = 1'b0;
#100;
S0 = 1'b0;
S1 = 1'b1;
#100;
S0 = 1'b1;
S1 = 1'b0;
#100;
S0 = 1'b1;
S1 = 1'b1;
end
endmodule
In VHDL:
Output:
81
RTL diagram:
Conclusion:
The results observed in simulator are same as that of the truth table for JK flip-flop
and 4:1 mux. And for the multiplier the product of two numbers obtained are verified.
82
Task-3
Objective: To realize synchronous and asynchronous FIFO
Theory:
FIFO:
A FIFO is a special type of buffer. The name FIFO stands for first in first out and means
that the data written into the buffer first comes out of it first. There are other kinds of buffers like the
LIFO (last in first out), often called a stack memory, and the shared memory. The choice of a buffer
architecture depends on the application to be solved. FIFOs can be implemented with software or
hardware. The choice between a software and a hardware solution depends on the application and
the features desired. When requirements change, a software FIFO easily can be adapted to them
by modifying its program, while a hardware FIFO may demand a new board layout. Software is
more flexible than hardware. The advantage of the hardware FIFOs shows in their speed.
In concurrent read/write FIFOs, there is no dependence between the writing and reading of data.
Simultaneous writing and reading are possible in overlapping fashion or successively. Concurrent
read/write FIFOs, depending on the control signals for writing and reading, fall into two groups:
➢ Synchronous FIFO
➢ Asynchronous FIFO.
Synchronous FIFO:
The purpose of a FIFO is to pass the first given input as the first output, second input as
the second output, etc... What makes the circuit synchronous is the use of a clock signal. The clk
signal for our circuit has a period of 20 nano-seconds (ns), and is positive edge triggered. This
means the clock will only recognize the data during the rising edge of the clock. If the data were to
change within the 20ns period, the clk will not recognize the data until the next positive edge
trigger – this assumes the data hasn’t changed to a new value before the next positive edge of the
clock. One limitation of the Synchronous FIFO circuit is the speed at which the circuit can be
operable.
A Synchronous FIFO circuit must be clocked depending on the slowest block that processes the
information. Data can be fully processed through each ‘Reg’ block during the same clock period –
keeping the process synchronized. During the positive edge of the clock, an 8-bit binary number is
passed into the first Register block (Reg1). In the next clock cycle, the data within Reg1 is
transferred to Reg2, while at the same time a new 8-bit binary number is passed into Reg1. This
process is repeated until the data that was first entered into Reg1 is outputted out of Reg4.
Fig 3.1 represents the basic block diagram of Synchronous FIFO.
Asynchronous FIFO:
A FIFO is a digital circuit that is used for safe transmission of data, usually from one clock
domain to another asynchronous clock domain. That is, a block of data is sent to the FIFO memory
from one clock domain and that stored data is read back from the same FIFO by a different clock
83
domain, with the two clock domains being asynchronous with each other. This is usually achieved
by placing the data block into the FIFO memory with the help of control signals in one clock
domain and control signals from the other clock. domain are used to retrieve the stored data from
the FIFO memory from the output port of the FIFO.
The FIFO is full, when both the pointers are equal, in the case where the write pointer has
wrapped around and caught up with the read pointer. This gives rise to a problem as we are
unable to distinguish between the cases where the FIFO is full or empty. One way to overcome this
ambiguity is to add an extra bit to the read and write pointers. Using this, whenever the write
pointer moves past the last FIFO address, it will toggle that extra bit and will reset the rest of its bits
back to zero. The read pointer follows the same technique. If the MSBs of the two pointers are the
same then that would mean that the pointers have wrapped the same number of times and the
FIFO is empty and if the MSBs of the two pointers are different, that means that the write pointer
has wrapped one more time than the read pointer and hence the FIFO is full
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
component DFF
port (
84
D : in STD_LOGIC_VECTOR (7 downto 0);
Q : out STD_LOGIC_VECTOR (7 downto 0);
clk : in STD_LOGIC );
end component;
--'Signal' represents wires interconnecting each Register block within the top level module
signal W1,W2,W3 : std_logic_vector(7 downto 0);
begin
--Format
--Block name: DFF (input, output, clock);
Reg1: DFF port map(input,W1,clk);
Reg2: DFF port map(W1,W2,clk);
Reg3: DFF port map(W2,W3,clk);
Reg4: DFF port map(W3,output,clk);
end Behavioral;
--FIFO Test Bench
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY FIFO_4reg_8bits_TB is
END FIFO_4reg_8bits_TB;
ARCHITECTURE behavior of FIFO_4reg_8bits_TB is
-- Declare the component for the Unit Under Test (UUT)
COMPONENT FIFO_4reg_8bits PORT(
clk : in std_logic;
input : in std_logic_vector(7 downto 0);
output : out std_logic_vector(7 downto 0)
);
END COMPONENT;
--Defining Inputs Outputs
signal clk : std_logic := '0';
signal input : std_logic_vector(7 downto 0) := (others => '0');
signal output : std_logic_vector(7 downto 0);
-- Clock period definitions
constant clk_period : time := 20 ns;
BEGIN
-- Instantiate the Unit Under Test (UUT)
--Assigning equivalent ports from Design to TB
uut: FIFO_4reg_8bits PORT MAP (
clk => clk,
input => input,
output => output );
-- Clock process definitions
--Clock starts at 0, and toggles every clk_period/2 (10ns)
clk_process :process
begin
clk <= '0';
wait for clk_period/2;
clk <= '1';
wait for clk_period/2;
end process;
-- Stimulus process
stim_proc: process
begin
-- hold state for 200 ns.
input <= "11111111"; --FF
wait for 200 ns;
input <= "11101110"; --EE
wait for 200 ns;
85
input <= "11011101"; --DD
wait for 200 ns;
input <= "11001100"; --CC
wait for 200 ns;
input <= "10111011"; --BB
wait for 200 ns;
wait for clk_period*4;
wait;
end process;
END;
--code for DFF component Used
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
--Define I/O's of DFF
entity DFF is
Port
( clk : in STD_LOGIC;
D : in STD_LOGIC_VECTOR (7 downto 0);
Q : out STD_LOGIC_VECTOR (7 downto 0));
end DFF;
--Process to set the clock characteristics.
--DFF becomes Synchronous with the introduction of a clock architecture Behavioral of DFF is
--Defines the behavior of the DFF.
architecture Behavioral of DFF is
begin
process(clk)
begin
if ( rising_edge(clk) ) then
Q <= D;
end if;
end process;
end Behavioral;
2. Code for Asynchronous FIFO:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
--Define top level ports of Async FIFO block
--Design contains 8 Async FIFO reg's
entity Async is Port
( R_in_Top : in STD_LOGIC;
A_in_Top : out STD_LOGIC;
A_out_Top : in STD_LOGIC;
R_out_Top : out STD_LOGIC;
D_in_Top : in STD_LOGIC_VECTOR (7 downto 0);
D_out_Top : out STD_LOGIC_VECTOR (7 downto 0));
end Async;
91
Results:
Conclusions:
Designed and obtained results for synchronous and asynchronous FIFO using VIVADO Design
Suite and simulation results are also obtained.
92
TASK-4
Objective: To design Finite state machine for detecting sequence of 11010.
Theory:
FSM:
The definition of a finite state machine is, the term finite state machine (FSM) is also known
as finite state automation. FSM is a calculation model that can be executed with the help of
hardware otherwise software. This is used for creating sequential logic as well as a few computer
programs. FSMs are significant for understanding the decision making logic as well as control the
digital systems. In the FSM, the outputs, as well as the next state, are a present state and the input
function. This means that the selection of the next state mainly depends on the input value. There
are two types of FSMs.
Mealy State Machine: A Finite State Machine is said to be Mealy state machine, if outputs depend
on both present inputs & present states. The block diagram of Mealy state machine is shown in the
following figure.
Mealy State Machine: A Finite State Machine is said to be Mealy state machine, if outputs
depend on both present inputs & present states. The block diagram of Mealy state machine is
shown in the following figure.
Moore State Machine: A Finite State Machine is said to be Moore state machine, if outputs depend
only on present states. The block diagram of Moore state machine is shown in the following figure.
93
Procedure of Experiment:
Vivado Design suite was opened and a new project is created and name of project was set
and coding language was selected as VHDL.
The code is written and simulated with test bench and appropriate inputs were given with
respective delays.
Test bench is run to get the output.
CODES:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity FSM is
Port
( clk, X, rst : in std_logic;
Y : out std_logic);
end FSM;
architecture Behavioral of FSM is
type mystate is (S0,S1,S2,S3,S4);
signal ps,ns: mystate;
begin
process(clk)
begin
if rising_edge(clk) then
if (rst<='1') then
ps<=S0;
else
ps<=ns;
end if;
end if;
end process;
state_moments:process(ps,X)
begin
Y<='0';
case (ps) is
--CASE OF S0
when S0=>
if (X='1') then
ns<=S1;
Y<='0';
else if (X='0') then
ns<=S0;
94
Y<='0';
end if;
end if;
--CASE OF S1
when S1=>
if (X='1') then
ns<=S2;
Y<='0';
else if (X='0') then
ns<=S0;
Y<='0';
end if;
end if;
--CASE OF S2
when S2=>
if (X='0') then
ns<=S3;
Y<='0';
95
signal Y:std_logic;
constant clk_period : time := 100 ns;
begin
uut: FSM port map(clk=>clk,rst=>rst,X=>X,Y=>Y);
clk_process :process
begin
clk <= '0';
wait for clk_period/2;
clk <= '1';
wait for clk_period/2;
end process;
instances:process
begin
rst <= '1';
wait for 100 ns;
rst <= '0';
X<='0';
wait for 100ns;
X<='1';
wait for 100ns;
X<='1';
wait for 100ns;
X<='0';
wait for 100ns;
X<='1';
wait for 100ns;
X<='0';
wait for 100ns;
X<='0';
wait for 100ns;
X<='1';
end process;
end Behavioral;
Results:
Conclusion: Designed and obtained simulation results for FSM detecting sequence 11010.
96
Aim: To realize the 8-bit fixed point adder and 8-bit fixed point multiplier using Verilog
Code:
Bit fixed point Adder
Top module
module qadd #(
//Parameterized values
parameter Q = 4,
parameter N = 8
)
(
input [N-1:0] a,
input [N-1:0] b,
output [N-1:0] c
);
reg [N-1:0] res;
assign c = res;
always @(a,b) begin
if(a[N-1] == b[N-1]) begin
res[N-2:0] = a[N-2:0] + b[N-2:0];
res[N-1] = a[N-1];
end
else if(a[N-1] == 0 && b[N-1] == 1) begin
if( a[N-2:0] > b[N-2:0] ) begin
res[N-2:0] = a[N-2:0] - b[N-2:0];
res[N-1] = 0;
end
else begin
res[N-2:0] = b[N-2:0] - a[N-2:0];
if (res[N-2:0] == 0)
res[N-1] = 0;
else
res[N-1] = 1;
end
end
else begin
if( a[N-2:0] > b[N-2:0] ) begin
res[N-2:0] = a[N-2:0] - b[N-2:0];
if (res[N-2:0] == 0)
res[N-1] = 0;
else
res[N-1] = 1;
end
else begin
res[N-2:0] = b[N-2:0] - a[N-2:0];
res[N-1] = 0;
end
end
end
endmodule
Testbench Code
`timescale 1ns / 1ps
module Test_add;
97
// Inputs
reg [7:0] a;
reg [7:0] b;
// Outputs
wire [7:0] c;
// Instantiate the Unit Under Test (UUT)
qadd #(8,8) uut (
.a(a),
.b(b),
.c(c)
);
//These are to monitor the values...
wire [6:0] c_out;
wire [6:0] a_in;
wire [6:0] b_in;
wire a_sign;
wire b_sign;
wire c_sign;
assign a_in = a[6:0];
assign b_in = b[6:0];
assign c_out = c[6:0];
assign a_sign = a[7];
assign b_sign = b[7];
assign c_sign = c[7];
initial begin
// Initialize Inputs
a[6:0] = 0;
a[7] = 0;
b[7] = 1;
b[6:0] = 0;
// Wait 100 ns for global reset to finish
#100;
// Add stimulus here
forever begin
#1 a = a+5179347;
a[7] = 0;
b[7] = 1;
if (a[6:0] > 2.1E9)
begin
a = 0;
b[7] = 1;
b[6:0] = b[6:0] + 3779351;
end
end
end
endmodule
8-Bit fixed point multiplier
`timescale 1ns / 1ps
module qmult #(
//Parameterized values
parameter Q = 4,
parameter N = 8
)
(
input [N-1:0]i_multiplicand,
98
input [N-1:0]i_multiplier,
output[N-1:0]o_result,
output reg ovr
);
reg [2*N-1:0] r_result;
reg [N-1:0]r_RetVal;
assign o_result = r_RetVal;
always @(i_multiplicand, i_multiplier)
begin
r_result <= i_multiplicand[N-2:0] * i_multiplier[N-2:0];
ovr <= 1'b0;
end
always @(r_result) begin
r_RetVal[N-1] <= i_multiplicand[N-1] ^ i_multiplier[N-1];
r_RetVal[N-2:0] <= r_result[N-2+Q:Q];
if (r_result[2*N-2:N-1+Q] > 0)
ovr <= 1'b1;
end
endmodule
Testbench Code:
module Test_mult;
// Inputs
reg [7:0] i_multiplicand;
reg [7:0] i_multiplier;
// Outputs
wire [7:0] o_result;
wire ovr;
// Instantiate the Unit Under Test (UUT)
qmult #(8,8) uut (
.i_multiplicand(i_multiplicand
.i_multiplier(i_multiplier),
.o_result(o_result),
.ovr(ovr)
);
initial begin
$monitor ("%b,%b,%b,%b", i_multiplicand, i_multiplier, o_result, ovr);
// Initialize Inputs
i_multiplicand = 8'b00110010; //pi = 3.141592
i_multiplicand[7] = 0;
i_multiplier[7] = 0;
i_multiplier[6:0] = 0;
#100;
#100
i_multiplier[0] = 1;
end
always begin
#10
i_multiplier[6:0] = (i_multiplier[6:0] << 1) + 1;
end
endmodule
99
Result:
Conclusion:
Fixed point number is the binary representation of fixed position decimal. This use for
precision in DSP.
100
TASK-9
Realize ADC-DAC interface with FPGA.
Theory:
12 bit ADC and 14 bit DAC are interfaced with FPGA. FPGA uses 16 I/O pins to interface
ADC/DAC to have parallel and fast read/write access.
ADC converts analog signal to digital data format. The ADC VHDL code for receiver part is
mentioned below in which 12 bits are converted to 16 bits with four leading zeroes for FPGA to
read the digital data from ADC.
Pin Diagram:
101
VHDL Code for rtl modelling:
library ieee;
use ieee.std_logic_1164.all;
entity adc_parallel_interface_ddr is
port (
i_clk : in std_logic;
i_rise_fall_b : in std_logic;
i_data : in std_logic_vector(3 downto 0);
o_data : out std_logic_vector(3 downto 0));
end adc_parallel_interface_ddr;
architecture rtl of adc_parallel_interface_ddr is
signal r_data_rise : std_logic_vector(3 downto 0);
signal r_data_fall : std_logic_vector(3 downto 0);
begin
p_sample_rise : process(i_clk) -- sample ADC data on rising edge
begin
if(rising_edge(i_clk)) then
r_data_rise <= i_data;
end if;
end process p_sample_rise;
p_sample_fall : process(i_clk) -- sample ADC data on falling edge
begin
if(falling_edge(i_clk)) then
r_data_fall <= i_data;
end if;
end process p_sample_fall;
p_output : process(i_clk) -- select EDGE sampling
begin
if(rising_edge(i_clk)) then
if(i_rise_fall_b='1') then
o_data <= r_data_rise;
else
o_data <= r_data_fall;
end if;
end if;
end process p_output;
end rtl;
RTL model:
102
TASK-8
Theory:
The moving average filter operates by averaging a number of points from the input signal to
produce each point in the output signal , shows the theory of moving average filter.
103
ov_avg <= (others => '0'
else
en_reg <= en;
a_samples(0) <= unsigned(iv_data);
for i in 1 to G_FIL_L-1 loop
a_samples(i) <= a_samples(i-1);
end loop;
v_sum := (others => '0');
if en_reg = '1' then
for i in 0 to G_FIL_L-1 loop
v_sum := v_sum + resize(a_samples(i), v_sum'length);
end loop;
end if;
ov_avg <= std_logic_vector(v_sum(G_DATA_W+sumlog2(G_FIL_L)-1 downto
sumlog2(G_FIL_L))); -- divide by sumlog2(G_FIL_L)
end if;
end if;
end process;
end architecture;
TEST BENCH:
library ieee;
use ieee.std_logic_1164.all;
entity tb_AvgFilter is
generic (
G_DATA_W :integer := 16;
G_FIL_L :integer := 4
);
end entity;
architecture tb_AvgFilter_rtl of tb_AvgFilter is
component AvgFilter is
generic (
G_DATA_W :integer := 16;
G_FIL_L :integer := 4
);
port (
clk :in std_logic;
rst :in std_logic;
en :in std_logic;
iv_data :in std_logic_vector(G_DATA_W-1 downto 0);
ov_avg :out std_logic_vector(G_DATA_W-1 downto 0)
);
end component;
signal clk :std_logic := '0';
signal rst :std_logic := '0';
signal en :std_logic := '0';
signal iv_data :std_logic_vector(G_DATA_W-1 downto 0);
signal ov_avg :std_logic_vector(G_DATA_W-1 downto 0);
constant ClkGenConst :time := 10 ns;
begin
UUT: AvgFilter
generic map (
G_DATA_W => G_DATA_W,
G_FIL_L => G_FIL_L
)
port map (
clk => clk,
rst => rst,
104
en => en,
iv_data => iv_data,
ov_avg => ov_avg
);
ClockGenerator: process
begin
clk <= '0' after ClkGenConst, '1' after 2*ClkGenConst;
wait for 2*ClkGenConst;
end process;
run_proc: process
begin
rst <= '1';
iv_data <= (others => '0');
en <= '0';
wait for 100 ns;
rst <= '0';
wait for 40 ns;
iv_data <= x"000A";
en <= '1';
wait for 20 ns;
iv_data <= x"000A";
wait for 20 ns;
iv_data <= x"000A";
wait for 20 ns;
iv_data <= x"000A";
wait for 20 ns;
iv_data <= x"000A";
wait for 20 ns;
iv_data <= x"000A";
wait for 20 ns;
iv_data <= x"000A";
wait for 20 ns;
iv_data <= x"000A";
wait for 20 ns;
iv_data <= x"000A";
wait for 20 ns;
iv_data <= x"000A";
wait for 20 ns;
en <= '0';
wait;
end process;
end architecture;
Simulation:
105
TASK-10
Theory:
A finite impulse response (FIR) filter is a filter whose impulse response (or response to any
finite length input) is of finite duration, because it settles to zero in finite time. An FIR filter is
designed by finding the coefficients and filter order that meet certain specifications, which can be
in the time domain (e.g. a matched filter) and/or the frequency .
Filters play an important role for removal of unwanted signal or noise from original input signal by
removing the selected frequencies from incoming signal. They became much popular due to the
increase of the digital signal processing
The first order filters can be easily converted into second order filters simply by using an additional
RC network within the input or feedback path. Then we can define second order filters as simply
being two 1st-order filters cascaded together with amplification circuit.
VHDL code for the FIR filter(low pass):
Library IEEE;
USE IEEE.Std_logic_1164.all;
USE IEEE.Std_logic_signed.all;
entity FIR_RI is generic (
input_width : integer :=8; -- set input width
output_width : integer: =16; -- set output width
coef_width : integer : =8 -- set coefficient
tap : integer :=11 ; -- set filter order
guard : integer :=0);
port(Din : in std_logic_vector(input_width-1 downto 0);-- input data
Clk : in std_logic;-- input clk
reset: in std_logic;-- input reset
Dout : out std_logic_vector(output_width-1 downto 0));-- output data
end FIR_RI;
architecture behaivioral of FIR_RI is
component N_bit_Reg
generic (input_width: integer:=8);
port(
Q : out std_logic_vector(input_width-1 downto 0);
Clk :in std_logic;
reset :in std_logic;
D :in std_logic_vector(input_width-1 downto 0)
);
end component;
type Coeficient_type is array (1 to tap) of std_logic_vector(coef_width-1 downto 0);
constant coeficient: coeficient_type := ( X"F1", X"F3", X"07", X"26", X"42", X"4E", X"42", X"26",
X"07", X"F3", X"F1" );
type shift_reg_type is array (0 to tap-1) of std_logic_vector(input_width-1 downto 0);
signal shift_reg : shift_reg_type;
type mult_type is array (0 to tap-1) of std_logic_vector(input_width+coef_width-1 downto 0);
signal mult : mult_type;
type ADD_type is array (0 to tap-1) of std_logic_vector(input_width+coef_width-1 downto 0);
signal ADD: ADD_type;
begin
shift_reg(0) <= Din;
106
mult(0)<= Din*coeficient(1);
ADD(0)<= Din*coeficient(1);
GEN_FIR:
for i in 0 to tap-2 generate
begin
N_bit_Reg_unit : N_bit_Reg generic map (input_width => 8)
port map ( Clk => Clk,
reset => reset,
D => shift_reg(i),
Q => shift_reg(i+1)
);
-- filter multiplication
mult(i+1)<= shift_reg(i+1)*coeficient(i+2);
-- filter conbinational addition
ADD(i+1)<=ADD(i)+mult(i+1);
end generate GEN_FIR;
Dout <= ADD(tap-1);
end Architecture;
Library IEEE;
USE IEEE.Std_logic_1164.all;
entity N_bit_Reg is
generic (input_width : integer :=8);
port(
Q : out std_logic_vector(input_width-1 downto 0);
Clk :in std_logic;
reset :in std_logic;
D :in std_logic_vector(input_width-1 downto 0)
);
end N_bit_Reg;
begin
process(Clk,reset)
begin
if (reset = '1') then
Q <= (others => '0');
elsif ( rising_edge(Clk) ) then
Q <= D;
end if;
end process;
end Behavioral;
Testbench VHDL code for the FIR filter:
Library IEEE;
USE IEEE.Std_logic_1164.all;
USE IEEE.numeric_std.all;
Use STD.TEXTIO.all;
entity TB_FIR is
end TB_FIR;
architecture behaivioral of TB_FIR is
Component FIR_RI is
generic (input_width: integer :=8; -- set input width
output_width: integer:=16; -- set output width coef_width: integer:=8; -- set coefficient width
tap: integer:=11; -- set filter order
guard : integer:=4); -- log2(tap)+1
port(Din : in std_logic_vector(input_width-1 downto 0;
-- input data
Clk: in std_logic; -- input clk
reset : in std_logic; -- input reset
Dout : out std_logic_vector(output_width-1 downto 0));
end Component;
107
signal Din : std_logic_vector(7 downto 0);
signal Clk: std_logic:='0';
signal reset : std_logic:='1’;
signal output_ready : std_logic:='0';
signal Dout : std_logic_vector(15 downto 0);
signal input: std_logic_vector(7 downto 0);
file my_input : TEXT open READ_MODE is "input101.txt";
file my_output : TEXT open WRITE_MODE is "output101_functional_sim.txt";
begin
FIR_int : FIR_RI
generic map(input_width => 8,
output_width => 16,
coef_width => 8,
tap=>11,
guard => 0);
port map (Din => Din,
Clk => Clk,
reset => reset,
Dout => Dout );
process(clk)
begin
Clk <= not Clk after 10 ns;
end process;
reset <= '1', '1' after 100 ns, '0' after 503 ns;
process(clk)
variable my_input_line : LINE;
variable input1: integer;
begin
if reset ='1' then
Din <= (others=> '0');
input <= (others=> '0');
output_ready <= '0';
elsif rising_edge(clk) then
readline(my_input, my_input_line);
read(my_input_line,input1);
Din <= std_logic_vector(to_signed(input1, 8));
--Din<=input(7 downto 0);
output_ready <= '1';
end if;
end process;
process(clk)
variable my_output_line : LINE;
variable input1: integer;
begin
if falling_edge(clk) then
if output_ready ='1' then
write(my_output_line, to_integer(signed(Dout)));
writeline(my_output,my_output_line);
end if;
end if;
end process;
end Architecture;
VERILOG code:
module fir_4tap(
input Clk,
input signed [7:0] Xin,
output reg signed [15:0] Yout);
108
//Internal variables.
wire signed [7:0] H0,H1,H2,H3;
wire signed [15:0] MCM0,MCM1,MCM2,MCM3,add_out1,add_out2,add_out3;
wire signed [15:0] Q1,Q2,Q3;
//filter coefficient initializations.
//H = [-2 -1 3 4].
assign H0 = -2;
assign H1 = -1;
assign H2 = 3;
assign H3 = 4;
//Multiple constant multiplications.
assign MCM3 = H3*Xin;
assign MCM2 = H2*Xin;
assign MCM1 = H1*Xin;
assign MCM0 = H0*Xin;
//adders
assign add_out1 = Q1 + MCM2;
assign add_out2 = Q2 + MCM1;
assign add_out3 = Q3 + MCM0;
//flipflop instantiations (for introducing a delay).
DFF dff1 (.Clk(Clk),.D(MCM3),.Q(Q1));
DFF dff2 (.Clk(Clk),.D(add_out1),.Q(Q2));
DFF dff3 (.Clk(Clk),.D(add_out2),.Q(Q3));
//Assign the last adder output to final output.
always@ (posedge Clk)
Yout <= add_out3;
Endmodule
DFF:
module DFF
(input Clk,
input [15:0] D,
output reg [15:0] Q
);
always@ (posedge Clk)
Q = D;
endmodule
Testbench for the FIR filter:
module tb;
// Inputs
reg Clk;
reg signed [7:0] Xin;
// Outputs
wire signed [15:0] Yout;
// Instantiate the Unit Under Test (UUT)
fir_4tap uut (
.Clk(Clk),
.Xin(Xin),
.Yout(Yout)
);
//Generate a clock with 10 ns clock period.
initial Clk = 0; always #5 Clk =~Clk;
//Initialize and apply the inputs.
initial begin
Xin = 0; #40;
Xin = -3; #10;
Xin = 1; #10;
Xin = 0; #10;
Xin = -2; #10;
109
Xin = -1; #10;
Xin = 4; #10;
Xin = -5; #10;
Xin = 6; #10;
Xin = 0; #10;
END
Simulation waveform:
110
XA Zynq UltraScale+ MPSoC Data Sheet: Overview
General Description
The XA Zynq® UltraScale+™ MPSoC family is based on the Xilinx® UltraScale™ MPSoC architecture. This family of products
integrates a feature-rich 64-bit quad-core Arm® Cortex™-A53 and dual-core Arm Cortex-R5 based processing system (PS)
and Xilinx programmable logic (PL) UltraScale architecture in a single device. Also included are on-chip memory, multiport
external memory interfaces, and a rich set of peripheral connectivity interfaces.
111
Arm Mali-400 Based GPU
Supports OpenGL ES 1.1 and 2.0
Supports OpenVG 1.1
GPU frequency: Up to 600MHz
Single Geometry Processor, Two Pixel Processors
Vertex processing: 66 M Triangles/s
Pixel processing: 1.2 G Pixels/s
64KB L2 Cache
Power island gating
External Memory Interfaces
Multi-protocol dynamic memory controller
32-bit or 64-bit interfaces to DDR4, DDR3, DDR3L, or LPDDR3 memories, and 32-bit interface to
LPDDR4 memory
ECC support in 64-bit and 32-bit modes
Up to 32GB of address space using single or dual rank of 8-, 16-, or 32-bit-wide memories
Static memory interfaces
o eMMC4.51 Managed NAND flash support
o ONFI3.1 NAND flash with 24-bit ECC
o 1-bit SPI, 2-bit SPI, 4-bit SPI (Quad-SPI), or two Quad-SPI (8-bit) serial NOR flash
8-Channel DMA Controller
Two DMA controllers of 8-channels each
Memory-to-memory, memory-to-peripheral, peripheral-to-memory, and scatter-gather transaction
support
Serial Transceivers
Four dedicated PS-GTR receivers and transmitters supports up to 6.0Gb/s data rates
o Supports SGMII tri-speed Ethernet, PCI Express® Gen2, Serial-ATA (SATA), USB3.0, and DisplayPort
Dedicated I/O Peripherals and Interfaces
PCI Express — Compliant with PCIe® 2.1 base specification
o Root complex and End Point configurations
o x1, x2, and x4 at Gen1 or Gen2 rates
SATA Host
o 1.5, 3.0, and 6.0Gb/s data rates as defined by SATA Specification, revision 3.1
o Supports up to two channels
DisplayPort Controller
o Up to 5.4Gb/s rate
Four 10/100/1000 tri-speed Ethernet MAC peripherals with IEEE Std 802.3 and IEEE Std 1588 revision 2.0
support
o Scatter-gather DMA capability
o Recognition of IEEE Std 1588 rev.2 PTP frames
o GMII, RGMII, and SGMII interfaces
o Jumbo frames
Two USB 3.0/2.0 Device, Host, or OTG peripherals, each supporting up to 12 endpoints
o USB 3.0/2.0 compliant device IP core
o Super-speed, high- speed, full-speed, and low-speed modes
o Intel XHCI- compliant USB host
Two full CAN 2.0B-compliant CAN bus interfaces
o CAN 2.0-A and CAN 2.0-B and ISO 118981-1
standard compliant
Two SD/SDIO 2.0/eMMC4.51 compliant controllers
Two full-duplex SPI ports with three peripheral chip selects
Two high-speed UARTs (up to 1Mb/s)
Two master and slave I2C interfaces
Up to 78 flexible multiplexed I/O (MIO) (up to three banks of 26 I/Os) for peripheral pin assignment
Up to 96 EMIOs (up to three banks of 32 I/Os) connected to the PL
112
Interconnect
High-bandwidth connectivity within PS and between PS and PL
Arm AMBA® AXI4-based
QoS support for latency and bandwidth control
Cache Coherent Interconnect (CCI)
System Memory Management
System Memory Management Unit (SMMU)
Xilinx Memory Protection Unit (XMPU)
Platform Management Unit
Power gates PS peripherals, power islands, and power domains
Clock gates PS peripheral user firmware option
Configuration and Security Unit
Boots PS and configures PL
Supports secure and non-secure boot modes
System Monitor in PS
On-chip voltage and temperature sensing
The UltraScale MPSoC architecture provides processor scalability from 32 to 64 bits with support for
virtualization, the combination of soft and hard engines for real-time control, graphics/video processing, waveform and
packet processing, next-generation interconnect and memory, advanced power management, and technology
enhancements that deliver multi-level security, safety, and reliability. Xilinx offers a large number of soft IP for the XA Zynq
UltraScale+ MPSoC family. Stand-alone and Linux device drivers are available for the peripherals in the PS and the PL.
Xilinx’s Vivado® Design Suite, SDK™, and PetaLinux development environments enable rapid product development for
software, hardware, and systems engineers. The Arm-based PS also brings a broad range of third-party tools and IP
providers in combination with Xilinx's existing PL ecosystem.
The XA Zynq UltraScale+ MPSoC family delivers unprecedented processing, I/O, and memory bandwidth
in the form of an optimized mix of heterogeneous processing engines embedded in a next-generation, high-
performance, on-chip interconnect with appropriate on-chip memory subsystems. The heterogeneous processing
and programmable engines, which are optimized for different application tasks, enable the XA Zynq UltraScale+ MPSoC
to deliver the extensive performance and efficiency required to address next-generation smarter systems while retaining
backwards compatibility with the original XA Zynq-7000 All Programmable SoC family. The UltraScale MPSoC architecture
also incorporates multiple levels of security, increased safety, and advanced power management, which are critical
requirements of next-generation smarter systems. Xilinx’s embedded UltraFast™ design methodology fully exploits the ASIC-
class capabilities afforded by the UltraScale MPSoC architecture while supporting rapid system development.The inclusion
of an application processor enables high-level operating system support (e.g., AutoSAR and Linux). Other standard
operating systems used with the Cortex-A53 processor are also available for the XA Zynq UltraScale+ MPSoC family.
The PS and the PL are on separate power domains, enabling users to power down the PL for power management if
required. The processors in the PS always boot first, allowing a software centric approach for PL configuration. PL
configuration is managed by software running on the CPU, so it boots similar to an ASSP.
Processing System
Application Processing Unit (APU)
The key features of the APU include:
64-bit quad-core Arm Cortex-A53 MPCores. Features associated with each core include:
o Arm v8-A Architecture
o Operating target frequency: up to 1.2GHz
o Single and double precision floating
point: 4 SP/2 DP FLOPS/MHz
o NEON Advanced SIMD support with single and double precision floating point instructions
o A64 instruction set in 64-bit operating mode, A32/T32 instruction set in 32-bit operating mode
o Level 1 cache (separate instruction and data, 32KB each for each Cortex-A53 CPU)
– 2-way set-associative Instruction Cache with parity support
– 4-way set-associative Data Cache with ECC support
o Integrated memory management unit (MMU) per processor core
o TrustZone for secure mode operation
114
o Virtualization support
Ability to operate in single processor, symmetric quad processor, and asymmetric quad-processor modes
Integrated 16-way set-associative 1MB Unified Level 2 cache with ECC support
Interrupts and Timers
o Generic interrupt controller (GIC-400)
o Arm generic timers (4 timers per CPU)
o One watchdog timer (WDT)
o One global timer
o Two triple timers/counters (TTC)
CoreSight debug and trace support
o Embedded Trace Macrocell (ETM) for instruction trace
o Cross trigger interface (CTI) enabling hardware breakpoints and triggers
ACP interface to PL for I/O coherency and Level 2 cache allocation
ACE interface to PL for full coherency
Power island gating on each processor core
Optional eFUSE disable per core
Real-Time Processing Unit (RPU)
Dual-core Arm Cortex-R5 MPCores. Features associated with each core include:
o Arm v7-R Architecture (32-bit)
o Operating target frequency: Up to 500MHz
o A32/T32 instruction set support
o 4-way set-associative Level 1 caches (separate instruction and data, 32KB each) with ECC support
o Integrated Memory Protection Unit (MPU) per processor
o 128KB Tightly Coupled Memory (TCM) with ECC support
o TCMs can be combined to become 256KB in lockstep mode
Ability to operate in single-processor or dual-processor modes (split and lock-step)
Dedicated SWDT and two Triple Timer Counters (TTC)
CoreSight debug and trace support
o Embedded Trace Macrocell (ETM) for instruction and trace
o Cross trigger interface (CTI) enabling hardware breakpoints and triggers
Optional eFUSE disable
Full-Power Domain DMA (FPD-DMA) and Low-Power Domain DMA (LPD-DMA)
Two general-purpose DMA controllers one in the full-power domain (FPD-DMA) and one in the low-power
domain (LPD-DMA)
Eight independent channels per DMA
Multiple transfer types:
o Memory-to-memory
o Memory-to-peripheral
o Peripheral-to-memory and
o Scatter-gather
8 peripheral interfaces per DMA
TrustZone per DMA for optional secure operation
115
Xilinx Artix Nexys4 DDR™ FPGA Board Reference Manual:
overview
The Nexys4 DDR board is a complete, ready-to-use digital circuit development platform based on the
latest Artix-7™ Field Programmable Gate Array (FPGA) from Xilinx®. With its large, high-capacity FPGA (Xilinx
part number XC7A100T-1CSG324C), generous external memories, and collection of USB, Ethernet, and other
ports, the Nexys4 DDR can host designs ranging from introductory combinational circuits to powerful embedded
processors. Several built-in peripherals, including an accelerometer, temperature sensor, MEMs digital
microphone, a speaker amplifier, and several I/O devices allow the Nexys4 DDR to be used for a wide range of
designs without needing any other components
The Artix-7 FPGA is optimized for high performance logic, and offers more capacity, higher
performance, and more resources than earlier designs. Artix-7 100T features include:
15,850 logic slices, each with four 6-input LUTs and 8 flip-flops
4,860 Kbits of fast block RAM
Six clock management tiles, each with phase-locked loop (PLL)
240 DSP slices
Internal clock speeds exceeding 450 MHz
On-chip analog-to-digital converter (XADC)
The Nexys4 DDR also offers an improved collection of ports and peripherals, including:
116
Callout Component Description Callou Component Description
t
1 Power select jumper and battery header 13 FPGA configuration reset button
2 Shared UART/ JTAG USB port 14 CPU reset button (for soft cores)
3 External configuration jumper (SD / USB) 15 Analog signal Pmod connector (XADC)
4 Pmod connector(s) 16 Programming mode jumper
5 Microphone 17 Audio connector
6 Power supply test point(s) 18 VGA connector
7 LEDs (16) 19 FPGA programming done LED
8 Slide switches 20 Ethernet connector
9 Eight digit 7-seg display 21 USB host connector
10 JTAG port for (optional) external cable 22 PIC24 programming port (factory use)
11 Five pushbuttons 23 Power switch
12 Temperature sensor 24 Power jack
117
Power Supplies
The Nexys4 DDR board can receive power from the Digilent USB-JTAG port (J6) or from an
external power supply. Jumper JP3 (near the power jack) determines which source is used.
All Nexys4 DDR power supplies can be turned on and off by a single logic-level power switch
(SW16). A power-good LED (LD22), driven by the “power good” output of the ADP2118 supply, indicates
that the supplies are turned on and operating normally. An overview of the Nexys4 DDR power circuit is
shown in Figure 2.
The USB port can deliver enough power for the vast majority of designs. Our out-of-box demo draws
~400mA of current from the 5V input rail. A few demanding applications, including any that drive
multiple peripheral boards, might require more power than the USB port can provide. Also, some
applications may need to run without being connected to a PC’s USB port. In these instances, an
external power supply or battery pack can be used.
118
TM4C123G Launchpad Evaluation Kit
The Tiva C Series TM4C123G LaunchPad Evaluation Kit (EK-TM4C123GXL) is a low-cost evaluation platform for
ARM® Cortex™-M4F based microcontrollersThe Tiva C Series LaunchPad design highlights the TM4C123GH6
microcontroller’s USB 2.0 Device interface, Hibernation module, Motion Control PWMs and overall cost effectiveness. The Tiva C
Series LaunchPad also features programmable user buttons and an RGB LEDfor custom applications. The stackable head- ers
of the Tiva C Series TM4C123G Launch- Pad BoosterPack XL interface demonstrate how easy it is to expand the functionality
of the C Series LaunchPad when interfacing to other peripherals with MSP430™ and other TI MCU BoosterPacks
Features
• Tiva C Series TM4C123GH6 microcontroller
• USB Micro-AB connector
• Device mode default configuration
• Host/OTG modes supportable
• RGB user LED
• Two user switches (application/wake)
• Available I/O brought out to headers on a 0.1" grid
• On-board In-Circuit Debug Interface (ICDI)
• Switch-selectable power sources
• ICDI USB Device
• Reset switch.
• Preloaded RG. quickstart application.
• Supported by TivaWare™ for C Series software including the USB library and the peripheral driver library.
• Tiva C Series TM4C123G LaunchPad BoosterPack XL interface which features stackable headers to expand the
capabilities of the 40-pin Tiva C Series LaunchPad evaluation platform.
119