Digital thermometer project in Assembly, using an FPGA board and VHDL PDF

Title Digital thermometer project in Assembly, using an FPGA board and VHDL
Author Adrian Rakk
Pages 30
File Size 393.9 KB
File Type PDF
Total Downloads 136
Total Views 915

Summary

Blekinge Institute of Technology (BTH) Digital Design and Microprocessors (ET1123) Digital Thermometer project June 2013 Group members: Adrian Rakk Mehenni Sadaoui Table of content 1. Introduction ..........................................................................................................


Description

Blekinge Institute of Technology (BTH)

Digital Design and Microprocessors (ET1123) Digital Thermometer project June 2013

Group members: Adrian Rakk Mehenni Sadaoui

Table of content

1. Introduction ................................................................................................................................. 3 2. Project description and requirements .......................................................................................... 3 3. Theory ......................................................................................................................................... 4 3.1. Temperature sensor .............................................................................................................. 4 3.2. Voltage converter ................................................................................................................. 5 3.3. Microcontroller..................................................................................................................... 7 4. Design and implementation ........................................................................................................ 8 4.1. Schematic of the digital thermometer board ........................................................................ 8 4.2. Circuit board soldering and mounting of sensor ................................................................ 10 4.3. Functional test of the digital thermometer board ............................................................... 10 4.4. Programming the microcontroller (Assembly) .................................................................. 11 4.5. Programming the FPGA board (VHDL) ............................................................................ 12 5. Manual ...................................................................................................................................... 14 5.1. Operation ............................................................................................................................ 15 5.2. Characteristics .................................................................................................................... 15 5.3. Precautions ......................................................................................................................... 16 6. Results ....................................................................................................................................... 16 References ..................................................................................................................................... 17

1

Abstract The project is about to realize a digital thermometer that can measure and display the real time temperature. The thermometer board is supposed to transmit the data through a serial port to the receiver, which is an FPGA board with a seven segment display. The project consisted of two different parts, the hardware and the software part. In the hardware part we managed to build a digital thermometer with a serial port, a microcontroller, a voltage converter and a temperature sensor on board. In the software part we did the programming of the microcontroller and the FPGA board. We used assembly language to program the microcontroller and VHDL language to write a code for the FPGA board in order to establish communication between them. Keywords: digital thermometer, microcontroller, duty cycle, voltage converter, RS-232 communication

2

1. Introduction A thermometer is a device that measures temperature using a variety of different principles. Thermometers have two important elements: the temperature sensor in which some physical change occurs with temperature, plus some means of converting this physical change into a numerical value. The traditional thermometer is a glass tube with a bulb at one end containing a liquid which expands in a uniform manner with temperature. The tube itself is narrow and has calibration markings along it. The liquid in most of the cases is mercury, but alcohol thermometers are also used. These type of thermometers are still widely used, but not in the industry, where frequent monitoring and readings of high precision values are very important. Since compact and inexpensive methods of measuring and displaying temperature became available, digital thermometers have been used. A digital thermometer operates based on the same principles, but it offers significant benefits compared to the older glass tubes. The thermistor in a digital thermometer acts as a temperature sensitive electric resistor. At low temperatures, the thermistor does not conduct electricity, but as its temperature rises, the state of the thermistor changes and it becomes more and more conductive. A simple and inexpensive microcontroller inside the thermometer determines the temperature of the thermistor by measuring its electric resistance. The microcontroller then generates a digital signal, which is proportional to the temperature. This signal is usually displayed on a liquid crystal-based screen. In this report we try to explain all the steps that we did during our project starting from the soldering of the digital thermometer board to the programming of the microcontroller. The programming part is explained in more detail. We also provide a brief explanation about the main components that were used to build our digital thermometer.

2. Project description and requirements The main goal of the project is to build and do the programming of a digital thermometer, which displays the real time temperature in Celsius. An SMT160 TO92 linear response temperature sensor is connected to an ATtiny 2313 microcontroller, which transmits the data through a standard serial port to a Spartan3E-500 FPGA board and displays the temperature on its seven segment display.

