0% found this document useful (0 votes)
79 views69 pages

Project Alessandro Montanari

This document describes a VHDL project completed for a digital systems design course at Mid Sweden University's Department of Information Technology and Media. The project involved designing several modules including a Sobel edge detection module, number displayer, range sensor, and BCD converter. The project was implemented on a FPGA and outputs video signals to a VGA display. Diagrams and code listings are provided in the appendices to describe the design and functionality of each module.

Uploaded by

Fawaz Labeeb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views69 pages

Project Alessandro Montanari

This document describes a VHDL project completed for a digital systems design course at Mid Sweden University's Department of Information Technology and Media. The project involved designing several modules including a Sobel edge detection module, number displayer, range sensor, and BCD converter. The project was implemented on a FPGA and outputs video signals to a VGA display. Diagrams and code listings are provided in the appendices to describe the design and functionality of each module.

Uploaded by

Fawaz Labeeb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 69

Department of Information Technology and Media (ITM)

VHDL Project
Digital System Design with VHDL - 6 Credits
Group 1

Date
13/06/2011
Student
Alessandro Montanari

Study year 2010 - 2011


Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

Abstract

The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
The last chapter deals with a conclusion and covers possible improvements and enhancements.

March 18, 2011 1 Aart Mulder and Kolja Roese

2
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

Abstract

Table of Contents The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
1 Introduction!......................................................................6
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
The last chapter deals with a conclusion and covers possible improvements and enhancements.
1.1 Project Requirements!.........................................................................6

2 Theoretical Concepts!......................................................8
2.1 VGA Video Signals!.............................................................................8

2.2 Sobel Operator!..................................................................................11


2.2.1 Basic Edge Detection Concepts!..................................................................11

2.2.2 First-Order Derivative!...................................................................................13

2.3 Range Sensor!....................................................................................16

2.4 Binary-Coded Decimal!.....................................................................18

3 Design!.............................................................................19
3.1 Overview!............................................................................................19

3.2 Sobel Operator Module !....................................................................20


3.2.1 Cache System Module!..................................................................................20
March 18, 2011 1 Aart Mulder and Kolja Roese
3.2.2 Sobel Kernel Module!....................................................................................30

3.2.3 Simulation!......................................................................................................31

3.3 Number Displayer Module!...............................................................32


3.3.1 Numbers ROM!...............................................................................................33

3.3.2 Code Description!..........................................................................................36

3.3.3 Simulation!......................................................................................................37

3.4 Range Sensor Module !......................................................................38


3
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

3.4.1 Trigger Generator!.........................................................................................39

3.4.2 Distance Measurer!........................................................................................40

3.4.3 Simulation!......................................................................................................
Abstract 41

3.5 BCD Converter Module !....................................................................42


The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
3.5.1 Double-Dabble Algorithm! .............................................................................
the requirement 42
of environmental monitoring with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
3.5.2 Code Description!.......................................................................................... 43 a short
systems with hard disk storage in order to maintain the reliability. The report contains
introduction in wireless sensor networks and describes the complete process of development.
The last chapter deals with a conclusion and covers possible improvements and enhancements.
3.5.3 Simulation!......................................................................................................44

3.6 Top VGA Module !...............................................................................44

3.7 Test!.....................................................................................................46

4 Conclusions and Future Works!...................................48


References!........................................................................49
Appendix!...........................................................................50
Appendix A - counter.vhd!......................................................................50

Appendix B - fifo_linebuffer.vhd!...........................................................50

Appendix C - double_fifo_linebuffer.vhd!..............................................51

Appendix D - sync_signals_delayer.vhd!..............................................52

Appendix E - cache_system.vhd!...........................................................54

Appendix F - sobel_kernel.vhd!..............................................................57
March 18, 2011 1 Aart Mulder and Kolja Roese

Appendix G - edge_sobel_wrapper.vhd!...............................................58

Appendix H - num_rom.vhd!...................................................................59

Appendix I - number_displayer.vhd!......................................................62

Appendix J - bcd_converter.vhd!...........................................................63

Appendix K - trigger_generator.vhd!.....................................................64

Appendix L - distance_measurer.vhd!...................................................65

4
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

Appendix M - range_sensor.vhd!...........................................................66

Appendix N - top_vga.vhd!.....................................................................67

Appendix O - top_vga.ucf!Abstract
......................................................................68

The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
The last chapter deals with a conclusion and covers possible improvements and enhancements.

March 18, 2011 1 Aart Mulder and Kolja Roese

5
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

Abstract
1 Introduction The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
The first aim of this project is to create
complex anwireless
FPGA based
network embedded
structure was designedvideo
with thesystem that is ofable
flexible integration to
multiple
sensor devices. A possible application is the observation of temperature in several server
emphasize the edges of the incoming images using the Sobel operator. The system is basically
systems with hard disk storage in order to maintain the reliability. The report contains a short
composed by a camera that acquire the video
introduction of sensor
in wireless the networks
real world, an the
and describes FPGA and
complete a monitor
process to
of development.
display the processed video stream. The last chapter deals with a conclusion and covers possible improvements and enhancements.

The second aim of this project is to measure the distance between the lens of the camera and
the object in front of it. To achieve this purpose an external range sensor is used to find out the
distance of interest. The detected distance has to be displayed on the monitor overlapped with
the processed video stream that comes from the FPGA.

C
A
M 1.32
E
R
A
Object FPGA \
S
E
N
S
O
R

Figure 1.1.1 - Project Overview

1.1 Project Requirements


March 18, 2011 1 Aart Mulder and Kolja Roese

The components used for the project are the following:


1. Camera Micron MT9V032L MONO: camera for acquire the image of the real world.
2. Digilent Nexys2 Board: circuit development platform based on a Xilinx Spartan 3E
FPGA.
3. Digilent FX2 Module Interface Board: expansion board used to connect the camera
to the development board.
4. SRF05 Ultrasonic Range Sensor: Sensor used to measure the distance between the
lens and the object.
5. VGA Monitor: screen with the resolution of 640x480 for display the results.

6
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

The project is divided into four major tasks:


1. Sobel Edge Detection: this module is responsible to take the images from the
camera and modify them in order to emphasize the edges of the objects using the
Sobel operators. This module must use two 3x3 kernels that must be convolved with
the images from the camera. Abstract This module must be also configurable about the
threshold used to determine if a point is an edge point or not. More informations on the
Sobel operator are reported in section 2.2.
2. Number Displayer: a module The projectmust bein created
is placed in order
the field of Wireless toNetworks.
Sensor displayIt isthree decimal
developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
numbers (separated aftercomplex
the first number
wireless by a decimal
network structure was designeddot)
withonthe a static
flexible imageof or
integration on
multiple
the video stream that comes from the camera. The position of these three numbers
sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
must be configurable: in other words it must be possible to chose the location on the
introduction in wireless sensor networks and describes the complete process of development.
image (or on the video stream)
The last of thedeals
chapter threewith numbers.
a conclusion andThe
coversthree
possiblenumbers
improvementsrepresent the
and enhancements.
distance from the camera to the object in meters and centimeters in the following
format: X.XX.
3. Distance Measurer: the purpose of this module is to send a trigger (of the appropriate
width) to the range sensor and then measure the width of the received echo in order to
find out the distance of the object. The width of the echo must be processed in order to
convert the width in a distance in centimeters.
4. BCD Conversion: the last module is responsible to convert the distance value from
the previous module in three BCD numbers that represent respectively the meters, the
decimeters and the centimeters. These three numbers will be put as inputs to the
Number Displayer module.

The project should be implemented in hardware in the development board mentioned before, for
this reason particular attention must be kept in order to ensure that the entire code of the project
is synthesizable. For achieve the best result in terms of speed and area occupation, during the
entire design some best practices are used.

March 18, 2011 1 Aart Mulder and Kolja Roese

7
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

Abstract
2 Theoretical Concepts The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
In this chapter will be explained thecomplex
theoretical concepts
wireless network that
structure was are lying
designed withbehind the
the flexible development
integration of multiple
sensor devices. A possible application is the observation of temperature in several server
of the project, like the signals used systems
to display images on the screen, the Sobel operator, how to
with hard disk storage in order to maintain the reliability. The report contains a short
read and process the distance detected fromin the
introduction range
wireless sensor sensor and
networks and whattheiscomplete
describes the BCD encoding.
process of development.
The last chapter deals with a conclusion and covers possible improvements and enhancements.

2.1 VGA Video Signals


In general for read out pixels from a camera or for write down pixels on a screen the VGA
standard is used. Like any video format, VGA video is a stream of images also called frames:
each frame is made up of a series of horizontal lines, and each line is made up of a series of
points also called pixels. The lines in each frame are transmitted in order from top to bottom,
and the pixels in each line are transmitted from left to right, as it is possible to see in the Figure
2.1.1.

640
(0,0) (639,0)

480

(0,479) (639,479)

Figure 2.1.1 - Monitor Display Order


Eduardo Sanchez
A Page
color3 VGA video signal is composed by 5 different
Ecole Polytechnique
March 18, 2011
signals:
Fédérale de Lausanne
1 Aart Mulder and Kolja Roese
1. Frame Sync: digital signal that indicates the period of time when a new frame is
displayed on the screen. Sometimes this signal is referred as Vertical Sync.
2. Row Sync: digital signal that indicates the period of time when a new line is displayed
on the screen. Sometimes this signal is referred ad Horizontal Sync.
3. Red: analog signal that represents the intensity of the Red component of a given pixel;
4. Green: analog signal that represents the intensity of the Green component of a given
pixel;
 TheBlue:
5.
screen
pixel.
refresh process begins in the top left corner and
analog signal that represents the intensity of the Blue component of a given

paintsto 1thepixel
In addition at signals
previous a timethere from leftato
is also right.
clock, At defined
usually the end of the
as Pixel firstthat
Clock,
row, the
represents thetime
row increments
available to display one andpixel theof information.
column address is reset to
the first column. Once the entire screen has been painted, the
refresh process begins again 8
 The video signal must redraw the entire screen 60 times per
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

In the Figure below is shown the timing for the VGA synchronization signals.

pixel clock
Abstract
frame sync
The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
row sync row 0 row 1devices. A possible
sensor row 2 applicationrow 477
is the observationrow 478
of temperature in row 479
several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
The last chapter deals with a conclusion and covers possible improvements and enhancements.
Figure 2.1.2 - VGA Synchronization Signals

The Row Sync signal is high for the entire period necessary to display one line on the screen,
when this signal goes down it marks the end of the previous line and the start of the next one.
While the Row Sync signal is high the monitor displays one pixel for each rising edge of the
pixel clock with the color of the pixel defined as a mixture of the three primary colors, Red,
Green and Blue.

On the other hand, the Frame Sync signal marks the start and the end of a frame made up of
video lines. This signal is high for the time necessary to display one entire frame on the screen.
While this signal is high the monitor uses the Row Sync signal to determines when it has to
display a new line.

In more detail, is not possible to display information through the entire interval when the Frame
Sync and the Row Sync signals are high. Indeed there are two intervals, called Front Porch
and Back Porch, during which the screen is not able to display the pixels. These intervals are
present for both synchronization signals, how it is possible to see in Figure 2.1.3. The only
interval where the pixels are printed into the screen is the Display Time and how it is possible to
see it is composed by 480 lines and each line is composed by 640 pixels (obviously for a
640x480 monitor).

The Frame Sync, Row Sync and Pixel Clock determine the screen resolution (ex. 640x480) and
the refresh rate of the entire screen (ex. 60Hz). There are different VGA monitors with different
resolutions and refresh rate, for each of those monitors there are different timings for the
synchronization signals and for the Pixel Clock. For the most common VGA mode 640x480 with
March 18, 2011 1 Aart Mulder and Kolja Roese
the refresh frequency of the entire screen equal to 60 Hz, the timings for the synchronization
signals are reported in the table below. Usually the Pixel Clock frequency is 25.175 MHz.

9
anual www.digilentinc.com

d to each pixel location (the Nexys2 uses three bits per pixel). The controller must
Mid Sweden University
mory as the beams
Department move across the display,
of Information Midand
Swedenretrieve and apply video data to
University
ely the time the electron Department of Information
Technology and Media beam
(ITM) is moving across a given pixel.
technology and media (ITM).

cuit must generate the !"


ignals and coordinate !(& !#$%&
data based on the pixel
k defines the time
one pixel of information. Abstract
! &' !)&
es the “refresh”
play, or the frequency at
on the display is 4*)+-/(&5!"3/
The project is placed 6%)-785!"3/
in the field of Wireless Sensor Networks. It is developed to fulfill
!"#$%& '()(#*+*) the requirement of environmental monitoring with the focus on temperature observation. A
um refresh frequency is ,-#* network
complex wireless .&%/01 2-3*1
structure ,-#* with
was designed .&01 the flexible integration of multiple
play’s phosphor and !" sensor
"*+,-&./%0 devices. A possible
<=>?4% B<=GFDD @C<application is the
AC-.% FDD of temperature in several server
observation
systems with hard disk storage in order to maintain the reliability. The report contains a short
sity, with practical ! #$%& 1$%&/2*-3$40 <@>A=4%
introduction AFBGDDD
in wireless BFD and
sensor networks C@>=-.%
describes=BD
the complete process of development.
alling in the 50Hz to The last chapter deals with a conclusion and covers possible improvements and enhancements.
! &' 5./%0-'$#36 =B-.% <G=DD C A>FB-.% E=
umber of lines to be ! (& 789+3-&98,6 ACD-.% FGDDD <D =BD-+% <=
refresh frequency ! )& :2,;-&98,6 ECF-.% CAGCDD CE <>EC-.% BF
al “retrace” frequency.
80-row display using a
Digilent
Figure 2.1.3 -Figure
nd 60 +/-1Hz refresh,
nual Timings19:VGAVGA system
640x480, 60timings
Hz (fromfor 640x480
Nexys2 Board display
Reference Manual)
www.digilentinc.com
own in the table at right
The VGA
ngs for sync pulsestandard
width anduses a three-row
front and back15-pinporchDE-15intervals connector
(porch like depicted
intervals arein figure 2.1.4.
nc pulse times during which information cannot be displayed) are based on
rom
es 10actual
FPGAVGA displays.
signals to
h 8-bit color and the two
cuit
(HSdecodes the output
– Horizontal Sync, of a horizontal-sync counter driven by the pixel clock to
imings. This counter
c). The color can be used to locate any pixel location on a given row.
signals use
softhat
a vertical-sync counter that increments with each HS pulse can be used to
work in conjunction
imings,
nation resistance of the can be used to locate any given row. These two
and this counter
ounters can levels
eight signal be used on to
theform an address Figure
into video RAM. No time relationship
2.1.4 - VGA Connector
fgnals,
the HSandpulse
four and the onset of the VS pulse is specified, so the designer can
on blue
ss to easily form
sensitive video RAM addresses, or to minimize decoding logic for sync
Theto connector
blue levels).
carries the three analog signals for the color of the pixel and the two digital
figure 13, produces video
signals for the synchronization, for this reason the same connectors and cables can be used
eed in equal increments
with monitors with different resolutions and refresh rate.
and 0.7V (fully on). Using
nt colorsThe
cancamera
be used for the project uses the same VGA standard, so the pixels are read from left
ch uniqueto8-bit right, row A
pattern. by row and an entire frame is composed by several rows. The same
must besynchronization
created in the signals (Frame Sync and Row Sync) are generated by the camera for indicate
nc and colorwhen signals
a newwith
row or a new frame is March 18, 2011
started. 1
The only difference with the VGAAart Mulder and Kolja Roese
standard is that in
rder to produce
this case a working
the camera is a gray scale camera and the values for each pixel is transmitted in a
digital format. Indeed the gray value of each pixel is represented using 8 bits, so a total of 256
different gray values are possible.

For simulate the behavior of the monitor and the camera is used a particular test bench which is
Figure
e specified, to20: Schematic
ablepublished,
read an imageforfrom
a VGA
thecontroller
filesystemcircuit
and produce the synchronization signals like in the
by the VESA
VGA organization
standard: row sync, frame sync and pixel value (gray scale - 8 bits). At the same time this
followingtest
VGA system
bench also providesFigure
the possibility
16: VGA pinto write a grayand
definitions scale imagecircuit
Nexys2 on the filesystem using the
rovided same
as an VGA
example of
signals.
might be driven in 640 by 480 mode. For more precise information, or for
VGA frequencies, refer to documentation available at the VESA website.

lays use amplitude-modulated moving electron beams (or cathode rays) to


c. Page
a phosphor-coated screen. displays use an array10of switches thatDoc:
LCD12/17 can 502-107
oss a small amount of
changing light !"#$%&'%"()*%&+,*%%"-
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

pxlclk
data_out
data_in 8
8 img_testbench fsync_out
fsync_in
rsync_in Abstract rsync_out

The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
Figure 2.1.5 - img_testbech Module
the requirement of environmental monitoring with the focus on temperature observation.
A
complex wireless network structure was designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
As it is possible to see in the previous figure the test bench is called img_testbench and has
systems with hard disk storage in order to maintain the reliability. The report contains a short
four inputs and three outputs. The outputs
introductionrepresent thenetworks
in wireless sensor signals andgenerated duringprocess
describes the complete the ofreading of
development.
a certain image on the filesystem while
The lastthe inputs
chapter represent
deals with a conclusionthe signals
and covers used
possible to write
improvements an image
and enhancements.

on the filesystem. In other words this module is at the same time a “camera” and a “monitor”.
This test bench was not created but was already provided for the project.

The test bench just mentioned is not able to handle the porch intervals, in other words the
period necessary to display a line (or a frame) is exactly the time necessary to display 640
pixels (or 480 lines) and not more. The entire design is developed keeping in mind this fact,
with the future intention of improve it from this point of view.

2.2 Sobel Operator


2.2.1 Basic Edge Detection Concepts

Before to talk about the Sobel operator here we report a brief explanation of what is an edge
inside an image and the basic concepts used to detect it.

Edges characterize boundaries as well as giving the information of the location object, shape
and size. Therefore, edge detection is a fundamental practice in image processing. For
simplicity we will focus only on the gray-scale images. Intuitively an edge is a gray-level
transition from a start value to a final value as it is possible to see in Figure 2.2.1.

