USB Temperature Sensor for Medical Applications Semester Thesis Fall 2010 Thomas R¨uttimann
Felix Schulthess
Department of Electrical Engineering and Information Technology
Advisor: P´eter Baki Supervisor: Prof. Dr. G´abor Sz´ekely January 5, 2011
Abstract Minimal-invasive surgery today still lacks haptic feedback. A first step to remedy this drawback is the enhancement of surgical tools with three-dimensional force sensors. However, these sensors depend on the temperature of the measurment environment. This work presents a temperature sensor that can be used to measure temperature at the tip of surgical tools in order to account for the temperature dependence of the force sensors.
For this purpose, two circuits boards were developed. The circuit board responsible for temperature measurement features three different solutions for reading a thermocouple value. To demonstrate reliability and precision of the values, a temperature control was implemented under utilization of a second board with a fan and a heating element. Evaluation of the measurement results shows that an application in the medical field is feasible.
I
Acknowledgements Being able to do a hands-on hardware design project is a rare gift during the master studies of electrical engineering at the university. We really enjoyed working on our semester thesis and would like to thank the Computer Vision Lab that it was possible to do such a project there. Especially, we are thankful for the support P´eter Baki gave us throughout the project. His experience with analog circuits and PCB design was of great value to us. A very special thank goes to the nameless venetian salesmen who first brought coffee to Europe. Their contribution to this work (and supposedly to an innumerable set of others as well) can not be appreciated enough.
III
Contents 1
Introduction 1.1 Problem Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2 Organization of this Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
Hardware 2.1 System Overview . . . . . . . . . . . . . . 2.1.1 Microcontroller . . . . . . . . . . . 2.1.2 Data Acquisition and Preprocessing 2.1.3 Power Supply . . . . . . . . . . . . 2.1.4 Communication Channels . . . . . 2.1.5 Temperature Control . . . . . . . . 2.2 Design Considerations . . . . . . . . . . . 2.2.1 Microcontroller . . . . . . . . . . . 2.2.2 Data Acquisition and Preprocessing 2.2.3 Communication Channels . . . . . 2.2.4 Temperature Control . . . . . . . .
3
4
5
1 1 2
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
3 . 3 . 4 . 4 . 5 . 5 . 6 . 7 . 7 . 8 . 10 . 11
Software 3.1 Temperature Measurement and Control . . . . . . 3.1.1 Temperature Measurement and Conversion 3.1.2 Closing the Control Loop . . . . . . . . . 3.2 Communication via USB . . . . . . . . . . . . . . 3.2.1 USB Overview and Technical Terms . . . . 3.2.2 Communication System . . . . . . . . . . 3.2.3 Operation of the USB Host Software . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
13 13 13 14 16 16 18 21
. . . . .
23 23 24 24 24 25
. . . . . . . . . . .
. . . . . . . . . . .
Measurement Results 4.1 Evaluation of Sensor Solutions . . . . . . . . . 4.2 Evaluation of Heating and Cooling Performance 4.2.1 Heating with the IRL530N . . . . . . . 4.2.2 Arctic Cooling? . . . . . . . . . . . . . 4.3 Discussion of Temperature Control . . . . . . . Conclusion
. . . . . . . . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
29 V
A A.1 List of Commands . . . . . . . . . . . . . . . . A.2 Circuit Schematics and Board Layouts . . . . . A.2.1 Heat Control Board . . . . . . . . . . . A.2.2 Temperature Measurement Board . . . A.3 Pictures . . . . . . . . . . . . . . . . . . . . . A.4 Code Snippets . . . . . . . . . . . . . . . . . . A.4.1 Using the SPI . . . . . . . . . . . . . . A.4.2 Sampling the Analog Channels . . . . . A.4.3 Generating the PWM Heating Signal . A.4.4 Generating the PWM Fan Signal . . . . A.4.5 Sending Data via USB . . . . . . . . . A.4.6 Plotting Temperature Curves in Matlab
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
31 31 32 32 33 35 35 35 36 37 38 38 40
List of Figures 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9
Block Diagram of the System and its Different Components Microcontroller Pinout . . . . . . . . . . . . . . . . . . . . Schematic of the MAX6675 . . . . . . . . . . . . . . . . . Schematic of the AD595 . . . . . . . . . . . . . . . . . . . Schematic of the LTC2053 with separate CJ-Compensation . Schematic of the USB Connector . . . . . . . . . . . . . . . Schematic of the USART-RS232 Level Shifter . . . . . . . . Schematic of the ISP Interface . . . . . . . . . . . . . . . . Schematic of the Heat Control Board . . . . . . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
3 8 8 9 9 10 11 11 12
3.1 3.2 3.3 3.4 3.5
Diagram of PWM Signal Generated by Timer 0 . . . Diagram of PWM Signal Generated by Timer 2 . . . Control Structure . . . . . . . . . . . . . . . . . . . Schematic View of the USB Communication System A Screenshot of tempsens.exe During Runtime .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
14 15 16 19 22
4.1 4.2 4.3 4.4 4.5
Step Response With Different Measurement Methods . . . Distribution of Measurement Results for the three Methods Cooling Down From 100 ◦ C . . . . . . . . . . . . . . . . Step Response of the MAX6675 . . . . . . . . . . . . . . Following a Setpoint Curve . . . . . . . . . . . . . . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
23 24 25 26 27
A.1 A.2 A.3 A.4 A.5
Schematic of the Heat Control Board . . . . . . . . . . Board Layout of the Heat Control Board . . . . . . . . Schematic of the Temperature Measurement Board . . Board Layout of the Temperature Measurement Board Pictures of the Hardware and PWM Signal . . . . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
32 32 33 34 35
. . . . .
. . . . .
. . . . .
. . . . .
VII
List of Tables 3.1
Comparison of USB Transfer Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
A.1 List of Commands for Transmission Over USB or Serial Port . . . . . . . . . . . . . . . . . 31
IX
Chapter 1
Introduction Design of modern surgical equipment is a demanding challenge from an engineer’s point of view. Their field of application dictates the highest standards in terms of reliability and precision. A group of tools that is of special importance to modern surgical methods are the tools for minimal-invasive techniques. State-of-the-art tools for minimal-invasive surgery do not feature haptic feedback. Such an instrument with real-time haptic feedback would be a great improvement since surgeons are trained to rely not only on what they see but also on what they feel when working with traditional surgical instruments (scalpels, ...). A minimal-invasive instrument with haptic feedback could combine the advantages of both traditional and modern surgery. A first step to equipping an instrument with haptic feedback is the reliable measurement of force at the far end of the instrument. This can be achieved by adding miniature strain gauges to a small probe. These change their electrical resitance when strained or compressed and therefore provide a way to measure the force. However, the result is not independent of the temperature of the environment. Since some surgical methods transfer heat to the surrounding tissue, this dependence must be taken into consideration. One example for such a method is minimal-invasive heart ablation which can be used to treat heart arrythmias [13]. If the temperature is measured accurately, it can be used to infer the true force vector. This in turn, can then be utilized to drive a input device that is able to give haptic feedback to the surgeon. This work documents the semester project at the Computer Vision Lab during which a prototype was created that is able to measure temperature reliably with a thermocouple and transfer the results to a computer over the Universal Serial Bus. Furthermore, a control loop was built to demonstrate the usability of the measurement values provided.
1.1
Problem Description
The aim of this project is the development of a temperature measurement device that satifies the following requirements: • Temperature shall be measured continuously and reliably. Various solutions of reading the thermocouple input shall be evaluated. • Values shall be transferred to a Computer running Microsoft Windows via the Universal Serial Bus. 1
C HAPTER 1. I NTRODUCTION • A control loop shall be implemented in order to evaluate measurement performance. Cooling and heating the measurement point is necessary for this.
1.2
Organization of this Work
Before we dive into the hardware and software description of our work, a short overview of the organization of this document is given. Chapter 2 describes the two circuit boards we developed. The choice of components and other hardware design consierations are discussed. Complete schematics and board layouts are attached in A.2. Chapter 3 describes the software parts of the project. It is split into two parts dealing with temperature measurement/control in the beginning and software responsible for reliable USB communication afterwards. In the last chapter, the measurements that were conducted are discussed before we close with a short conclusion that sums up the contribution of our work and lists possibilities for further improvement.
2
Chapter 2
Hardware 2.1
System Overview
This section will describe the different functional blocks which make up the system, namely power supply, data aquisition, temperature control, several communication interfaces including USB and the microcontroller linking them. Figure 2.1 gives an overview by means of a block diagram of the complete system.
PC
5V
MAX6675 ISP-Interface
12V
Serial RX/TX 5V
USB
Interchangeable
5V
Reset & Programming buttons
K-Type Thermocouple
CPUFan
5V
AD595
12V SPI
AT90USB1287
PWM
Analog PWM
TC4427
N-Channel MOSFET
Analog
LTC2053
LT1025
Figure 2.1: Block Diagram of the System and its Different Components
3
C HAPTER 2. H ARDWARE
2.1.1
Microcontroller
The microcontroller is obviously the heart of the system. The choice fell on an Atmel AT90USB1287. It features an 8-bit RISC CPU of the AVR family and, what is crucial for the project, a USB-controller compliant with the USB 2.0 Specification. The choice was taken because of two main reasons: First, the USB controller was the only special requirement imposed by the problem description and there was nothing that would have justified a more complex solution. Second, the AT90USB1287 has already been used in other projects of the BIWI institute and it was therefore possible to get quick and profound support from the advisor if needed.
2.1.2
Data Acquisition and Preprocessing
Thermocouple An easy way to measure temperature is by using a thermocouple. Thermocouples consist of two wires made of different metal alloys. The wires are electrically connected at one end, the so-called warm junction, and electrically isolated on the other end, the cold junction. From a thermal point of view, the two wires are kept as much at the same level as possible by fabrication. Any temperature difference between the warm and cold junctions generates a differential voltage between the two wires of the cold junction. This is known as the Seebeck Effect. A more detailed description of the Seebeck effect and other physical aspects can be found in the first five chapters of [15]. Thermocouples can be categorized by the type of metals used for the two wires. Each combination of metals yields a different voltage response. Hence, thermocouples cover a large field of applications. For this project a K-Type thermocouple was used. The positive electrode of K-Type thermocouples is made up of chromel (90% nickel and 10% chromium) and the negative electrode of alumel (95% nickel, 2% manganese, 2% aluminium and 1% silicon). The measurement range goes from -270 ◦ C to +1370 ◦ C. The K-Type is the most common and inexpensive thermocouple type. Nonlinearity and Cold Junction Compensation The voltage-temperature-characteristic of thermocouples is nonlinear. For relatively small operating ranges this can normally be neglected, though; if the characteristic is approximated by a linear curve centered at (25 ◦ C , 1V), the error is roughly one percent at 50 ◦ C and two percent at 100 ◦ C. This lies within the acuracy margin of most thermocouple amplifiers, including the ones used in this system (see paragraph below). Another important aspect is the so-called Cold Junction Compensation. Since the thermocouple voltage represents only the temperature gradient along the two wires, it does not give an absolute value for the temperature of the probe. To get the desired output, one has to take the temperature of the cold junction, i.e. the measurement system into account. Normally, this is done by measuring the cold junction temperature with a thermistor or another thermally sensitive device. However, due to the nonlinearity of the output voltage, this temperature can not simply be added to the temperature corresponding to the thermocouple output voltage, but has to be tranlsated back into a voltage according to the characteristic of the type of thermocouple in use [15]. The sum of the two voltages can then be interpreted as the absolute temperature of the probe. Integrated devices that deal with Cold Junction Compensation are readily available on the market. When layouting a circuit, one has to take care not to introduce an additional temperature gradient between the actual cold junction and the compensation device, as this would introduce further inaccuracies into the measurement. 4
C HAPTER 2. H ARDWARE Data Preprocessing In the problem formulation phase of the project, it was decided that the preprocessing of the thermocouple output should be implemented three times. Each method should feature cold junction compensation and amplification. The result should then be fed into the microcontroller. These methods should then, in a later phase, be compared with each other. The main difference between the three concepts is the grade of integration. • The first method makes use of a Maxim MAX6675 chip which combines cold junction compensation, amplification and analog-to-digital conversion. The data is output in a 12-bit resolution, SPIcompatible format. The measurable temperature ranges from 0 ◦ C to 1024 ◦ C, which, together with the 12-bit output, results in a resolution of 0.25 ◦ C. The error on the output is guaranteed by the manufacturer to be no more than ±9 LSB over a range from 0 ◦ C to 700 ◦ C, given a supply voltage of 5V, which is equivalent to ±2.25◦ C [5]. • The device used in the second method is comparable to the MAX6657, except for the digitization functionality. The data is output as a standardized analog signal of 10 mV/ ◦ C. The device used is a AD595 Instrumentation Amplifier from Analog Devices. It is especially suited for K-Type thermocouple signals and features an on-chip Cold Junction Compensator. It’s linear output is calibrated around 25 ◦ C with maximal ±1 ◦ C calibration error and ±0.75 ◦ C gain error over a range from 0 ◦ C to 50 ◦ C [2]. • Finally, as a third option, the thermocouple signal can be preprocessed by a small network consisting of a high precision Instrumentation Amplifier and a separate Cold Junction Compensator, together with a small number of passive components for gain programming and noise filtering. The aforementioned devices are a LTC2053 amplifier and a LT1025 compensator, both from Linear Technology. The LT1025 measures the cold junction temperature and has several outputs which are matched to the characteristics of all common thermocouple types - also taking into account, their nonlinearities - as well as a 10 mV/ ◦ C standard output. The acuracy of this implementation has to be evaluated experimentally. It can be expected to be inferior to the performance of the other two alternatives, though, since the LT1025 alone has a guaranteed maximum error of ±2 ◦ C at 25 ◦ C and even slightly more than ±5 ◦ C at 100 ◦ C at the 10 mV/ ◦ C output [1]. This performance is further degraded by inacuracies in the voltage division at the other outputs and by the Amplifier.
2.1.3
Power Supply
One of the key features of the Universal Serial Bus is the possibility to supply a device with power. This is very attractive for the purpose of this project, since it reduces the whole wiring to one cable for power and data transfer. The power transmission over the USB is limited to 500 mA at 5 V, or, in other words, to 2.5 W. This is enough to supply most of the components used, except for the actuators of the temperature control loop, i.e. the heating and cooling devices. For those two devices, it was decided during the hardware design phase to use a separate 12 V supply. The considerations, which lead to this decision, although it conflicts strongly with the desire for a one-wire system, are described more profoundly in subsection 2.1.5.
2.1.4
Communication Channels
As mentioned before, the system is intended to work as a one-wire device. For proper functionality of the USB channel, the internal clock sources of the AT90 are not accurate enough. For this reason, an external 5
C HAPTER 2. H ARDWARE oscillator needs to be connected to the XTAL-Pins of the microcontroller. The communication between the user/PC and the device includes measurement results sent from the device to the PC and instructions from the PC to the device as well as data exchange for programming and debugging purposes. In addition to the USB channel, a simple three-wire serial channel to communicate via RS232 and a channel compatible with the serial AVR-In-System-Programmer (ISP) concept were also implemented for testing and debugging purposes while the work on the USB communication firmware was still in process. In fact, while the three-wire serial interface has been used extensively during the development of the system, the ISP option has not been used at all. It was implemented, however, because it is a convenient way to access certain low level fuse-bits on the microcontroller. To communicate with the controller via the three-wire serial interface, the following configurations have to be set: Baudrate 250 kBit/s; 8 Data Bits; no Parity Bit; one Stop Bit (see code snippet in A.4.1). Commands recieved either over the USB- or serial channel are handled by the same firmware routines. A list of one character commands can be found in Table A.1 in the Appendix to this document.
2.1.5
Temperature Control
The temperature control loop has two actuators; one to cool and one to heat the probe. These two components are not located on the sensor board itself, but on a separate board. As a cooling device, a fan is used, the heating is performed by controlled power dissipation of a MOSFET. Both devices are controlled by PWM signals. While this is a pretty straightforward operation for the MOSFET - The transistor is in saturation when the PWM signal is high and in cutoff when the PWM signal is low - the PWM operation of a fan is subject to some limitations. There are three posible ways to control the cooling performance of a fan. The first is to translate the PWM signal into an analog signal by means of a low pass filter and then apply this signal to the fan. The problem with this is that most fans do not operate reliably if the voltage is too low. Since the whole sensor board runs at 5 V provided by the USB, first priority was given to a solution with a 5 V fan. This class of devices, however, needs at least 3.5 V to 4 V to overcome the inertia of the propeller and work at all. On top of that, the fan speed at that voltage would be already close to the maximum speed. The control range with this method applied to a 5 V fan would therefore be very small. The next bigger class of fans run on a supply voltage of 12 V. With these, the control range would be considerably higher but still the fan speed could not be driven much lower than half of the maximum speed [9]. Moreover, one would have to boost the 5 V USB supply to 12 V. Because of power conservation, the 500 mA limitation on the USB power supply would translate roughly to a 200 mA limitation on the fan. Although there are 12 V fans available with nominal operating currents as low as 100 mA or even lower, at this point a solution with separate power supply for the control board was preferred. The risk of damaging the USB controllers on the device and host side by sourcing an overcurrent, caused for instance by a current peak during start-up of the fan, was considered to be too high. The fact that this solution undermines the one-wire concept, on the other hand, was given not too much importance, since a possible later implementation of the system in a medical device would not include any temperature control circuitry anyway. 6
C HAPTER 2. H ARDWARE The second and third fan control method both apply the PWM signal directly to the fan. This can be done either by switching the fan on and off according to the PWM signal. In this case, an additional transistor would be required to drive the fan. The last option would be to apply the PWM signal to a 4-wire fan with a PWM input. This class of devices has internal control circuitry that changes the fan speed according to the dutycycle of the signal applied to the PWM input. Based on the new situation in terms of power supply, a 12 V supply for the heating MOSFET and the fan was chosen, together with an ARCTIC F8 12 V PWM controlled fan from Arctic Cooling as this was considered the more elegant solution. Both PWM signals are buffered by a TC4427 dual MOSFET driver to protect the low impedance output pins of the microcontroller.
2.2
Design Considerations
In this section, the process of hardware design is elaborated step by step. A number of difficulties that occured during the design are covered as well as their respective solutions. The section will be focussing on the different functional blocks that were presented in the previous section. The power supply will not be treated in a separate section, but in the Communication/USB and Temperature Control sections. Each functional block description will be accompanied by the according extraxt of the circuit schematic. The entire schematic can be found in section A.2 in the appendix. As a development tool, the Altium Designer software package was used during hardware design. As we had no previous experience with this tool, we had to get acquainted with the use of it in parallel to the actual design. This fact was reflected in some difficulties and detours in the beginning of the process, which will not be further discussed.
2.2.1
Microcontroller
In Figure 2.2, the AT90 microcontroller and its pin assignment is depicted. On pins 23 and 24, the external crystal oscillator is connected. The values of capacitor C12 and C13 are in accordance with the recommendations of the AT90 Datasheet. On the right side of the controller, one can see the power supply circuitry: Note the connection between pin 8 (VBUS, connected to the 5 V line of the USB connector) and pins 21 and 52 (VCC) that indicates the power supply over the USB as well as the LC-filter to decouple the analog and digital circuitry. Those connections are in accordance with the recommendations of the AT90 Datasheet as well. Pins 27 and 28 are associated with the USART interface for serial communication, pins 4 and 5 are connected to the USB data lines, pins 60 and 61 are the input pins for the analog temperature data sent from the AD595 and LTC2053 ICs, pins 10 to 13 are associated with the SPI Bus, pins 14 and 17 are the PWM output pins for the temperature control circuit, pins 35 to 38 are driving four general purpose LEDs and pins 20 and 43 are inputs for the Reset and Hardware Boot signals. The two pins last mentioned can be set to ground by simple pushbuttons to execute a reset of the AT90 or activate the hardware bootloader, respectively. The latter function is necessary to access the internal flash memory when programming over USB. 7
100nF
100nF PIC201
COC1 C1
50 PIIC2050 49 PIIC2049 48 PIIC2048 47 PIIC2047 46 PIIC2046 45 PIIC2045 44 PIIC2044
C HAPTER 2. H ARDWARE
VCC
PA0/AD0 PA1/AD1 PA2/AD2 PA3/AD3 PA4/AD4 PA5/AD5 PA6/AD6 PA7/AD7
VCC
PIC205
GND AT90USB1287
OC2A 14 PIIC2014 PB4/PCINT4/OC2A 51 15 PIIC2051 PA0/AD0 PIIC2015 PB5/PCINT5/OC1A 50 16 PIIC2050 PA1/AD1 PIIC2016 49 PB6/PCINT6/OC1B PIIC2049 PA2/AD2 OC0A PIIC2017 48 17 PB7/PCINT7/OC0A/OC1C PIIC2048 PA3/AD3 47
PIIC2047
PIC202
52
VCC
COIC2 IC2
PDO/OC0B/SCL/INT0 PD1/OC2B/SDA/INT1 PD2/RXD1/INT2 PD3/TXD1/INT3 PD4/ICP1 PD5/XCK1 PD6/T1 PD7/T0
PA4/AD4
46 35 PC0 PIIC2046 PIIC2035 PA5/AD5 PC0/A8 45 PIIC204536PA6/AD6 PC1 PIIC2036 44 PC1/A9 PIIC2044 PC2 37PA7/AD7 PIIC2037 PC2/A10 38 SSPC3 10 PIIC2010 PIIC2038 PB0/SS/PCINT0 PC3/A11/T3 SCK PIIC2011 11 39 PB1/PCINT1/SCLK PIIC2039 PC4/A12/OC3C MOSI 12 40 PIIC2012 T_ALM PB2/PDI/PCINT2/MOSI PIIC2040 MISOPIIC2013 13 PC5/A13/OC3B 41PB3/PDO/PCINT3/MISO PIIC2041 PC6/A14/OC3A 42 PIIC2042 PC7/A15/IC3/CLK0
UVcc DD+ UGnd UCap VBus PE3/IUID
OC2A 14 PIIC2014 PB4/PCINT4/OC2A 15 PIIC201520PB5/PCINT5/OC1A RESET 16 PIIC2020 RESET PIIC2016 PB6/PCINT6/OC1B NLXTAL1 XTAL1 OC0A 17 24 PIIC2024 PIIC2017 XTAL1 PB7/PCINT7/OC0A/OC1C
XTAL2 PC0 35 43 PIIC2035 HWB PC0/A8 PIIC2043 PE2/ALE/HWB PC1 PIIC2036 36 PC1/A9 PC2 PIIC2037 37 PC2/A10 PC3 PIIC2038 38 PC3/A11/T3 XTAL 39 PIIC2039 PC4/A12/OC3C T_ALM 40 COC12 COC13 PIIC2040 PC5/A13/OC3B C12 C13 41 PIIC2041 PC6/A14/OC3A 42 PIIC2042 PC7/A15/IC3/CLK0 22pF 22pF
GND
GND COY1 Y1
1 PIY101
2 PIY102
RESET 20 PIIC2020 RESET NLXTAL1 XTAL1 24 PIIC2024 XTAL1 NLXTAL2 XTAL2 23 PIIC2023 XTAL2 HWBPIIC2043 43 PE2/ALE/HWB
PIC120222pF GND
PIC1301
COC13 C13
GND
PIC1302 22pF
8 PIIC208 9 PIIC209
PE0/WR PE1/RD NLAVCC AVCC
53
22
PIC20
PIC2053
22
PIC1201
PIC2053
GND
XTAL COC12 C12
PIC20 GND
PIC1302
PF4/ADC4/TCK 3 PIIC203 PF5/ADC5/TMS 4 DPIIC204 PF6/ADC6/TDO 5 D+ PIIC205 PF7/ADC7/TDI 6 PIIC206 7 UCAP AGND PIIC207
26 PIIC2026 27 CMOS_RX PIIC2027 28 CMOS_TX PIIC2028 29 PIIC2029 30 31 32
PIIC2030 PIIC2031
VCC
PIIC2032
3 PIIC203
VCC
4 DPIIC204 5 D+ PIIC205
NLMOSI MOSI
PIL102
2 MOSI VCC PICON102 4 GND PICON104 6 RES GND PICON106 8 COR2 R2 PICON108 NLD0 SCK GND D- PIR201 9 10 PICON109 MISO GND PICON1010 10uH COR4 NLD0 D+ R4 COCON1 CON1
PIJP101
6 PIIC206
3 COL1 L1 PICON103 N/C 5
RESET
9 PIIC209
PIL101
64 NLAVCC AVCC 62 PIIC2062 61 OUT_2 PIIC2061 60 OUT_1 PIIC2060 59 PIIC2059 58 PIIC2058 VCC 57 PIIC2057 56 PIIC2056 55 PIIC2055 PIL102 54 PIIC2054 63 COL1 GND L1 PIIC2063 33 34 PIIC2034 18 PIIC2018 19 PIIC2019 1 PIIC201 2 PIIC202
PE0/WR PE1/RD
33 34
PIIC2033
22R
PIR402
PICON203
PICON205
PIC901 GND PIC902
PIC10 1 PIC10 2
COC9 C9
COC10 C10 100nF
GND
GND
VCC
PIR2302
VCC
10uH
PIL101
COR2 R2 PIR201
22R
PIR202
COR4 R4
NLD0 22R D+ PIR401 AGNDPIR402
PICON202
PIC901
PIR2301
PICON201
NLfuck fuck
COCON2 CON2 PICON203
1uF
NLUCAP UCAP
PICON204
PICON205
PIC902
PILED501
PICON206
COLED5 LED5
COC9 C9
COC10 C10
COR23 R23 1k
USB_CONN_ETH
PILED502
100nF
GND
COR24 R24
AGND
PIIC2034
PICON202
1uF
NLUCAP UCAP
NLD0 D-
PIC10 1 PIC10 2
22R
PIR202
PIR401
PIIC2064
PIIC2033
USB_CON
PICON105 7 PICON107
NLSCK SCK NLMISO MISO
8 PIIC208
1
PIJP102 PICON101
GND
7 UCAP PIIC207
GND
GND
GND
GND
0R
PIR2401
18 PE4/INT4/TOSC1 PIIC2018 19 PIIC2019 GND PE5/INT5/TOSC2 1 PIIC201 PE6/INT6/AIN0 2 PE7/INT7/AIN1/UVcon PIIC202
PIR2402
COIC3A IC3A
AGND
GND NLOC0APIIC302 OC0A 2
In1 Out1
7 PICON4 1 PIIC307
2 PICON4
TC4427 COR24 R24
PIR2401
GND
COJP1 JP1
JUMPER2
53
PIC1301
PIC1202
GND
PIC1201
AVCC 26 PIIC2026 AREF 27 CMOS_RX PIIC2027 28 PF0/ADC0 CMOS_TX PIIC2028 29 PF1/ADC1 PIIC2029 30 PIIC2030 PF2/ADC2 31 PIIC2031 32 PF3/ADC3 PIIC2032
25 PIIC2025
GND
COY1 Y1
2 PIY102
25 PIIC2025
64 AVCC PIIC2064 62 AREF PIIC2062 61 OUT_2 PIIC2061 PF0/ADC0PE4/INT4/TOSC1 60 OUT_1 PIIC2060 PF1/ADC1PE5/INT5/TOSC2 59 PIIC2059 PF2/ADC2 PE6/INT6/AIN0 58 PF3/ADC3 PIIC2058 PE7/INT7/AIN1/UVcon 57 PF4/ADC4/TCK PIIC2057 56 PF5/ADC5/TMS PIIC2056 55 PF6/ADC6/TDO PIIC2055 54 PF7/ADC7/TDI PIIC2054 63 AGND PIIC2063
NLXTAL2 XTAL2 23 PIIC2023
1 PIY101
UVcc DD+ UGnd UCap VBus PE3/IUID
COC2 C2
VCC
21
PIC201
VCC GND GND GND GND
COCON1 CON1
PDO/OC0B/SCL/INT0 PD1/OC2B/SDA/INT1 PD2/RXD1/INT2 PD3/TXD1/INT3 PD4/ICP1 PD5/XCK1 PD6/T1 PD7/T0
100nF PIC201
MOSI N/C RES SCK MISO
PICON103
AT90USB1287
VCC
SS PIIC2010 10 PB0/SS/PCINT0 100nF SCK PIIC2011 11 PB1/PCINT1/SCLK PIC101 PIC102 MOSIPIIC2012 12 PB2/PDI/PCINT2/MOSI COC1 C1 MISOPIIC2013 13 PB3/PDO/PCINT3/MISO GND
1 3 5 PICON105 7 PICON107 9 PICON109
PIJP102 PICON101
RESET NLSCK SCK NLMISO MISO
GND
VCC
21
PIC205
52
PIC201
GND
COJP1 JP1
JUMPER2
PIJP101
COC2 C2
COIC2 IC2 51 PIIC2051
NLMOSI MOSI
PIC202
1
PIC102
2
PIC101
GND
GND
AGND
0R
COIC3B IC3B
PIR2402
NLOC2A 4 OC2A PIIC304
GND
In2 Out2
GND
5
1 2
PIIC305 PICON5
PICON5
TC4427
Figure 2.2: Microcontroller Pinout
2.2.2
GND
Data Acquisition and Preprocessing VCC 100nF
VCC
PIC1702 PIC1701
COC17 C17
VCC
PIR1802
100nF PIC1702 PIC1701
COC17 C17
GND VCC
AGND
JUMPER2
4
PIR2 01
PIIC603 0R
T+
PIR2 01
SCK
PIIC605
PIC601 PI C601
MISO PIJP202
NLS\S\ SS SCK
SCK
1
1
0R
GND VCC
COCON8 CON8
COJP2 JP2
PIR2 02
R22 COR22
PIR2 02
R22 COR22
AGND AGND
AGND
AGND
2 NLT002 T-_2 1 NLT002 T+_2
14 1
PICON702
PIIC5014
PICON701
PIIC501
PIR1901
COCON7 0R CON7
2 3 4 PIIC504 5 PIIC505 6
R19 PIIC502 COR19
PIR1902
PIIC503
PIIC506
11
IC5 COIC5
MAX6675
PIC501
PIR1901
IC5 COIC5 COR18 R18 14 -IN 20k 1 PIIC501 +IN PIR1801
PIR1802
PIIC5014
AD595 12 T_ALM NLT0ALM 0R PIIC5012 COCON7 +ALM -IN CON7 2 9 PIIC502 OUT_1+C NLOUT01 R19 COR19 +IN VO PIIC509 3 8 PIIC503 +T FB PIIC508 4 +C PIIC504 COM 10 5 PIIC5010 +T COMP PIIC505 -T COM 6 13PIIC506 -C -T -ALM PIIC5013 -C
PIR1902
PIC507
AGND
Figure 2.3: Schematic of the MAX6675 MAX6675: From a hardware design point of view, the MAX6675 is the simplest of the three implemented data acquisition methods, since it is the most integrated of the three. The thermocouple’s cold junction wires are plugged in CON8. The 0 Ω resistor between the positive thermocouple electrode and ground potential was designed to have a simple possibility to stabilize the thermocouple voltage by pulling one electrode to a reference potential, if needed. This procedure was not mentioned in the component’s data sheet, however and the resistor has in fact not been equipped because the IC works satisfactorily without it. The jumper JP2 is discussed later in subsection 2.2.3. 8
PIC501
V-
COIC6 IC6
PIC604
NLT001 2 T-_1 PIIC602 7 COIC6 IC6 2 MAX6675 SO PIIC607 PICON802 PIJP201 TCOJP2 1 6 JUMPER2 JP2 PICON801 PIIC606 NLT001 2 T-_1NLT001 2 7 CS MISO T+_1 5 PICON802 PIIC602 T-3 PIIC607 PIJP201 PIJP202 SO PIIC603 T+ 1 6 SCK PIIC605 COCON8 PICON801 CS PIIC606 CON8 NLT001 NLS\S\ T+_1 3 5 SS
2 NLT002 T-_2 1 NLT002 T+_2 PICON701 PICON702
V+
4
COC20 C20
AGND
V-
PIC604
AGND
7
COC20 C20 100nF PIC2001 PIC2002
11
100nF
PIR1801
AD595
12 9 8 PIIC508
+ALM VO FB
PIIC5012
COMP
PIIC5010
-ALM
PIIC5013
PIC507
7
PIC2001 PIC2002
VCC
V+
AGND
AGND
PIIC509
10 13
A
10M
PIR902
PIR901
PI
COR9 R9
AGND
PIR1302
1M
PIR1301
COR14 R14
1M
C HAPTER 2. H ARDWARE
COR13 R13
PIR1402 PIR1401
VCC 2 1
PICON602 VCC
PIC1702 PIC1701
MISO
PIJP202
NLD0 D+
PIR401
22R
PIR202
COR4 R4
22R
PIR402
PIC901
PIC902
COLED5 LED5
2
GND
GND
GND
PIK201
PIC1 01 PIC1 02
100nF
GND
10k
NLHWB HWB
PILED502
PIC507
COR3 R3
9 PIIC109
RX2
RXD2
330nF
C21 COC21
AGND
COIC7 IC7
GND
1 E 3 V_O 5 PIIC705 RPIIC701 PIIC703
PICON30 PICON302 PICON301
AGND LT1025
J K,T R,S
PIC704
GND
COCON3 CON3
COC11 C11
Figure 2.4: Schematic of the AD595
GND GND
GND
AD595: The AD595 does not require much additional circuitry either. In contrast to the MAX6675 de- AGND NLPC0 NLPC1 NLPC2 NLPC3 scribed before,COIC3Athe positive input pin of the AD595 was connected to ground potential after the input was PIR502 PIR602 PIR702 NLOC0A traced with an oscilloscope and was discovered to oscillate extensively. In thisPIR802 case, the procedure was also PIR501 PIR601 PIR701 PIR801 recommended by the manufacturer [2]. The features an alarm signal that indicates if one of the COCON4 PI C306 AD595 PIC1402 P I L E D 1 0 1 P I L E D 2 0 1 P I L E D 3 0 1 PILED401 thermocouple leads is disconnected. For this alarm circuit to operate properly, pin 13 must be no higher PIC1401 COIC3B P I L E D 1 0 2 P I L E D 2 0 2 P I L E D 3 0 2 P I L E D 4 0 2 than 1 V, so it is connected to ground. PinPI C30 12 on the other hand must be connected to a pull-up resistor and NLOC2A is actively driven low by the AD595 in case of an alarm. The functions of pins 2,3,5,6,8 and 10 are not COCON5 important for our application and are handled as recommended. PC0
7 PICON401 1 PIIC307 2 PICON402
CON4
PC3
COR5 R5
COR6 R6
COR7 R7
COR8 R8
1k
1k
1k
1k
1
1
1
1
COIC3C IC3C
GND
IC3B
100nF
TC4427
0R
COC14 C14
COLED1 LED1
TC4427
COLED2 LED2
COLED3 LED3
COLED4 LED4
2
5 1 In2 Out2 PIIC305PICON501 2 PICON502
2
OC2A 4 PIIC304
2
GND
2
3
PIR2402
PC2
6
In1 Out1
- +
OC0A 2 PIIC302
PC1
VCC
IC3A
CON5
TC4427
GND
GND
GND
VCC 100nF 10M
PIR902
10M
PIR901
PIR1002
COR9 R9
PIR1001
PIC1502 PIC1501
COR10 R10
PIR1401
PIC1702 PIC1701
COC17 C17
12 T_ALM NLT0ALM +ALM PIIC5012 9 OUT_1 NLOUT01 VO PIIC509 8 FB PIIC508 COMP
10 PIIC5010
-ALM
PIIC5013
13
PIC507
PIR1702
2
3
10nF
PIIC403
-IN
+IN
V+
PIR1701
10k 10k
COR15 PIC16LTC2053 01 PIR1502 R15
100nF
COC16 C16
OUT
PIC1602
7
PIIC407
PIR1201
R12 COR12
AGND
249k
PIR1501 NLOUT02 OUT_2
PIC401 PIC405 PIC40
COC19 C19
100nF PIC2102 PIC2101
PIC702
C21 COC21
AGND
COIC7 IC7
1 E 3 V_O 5 PIIC705 RPIIC701 PIIC703
AGND LT1025
AGND J K,T R,S
COR20 R20 8 COR21 R21 7 6 PIIC706
0R 0R
PIIC708 PIR2001
PIR2002
PIIC707 PIR2101
PIR2102
NLLTC20530REF LTC2053_REF
PIC704
4
7
PIR1902
V-
R19 PIIC502 +C COR19
PIC1901 COC18 C18 PIC1902 10nF
PIR1602 PIIC402
1k PIR1202
5
11
20k
PIR1801
AD595
2
2 3 PIIC503 +T 4 PIIC504 COM 5 PIIC505 -T 6 PIIC506 -C
PIC501
PIC1801 PIC1802
VCC
V_IN
PIR1901
IC5 COIC5 14 PIIC5014 -IN 1 PIIC501 +IN
COCON6 CON6 COR18 R18
GND
2 NLT002 T-_2 PICON702 1 NLT002 T+_2 PICON701
V+
AGND
PIR1802
COR16 R16 COR17 R17
REF
100nF
PIR1601
PIR1102
4
NLT003 2 T-_3 NLT003 1 T+_3 PICON601
PIC408 PIC406 6
VCC
PIR1101
COIC4 PIR1 03 IC4
8
COR14 R14
PICON602
COR11 100R R11 AGND
EN Rg
PIR1301
COR13 R13
COC15 C15
PIR1402
1M
V-
1M
1
PIR1302
AGND
OCON7 0R CON7
PIC702
PIC602
COC6 C6
2
PIC601
COC5 C5
PIC2102 PIC2101
8 PIIC108
GND
AGND
AGND
Title
Size AGND
Number
Revision
A3 Date: File:
1
CO C
100nF PIC502
PI C1015
PIK202
COK2 K2
PIC1901 PIC1902
10nF
COC18 C18
330nF PIC501
V-
PIR301
PILED501
PICON206
COC9 C9
COC10 C10
PIR302
NLfuck fuck
COCON2 CON2 PICON204
PICON205
GND
ND
PICON201
PICON203
1uF
NLUCAP UCAP
R24 24
PICON202
PIR1801
VCC
PIR2301
100nF
COR2 R2 PIR201
1
10uH
NLD0 D-
COR23 R23 1k
USB_CONN_ETH
PIL101
2401
PIR2302
VCC
COL1 L1
GND
4
PIL102
VCC
PIC1801 PIC1802
VCC
20k ST3232CD
PIR1902
NLS\S\ SS SCK
PIIC605
COCON6 CON6
100nF
3 2 1
7 6 PIIC606 5
PIC501
PI
COR18 R18PIC302
1 PIIC101 C1+ IC5 PIC401 PIC402 AD595 COIC5 COC4 C4 14 12 T_ALM 2 NLT0ALM PIIC5014 -IN PIIC5012 V+ PIIC102 3 6 330nF +ALM PIIC103 C1PIIC106 1 9 OUT_1 VNLOUT01 PIC701 4 PIIC509 PIIC501 +INPIC801 PIC802 VO PIIC104 C2+ P I R 1 9 0 1 8 COC7 PIIC508 C7 COC8 FB C8 PIC702 CON7 COCON7 0R 2 5 R19 PIIC502 +C COR19 PIIC105 C2-10 3 PIIC503 +TNLCMOS0TX COMP PIIC5010 GND GND CMOS_TX 11 14 PIIC1011 TX1 4 TXD1 PIIC1014 PIIC504 COM 5 13 10 7 PIIC1010 TX2 TXD2 PIIC107 PIIC505 -T PIIC5013 -ALM 6 NLCMOS0RX 12 13 PIIC506 -CCMOS_RX PIIC1012 RX1 RXD1 PIIC1013
2 PIK102NLT002 T-_2 PICON702 COK1 K1 1 NLT002 T+_2 PICON701
PIK101
C R C R
PI
PIC301
COC3 C3
PI C1016
COIC1 IC1
47nF
GND
JUMPER2
PIC10 2
100nF
GND
PIR1802
AGND
PIR101
NLR\E\S\E\T\ RESET
COJP2 JP2
PIIC607PIJP201
COR1 R1 10k
COCON1 CON1
MAX6675
DPIC10 1
PIR102
PICON104
16
2 4 6 PICON106 8 PICON108 10 PICON1010 PICON102
11
VCC GND GND GND GND
15
AGND
MOSI N/C RES SCK MISO
V+
PICON103
7
1 3 5 PICON105 7 PICON107 9 PICON109
PIJP102 PICON101
RESET PIC2001 PIC2002 NLSCK SCK NLMISO MISO COC20 C20
SO VCC CS SCK
COC17 C17
VCC
VCC
COJP1 JP1
V_IN
100nF
VCC JUMPER2
NLMOSI MOSI 100nF PIJP101
GND
C
PICON601
NLT003 T-_3 NLT003 T+_3
12/21/2010 Sheet of C:\medical instrumentation\..\tempsens.SchDoc Drawn By:
Figure 2.5: Schematic of the LTC2053 with separate CJ-Compensation LTC2053 with LT1025: The design of this data acquisition block is based on a design note released by the manufacturer, Linear Technology [14]. The thermocouple is plugged in CON6. The RC-filters on the input lines are suggested to absorb radio frequency pickup and suppress sampling artifacts from appearing 9
COR20 R20 8 COR21 R21 7 6 PIIC706 PIIC708 PIR2001 PIIC707 PIR2101
C HAPTER 2. H ARDWARE on the thermocouple leads. The high impedance network of R9, R10, R13 and R14 biases both input lines to half the supply voltage in order to maximize common mode immunity. The resistor network at the output of the amplifier is for adjusting the gain such that the output voltage matches the 10 mV/ ◦ C standard. The capacitor C16 in the feedback path is to roll-off the response of the amplifier part of the LTC2053, i.e. to dampen high frequency parts. The output signal of the LT1025 Cold Junction Compensator which is matched to the K-Type thermocouple characteristic, is fed to the REF input of the LTC2053. By equipping R20 instead of R21, the amplifier-compensator-unit can be configured for a J-Type thermocouple. This feature has so far never been profited of, however. VCC
The behaviour of the output of the whole block is described by the following formula: NLMOSI MOSI
10k
PIR101
where VOU T is the output signal, VIN is the differential input signal and VREF is the voltage appliedPIK101to the PIK102 COCON1 CON1 NLR\E\S\E\T\ RESET COK1 K1 REF pin for Cold Junction Compensation. GND
27 CMOS_RX PIIC2027
PIC701 PIC702
28 CMOS_TX PIIC2028
2.2.3
GND
VCC
7 UCAP PIIC207 8 PIIC208 9 PIIC209
10uH
PIL101
64 NLAVCC AVCC 62 61 OUT_2 PIIC2061 60 OUT_1 PIIC2060 59 PIIC2059 58 PIIC2058 57 PIIC2057 56 PIIC2056 55 PIIC2055 54 PIIC2054 63 PIIC2063
WR /RD
PIIC2033
SC1 SC2 AIN0 Vcon
PIIC2018 19 PIIC2019
33 34
PIIC2034
18
1 PIIC201 2 PIIC202
USB_CONN_ETH
NLD0 D-
COR2 R2 PIR201
NLD0 D+
PIR401
22R
PIR202
COR4 R4
NLUCAP UCAP
PIIC2062
22R
PIR402
COC10 C10
PICON202
PICON201
PICON203
PICON204
PICON205
PIC902
COR23 R23
VCC
1k
PIR302
PIR2301 NLfuck fuck
COCON2 CON2
1uF
PIC901
PIC10 1 PIC10 2
PIR2302
VCC
COL1 L1
PIR301
PILED501
PICON206
PILED502
100nF
GND
GND
GND
GND
10k
NLHWB HWB
COLED5 LED5
COC9 C9
COR3 R3
PIK201
PIC1 01 PIC1 02
PIK202
COK2 K2 COC11 C11
GND GND
Figure 2.6: Schematic of the USB Connector
USB: Figure 2.6 shows the USB connector and auxiliary components. The values of the serial resistors AGND on the data lines are strictly prescribed in the AT90 datasheet. The same holds for the value of the capacitor COIC3A IC3A on the UCAP pin. A LED is added in parallel to the power line to indicate proper functionality of the power supply. To program the AT90 via USB, we relied on the AVR FLIP software. 7This tool provided by Atmel NLOC0APIIC302 OC0A 2 1 In1 Out1 PIIC307PICON401 2 supports in-system programming of flash devices through USB, among others [10]. PICON402 COCON4 CON4
TC4427
USART-RS232 The serial communication between the USARTGND registers of the microcontroller COR24 Interface: R24 0R COIC3B PIR2401 PIR2402 IC3B and the RS232 lines of a computer is handled via a ST3232 Driver/Reciever from STMicroelectronics. This componentAGND is highly capacitors (apart from the obvious NLOC2A external GNDintegrated and only needs four standard OC2A 4 5 PICON501 1 PIIC304 In2 Out2 PIIC305 2 bypass capacitor) for proper operation. Although the data sheet recommends electrolytic capacitors with the values that are indicated in the schematic in Figure 2.7, we were advised to use 100 nFCON5 ceramic capacitors COCON5 TC4427 instead. There has never been any problem with the ST3232 because of that change.
GND
VCC
PI C3 06 PI C3 0
PICON502
GND
10
COIC3C IC3C
GND
TC4427
100nF
GND
6
6 PIIC206
- +
PIL102
5 D+ PIIC205
1
4 DPIIC204
PIIC2064
GND
VCC
3 PIIC203
VCC REF DC0 DC1 DC2 DC3 TCK TMS TDO TDI GND
COC7 C7
Communication Channels
100nF
29 PIIC2029 30 PIIC2030 31 PIIC2031 32 PIIC2032
COR1 R1
3
26 PIIC2026
PIR102
+ VREF ),
100nF
25 PIIC2025
VCC
2 1 MOSI VCC PICON102 R15 3 4 PICON103 N/C VOU TPICON105 = 5 1 + GND PICON104 · (V 6 IN RESR12 GND PICON106 7 8 PICON107 SCK GND PICON108 9 10 PICON109 MISO GND PICON1010
PIJP102 PICON101
2
UVcc DD+ Gnd UCap VBus UID
COJP1 JP1
RESET NLSCK SCK NLMISO MISO
B1287
NT0 NT1 NT2 NT3 CP1 CK1 6/T1 7/T0
JUMPER2
PIJP101
C HAPTER 2. H ARDWARE VCC VCC
PIR102
100nF PIC301
COR1 R1
PIK101
PIC801
COC7 C7
PIC802
NLCMOS0TX CMOS_TX
GND
11
1
PIR301
2
GND 14
TX2
TXD2
7 PIIC107
12 PIIC1012
RX1
RXD1
13 PIIC1013
9 PIIC109
RX2
RXD2
8 PIIC108
10k
PIIC1014
PICON30 PICON30 2 P ICON301
PI C1015
PIK201
PIC1 01 PIC1 02
100nF
PILED502
PIC602
C2-
10 PIIC1010
COR3 R3
NLHWB HWB
COLED5 LED5
330nF
PIC601
15
NLfuck fuck
PILED501
PIC502
COC5 C5
COC6 C6
TXD1
VCC
PIR302
PIC501
6 PIIC106
TX1
PIIC1011
NLCMOS0RX CMOS_RX 1k
330nF
2 PIIC102
V+ V-
COC8 C8
VCC
PIR2301
GND
ST3232CD
3 PIIC103 C14 PIIC104 C2+
330nF
5 PIIC105
COR23 R23
16
COC4 C4
PIK102
COK1 K1
GND
PIR2302
C1+
3 2 1
100nF
PIC701 PIC702
1 PIIC101
PIC402
GND
NLR\E\S\E\T\ RESET
PI C1016
COIC1 IC1
47nF PIC401
VCC
10k
PIR101
PIC302
COC3 C3
PIK202
GND
COK2 K2
GND
COCON3 CON3
COC11 C11
GND
Figure 2.7: Schematic of the USART-RS232 Level Shifter GND
GND
Since it was not considered desirable to fix a bulky RS232 plug onto the circuit board and there were NLPC0 NLPC1 NLPC2 NLPC3 PC0 PC1 PC2 PC3 only three wires VCC needed, a three pole Molex plug was used, which could be connected over three wires to an external RS232 plug. COR6 COR7 PIR502 COR5 PIR602 R6 PIR702 R7 PIR802 COR8 R5 R8 7 PICON401 1 PIIC307
1k
2 PICON402
NLMOSI MOSI
OC2 C2 C4427 GND
PIJP102 PICON101
RESET NLSCK SCK NLMISO MISO
GND GND
1
PILED302
1 3 PICON103 5 PICON105 7 PICON107 9 PICON109
PIJP101
COCON5 CON5
PILED202
PILED401
COLED3 LED3
AT90USB1287
VCC
COLED4 LED4
PILED402
VCC
2
COJP1 JP1
JUMPER2
PILED102
PILED301
COLED2 LED2
2
PI C30
1 2
PICON502
PILED201
COLED1 LED1
2
5
PIR801
1
PILED101
C14 PIC1401 COC14
TC4427
PIIC305 PICON501
PIC202
1k
PIR701
1
1
PIC1402
3
100nF In2 Out2
1k
PIR601
6
GND
IC3B 3B
COIC3C IC3C
- +
C4427
1k
PIR501
PI C30 6
COCON4 CON4
100nF
In1 Out1
2
IC3A 3A
MOSI N/C RES SCK MISO
VCC GND GND GND GND GND
2 4 PICON104 6 PICON106 8 PICON108 10 PICON1010 PICON102
PIR102
10k
PIR101
COCON1 CON1
NLR\E\S\E\T\ RESET
26 PIIC2026
VCC
27 CMOS_RX PIIC2027 29 PIIC2029 30 AGND 31 32 PIIC2032
PIR902
10M
PIR901
PIR1002
COR9 R9
PIIC2030
PIR1001
COC15 C15
PIR1301
COR11 100R R11
PIC701 PIC702
PIK102
COK1 K1 COC7 C7
1k
Figure 2.8:AGND Schematic of the ISP Interface
PIR1402
1M
PIR1101
VCC COR13 R13
PIK101
PIC1502 PIC1501
COR10 R10
PIR1302
1M
PIIC2031
GND
100nF
28 CMOS_TX 10M PIIC2028
100nF
25 PIIC2025
PIC408 PIC406
PIR1401
COR14 R14
8
PDO/OC0B/SCL/INT0 PD1/OC2B/SDA/INT1 PD2/RXD1/INT2 PD3/TXD1/INT3 PD4/ICP1 PD5/XCK1 PD6/T1 PD7/T0
COR1 R1
PIR1102
COIC4 PIR1 03 IC4 COR15 01 PIR1502 R15 100nFPIC16LTC2053
PIR1202
GND
PIR1201
GND
R12 COR12
AGND
REF
PIR2302
EN Rg
PIL102
PIR302
V-
V+
6
3 VCC was used for the serial Serial Programming Figure 2.8 COC16 shows249k a general 10-pin connector that UVcc PIIC203 COR16 Interface R16 10k T-_3 2 C16 PIC1602 42 D-NLT003 PICON602 PIR1601 PIR1602 PIIC402 -IN COR17 R17 10k NLT003 P I R 1 5 0 1 D- PIIC204 1 T+_3 PICON601 PIR1701 PIR1702 ISP Since the microcontroller’s SPI 7is connected andCOR23 the ISP, we decided 5 channel. D+ VCC VCCto R23 NLOUT02 to both the MAX6675 OUT_2 D+ PIIC205 OUT PIIC407 6 COCON6 CON6 3 PIIC206 COL1 PIIC403 +IN UGnd GND L1 multiplex the MOSI pin with a jumper. Otherwise, it would be possible for the MAX6675 to interfere with 1k PIC1801 10nFPIC1901 10nF COR3 7 UCAP USB_CONN_ETH R3 UCap PIIC207 VCC COR2 R2 22R P I R 2 3 0 1 NLD0 8programmingCOC18 D- PIR201 COC19 C18 C19 PIIC208 PIR202 PICON202 PICON201 a sequence and cause unpredictable results. VBus P I C 1 8 0 2 P I C 1 9 0 2 NLfuck 10k 9100nF fuck 10uH COCON2 PE3/IUID PIIC209 CON2 COR4 NLD0 R4 22R D+ PIR401 PIC2102 PIC2101 PIR402 PICON203 PICON204 NLAVCC AGND 64 AVCC 1uF C21 COC21 AVCC PIIC2064 NLUCAP NLHWB 62 COIC7 UCAP HWB PIC901 PIC902 PIK201 AGNDPIIC2062 IC7 LT1025 COLED5 AREF LED5 61 OUT_2 COK2 K2 PF0/ADC0 PIIC2061 COC9 C9 COC10 AGND 60 OUT_1 C10 PF1/ADC1 PIIC2060 COR20 R20 0R NLLTC20530REF 1 8 LTC2053_REF components to 59The PIR2002perform the temperature control task were assembled on a separate board. As menE J PIIC708PIR2001 PIIC2059 COC11 COR21 R21 0R PF2/ADC2 PIIC701 C11 3 7 PIIC703 PIR2102 V_O K,T PIIC707PIR2101 58 100nF 5 6 this board was PF3/ADC3 PIIC2058 tioned before, equipped with a 12 V power supply. The coaxial plug for the supply can be RR,S GND GND GND GND GND 57 PF4/ADC4/TCK PIIC2057 56 on the left side of the schematic in Figure 2.9, together with an electrolytic capacitor for voltage staseen PF5/ADC5/TMS PIIC2056 GND 55 PF6/ADC6/TDO PIIC2055 54 bilization. To the right of it, the MOSFET can be seen (Actually, a different model than indicated on the PF7/ADC7/TDI PIIC2054 63 AGND PIIC2063 4
1
PIC401 P I C 4 0 PIC405
1
PIC702Temperature Control
2
PICON205
2
100nF
PILED502
PIK202
PIC1 01 PIC1 02
PIIC706
GND
PIIC705
PILED501
PICON206
PIC10 1 PIC10 2
V_IN
2.2.4
PIR301
5
PIL101
GND
4
PIC704
PE0/WR PE1/RD PE4/INT4/TOSC1 PE5/INT5/TOSC2 PE6/INT6/AIN0
33 34
PIIC2033 PIIC2034
Title
Size
18
A3
1 PIIC201
Date: File:
PIIC2018 AGND 19 PIIC2019
2 PIIC202
11
AGND Number
Revision
VCC
COIC3A IC3A 12/21/2010 Sheet of C:\medical instrumentation\..\tempsens.SchDoc Drawn By:
NLOC0APIIC302 OC0A 2
7 PICON401 1 PIIC307
PIX10
COX1 X1 Heatsink
Heat
C HAPTER 2. H ARDWARE 12V
12V
2
12V
PICON20
PIC101
470uF
PIT102
COCON2 CON2
PICON201 PICON203 3
PIC102
1
COC1 C1
2k2
PIR102
COR1 R1
PIR202
3k3
PIR201 GND
FQP50N06
PIR101HeatSig PIT101
COCON3 CON3
GND
CoolSig 1 PICON401 SensePICON402 2 3 PICON403 4 PICON404
COT1 T1
2 PICON302 1 PICON301
GND
PIT103
2
PICON102 1 CoolSig PICON101
COCON1 CON1
PIR302
10k
COCON4 CON4
COR2 R2
PIR301 GND
GND
GND
COR3 R3
GND
Figure 2.9: Schematic of the Heat Control Board schematic - a IRL530N from International Rectifier - was used). Its gate voltage is controlled by the PWM signal from the microcontroller. A voltage divider at the gate scales the maximal voltage down to 3 V, which lies significantly higher than the threshold voltage but constrains the maximal drain current to a relatively moderate 3 A. On the right side of the schematic, two more connectors can be seen. On the two-pin plug lies the PWM cooling signal from the AT90 and into the four-pin connector the PWM compatible fan is plugged. In fact, when the board was assembled, the wires of the fan were soldered directly to the board Title because there was not enough room for the plug. Size
Number
A4 Date: File:
12
12/21/2010 Sheet of C:\medical instrumentation\..\Heat.SchDoc Drawn By:
Revision
Chapter 3
Software This chapter discusses the implementation of the software parts of our project. Logically, this work can be separated into two parts: first, temperature measurement and control and second, communication over the Universal Serial Bus. The first part runs only on the AT90. The latter can be regarded as two subsystems that run on the microcontroller and on the USB Host. Accordingly, this chapter is divided into the respective sections. We decided to move code snippets to appendix A.4 to avoid an impairment of reading fluency.
3.1 3.1.1
Temperature Measurement and Control Temperature Measurement and Conversion
Swapping Bytes via the SPI The Serial Peripheral Interface (SPI) is a perfect solution for connecting embedded processors with their onboard peripherals. The MAX6675 samples the thermocouple input, converts it to a 12-bit digital value and is able to send the result over the SPI. Initializing the interface is a matter of a few lines of code with are appended in A.4.1. It lies in the nature of the SPI that read and write operations are always done simultaneously. Each end of the 3-wire connection is equipped with a shift register and after a transmission the contents of both shift registers are swapped. The MAX6675 starts a transmission on the first rising edge of the clock signal after the slave select signal is pulled low. The AT90 reads the data on the MISO line after a dummy write is executed. Sampling the Analog Temperature Input The other two solutions for collecting the sensor data are not capable of converting the analog value into a binary number by themselves. This is no problem because the AT90 has an integrated analog-to-digital converter (ADC) that provides samples with reasonable accuracy. In fact the measurement error of the analog circuitry is significantly higher than the error introduced by the sampling process. The process of initializing and sampling a given ADC channel is documented in the Appendix (see A.4.2). When sampling the two analog inputs the maximum value is achieved at voltage level over 2.56 V. This reference voltage is generated by the microcontroller internally. Since both the AD595 and LT2053 are calibrated to 10 mV per ◦ C the theoretical value after conversion can be calculated in the following way: Tsamp = Vanalog · 100 13
C HAPTER 3. S OFTWARE Here, Tsamp is given in ◦ C if Vanalog is given in V. However, the output of the ADC is a 10-bit value. The maximum value corresponds to 256 ◦ C. When sampling with the 10-bit ADC one LSB corresponds to 0.25 ◦ C. An application using these values must take care to interpret them correctly.
3.1.2
Closing the Control Loop
Heating In order to control the temperature effectively we wanted to be able to both cool and heat the point of measurement. For heating the dissipated power of a MOSFET is used. The power is controlled by pulse-width modulating the gate voltage. Constructing the PWM signal with the AT90 is a straight-forward process: once the Timer0 (an 8-bit counter) of the controller is set to PWM-mode it is only a matter of adjusting the timer’s output compare register (OCR0A). When the timer begins counting, the PWM output pin (OC0A) is high. When the output compare value is reached, the output pin becomes low. When the timer reaches the value 0xFF it causes an overflow and starts from the beginning. The output pin is set to high again. Hence the PWM duty cycle is adjusted by simply moving the output compare value between 0x00 and 0xFF. Figure 3.1 illustrates this approach. The code snippet in section A.4.3 gives the main statements necessary to set up the basic PWM output and a simple method to control the duty cycle. TCNT0 0xFF
OCR0A 0x00 t OC0A
HIGH LOW t
Figure 3.1: Diagram of PWM Signal Generated by Timer 0
Cooling For cooling down the measurement point, another PWM channel of the microcontroller was used to drive a PWM capable fan. These fans are normally used for cooling PC cases and CPUs. Hence, there is a semi-official specification with which the fan manufacturers are supposed to comply [6]. This specification defines the nominal PWM frequency as 25 kHz. Variations are allowed between 21 kHz and 28 kHz. 14
C HAPTER 3. S OFTWARE The fan RPM is supposed to increase linearly starting at a duty cycle of 30 %. Below this threshold the fan behaviour is not completely defined, but the RPM shall be less or equal to the minimum RPM (at 30 %). The frequency of 25 kHz cannot be created by using the normal PWM function of the microcontroller’s various timers. Only a couple of predefined frequencies are available, dictated by the AT90 CPU frequency and the timer’s prescaler that divides the input frequency by a power of 2. We worked around this by adjusting the maximum value of Timer2 (a 16-bit counter) to achieve the correct frequency. Again the output compare value is used for adjusting the duty cycle. This is illustrated in Figure 3.2. Because of the custom top value the PWM signal must be generated by setting/resetting the PWM output pin (OC2A) in the Interrupt Service Routines that serve the overflow and compare interrupts. This procedure is further elaborated in section A.4.4. TCNT2 0xFFFF ICR1 OCR2A 0x0000 t
OC2A
HIGH LOW t
Figure 3.2: Diagram of PWM Signal Generated by Timer 2
During testing it turned out that the fan we chose by Arctic Cooling does not comply with [6]. When the PWM duty cycle is reduced to zero the fan runs full tilt which is a violation of the specifications. One can assume that the reason for this is compatibility with the 3-pin fans, that do not provide a PWM signal but only VCC, GND and SENSE. The consequence of this is that we are not able to turn the fan off by software. This is interesting, but not really a problem for our project because the cooling of the fan when running at lowest RPM is negligible. Proportional Control In order to control the temperature, a simple proportional controller was implemented in software. First the difference between temperature setpoint and measured temperature is calcu15
C HAPTER 3. S OFTWARE lated and then multiplied by a factor of 10. This is convenient, because it improves the resolution of the control input. The software uses no floating point values because floating point operations are costly in terms of CPU cycles. So, by multiplying the control input by 10, the resolution gets also multiplied by a factor of 10. In the next step, the control output is calculated by multiplying the input with the gain. Again, to improve the resolution, the gain is a relatively large number and the result gets divided by 100 aferwards. So, summing up, the actual gain value is equal to the value of the gain variable devided by 100. P W Mf an (t) T (t)
Kp
P W Mf et (t)
Figure 3.3: Control Structure
Now, depending on the sign of the error, either the cooling or heating PWM duty cycle is set according to the control output. This concept proved to be too simple because the system is constantly cooled by air convection without the fan actually working. The consequence of this is that the heating should never be completely switched off if the controller is active. The control concept was therefore modified in the following way: If the deviation from the setpoint is smaller than 1.5 ◦ C, the PWM heating duty cycle is set to a value not dependent of the control output, but of the Setpoint itself. The control stucture is depicted in Figure 3.3. We are not making a secret out of the fact that control performance did not have a high priority during the project. If one wanted to improve the control performance, one could play with the values of the gain or the variables defining steady state heating or incorporate integral action, just to name a few possibilities. For our purpose, howewer, it was sufficient to have a working solution.
3.2 3.2.1
Communication via USB USB Overview and Technical Terms
The Universal Serial Bus was developed to replace the various busses and protocols between the PC and its peripherals. From the consumer electronics market, the predecessors of the USB have already vanished completely. Modern notebook computers always have several USB ports but lack connectors for the serial and parallel ports. In the industrial sector the USB is becoming increasingly popular as well. To become a practical substitute for all the different peripherals the USB Specification has to meet a lot of different requirements specific to one particular group of devices. This is the reason for the complex topology and several layers of abstraction of the USB. The fact that the USB shall stay extensible for future use adds even more complexity to the system. This subsection describes the basics of the USB and introduces some technical terms which will be used in the following parts of the software descripton. • USB Host, Hubs, Devices: The Universal Serial Bus has tree topology. The root of the tree is the USB Host. In most cases this will be a general purpose computer. The leaves of the tree are the USB Devices and the intermediate nodes are USB Hubs. In fact, hubs are only a special class of devices. USB Devices can be connected to the bus by either attaching them directly to the host or via a (set 16
C HAPTER 3. S OFTWARE of) hubs. The USB Specification allows a maximum of 5 hubs daisy-chained together. The edges of the tree are USB cables. According to the USB Specification, they have a maximum length of 5 m (3 m for low-speed devices). Hence, the maximum distance of a device from the host is 30 m (18 m for low-speed devices). • IN/OUT Communication: The USB Specification defines the direction of communication from the host’s point of view. Data sent from the USB Host to a device is called an OUT transaction. In contrast data emitted by the device and transferred to the USB Host is a IN transaction. • Endpoints, Pipes: The different functional features of a given USB device can be implemented using different Pipes of communication. These Pipes are terminated by Endpoints on both the host and the device side. The Endpoints of a device are enumerated starting from 0 to a maximum number of 32. Depending on the kind of transfer that is conducted via a given Endpoint/Pipe, the Endpoint and its Pipe can have four different types, as shown in Table 3.1. • Human Interface Device: Each USB device belongs to a specific Device Class according to the functionality of the device. Examples for Device Classes are the Mass Storage Class (USB flash drives, external harddisks, . . . ), the Printer Class (printers, CNC mills, PCB manufacturing, . . . ) or the Image Class (cameras, scanners, . . . ). This separation into classes allows for easier handling of the devices by the operating system. For instance, a single driver can be developed to interface with a whole class of devices. Our device belongs to the class of Human Interface Devices. HIDs are devices that process user input and send it to the USB Host. Although a temperature sensor is not a Human Interface Device in the strict sense, we decided to stick with this Device Class because it is relatively simple and because Microsoft Windows includes libraries for communicating with HIDs in an uncomplicated (and also unflexible) way. • Report Descriptors: The USB Specification defines a large number of different data structures for identifying entities related to devices and the bus. These are called Descriptors. There are Device Descriptors, Configuration Descriptors and Endpoint Descriptors to name only a few. In addition to this, the specification allows for device-class-specific Descriptors that are used only by devices belonging to the Device Class. The Device Class Definition for Human Interface Devices defines several device-class-specific descriptors of which one is particularly interesting for us [4]. The Report Descriptor is a complex byte structure that contains information about the type of the HID, the format of the reports that are sent or received by the HID and also meta information on the data that is exchanged. This information can be used by the host to handle the device correctly. Furthermore, a device developer can expect applications to use the data in a consistent way across different platforms. For example the Report Descriptor of a USB mouse tells the host not only that 4-byte messages are sent. It also informs the host that the device is a pointing device, that it has three buttons whose state is mapped to the first three bits of byte 0 and that it sends differential 1-byte values for the x-axis, the y-axis and the wheel in bytes 1-3. In contrast to other descriptors the Report Descriptor is not a predefined structure but a complex array of hexadecimal values that need to be parsed and compared with a special syntax. This list can only serve as a very compact overview of the bus components that are most important for our application. A more detailed treatment is beyond the scope of this work. The interested reader is kindly referred to the Universal Serial Bus Specification, Revision 2.0 [3]. 17
C HAPTER 3. S OFTWARE Transfer Type Control Transfer
Direction 2-way
Bandwidth n/a
Latency n/a
Interrupt Transfer
1-way
n/a
small
Bulk Transfer
1-way
high, unknown
unknown
Isochronous Transfer
1-way
guaranteed
small
Applications (Usage) Configuration of device (Connection to bus, Definition of device adress, ...) asynchronous, small transfers (Status updates from mouse, keyboard, ...) exchange of large amounts of data (File transfer from hdd, flashdrive, . . . ) streaming data (Audio stream, Video stream, ...)
Table 3.1: Comparison of USB Transfer Types
3.2.2
Communication System
After understanding the basics of the USB, we will take a look at the design of our communication system. On one hand, it is responsible to continuously deliver temperature values acquired by the sensor board. On the other hand, it will be used to send commands to the sensor board. For these purposes we only need 2 Endpoints of the AT90 USB controller, although in theory, it would support up to 7. Endpoint 0 handles Control Transfers (as specified by the USB Specification). Endpoint 1 is configured for Interrupt Transfers in order to deliver temperature values once a new measurement becomes available. Figure 3.4 depicts the communication system in a schematic way. The Report Descriptor of our device is a straight-forward combination of a 4-byte input and a 1-byte feature request. It is listed in hexadecimal code below. For a complete documentation of the syntax of Report Descriptors the reader is referred to [4]. The hexadecimal codes here are translated into human readable form. 0x05, 0x40, 0x09, 0xC0, 0xA1, 0x01, 0x09,0x01, 0xA1,0x00, 0x05,0x01, 0x09,0xC0, 0x09,0xC1, 0x09,0xC2, 0x09,0xC3, 0x75,0x08, 18
// // // // // // // // // // //
Usage Page (Medical Instrument) Usage (arbitrary value) Collection (Application) Usage (Pointer) Collection (Application) Usage Page (Generic Desktop Control) Usage (arbitrary value) Usage (arbitrary value) Usage (arbitrary value) Usage (arbitrary value) Report Size (8)
C HAPTER 3. S OFTWARE 0x95,0x04, 0x81,0x06, 0x05,0x01, 0x09,0xC4, 0x75,0x08, 0x95,0x01, 0xB1,0x06, 0xC0, 0xC0
// // // // // // // // //
Report Count (4) Input (Data, Variable, Absolute) Usage Page (Generic Desktop Control) Usage (arbitrary value) Report Size (8) Report Count (1) Feature (Data, Variable, Absolute) End Collection End Collection
Note that the only important part is the block that is indented most. It defines 4 entities with Usage (...). The value in parentheses does not matter for our application. Their size of one byte is given by Report Size (8) in bits and the number of entities is specified with Report Count (4). In the following line an Input code is issued which makes the entities inputs. In a similar way, the 1-byte feature request is defined after the input definition.
USB Host
Control Transfer Pipe Interrupt Transfer Pipe
AT90 USB Controller 0
1
Figure 3.4: Schematic View of the USB Communication System
AT90 Software For the software part on the AT90 side, we used a piece of example code provided by Atmel, the manufacturer of the AT90 microcontroller series [7]. Their work shows how to program the AT90 in order to emulate the behaviour of a generic USB mouse. During the process of separating the useful parts from unneeded sections we faced a couple of problems though. First of all, it was not always easy to determine if a piece of code was necessary for our purpurpose or not. Second, the code was kept very generic and designed to be used with different compilers without adaptions (we relied on the AVR-GCC 19
C HAPTER 3. S OFTWARE compiler througout our project). This style of coding makes the resulting program very flexible but also full of macros, whose function is sometimes hard to grasp. Macros in C are complex find-and-replace operations executed by the C preprocessor before the program is compiled and linked. This means that the source code for the compilation is not exactly the code that the developer sees on the screen. In fact, macros are often used to disable and remove whole functional blocks from the software to minimize the size of the binary. The resulting discrepance of line numbers makes the debugging process very cumbersome. Third, the Atmel code was designed for specific evaluation- or demo-boards which are sold by Atmel. Hence another difficult step was the adaption to our own hardware design while the actual board was still being manufactured. And last but not least, the inital mouse code had no need for reports sent from the host system to the device, so the communication was only unidirectional (apart from acknowledgements which are handled by hardware anyway). We extended the code to handle bidirectional communication as described above and depicted in Figure 3.4. In the end, all that remained from the original Atmel code was the “low-level” USB driver and the basic structure of the software including the task scheduler. The driver is responsible for the lowest level of abstraction by providing basic functions and macros for handling the relevant registers of the controller. USB Host Software In order to write the software on the USB Host side (the computer) one further design decision had to be made. Unfortunately, we were obliged to use Microsoft Windows on host side, because future work could comprise the development of a graphical user interface with LabView. When faced with the task of developing an application for Windows that communicates over the USB, the developer must choose from these three possibilities: • Using WinUSB API: The WinUSB API was developed to simplify the development of Windows drivers for Microsoft-independent hardware manufacturers. This simplification brings some limitations with it: there is no support for two applications accessing the same device at the same time. Also, WinUSB cannot work with devices that stream data using isochronous endpoints. Since WinUSB is used to develop a driver, there is the need to manage several additional files that need to be distributed together with the main application and the dynamic link library of the driver itself. Some of these files contained in the final package have to be digitally signed in order to work with the newer and more restrictive versions of Windows. The WinUSB API is included in the Windows Driver Kit. • Using hidpi.h, hidsdi.h, hidusage.h: Of course Microsoft Windows has native drivers for USB mice and keyboards. But there is also a special HID API defined by the aforementioned three header files designed to work with HIDs in general. This API has similar limitations to the ones imposed by WinUSB. Additionally it works only with HIDs, of course. Although one can only speculate, it seems likely that the HID API is internally based on WinUSB. Since there is no need to write a custom kernel-mode driver, no driver package has to be built. • Using low-level APIs: For complex devices developers cannot base their host applications on WinUSB or the HID API. This makes development and testing more time-consuming. On the other hand, communication with isochronous endpoints can be set up and several applications can access the device at the simultaneously. A USB headset with speakers and microphone demands such a design, to give just one example. Similar to the WinUSB solution the usage of low-level USB APIs requires the management of a whole package of files, some of which have to be digitally signed. Keeping our problem statement in mind, the only sensible solution is the second. The overhead of managing a driver package and getting to know the involved low-level libraries is just too big. We assume that 20
C HAPTER 3. S OFTWARE the project could not have been completed within the given time constraints if we had used either the first or the third solution. Since the HID API provides all the features needed for our purpose, nothing stood against using this method. Additionally there is a small sample application available from the Microsoft Software Development Network that demonstrates how to open HIDs with the HID API and read basic key figures (descriptors) [11]. This turned out to be a good starting point when developing the Windows software. In the year 2010 programmers are used to automatic code completion, straight-forward refactoring of functions and most of all hands-on debugging during runtime. Unfortunately the Windows Driver Development Kit (WinDDK) sets programming standards back to 1980 where development environments had no “I” in front of them, makefiles were edited manually and the comfortable features mentioned above were not available. However we were forced to use the WinDDK since it contains a special build environment that allows linking against all the libraries inculded in the driver kit. A nice feature of this build environment is the easy management of different architectures and target systems. By setting different environment variables one can easily change between a 64-bit build for Windows 7 and a 32-bit version for Windows XP [8].
3.2.3
Operation of the USB Host Software
One of the project’s results is a small Windows application called tempsens.exe. It is capable of reading the temperature values over the USB and issuing commands for controlling the software on the AT90. Based loosely on the code of Microsoft’s HClient sample application, it includes some of the methods of the latter. However it does not feature a graphical user interface. This was skipped deliberately and replaced by command line I/O to make the source code simple and easy to understand while still providing the necessary functionality. To run tempsens.exe under Windows, one has to open a cmd.exe, cd to the directory in which the application resides and execute it simply with tempsens.exe. The application starts by creating a list of all HIDs that are attached to the system. It then looks for a device with our predefined Vendor ID/Product ID tuple. For our academical purposes we are allowed to use Atmel’s Vendor ID, which is 0x03EB. Our arbitrary chosen Product ID is 0x1337. If tempsens.exe finds our USB device it opens a handle which will then be used by two threads concurrently. One thread is responsible for reading the provided data in regular intervals. The other is responsible for handling user input and sending commands to the microcontroller. It is important to separate these two threads from each other to ensure responsiveness of the application. This is because I/O transactions of the HID API are all synchronous: they are blocking the calling thread. Once running, tempsens.exe prints the sensor data to the command line. The user can terminate the application by pressing ’q’. All other ASCII values are passed on to the AT90. They are packed into a Feature Request and transmitted to the microcontroller where they are handled by the command interpreter routine. A list of commands that are accepted by the AT90 software can be found in Appendix A.1. Additionally to printing information on the command line, the output is duplicated to a log file. The name of the logfile is the time at which tempsens.exe was started. This is useful for further processing (plotting, statistical analysis). Figure 3.5 shows a screenshot of the running application. The last two columns are the current temperature given in steps of 0.25 ◦ C. Obviously, the temperature was normal room temperature at the time of execution. A value of 94 for instance, corresponds to 23.50 ◦ C. The second column specifies the temperature setpoint in steps of 1◦ C. If the control loop is enabled, the temperature would be regulated around this value. A value of 50 is assigned by default. The first column 21
C HAPTER 3. S OFTWARE
Figure 3.5: A Screenshot of tempsens.exe During Runtime is used for debugging purposes. For example, it can be used to store the last command that was sent to the microcontroller. Code snippet A.4.5 shows how this kind of report is built in software.
22
Chapter 4
Measurement Results This chapter presents the measurement results that were obtained with the device described in the previous chapters. The focus of this evaluation is centered on the following questions: Are there any significant differences in the quality and accuracy of measurement of the three data processing circuits implemented? And if yes, what conclusions can be drawn from this? How important is the contribution of the fan to the cooling performance? What are the key characteristics of the temperature control? Each problem field is treated in a section of its own.
4.1
Evaluation of Sensor Solutions
Figure 4.1: Step Response With Different Measurement Methods
The comparison of the three step responses shows clearly, what was already suspected prior to the measurement phase of the project: that the most integrated component, the MAX6675 yields the most accurate results. Characteristic figures such as rise time, overshoot, settling time or steady state error can be derived from the curve (see section 4.3). The step responses of the other two implementations on the other hand are very noisy. One reason for this behaviour might be the fact, that the data remains in analog form over a significantly longer distance and will therefore pick up more noise. Secondly, the higher the level of integration, the better are the individual functions - Cold Junction Compensation, amplification and digitization - matched to each other, thus reducing the overall error. 23
C HAPTER 4. M EASUREMENT R ESULTS The result of the comparison of the step responses is confirmed by some simple calculations: The average steady state error (in absolute value, ignoring the first 40 Seconds) is equal to 1.3062 ◦ C for the step response recorded using the MAX6675, 1.5687 ◦ C using the AD595 and 1.5095 ◦ C using the LTC2053. Of course, these numbers are very sketchy and can by no means be seen as strict mathematical figures, but they give a general idea of the quality of the different mesurement chains implemented. Figure 4.2 shows three histograms. They depict the distribution of measured temperature values at room temperature. The MAX6675 is the only measurement solution that produces continuously distributed reults. Furthermore, the distribution is roughly gaussian. Hence, one could refine the results further by averaging over a certain time period. The AD595 method, on the other hand, shows a non-continuous distribution with a gap between the two most common values. Finally, the LTC2053 method yields fragmentary distributed results with a very high variance. Although the results obtained with the MAX6675 show a slightly higher variance than the ones obtained with the AD595, this method is preferred because of its continuous distribution. Once more, the most integrated solution proves to be superior.
Figure 4.2: Distribution of Measurement Results for the three Methods
Based on the results of the comparison above, for all further measurements and especially for the evaluation of the control performance, the two analog measurement channels were not taken into account.
4.2 4.2.1
Evaluation of Heating and Cooling Performance Heating with the IRL530N
The thermal junction of the thermocouple can be heated with the PWM-controlled IRL530N MOSFET. This component turned out to be a very effective heating element. However, one improvement that could be made to the heating system is electrical isolation of the MOSFET’s heatsink. The lack of isolation once caused an inadvertent crash of our attached computer. Another problem is the fact, that there is no overcurrent protection. When using a “wall-wart” power supply, one has to take care not to overload it. Their circuitry is seldomly protected from sourcing too much current.
4.2.2
Arctic Cooling?
While developing a concept of the control loop, it was not clear how efficient the cooling solution with the PWM-controlled fan would be. After all, there was no ordinary heatsink with cooling ribs but only slots 24
C HAPTER 4. M EASUREMENT R ESULTS in the PCB instead. To assess the performance of the fan experimentally, the cooling process starting from 100 ◦ C was recorded. During the first measurememt the fan was running at maximum RPM while it was disabled before starting the second. Figure 4.3 plots temperature against time for both experiments. An exponential regression on the recorded values yields the following relations.
Figure 4.3: Cooling Down From 100 ◦ C
Tf an (t) = T0 · e−0.0201·t
Tnof an (t) = T0 · e−0.0074·t
These figures show that the fan is indeed capable of enhancing the cooling efficiency significantly. The half-life of the cooling process is reduced by more than 60%. Still, it is important to note that the fan also has the negative effect of overtravelling although the PWM duty cycle might already be reduced to a minimum. The impact of this effect is hard to express in numbers and further elaborations are omitted at this point.
4.3
Discussion of Temperature Control
Figure 4.4 shows again the step response that was recorded with the temperature measurement executed by the MAX6675. It can be analyzed with an apropriate tool, for example with the Control System Toolbox of Matlab. The two most significant characteristics for this step response are the Rise Time (defined as the time it takes the system to drive the output from 10% of the setpoint to 90% of the setpoint) and the Overshoot (defined as a measurement for the local maximum after the first crossing of the setpoint in percent of the 25
C HAPTER 4. M EASUREMENT R ESULTS MAX, Gain75, SSO12
55
Temperature (°C)
50
45 Measurement Setpoint 40
35
30
25 0
20
40
60 Time (s)
80
100
120
Figure 4.4: Step Response of the MAX6675 setpoint). The Rise Time is equal to 18.25 s and the overshoot equals 4%. For a quantity like temperature, which changes very slowly in comparison to other physical quantities, the rise time is in an acceptable range and an overshoot of only 4% with a single P-controller is considered to be not too bad either. Figure 4.5 shows the result of another experiment. This time, the setpoint was changed every 30 s and the reaction of the system was recorded. One thing that can be seen, is the fact that the temperature fluctuates significantly more when the system is cooling than when it is heating. The reason for this lies in the electrical and mechanical properties of the fan which are not specially treated in the control software. Once running, the fan needs very little current to keep running. Experimentally, we were able to keep the fan running with a PWM duty cycle of only 5 to 6 percent. But to overcome inertia and start running, a duty cycle of 15 percent is necessary. Because of this, the fan only starts running at a certain temperature error, and when it does, its speed is already on a considerable level. When it is running, on the other hand, it keeps running down for some time before it stops. These effects lead to the delay in reaction to temperature errors that can be seen on the plot.
26
C HAPTER 4. M EASUREMENT R ESULTS
Figure 4.5: Following a Setpoint Curve
27
C HAPTER 4. M EASUREMENT R ESULTS
28
Chapter 5
Conclusion The result of this project is a small USB device that can reliably measure temperature. Implementation of a control loop under utilization of a second board demonstrates that the values are accurate and can be used for further processing with little effort. Since this was our first PCB design project, we were sceptical about the quality of the results in the beginning. We are glad that both the hardware and software turned out so well in the end. However, since a first prototype is seldomly perfect some improvements could certainly be made with little time effort. • Implement a PI-controller to get rid of the steady-state error that remains (compare Figure 4.4). An alternative would be to increase the gain of the P-controller, but that would also cause a large overshoot in the beginning. • For safety reasons mentioned above it would certainly be desirable to electrically isolate the heatsink of the IRL530N. An optimal setup would also fix the probe of the thermocouple with thermally conductive adhesive to the hole of the MOSFETs heatsink. • In order to protect the power supply and the MOSFET, it would be nice to add a current protection to the temperature control board. • A multiplexer could be used to multiplex the thermocouple input and substitute the 3 identical connectors for the different measurement methods. • It turns out that we never used the ISP header for accessing the programmable flash and the fuses of the AT90. Since the connector is very bulky it could be omitted in the next design. This would also make the jumper-configuration of the SPI interface obsolete. Also, a Mini-B USB connector would be nice because it is more compact as well. • The whole board could be made a lot smaller if components were placed closer together. • The voltage-temperature charachteristic is approximated linearly by hardware. The measurement accuracy could be improved by using a higher order polynomial instead. • Measurement accuracy could be enhanced even further by sampling at a higher frequency and averaging over time. 29
C HAPTER 5. C ONCLUSION We enjoyed working on this project during the semester. It gave us an opportunity to do a hands-on hardware design project, to learn about PCB layout and to improve our teamworking skills. Unfortunately, we underestimated the effort that was necessary for both software and hardware development in the beginning.
30
Appendix A
A.1
List of Commands
Table A.1 gives a list of all commands that are understood by the AT90 software. They all are only one character long since this makes processing easier and there is no need for overcomplicating the system with longer commands. The commands can either be sent by the tempsens.exe application or over the serial port. For the latter, a terminal application and a serial COM port connector is necessary. An open-source terminal application is Realterm, for example [12]. (a) Normal Commands
Command 1 2 3 c a s d f g
Function Activate measurement with MAX6675 Activate measurement with AD595 Activate measurement with LTC2053 Toggle the temperature control loop on/off Set temperature setpoint to 50 ◦ C Set temperature control setpoint to 75 ◦ C Set temperature control setpoint to 100 ◦ C Increment temperature control setpoint by 5 ◦ C Decrement temperature control setpoint by 5 ◦ C
(b) Debugging and Development Commands
Commmand m + 9 8 y x
Function Print latest temperature value over the serial channel Increment PWM dutycycle for heating Decrement PWM dutycycle for heating Increment PWM dutycycle for cooling Decrement PWM dutycycle for cooling Print PWM dutycycle of heating signal over the serial channel Print PWM dutycycle of cooling signal over the serial channel
Table A.1: List of Commands for Transmission Over USB or Serial Port
31
A PPENDIX A.
A.2
Circuit Schematics and Board Layouts
A.2.1
Heat Control Board X1 Heatsink
Heat
12V
12V
2
12V
470uF
CON2
2 1
3
1
C1
2k2
HeatSig
CoolSig Sense
T1 FQP50N06
R1
1 2 3 4
2 1 CON1
3k3
CON3
CoolSig 10k
CON4 R2
GND
GND
GND
R3
GND
GND
Figure A.1: Schematic of the Heat Control Board
Figure A.2: Board Layout of the Heat Control Board
32
GND
GND
A PPENDIX A.
A.2.2
Temperature Measurement Board
Figure A.3: Schematic of the Temperature Measurement Board
33
A PPENDIX A.
Figure A.4: Board Layout of the Temperature Measurement Board
34
A PPENDIX A.
A.3
Pictures
Figure A.5: Pictures of the Hardware and PWM Signal
A.4
Code Snippets
The code snippets in this section are sometimes slightly abridged and stripped from statements that would make them unnecessarily complicated. For the complete code, please refer to the attached medium with all project source files.
A.4.1
Using the SPI
The SPI must be configured according to the needs of the MAX6675 chip. The second function is used for exchanging bytes between the register of the MAX6675 and the SPDR register of the AT90. Note that the slave select pin must be reset prior to transmission and set after completion void SPI_init(void) { // define spi pins MOSI SCK,SS as outputs DDRB = (1