3

For this task the use of two different programming languages are required. The software used for programming the microcontroller is called AVR Studio and the code is written in assembly language. For programming the FPGA board we used the software called Xilinx ISE and the code is written in VHDL language. The following list contains the bill of materials: •















1 µF capacitors (5 pieces) Power supply Reset button RS-232 serial port Smartec SMT160 TO92 digital temperature sensor Maxim 232 CPE voltage converter Atmel ATtiny 2313 microcontroller Xilinx Spartan3E-500 FPGA board

3. Theory In this part we provide a brief introduction of the main components and explain why do they play a significant role in our project. We also try to give a basic theoretical background that is required in order to understand the concept behind these components.

3.1. Temperature sensor The SMT160 TO92 is a sophisticated full silicon temperature sensor. The sensor has a digital output, which can be directly connected to the digital input of all kinds of microcontrollers without the need of an analogue to digital conversion. The supported temperature range is from -45 to +130 degrees with an absolute accuracy of ±0.7 in Celsius. The sensor has 3 pins: the third pin should be connected to ground, the second to a 5V power supply and the first pin generates the digital signal. The output of the sensor is the duty cycle.

4

Figure 1: Period and pulse width The duty cycle is directly related to the temperature and it is the quotient of pulse width and period. If we want to obtain the duty cycle in percentage, then the quotient should be multiplied by 100. According to Figure 1 the period is the time between two positive edges and the pulse width consists of one positive edge and one negative edge. It can be also interpreted that the pulse width is the high time and the period is the high time plus the low time. Therefore the period should always be greater or equal than the pulse width. We can summarize all of this with the following formula: Duty cycle =

puse width period

, where period ≥ pulse width. The duty cycle is a

positive number between 0 and 1 or between 0 and 100 in percentage. To calculate the temperature we need to use the following formula, which is given in the user manual of the temperature sensor: Temperature =

duty cycle − 0.32 0.0047

, where the temperature is in

Celsius degrees. Based on this if the duty cycle is 0.32 or 32%, we can easily calculate that the temperature is 0 Co. The valid duty cycle range of the sensor is between 10.85% and 93.1% with respect to the formula, which corresponds to the temperature range from -45 to +130 Co.

3.2. Voltage converter The Maxim 232 CPE is designed for standard RS-232 communication, which converts the +5V input voltage to ±10V. This integrated circuit contains two drivers and two receivers to adapt the RS-232 signal voltage levels to TTL logic. The following diagram on the next page shows the pin layout of the device:

5

Figure 2: Maxim 232 CPE voltage converter pinout The voltage converter requires 5 external capacitors with the capacity of 0.1 µF or 1 µF. The pins marked with C represent the connectors for capacitors. The voltage pump is marked with V+, which creates a +10V output voltage, and V- is the output of the voltage inverter, which is -10V. The two driver inputs are T1 in and T2 in , both of them receives a TTL signal from the microcontroller and another two drivers produce the RS-232 output signal, namely T1 out and T2 out . The two receiver inputs R1 in and R2 in convert an incoming RS-232 signal to a classic TTL signal with the help of R1 out and R2 out that can be interpreted by the microcontroller. In our project we used R1 in and R1 out to receive the data, and T1 in and T1 out for transmission. The pin called GND is connected to ground and the Vcc pin to a 5V power supply. During the serial communication different voltage levels represent logic zeros and ones. A negative voltage level is used for a 1 and a positive voltage for a 0. The RS-232 standard defines an asynchronous communication, where bits are transmitted one at a time. The voltage ranges are between -15V and -3V to transmit a binary 1, or between +3V and +15V to transmit a binary 0, so the total range is ±15V. On the other hand the classic TTL computer logic operates between 0V and +5V. Approximately a voltage between 0V and +0.8V is referred to as low for binary 0, and between +2V and +5V for high binary 1. So the maximum RS-232 signal levels are far too high for computer logic electronics, and the negative serial voltage cannot be interpreted at all by the TTL logic. To receive data from an RS-232 interface the low logic voltage has to be reduced, and the high logic voltage needs to be inverted. To send data the low logic voltage has to be pumped up and a negative voltage level needs to be generated. 6

