Académique Documents
Professionnel Documents
Culture Documents
Project Report on
Certificate
I hereby certify the project Universal Temperature Indicator and Controller with USB interface submitted in the fulfillment of the requirement for third year mini project for the year 2011-12 in the Department of Electronics and Telecommunication of the College of Engineering, Pune. Its the record of the project carried out under my guidance and supervision by following students:1) Bhimsen Padalkar 2) Sanket Naik 3) Swapnil Daberao 4) Yogesh Palkar 110907037 110907032 110907027 110907036
The assistance and help received during the project work and sources of knowledge have been acknowledged.
Prof. V. B. Bapat
(Dept. of E&TC, COEP)
Abstract:
The Universal Temperature Indicator and Controller with USB Interface is a unit that continuously monitors the temperature and takes the required control action with the help of a microcontroller. The unit provides a LCD display, where the current time, temperature, and set points are continuously displayed, and a keypad for direct user interface. With the help of USB interface, this data is continuously sent to the PC where a log of the temperature versus the time is maintained. A graph of the temperature against the time is then plotted on the PC. The Universal Temperature Indicator and Controller with USB Interface is currently designed for operation using LM35 and PT100. The operating temperature range is between 0:C and 120:C. With the help of industrial grade PT100, this range can be certainly increased to temperatures up to 500:C. The microcontroller chosen is the PIC18F4550 microcontroller. For data storage within the unit, a memory chip 24C512 is used. For the purpose of acquiring current time, a real time clock chip BQ32000 is used. The keypad is interfaced to the PIC using the 8 bit expander. All the above mentioned integrated circuits are I2C compatible and I2C bus interface is used for internal communication within the unit. The entire unit can be powered up using a USB bus powered connection or using the mains 230Vac power supply.
Acknowledgements
We are grateful to Dr. M. S. Sutaone (HoD E&TC Dept.) for providing us all the laboratory facilities. We feel immense pleasure in expressing our deepest sense of gratitude and sincere thanks to Prof. V. B. Bapat and Dr. A. M. Sapkal for guidance and generous support at every stage of our project work. 1) Bhimsen Padalkar 2) Sanket Naik 3) Swapnil Daberao 4) Yogesh Palkar 110907037 110907032 110907027 110907036
ii
Project Title
iii
Table of Content
Abstract Acknowledgement Project Title Chapter 1. Introduction Chapter 2. Review of Literature Chapter 3. Hardware Design Chapter 4. Firmware and Software Development Chapter 5. Performance Evaluation Chapter 6. Future Improvements Appendix References i ii iii 1 3 6 18 30 33
iv
List of Figures
Figure 1. Block Diagram Figure 2. Power Supply Section Circuit Diagram Figure 3. Input Section Circuit Diagram Figure 4. PT100 3 wire compensation Circuit Diagram Figure 5. Output Section Circuit Diagram Figure 6. Controller Section Circuit Diagram Figure 7. Main Routine Flowchart Figure 8. ISR Flowchart Figure 9. Screenshot of Application Interface Figure 10. LM35 Voltage vs Temperature Readings Figure 11. PT100 Voltage vs Temperature Readings Figure 12. I2C Timing Diagram 6 7 9 11 12 14 19 24 27 30 31
List of Tables
Table 1. Power Consumption Table 2. USB Power Table 3. Mains supply Table 4. Temperature Sensor Comparison Table 5. Bill of Material 17 17 17
vi
Chapter 1: Introduction
The Universal Temperature Indicator and Controller with USB Interface is designed to continuously monitor the temperature and take the required control action using a microcontroller. The LCD display continuously displays the current time and temperature. A keypad is provided for user interface. If connected to the PC with the help of USB interface, whenever the application on the PC runs, the data from the microcontroller is continuously sent to the PC where a log of the temperature versus the time is maintained. A graph of the temperature against the time is then plotted in the application. Features of exporting the data, saving the graph are also provided in the PC application. For acquisition of temperature data, the sensors that are used are LM35 and PT100. The LM35 outputs a direct voltage that changes at the rate of 10mV/ :C. The PT100, on the other hand, is a temperature dependent resistor. This sensor changes its resistive value at the rate of 0.385/:C. This sensor is connected in a bridge network to measure accurately the change in resistance. This resistance change manifests into a voltage change. The voltage thus obtained in case of both the sensors is fed to the PIC microcontroller ADC from where after calibration, the correct temperature is obtained. A major advantage of the PT100 used is that it is by far the most accurate device that can measure a change in temperature. This PT 100 is connected to the bridge network using a three wire connection for more accuracy. The temperature range for this unit is from 10:C to 120:C. The controller used is PIC18F4550 microcontroller that supports a USB interface, a Master Synchronous Serial Port (MSSP) module and an inbuilt programmable Analog to Digital Converter. All these features are used in the unit. These features are the main reasons of choice of the PIC18F4550 for the unit. The unit required a memory storage unit for storing the temperature and time acquired by the unit. Hence an I2C compatible memory chip 24FC512 is used. For minimization of the lines needed for interface with keypad, an I2C compatible remote 8 bit I/O Expander chip PCF8574 is used. For storing the temperature as a function of time, a Real Time Clock chip BQ32000 is used. This chip is also I2C compatible. Thus with the help of an I2C serial bus, the number of lines needed for interfacing the PIC with various chips is reduced. For displaying the data on the unit, a LCD module JHD162A is used. This module is a 16*2 alphanumeric LCD that has provision for contrast adjustment. This data can also be displayed on the PC side with the help of the designed application.
The unit features two user configurable temperature set points and two output contacts of relays. With the help of the two configurable set points the user can declare a band of temperature within which the surrounding or the device under test has to be maintained. If the temperature exceeds the upper set point, one relay contact is turned on. A cooler, if connected to this contact can immediately act to bring the temperature within the given band. On the other hand, if temperature goes below the lower set point, the other relay contact is turned on. A heater connected to this contact can then immediately act to raise the temperature within the given band. Another feature is that user can calibrate the PT100 output. The unit offers the user to set two temperatures and then using these two values the controller adjusts the zero and span and all further temperatures are displayed in accordance with the calibration done by the user. Furthermore, the unit has a capacity of Power-On-Self-Test, in which it detects whether the sensors are connected properly. Any improper connection will result into an error message being displayed on screen. The unit has two sources for power supply; the USB connection and the mains 230Vax power supply. The user has the freedom to choose any one of the above mentioned for powering the unit. If the USB is connected to the PC and the application is run, the data that is obtained is displayed in the graphical form in the application window as well as on the LCD integrated with the unit. In the absence of any such connection, the user has to power up the unit using the 230Vac mains power supply. In this case the unit obtains the data and the data is then displayed with the help of the LCD.
discarded. LM308 had been graded as obsolete in the datasheet although it satisfied our primary criteria of cost and operating supply voltage and minimum power consumption. In its place the datasheet had suggested OP07. Also, the input impedance of OP07 is typically 50M with a bias current of 1.5nA. Thus OP07 would not have affected the working of the bridge circuit. So, OP07, which has been used in industrial grade temperature controllers, is used. The practical difference amplifier circuits of operational amplifiers were then studied from application notes of Texas Instruments. For selection of the communication interface within the unit, a study of the possible interfaces was done. For this, the Philips Semiconductors application note on various communication buses was used. I2C bus was then selected as a communication bus within the device. The basics of this protocol are discussed in Appendix II. Finally industrial mechanical standards were studied to understand the necessary conventions followed in making such a unit of industrial packaging type.
PC application specifications: Real time plotting of temperature v/s time Display of numeric values of temperature and corresponding time Two data formats for saving temperature log viz. .csv and .txt Display of unit status User controllable data acquisition rate
The Power Supply Section generates the required voltages for the entire circuit. The Input section takes in the necessary external inputs which are the temperature sensors and process them so that they can be directly fed to the controller section. The Controller Section processes the inputs received from the Input Section along with the data received from the user through the keypad. It also has its own supporting peripherals. The Controller Section then generates the outputs that are connected to the Output Section from where the heater and the cooler can be connected. The Controller Section also has a direct interface with the PC section and the Display Device.
6
The Power Supply Section is responsible for generating the necessary power for driving the circuits. From the power supply section, voltages of +5V, -5V and +3V are obtained. The circuit has two ways to derive the basic power: a) The USB connecter has two lines that deliver power. The voltage obtained is 5V and the current supplying capacity is 120mA. This output voltage is filtered and used further. b) From the AC mains, a voltage of 230V is obtained. This voltage is fed to the step down transformer. The Metal Oxide Varistor (MOV) rated at 275V is connected across the 230V supply. The output obtained is 9-0-9V. Then a centre tapped full wave rectifier circuit consisting of two diodes 1N4007 is used. The output of the rectifier circuit is filtered and fed to the voltage regulator IC 7805. The output of the voltage regulator is filtered further and a stable voltage of 5V is obtained. The current capacity is more than 250mA.
7
Either of the 5V obtained from above two circuits can be used further. If the Temperature Indicator and Controller is to be operated using the USB power supply, then the switch is positioned as shown in Figure 2. On the other hand if the USB is disconnected, then the switch can be toggled to the other position to obtain the power from the AC Mains supply. In either case the LED at the switch output glows indicating that the circuit has turned on. The 5V obtained at the output of the switch is the used for driving the entire circuit other than the Real-Time Clock BQ32000. For the operational amplifier OP07, a dual supply of +/-5V is used. For obtaining the -5V, LM2662, a switched capacitor voltage converter, is used. The output current capacity of this IC is 200mA. For the Real Time Clock BQ32000, we need a supply voltage of 3V which is obtained using a 3V Lithium Manganese Dioxide battery. This battery provides a high ampere hour rating at low cost as compared to other batteries. Design: 1. Transformer: The input voltage to the voltage regulator 7805 has to be at least 7V. Taking this into consideration, and taking the voltage drop across the diode as 0.7V, the peak voltage at the input must exceed 7.7V. Hence the transformer chosen has the peak voltage of 9V. Since,
With R and C having sufficiently large values, smoothened DC voltage is around 9V. This satisfies the requirement of the circuit. 2. Metal Oxide Varistor: The integral part of the AC mains power supply is the MOV. The MOV is rated at 275V. This is chosen using the fact that the 230V line voltage is sometimes subjected to sustained overvoltages which may burn out the circuitry. Considering that the line voltage can reach up to 270V in normal conditions due to the fluctuations in the line voltage, the output of the transformer can still be easily converted to 5V by the regulator and no circuit damage will occur. However, high voltage spikes can cause the circuit to damage. In such cases, the MOV clamps the line voltage to 275V by passing maximum current through it. However sustained high voltage will cause very high energy dissipation in the MOV that will burn the MOV. However for this to occur, a very high current has to flow through the MOV. Such high currents can be easily removed by protecting the circuit with a fuse. Hence the connection of an external fuse is highly recommended. In the absence
8
of such fuses, high voltage spikes can be easily tolerated but sustained overvoltage will cause circuit damage.
Input Section:
Interfacing of the Temperature Indicator and Controller is possible with two temperature sensors viz. LM35 and PT100. So provision for two sensor inputs is available. LM35 needs a supply of +5V for its operation which has been provided. The output of the LM35 is linear in the range from -55:C to +155:C and is available in the form of voltage. The output of LM35 changes by 10mV per degree centigrade. This voltage is directly fed to the analog to digital converter of the PIC microcontroller. PT100 provides a linear change in resistance with change in temperature. The resistance is 100 at 0:C and changes by 0.385/:C. The resistance of the PT100 is put in a bridge circuit that accurately extracts the difference voltage. This difference voltage is fed to a difference amplifier circuit of OP07. The circuit provides a gain of 10. The output of this difference amplifier is then fed to the analog to digital converter of the PIC microcontroller.
Design: 1. Choice of Operational Amplifier: As explained in literature review, the OP07 was selected since it has the capacity to operate with power supply voltage of +/-5V. The input impedance of this operational amplifier is 50M with an input bias current of merely 1.5nA. Such high impedance and such low bias currents eliminate the concern of the effect the OP07 will have on the bridge network it is connected to. Also the output impedance of OP07 is 60. This output is connected to the Analog to Digital Converter of the PIC microcontroller. The PIC datasheet suggests that the impedance of the analog input must be less than 2.5k. The output impedance of OP07 satisfies this requirement. Also the cost of this amplifier is less. Hence, the OP07 is chosen as the operational amplifier in the circuit. 2. OP07 Gain circuit: At X:C, the resistance is Y and at (X+1):C, the resistance is (Y+0.385) . Hence the difference in output voltage of the bridge circuit for a unit degree Celsius change in temperature is, ( )
Since the resolution of the PIC microcontroller analog to digital converter is approximately 5mV, this voltage must be scaled to 5mV or more. Hence the minimum gain required will be,
So the chosen gain is 10. This gain is determined in terms of the feedback resistance and input resistance. The input resistances R9 and R10 are chosen as 4.7k and the fee dback resistances R11 and R12 are chosen to be same. Since the gain is the ratio of the feedback resistance to input resistance,
Hence R11 and R12 are chosen as 47K. 3. Capacitors: Capacitor used in feedback loop provides stability in the gain and bandwidth. It also compensates for the lead capacitances of various components. Capacitors at the input of operational amplifier act as a compensation circuit that ensures linear output of the attenuator over a wide range of resistance changes and hence temperature changes.
10
4. 3 wire compensation:
The 3 wire compensation technique is used while connecting the PT100 in the bridge network. Since the resistance of the wires cause an error in resistor and hence temperature measurement, this technique is used. It involves the use of the fact that if the wire resistance of the PT100 is introduced in two separate arms of the bridge, the same resistance is introduced in both arms and hence the error is minimized. The two wires that connect in to the different arms of the bridge should have the same length so that they have the same resistance. The third wire is connected to the negative terminal of the supply and hence, in the circuit, it is connected to ground. In the Figure 4, the two wires that connect to the different arms of the bridge are wires A and C while wire B is connected to ground.
Output Section: In the Output circuit, for driving the heater and cooler, relays are used. The relays chosen are rated at +5V and have a coil resistance of 70 ohm. Transistor BC547 is used to drive these relays. The diode connected across the relay acts when a voltage spike in the form of back-emf appears in the relay coil. Whenever the transistor turns off, the current flowing through the coil stops flowing. This induces a very large back-emf in the coil which might cause circuit damage. However this excess voltage gets clamped to 0.7V because the diode gets forward biased and dissipates the excess energy through it. The capacitor connected across the relay coil helps in reducing the relay chattering due to external noise.
11
Design: 1. Transistor Circuit: The maximum voltage applied across relay will be 5V. The resistance of the relay coil is 70. Hence, the maximum current that will flow through the coil will be,
Thus a current of around 71mA should flow through the coil for providing the switching action. Hence the maximum current that will flow through the output circuit transistor is always less than 75mA. Hence we choose BC547 for the transistor. It has a sustainable collector current capacity of 500mA which is higher than 75mA. The gain of the transistor is 100. So the base current that has to flow for a collector current of 75mA is 0.8mA. So the resistor at the base of the transistor will be,
12
Hence we choose R4 = R5 = 4.7K. 2. Capacitor and Diode: The capacitor has to sustain voltage of around 5V, every time the relay turns on. Hence a moderate value capacitor of 22F rated at 25V is used. The diode has to sustain peak voltages and current for a very short time due to the backemf of the inductor which is caused by the energy stored in coil of the relay. At any instant the energy stored in inductor is
Considering a silicon diode, a voltage drop of 0.7V takes place. Equating the energy dissipated in the diode with energy stored in inductor,
So the product of current and time comes to around 80Ampere-second. Hence 1N4007 is used. This diode has a surge current capacity of 30A for a period of 8.33ms. This product is 250mAmpere-sec which is greater than 80uAmpere-sec. This satisfies the requirement of the circuit.
Controller Section: The microcontroller used in the circuit is PIC18F4550. This microcontroller is interfaced to the Real Time Clock BQ32000, the 8 bit Expander PCF8574 and the 64KB serial EEPROM 24FC512 using the I2C bus. It is also interfaced with the LCD module JHD162A. All the necessary data is then sent to the PC through the USB. The PCF8574 has an interrupt pin which is given to the PIC microcontroller. The BQ32000 has a configurable output pin which is given to the PIC microcontroller. Every peripheral chip that is connected to the PIC acts as a slave device and the PIC acts as a master device. The PCF8574 address pins A2A1A0 are connected to yield 100 as address. The 24FC512 address pins A2A1A0 are connected to yield 000 as address. The BQ32000 has its address hardcoded in the chip and hence it cannot be manipulated by the user.
13
The keypad used is connected to the PCF8574 8 bit I/O bus. The PCF8574 is then interfaced using I2C bus to the PIC microcontroller. Thus, instead of using 8 pins for keypad, we can restrict the controller to using the 2 pin I2C bus and still interface with the keypad through the PCF8574. Another important feature of the PCF8574 is the active low interrupt it provides when it detects any change at the 8 pin port when it is configured as input. This feature enables in detecting a key press. Hence the active low interrupt pin is connected to the INT2 pin of PIC microcontroller. Whenever a key press is detected, the PIC is interrupted and it goes through the routine that detects which key is pressed and takes the required action. The interrupt of PCF8574 is reset and reactivated automatically when the data from the port is read by the PIC or a new data is written to the port by the PIC. The 8 resistors RESPACK of 4.7k is used to increase the speed of opera tion and reliability of the PCF8574 in the input mode. This pull up resistor configuration increases the detection of key press quick and reliable. The 64KB EEPROM 24FC512 is interfaced to the PIC using the I2C bus. It has a write protect pin which is connected to ground allows for read and write operations. If it was left open or connected to +5V, it would have been write protected. This would have rendered it useless in the circuit since the time data and the temperature is continuously written into the memory for future reference.
14
The Real Time Clock is also interfaced to the PIC using I2C bus. The crystal of 32.768 kHz is connected at the oscillator input pins of BQ32000. The configurable interrupt output is connected to the RB3 input pin of the PIC. This output pin is configured to generate a 1Hz clock and is used while displaying the time data on the LCD by the PIC. The LCD module JHD162A is interfaced to the PIC. The data lines of the LCD module are connected to PORT D of the PIC and the control lines of the LCD module, RS (Register Select), RW (Read/Write) and EN (Enable) are connected to pins RC0, RC1 and RC2 of the PIC. The contrast of the LCD display is adjustable by varying the voltage at the VEE pin. This voltage has to be kept below 1V for the LCD display to be readable. The LCD module does not change power consumption if the contrast is changed. Any increase in voltage at this pin decreases the contrast. Hence it has been connected to ground. The PIC microcontroller has been driven by a 20MHz crystal as it is required to communicate with PC using USB. The entire PORTB has been pulled up to +5V by using 8 resistors RESPACK of 1k. This has been done because of the 8 pins, the SDA, SCL, INT2 and RB3 pin needed to be pulled up to +5V. This demands use of four resistors. In order to save board space, the resistors have been replaced by 8 resistors RESPACK. This connection also does not affect the functionality of the other pins of the port. PC section: In the PC section, a GUI is prepared. The PC is interfaced to the Hardware using a USB bus.
to no limitation on the size of words, the speed which I2C supported of minimum 100 kHz was more than sufficient for the TIC. Hence, I2C compatible peripheral chips are used. Hence, for the Real Time Clock, BQ32000 is used. It is I2C compatible real time clock IC. For keypad, PCF8574 is used. It is an 8 bit expander with I2C interface. For memory, 24FC512 is used. It is I2C compatible EEPROM. In the design of the I2C interface of these peripherals, the addresses were initially finalized. The BQ32000 has a hardcoded address. So, the hardware is designed to ensure that the configurable address pins of the remaining two chips, viz. PCF8574 and 24FC512 make the addresses of those two different from each other and from the BQ32000. Another design consideration that is made is the speed at which I2C operates. The BQ32000 and 24FC512 can operate at speeds of 100 kHz and 400 kHz and the PCF8574 can operate at the speed of 100 KHz. Hence the bus could be clocked at the speed of 400 kHz for the interface with BQ32000 and 24FC512 while for interface with PCF8574, the bus could be clocked at 100 kHz. The other option was that the bus could be clocked at 100 kHz for all the peripheral chips. The second option is preferred. This is because interfacing with the 24FC512 and BQ32000 did not cause any degradation in performance of the system. Another important factor is that the speed of 100 kHz is an industrial standard for I2C interface. The PIC is configured as the master in the I2C interface. The I2C bus is operating at 100 kHz continuously. Hence the Slew Rate Control bit in the PIC is configured as low since at such low speeds, EMI is not observable. Had the speed been 400 kHz or more, this bit would have been set. When the bit is set the slew rate control circuit in the PIC smoothens out the transitions from low to high and high to low and hence reduces the EMI.
Taking the remaining components into account like the resistors and the LEDs, the additional power that will be needed is not greater than 50mW. So the entire circuit consumes only 550mW power maximum. Also the relays are not continuously turned on. This reduces the power consumption in most cases to 200mW. Powered from USB: Power Supplied by USB is 5V, 120mA. This amounts to 600mW. Thus the entire can be easily powered using a USB connection. Supply Voltage capacity 5V Supply Current capacity 120mA
Table 2. USB Power
Powered from AC mains supply: When powered using the 230Vac mains, the entire circuit is powered through a 7805 which has a maximum supply current capacity of 1A at 5V. This is tantamount to a power dissipation of 5W which is greater than what the entire unit needs. Thus the entire unit can also be easily run using the 230Vac mains supply. Supply Voltage capacity 5V Supply Current capacity 1A
Table 3. Mains supply 17
TEMP
Show data on PC
YES
NO
//POST for LM35 //Faulty sensor skipped by user //POST for PT100 //Faulty sensor skipped by user //Display POST Successful!
20
while(1) { #if defined(USB_POLLING) USBDeviceTasks(); #endif INTCON3bits.INT2IE = 1; Delay(60000); INTCON3bits.INT2IE = 0; if(setpoint[0] == '1') { val = ADCRead(0); temperature = (val)*0.284369; } else if(setpoint[0] == '2') { val = ADCRead(1); if(calibration_flag) { temperature = (val - calibration[0])*100/ (calibration[1] - calibration[0]); } else temperature = (val)*0.384369; } if((flag|flag_temp|flag_cal) != 1) { lcdcmd(0x0C); Delay(100); lcddat[22] = setpoint[1]; lcddat[23] = setpoint[2]; lcddat[25] = setpoint[3]; lcddat[26] = setpoint[4]; if(flaginit) { if(lcddat[18] == 0x20) { lcddat[18] = 0x3A; SendMessage(lcddat); } else { lcddat[18] = 0x20; SendMessage(lcddat); } } sec = clockdata[0]; //Display setpoints. //Internal Calibration for PT100 //Check for keypad mode. If not any any mode then display on LCD //Enable Keypad interrupt to get keypad entry. //Disable Keypad. //Select LM35 //Read data from AN0(connected to LM35) //Calibrate ADC data. //Select PT100 //Read data from AN1(connected to OP07) //Check for external calibration for PT100
21
//Read data over I2C for clock bq32000 //Convert data from bq32000 in display format //Put temperature data in memory buffer //Put temperture data in USB buf
ToSendDataBuffer[i] = temperature; for(i=1;i<8;i++) { final[i+j] = clockdata[i-1] & 0x7F; //Put clock data in memory buf ToSendDataBuffer[i] = clockdata[i-1] & 0x7F; //Put clock data in USB buffer } lcddat[29] lcddat[28] lcddat[30] lcddat[31] = = = = (temperature) % 10 + 0x30 ; //LSB of temperature (temperature/10) % 10 + 0x30;//MSB of temperature 0xDF; //Degree sign 0x43; //Centigrade Sign //Display all data on LCD
SendMessage(lcddat);
setptup = (setpoint[3] - 0x30)*10 + (setpoint[4] - 0x30); setptlo = (setpoint[1] - 0x30)*10 + (setpoint[2] - 0x30); final[j+8] = setpoint[0]; final[j+9] = setptlo; final[j+10] = setptup; for(i = 11;i<16;i++) final[i+j] = 0; ToSendDataBuffer[8] = setpoint[0]; ToSendDataBuffer[9] = setptlo; ToSendDataBuffer[10] = setptup; if(temperature > setptup) { COOLER = 1; HEATER = 0; } else if(temperature < setptlo) { COOLER = 0; HEATER = 1; } else { HEATER = 0; COOLER = 0; } //Put sensor data and setpoints in USB buffer //Put sensor data and setpoints in Memory buffer
//Turn OFF cooler and turn ON heater //If temperature is in set band //Turn OFF bothe heater & cooler
22
} else _asm nop _endasm ProcessIO(); if(j==48) { pageno++; write_page_eeprom(final,pageno); j = 0; } i=0; j+= 16; } }//end main //Update pointers for USB data buffer and Memory data buffer. //Send data to USB //Write data to memory after 4 read cycles for clock (i.e. 4s)
4.1.2 Interrupt Subroutine: The controller enters an interrupt subroutine (ISR) whenever it is interrupted by the interrupt output of the keypad. The following described code is put in the Low Priority ISR. Description of Interrupt Subroutine: The keypad operation is divided in 4 modes. Any other key pressed without selecting any modes defined below is rejected. The four modes are: Temperature Set: If the key corresponding to Temperature is pressed then microcontroller goes in this mode and accepts user inputs for sensor selection and set-points. After each entry Set button needs to be pressed to send corresponding data to respective subroutines. Clock Set: If the key corresponding to Clock is pressed then microcontroller goes in this mode and cursor moves on LCD screen to get entry for clock input. Once all inputs are entered, user presses Set key to set the clock as per requirement. Calibration: This key is corresponding to calibration of PT100 using external resistors. In this mode external resistors are connected in place of PT100. Values of ADC for these resistors are stored in calibration buffer to calibrate the sensor output. Set: This key is used to complete each mode and take microcontroller out of ISR.
23
Decode Key
Entry = F Entry = 0 to 9
Entry = B
flag=1
flag_temp=1
Check mode
Entry = C
Set Clock/Temp
No mode
Ignore Entry
flag = !flag
flag_temp = !flag_temp
24
//Get column of pressed key //Get column of pressed key //Get entry of pressed key //Clock Set values //cursor blinking ON //Enter into time set mode //Copy current clock data & 0x0F; //Cursor to required position //Set clock mode //Clear Interrupt flags
//Temperature Setpoints
//Send "Enter temperature" message to LCD //Wait for next Entry //cursor blinking ON //Cursor to required position //Set temperature mode //Clear Interrupt Flag
25
default: { if(flag == 1) //Check for clock mode { execute(entry,clock_buffer,indicator); // Put entry in clock buf indicator = 0; } else if(flag_temp == 1) { getsetpoint(entry,setpoint); //Put entry in setpoint buffer } InitializeKeypad(); //Wait for next entry INTCON3bits.INT2IF = 0; //Clear Interrupt } } }
26
Universal TIC application Algorithm: 1) Check whether unit is connected to PC. 2) If yes, show the unit status as Connected and go to step 3. Else, show the unit status as Disconnected and wait till the device is connected. 3) To display the previous data (from memory), click on button Show Previous Data. The command 0x81 is sent to unit. 4) After receiving this command, the unit will send the data from memory. 5) When data from memory is being plotted, real-time data cannot be taken from unit. 6) Once the memory is empty, click on button Show Current Data. The command 0x80 will be sent to the unit. 7) After receiving this command, the unit starts sending the current data. Above process is repeated periodically after the user configured time interval.
27
Description: The data sent by device is a 64 byte buffer. This buffer contains all the information about set points, current temperature, type of sensor used, current date & time, etc. Using contents of the buffer, the information is shown on the user interface of the application. When data is read from memory, the display is updated at a faster rate as the data is not real time but is already available. In this case, input buffer contains 4 blocks of information. Each information block is of 16 bytes. In case of real time data, input buffer contains 1 block of information. Here the sampling interval can be varied. The user can change it from 1 second to 10 second in steps of 1 second, depending on which the update rate of the user interface of the application changes. A screen shot of the GUI is shown in Figure 9.
On the controller side, with the help of Microchip Inc. application libraries, the device has been made compatible with the PC. The firmware in the PIC has details about the device descriptor, vendor ID, product ID, configuration descriptor, interface descriptor, endpoint descriptor, etc. Brief Explanation of the USB communication: Each time the TIC is connected to the PC, it first gets detected by the host controller in the PC. Following this, communication link in the form of pipelines is established between the host controller and the PIC present in TIC. This is then followed by the enumeration process. Once enumeration is successful, Windows will add the TIC in the Device Manager display in the Control Panel. Following this, the host controller continuously polls the device after regular intervals checking whether data needs to be transmitted. If data is ready to be transmitted, the data transaction occurs. This communication is generally referred to as Application Communication. Upon removal, this device is removed from the display. During Enumeration, the device initially gets powered up. Then because of the pull up resistor configuration on device side and pull down resistor configuration on the host side, the device gets detected by the host. No USB traffic flow has begun. Also the pull up resistor configuration on the device side indicates whether the device is low speed or full speed. This is then followed by assigning an address to the device. Then finally after assigning the addresses, the host requests for the various descriptors of the device using which the device gets configured and linked to a particular driver on the PC side. Whenever the device gets removed, the host detects the removal and simply makes the device address available for a new device. During application communication, on the PC side, using API commands, the application reads from and writes to the device. On the device side, data transferring is done by placing data to send in the USB controllers transmit buffer or retrieving received data from the receive buffer, and on completing a transfer, ensuring that the device is ready for next data transfer. Each transaction involves three phases; the first is the token phase, then the data phase and finally the handshake phase, with each phase containing packets. In general each packet has a packet identifier which identifies the packet type used, the number of the data transaction which helps in keeping a track of the data transfer. Communication initiates with the token phase with the host sending out token packet that contains the address and the endpoint of the device. This is then followed by the data phase when the actual data is exchanged. All packets involved in the token and data phase have provision for error correction. Then finally at the end of each transaction a handshake packet is exchanged when the device or the host acknowledges a transaction as error-free, undetected or fast.
29
30
As expected from the LM35 datasheet, the temperature increases by almost 10mV for every centigrade change in temperature. The actual obtained readings are shown in Figure 10. The ADC outputs obtained for temperature readings were noted and the multiplier constant was then determined. The multiplier constant obtained is 0.284369. The value obtained is then the actual temperature. Calibration of unit for PT100 temperature sensor: As specified in the PT100 calibration sheet, the PT100 was assumed to be accurate and the resistance was assumed to be changing by 0.385/:C. The PT100 is connected in a three wire fashion to the Wheatstone Bridge network. The OP07 circuitry provided a gain of 10 and the output of this amplifier was applied to the ADC of the controller.
31
Figure 11 demonstrates the actual output voltage readings that are observed. As can be seen in the above figure, the output of the OP07 circuit is almost linear. The output voltage changes at almost 7mV per degree centigrade. As the user is allowed to calibrate the PT100 connection, the multiplier constant of the unit is determined in real time. Also if the user prefers to use the by default calibration, the multiplier constant has been determined as 0.384369. PT100 circuit deviation from actual temperature and the effect on accuracy: Ideally, for 0:C the resistance of the PT100 is 100 and for 1:C the resistance is 100.38. Accordingly the OP07 output voltage change for 1:C is 7.4mV. So at 100:C, the output should ideally be 740mV. However because of the circuit connection, the output voltage at 100:C is ( )
Thus the deviation is of around 13mV. Hence the accuracy of the unit will degrade by 2:C for every 100:C change in temperature using PT100 as the temperature sensor. Resolution: LM35: The LM35 sensor can distinguish between temperatures that are a degree Celsius apart. Every degree Celsius change causes a change in output voltage by 10 mV. The ADC of the controller has been programmed to a resolution of less than 5 mV. Hence the unit has a resolution of 1:C using LM35 temperature sensor. PT100: The PT100 sensor can distinguish between temperatures that are a degree Celsius apart. The PT100 output changes at 0.38/:C. The analog circuitry converts this to a change of 7mV/:C. Again with the available resolution of the ADC, the unit has resolution of 1:C using PT100. Zero Drift and Sensitivity Drift Testing: An important parameter in the testing of any unit is zero drift and sensitivity drift testing. The testing procedure was to subject the sensors to rising and falling temperatures and checking for consistency in the sensor reading. The sensor outputs were noted after random time intervals. The outputs obtained were consistent with the previous output making it sure that there were no zero drift or sensitivity drift errors. Performance Evaluation of Microcontroller Unit and Application Code Stability: The entire working unit was connected to the computer and the code was tested for stability for two hours continuously. The entire unit and the application worked without any error. This established the stability of the codes on both the sides.
32
errors. At the unit end a corresponding receiver will be used which will actually be a precise 250 resistance. Reduction in Unit size: The front panel of the unit has dimensions of 144mm*144mm. This large size is because of the size of the keypad. If this keypad is reduced in size, the size of this unit can be scaled down to 144mm*72mm. This size reduction of keypad can be achieved by using a keypad having 4 keys, which can support the entire functioning of the unit. Such a keypad can be made using simple push button reset switches. Use of LED display: The current unit uses a LCD display. This LCD display causes a limited range of sight, that is if the observer is standing beyond 2 meters, it is impossible for him to see the temperature indicated on the display. Hence instead of LCD display, a LED display can be incorporated. This LED display will have large size seven segment display that will enable the observer to read the display from distances of 10 meters or even more. Wireless Data Transmission: The temperature data that is acquired using the PT100 and LM35 is stored in the microcontroller first. From here the data is sent to PC over the USB. If this unit is used in a plant, then the unit might be placed away from the main computer and the USB protocol might not support the long distance cabling. In such case, the data can be relayed over a series of wireless data repeaters to the main control computer. Thus the temperature sensor can also be easily incorporated in a SCADA system.
34
Advantages: Self Powered Simple, Rugged And Inexpensive Wide Temperature Range Disadvantages: Non Linear Least Stable and Least Sensitive Low Voltage and Requires Reference Expensive Current Source Required Small Resistance Change Non Linear Limited Temperature Range Fragile and Self Heating Limited Temperature Range Power Supply Required Limited configurations Most Stable Most Accurate More Linear Than Any Non-IC Sensor High Output Fast Two Wire Resistance Measurement Most Linear Highest Output Inexpensive
A.1
I2C communication: Protocol: Start of communication is indicated by pulling the SDA line from high to low when the SCL line is high. End of communication is indicated by the pulling the SDA line from low to high when the SCL is high. These are the only two states when the SDA line is allowed to change when the SCL is high. Otherwise, the SDA line should change only when the SCL line is low, with the data on SDA line being valid when the SCL goes from low to high. Every data that is put out on the SDA line by the master has to be in 8 bit format with the most significant bit being put out first.
A.2
Arbitration: Here the masters output some data and clock cycles. The outputs of both the masters dont match. For the first time when one master outputs a high and the other master outputs a low, the master that outputs a high loses the arbitration and becomes the slave. The master that outputs a low then becomes the Bus Master. Procedure:
Every I2C communication involves the following steps: 1) An IC that wants to communicate waits until it sees no activity on the I2C bus. This condition is reached when the previous master makes the SDA line high when the clock is in the high state. 2) When the bus gets free, the IC asserts itself as the master. All other ICs then become slaves. In case of multimaster configuration when two or more masters try to claim the bus master position, arbitration occurs and the true bus master is determined. 3) The master provides a clock signal on the SCL line and the data on the SDA line. The clock signal will be used by all other ICs as the reference time. 4) The master then indicates Start of the communication by the protocol explained above. Then the master puts out the unique binary address of the IC that it wants to communicate with in serial form. This is followed by outputting a bit that indicates whether it wants to send data or receive data. This bit is 1 if the data is to be read from and is 0 if the data is to be written to. The address is restricted to 7 bits. Hence, a master can communicate with 128 I2C devices with appropriate addressing. This step takes eight clock pulses. 6) On the ninth clock pulse, the addressed slave acknowledges the master whether it is ready to communicate. This is a one bit acknowledgement. If the slave acknowledges, it pulls the SDA line low or else it is left high. Once the master receives the acknowledgement bit and if this bit indicates a yes to communication the data transfer gets initiated.
A.3
8) The master IC then sends or receives data as indicated in the read/write bit it outputs in the eighth clock cycle. The IC can send or receive data in the form of 8-bit words. After every 8-bit data word gets transmitted or received, the sending IC expects the receiving IC to acknowledge the transfer is going OK. This is again in the form of acknowledgement bit which is low if successful and high if not. 9) When all the data is exchanged successfully, the master must free up the bus. This is done by using the Stop of communication as explained in the protocol above. Terminology for Bus Transfer: F (FREE) - the bus is free; the data line SDA and the SCL clock are both in the high state. S (START) or SR (Repeated START) - data transfer begins with a start condition (not a start bit). The level of the SDA data line changes from high to low, while the SCL clock line remains high. When this occurs, the bus becomes busy. C (CHANGE) - while the SCL clock line is low, the data bit to be transferred can be applied to the SDA data line by a transmitter. During this time, SDA may change its state, as long as the SCL line remains low. D (DATA) - a high or low bit of information on the SDA data line is valid during the high level of the SCL clock line. This level must be maintained stable during the entire time that the clock remains high to avoid misinterpretation as a Start or Stop condition. P (STOP) - data transfer is terminated by a stop condition, (not a stop bit). This occurs when the level on the SDA data line passes from the low state to the high state, while the SCL clock line remains high. When the data transfer has been terminated, the bus is free once again. Hardware Configuration: The bus lines are named SDA (serial data) and SCL (serial clock). These two bus lines have the same configuration. They are pulled-up to the logic high level by resistors connected to a single positive supply, usually +3.3 V or +5 V. Designers are now moving to +2.5 V and towards 1.8 V in the near future. All the connected devices have open-collector (open-drain for CMOS - both terms mean only the lower transistor is included) driver stages that can transmit data by pulling the bus low, and high impedance sense amplifiers that monitor the bus voltage to receive data. Unless devices are communicating by turning on the lower transistor to pull the bus low, both bus lines remain high. To initiate communication a chip pulls the SDA line low. It then has the responsibility to drive the SCL line with clock pulses, until it has finished, and is called the bus master.
A.4
Advantages: Simple Hardware standard Simple protocol standard Easy to add / remove functions or devices (hardware and software) Easy to upgrade applications Simpler PCB: Only 2 traces required to communicate between devices Very convenient for monitoring applications Fast enough for all Human Interfaces applicationsDisplays, Switches, KeyboardsControl, Alarm systems Large number of different I2C devices in the semiconductors business Well known and robust bus
Shortcomings: Low speed Number of Devices limited by the maximum capacitive loading of 400pF. Number of Devices limited to 128 The different devices that are connected on the bus may not be voltage level compatible.
Solutions to Shortcomings: Although low speed is a shortcoming the speeds available up to 3.4Mbps are useful for many applications for which the I2C bus is designed. To overcome the limitation introduced due to capacitive loading the use of I2C demultiplexers like PCA9540 or PCA9546 or PCA9548 may be used. The same demultiplexers can be used to overcome the limitation caused due to limited addressing capability. For introducing the voltage level compatibility, use voltage translators or voltage converter ICs.
A.5
// Size of this descriptor in bytes // DEVICE descriptor type // USB Spec Release Number in BCD format: USB2.0 // Class Code // Subclass code // Protocol code // Max packet size for EP0 // Vendor ID: Microchip Inc. // Product ID: Custom HID device demo // Device release number in BCD format // Manufacturer string index // Product string index // Device serial number string index // Number of possible configurations
Configuration Descriptor: Following the Device Descriptor, the host retrieves the Configuration Descriptor. The important point in this descriptor is the maximum power consumption. Here it is set to 50. This indicates that the device is demanding a maximum current of 50*2=100mA. Another important point is that the in the attributes field, it has been mentioned that the device is bus powered. Since a string descriptor is absent all related fields are kept 0.
A.6
// Size of this descriptor in bytes // CONFIGURATION descriptor type // Total length of data for this configuration register and its subordinate registers // Number of interfaces in this cfg // Index value of this configuration // Configuration string index // Attributes Bus Powered // Max power consumption (2X mA)
Interface Descriptor: Following the Configuration Descriptor, the host receives the Interface Descriptor. The interface descriptor provides information about a function or feature that a device implements. Since the device is not composite device, the interface number and alternate setting number is kept 0. Since two additional endpoints are required as the device is HID, the number in that field is 2. The class code of 3 indicates HID device.
USB_INTERFACE_DESCRIPTOR interface_dsc= { 0x09, USB_DESCRIPTOR_INTERFACE, 0, 0, 2, 3, 0, 0, 0 };
// // // // // // // // //
Size of this descriptor in bytes INTERFACE descriptor type Interface Number Alternate Setting Number No. of endpoints in this interface Class code: HID Subclass code Protocol code Interface string index
Endpoint Descriptor: The Endpoint Descriptor is necessary if additional endpoints are used other than Endpoint 0. Since 2 additional endpoints are used, this descriptor is defined. In the former definition an IN endpoint descriptor is defined and in the latter definition, the OUT endpoint descriptor is defined. The two endpoint descriptors do not differ in addresses but in direction of data flow. As indicated in Attributes, the endpoint demands an interrupt type data transfer. The maximum allowed data size field is 0x40 which is 64 bytes. This is, in fact, the maximum allowed data bytes in an Interrupt Transfer. Hence at a time, the number of data bytes that can be sent is 64. The interval field is set to 1, indicating that the host should poll the device after every 1 millisecond. For control transfers this value is ignored.
A.7
In the endpoint address field, one byte is present. Bits 0 to 3 indicate the endpoint number and bit 7 indicates the direction of data flow with 0 being OUT endpoint and 1 being an IN endpoint. The bits 4 to 6 are zero. Here HID_EP = 1; this indicates that in both cases the endpoint location is same. Only the behavior, that is IN endpoint and OUT endpoint, changes.
USB_ ENDPOINT _DESCRIPTOR endpoint_dsc= { 0x07, USB_DESCRIPTOR_ENDPOINT, HID_EP | _EP_IN, 0x03, 0x40, 0x01 }; USB_ ENDPOINT _DESCRIPTOR endpoint_dsc= { 0x07, USB_DESCRIPTOR_ENDPOINT, HID_EP | _EP_OUT, 0x03, 0x40, 0x01 };
// Size of this descriptor in bytes //Endpoint Descriptor //Endpoint Address HID_EP = 0x01 _EP_IN = 0x80 //Attributes Interrupt //size //Interval
// Size of this descriptor in bytes //Endpoint Descriptor //Endpoint Address HID_EP = 0x01 _EP_OUT = 0x00 //Attributes Interrupt //size //Interval
HID Class-Specific Descriptor: This is the Class Specific Descriptor. The release specification as indicated is HID 1.11. Since the hardware is global, the country code field is kept 0. Since every HID device has an additional report descriptor, it is mentioned in the appropriate field.
USB_ ENDPOINT _DESCRIPTOR endpoint_dsc= { 0x09, DSC_HID, 0x11,0x01, 0x00, 1, DSC_RPT, 28, 0x00 };
//Size of this descriptor in bytes //HID descriptor type DSC_HID = 0x21 //HID Spec Release Number in BCD format (1.11) //Country Code(0x00 for Not supported) //Number of class descriptors //Report descriptor type //Size of report descriptor in bytes
A.8
A.9
Data Memory: Data memory is segmented as shown below. For quicker and efficient access, the microcontroller provides a 256 byte Access Bank shown in the linker script using ACCESSBANK. Of this the Special Function Registers (SFR) occupy the last 160 locations as shown in the linker script using accesssfr and the first 96 locations are used for variable storage as shown in the linker script using accessram. The accessram occupies locations from 0x00 to 0x5F. This is the RAM that is by default used by the controller to store the data variables. For accessing remaining of the 2kBytes of location, the data memory has been segmented into 4 General Purpose RAMs (GPR), each GPR of 256 bytes viz. gpr0 to gpr3. They are useful for storing code variables if the default accessram is not sufficient. The first GPR is reserved for storing variables that cannot fit in the accessram. The fourth GPR is reserved for Stack. The size of stack is so chosen that while in ISR, it can perform tasks like USB data transfer. The remaining locations are used as RAM locations for USB purposes, usb4 to usb7.
ACCESSBANK NAME=accessram DATABANK DATABANK DATABANK DATABANK DATABANK DATABANK DATABANK DATABANK NAME=gpr0 NAME=gpr1 NAME=gpr2 NAME=gpr3 NAME=usb4 NAME=usb5 NAME=usb6 NAME=usb7 START=0x0 START=0x60 START=0x100 START=0x200 START=0x300 START=0x400 START=0x500 START=0x600 START=0x700 START=0xF60 RAM=gpr3 NAME=USB_VARS NAME=x_buf RAM=usb4 RAM=gpr1 END=0x5F END=0xFF END=0x1FF END=0x2FF END=0x3FF END=0x4FF END=0x5FF END=0x6FF END=0x7FF END=0xFFF PROTECTED PROTECTED PROTECTED PROTECTED PROTECTED PROTECTED
A.10
Component
Part Ref/Value
Cost (Rs.)
250 50 50 30 5 15 25
6 2 2 1 2 3 3
1 3 2 2 4 2
Diodes 4 4 Transistors 2 Miscellaneous 1 1 1 1 1 1 1 1 1 2 1 1 1 1 Box 1 TOTAL PRICE BOX UNIT AND STICKERS 250 1200 M1 M2 X1 X2 J1 P1 P2 P3 P4 RL1, RL2 S1 TR1 MOV SWITCH CRYSTAL 20MHz CRISTAL 32.786KHz USB CONNECTOR KEYPAD 4*4 LCD 16*2 PT100 LM35 RELAY 5V CELL 3V 2300 > 9 0 9 WIRE CABLE 15 PIN TERMINAL STRIP 40 5 4 4 20 120 130 200 40 40 15 75 5 30 Q1, Q2 BC547 4 D1 D3,D8 D4 D7 LED-RED 1N4007 2 8
References
[1] R. Mancini, Op Amps For Everyone, Texas Instruments, 2002. [2] M. A. Mazidi and R. D. Mckinlay and D. Causey, PIC Microcontroller and Embedded Systems, Delhi, India: Pearson Education, 2008. [3] J. Axeslson, USB Complete: Everything You Need to Develop USB Peripherals, 3rd ed. Madison: Lakeview Research LLC, 2005. [4] VDCResearch, Industrial Electronic Temperature Controllers Global Market Demand Analysis [Online]. Available: http://www.vdcresearch.com/_Documents/proposal/pro-attachment-2385.pdf [5] National Instruments, Choose the Right Temperature Sensor [Online]. Available: http://www.ni.com/temperature/right_sensor.htm
[6] Agilent Technologies, Practical Temperature Measurements Application Note 290 [Online]. Available: http://cp.literature.agilent.com/litweb/pdf/5965-7822E.pdf [7] J. Irazabal and S. Blozis, I2C manual AN10216-01 [Online]. Available: http://ics.nxp.com/support/documents/interface/pdf/an10216.pdf [8] Microchip Inc., PIC18F2455/2550/4455/4550 Data Sheet [Online]. Available: http://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf [9] Universal Serial Bus, Universal Serial Bus Specification [Online]. Available: http://www.usb.org
A.13