March 18, 2011 1 Aart Mulder and Kolja Roese

Figure 2.2.1 - Image and profile of an ideal edge and of a ramp edge

11
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

In the picture above it is possible to notice that an ideal edge is a set of connected pixels (in the
vertical direction in the example) each of which have a completely different gray value from the
other pixel. In the real world, however the edges are blurred and so they have a profile that is
very similar to a ramp (this effect can be reduced using a good quality acquisition system). In
Abstract
this case the transition from one pixel to the adjacent one is not strong as in the ideal case and
so there isnʼt anymore a thin edge (one pixel thick) as in the ideal case but now the edge is
contained in the ramp and is more thick. The blurring effect makes more difficult to recognize
the exact position of an edge usingTheonly the
project grayinvalue
is placed the fieldof
of adjacent pixels,
Wireless Sensor forItthis
Networks. reason
is developed the
to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
most used techniques to detect complexan edge are based upon the first-order or second-order
wireless network structure was designed with the flexible integration of multiple
derivative. sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
As it is possible to see in Figure The
2.2.2 the deals
last chapter first-order derivative
with a conclusion and coversis positive
possible at the
improvements points of
and enhancements.
transition into and out of the ramp as we move from left to right along the profile and it is
constant for points in the ramp and is zero in areas of constant gray level. The second-order
derivative instead is zero along the ramp and in areas of constant gray level and is different
from zero (negative or positive) at the start and at the end of the ramp (from left to right).

Figure 2.2.2 - First- and second-order derivative of a blurred edge

From this brief explanation is possible to notice that the magnitude of first-order derivative can
be used to detect an edge at a point of 18,
March an2011
image, in other words1 is possibleAart
toMulder
understand if a
and Kolja Roese
point is on a ramp that represents a gray level transition. Similarly, the sign of second-order
derivative can be used to determine if a edge pixel lies on the dark (start of the ramp) or light
side (end of the ramp) of an edge.

An important concept that should not be forgotten is that for detect edges inside an image we
are dealing with local computations because we are measuring the transition between adjacent
pixels, for this reason a point in an image can be classified as an edge point if the transition
associated with that point is “significantly” stronger than the background at that point. Therefore
a threshold must be used to determine if the value is “significant” or not. In a formal way it is
possible to say that: a point in an image is an edge point if its first-order derivative is equal or
greater than a specified threshold. If the second-order derivative is used the threshold is used to
check if the two spikes are stronger enough and then the edge point is located at the zero-

12
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

crossing point (point where the line that join the extreme positive and negative values of the
derivative cross the x-axis). It is easy to notice that in general an edge detection technique that
uses the first-order derivative will lead to more thicker edges in relation with techniques that use
the second-order derivative. When all the edge points are discovered, a connectedness criterion
Abstract
must be used to connect all these points to define an edge.

In the next section we will analyze more deeply the technique used to detect edge points based
upon the first-order derivative sinceThe
it isproject
one isofplaced
the aims of this
in the field project.
of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
2.2.2 First-Order Derivative sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
The Sobel operator is one of the fundamental operators
The last chapter deals for and
with a conclusion edgecoversdetection algorithms.
possible improvements It is of
and enhancements.
the family of first-order derivative because it is computed using the digital gradient of the image.
The digital gradient of an image f(x, y) at location (x, y) is defined as the vector:

!"
!! !"
!! ! ! ! ! !" !!!
!
!"
!!"
!! direction
The gradient vector points in the !" of maximum rate of changes of f at coordinates (x, y).
An important quantity!! ! ! detection,
in edge !
! ! !!
!" as!!!
! !"#
stated!! !!! ! !section,
! !previous
in the !
!! is the magnitude of
this vector, denoted ∇f, is computed in !"
this way:
!
!! ! !!! ! !! !!
!! ! !"# !! !! ! ! !! !!! !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!"! !!!
! ! !
! ! !"
This quantity gives the!maximum
! ! !! ! !rate
!! !!!
of increase ! !
of f(x, y) per unit distance in the direction of ∇f
!"
and is the value that should be checked
! ! !! ! ! !
!! !! ! !! !!the
against !!threshold
!! !"
!! !!!! in !!!order
! !!to!determine
!! !! if a point is
! ! ! ! ! ! !
an edge point or not.
! !! ! !! ! !! ! !" !! ! !!! ! !! ! !! !!
Computing the gradient
!
! of an image is! based on obtaining the partial derivatives ∂f/∂x and ∂f/∂y
at every pixel location!and! ! !! ! !! ! !!
! !! !
there are different !ways!!! !
!"# to!!!compute
! !!!!! !!!!! ! !!! !
them: Roberts, Prewitt and Sobel
operators. Using the 3x3!! ! area! shown ! ! ! 2.2.3,
in Figure
! ! !! !!!! ! !!!! ! !
! !!!the ! simplest
!!!
!!! !!! !!!approximation
! !!! ! !! !!to a first-order
derivative is the Roberts approximation!where
! ! the two components
! ! !! ! !!! ! !! ! !!! ! !!! ! !! !!
are computed in this way:

! ! !
March
! !!! ! !! !!
18,! 2011 1 Aart Mulder and Kolja Roese
!
!! ! !! ! !!!! ! !!! ! !! ! !! ! ! !!
! !!!! ! ! !!
! ! !
!!!! !
!! ! !! ! !!! ! !! !!!!! ! !! ! ! ! ! !
! ! ! !! !!
! ! !! !
! !
! z1 ! ! ! !
z2! z3 ! ! ! ! !
! ! !!! ! !! ! !! !!
!! ! !! ! !! ! !! ! !!! ! !! ! !! !!
!! ! ! !! ! !! ! z4 !!!!!!!!!!!!!!!!!!!!!!!"!
z5 z6 !!!
! ! ! ! !
!z7 0z8 z9
! -1 0 -1 !
! !! ! !! ! !!! ! !! ! !!!! ! !!! ! !! !!
0!!zʼs!are 1 gray-level
! !! ! !!! ! !! ! !!!! ! !!! ! !! !!
Figure 2.2.3 - A 3x3 region of an image (the 1 values). 0 Also called neighborhood of z5.
!
! !
-1 0
! 0! -1 !
!
0 1 1!!
-1 ! -1 ! !!
!
0 13! -1 !! ! -1 0 1 !
! ! ! !
0 0 0 -1 0 1 !
! !
!! ! ! !! ! ! !" !!!
! ! !"
!
! ! ! !! ! !! !!"! ! ! ! ! !! ! !! ! !!! ! !! ! !! !!
! ! ! !! ! !! ! !! !!
! !! ! !! ! !!! ! !!! ! !! ! ! !! ! !! !!
Mid Sweden University !!! ! !
! !! ! !!!
!"# ! !University
!!! !! !!!!
! !! ! !!!! ! !! !!
! Department
Mid Sweden !
! ! !!! ! !!! !
!
!!! ! !"# !!of Information
Department of Information
Technology and Media (ITM)
! technology and media (ITM).
!
! !! ! !!!!! ! !!! ! !! ! !!! ! !!! ! !! !!
!!! ! !!
This operators can be implemented !!!convolving
! !! !! ! ! ! !
the masks!!! !in!! ! ! !2.2.4
Figure ! !! with the entire image,
!! ! !! !
!! !
! ! ! ! !!
!!to!!
! ! ! !! ! ! ! ! ! !! ! ! !! ! ! ! !!
but since masks of size 2x2!are ! !awkward
! !!! ! !! ! !! ! !!because
! implement ! ! !!! ! they!! !!donʼt !have a clear center,
a different approach is use! masks
! ! ! !! !
! !of size ! !!
! 3x3 (Figure 2.2.5) in conjunction with the Prewitt
operators computed in this way: !! !
!! ! !! Abstract
! !!!!! ! !! ! ! ! ! ! ! !!
!! ! ! ! !! !!!! !! !! !!
! !!! ! !!! ! !! ! !! !!
! ! ! ! !
!! ! ! ! !! ! !! ! !! ! ! !!! !! !! ! !! !!
! ! ! ! ! ! !
!! ! ! !The ! !
! project ! !
! is placed ! !! !
! in the !field of ! ! ! ! !!
Wireless!Sensor Networks. It is developed to fulfill
!!!
!! ! the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
!
!!! ! !!systems ! ! !! !!in!!order
devices.! A! ! application ! !! is the! !the
! !!reliability. The report contains a short
sensor possible observation of temperature in several server
!hard disk!! storage !
!!! ! !!introduction
!! !!0!in!
!"
with
!!! sensor
! !! ! !! ! !!! !!
to maintain
!! ! !!
! ! !! ! ! !! !! ! ! 0 !!networks
!! ! !!
-1 ! -1
wireless ! describes
and ! the complete process of development.
-1 0 !"
!!!!! !!!! !
The !last !!
! !deals
!!with!a conclusion
!!! ! !! !! ! !possible
! !! improvements and enhancements.
!! !chapter 0 -1
!" !!!
and covers
!
!! 0 10 1
!" 1 01 !
0 !
! !!!! Figure
! !! 2.2.4!! !- Roberts!! ! masks for gradient
!! ! ! !"#! !! !!! ! ! !! ! ! ! ! !
!! ! !! ! !
!! -1 -1! !-1 ! -1 ! !
-1 -1
-1 -1 0 10 1
!
! !! !
0 0 0 -1 0 1 !
!!!! 0! !!!0! !! !!0 ! -1 0 1 !
!!! -1 1! -1 ! -1 !
1! !!!1 0! !! !!1 0
1 1
-1 0 10 1 !
! -1 0 0 -1 !! ! !
! 0Figure! 12.2.5 -! Prewitt 1 masks 0 for!! gradient
0 !1 1 0
!!! ! !! ! !! ! !! ! !!! ! !! ! ! !! !!
!!!! -1
A little variation of the previous
!two equations
! !!are-1 !the Sobel operators
!!10!! that 1 uses ! a weight! of 2 in
!!-2 -1! !! -1 -2 -1! ! !-1
!! 0! !
the center coefficient in order ! to achieve some smoothing by giving more importance
! ! to the
! -1 -1 -1 -1 0
-2 1
center point: 0 00 00 0 -2 0 20 2
!! !
! -1 -1 -1 -1 0 1
0 01 02 -1 0
-1 10 1 !! !
!! 10! !!20 ! !!!10 ! !! 1!-1 !!
-1 ! ! 0
0!! ! ! 1
1 ! ! !!
!!
!! 1! !!1! !!!1! !! !-1 !!! ! 0!!! !1!! !! !
! 1 1 1 -1 0 1 !!
! !
!
!! ! ! ! !! ! ! !
! !
! !
! -1 -2 -1 ! -1 0 1
-1 0 1 !!
! -1 -2 -1
-2 0 12
0 0 18, 0
March 2011
!! Mulder and Kolja Roese
Aart
! 0 0 0 -2 0 2
!
! 1 2 1 ! -1 0 1
!
1 2 1 -1 0 1 !
-1 Figure 0 2.2.6 - Sobel 0 masks !
-1 for gradient !
!
0 1 1 0 !
An important thing that should be noticed is that the coefficients in masks in Figures 2.2.5 and
! they would give a response of 0 in an area of constant gray level,
2.2.6 sum to 0, indicating that
as expected of a derivative! operator.
!
Using the masks described-1 before-1it is possible-1 to-1 compute 0 the 1two components of the gradient
!
(x and y), these two values0then 0 must be 0 combined -1 computing 0 1 the magnitude of the gradient
using the expression reported in Eq. 1. Since the computational burden of! implementing this
1 1 1 -1 0 1 !
14 !
!
!
!! ! !! ! !! ! !! ! !!! ! !! ! !! !!
!! ! !! ! !! ! !! ! !!! ! !! ! !! !!
Mid Sweden University !
Mid Sweden University
Department of Information
Technology and Media (ITM)
! Department of Information
!! ! technology
!! ! !! ! ! !! ! !!! ! !!! ! !! !!
and media (ITM).

expression over an entire image !! ! !! trivial


is not ! !!!(especially
! !! ! !! !!
for big!! ! ! !! !!it is common practice to
images),
approximate the squares and! square roots with absolute values as reported below:
!
!! ! ! !! ! !! !!!!!!!!!!!!!!!!!!!!!!!"! !!!
!
Abstract !
This equation is much more !attractive computationally, and it still preserves relative changes in
gray levels but with a price. The price is that the resulting filters will not be isotropic in general.
!
A filter is isotropic when its response
The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the is independent
requirement of themonitoring
of environmental directionwith of
the the
focus discontinuities in theA
on temperature observation.
! complex wireless !
image to which the filter is applied. This is not a big issue because the isotropic properties of
network structure was designed with the flexible integration of the
multiple

digital gradient are preserved -1 only for a limited number


0 with hard0disk storage
systems of !
sensor devices. A possible application is the observation of temperature in several server
rotational increments that depend
-1 in order to maintain the reliability. The report contains a shorton
the masks used to approximate the derivatives. The most! popular masks used to approximate
introduction in wireless sensor networks and describes the complete process of development.
the gradients (Prewitt and Sobel) 0 give 1 lastthe
The 1 with
chapter deals
same 0a conclusion
result only and covers possible improvements and enhancements.
! for vertical and horizontal edges
(they are isotropic for multiples
! of 90°) an this result is independent of which of the two
equations (Eq. 1 or Eq. 2) is used. Thus, using the simplification in computing the magnitude of
!
the gradient will not lead to a significant lost of information. If it is necessary to emphasize
diagonal edges the masks presented-1 -1 before -1 can be -1 easily 0 modified1 in order ! to create the
strongest response along the diagonal directions. !
0 0 0 -1 0 1 !
An important consideration in1 implementing1 1 neighborhood -1 0 operations
1 is the ! issue of what
happens when the center of the kernel approaches the border of the image. Indeed ! is possible
that when the center of the mask is exactly on a pixel of the border one or more rows or
columns of the mask are outside the! image. In this case there are different ways to handle it:
1. limit the excursion ! of the mask in order to ensure that each part of it is inside the
image. Using this approach
-1 -2 however-1 the -1 resulting0 image 1 will be !smaller than the
original one and the intensity of the reduction depends on the mask size; !
2. 0 mask
use only the part of the 0 that0is fully contained -2 0 inside 2 the image,! in this case the
size of the image is the same as the original but there will be some pixels close to the
1 2 1 -1 0 1 !
borders that are computed using only a part of the mask;
3. surround the image with lines and columns of constant gary! level. The most used
value is zero but sometimes are used the same pixels near the border that are
replicated. As the previous technique the resulting image will have the same size of
the original one but the pixels near the borders will be corrupted.

March 18, 2011 1 Aart Mulder and Kolja Roese

15
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

Abstract

The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless network
Original Image structure was designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
The last chapter deals with a conclusion and covers possible improvements and enhancements.

Figure 2.2.7 - Boundaries of an Image

In this project was made the choice to keep the resulting image of the same size of the original
one and it was choice to adopt as black the pixels that are out of the image boundaries as
shown in Figure 2.2.7.

2.3 Range Sensor


For measure the distance from the camera lens to the object in front of it an ultra-sonic sensor
is used. The basic principle behind this kind of sensors is the following: an ultrasonic signal is
emitted form the sensor and then the time between the emission of the ultrasound and the first
echo received is measured, the time measured is proportional to the distance of the object in
front of the sensor. The sending of the ultrasonic signal can, in general, be controlled by a
specific pin on the sensor, usually, this pin is called Trigger. Each time that the Trigger pin
pulses, an ultrasound signal is emitted. In particular the sensor SRF05 can work in tow different
modes:
1. Mode 1 - Separate Trigger and Echo: in this case two different pins are used for the
Trigger and the Echo signals.
March 18, 2011 1 Aart Mulder and Kolja Roese
2. Mode 2 - Single pin for Trigger and Echo: in this case the same pin is used as input
for receive the Trigger pulse and as output for Echo pulse. This mode is convenient
when the sensor is used with controllers that have a limited number of I/O pins.

In Figure 2.3.1 is depicted the sensor and the connections that must be made for use it in the
Mode 1. As it possible to see only four pins has to be connected: two for the power (5V and 0V)
and two for the Trigger and Echo signals. The pin Mode should be disconnected because it is
used only in Mode 2. The pins on the right side of the sensor must be disconnected because
they are used for program the internal controller of the sensor, if this pins are connected the
correct behavior of the sensor could be compromised.