3.3. Microcontroller The Atmel ATtiny 2313 is an 8-bit microcontroller with 2048 bytes of non-volatile flash memory. This is the program memory, which can be easily erased or reprogrammed ten thousand times. The architecture has two main memory spaces, the previously mentioned program memory and the data memory space. It is based on the Harvard architecture, because the program and the data are stored in separate physical memory systems that appear in different address spaces. The data memory consists of 32 general purpose working registers, 64 input/output registers and 128 bytes of internal SRAM. Moreover the microcontroller features an additional 128 bytes of EEPROM memory for semi-permanent data storage. This is a non-volatile memory like flash, EEPROM can maintain its content when electrical power is removed. It can be accessed the same way like an external peripheral device, using special pointer registers and read/write instructions, which makes the access time of the EEPROM much slower than other internal RAM. The ATtiny 2313 is using a calibrated internal oscillator to generate a clock frequency of 8 Mhz by default. The microcontroller operates between 2.7 and 5.5 volts, it offers low power consumption and high processing speed. The following diagram shows the pin layout of the device:

Figure 3: Atmel ATtiny 2313 microcontroller pinout As you can see on Figure 3 the microcontroller has altogether 20 pins, but we used only 6 of them in our project, so we will focus on those. The first pin (PA2) is the reset input, the bar above it represents a complement sign, which means that it will reset the microcontroller only if it receives a logical 0. PD0 is the UART data receiver input and PD1 is the UART data 7

transmitter output. Both of these pins are connected to the voltage converter and they either receive or generate a classic TTL signal. The pin called GND is connected to ground and the Vcc pin to a 5V power supply. The last pin we used is PD6, the input capture pin. This receives the duty cycle, which is generated by the temperature sensor. We can use a built-in timer that is directly clocked by the system clock of the microcontroller for capturing the pulse width and the period to calculate the duty cycle. This step is necessary because the device cannot interpret the received duty cycle automatically.

4. Design and implementation In this part we provide the schematic diagram of the digital thermometer and we briefly explain the connections between the main components. The last part of this chapter covers how we managed to calculate the temperature with the microcontroller and display it on the FPGA board.

4.1. Schematic of the digital thermometer board Before we started building the board we created the following schematic:

Figure 4: Schematic of the digital thermometer 8

The third pin of the temperature sensor is connected to ground and the second to a 5V power supply. The output of the sensor is connected to pin 11 (PD6) on the microcontroller, which is the input capture pin with a built-in timer. This way we can achieve a better accuracy than using a conventional digital input pin to capture the pulse width and the period. The first pin of the microcontroller is connected to a reset button, which is grounded. The second pin (PD0) receives TTL signal from pin 12 (R1 out ) of the voltage converter, which was originally an RS-232 signal coming from the serial port. The third pin (PD1) is transmitting data in TTL logic to pin 11 (T1 in ) on the voltage converter, which will be converted to an RS-232 signal later on. Evidently the last two pins of the microcontroller, pin 10 (GND) is connected to ground and pin 20 (Vcc) to a 5V power supply. According to Figure 4 one driver and one receiver is used on the voltage converter. It is important to point out that that the role of the receiver and transmitter pins are switched on the serial port. This means that pin 3 (TD) of the serial port receives an RS-232 signal from another device, which goes to pin 13 (R1 in ) on the voltage converter, and it is sent to the microcontroller as a TTL signal via pin 12 (R1 out ). The dataflow changes when the microcontroller transmits a TTL signal to pin 11 (T1 in ) on the voltage converter, and it is sent as an RS-232 signal to pin 2 (RD) on the serial port via pin 14 (T1 out ). If we connect our serial port devices together, then the digital thermometer’s receiver pin goes to the FPGA board’s receiver pin and the transmitter pin goes to the other equipment’s transmitter pin, see Figure 5 below:

