Professional Documents
Culture Documents
Building a Temperature
Sensing System
Using DE2-115 FPGA and System Verilog
(Group 3)
Study Project
Fall 2016
(Group 3)
Table of Contents
Introduction ........................................................................................................................2
Sensors .............................................................................................................................2
Processing ........................................................................................................................2
Temperature Sensing and Control System ......................................................................3
High-Level Design ...............................................................................................................4
Block Diagram ..................................................................................................................4
Solution Algorithm ...........................................................................................................5
Code Hierarchy ...............................................................................................................6
Code Remarks .................................................................................................................. 6
Lower-Level Design .............................................................................................................8
Hardware..........................................................................................................................8
Results................................................................................................................................. 11
Conclusion .......................................................................................................................... 14
Appendix ............................................................................................................................14
TemperatureSensing.sv ..................................................................................................14
LCD_Display.sv ..............................................................................................................16
References.......................................................................................................................... 20
1!
(Group 3)
Introduction
Many of todays industrial systems rely on stabilized temperature readings to maintain
the safety and quality of the products and appliances. For the most part, many modern
procedures rely on balanced out temperatures and henceforth it is vital to manage an
ideal temperature. Temperature control can be characterized as the method of detecting
temperature change and coordinating the warmth energy into or outward of the
framework to realize the correct temperature [1].
Temperature control frameworks are for the most part useful for closed loop control
frameworks [1]. In such frameworks, an action is taken according to the monitored
temperature in the vicinity. To achieve temperature control, two components must be
considered, which are sensing and processing [3]. Securing the information is the key
part of the entire controlled process. Sensors assume a noteworthy part in gaining the
information and the processor assesses the information and gives a standard coherent
output to accomplish the required outcome [2].
Sensors
The study of sensing can be characterized as the process of obtaining information from
remote geological areas. Various sensors are positioned into the surveillance field to
collect data. Sensor can be characterized as a transducer which changes over one type of
energy into another [2]. Sensors operate by detecting any variations in the surrounding
area, then they send such observations in the form of an output that convey the changes.
The market offers a variety of accessible sensors, such as temperature sensors, gas
sensors, humidity sensors, light sensors and so forth. Whats common between such
sensors is that they produce their output in an electrical form that can be used for
additional processing [3].
Processing
The idea of processing can be described as the act of evaluating data through some type of
program. Electric signals form the input to the processor from the sensor devices. Based on the
given input signal, the processor evaluates the given data and produces an output with respect to
the input data. There are two major types of processors, which fall under PLCs (programmable
Logic controllers) or FPGAs (field programmable entryway exhibits) which can be modified and
programmed to perform in a certain manner. Coding of the FPGA can be performed using
different types of software, which vary depending on the processor compatibility [3].
!
2
(Group 3)
http://www.terasic.com.tw/cgi-bin/page/archive.pl?Language=English&No=502
!
3
(Group 3)
High-Level Design
Block Diagram
The system starts with a temperature sensor that converts the measured
temperatureinto electrical signals forfurther processing. The measured temperature is
read in terms of analogue voltage and the DE2115 board only accepts digital data.
Hence, from the sensor the output voltage is given to the analogue to digital converter
(ADC) which digitizes the voltage for further the processing of data. The output of ADC
is given to the board through the GPIO pins. The processor processes the information
and displays it on the LCD display [3]. The block diagram is as shown below.
!
4
(Group 3)
Solution Algorithm
The software part of the solution can be defined using the following algorithm.
!
5
(Group 3)
Code Hierarchy
The project code was organized in the following structure (generated through the Tree 2
command on Windows):
C: POCSD_final_project_team_3 / main project folder (contains the
source files in SystemVerilog)
DE2_115.qsf/ Pin assignments file
LCD_Display.sv/ System Verilog file for displaying temp on LCD
README.txt/ README file for instructions about the project
Reset_Delay.sv/ System Verilog file to control resent on DE2-115
TemperatureSensing.sv/ Main System Verilog for temp sensing
+---db/ Compilation temp folder (May be deleted)
+---incremental_db/ Compilation temp folder (May be deleted)
|
\---compiled_partitions
+---output_files
\---simulation / main folder for simulation files
\---modelsim
Code Remarks
Since the implementation of this project is mainly based on the work done in [3],
we tried to re-implement their system by tracing their circuitry and re-writing their
VHDL code. However, this attempt failed because of the inherent differences between
VHDL and System Verilog. Our project requirements state that we must use System
Verilog, and we are more familiar with System Verilog. Moreover, converting code from
VHDL to System Verilog was not a straight forward task. For the most part, the major
components could be converted. Yet, there were some small issues that caused
2
http://www.computerhope.com/treehlp.htm
!
6
(Group 3)
The temperature here is defined as an 8 bit wire that gets its values from the
GPIO in binary. Then the values are converted with the hex1 and hex0 assignments that
will be done in the LCD_Display.sv file. The code snippet below shows the changes
made to the LCD display file in which the output of the display was modified to show the
temperature obtained from the sensor. Each ASCII code corresponds to a letter that
shows the statement Temperature(C)=XX which means the temperature in degrees
Celsius equals the value read from the sensor and converted with the ADC.
// ASCII hex values for LCD Display
// Enter Live Hex Data Values from hardware here
// LCD DISPLAYS THE FOLLOWING:
//----------------------------//| Temperature(C)=
|
//| XX
|
//----------------------------!
7
(Group 3)
// Line 1
//always@(Temp)
//tempOutput = Temp;
always
case (index)
5'h00: out <= 8'h54;//T
5'h01: out <= 8'h65;//e
5'h02: out <= 8'h6d;//m
5'h03: out <= 8'h70;//p
5'h04: out <= 8'h65;//e
5'h05: out <= 8'h72;//r
5'h06: out <= 8'h61;//a
5'h07: out <= 8'h74;//t
5'h08: out <= 8'h75;//u
5'h09: out <= 8'h72;//r
5'h0A: out <= 8'h65;//e
5'h0B: out <= 8'h28;//(
5'h0C: out <= 8'h43;//C
5'h0D: out <= 8'h29;//)
5'h0E: out <= 8'h3D;//=
// Line 2
//Converted temperature value
5'h10: out <= {4'h0,hex1};
5'h11: out <= {4'h0,hex0};
default: out <= 8'h20;
endcase
Lower-Level Design
Hardware
The components used for the temperature sensing system are as follows:
LM35 Temperature Sensor
ADC0804 IC
DE2115 Board
10Kresistor
10K pot
150pF capacitor
100F capacitor
Bread Board
!
8
(Group 3)
Connecting wires
Multi-meter
(Group 3)
This sensor provides variable voltage at the output, based on temperature. For every +1
centigrade rise in temperature there will be +10mV higher voltage at the output pin. For
example, if the temperature is 0 centigrade the output of sensor will be 0V, if the
temperature is 24 centigrade the output of sensor will be +240mV [7].
As shown in Figure 4, so a100uF capacitoris used to smooth out the output of the
LM35 since it has lot of voltage fluctuations [7].
(Group 3)
is of +3v, so we cannot feed the output of the ADC directly to the DE2115 GPIO pins
because if we give +5V to any GPIO pin of PI, the board gets damaged [8].
To overcome this problem, we made use of the adjustable Vref pin (PIN9) on ADC0804.
So weset the Vref of the chip to +2V. This is done by using 10K pot to adjust the voltage
at PIN9 to a voltage of +1V (VREF/2). The voltmeter to get the accurate voltage [7].
The ADC is known to have lots of noise which can greatly affect the performance, so we
use150 pF capacitor for Noise Filtration to eliminate fluctuations at output. The
chip works on RC (Resistor-Capacitor) oscillator clock. As shown in circuit diagram, C=
150 pF and R= 10k ohm form a Clock [6].
The important thing to remember here is the capacitor can be changed to a lower value
for higher rate of ADC conversion. However with higher speed there will be decrease in
accuracy. So if the application requires higher accuracy, choose the capacitor with
higher value and for higher speed choose the capacitor with lower value [6].
Results
Results of connecting the circuit to the DE2-115 FPGA board and downloading the
system Verilog code to it can be found in the short video on Drop Box [5].
The video shows that the FPGA board is able to receive the temperature reading through
the GPIO and display it to the user in a readable format in Celsius. According to the
video, the temperature sensor was able to successfully detect the room temperature,
!
11
(Group 3)
which was 22 C at the time of filming the video. Moreover, this temperature can be used
to compare the actual room temperature with the values given by the thermostat in the
room to compare their accuracy.
Execution time was extremely fast so long as all the components are properly connected
and pins assigned to their proper input source on the GPIO. Moreover, any improper
circuitry results in compilation errors, so the deployment of the code was done after
ensuring that all connections were done accurately. Some components could not be
integrated in the initial plan like the buzzer that was supposed to fire an alarm sound
when the temperature changes. This was not accomplished due to complications with
hardware and lack of time.
The complete project circuit configuration is shown below:
!
To check that the temperature measured is equal to the temperature displayed, a
multimeter was used to measure the output voltage from the temperature sensor.
!
12
(Group 3)
!
13
(Group 3)
Conclusion
The aim of the temperature system was to measure the room temperature and
display it on the LCD of the DE2115 board, which was successfully achieved.
However, the initial plan was to have a control system where a fan would turn on
if the room temperature exceeds a certain threshold or a heater will turn on if it falls
below this threshold. Also, a buzzer was to be installed in order to warn the user when
these two cases happen. But this was not achievable due to time constraints and difficult
access to components. The buzzer was ordered, but it turned out to be damaged and
there was no enough time to order a new one.
Future plans include implementing the above described conditions, in addition to
providing a live feed on a TV screen or monitor to show the measured temperature and
show any warnings. In case of warning an email or text message is sent to the
responsible people in order to take action. This was actually implemented by us before
using the Raspberry Pi.
Finally, it is important to note that the lcd code was provided by the lab instructor
and it was modified by us in order to read the temperature from the adc and convert it
into integer to be displayed on the LCD.
Appendix
This section contains the full code that was used in the implementation of this project.
The major Verilog files include TemperatureSensing.sv and LCD_Display.sv.
TemperatureSensing.sv
module TemperatureSensing(
input
CLOCK_50, // 50 MHz clock
input [3:0] KEY,
// Pushbutton[3:0]
input [17:0] SW,
// Toggle Switch[17:0]
output [6:0] HEX0,HEX1,HEX2,HEX3,HEX4,HEX5,HEX6,HEX7, // Seven Segment
Digits
output [8:0] LEDG, // LED Green
output [17:0] LEDR, // LED Red
inout [35:0] GPIO_0,GPIO_1,
// GPIO Connections
// LCD Module 16X2
output LCD_ON, // LCD Power ON/OFF
output LCD_BLON,
// LCD Back Light ON/OFF
output LCD_RW, // LCD Read/Write Select, 0 = Write, 1 = Read
!
14
(Group 3)
=
=
1'b1;
1'b1;
(Group 3)
assign
assign
assign
assign
HEX4
HEX5
HEX6
HEX7
=
=
=
=
7'b111_1111;
7'b111_1111;
7'b111_1111;
7'b111_1111;
endmodule
LCD_Display.sv
module LCD_Display(iCLK_50MHZ, iRST_N, Temp, hex1, hex0,
LCD_RS,LCD_E,LCD_RW,DATA_BUS);
input iCLK_50MHZ, iRST_N;
input [3:0] hex1, hex0;
//Read temperature value from GPIO
input [7:0] Temp;
output LCD_RS, LCD_E, LCD_RW;
inout [7:0] DATA_BUS;
parameter
HOLD = 4'h0,
FUNC_SET = 4'h1,
DISPLAY_ON = 4'h2,
MODE_SET = 4'h3,
Print_String = 4'h4,
LINE2 = 4'h5,
RETURN_HOME = 4'h6,
DROP_LCD_E = 4'h7,
RESET1 = 4'h8,
RESET2 = 4'h9,
RESET3 = 4'ha,
DISPLAY_OFF = 4'hb,
DISPLAY_CLEAR = 4'hc;
reg [3:0] state, next_command;
// Enter new ASCII hex data above for LCD Display
reg [7:0] DATA_BUS_VALUE;
wire [7:0] Next_Char;
reg [19:0] CLK_COUNT_400HZ;
reg [4:0] CHAR_COUNT;
reg CLK_400HZ, LCD_RW_INT, LCD_E, LCD_RS;
// BIDIRECTIONAL TRI STATE LCD DATA BUS
assign DATA_BUS = (LCD_RW_INT? 8'bZZZZZZZZ: DATA_BUS_VALUE);
LCD_display_string u1(
.index(CHAR_COUNT),
.out(Next_Char),
.hex1(hex1),
.hex0(hex0),
);
assign LCD_RW = LCD_RW_INT;
always @(posedge iCLK_50MHZ or negedge iRST_N)
if (!iRST_N)
begin
CLK_COUNT_400HZ <= 20'h00000;
CLK_400HZ <= 1'b0;
!
16
(Group 3)
end
else if (CLK_COUNT_400HZ < 20'h0F424)
begin
CLK_COUNT_400HZ <= CLK_COUNT_400HZ + 1'b1;
end
else
begin
CLK_COUNT_400HZ <= 20'h00000;
CLK_400HZ <= ~CLK_400HZ;
end
// State Machine to send commands and data to LCD DISPLAY
always @(posedge CLK_400HZ or negedge iRST_N)
if (!iRST_N)
begin
state <= RESET1;
end
else
case (state)
RESET1:
// Set Function to 8-bit transfer and 2 line display with 5x8 Font size
// see Hitachi HD44780 family data sheet for LCD command and timing details
begin
LCD_E <= 1'b1;
LCD_RS <= 1'b0;
LCD_RW_INT <= 1'b0;
DATA_BUS_VALUE <= 8'h38;
state <= DROP_LCD_E;
next_command <= RESET2;
CHAR_COUNT <= 5'b00000;
end
RESET2:
begin
LCD_E <= 1'b1;
LCD_RS <= 1'b0;
LCD_RW_INT <= 1'b0;
DATA_BUS_VALUE <= 8'h38;
state <= DROP_LCD_E;
next_command <= RESET3;
end
RESET3:
begin
LCD_E <= 1'b1;
LCD_RS <= 1'b0;
LCD_RW_INT <= 1'b0;
DATA_BUS_VALUE <= 8'h38;
state <= DROP_LCD_E;
next_command <= FUNC_SET;
end
// EXTRA STATES ABOVE ARE NEEDED FOR RELIABLE PUSHBUTTON RESET OF LCD
FUNC_SET:
begin
LCD_E <= 1'b1;
LCD_RS <= 1'b0;
LCD_RW_INT <= 1'b0;
DATA_BUS_VALUE <= 8'h38;
!
17
(Group 3)
(Group 3)
(Group 3)
end
endcase
endmodule
module LCD_display_string(index,out,hex0,hex1);
input [4:0] index;
input [3:0] hex0,hex1;
output [7:0] out;
reg [7:0] out;
integer tempOutput;
// ASCII hex values for LCD Display
// Enter Live Hex Data Values from hardware here
// LCD DISPLAYS THE FOLLOWING:
//----------------------------//| Temperature(C)=
|
//| XX
|
//----------------------------// Line 1
//always@(Temp)
//tempOutput = Temp;
always
case (index)
5'h00: out <= 8'h54;//T
5'h01: out <= 8'h65;//e
5'h02: out <= 8'h6d;//m
5'h03: out <= 8'h70;//p
5'h04: out <= 8'h65;//e
5'h05: out <= 8'h72;//r
5'h06: out <= 8'h61;//a
5'h07: out <= 8'h74;//t
5'h08: out <= 8'h75;//u
5'h09: out <= 8'h72;//r
5'h0A: out <= 8'h65;//e
5'h0B: out <= 8'h28;//(
5'h0C: out <= 8'h43;//C
5'h0D: out <= 8'h29;//)
5'h0E: out <= 8'h3D;//=
// Line 2
//Converted temperature value
5'h10: out <= {4'h0,hex1};
5'h11: out <= {4'h0,hex0};
default: out <= 8'h20;
endcase
endmodule
References
!
20
(Group 3)
[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]
Additional References
[10]
!
21
N. Emmanuel, "Non-inverting operational amplifier - the Non-inverting opamp," Basic Electronics Tutorials, 2013. [Online]. Available: http://
www.electronics-tutorials.ws/opamp/opamp_3.html. Accessed: Dec. 11, 2016.
(Group 3)
[11]
[12]
"Temperature sensor using 741 OPAMP & LM35," 2028. [Online]. Available:
http://8051funkey.blogspot.qa/2014/08/temperature-sensor-using-741-opamplm35.html. Accessed: Dec. 11, 2016.
[13]
[14]
A. 01, "Using analog temperature sensors with ADCs - application note - maxim,"
2001. [Online]. Available: https://www.maximintegrated.com/en/app-notes/
index.mvp/id/571. Accessed: Dec. 11, 2016.
[15]
[16]
[17]
[18]
[19]
[20]
(Group 3)
[21]
vb. S. 2011, "How to read ADC0804 into 89S52," Forum for Electronics. [Online].
Available: http://www.edaboard.com/thread252180.html. Accessed: Dec. 11,
2016.
[22]
[23]
!
23