16
%&'()$/5#3,2#+$A*2"$+#5,3,2#$23*<<#3$,-:$#="/$5*-+9$0*F#$2"#$%&'(8?$!"#$%&'()$*-=01:#+$,$+7,00$:#0,4$;#6/3#$2"#
#="/$510+#$2/$<*.#$+0/A#3$=/-23/00#3+$+1="$,+$2"#$G,+*=$%2,75$,-:$H*=,>#$2*7#$2/$#>#=12#$2"#*3$510+#$*-$=/77,-:+?

Mid :-82&;&'&!"#$<&0-=5,*/>)2&'&!25,+,*2&3+/112+&,.8&?04-
Sweden University
!"*+$7/:#$1+#+$+#5,3,2#$23*<<#3$,-:$#="/$5*-+9$,-:$*+$2"#$+*750#+2$7/:#$2/$1+#?$@00$=/:#$#>,750#+$6/3$2"#$%&'(8
Department of Information Mid Sweden University
A*00$A/3F$6/3$2"#$%&'()$*-$2"*+$7/:#?$!/$1+#$2"*+$7/:#9$I1+2$0#,.#$2"#$7/:#$5*-$1-=/--#=2#:$J$2"#$%&'()$",+$,-
Technology and Media (ITM) Department of Information
technology and media (ITM).
*-2#3-,0$5100$15$3#+*+2/3$/-$2"*+$5*-?

Abstract

The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
The last chapter deals with a conclusion and covers possible improvements and enhancements.

Figure 2.3.1 - Connections for 2-pin Trigger/Echo Mode SRF05

In Figure 2.3.2 is depicted the timing diagram for the sensor used in Mode 1. The users of the
sensor only need to supply a 10us pulse to the Trigger input to start the measure of the
distance. The period between each Trigger pulse must be at least 50ms, this interval should be
respected in order to ensure that the previous ultrasonic signal will not cause a false echo on
the current measure. After the Trigger pulse the sensor will send out an 8 cycle burst of
ultrasound at 40kHz and raise its Echo pin high. Then the sensor listens for an echo,
84947$,2,-784/0-:;-4;5<=>=:8?"%7,-.;.76 #=@ and as
soon as it detects one it lowers the Echo pin again. In this way like described before, the width
of the pulse on the Echo pin is proportional
!"##$"%$#&
to distance to the object. The maximum measurable
'()"%*+,-./0-12*34-56,/71704/
distance of this sensor is about 4 meters and this distance is represented by an echo pulse of
25ms. If no objects are detected in front of the sensor, the Echo pin will become lower anyway
after 30ms.

March 18, 2011 1 Aart Mulder and Kolja Roese

Figure 2.3.2 - Timing Diagram 2-pin Mode SRF05

!"#$%&%'%()*+,$%-)*%."/%0"12%3/)++$/%4*#%562"
!"#$%&'()%*$)$%+%$#,-.)%/#,%0'1%2'3"%!1#--)1%+,(%45"'%$#-,+.$6%+,(%#$%()$#-,)(%3'%$+7)%7+.*+2.)%/#,$%',%)&2)(()(
5',31'..)1$8%!'%*$)%3"#$%&'()6%5',,)53%3")%&'()%/#,%3'%3")%97%:1'*,(%/#,8%!")%)5"'%$#-,+.%;#..%+//)+1%',%3")%$+&)
/#,%+$%3")%31#--)1%$#-,+.8%!")%<=>9?%;#..%,'3%1+#$)%3")%)5"'%.#,)%*,3#.%@99*<%+03)1%3")%),(%'0%3")%31#--)1%$#-,+.8%A'*
17
"+7)%3"+3%.',-%3'%3*1,%3")%31#--)1%/#,%+1'*,(%+,(%&+B)%#3%+,%#,/*3%+,(%3'%"+7)%C'*1%/*.$)%&)+$*1#,-%5'()%1)+(C8%!")
DEF<GH%5'&&+,(%0'*,(%',%&+,C%/'/*.+1%5',31'..)1$%(')$%3"#$%+*3'&+3#5+..C8
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

Measuring the width of the Echo pulse is possible to calculate the distance in centimeters or in
another unit. In particular if the width of the pulse is measured in micro-seconds, the distance in
centimeters can be calculated dividing the width by 58 (us / 58 = cm).

Abstract
2.4 Binary-Coded Decimal
The binary-coded decimal is a digital
Theencoding method
project is placed for ofdecimal
in the field numbers
Wireless Sensor where
Networks. each digit
It is developed is
to fulfill
represented with a binary sequence. In BCD each digit is represented using four bits like in theA
the requirement of environmental monitoring with the focus on temperature observation.
complex wireless network structure was designed with the flexible integration of multiple
table below. sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
DecimalThe last chapter deals with a conclusion BCD
and covers possible improvements and enhancements.

0 0000

1 0001

2 0010

3 0011

4 0100

5 0101

6 0110

7 0111

8 1000

9 1001
Table 2.4.1 - BCD Encoding

Exist two different methods to encode a BCD number in the memory:


1. Uncompressed: each digit is encoded in one byte, with four bits representing the
digits and the other bits having no significance.
2. Packed: two different digits are encoded into a single byte.
March 18, 2011 1 Aart Mulder and Kolja Roese

It is obvious that using the Uncompressed method to store numbers in BCD encoding is not
efficient like using the Packed method. However using the BCD encoding there is, in general,
less efficiency, from the storage point of view, instead of using a typical binary format. After the
inefficiency from the storage point of view, the second most important drawback in using BCD
encoding is that some operations are more complex to implement and therefore slower during
the execution. Nevertheless the BCD format is sometimes used because it makes really easy
the conversion between machine and human-readable formats and also because it makes
possible to achieve a more precise machine-format representation of decimal quantities. For
example the representation of fractions is easier in BCD than in binary.

18
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

Abstract
3 Design The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
In the following chapter is explained thewireless
complex implementation
network structure ofwasthe project
designed with theonflexible
the integration
board Nexys2
of multiple
sensor devices. A possible application is the observation of temperature in several server
using the VHDL language. The first systems
section provide a generic description of the main modules in
with hard disk storage in order to maintain the reliability. The report contains a short
the design, the following sections analyze inindetail
introduction wirelesseach module.
sensor networks and describes the complete process of development.
The last chapter deals with a conclusion and covers possible improvements and enhancements.

The code for each module described in this section can be found in the Appendix.

3.1 Overview

top_vga

pxlclk pxlclk
data_out data_in data_out
FROM THE data_in 8 8 TO THE
8 edge_sobel_wrapper fsync_out fsync_in number_displayer fsync_out
CAMERA fsync_in
rsync_out
MONITOR
rsync_out rsync_in
rsync_in
pos_row pos_col meters decimeters centimeters

10 10 4 4 4
255 255

FROM THE FPGA fpgaclk meters


FROM/TO THE trigger range_sensor decimeters
pulse centimeters
SENSOR

Figure 3.1.1 - Components Overview

In Figure 3.1.1 are depicted the main blocks of the project. The module edge_sobel_wrapper
implements the Sobel algorithm for edge detection. This module takes the synchronization
signals and the value of each pixel from the camera, it modifies
March 18, 2011 1
the value of each pixel in
Aart Mulder and Kolja Roese
accordance to the Sobel operator and put on the outputs the same synchronization signals in
input and the new data for the pixels. These values are then used from the number_displayer
module to recognize the position where the numbers representing the distance should be
displayed. The new values of the pixel data together with the synchronization signals are then
send to the VGA interface.

The range_sensor module is responsible to send the trigger signal to the range sensor and then
measure the echo received from it. The distance is then processed to convert it in meters,
decimeters and centimeters, these values are encoded in BCD and then send to the
number_displayer module.

19
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

3.2 Sobel Operator Module


Abstract
pxlclk
data_out
data_in 8
fsync_in The edge_sobel_wrapper
8 fsync_out
project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
rsync_out
rsync_in the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
Figure 3.2.1 - edge_sobel_wrapper
introduction in wireless sensor networksModule
and describes the complete process of development.
The last chapter deals with a conclusion and covers possible improvements and enhancements.

In Figure 3.2.1 is depicted the edge_sobel_wrapper module. This module is responsible to take
the synchronization signals and the pixel values from the camera and compute the gradient for
each pixel using the Sobel operators.

edge_sobel_wrapper

pxlclk
fsync_out fsync_in
rsync_out rsync_in

data_out1 data_in1
8
data_out2 data_in2
8
pxlclk data_out3 data_in3
data_in
8 data_out
8
8 data_out4 data_in4 fsync_out
fsync_in cache_system 8 sobel_kernel
rsync_in rsync_out
data_out5 data_in5
8
data_out6 data_in6
8
data_out7 data_in7
8
data_out8 data_in8
8
data_out9 data_in9
8

Figure 3.2.2 - edge_sobel_wrapper Internal Connections

How it is possible to see in Figure 3.2.2


March the design of the edge_sobel_wrapper
18, 2011 1 module
Aart Mulder and is
Kolja Roese
divided into two macro modules:
1. cache_system: responsible of the accumulation of the pixel values of the first two
lines and of the retardation of the synchronization signals;
2. sobel_kernel: responsible of computing the approximation of the gradient in both
directions (horizontal and vertical) using the Sobel operators described in section 2.2.

3.2.1 Cache System Module

This module takes, directly from the camera, the two synchronization signals (frame sync and
row sync) and the pixel values (8 bits in gray scale) and put as outputs the values of the eight
pixels that represent the neighborhood of the pixel in the center of the 3x3 kernel, as shown in

20
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

Figure 2.2.3. This module have also to put as outputs the synchronization signals with the right
timings.

The first problem here is the fact that every frame is produced by the camera using the vga
standard reported in section 2.1, Abstract
for this reason it is not possible to emit the pixels of the
resulting image during the reading of the original image in the same order, in other words it is
not possible to emit the first pixel of the resulting image after the reading of the first pixel of the
original image because are not yet The available
project isall theinpixels
placed the fieldin
of the neighborhood
Wireless Sensor Networks. of It that pixel.toThis
is developed fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
fact can be noticed more clearly in Figure 3.2.3,network
complex wireless here structure
it is possible to with
was designed notice that for
the flexible compute
integration the
of multiple
value of the pixel in position (0,0) in the resulting image, nine pixels are needed (from z1 to z9 in
sensor devices. A possible application is the observation of temperature in several server
the position 1), five of these pixels systems
(z1, z2,with hard disk storage in order to maintain the reliability. The report contains a short
z3, z4, z7) are assumed to be black (gray value of
introduction in wireless sensor networks and describes the complete process of development.
zero) as explained at the end of the The section
last chapter 2.2.2.
deals withThe others
a conclusion fourpossible
and covers pixels (z5, z6,and
improvements z8, z9) are
enhancements.
available only after the reading of the entire first line and of the first two pixels of the second
line. This basically means that the emission of the pixels in the resulting image is in “late” of one
line and two pixels respect to the reading of the original image. This also means that for emit
each pixel in the resulting image it is necessary to accumulate the two previous lines of the
original image (in Figure 3.2.3, lines 3 and 4 for positions 4, 5 and 6) and during the reading of
the third line (line 5 in Figure 3.2.3) it is possible to emit the pixels in the line 4 of the resulting
image.

0 1 2 3 ....................................................................... 639

z1 z2 z3 z1 z2 z3 z1 z2 z3

0 z4 z5 z6 z4 z5 z6 z4 z5 z6
1 z7 z8 z9 1 z7 z8 z9 2 z7 z8 z9 3
2
3 z1 z2 z3 z1 z2 z3 z1 z2 z3

4 z4 z5 z6 z4 z5 z6 z4 z5 z6
5 z7 z8 z9 4 z7 z8 z9 5 z7 z8 z9 6
...........................................

Original Image

March 18, 2011 1 Aart Mulder and Kolja Roese

z1 z2 z3 z1 z2 z3 z1 z2 z3
479 z4 z5 z6 z4 z5 z6 z4 z5 z6

z7 z8 z9 7 z7 z8 z9 8 z7 z8 z9 9

Figure 3.2.3 - Convolving a 3x3 mask with an image. With numbers from 1 to 9 are marked the relevant
positions of the mask.

For cope to this problem the basic idea was to create a memory architecture that was able to
stores two lines of the image. The basic structure of this memory is in Figure 3.2.4.

21
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

pixel stream input


fifo_linebuffer 1 fifo_linebuffer 2

d1 d2 d3
z9 z8 z7
Abstract
z6 z5 z4 z3 z2 z1

The 3.2.4
Figure project -isMemory
placed in the field of Wireless
Architecture Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
As it is possible to see in the previous
sensor figure
devices. there are
A possible two fifo
application line
is the buffersof that
observation are responsible
temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
to accumulate exactly the number ofintroduction
pixels in one line
in wireless sensor(640).
networksThese buffers
and describes haveprocess
the complete a First-In-First-
of development.
Out policy, this means that the pixelThevalues
last chaptergo out
deals withfrom the and
a conclusion buffer with the
covers possible same and
improvements order which
enhancements.
they entered and they start to go out only when the line buffer is full. The elements marked with
labels from z1 to z9 (from now called pixel elements) represent a smaller copy of pixel values
which are also stored in the line buffers and they are necessary to extract from the line buffers
exactly the pixel values that must be used from the Sobel kernel. All of these elements are
driven by the pixel clock, this means that at every rising edge of the pixel clock the pixel values
are stored in the line buffers and pass trough the small elements. For example, for the position
5 (Figure 3.2.3) the fifo_linebuffer 1 will hold the line number 4 and the fifo_linebuffer 2 will hold
the line number 3 and when the pixel z9 of the line 5 is read the small elements will contains all
the pixels in the neighborhood of z5.

Consequently the cache_system module has to properly delay the synchronization signals in
order to ensure that the sobel_kernel module will understand when the nine pixel values are
valid. Indeed, the sobel_kernel module has to wait until the cache_system module has
accumulate the right number of lines and pixels so it can start to compute the gradient with the
right values for the nine pixels. This synchronization can be achieved delaying the two
synchronization signals (frame sync and row sync) for the right time, in this case the
cache_system module will rise the frame sync and the row sync after one line and two pixels
because for the position number 1 only the first line is necessary since the pixels z1, z2 and z3
are assumed black.

The implementation of this module (Figure 3.2.5) was divided into several parts:
1. double_fifo_linebuffer : responsible of accumulate two lines of the original image;
2. sync_signals_delayer : responsible of delaying the synchronizations signals;
3. counter : general counter used to count the lines and the pixels during the reading.
The pixel elements responsible ofMarch
storing only the neighborhood
18, 2011 1 pixels ofAart
a Mulder
givenandpixel are
Kolja Roese
created using variables inside the cache_system itself, as described later.

22
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

cache_system

pxlclk

fsync_in
Abstract fsync_out
sync_signals_delayer
rsync_in rsync_out
The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
z9 a short
systems with hard disk storage in order to maintain the reliability. The report contains
pxlclk pdata_out1
introduction in wireless sensor networks and describes the complete8 process of development.
8 z8
The last chapter deals with a conclusion and covers possible improvements and enhancements.

c1
fsync 8
z7
rsync 8
pdata_in z6
8 double_fifo_linebuffer pdata_out2 8
8 z5

c2
8 z4
8
z3
pdata_out3 8 8
z2

c3
8 z1
8

Figure 3.2.5 - cache_system Internal Structure

Fifo Linebuffer Module

In the following Figure is depicted the module that is responsible to store an entire line (640
pixels) using the FIFO policy.

pxlclk
fsync
fifo_linebuffer pdata_out
8
rsync
pdata_in
8 March 18, 2011 1 Aart Mulder and Kolja Roese

Figure 3.2.6 - fifo_linebuffer Module

To implement the FIFO policy this principle is used: always read a pixel value from the memory
before writing in the same cell. To achieve this behavior is used the pixel clock and is inverse
(clk2), in this way the rising edges of the pixel clock are used to read from the memory and
instead, the rising edges of clk2 are used to write into the memory in the same cell of the
reading. A variable is used as a counter that is incremented after each writing and is used to
determine the cell inside the memory for reading/writing phase. Using this approach during the
reading of the first line the output of this module will be Undefined because the memory is not

23
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

initialized, but during the reading of the second line in output there will be the pixel values of the
first line in the same order they entered inside the memory.

Special attention in the code style has been used in order to ensure that XST will use a RAM
Abstract
device already available inside the board, this will lead to a less usage of flip-flops and also to a
better performance. To achieve this result two processes inside the code are created, one for
the reading phase, driven by the pixel clock and one for the writing phase driven by the inverse
of the pixel clock. The frame sync The
andproject
row issync
placedsignals
in the fieldare used Sensor
of Wireless like the enable
Networks. It is and reading/
developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
writing enable signals respectively [3] [4] [5].
complex wireless network structure was designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
In the next picture is depicted the simulation of this module: the img_testbench module
introduction in wireless sensor networks and describes the complete process of development.
described in section 2.1 is used to
Theread an deals
last chapter imagewith afrom the
conclusion andfilesystem and for simulate
covers possible improvements the
and enhancements.
synchronization signals. It is possible to see that during the reading of the first line the output of
the module is Undefined while when the second line is started, the first line starts to come out.

Figure 3.2.7 - fifo_linebuffer Simulation

In the next figure there is a detail of the start of the second line: the signals in the high part of
the image represent the first five cells of the RAM inside the module. As it is possible to see for
each rising edge of the signal clk2 (in red) the values inside the memory change: the old values
are overwritten with the new ones that are taken from the input signal. At the same time in the
output signal are emitted the old values.

March 18, 2011 1 Aart Mulder and Kolja Roese

Figure 3.2.8 - fifo_linubuffer Simulation Detail

As described before, it is necessary to store two lines in order to have all the pixels in the
neighborhood of a given pixel, for this reason another module, called double_fifo_linebuffer is
created combining two instances of the fifo_linebuffer module as shown in Figure 3.2.9. As it is
possible to notice there are three output signals: pdata_out1 is the current line, pdata_out2 is
the previous line and pdata_out3 is the line before the one on pdata_out2.

24
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

double_fifo_linebuffer

pxlclk Abstract pxlclk


fsync fsync
fifo_linebuffer 1 pdata_out fifo_linebuffer 2 pdata_out pdata_out3
rsync 8 rsync 8

pdata_in The project is placed in pdata_in


the field of Wireless Sensor Networks. It is developed to fulfill
8
the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integrationpdata_out2
of multiple
sensor devices. A possible application is the observation of temperature in several server
pdata_out1
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
The last chapter deals with a conclusion and covers possible improvements and enhancements.

Figure 3.2.9 - double_fifo_linebuffer Internal Structure

As expected the simulation of this module shows that the pdata_out1 signal copy the input
signal while pdata_out2 and pdata_out3 signals are Undefined respectively for the first and for
the second line.

Figure 3.2.10 - double_fifo_linebuffer Simulation

March 18, 2011 1 Aart Mulder and Kolja Roese

Figure 3.2.11 - double_fifo_linebuffer Simulation Detail

Pixel Elements

This part is designed using three variables called cache1, cache2 and cache3. Each of them
are logically divided into three parts as shown in Figure 3.2.12. Each of those parts is 8 pixels
wide and have the responsibility to hold one pixel value. The three outputs of the
double_fifo_linebuffer module are “connected” with the high part (23-16) of the variables and in
particular: pdata_out1 is connected with cache1, pdata_out2 with cache2 and pdata_out3 with
cache3 as shown in Figure 3.2.5.

25
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

cache1 z9 z8 z7

23 16 15 8 7 0

Abstract
cache2 z6 z5 z4

23 The16project
15 is placed in the field of
8 Wireless
7 Sensor Networks. 0 It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
cache3 z3 systems with hard diskz2storage in order to maintain z1
the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
23 The16 15
last chapter 8 and
deals with a conclusion 7 covers possible improvements
0 and enhancements.

Figure 3.2.12 - Logical Division Of Pixel Elements Variables

For each rising edge of the pixel clock the pixels inside the variables are shifted from the high
part (23-16) to the low part (7-0) and after that they will lost. This mechanism is the
implementation of the structure depicted in Figure 3.2.4.

Rows and Columns Counter

As described in section 2.2.2 the pixels that lie out of the image boundaries are assumed to be
black, so it is important to detect the various positions in which the kernel will stay as shown in
Figure 3.2.3, because for the positions close to the boundaries the module must emit black
pixels. The easiest way to detect those positions is to count the rows and columns during the
display time, so, a generic counter, was designed, with active low reset and then instantiated
two times: one counter is used to count the rows and the other is used to count the columns
(pixels inside one row). The counter for the rows has to count the rising edges of the rsync
signal so this counter takes as clock the rsync signal. This counter is reseted when the signal
fsync goes low because this means that a frame was displayed and will start a new one so the
counter for the rows should restart from 0. Instead the counter for the columns has to count the
rising edges of the pixel clock only when the rsync signal is high because this means that the
monitor is displaying a certain row, so this counter uses as clock, the pixel clock and as enable
the rsync signal. The counter for the columns is reseted when the signal rsync goes low
because this means that a row was displayed and a new one will start, so the columns counter
should restart from 0.
March 18, 2011 1 Aart Mulder and Kolja Roese

fsync_temp en
fsync_temp reset Counter out RowsCounterOut
10
rsync_temp clk

Figure 3.2.13 - Rows Counter Connections

26
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

rsync_temp en
rsync_temp reset Counter out ColsCounterOut
10
pxlclk clk
Abstract
Figure 3.2.14 - Columns
The project is placedCounter
in the fieldConnections
of Wireless Sensor
Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
The outputs of these two counterscomplex are usedwirelessinside
network structure
a process was designed with the flexible
to understand integration
where theof Sobel
multiple
sensor devices. A possible application is the observation of temperature in several server
kernel is positioned, in this way it issystems
possible
with hardtodisk
emit the
storage rightto maintain
in order pixel values taken
the reliability. fromcontains
The report the three
a short
cache variables or using the constant value of zero that represent the color black.
introduction in wireless sensor networks and describes the complete process of development.
The last chapter deals with a conclusion and covers possible improvements and enhancements.

One thing should be notice: the signals used as input to the counters (fsync_temp and
rsync_temp) are the signals properly delayed by the sync_signals_delayer and not the original
synchronization signals. This because the Sobel kernel starts “to move” only after the first line of
the original image.

Synchronization Signals Delayer Module

pxlclk
fsync_out
fsync_in sync_signals_delayer
rsync_in rsync_out

Figure 3.2.15 - sync_signals_delayer Module

This is the module responsible of delaying the synchronization signals of one line and two pixels
in order to ensure that the memories are filled with the appropriate pixel values. The design was
divided into five phases:
1. delay the row sync signal of two pixels (two clock cycles), this signal will called rsync2;
2. count the rising edges of the signal rsync2 using an instance of the previous counter.
The output of the counter will put in a signal called rowsDelayCounterRising;
3. when the signal rowsDelayCounterRising
March 18, 2011 assume the value
1 2, theAart
output
Mulderframe
and Koljasync
Roese
signal will go high;
4. count the falling edges of the signal rsync2 and put the value of the counting in the
signal rowsDelayCounterFalling;
5. when the signal rowsDelayCounterFalling assume the value 0, the output frame sync
signal will go low.
In the following figures is depicted the simulation of this module (in red the delayed signals).
The figures show that the fsync_out signal goes high after the reading of the first line and
exactly after two clock cycles, and it goes low in late of one line respect to the original signal.
The row sync signal is synchronized with the frame sync signal and delayed of two clock cycles.

27
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

Abstract

The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
Figure 3.2.16 - sync_signal_delayer Simulation
complex wireless network structure Start with
was designed Image the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
The last chapter deals with a conclusion and covers possible improvements and enhancements.

Figure 3.2.17 - sync_signal_delayer Simulation Start Image Detail

Figure 3.2.18 - sync_signal_delayer Simulation End Image

March 18, 2011 1 Aart Mulder and Kolja Roese

Figure 3.2.19 - sync_signal_delayer Simulation Detail (between two lines)

Simulation

In this subsection is reported the simulation of the entire cache_system module. The Figure
3.2.20 depicts the start of the image, in other words when the Sobel kernel is in the position
number 1 (Figure 3.2.3), as it is possible to see the pixels z1, z2, z3, z4, and z7 are black (0)
because they lie outside the original image (the only pixels from the original image are z5, z6,

28
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

z8 and z9). Instead in Figure 3.2.21 is reported the position number 3: in this case the pixels
that are outside the image are z1, z2, z3, z6 and z9, indeed they are black.

Abstract

The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
The last chapter deals with a conclusion and covers possible improvements and enhancements.

Figure 3.2.20 - cache_system Simulation position 1

March 18, 2011 1 Aart Mulder and Kolja Roese

Figure 3.2.21 - cache_system Simulation position 3

29
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

3.2.2 Sobel Kernel Module

pxlclk
fsync_in Abstract
rsync_in

data_in1The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
8
the requirement of environmental monitoring with the focus on temperature observation. A
data_in2complex wireless network structure was designed with the flexible integration of multiple
8
sensor devices. A possible application is the observation of temperature in several server
data_in3systems with hard disk storage in order to maintain the reliability. The report contains a short
8 data_out
introduction in wireless sensor networks and describes the complete
8 process of development.
data_in4The last chapter
sobel_kernel fsync_out
deals with a conclusion and covers possible improvements and enhancements.
8
rsync_out
data_in5
8
data_in6
8
data_in7
8
data_in8
8
data_in9
8

Figure 3.2.22 - sobel_kernel Module

The next step was to design the module responsible of the computation of the approximation of
the gradient, in every pixel of the image, using the Sobel operators. The module is implemented
using a process: into two variables are stored the horizontal and vertical magnitude using the
Sobel kernel (the coefficient 2 in the mask is obtained shifting to the left of one position the pixel
value), if the resulting numbers are negative they are converted into positive with a complement
operation (not number + 1), the 11th bit is used to understand if a number is negative or not.
Then the two magnitudes are combined together as described in section 2.2.2 (Eq. 2). At the
end a threshold of 127 is applied: if the value is higher than the threshold the output will be
withe (255), otherwise only the least 8 bits are taken and put in output.

In the following figure is reported the simulation of the module: in red is depicted the output
signal that change when the input signals change, in the example when all the inputs are zero
the output is zero (the same if the inputs are
March 18, 2011255). Instead when some
1 of theAart
pixel areand
Mulder black and
Kolja Roese
some are white the output is white because the value of the magnitude is above the threshold.

Figure 3.2.23 - sobel_kernel Simulation

30
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

3.2.3 Simulation

In this section is tested the edge_sobel_wrapper module using the img_testbench with different
test images reported below. The first image have a withe background and three shapes with 1
Abstract
pixel lines thick: the white background is chosen to test the response of the module along the
borders of the image, indeed the expectation is to obtain an image with black background and
with white borders, this depends to the fact that the pixels that lie outside the image boundaries
are assumed to be black. In the second image
The project instead
is placed in the the borders
field of of theNetworks.
Wireless Sensor resulting
It is image
developedwill be
to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
of different colors because the background of the image is not perfectly black but there are
complex wireless network structure was designed with the flexible integration of multiple
many pixels with different values (like noise).
sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
The last chapter deals with a conclusion and covers possible improvements and enhancements.

Figure 3.2.24 - Test Image 1 and Resulting Image

March 18, 2011 1 Aart Mulder and Kolja Roese

Figure 3.2.25 - Test Image 2 and Resulting Image

31
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

Abstract

The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
Figure 3.2.26
The last-chapter
Resulting Image
deals with 1 Waveform
a conclusion and covers possible improvements and enhancements.

Figure 3.2.27 - Resulting Image 1 Waveform Detail

The previous two figures depict the signals of the edge_sobel_wrapper during the simulation.
From the Figure 3.2.26 it is possible to notice that the entire first line is white and from the
Figure 3.2.27 it is possible to see that each line ends and starts with a white pixel.

3.3 Number Displayer Module


pxlclk
data_in data_out
8 8
fsync_in number_displayer fsync_out
rsync_in rsync_out
pos_row pos_col meters decimeters centimeters
March 18, 2011 1 Aart Mulder and Kolja Roese
10 10 4 4 4
255 255

Figure 3.3.1 - number_displayer Module

In Figure 3.29 is depicted the number_displayer module. This module is responsible to take the
video signals that come from the Sobel Edge Detection module and display three decimal
numbers at a certain position. For achieve this aim the module takes 9 inputs:
1. pxlclk: is the pixel clock used to display one pixel.
2. data_in: this signal has a width of 8 bits and represents the value of each pixel in gray
scale. With 8 bits is possible to represent 256 different gray values.
3. fsync_in: frame synchronization signal.

32
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

4. rsync_in: row synchronization signal.


5. pos_row - pos_col: these signals represent the position in the screen where the
three numbers should be displayed. Ten bits are used because the target monitor for
the project has a resolution of 640x480 so at least 10 bits are necessary to cover all
Abstract
possible locations. In Figure 3.2 the values for the position are fixed (255, 255) but it is
possible to change it inside the design.
6. meters - decimeters - centimeters: these signals represent the three decimal
numbers that should be displayed
The project is on the
placed screen.
in the Four Sensor
field of Wireless bits are usedIt because
Networks. is developed toeach
fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
digit is encoded in BCD. Between thenetwork
complex wireless meters digitwasand
structure the with
designed decimeters digit a decimal
the flexible integration of multiple
dot will be displayed. sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
The outputs of this module are theThesynchronization
last chapter deals with asignals (that
conclusion and remain
covers unchanged
possible improvements from the
and enhancements.
inputs) and the value of each pixel that will be changed in correspondence of the position where
the numbers should be displayed. The pixel values in the others positions will remain
unchanged from the inputs.

3.3.1 Numbers ROM

One of the main problems encountered during the development of this module is about how to
display numbers on the screen since the only informations available are the values of the single
pixels. This problem was solved implementing a ROM memory where, for each number in the
range 0 - 9 and for the decimal dot, stores the values of the pixels that have to be displayed in
order to create the shape of the different numbers. The ROM module is depicted in Figure 3.3.

en
rd num_rom data_out
8
address
7

Figure 3.3.2 - num_rom Module

The ROM is a combinational module: when the input signals en and rd are high the output is the
value present in the location specified from the address signal, otherwise if en and rd are low
the output signal is in high impedance.

An example of one number stored insideMarch 18,the


2011memory is depicted 1in Figure 3.31. As it and
Aart Mulder is possible
Kolja Roese

to see the address is conceptually divided into two parts:


1. from bit 6 to bit 3: this part identifies the number (in BCD notation) that has to be
displayed. For example for the number 4 this part of the address is equal to 0100 for
all addresses, instead for the number 1 this part is equal to 0001.
2. from bit 2 to bit 0: these bits represent the rows that contains the values that define
the number. This part of the address is composed by the numbers from 0 (000) to 7
(111). Three bits in this case are used so each number will have an height of 8 pixels.
This structure makes easy to build the address for a given number because it is just necessary
to concatenate the number to display with an index that is incremented of one unit after each
line.

33
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

Addresses Output

Abstract

The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
The last chapter deals with a conclusion and covers possible improvements and enhancements.

Figure 3.3.3 - Example of numbers in num_rom

How it is possible to see Figure 3.31 for each address, the memory will provide as output 8 bits
that represent one line of a certain number: those 8 bits can not be displayed immediately on
the screen. Indeed each bit from the output of the ROM must be extended to 8 bits and then in
correspondence of each rising edge of the pixel clock these 8 bits must be displayed. The effect
of this procedure is that the numbers will be displayed in white on a black background because
looking at the Figure 3.4 it is possible to understand that the bits with the value of 0 will
generate black pixels (0 = 00000000), instead the bits with the value of 1 will generate white
pixels (255 = 111111111)."

For display the numbers at the exact specified position the value for each pixel that should be
displayed has to be ready before the respective rising edge of the pixel clock. Therefore using a
March 18, 2011 1
combinational ROM it is necessary to start to emit the address for the Aart
ROM Mulder and Kolja Roese
one pixel in
advance. For example if we want to display the numbers in position (255, 255) the address for
the first line will be emitted when the position (255, 254) is detected, in this way during that
period of the clock the ROM will put as outputs the values for the pixels in the position (255,
255) and also for the pixels in the next 7 columns. In Figure 3.5 are depicted the waveforms of
the signals when a number is displayed. It is possible to see (red circle) that using a
combinational ROM when an address is provided the value of the pixel (data_out) will be
available inside the same clock cycle.

34
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

253 254 255 256 257 258 259 260


pixel clock

rows count Abstract 255

cols count 252 253 The254


project is255 256
placed in the 257 Sensor
field of Wireless 258Networks. 259It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
address 0001000
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
The last chapter deals with a conclusion and covers possible improvements and enhancements.
data_out 00000000 11111111 00000000

Figure 3.3.4 - Combinational ROM waveforms

Using a synchronous ROM it is still possible to print a number at the exact specified position but
in this case the address must be emitted two times in advance. For example if we want to
display the numbers at (255, 255), the address for the first line must be emitted when the
location (255, 253) is detected. This happens because this kind of memory accepts the address
in correspondence of the rising edge of the clock and provides the output a short time later this
edge. It is possible to see the waveforms for this case in Figure 3.33.

253 254 255 256 257 258 259 260

pixel clock

rows count 255

cols count 252 253 254 255 256 257 258 259

address 0001000

March 18, 2011 1 Aart Mulder and Kolja Roese


data_out 00000000 11111111 00000000

Figure 3.3.5 - Synchronous ROM waveforms

It was choose to use a combinational ROM rather than a synchronous one because using the
latter kind of memory will lead to a more complex design instead of using the combinational
memory.

The drawback of this choice is that is not possible to start the printing of a number in the pixel 0
of each row because in this case it is impossible to detect the previous pixel. Moreover is not
possible to print the numbers in a position too close to the right side of the screen because we

35
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

have to consider the space necessary to display all the numbers 8 pixels * 4 digits = 32 pixels
(Figure 3.34).

3.3.2 Code Description


Abstract
To count the lines and the pixels displayed are used two counters with the same configuration
shown in figure 3.14 and 3.15.
The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
For detect the position on the screen where the numbers should be displayed is used a process
complex wireless network structure was designed with the flexible integration of multiple
and several if...elsif statements. sensorIn the sensitivity
devices. list ofisthe
A possible application process ofthere
the observation are the
temperature signals
in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
that come out from the counters for the rows and for the columns, in this way the process is
introduction in wireless sensor networks and describes the complete process of development.
executed every time that the monitorTheislast
displaying a new
chapter deals with row or
a conclusion andacovers
newpossible
pixel.improvements and enhancements.

Given a certain position in terms of row and column (that from now we will call pos_row and
pos_col respectively) these coordinates represent the position of the pixel in the left top corner
of the first number as depicted in Figure 3.34.

pos_col pos_col + 7 pos_col + 15 pos_col + 23 pos_col + 31

pos_row 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 1 0
0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 1 0 1 1 0 0 0 1 1
0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 1 0 0 0 0 0 0 1 1
0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 1 1 0
0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 1 0
0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 1
0 0 0 0 1 1 0 0 0 0 0 1 1 0 0 0 0 0 1 1 0 0 1 1 0 1 1 0 0 0 1 1
pos_row + 7 0 0 1 1 1 1 1 1 0 0 0 1 1 0 0 0 0 1 1 1 1 1 1 1 0 0 1 1 1 1 1 0

Figure 3.3.6 - Numbers Area

As it is possible to see the other numbers have to follow the first number horizontally. Since the
display is row by row during the display of a certain row should be displayed one line of each
number, this means that the address for the ROM that contains the shape of the numbers must
change when the monitor passes from one number to another. For obtain this result four if
statements are used to distinguish the area of each single digit (numbers and decimal dot) and
inside each if the correct address for the number is generated simply concatenating the
number that should be displayed in that position and the difference between the current row and
March 18, 2011 1 Aart Mulder and Kolja Roese
the row where the user want to print the number. This difference is necessary to create the least
significant part of the address (Figure 3.4) that goes from 0 to 7. Now each bit of the output of
the ROM has to be extended to 8 bits in order to display a valid pixel black or white. For the first
number, to achieve this result is calculated the difference between the current column and the
column where the user want to display the number and the result of this difference is used as
index inside the output of the ROM to indicate which bit has to be extended. For the other
numbers the principle is the same but has to keep in consideration that the following numbers
have a different start and end point inside the screen, so some constants (8, 16, 24) are used to
generate the correct difference (from 0 to 7). The constant -1 is used to achieve the result
explained in the section 3.2.1 about the combinational ROM. The first if statement present in
the process is used to understand if the monitor is displaying the pixels outside the area of the

36
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

numbers and in this case the value of each pixel is left unchanged from the input. In this way
only the area necessary to display the numbers is changed.

3.3.3 Simulation
Abstract
For test the functionality of this module is used the img_testbench module with the following
configuration.
The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
pxlclk complex wireless network structure was designed with the flexible integration of multiple
pxlclk
data_in sensor devices. A possible application
data_out data_inis the observation of temperature in several server
data_out
8
fsync_in number_displayer systems with hard disk storage
fsync_out in order to maintain
fsync_in the reliability.
img_testbench The report contains 8a short
fsync_out
rsync_in introduction in wireless
rsync_out sensor rsync_in
networks and describes the complete process of development.
rsync_out
The
pos_row pos_col meters decimeters last chapter deals with a conclusion and covers possible improvements and enhancements.
centimeters

10 10 4 4 4
60 60 2 7 9

Figure 3.3.7 - number_displayer Test Overview

The outputs of the test bench are connected with the Number Displayer module in order to
display three fixed numbers (2.79) and the outputs of this module are put in the inputs of the
test bench: in this way the image is read, modified and the written on another file.

The result of this test can be see in the following images. The numbers are flipped because in
the img_testbench the image is read in the opposite direction compared to the VGA standard:
from the bottom left corner to top right corner.

Figure 3.3.8 -March 18, 2011


number_displayer 1
Simulation Waveform Aart Mulder and Kolja Roese

From the previous figure is possible to see that when the line 60 and column 59 is reach the
module starts to emit the appropriate addresses for the font ROM (light-blue signals): in this
example initially is emitted the address for the first row of the number 2 (0010000) and then for
the decimal dot (1111000) (an then, for the others two numbers, not displayed here).

37
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

Abstract

The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
The last chapter deals with a conclusion and covers possible improvements and enhancements.

Figure 3.3.9 - Result of the number_displayer Test

3.4 Range Sensor Module

meters
fpgaclk 4
decimeters
range_sensor 4
centimeters
pulse March 18, 2011 1 4 Aart Mulder and Kolja Roese
trigger

Figure 3.4.1 - range_sensor Module

In Figure 3.4.1 is depicted the module that is responsible of the following three tasks:
1. Generate the trigger pulse of the right width necessary to activate the range sensor
and start the distance measure.
2. Measure the width of the echo pulse (from the range sensor) and convert it in a
distance in meters, decimeters and centimeters.
3. Encode the distance in three BCD digits.

38
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

To simplify the work, the design is divided into three different modules, one for each task. The
generic overview and the connections between each module can be seen in the next figure.

Abstract
range_sensor

clk hundreds
4
The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
pulse distance_measurer distance
the requirement of environmental
input bcd_converter tens
monitoring with the focus on temperature observation. A
9 4
complex wireless network structure was designed with the flexible integration unit of multiple
trigger 4 server
sensor devices. A possible application is the observation of temperature in several
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
The last chapter deals with a conclusion and covers possible improvements and enhancements.

clk trigger_generator trigger

Figure 3.4.2 - range_sensor Internal Connections

The trigger_generator uses the fpga clock to generate the trigger signal for the range sensor.
The distance_measurer receive the echo pulse and convert it into a 9 bits number that
represent the distance in centimeters. Finally the bcd_converter encode the distance into three
BCD digits.
The bcd_converter module is explained in detail in the next section.

3.4.1 Trigger Generator

This module has only one input signal, the fpga clock and one output signal, the trigger signal
that has to be connected with the trigger input in the range sensor. The module is essentially
based upon one counter. The counter is used to perceive the passage of the time: when the
time is greater than 250ms the trigger signal is activated and is kept high for 100us. When the
time reach the value of 250ms + 100us the trigger signal is deactivated and the counter is
reseted: in this way a new interval of 250ms is measured and a new pulse of the trigger signal
will be generated.
March 18, 2011 1 Aart Mulder and Kolja Roese

The values of 250ms for the interval between each pulse and 100us for the width of each pulse
are chosen to be sure that the range sensor can work properly without problems and without
any interferences between each trigger pulse. Indeed these timing values are quite greater than
the values specified on the technical documentation as explained in the section 2.3. We made
this choice even because we assumed that the distance between the camera and the object will
not change too much frequently so we can sense this distance with a lower frequency than the
maximum permitted, however if it is necessary is possible to reach this limit changing two
constants in the design.

In the following figure is depicted the waveform of the simulation of this module and is possible
to see that the trigger is activated after 250ms and it remains high for 100us.

39
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

Abstract

The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
Figure 3.4.3 - Trigger
the requirement Generator monitoring
of environmental Simulation
with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
The last chapter deals with a conclusion and covers possible improvements and enhancements.

Figure 3.4.4 - Trigger Generator Simulation Counter Detail

3.4.2 Distance Measurer

This module is responsible to measure the width of the echo pulse generated from the range
sensor and convert it into a distance in centimeters. As explained in the section 2.3 for convert
the width of the pulse in a distance in centimeters we have to measure the width in micro-
seconds and then divide it by 58. Since the fpga clock has a period of 20ns using it we will get a
time in nano-seconds. In fact if X is the number of the clock cycles counted when the echo
pulse is high, to convert this number in a distance in centimeters the expression is the following:

X * 20 X
= = cm
1000 * 58 2900

The number of cycles X is multiplied by 20 and divided by 1000 to convert it into a time in micro-
seconds, after that is possible to apply the standard expression (section 2.3) and divide it by 58.
Making some simplifications we can Marchget the final expression where
18, 2011 1 the number
Aart Mulder of
and counted
Kolja Roese
cycles has to be divided by 2900. Divide the number X by a big number such 2900 is quite
expensive in hardware. In general the division is a complex operation to implement in hardware.
The standard algorithms indeed, leads to an hardware implementation that is expensive in
terms of both propagation delay and hardware resources. For these reasons, in general, we try
to not use the divisions in our designs.

To solve this problem we figured out that the number 8192 = 213 and that 8192 is quite close to
the number 8700 that is equal to 2900 * 3. So the division by 2900 can be approximated by
multiplying X by 3 and then divide it by 8192 that is not perfect because it is not 8700 but is
useful because the division by 8192 can be done simply shifting X to the right of 13 positions.
The new expression is the following:

40
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

3*X 3*X 3*X


= ≈ = cm
3 * 2900 8700 8192

Abstract
To implement this behavior one counter is used to count the clock cycles when the echo pulse is
high. The trigger signal generated from the module explained in the previous section is used to
reset this counter: indeed we know that when the trigger signal goes low a new measure is
started so the counter has to be reseted to count
The project is placedainnew width
the field of theSensor
of Wireless echo pulse.ItAs
Networks. it is possible
is developed to fulfill
the requirement
to see in the following figure the counter of environmental
is reseted when the monitoring
triggerwithsignal
the focusisonhigh.
temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
pulse en
The last chapter deals with a conclusion and covers possible improvements and enhancements.
trigger reset Counter out CounterPulseOut
22
fpgaclk clk

Figure 3.4.5 - Distance Measure Counter Connections

Then a process is used to detect when the echo pulse goes low and to calculate the distance
using the approximation explained before. The distance is a 9 bits number.

In the following picture is reported the simulation of the distance_measurer module. The signals
trigger and pulse are generated manually inside the test bench. It is possible to see that when
the pulse signal goes low the distance is calculated and put as output. The test bench simulates
two different distances.

Figure 3.4.6 - Distance Measurer Simulation

3.4.3 Simulation

In Figure 3.4.7 is depicted the waveform of the simulation of the entire range_sensor module.
The echo pulse is generated manually inside
March 18, 2011 the test bench. As1 it is possible to see
Aart Mulder andafter the
Kolja Roese
echo pulse the distance is put in output encoded in three BCD numbers.

Figure 3.4.7 - Range Sensor Simulation

41
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

3.5 BCD Converter Module


Abstract
hundreds
4
input bcd_converter
The project is placed in the field of Wirelesstens
Sensor Networks. It is developed to fulfill
9 4
the requirement of environmental monitoring with the focus on temperature observation. A
unit
complex wireless network structure was designed with 4the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
Figure
The3.5.1 - BCD
last chapter Converter
deals Module
with a conclusion and covers possible improvements and enhancements.

In this section is described the approach used to implement a module that permits to convert a
binary number into a BCD format. In particular the objective is to convert the 9-bits number that
represent the distance (as explained in the previous section) and convert it into three 4-bits
numbers in BCD notation. This can be easily done dividing the number by 10 for three times
and after each division taking the remainder which represents respectively the units, the tens
and hundreds of the number. After the divisions the number can be represented in BCD simply
converting the units, the tens and the hundreds in BCD. This solution is simple but the main
drawback is due to the fact that it uses the division. As explained in the previous section the
division is an expensive operation and if it is possible it is avoided.

3.5.1 Double-Dabble Algorithm

For implement the binary-BCD conversion without using the division operation the Double-
Dabble algorithm is used. The steps for convert a n-bit binary number are the following:
1. Reserve enough space to hold both the original number and its BCD representation.
This space can be calculated as n + (4n / 3). The reserved space is conceptually
divided into hundreds, tens and units like in Figure 2.5.
2. Shift the binary number left one bit.
3. If n shifts have taken place the BCD number is ready in hundreds, tens and units
places.
4. If the binary value in any of the BCD columns (hundreds, tens, units) is greater than 4,
add 3 to the value in that BCD column.
5. Go to step 2.
March 18, 2011 1 Aart Mulder and Kolja Roese

Figure 3.5.2 - Reserved space in Double-Dabble algorithm

In the Figure below are reported the different phases necessary for convert the number 24310 =
111100112 in BCD.

42
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

Abstract

The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
The last chapter deals with a conclusion and covers possible improvements and enhancements.

Figure 3.5.3 - Double-Dabble algorithm applied to the decimal value 243.

The shifting is the double part of the algorithm because after each shift the values in the BCD
columns become the double of the previous values, this happens first for the units, then for the
tens and finally for the hundreds in the case of a three digits number (0 - 999). If one of the
numbers in the BCD columns is greater than 4 this means that after the next shift the number
will become 10 or more (depends from the value of the bit that enters in the BCD column) and
this means that another ten (or hundreds) should be added to the tens (or hundreds) column.
For do this is sufficient to add 3 to the number, in this way after the next shift the number will
become 16 or greater, so one bit with the value of 1 will pass into the next BCD column and this
represents the fact that a new tens (or hundreds) was detected. This happens because if you
add 3 to a 4-bit number that is greater than 4 (for example 5,6,7,8,9) the resulting number will
have the most significant bit set to 1 so after the next left shift this bit will pass into the next BCD
digit.

This algorithm is a good alternative to the use of the division operation because it uses only shift
and add operations that are faster than the division. Furthermore it is also easy to implement in
VHDL because no particular constructs are necessary.

3.5.2 Code Description

This module is implemented as a combinational module where the three BCD numbers are put
as output only when the 9-bit number Marchin
18,input
2011 changes. For make
1 this possible a process
Aart Mulder that
and Kolja Roese
has the input number in the sensitivity list is used. Inside the process initially is reserved the
space necessary for the algorithm like explained in the step 1: a signal of 21 bits is created and
in the 9 least significant bits is loaded the binary number that represents the distance, the other
bits are initialized to zero. After that using a for...loop the steps from 2 to 5 are
implemented. Inside the for...loop the number is first left shifted and then each part of the
signal that represents a BCD digit is checked if its value is greater than 4 or not: if it is the
number 3 is added to that value like explained in the algorithm. At the end of the for...loop
the signal is divided into the three BCD digits and these parts are put on the output signals
(hundreds, tens and unit). The bits from 20 to 17 represent the hundreds, the bits form 16 to 13
represent the tens and the bits from 12 to 9 represent the units.

43
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

3.5.3 Simulation

In the following figure is depicted the waveform of the simulation of the BCD Converter module.
Three different 9-bit numbers are generated and converted in three BCD digits.
Abstract

The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
The last chapter deals with a conclusion and covers possible improvements and enhancements.

Figure 3.5.4 - BCD Converter Simulation


Digilent
al www.digilentinc.com
3.6 Top VGA Module
Inside the top_vga module the components for the edge detection, for the numbers display and
10 FPGA for signals
the distance
to measure are instantiated and connected following the schema reported in
Figure
8-bit color 3.1.1.
and the twoParticular attention was used to connect the number_displayer module to VGA
HS – Horizontal Sync,as it is possible to see in Figure 3.6.1, the Nexys2 board uses eight signals to
port. Indeed
produce
. The color theuse
signals video color signals for the VGA standard. Three signals are used for both Red and
Green and only two signals are used for Blue, this because the human eye is less sensitive to
hat work in conjunction
blue levels so makes no sense to produce small variations on the blue level that are not visible.
ation resistance of the
ight signal levels on the
nals, and four on blue
sensitive to blue levels).
ure 13, produces video
ed in equal increments
nd 0.7V (fully on). Using
colors can be
unique 8-bit pattern. A
must be created in the March 18, 2011 1 Aart Mulder and Kolja Roese
and color signals with
er to produce a working

specified, published,
the VESA organization
lowing VGA system Figure 16:3.6.1
Figure VGA- pin definitions
Nexys2 and Nexys2
VGA Generation circuit
Circuit
vided as an example of
ht be driven in 640 by 480 mode. For more precise information, or for
A frequencies, refer to documentation available at the VESA website.

ys use amplitude-modulated moving electron beams44(or cathode rays) to


phosphor-coated screen. LCD displays use an array of switches that can
s a small amount of
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

Using eight signals is possible to display 256 different colors, one for each unique 8-bit pattern.
But for the purpose of this project we are interested only in gray scale images, so we have to
keep the three components equal: R = G = B = gray. In this way when the three values are
summed on the screen, it will generate an image with colors from white to black with various
shades of gray in the middle. Abstract
To physically connect the signals inside the design with the right pins on the board a UCF file is
used. This file specifies the mappingThebetween the signals
project is placed in the fieldand the pins.
of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
The entire design was made with intention to implement
sensor devices. the project
A possible application itself on
is the observation a evaluation
of temperature board,
in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
how is stated in the requirements. introduction
For this reason some useful guidelines are used in order to
in wireless sensor networks and describes the complete process of development.
obtain optimal performances in terms
Theoflastspeed andwith
chapter deals area occupation:
a conclusion and covers possible improvements and enhancements.
1. adopt a correct style for the RAM and ROM design to ensure that the FPGA-specific
resources are used;
2. when a process is used all inputs are put into the sensitivity list of the process itself.
This is useful because XST will put automatically all the inputs into the sensitivity list,
so the result obtained in the simulation could be different from the result in real world;
3. inside a process, when it is possible, the output signals are assigned under all
conditions. This will reduce the inference of latches that are responsible of timing
problems.
In the following figure is reported the design summary after the implementation. As it is possible
to see this design is not so large and there are still resources available for other applications if
necessary.

March 18, 2011 1 Aart Mulder and Kolja Roese

Figure 3.6.2 - Design Summary

45
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

3.7 Test
Abstract
After the setup of the hardware the design is synthesized and the BIT file necessary for program
the board is generated.
The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
The result of the project running onthethe boardof is
requirement reportedmonitoring
environmental in the with
following two
the focus on images.
temperature As it isA
observation.
complex wireless network structure was designed with the flexible integration of multiple
possible to see the scene took fromsensor the devices.
camera is processed in order to detect the edges of the
A possible application is the observation of temperature in several server
objects and the three numbers, that represent
systems the
with hard disk distance
storage in order tofrom
maintainthe cameraThetoreport
the reliability. thecontains
object in
a short
introduction
front of it, are displayed in the top left corner.in wireless sensor networks and describes the complete process of development.
The last chapter deals with a conclusion and covers possible improvements and enhancements.

March 18, 2011 1 Aart Mulder and Kolja Roese

Figure 3.7.1 - Project Result on the monitor

46
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

Abstract

The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
The last chapter deals with a conclusion and covers possible improvements and enhancements.

Figure 3.7.2 - Detail of the numbers on the monitor

In the previous image is reported a detail of the numbers displayed. It is possible to see that
with characters of 8 x 8 pixels, the numbers are readable without problems.

March 18, 2011 1 Aart Mulder and Kolja Roese

47
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

Abstract
4 Conclusions and Future Works The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
As shown in the previous section the project
complex is network
wireless completedstructurewith success,
was designed so flexible
with the now integration
it is possible to
of multiple
sensor devices. A possible application is the observation of temperature in several server
use it in applications where is useful to emphasize edges and where the distance from the
systems with hard disk storage in order to maintain the reliability. The report contains a short
camera to the object is relevant. Moreover
introductionthe modular
in wireless structure
sensor networks of thethe
and describes project
completepermits to reuse
process of development.
The last chapter deals with a conclusion and covers possible
the components in other projects, for example the range_sensor module or the bcd_converter improvements and enhancements.

module can be used in many different projects without problems because these modules are
designed to be independent form the whole project. Same reasoning applies to the
number_displayer module that can be easily modified in order to display more numbers or
different informations.

In the other hand there are still some points that could be improved. For example with the
current implementation the number_displayer module can not print the numbers in the first pixel
of each row, this means that is not possible to print the numbers on the borders of the monitor
and this could be a problem for some applications.

Another problem is about the distance measure. Indeed, now the measure is approximated in
order to keep the implementation fast and easy, but some applications can require a very
accurate measure (using precision sensors). So in the future could be a good idea to spend
time to remove the approximation during the measure and keeping, at the same time, the
design fast and easy.

An important thing that should be explored is the possibility to make the design so general that
the modules will adapt automatically to different mask sizes, for example if a mask of 5x5 is
needed.

Finally the test bench used to read/write an image from/into the filesystem can be fixed and
improved in order to respect the VGA signals and timings because this test bench is a useful
tool to test the implementation without using the board and the monitor.

March 18, 2011 1 Aart Mulder and Kolja Roese

48
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

Abstract
References The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
[1] - Get your Priorities Right – Make yourwireless
complex Design Up structure
network to 50%wasSmaller (Ken
designed with theChapman)
flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
http://www.xilinx.com/support/documentation/white_papers/wp275.pdf
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
[2] - The last chapter
Get Smart About Reset: Think Local, deals with (Ken
Not Global a conclusion and covers possible improvements and enhancements.
Chapman)
http://www.xilinx.com/support/documentation/white_papers/wp272.pdf

[3] - Synthesis and Simulation Design Guide


http://www.xilinx.com/support/documentation/sw_manuals/xilinx13_1/sim.pdf

[4] - XST User Guide


http://www.xilinx.com/itp/xilinx10/books/docs/xst/xst.pdf

[5] - XST User Guide for Virtex-4, Virtex-5, Spartan-3, and Newer CPLD Devices
http://www.xilinx.com/support/documentation/sw_manuals/xilinx13_1/xst.pdf

[6] - ISim User Guide


http://www.xilinx.com/support/documentation/sw_manuals/xilinx13_1/plugin_ism.pdf

[7] - Digilent Nexys2 Board Reference Manual


http://www.digilentinc.com/Data/Products/NEXYS2/Nexys2_rm.pdf

March 18, 2011 1 Aart Mulder and Kolja Roese

49
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

Abstract
Appendix The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A

Appendix A - counter.vhd complex wireless network structure was designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
library IEEE;
The last chapter deals with a conclusion and covers possible improvements and enhancements.
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity Counter is
generic(n : POSITIVE := 10);
Port ( clk : in STD_LOGIC;
en : in STD_LOGIC;
reset : in STD_LOGIC; -- Active Low
output : out STD_LOGIC_VECTOR(n-1 downto 0) );
end Counter;

architecture Behavioral of Counter is


signal num : STD_LOGIC_VECTOR(n-1 downto 0);

begin
process (clk, reset)

begin
if(reset = '0') then
num <= (others => '0');
elsif(clk'event and clk = '1') then
if (en = '1') then
num <= num + 1;
end if;
end if;
end process;

output <= num;

end Behavioral;

Appendix B - fifo_linebuffer.vhd
March 18, 2011 1 Aart Mulder and Kolja Roese

PACKAGE TYPES IS
subtype SMALL_INTEGER is INTEGER range 0 to 639;
END PACKAGE;

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use WORK.TYPES.all;

entity FIFOLineBuffer is
generic (
DATA_WIDTH : integer := 8;

50
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

NO_OF_COLS : integer := 640 );


port(
clk : in std_logic;
fsync : in std_logic;
rsync : in std_logic;
pdata_in
pdata_out
Abstract
: in std_logic_vector(DATA_WIDTH -1 downto 0);
: buffer std_logic_vector(DATA_WIDTH -1 downto 0) );
end FIFOLineBuffer;

architecture Behavioral of FIFOLineBuffer is


The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless-network
type ram_type is array (NO_OF_COLS 1 downtostructure0)
wasofdesigned with the flexible integration of multiple
std_logic_vector(DATA_WIDTH
sensor devices. A possible application is the observation of temperature in several server
-1 downto 0);
systems with hard disk storage in order to maintain the reliability. The report contains a short
signal ram_array : ram_type; -- := (others => "00000000");
introduction in wireless sensor networks and describes the complete process of development.
signal clk2 : std_logic; The last chapter deals with a conclusion and covers possible improvements and enhancements.
signal ColsCounter : SMALL_INTEGER := 0;

begin
clk2<=not clk;

--NB: putting the two IF about fsync and rsync inside the clk and clk2 IFs
-- will lead to an automatic inference of a RAM

-- reading from the memory


p : process(clk)
begin
if clk'event and clk='1' then
if fsync = '1' then
if rsync = '1' then
pdata_out <= ram_array(ColsCounter);
end if;
end if;
end if; -- clk
end process;

-- writing into the memory


p2 : process (clk2)
begin
if clk2'event and clk2='1' then
if fsync = '1' then
if rsync = '1' then
ram_array(ColsCounter) <= pdata_in;

if ColsCounter < 639 then


ColsCounter <= ColsCounter+1;
else
ColsCounter
March 18, 2011 <= 0; 1 Aart Mulder and Kolja Roese
end if;
else
ColsCounter <= 0;
end if; -- rsync
end if; -- fsync
end if; -- clk2
end process p2;

end Behavioral;

Appendix C - double_fifo_linebuffer.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

51
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

entity DoubleFiFOLineBuffer is
generic (
DATA_WIDTH : integer := 8;
NO_OF_COLS : integer := 640 );
port(
clk : in std_logic;
Abstract
fsync : in std_logic;
rsync : in std_logic;
pdata_in : in std_logic_vector(DATA_WIDTH -1 Sensor
The project is placed in the field of Wireless downto 0); It is developed to fulfill
Networks.
pdata_out1 : out std_logic_vector(DATA_WIDTH
the requirement of environmental monitoring-1 withdownto
the focus on 0);
temperature observation. A
complex wireless network structure was
pdata_out2 : buffer std_logic_vector(DATA_WIDTH -1 downto 0); designed with the flexible integration of multiple
pdata_out3 : buffersensor devices. A possible application is the observation of temperature in several server
std_logic_vector(DATA_WIDTH -1 downto 0) );
systems with hard disk storage in order to maintain the reliability. The report contains a short
end DoubleFiFOLineBuffer; introduction in wireless sensor networks and describes the complete process of development.
The last chapter deals with a conclusion and covers possible improvements and enhancements.
architecture Behavioral of DoubleFiFOLineBuffer is

component FIFOLineBuffer is
generic (
DATA_WIDTH : integer := 8;
NO_OF_COLS : integer := 640 );
port(
clk : in std_logic;
fsync : in std_logic;
rsync : in std_logic;
pdata_in : in std_logic_vector(DATA_WIDTH -1 downto 0);
pdata_out : buffer std_logic_vector(DATA_WIDTH -1 downto 0));
end component;

begin

LineBuffer1 : FIFOLineBuffer
generic map (DATA_WIDTH => DATA_WIDTH, NO_OF_COLS => NO_OF_COLS)
port map(clk, fsync, rsync,pdata_in, pdata_out2);

LineBuffer2 : FIFOLineBuffer
generic map (DATA_WIDTH => DATA_WIDTH, NO_OF_COLS => NO_OF_COLS)
port map(clk, fsync, rsync, pdata_out2, pdata_out3);

pdata_out1 <= pdata_in;

end Behavioral;

Appendix D - sync_signals_delayer.vhd
library IEEE; March 18, 2011 1 Aart Mulder and Kolja Roese
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity SyncSignalsDelayer is
generic (
ROW_BITS : integer := 9 );
port(
clk : in std_logic;
fsync_in : in std_logic;
rsync_in : in std_logic;
fsync_out : out std_logic;
rsync_out : out std_logic );
end SyncSignalsDelayer;

52
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

architecture Behavioral of SyncSignalsDelayer is

signal rowsDelayCounterRising, rowsDelayCounterFalling : std_logic_vector


(ROW_BITS - 1 downto 0);
signal rsync2, rsync1, fsync_temp : std_logic;

COMPONENT Counter is
Abstract
generic (n : POSITIVE);
Port ( clk : in STD_LOGIC;
en : in STD_LOGIC;
The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
reset the
: requirement
in STD_LOGIC; --onActive
of environmental monitoring with the focus temperatureLowobservation. A
complex wireless network structure was
output : out STD_LOGIC_VECTOR(n-1 downto 0)); designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
end COMPONENT;
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
begin The last chapter deals with a conclusion and covers possible improvements and enhancements.

-- Step 2
RowsCounteComp : Counter generic map(ROW_BITS)
port map(rsync2, fsync_in,fsync_in,rowsDelayCounterRising);
rsync_out <= rsync2;
fsync_out <= fsync_temp;

-- Step 1
p1 : process(clk)
begin
if clk'event and clk='1' then
-- Step 1 - delay of two clock cycles
rsync2 <= rsync1;
rsync1 <= rsync_in;
end if;
end process p1;

-- Steps 3 and 5
p2 : process(rowsDelayCounterRising, rowsDelayCounterFalling)
begin
-- rows2 = 2
if rowsDelayCounterRising = "000000010" then
fsync_temp <= '1';
elsif rowsDelayCounterFalling = "000000000" then
fsync_temp <= '0';
end if;
end process p2;

-- Step 4
p3 : process(rsync2)
begin
if rsync2'event and rsync2March
= '0' then
18, 2011 1 Aart Mulder and Kolja Roese
if fsync_temp = '1' then
-- 479
if rowsDelayCounterFalling < "111011111" then
rowsDelayCounterFalling <= rowsDelayCounterFalling + 1;
else
rowsDelayCounterFalling <= "000000000";
end if;
else
rowsDelayCounterFalling <= "000000000";
end if;
end if;
end process p3;

end Behavioral;

53
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

Appendix E - cache_system.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
Abstract
entity CacheSystem is
generic (
DATA_WIDTH : integer :=
The8; project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
WINDOW_SIZE : integer := 3;
ROW_BITS : integer := 9; the requirement of environmental monitoring with the focus on temperature observation. A
COL_BITS : integer := 10; complex wireless network structure was designed with the flexible integration of multiple
NO_OF_ROWS : integer := 480;devices. A possible application is the observation of temperature in several server
sensor
NO_OF_COLS : integer := 640 );
systems with hard disk storage in order to maintain the reliability. The report contains a short
port(
clk introduction
: in std_logic; in wireless sensor networks and describes the complete process of development.
fsync_in : in std_logic; The last chapter deals with a conclusion and covers possible improvements and enhancements.
rsync_in : in std_logic;
pdata_in : in std_logic_vector(DATA_WIDTH -1 downto 0);
fsync_out : out std_logic;
rsync_out : out std_logic;
pdata_out1 : out std_logic_vector(DATA_WIDTH -1 downto 0);
pdata_out2 : out std_logic_vector(DATA_WIDTH -1 downto 0);
pdata_out3 : out std_logic_vector(DATA_WIDTH -1 downto 0);
pdata_out4 : out std_logic_vector(DATA_WIDTH -1 downto 0);
pdata_out5 : out std_logic_vector(DATA_WIDTH -1 downto 0);
pdata_out6 : out std_logic_vector(DATA_WIDTH -1 downto 0);
pdata_out7 : out std_logic_vector(DATA_WIDTH -1 downto 0);
pdata_out8 : out std_logic_vector(DATA_WIDTH -1 downto 0);
pdata_out9 : out std_logic_vector(DATA_WIDTH -1 downto 0) );
end CacheSystem;

architecture CacheSystem of CacheSystem is

COMPONENT Counter is
generic (n : POSITIVE);
port ( clk : in STD_LOGIC;
en : in STD_LOGIC;
reset : in STD_LOGIC; -- Active Low
output : out STD_LOGIC_VECTOR(n-1 downto 0));
end COMPONENT;

COMPONENT DoubleFiFOLineBuffer is
generic (
DATA_WIDTH : integer := 8;
NO_OF_COLS : integer := 640 );
port(
clk : in std_logic;
fsync : in std_logic;
rsync : in std_logic;
pdata_in : in std_logic_vector(DATA_WIDTH -1 downto 0);
pdata_out1 : out std_logic_vector(DATA_WIDTH -1 downto 0);
pdata_out2 : buffer std_logic_vector(DATA_WIDTH -1 downto 0);
pdata_out3 : buffer std_logic_vector(DATA_WIDTH -1 downto 0) );
end COMPONENT;

COMPONENT SyncSignalsDelayer
generic (
ROW_BITS : integer := 9 );
port(
clk : IN std_logic;March 18, 2011 1 Aart Mulder and Kolja Roese
fsync_in : IN std_logic;
rsync_in : IN std_logic;
fsync_out : OUT std_logic;
rsync_out : OUT std_logic);
end COMPONENT;

signal RowsCounterOut : STD_LOGIC_VECTOR(ROW_BITS-1 downto 0);


signal ColsCounterOut : STD_LOGIC_VECTOR(COL_BITS-1 downto 0);
signal dout1 : std_logic_vector(DATA_WIDTH -1 downto 0);
signal dout2 : std_logic_vector(DATA_WIDTH -1 downto 0);
signal dout3 : std_logic_vector(DATA_WIDTH -1 downto 0);
signal fsync_temp, rsync_temp : std_logic;

-- pixel elements caches


-- |----------------------------------|
-- | z9-z6-z3 | z8-z5-z2 | z7-z4-z1 |
-- |----------------------------------|
-- 23 16|15 8|7 0
shared variable cache1 : std_logic_vector((WINDOW_SIZE*DATA_WIDTH) -1 downto 0);
shared variable cache2 : std_logic_vector((WINDOW_SIZE*DATA_WIDTH) -1 downto 0);

54
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

shared variable cache3 : std_logic_vector((WINDOW_SIZE*DATA_WIDTH) -1 downto 0);

begin

DoubleLineBuffer: DoubleFiFOLineBuffer
GENERIC MAP (
DATA_WIDTH => DATA_WIDTH,
NO_OF_COLS => NO_OF_COLS )
PORT MAP ( Abstract
clk => clk,
fsync => fsync_in,
rsync => rsync_in,
pdata_in => pdata_in,
pdata_out1 => dout1,
The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
pdata_out2 => dout2, the requirement of environmental monitoring with the focus on temperature observation. A
pdata_out3 => dout3 ); complex wireless network structure was designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
Delayer: SyncSignalsDelayer
systems with hard disk storage in order to maintain the reliability. The report contains a short
GENERIC MAP (
ROW_BITS => ROW_BITS ) introduction in wireless sensor networks and describes the complete process of development.
PORT MAP ( The last chapter deals with a conclusion and covers possible improvements and enhancements.
clk => clk,
fsync_in => fsync_in,
rsync_in => rsync_in,
fsync_out => fsync_temp,
rsync_out => rsync_temp);

RowsCounter : Counter generic map(9) port map(rsync_temp, fsync_temp,fsync_temp,RowsCounterOut);


ColsCounter : Counter generic map(10) port map(clk, rsync_temp,rsync_temp,ColsCounterOut);

fsync_out <= fsync_temp;


rsync_out <= rsync_temp;

ShiftingProcess : process (clk)


begin
if clk'event and clk='1' then
-- the pixel in the middle part is copied into the low part
cache1(DATA_WIDTH -1 downto 0):=cache1(((WINDOW_SIZE-1)*DATA_WIDTH - 1) downto
((WINDOW_SIZE-2)*DATA_WIDTH) );
cache2(DATA_WIDTH -1 downto 0):=cache2(((WINDOW_SIZE-1)*DATA_WIDTH - 1) downto
((WINDOW_SIZE-2)*DATA_WIDTH) );
cache3(DATA_WIDTH -1 downto 0):=cache3(((WINDOW_SIZE-1)*DATA_WIDTH - 1) downto
((WINDOW_SIZE-2)*DATA_WIDTH) );
-- the pixel in the high part is copied into the middle part
cache1(((WINDOW_SIZE-1)*DATA_WIDTH - 1) downto ((WINDOW_SIZE-2)*DATA_WIDTH) ):=cache1
((WINDOW_SIZE*DATA_WIDTH) -1 downto ((WINDOW_SIZE-1)*DATA_WIDTH) );
cache2(((WINDOW_SIZE-1)*DATA_WIDTH - 1) downto ((WINDOW_SIZE-2)*DATA_WIDTH) ):=cache2
((WINDOW_SIZE*DATA_WIDTH) -1 downto ((WINDOW_SIZE-1)*DATA_WIDTH) );
cache3(((WINDOW_SIZE-1)*DATA_WIDTH - 1) downto ((WINDOW_SIZE-2)*DATA_WIDTH) ):=cache3
((WINDOW_SIZE*DATA_WIDTH) -1 downto ((WINDOW_SIZE-1)*DATA_WIDTH) );
-- the output of the ram is put in the high part of the variable
cache1((WINDOW_SIZE*DATA_WIDTH) -1 downto ((WINDOW_SIZE-1)*DATA_WIDTH) ):=dout1;
cache2((WINDOW_SIZE*DATA_WIDTH) -1 downto ((WINDOW_SIZE-1)*DATA_WIDTH) ):=dout2;
cache3((WINDOW_SIZE*DATA_WIDTH) -1 downto ((WINDOW_SIZE-1)
*DATA_WIDTH) ):=dout3;
end if; -- clk
end process ShiftingProcess;

EmittingProcess : process (RowsCounterOut,ColsCounterOut,fsync_temp)


begin
if fsync_temp = '1' then

if RowsCounterOut="000000000" and ColsCounterOut="0000000000" then --1


pdata_out1<= (others => '0');
pdata_out2<= (othersMarch 18, 2011
=> '0'); 1 Aart Mulder and Kolja Roese
pdata_out3<= (others => '0');
pdata_out4<= (others => '0');
pdata_out5<= cache2(((WINDOW_SIZE-1)*DATA_WIDTH - 1) downto ((WINDOW_SIZE-2)*DATA_WIDTH) );
pdata_out6<= cache2(((WINDOW_SIZE)*DATA_WIDTH - 1) downto ((WINDOW_SIZE-1)*DATA_WIDTH) );
pdata_out7<= (others => '0');
pdata_out8<= cache1(((WINDOW_SIZE-1)*DATA_WIDTH - 1) downto ((WINDOW_SIZE-2)*DATA_WIDTH) );
pdata_out9<= cache1(((WINDOW_SIZE)*DATA_WIDTH - 1) downto ((WINDOW_SIZE-1)*DATA_WIDTH) );

-- counter2>0 and counter2<639 (2)


elsif RowsCounterOut="000000000" and ColsCounterOut>"0000000000" and ColsCounterOut<"1001111111" then
pdata_out1<= (others => '0');
pdata_out2<= (others => '0');
pdata_out3<= (others => '0');
pdata_out4<= cache2((DATA_WIDTH - 1) downto 0 );
pdata_out5<= cache2(((WINDOW_SIZE-1)*DATA_WIDTH - 1) downto DATA_WIDTH );
pdata_out6<= cache2(((WINDOW_SIZE)*DATA_WIDTH - 1) downto ((WINDOW_SIZE-1)*DATA_WIDTH) );
pdata_out7<= cache1((DATA_WIDTH - 1) downto 0 );
pdata_out8<= cache1(((WINDOW_SIZE-1)*DATA_WIDTH - 1) downto DATA_WIDTH );
pdata_out9<= cache1(((WINDOW_SIZE)*DATA_WIDTH - 1) downto ((WINDOW_SIZE-1)*DATA_WIDTH) );

55
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

-- counter2=639
elsif RowsCounterOut="000000000" and ColsCounterOut="1001111111" then --3
pdata_out1<= (others => '0');
pdata_out2<= (others => '0');
pdata_out3<= (others => '0');
pdata_out4<= cache2((DATA_WIDTH - 1) downto 0 );
Abstract
pdata_out5<= cache2(((WINDOW_SIZE-1)*DATA_WIDTH - 1) downto DATA_WIDTH );
pdata_out6<= (others => '0');
pdata_out7<= cache1((DATA_WIDTH - 1) downto 0 );
pdata_out8<= cache1(((WINDOW_SIZE-1)*DATA_WIDTH - 1) downto DATA_WIDTH );
pdata_out9<= (others => '0');

-- row>0 and row<479 (4)


The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement
elsif RowsCounterOut>"000000000" of environmental monitoring and
and RowsCounterOut<"111011111" with ColsCounterOut="0000000000"
the focus on temperature observation.
then A
pdata_out1<= (otherscomplex
=> '0');wireless network structure was designed with the flexible integration of multiple
pdata_out2<= cache3(((WINDOW_SIZE-1)*DATA_WIDTH - 1) is
sensor devices. A possible application downto DATA_WIDTH
the observation of );
temperature in several server
pdata_out3<= cache3(((WINDOW_SIZE)*DATA_WIDTH - 1) downto ((WINDOW_SIZE-1)*DATA_WIDTH) );
systems with hard disk storage in order to maintain the reliability. The report contains a short
pdata_out4<= (others => '0');
introduction in wireless sensor networks
pdata_out5<= cache2(((WINDOW_SIZE-1)*DATA_WIDTH and describes
- 1) downto the complete
DATA_WIDTH ); process of development.
The last chapter deals with a conclusion
pdata_out6<= cache2(((WINDOW_SIZE)*DATA_WIDTH and covers
- 1) downto possible improvements and enhancements.
((WINDOW_SIZE-1)*DATA_WIDTH) );
pdata_out7<= (others => '0');
pdata_out8<= cache1(((WINDOW_SIZE-1)*DATA_WIDTH - 1) downto DATA_WIDTH );
pdata_out9<= cache1(((WINDOW_SIZE)*DATA_WIDTH - 1) downto ((WINDOW_SIZE-1)*DATA_WIDTH) );

-- row>0 and row<479 and counter2>0 and counter2<639


elsif RowsCounterOut>"000000000" and RowsCounterOut<"111011111" and ColsCounterOut>"0000000000" and
ColsCounterOut<"1001111111" then --5
pdata_out1<= cache3((DATA_WIDTH - 1) downto 0 );
pdata_out2<= cache3(((WINDOW_SIZE-1)*DATA_WIDTH - 1) downto DATA_WIDTH );
pdata_out3<= cache3(((WINDOW_SIZE)*DATA_WIDTH - 1) downto ((WINDOW_SIZE-1)*DATA_WIDTH) );
pdata_out4<= cache2((DATA_WIDTH - 1) downto 0 );
pdata_out5<= cache2(((WINDOW_SIZE-1)*DATA_WIDTH - 1) downto DATA_WIDTH );
pdata_out6<= cache2(((WINDOW_SIZE)*DATA_WIDTH - 1) downto ((WINDOW_SIZE-1)*DATA_WIDTH) );
pdata_out7<= cache1((DATA_WIDTH - 1) downto 0 );
pdata_out8<= cache1(((WINDOW_SIZE-1)*DATA_WIDTH - 1) downto DATA_WIDTH );
pdata_out9<= cache1(((WINDOW_SIZE)*DATA_WIDTH - 1) downto ((WINDOW_SIZE-1)*DATA_WIDTH) );

-- row>0 and row<479 and counter2>0 and counter2=639 (6)


elsif RowsCounterOut>"000000000" and RowsCounterOut<"111011111" and ColsCounterOut="1001111111" then
pdata_out1<= cache3((DATA_WIDTH - 1) downto 0 );
pdata_out2<= cache3(((WINDOW_SIZE-1)*DATA_WIDTH - 1) downto DATA_WIDTH );
pdata_out3<= (others => '0');
pdata_out4<= cache2((DATA_WIDTH - 1) downto 0 );
pdata_out5<= cache2(((WINDOW_SIZE-1)*DATA_WIDTH - 1) downto DATA_WIDTH );
pdata_out6<= (others => '0');
pdata_out7<= cache1((DATA_WIDTH - 1) downto 0 );
pdata_out8<= cache1(((WINDOW_SIZE-1)*DATA_WIDTH - 1) downto DATA_WIDTH );
pdata_out9<= (others => '0');

-- row=479 and counter2=0


elsif RowsCounterOut="111011111" and ColsCounterOut="0000000000" then --7
pdata_out1<= (others => '0');
pdata_out2<= cache3(((WINDOW_SIZE-1)*DATA_WIDTH - 1) downto DATA_WIDTH );
pdata_out3<= cache3(((WINDOW_SIZE)*DATA_WIDTH - 1) downto ((WINDOW_SIZE-1)*DATA_WIDTH) );
pdata_out4<= (others => '0');
pdata_out5<= cache2(((WINDOW_SIZE-1)*DATA_WIDTH - 1) downto DATA_WIDTH );
pdata_out6<= cache2(((WINDOW_SIZE)*DATA_WIDTH - 1) downto ((WINDOW_SIZE-1)*DATA_WIDTH) );
pdata_out7<= (others => '0');
pdata_out8<= (others => '0');
pdata_out9<= (others => '0');

-- row=479 and counter2>0 and counter2<639 (8)


elsif RowsCounterOut="111011111" and ColsCounterOut>"0000000000" and ColsCounterOut<"1001111111" then
March 18, 2011- 1) downto 0 );
pdata_out1<= cache3((DATA_WIDTH 1 Aart Mulder and Kolja Roese
pdata_out2<= cache3(((WINDOW_SIZE-1)*DATA_WIDTH - 1) downto DATA_WIDTH );
pdata_out3<= cache3(((WINDOW_SIZE)*DATA_WIDTH - 1) downto ((WINDOW_SIZE-1)*DATA_WIDTH) );
pdata_out4<= cache2((DATA_WIDTH - 1) downto 0 );
pdata_out5<= cache2(((WINDOW_SIZE-1)*DATA_WIDTH - 1) downto DATA_WIDTH );
pdata_out6<= cache2(((WINDOW_SIZE)*DATA_WIDTH - 1) downto ((WINDOW_SIZE-1)*DATA_WIDTH) );
pdata_out7<= (others => '0');
pdata_out8<= (others => '0');
pdata_out9<= (others => '0');

-- row=479 and counter2=639


elsif RowsCounterOut="111011111" and ColsCounterOut="1001111111" then --9
pdata_out1<= cache3((DATA_WIDTH - 1) downto 0 );
pdata_out2<= cache3(((WINDOW_SIZE-1)*DATA_WIDTH - 1) downto DATA_WIDTH );
pdata_out3<= (others => '0');
pdata_out4<= cache2((DATA_WIDTH - 1) downto 0 );
pdata_out5<= cache2(((WINDOW_SIZE-1)*DATA_WIDTH - 1) downto DATA_WIDTH );
pdata_out6<= (others => '0');
pdata_out7<= (others => '0');
pdata_out8<= (others => '0');
pdata_out9<= (others => '0');

56
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

end if; -- RowsCounterOut and ColsCounterOut


end if; --rsync_temp
end process EmittingProcess;
end CacheSystem;

Abstract
Appendix F - sobel_kernel.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
use IEEE.STD_LOGIC_ARITH.ALL;
the requirement of environmental monitoring with the focus on temperature observation. A
use IEEE.STD_LOGIC_UNSIGNED.ALL;
complex wireless network structure was designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
entity edge_sobel is
systems with hard disk storage in order to maintain the reliability. The report contains a short
generic (
introduction in wireless sensor networks and describes the complete process of development.
DATA_WIDTH : integer := 8 );
The last chapter deals with a conclusion and covers possible improvements and enhancements.
port (
pclk_i : in std_logic;
fsync_i : in std_logic;
rsync_i : in std_logic;
pData1 : in STD_LOGIC_VECTOR(DATA_WIDTH-1 downto 0);
pData2 : in STD_LOGIC_VECTOR(DATA_WIDTH-1 downto 0);
pData3 : in STD_LOGIC_VECTOR(DATA_WIDTH-1 downto 0);
pData4 : in STD_LOGIC_VECTOR(DATA_WIDTH-1 downto 0);
pData5 : in STD_LOGIC_VECTOR(DATA_WIDTH-1 downto 0);
pData6 : in STD_LOGIC_VECTOR(DATA_WIDTH-1 downto 0);
pData7 : in STD_LOGIC_VECTOR(DATA_WIDTH-1 downto 0);
pData8 : in STD_LOGIC_VECTOR(DATA_WIDTH-1 downto 0);
pData9 : in STD_LOGIC_VECTOR(DATA_WIDTH-1 downto 0);

fsync_o : out std_logic;


rsync_o : out std_logic;
pdata_o : out std_logic_vector(DATA_WIDTH-1 downto 0) );

end entity edge_sobel;

architecture Behavioral of edge_sobel is


begin
edge_sobel: process (pclk_i)

variable summax, summay : std_logic_vector(10 downto 0);


variable summa1, summa2 : std_logic_vector(10 downto 0);
variable summa : std_logic_vector(10 downto 0);

begin
if (pclk_i'event and pclk_i = '1') then

rsync_o <= rsync_i;


fsync_o <= fsync_i;

if fsync_i = '1' then


March 18, 2011 1 Aart Mulder and Kolja Roese
if rsync_i = '1' then

summax:=("000" & pdata3)+("00" & pdata6 & '0')+("000" & pdata9)


-("000" & pdata1)-("00" & pdata4 & '0')-("000" & pdata7);

summay:=("000" & pdata7)+("00" & pdata8 & '0')+("000" & pdata9)


-("000" & pdata1)-("00" & pdata2 & '0')-("000" & pdata3);

-- Here is computed the absolute value of the numbers


if summax(10)='1' then
summa1:= not summax+1;
else
summa1:= summax;
end if;

if summay(10)='1' then
summa2:= not summay+1;

57
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

else
summa2:= summay;
end if;

summa:=summa1+summa2;

Abstract
-- Threshold = 127
if summa>"00001111111" then
pdata_o<=(others => '1');
else
pdata_o<=summa(DATA_WIDTH-
The project is placed in the field of1Wireless
downto 0);Networks. It is developed to fulfill
Sensor
end if; the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
END IF; sensor devices. A possible application is the observation of temperature in several server
end if; systems with hard disk storage in order to maintain the reliability. The report contains a short
end if; -- pclk_i introduction in wireless sensor networks and describes the complete process of development.
end process edge_sobel; The last chapter deals with a conclusion and covers possible improvements and enhancements.
end Behavioral;

Appendix G - edge_sobel_wrapper.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity edge_sobel_wrapper is
generic (
DATA_WIDTH : integer := 8
);
Port ( clk : in STD_LOGIC;
fsync_in : in STD_LOGIC;
rsync_in : in STD_LOGIC;
pdata_in : in STD_LOGIC_VECTOR (DATA_WIDTH-1 downto 0);
fsync_out : out STD_LOGIC;
rsync_out : out STD_LOGIC;
pdata_out : out STD_LOGIC_VECTOR (DATA_WIDTH-1 downto 0));
end entity edge_sobel_wrapper;

architecture Structural of edge_sobel_wrapper is

SIGNAL pdata_int1 : std_logic_vector(DATA_WIDTH-1 downto 0);


SIGNAL pdata_int2 : std_logic_vector(DATA_WIDTH-1 downto 0);
SIGNAL pdata_int3 : std_logic_vector(DATA_WIDTH-1 downto 0);
SIGNAL pdata_int4 : std_logic_vector(DATA_WIDTH-1 downto 0);
SIGNAL pdata_int5 : std_logic_vector(DATA_WIDTH-1 downto 0);
SIGNAL pdata_int6 : std_logic_vector(DATA_WIDTH-1 downto 0);
SIGNAL pdata_int7 : March 18, 2011
std_logic_vector(DATA_WIDTH-1 downto 10); Aart Mulder and Kolja Roese
SIGNAL pdata_int8 : std_logic_vector(DATA_WIDTH-1 downto 0);
SIGNAL pdata_int9 : std_logic_vector(DATA_WIDTH-1 downto 0);
SIGNAL fsynch_int : std_logic;
SIGNAL rsynch_int : std_logic;

begin

CacheSystem : entity work.CacheSystem


GENERIC MAP (
DATA_WIDTH => DATA_WIDTH,
WINDOW_SIZE => 3,
ROW_BITS => 9,
COL_BITS => 10,
NO_OF_ROWS => 480,
NO_OF_COLS => 640 )

58
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

PORT MAP(
clk => clk,
fsync_in => fsync_in,
rsync_in => rsync_in,
pdata_in => pdata_in,
fsync_out => fsynch_int,
rsync_out => rsynch_int,
Abstract
pdata_out1 => pdata_int1,
pdata_out2 => pdata_int2,
pdata_out3 => pdata_int3,
The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
pdata_out4 => pdata_int4,
the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
pdata_out5 => pdata_int5,
sensor devices. A possible application is the observation of temperature in several server
pdata_out6 => pdata_int6,
systems with hard disk storage in order to maintain the reliability. The report contains a short
pdata_out7 => pdata_int7,
introduction in wireless sensor networks and describes the complete process of development.
pdata_out8 => pdata_int8,
The last chapter deals with a conclusion and covers possible improvements and enhancements.
pdata_out9 => pdata_int9
);

krnl: entity work.edge_sobel


GENERIC MAP ( DATA_WIDTH => DATA_WIDTH)
PORT MAP(
pclk_i => clk,
fsync_i => fsynch_int,
rsync_i => rsynch_int,
pData1 => pData_int1,
pData2 => pData_int2,
pData3 => pData_int3,
pData4 => pData_int4,
pData5 => pData_int5,
pData6 => pData_int6,
pData7 => pData_int7,
pData8 => pData_int8,
pData9 => pData_int9,
fsync_o => fsync_out,
rsync_o => rsync_out,
pdata_o => pdata_out
);

end Structural;

Appendix H - num_rom.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
March 18, 2011 1 Aart Mulder and Kolja Roese
entity Num_Rom is
port(
en : in STD_LOGIC;
address : in STD_LOGIC_VECTOR(6 downto 0);
rd : in STD_LOGIC;
data_out : out STD_LOGIC_VECTOR(0 to 7)
);
end Num_Rom;

architecture Behavioral of Num_Rom is

begin

process(en,rd,address)
begin

59
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

if(en = '1' and rd = '1') then


case address is
-- 0
when "0000000" => data_out <= "00111110";
when "0000001" => data_out <= "01100011";
Abstract
when "0000010" => data_out <= "01100011";
when "0000011" => data_out <= "01101011";
when "0000100" => data_out <= "01101011";
when "0000101" => data_out <= "01100011";
when "0000110"
The project is placed => data_out
in the <= Sensor
field of Wireless "01100011";
Networks. It is developed to fulfill
when "0000111"
the requirement => data_out
of environmental <=with
monitoring "00111110";
the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
--sensor
1 devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
when "0001000" => data_out <= "00001100";
introduction in wireless sensor networks and describes the complete process of development.
when "0001001"
The last => adata_out
chapter deals with conclusion and<= "00111100";
covers possible improvements and enhancements.
when "0001010" => data_out <= "00001100";
when "0001011" => data_out <= "00001100";
when "0001100" => data_out <= "00001100";
when "0001101" => data_out <= "00001100";
when "0001110" => data_out <= "00001100";
when "0001111" => data_out <= "00111111";

-- 2
when "0010000" => data_out <= "00111110";
when "0010001" => data_out <= "01100011";
when "0010010" => data_out <= "01100011";
when "0010011" => data_out <= "00000110";
when "0010100" => data_out <= "00001100";
when "0010101" => data_out <= "00011000";
when "0010110" => data_out <= "00110011";
when "0010111" => data_out <= "01111111";

-- 3
when "0011000" => data_out <= "00111110";
when "0011001" => data_out <= "01100011";
when "0011010" => data_out <= "00000011";
when "0011011" => data_out <= "00001110";
when "0011100" => data_out <= "00001110";
when "0011101" => data_out <= "00000011";
when "0011110" => data_out <= "01100011";
when "0011111" => data_out <= "00111110";

-- 4
when "0100000" => data_out <= "00000110";
when "0100001" => data_out <= "00001110";
when "0100010" => data_out <= "00011110";
when
March"0100011"
18, 2011 => data_out <=1 "00110110";
Aart Mulder and Kolja Roese
when "0100100" => data_out <= "01100110";
when "0100101" => data_out <= "01111111";
when "0100110" => data_out <= "00000110";
when "0100111" => data_out <= "00000110";

-- 5
when "0101000" => data_out <= "01111111";
when "0101001" => data_out <= "01100000";
when "0101010" => data_out <= "01100000";
when "0101011" => data_out <= "01111110";
when "0101100" => data_out <= "00000011";
when "0101101" => data_out <= "00000011";
when "0101110" => data_out <= "01100011";
when "0101111" => data_out <= "00111110";

60
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

-- 6
when "0110000" => data_out <= "00111110";
when "0110001" => data_out <= "01100011";
when "0110010" => data_out <= "01100000";
when "0110011" => data_out <= "01111110";
Abstract
when
when
"0110100"
"0110101"
=>
=>
data_out
data_out
<=
<=
"01100011";
"01100011";
when "0110110" => data_out <= "01100011";
when "0110111" => data_out <= "00111110";
The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
--the7 requirement of environmental monitoring with the focus on temperature observation. A
complex
when wireless network
"0111000" => structure
data_out was designed with the flexible integration of multiple
<= "01111111";
sensor devices. A possible application is the observation of temperature in several server
when "0111001" => data_out <= "01100011";
systems with hard disk storage in order to maintain the reliability. The report contains a short
when "0111010" => data_out <= "00000110";
introduction in wireless sensor networks and describes the complete process of development.
when "0111011"
The last => adata_out
chapter deals with conclusion and<= "00001100";
covers possible improvements and enhancements.
when "0111100" => data_out <= "00011000";
when "0111101" => data_out <= "00011000";
when "0111110" => data_out <= "00011000";
when "0111111" => data_out <= "00011000";

-- 8
when "1000000" => data_out <= "00111110";
when "1000001" => data_out <= "01100011";
when "1000010" => data_out <= "01100011";
when "1000011" => data_out <= "01100011";
when "1000100" => data_out <= "00111110";
when "1000101" => data_out <= "01100011";
when "1000110" => data_out <= "01100011";
when "1000111" => data_out <= "00111110";

-- 9
when "1001000" => data_out <= "00111110";
when "1001001" => data_out <= "01100011";
when "1001010" => data_out <= "01100011";
when "1001011" => data_out <= "01100011";
when "1001100" => data_out <= "00111111";
when "1001101" => data_out <= "00000011";
when "1001110" => data_out <= "01100011";
when "1001111" => data_out <= "00111110";

-- .
when "1111000" => data_out <= "00000000";
when "1111001" => data_out <= "00000000";
when "1111010" => data_out <= "00000000";
when "1111011" => data_out <= "00000000";
when "1111100" => data_out <= "00000000";
when
March"1111101"
18, 2011 => data_out <=1 "00000000";
Aart Mulder and Kolja Roese
when "1111110" => data_out <= "00011000";
when "1111111" => data_out <= "00011000";

when others => data_out <= "00000000";

end case;
else
data_out <= (others => 'Z');
end if;
end process;
end Behavioral;

61
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

Appendix I - number_displayer.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
Abstract
entity Number_Displayer is
generic ( The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
DATA_WIDTH : the
integer := of
requirement 8;environmental monitoring with the focus on temperature observation. A
COL_BITS : integer
complex wireless := 10 );
network structure was designed with the flexible integration of multiple
port( sensor devices. A possible application is the observation of temperature in several server
clk : in STD_LOGIC;systems with hard disk storage in order to maintain the reliability. The report contains a short
fsync_in : in STD_LOGIC;
introduction in wireless sensor networks and describes the complete process of development.
rsync_in : in STD_LOGIC;
The last chapter deals with a conclusion and covers possible improvements and enhancements.
data_in : in STD_LOGIC_VECTOR(DATA_WIDTH-1 downto 0);
pos_row : in STD_LOGIC_VECTOR(COL_BITS-1 downto 0);
pos_col : in STD_LOGIC_VECTOR(COL_BITS-1 downto 0);
meters : in STD_LOGIC_VECTOR(3 downto 0);
decimeters : in STD_LOGIC_VECTOR(3 downto 0);
centimeters : in STD_LOGIC_VECTOR(3 downto 0);
fsync_out : out STD_LOGIC;
rsync_out : out STD_LOGIC;
data_out : out STD_LOGIC_VECTOR(DATA_WIDTH-1 downto 0) );
end Number_Displayer;

architecture Behavioral of Number_Displayer is

constant NUMBERS_DIM : integer := 8;

component Counter is
generic(n : POSITIVE := 10);
port ( clk : in STD_LOGIC;
en : in STD_LOGIC;
reset : in STD_LOGIC; -- Active Low
output : out STD_LOGIC_VECTOR(COL_BITS-1 downto 0) );
end component;

component Num_Rom is
port(
en : in STD_LOGIC;
address : in STD_LOGIC_VECTOR(6 downto 0);
rd : in STD_LOGIC;
data_out : out STD_LOGIC_VECTOR(0 to NUMBERS_DIM-1) );
end component;

signal RowsCounterOut,ColsCounterOut : STD_LOGIC_VECTOR(COL_BITS-1 downto 0) := (others


=> '0');
signal FontDataOut : STD_LOGIC_VECTOR(0
March 18, 2011 to NUMBERS_DIM-1);1 Aart Mulder and Kolja Roese
signal FontAddress : STD_LOGIC_VECTOR(6 downto 0);

begin
RowsCounter : Counter port map(rsync_in, fsync_in,fsync_in,RowsCounterOut);
ColsCounter : Counter port map(clk, rsync_in,rsync_in,ColsCounterOut);
LUTFont : Num_Rom port map('1',FontAddress,'1',FontDataOut);

fsync_out <= fsync_in;


rsync_out <= rsync_in;

process(RowsCounterOut,ColsCounterOut,pos_row,pos_col,meters,decimeters,centimeters,
data_in)
variable rowLUT : STD_LOGIC_VECTOR(COL_BITS-1 downto 0);
variable colLUT : STD_LOGIC_VECTOR(COL_BITS-1 downto 0);
begin
-- First Number

62
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

if(RowsCounterOut >= pos_row and RowsCounterOut <= (pos_row+7) and ColsCounterOut


>= (pos_col-1) and ColsCounterOut <= (pos_col+7-1)) then
rowLUT := (RowsCounterOut - pos_row);
colLUT := (ColsCounterOut - (pos_col-1));
FontAddress <= (meters & rowLUT(2 downto 0));
data_out <= (others => FontDataOut(conv_integer(colLUT(2 downto 0))));
Abstract
-- Decimal Point
elsif(RowsCounterOut >= pos_row and RowsCounterOut <= (pos_row+7) and
ColsCounterOut >= (pos_col+8-1) and ColsCounterOut <= (pos_col+15-1)) then
rowLUT := (RowsCounterOut - pos_row);
The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
colLUT := (ColsCounterOut - environmental
the requirement of (pos_col+8-1));monitoring with the focus on temperature observation. A
FontAddress <= ("1111" & rowLUT(2
complex wireless downto
network structure was0));
designed with the flexible integration of multiple
data_out <= (others => FontDataOut(conv_integer(colLUT(2
sensor devices. downto 0))));
A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
-- Second Number introduction in wireless sensor networks and describes the complete process of development.
elsif(RowsCounterOut >=
Thepos_row
last chapterand
deals RowsCounterOut <= (pos_row+7)
with a conclusion and covers and and enhancements.
possible improvements
ColsCounterOut >= (pos_col+16-1) and ColsCounterOut <= (pos_col+23-1)) then
rowLUT := (RowsCounterOut - pos_row);
colLUT := (ColsCounterOut - (pos_col+16-1));
FontAddress <= (decimeters & rowLUT(2 downto 0));
data_out <= (others => FontDataOut(conv_integer(colLUT(2 downto 0))));

-- Third Number
elsif(RowsCounterOut >= pos_row and RowsCounterOut <= (pos_row+7) and
ColsCounterOut >= (pos_col+24-1) and ColsCounterOut <= (pos_col+31-1)) then
rowLUT := (RowsCounterOut - pos_row);
colLUT := (ColsCounterOut - (pos_col+24-1));
FontAddress <= (centimeters & rowLUT(2 downto 0));
data_out <= (others => FontDataOut(conv_integer(colLUT(2 downto 0))));

-- Original Image
else
FontAddress <= (others => '0'); -- Only to not make infer a latch
data_out <= data_in;
end if;
end process;
end Behavioral;

Appendix J - bcd_converter.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity bcd_converter is
Port ( input : in STD_LOGIC_VECTOR(8 downto 0);
hundreds : out STD_LOGIC_VECTOR(3 downto 0);
tens : out STD_LOGIC_VECTOR(3
March 18, 2011 downto 0); 1 Aart Mulder and Kolja Roese
unit : out STD_LOGIC_VECTOR(3 downto 0));
end bcd_converter;

architecture Behavioral of bcd_converter is

begin

process(input)
variable i : integer:=0;
variable bcd : std_logic_vector(20 downto 0);

begin
-- Initialization phase: the space for the BCD representation is reserved
bcd := (others => '0');
bcd(8 downto 0) := input;

63
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

for i in 0 to 8 loop
-- Left shift one bit
bcd(19 downto 0) := bcd(18 downto 0) & '0';

-- Check phase Abstract


if(i < 8 and bcd(12 downto 9) > "0100") then
bcd(12 downto 9) := bcd(12 downto 9) + "0011";
end if;
The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
if(i < 8 and bcd(16 downto
the requirement 13) > "0100")
of environmental then
monitoring with the focus on temperature observation. A
bcd(16 downto 13) := bcd(16 downto 13)with
complex wireless network structure was designed + the flexible integration of multiple
"0011";
sensor devices. A possible application is the observation of temperature in several server
end if;
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
if(i < 8 and bcd(20 downto
The last chapter 17)a conclusion
deals with > "0100") then
and covers possible improvements and enhancements.
bcd(20 downto 17) := bcd(20 downto 17) + "0011";
end if;

end loop;

-- The three BCD numbers are put in output


hundreds <= bcd(20 downto 17);
tens <= bcd(16 downto 13);
unit <= bcd(12 downto 9);
end process;
end Behavioral;

Appendix K - trigger_generator.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity trigger_generator is
port(
clk : in STD_LOGIC;
trigger : out STD_LOGIC
);
end trigger_generator;

architecture Behavioral of trigger_generator is

component Counter is
generic(n : POSITIVE := 10);
Port ( clk : in STD_LOGIC;
en : in STD_LOGIC;
reset : in STD_LOGIC;
March 18, 2011 -- Active Low
1 Aart Mulder and Kolja Roese
output : out STD_LOGIC_VECTOR(n-1 downto 0));
end component;

signal resetCounter : STD_LOGIC := '0';


signal outputCounter : STD_LOGIC_VECTOR(23 downto 0) := (others => '0');

begin

count : Counter generic map(24) port map(clk,'1',resetCounter,outputCounter);

process(clk)
constant ms250 : STD_LOGIC_VECTOR(23 downto 0) :=
"101111101011110000100000";
constant ms250And100us : STD_LOGIC_VECTOR(23 downto 0) :=
"101111101100111110101000";

64
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

begin
if(clk'event and clk = '1') then
if(outputCounter >= ms250 and outputCounter < ms250And100us) then
trigger <= '1';
else
trigger <=
Abstract
'0';
end if;

if(outputCounter = ms250And100us)
The project is placed in the field then
of Wireless Sensor Networks. It is developed to fulfill
resetCounter <= '0';
the requirement of environmental monitoring with the focus on temperature observation. A
else complex wireless network structure was designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
resetCounter <= '1';
systems with hard disk storage in order to maintain the reliability. The report contains a short
end if; introduction in wireless sensor networks and describes the complete process of development.
end if; -- clk The last chapter deals with a conclusion and covers possible improvements and enhancements.
end process;
end Behavioral;

Appendix L - distance_measurer.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use IEEE.NUMERIC_STD.ALL;

entity distance_measurer is
port ( clk : in STD_LOGIC;
trigg : in STD_LOGIC;
pulse : in STD_LOGIC;
distance : out STD_LOGIC_VECTOR(8 downto 0) := (others => '0') );
end distance_measurer;

architecture Behavioral of distance_measurer is

component Counter is
generic(n : POSITIVE := 10);
Port ( clk : in STD_LOGIC;
en : in STD_LOGIC;
reset : in STD_LOGIC; -- Active Low
output : out STD_LOGIC_VECTOR(n-1 downto 0) );
end component;

signal CounterPulseOut : STD_LOGIC_VECTOR(21 downto 0);

begin March 18, 2011 1 Aart Mulder and Kolja Roese

CounterPulse : Counter generic map(22)


port map(clk,pulse,not trigg,CounterPulseOut);

DistanceProcess : process(pulse,CounterPulseOut)
variable temp : integer;
variable tempVar : STD_LOGIC_VECTOR(23 downto 0);
begin
if(pulse'event and pulse = '0') then
tempVar := CounterPulseOut * "11";
temp := to_integer(unsigned(tempVar(23 downto 13)));
if(temp > 458) then
distance <= "111111111";
else
distance <= STD_LOGIC_VECTOR(to_unsigned(temp,9));

65
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

end if;
end if;
end process DistanceProcess;
end Behavioral;

Abstract
Appendix M - range_sensor.vhd
library IEEE; The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
use IEEE.STD_LOGIC_1164.ALL; the requirement of environmental monitoring with the focus on temperature observation. A
use IEEE.STD_LOGIC_UNSIGNED.ALL;complex wireless network structure was designed with the flexible integration of multiple
use IEEE.NUMERIC_STD.ALL; sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
entity range_sensor is introduction in wireless sensor networks and describes the complete process of development.
port ( The last chapter deals with a conclusion and covers possible improvements and enhancements.
fpgaclk : in STD_LOGIC;
triggerOut : out STD_LOGIC;
pulse : in STD_LOGIC;
meters : out STD_LOGIC_VECTOR(3 downto 0);
decimeters : out STD_LOGIC_VECTOR(3 downto 0);
centimeters : out STD_LOGIC_VECTOR(3 downto 0) );
end range_sensor;

architecture Behavioral of range_sensor is

component distance_measurer is
Port ( clk : in STD_LOGIC;
trigg : in STD_LOGIC;
pulse : in STD_LOGIC;
distance : out STD_LOGIC_VECTOR(8 downto 0) );
end component;

component trigger_generator is
port( clk : in STD_LOGIC;
trigger : out STD_LOGIC );
end component;

component bcd_converter is
Port ( input : in STD_LOGIC_VECTOR(8 downto 0);
hundreds : out STD_LOGIC_VECTOR(3 downto 0);
tens : out STD_LOGIC_VECTOR(3 downto 0);
unit : out STD_LOGIC_VECTOR(3 downto 0) );
end component;

signal distanceOut : STD_LOGIC_VECTOR(8 downto 0);


March 18, 2011 1 Aart Mulder and Kolja Roese
signal triggOut : STD_LOGIC;

begin

triggerOut <= triggOut;


trigger_gen : trigger_generator
port map(fpgaclk,triggOut);

measurer : distance_measurer
port map(fpgaclk,triggOut,pulse,distanceOut);

BCDConv : bcd_converter
port map(distanceOut,meters,decimeters,centimeters);

end Behavioral;

66
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

Appendix N - top_vga.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL; Abstract
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity topVGA is The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
port(
complex wireless network structure was designed with the flexible integration of multiple
clk : in std_logic;
sensor devices. A possible application is the observation of temperature in several server
dbg : out std_logic;
systems with hard disk storage in order to maintain the reliability. The report contains a short
grd : out std_logic;
introduction in wireless sensor networks and describes the complete process of development.
mode : in std_logic;
The last chapter deals with a conclusion and covers possible improvements and enhancements.
trigg : out std_logic;

data : in std_logic_vector(7 downto 0);


lv : in std_logic;
FV : in std_logic;
pixel_clk : in std_logic;

LV_out : out std_logic;


FV_out : out std_logic;
vgaRed : out std_logic_vector(7 downto 5);
vgaGreen : out std_logic_vector(7 downto 5);
vgaBlue : out std_logic_vector(7 downto 6)
);
end entity topVGA;

architecture structure of topVGA is

SIGNAL data_o : STD_LOGIC_VECTOR(7 DOWNTO 0);


SIGNAL meters : STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL decimeters : STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL centimeters : STD_LOGIC_VECTOR(3 DOWNTO 0);
SIGNAL FV_OUT_SOBEL : STD_LOGIC;
SIGNAL LV_OUT_SOBEL : STD_LOGIC;
SIGNAL DATA_FOR_VGA : STD_LOGIC_VECTOR(7 DOWNTO 0);

begin
dbg <= '0';
grd <= '0';

rs : entity work.range_sensor
port map(
fpgaclk =>March
clk, 18, 2011 1 Aart Mulder and Kolja Roese
pulse => mode,
triggerOut => trigg,

meters => meters,


decimeters => decimeters,
centimeters => centimeters
);

edge : entity work.edge_sobel_wrapper


Port map (
clk => pixel_clk,
fsync_in => FV,
rsync_in => lv,
pdata_in => DATA,
fsync_out => FV_OUT_SOBEL,

67
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

rsync_out => LV_OUT_SOBEL,


pdata_out => DATA_O
);

nm : entity work.number_displayer
port map(
clk => pixel_clk,
Abstract
fsync_in => FV_OUT_SOBEL,
rsync_in => LV_OUT_SOBEL,
The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
data_in => DATA_O, the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
fsync_out => FV_OUT,sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
rsync_out => LV_OUT,introduction in wireless sensor networks and describes the complete process of development.
data_out => DATA_FOR_VGA,
The last chapter deals with a conclusion and covers possible improvements and enhancements.

pos_row => "0000111100", -- 60


pos_col => "0000111100", -- 60

meters => meters,


decimeters => decimeters,
centimeters => centimeters
);

vgaRed <= DATA_FOR_VGA(7 DOWNTO 5);


vgaGreen <= DATA_FOR_VGA(7 DOWNTO 5);
vgaBlue <= DATA_FOR_VGA(7 DOWNTO 6);

end architecture structure;

Appendix O - top_vga.ucf
## clock pin for Nexys 2 Board
NET "clk" LOC= "B8"; # Bank = 0 , Pin name = IP_L13P_0/GCLK8 , Type = GCLK , Sch
name = GCLK0

NET "vgaRed<5>" LOC = "R9";


NET "vgaRed<6>" LOC = "T8";
NET "vgaRed<7>" LOC = "R8";
NET "vgaGreen<5>" LOC = "N8";
NET "vgaGreen<6>" LOC = "P8";
NET "vgaGreen<7>" LOC = "P6";
NET "vgaBlue<6>" LOC = "U5";
NET "vgaBlue<7>" LOC = "U4";
NET "LV_out" LOC = "T4";
March 18, 2011 1 Aart Mulder and Kolja Roese
NET "FV_out" LOC = "U3";

NET "Data<0>" LOC = "B4";


NET "Data<1>" LOC = "A4";
NET "Data<2>" LOC = "C3";
NET "Data<3>" LOC = "C4";
NET "Data<4>" LOC = "B6";
NET "Data<5>" LOC = "D5";
NET "Data<6>" LOC = "C5";
NET "Data<7>" LOC = "F7";
NET "FV" LOC = "A8";
NET "LV" LOC = "D7";
NET "pixel_clk" LOC = "A11";
NET "pixel_clk" CLOCK_DEDICATED_ROUTE = FALSE;
NET "mode" CLOCK_DEDICATED_ROUTE = FALSE;

68
Mid Sweden University
Department of Information Mid Sweden University
Department of Information
Technology and Media (ITM)
technology and media (ITM).

NET "lv" CLOCK_DEDICATED_ROUTE = FALSE;

NET "DBG" loc = "D14";


#NET "grd" LOC = "B14"; # Bank = 0, Pin name = IO_L04P_0, Type = I/O, Sch name = R-
IO38
Abstract
NET "mode" LOC = "A16"; # Bank = 0, Pin name = IO_L01N_0, Type = I/O, Sch name = R-
IO39
NET "trigg" LOC = "B16"; # Bank = 0, Pin name = IO_L01P_0, Type = I/O, Sch name = R-
IO40
The project is placed in the field of Wireless Sensor Networks. It is developed to fulfill
the requirement of environmental monitoring with the focus on temperature observation. A
complex wireless network structure was designed with the flexible integration of multiple
sensor devices. A possible application is the observation of temperature in several server
systems with hard disk storage in order to maintain the reliability. The report contains a short
introduction in wireless sensor networks and describes the complete process of development.
The last chapter deals with a conclusion and covers possible improvements and enhancements.

March 18, 2011 1 Aart Mulder and Kolja Roese

69

You might also like