Figure 5: Straight through RS-232 connection As the role of the receiver and the transmitter pins are switched, the digital thermometer’s receiver pin transmits data to the FPGA board’s receiver pin and vice versa. This makes it possible that the two devices are able to communicate with each other without using any cable. 9

4.2. Circuit board soldering and mounting of sensor The following picture illustrates the final result of the schematic:

Figure 6: Digital thermometer board

4.3. Functional test of the digital thermometer board A test code was written to analyze the functionality of the digital thermometer board. The microcontroller on the board was transmitting fixed data through the serial port in the form of ASCII characters. The board was connected to the serial port of a computer with an RS-232 cable. We managed to receive the data on the computer with the use of a software called Terra Term. The output of the board could be also seen on an oscilloscope. This code can be found in the appendix.

10

4.4. Programming the microcontroller (Assembly) The instruction set of the microcontroller doesn’t support floating numbers, so the formula was modified in order to calculate the temperature in assembly, which has the following form: Temperature =

(duty cycle · 10000 ) − 3200 47

, where the temperature is in Celsius degrees. Both the

numerator and the denominator are multiplied by ten thousand, so the result remains unchanged. The following steps describe the calculation process of the temperature: I. Capturing the pulse width and the period For this purpose we used the input capture pin (ICP) of the microcontroller with a 16 bit timer/counter called TCNT1. In addition two control and status registers were used, namely TCCR1A with a normal timer mode and TCCR1B with noise cancellation, variable edge detection and with a prescaler. An input capture flag (ICF1) is monitored in register TIFR to see if the desired edge has arrived. First we look for a positive edge and upon the arrival of the edge both the 16 bit counter and the input capture flag are reset. In the next step we need to look for a negative edge and if the edge has arrived, then the content of the timer is stored as pulse width before it is reset with the input capture flag. In the last step we look for a positive edge, upon the arrival of the edge the content of the counter is stored as the time between the negative and the positive edge. To obtain the period we need to add this time with the pulse width, see Figure 1. At this point both the pulse width and the period are considered to be 16 bit numbers. II. Multiplying the pulse width by 10000 After we have successfully captured the pulse width, which is stored as a 16 bit number, it has to be multiplied by ten thousand. For this purpose a 16 by 16 bit multiplication subroutine is used and the result is stored in four general purpose registers as a 32 bit number. III. Calculating the duty cycle In order to calculate the duty cycle we need to divide the result of the previous operation by the period. To do this a 32 bit by 16 bit division subroutine is used. As the valid duty cycle range of the sensor is between 0.1085 and 0.931, the result of this operation can be between 1085 and 9310, which is a 16 bit number. At this point we have the duty cycle multiplied by ten thousand.

11

IV. Calculating the numerator To calculate the numerator we need to subtract 3200 from the duty cycle of the previous operation. For this purpose a 16 bit subtraction subroutine is used. If the duty cycle is bigger than 3200, then the result is the duty cycle minus 3200 and a positive sign flag is set. If the duty cycle is smaller than 3200, then the result is 3200 minus the duty cycle and a negative sign flag is set. So the result of the subtraction will be always positive, just the sign flag changes in another register. V. Dividing the numerator by 47 In spite of that the numerator is not a 32 bit number, we can still use the 32 bit by 16 bit division subroutine once again, where the divisor is 47. The result of this operation is always an 8 bit number. VI. Transmitting the temperature The temperature is sent as one byte to the FPGA board, where the highest order bit is the sign bit. This means that theoretically we can send temperature values from -127 to +127. The frame format consists of 1 start bit, 1 stop bit and 8 data bits. The frames are transmitted at the speed of 9600 bps.

4.5. Program...


Similar Free PDFs