+ All Categories
Home > Documents > Final Miniproject Report

Final Miniproject Report

Date post: 20-Oct-2015
Category:
Upload: yogesh-palkar
View: 80 times
Download: 0 times
Share this document with a friend
Description:
Temperature ControllerRTCMemory
55
Department of Electronics and Telecommunication College of Engineering, Pune Project Report on “Universal Temperature Indicator And Controller With USB Interface
Transcript
  • Department of Electronics and Telecommunication

    College of Engineering, Pune

    Project Report on

    Universal Temperature Indicator And Controller

    With USB Interface

  • 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 110907037 2) Sanket Naik 110907032 3) Swapnil Daberao 110907027 4) Yogesh Palkar 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)

  • i

    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.

  • ii

    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 110907037 2) Sanket Naik 110907032 3) Swapnil Daberao 110907027 4) Yogesh Palkar 110907036

  • iii

    Project Title

    Universal Temperature

    Indicator and Controller

    with USB Interface

  • iv

    Table of Content

    Abstract i

    Acknowledgement ii

    Project Title iii

    Chapter 1. Introduction 1

    Chapter 2. Review of Literature 3

    Chapter 3. Hardware Design 6

    Chapter 4. Firmware and Software Development 18

    Chapter 5. Performance Evaluation 30

    Chapter 6. Future Improvements 33

    Appendix

    References

  • v

    List of Figures

    Figure 1. Block Diagram 6

    Figure 2. Power Supply Section Circuit Diagram 7

    Figure 3. Input Section Circuit Diagram 9

    Figure 4. PT100 3 wire compensation Circuit Diagram 11

    Figure 5. Output Section Circuit Diagram 12

    Figure 6. Controller Section Circuit Diagram 14

    Figure 7. Main Routine Flowchart 19

    Figure 8. ISR Flowchart 24

    Figure 9. Screenshot of Application Interface 27

    Figure 10. LM35 Voltage vs Temperature Readings 30

    Figure 11. PT100 Voltage vs Temperature Readings 31

    Figure 12. I2C Timing Diagram

  • vi

    List of Tables

    Table 1. Power Consumption 17

    Table 2. USB Power 17

    Table 3. Mains supply 17

    Table 4. Temperature Sensor Comparison

    Table 5. Bill of Material

  • 1

    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.

  • 2

    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.

  • 3

    Chapter 2: Review of Literature

    Initial research was conducted to find out the most frequently used electronic device in

    home appliances and industries. It was identified that from the microwave oven to the gas geezer,

    from the air conditioned rooms to the furnaces, the common thing used was Temperature

    Indicator and Controller. Some applications also simply indicate the temperature, while others

    control it only. Hence, it was decided to build a low cost, robust, microcontroller based

    temperature indicator and controller that could be used in all such environments. Another

    important conclusion from this research was that while most of the applications themselves are

    self-capable, they also have an interface to a laptop or a computer which is used by the user to

    store the data and analyze it for further use. It was observed that most recently, the laptops as well

    as the computers are doing away with the serial RS232 port and USB is taking its place instead.

    Hence, the interface with the PC was decided to be done using the USB protocol.

    Then, the market demand for this type of device was determined and research on similar

    monitoring devices that are currently sold was performed. According to a report from VDC

    research, the market for industrial temperature monitoring was 15 billion USD in 2011. The ever

    increasing demand in this field required that the devices that are introduced are required to be low

    cost, user friendly and easy to use. There was a rising trend in the demand of the users for a PC

    based application of the temperature controllers. The unit that would be built hence had to

    incorporate all these features.

    Next various sensors that are used in the temperature measurement were studied. Data

    was gathered about the various temperature sensors that are available. The comparison of these

    sensors along with their advantages and disadvantages is given in the Appendix I. Of these, PT100

    and LM35 were chosen. The LM35 can be used in daily applications while the PT100 can be used in

    industrial applications

    Following the selection of sensors, the methods of conditioning their outputs for our unit

    were studied. Application notes and documents of Agilent and National Instruments were referred.

    It was understood that for a controller based temperature measurement system, implementation

    of a Wheatstone Bridge circuit along with three wire compensation configuration is necessary.

    Then, operational amplifiers that are typically used in industry standard temperature

    control products were studied. They included TL081, TL071, ICL7650, LM741, LM308, LM324,

    LM358 and OP07. TL081, TL071 and ICL 7650 are costly. LM741 did not operate using +-5V supply.

    LM324 was a quad operational amplifier which was not necessary. LM358 was a dual version of the

    same operational amplifier. Again dual operational amplifiers were not needed and hence it was

  • 4

    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.

    2.1 Product Specifications:

    Unit Specifications:

    Supply Voltage: USB power or 230Vac mains

    High Voltage Spike Protection

    Maximum Power Consumption: 550mW

    Interface with two temperature sensors: PT100 and LM35

    3 wire Lead compensation for PT100

    Two Set Points for Temperature

    Accurate temperature determination in the range from 0-120:C

    User Adjustable Clock

    Output relays for heater and cooler

    4*4 Keypad Input and LCD output

    1:C temperature resolution

    Plug and Play capability

    Power On Self Test

    Accuracy of 2:C per 100:C

  • 5

    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

    Mechanical Specifications:

    Bezel Size = 144mm*144mm

    Channel Length = 150mm

  • 6

    Chapter 3: Hardware Design

    The entire Universal Temperature Indicator and Controller with USB interface is subdivided into

    five sections which are:

    1. Power Supply Section

    2. Input Section

    3. Controller Section

    4. Output Section

    5. PC section

    Figure 1. Block Diagram

    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.

  • 7

    Power Supply Section:

    Figure 2. Power Supply Section Circuit Diagram

    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.

  • 8

    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

  • 9

    of such fuses, high voltage spikes can be easily tolerated but sustained overvoltage will cause

    circuit damage.

    Input Section:

    Figure 3. Input Section Circuit Diagram

    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.

  • 10

    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 feedback 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.

  • 11

    4. 3 wire compensation:

    Figure 4. PT100 3 wire compensation Circuit Diagram

    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.

  • 12

    Figure 5. Output Section Circuit Diagram

    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,

  • 13

    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 back-

    emf 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.

  • 14

    Figure 6. Controller Section Circuit Diagram

    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 operation

    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.

  • 15

    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.

    3.1 Design of I2C subsection

    A major objective in the design of the TIC is to interface all peripheral integrated circuits

    with the PIC18F4550 using less number of connections. The peripheral devices that needed an

    interface with the PIC were a Real Time Clock, a non volatile EEPROM, a keypad and a LCD. Devices

    which could interface with PIC directly were easily available. But the number of pins required for

    interfacing these devices independently with the PIC was exceeding the available pins in the PIC.

    Hence, devices which could interface to the PIC using very less number of connections were found.

    These devices were either SPI compatible, which needed 3 lines for interface, or I2C

    compatible, which needed only two lines for interface. Also, since 3 peripheral chips were going to

    be interfaced with PIC, SPI compatible devices would have required 3 more lines for slave selection.

    I2C supports in-band addressing which meant only 2 lines was needed for interfacing all three

    peripherals. Although the SPI based devices had an advantage of faster communication speed due

  • 16

    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.

    3.2 Design of USB subsection

    The USB interface dictates the value of the crystal that is used for the PIC microcontroller.

    The PIC architecture demands the crystal frequency be scaled down to 4MHz by the firmware for

    proper USB interface. The firmware is written such that it divides the crystal frequency by 5. This

    frequency is then further used by the architecture for making the operation possible in the USB

    mode. Since the crystal frequency needs to be 5 times 4MHz, a crystal of 20MHz is used.

    The capacitor connected between Vbus pin of PIC and ground is designed to meet the

    inrush current requirement. USB specifications dictate that this capacitor should not be more than

    10uF. Hence the capacitor used is 470nF.

  • 17

    3.3 Power Budget

    Power Budget:

    DEVICE SUPPLY

    VOLTAGE SUPPLY

    CURRENT POWER

    CONSUMPTION

    PIC18F4550 +5V 20mA 100mW

    PCF8574 +5V 100A 500W

    BQ32000 +3 V 100A 300W

    24FC512 + 5V 400A 2mW

    OP07 +/-5V 2mA 20mW

    LM2662 +5V 4mA 20mW

    LCD JHD162A +5V 1.2mA 6mW

    LM35 +5V 60A 300W

    Relay 5V +5V 71mA 355mW

    TOTAL POWER CONSUMED 500mW Table 1. Power Consumption

    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 Supply Current capacity Supply Power capacity

    5V 120mA 600mW 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 Supply Current capacity Supply Power capacity

    5V 1A 5W Table 3. Mains supply

  • 18

    Chapter 4: Firmware & Software Development

    4.1 Firmware Development: The firmware is the code that is present in the PIC microcontroller. This firmware is basically

    responsible for gathering the temperature data in the analog form from the sensors, digitizing it,

    processing the data with the user data obtained through the keypad, displaying the temperature,

    controlling the output relays, and sending the data as and when demanded by the computer unit

    via USB communication bus.

    In this section two major PIC code-flow determining codes along with their description and

    their flowcharts are discussed.

    4.1.1 Main Routine:

    PIC Microcontroller is used for controlling various tasks like Analog to Digital conversion, I2C

    communication with peripherals like the memory, the real time clock and the 8 bit I/O Expander for

    keypad, the USB communication with the computer, etc. The main routine is the part of the code

    that governs the flow of operation and is discussed here.

    Description of Main Routine:

    The controller first initializes all ports for required operations. The next step is initialization

    of all peripherals which includes internal ADC, 8 bit port expander for keypad, memory. In

    initialization stage default values to set-points are assigned and LM35 temperature sensor is

    selected without any external calibration. LCD displays welcome message at startup and then goes

    to Power On Self Test (POST). If any faulty sensor is detected it asks user whether to continue.

    Thus, POST is completed for two sensors and then message is displayed. Keypad interrupt is

    enabled for short time period at start of routine to get keypad entry. According to user entry,

    controller takes decision for selection of modes as shown in flow chart. If the valid keypad entry is

    not present then the next step is to collect data from ADC as per selection of sensor. The data is in

    10 bits digital format. It is calibrated according to internal calibration or external calibration as per

    keypad entry. Temperature is converted in BCD format and sent to LCD data buffer. Controller

    reads clock data and puts it in LCD data buffer in suitable format. Then all this content is updated

    on LCD screen every second. At the same time it checks whether USB host (PC) is present or not

    and sends data to PC if Host is present. After collecting 8 samples of ADC and clock data it stores

    them in memory. When memory read command is sent from PC then it sends all this data to PC. In

    case of any set related entry, microcontroller stops execution of its routine tasks and waits for

    coming out of set mode.

  • 19

    Flow Chart of Main Routine:

    Check

    Keypad

    Entry

    Check USB

    Command

    Figure 7. Main Routine Flowchart

    Initialize Ports

    Initialize Keypad, LCD, ADC, I2C

    Set Clock Select Sensor & Set

    temperature TEMP CLK

    None

    Select ADC channel &

    Read ADC

    Read Clock Data &

    Display on LCD

    Show data on PC Store data to

    memory

    Control Heater &

    Cooler

    YES NO

    Start

    POST

  • 20

    Code of Main Routine: void main(void)

    {

    unsigned int i = 0,j = 0; //Initialize all required

    variables

    unsigned int val; //ADC value

    unsigned char temperature,flaginit = 0; //Temperature and setpoints

    unsigned char ,setptup,setptlo;

    lcddat[18] = 0x20;

    setpoint[0] = 0x31; //Select Default Sensor

    setpoint[1] = 0x35; //Set Default Lower Setpoint

    setpoint[2] = 0x30;

    setpoint[3] = 0x36; //Set Default Upper Setpoint

    setpoint[4] = 0x30;

    InitializeSystem(); //Initialize ports & Interrupts

    #if defined(USB_INTERRUPT) //Initialize USB device

    USBDeviceAttach(); interrupt

    #endif

    Initialise_LCD(); //Initialize LCD and send

    Delay(500); Welcome message

    SendMessage(buf4);

    i2c_init(); //Initialize I2C bus for data

    transfer at rate of 100kHz

    InitializeKeypad(); //Initialize Keypad for getting

    keypad entry

    InitializeADC(); //Initialize ADC for collecting

    Sensor data

    //clock_start(); //Initial start-up for clock

    (Done only once on initial and

    power on to force start osc)

    Delay(65535); //Delay for displaying message

    Delay(65535);

    Delay(65535);

    Delay(65535);

    flag_post = POST_LM(post1); //POST for LM35

    while(flag_post); //Faulty sensor skipped by user

    flag_post = POST_PT(post2); //POST for PT100

    while(flag_post); //Faulty sensor skipped by user

    Initialise_LCD();

    Delay(500);

    SendMessage(buf5); //Display POST Successful!

    Delay(65535);

    Delay(65535);

  • 21

    while(1)

    {

    #if defined(USB_POLLING)

    USBDeviceTasks();

    #endif

    INTCON3bits.INT2IE = 1; //Enable Keypad interrupt to get

    keypad entry.

    Delay(60000);

    INTCON3bits.INT2IE = 0; //Disable Keypad.

    if(setpoint[0] == '1') //Select LM35

    {

    val = ADCRead(0); //Read data from AN0(connected

    to LM35)

    temperature = (val)*0.284369; //Calibrate ADC data.

    }

    else if(setpoint[0] == '2') //Select PT100

    {

    val = ADCRead(1); //Read data from AN1(connected

    to OP07)

    if(calibration_flag) //Check for external calibration

    for PT100

    {

    temperature = (val - calibration[0])*100/

    (calibration[1] - calibration[0]);

    }

    else

    temperature = (val)*0.384369; //Internal Calibration for PT100

    }

    if((flag|flag_temp|flag_cal) != 1) //Check for keypad mode. If not

    any any mode then display on LCD

    {

    lcdcmd(0x0C);

    Delay(100);

    lcddat[22] = setpoint[1]; //Display setpoints.

    lcddat[23] = setpoint[2];

    lcddat[25] = setpoint[3];

    lcddat[26] = setpoint[4];

    if(flaginit)

    {

    if(lcddat[18] == 0x20)

    {

    lcddat[18] = 0x3A; //Second indicating Colon on

    SendMessage(lcddat);

    }

    else

    {

    lcddat[18] = 0x20; //Second indicating Colon off

    SendMessage(lcddat);

    }

    }

    sec = clockdata[0];

  • 22

    clock_read(clockdata); //Read data over I2C for clock

    bq32000

    clocktolcd(clockdata,lcddat); //Convert data from bq32000 in

    display format

    flaginit = 1;

    final[i+j] = temperature; //Put temperature data in memory

    buffer

    ToSendDataBuffer[i] = temperature; //Put temperture data in USB buf

    for(i=1;i

  • 23

    }

    else

    _asm nop _endasm

    ProcessIO(); //Send data to USB

    if(j==48) //Write data to memory after 4

    read cycles for clock (i.e. 4s)

    {

    pageno++;

    write_page_eeprom(final,pageno);

    j = 0;

    }

    i=0; //Update pointers for USB data

    buffer and Memory data buffer.

    j+= 16;

    }

    }//end main

    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.

  • 24

    Flowchart of Interrupt Subroutine:

    INT2 Interrupt

    Figure 8. ISR Flowchart

    Check Keypad

    Entry

    Decode Key

    Clock Set

    Mode

    Temp. Set

    Mode

    Set

    Clock/Temp

    flag = !flag flag_temp =

    !flag_temp

    Check mode

    Ignore Entry

    Get Temp Data Get Clock Data

    Clear Interrupt Flag

    Entry = F

    Entry = B

    Entry = C

    Entry = 0 to 9

    flag_temp=1 flag=1

    No mode

    Return to main code

  • 25

    Code of Interrupt Subroutine:

    void LowPriorityISRCode()

    {

    char col,row,entry,i;

    col = get_col(); //Get column of pressed key

    row = get_row(); //Get column of pressed key

    entry = get_keypad_entry(col,row); //Get entry of pressed key

    switch(entry)

    {

    case 'C': //Clock Set values

    {

    InitializeKeypad();

    lcdcmd(0x0F); //cursor blinking ON

    Delay(100);

    indicator = 1; //Enter into time set mode

    for(i=4;i

  • 26

    lcdcmd(0x0C); //cursor blinking OFF

    Delay(100);

    flag_temp = !flag_temp; //Out of temperature mode

    }

    else

    {

    InitializeKeypad(); //Key pressed without any mode

    so ignore it

    INTCON3bits.INT2IF = 0; //Clear Interrupt flag

    }

    }

    INTCON3bits.INT2IF = 0; //Clear Interrupt flag

    break;

    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

    }

    }

    }

    4.2 Software Development:

    The software is the code that runs the computer application. The software code is the one

    that is responsible for the application Universal TIC the computer application that runs

    alongside the unit for enhanced user interface. The drivers needed for the interface of the unit with

    the computer are HID drivers. These drivers are already present in the operating system. Hence no

    new driver installation is necessary to run this application. In the software code, Application

    Program Interface (API) commands are used. These commands deal with the data obtained by the

    driver and convert it into a format that is understandable by the application software. The two

    commands that are used here are the WriteFile () and ReadFile () command. The following sections

    include the algorithm which the application follows and the control flow description.

  • 27

    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.

    Figure 9. Screenshot of Application Interface

  • 28

    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.

    4.3 USB firmware and Software Development

    Design:

    A Full Speed USB interface has been selected for the TIC. This full speed interface makes the

    TIC compatible with the computers that support even the earliest version of USB. Also another

    consideration is that a High Speed Interface would have put an unnecessary burden on both the

    controller and the PC since the speed at which data needs to be transferred to the PC is not so

    important in the application. The High Speed Configuration demands that the host should attempt

    to gather data from the device 8 times every millisecond while the Full Speed demands just once

    every millisecond. Another major advantage of the Full Speed USB interface is that the data

    transfer in this interface has the least overhead as compared to the other two interfaces.

    The TIC is configured as a Human Interface Device (HID) since the Graphical User Interface

    (GUI) on the PC side is basically designed for interfacing with user. HID configuration has inbuilt

    drivers in every Windows based Operating System which look after the enumeration process and

    error checking. The Microchip Inc. provides an application library for HID interface configuration in

    PIC. This application library has been used in developing the HID compliant firmware for the PIC

    18F4550. A major advantage of the HID interface is that the data transfers use Interrupt type

    transfers which ensure fixed bandwidth every time a transfer is made. This makes sure that every

    time the PIC has data ready at its endpoint and the host polls the PIC, the data is transferred.

    On PC side, the inbuilt drivers for HID configuration deal with the enumeration process and

    ensure that the data transmission and reception successful. With the help of Application Program

    Interface (API) commands, data sent by the PIC can be easily obtained for the GUI for further use.

  • 29

    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.

  • 30

    Chapter 5: Performance Evaluation

    The Temperature Indicator and Controller with USB interface is designed to indicate and

    control temperatures from 10:C to 120:C. With PT100 the temperature can be increased to around

    500:C.

    Temperature Indication Calibration:

    Calibration of unit for LM35 temperature sensor:

    For calibration, a standard thermometer was used. The temperature indicated by the

    thermometer was noted. The multiplier constant that was needed to convert the voltage output of

    the LM35 to the corresponding temperature was then determined. This was done using five

    different temperature readings. The obtained values were then used to calibrate the unit.

    Figure 10. LM35 Voltage vs Temperature Readings

  • 31

    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.

    Figure 11. PT100 Voltage vs Temperature Readings

  • 32

    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.

  • 33

    Chapter 6: Future Improvements

    The Universal Temperature Indicator and Controller with USB interface has a temperature range

    from 10:C to 120:C. It can interface with either a PT100 or a LM35. With the help of LM35, it can

    be placed at a distance of 5 meters from the event whose temperature needs to be controlled.

    Beyond 5 meters, the accuracy goes on decreasing. The size of the unit is 144mm*144mm*150mm.

    This large size is mainly because of the size of the keypad used. Also an LCD display is used.

    Implementation of PID (Proportional-Integral-Derivative) control:

    The current unit firmware does not incorporate the firmware for PID control. This control can be

    incorporated easily. This would improve the control actions and make the temperature transitions

    smoother around set points.

    Confirmed Increase in Temperature Range:

    The unit currently designed has the capacity to work in temperatures ranging from 10:C to 120:C.

    This certainty is established because the temperature calculated by the unit and that on a

    thermometer match. This temperature range can be increased with certainty to temperatures up

    to 500:C with the availability of proper test equipment. Instead of a PT100, if a resistor of value

    270 is connected, the unit can display temperatures of 500:C. However this needs to be tested

    with an actual PT100 and actual high temperatures. This is one of the scopes for future

    improvement.

    Interface with a thermocouple:

    The unit currently can interface with only LM35 and PT100. For much higher temperatures in the

    range of 1000:C, even thermocouples can be used. This interface has not been provided. The

    thermocouple interface would need improvements which are proper calibration for thermocouple

    and ensuring that the potential generated due to various parasitic contacts do not affect the

    measurement.

    Use of Current transmitter:

    The LM35 used can be placed only 5 meters away from the unit. Beyond that, the accuracy

    decreases. As a solution for increasing the range without compromising the accuracy is the use of

    current transmitters. Standard transmitters that deliver current from 4mA to 20mA can be used.

    These current transmitters reduce the errors during long distance analog data communication as

    current is not generally affected in the entire operation of the system. Also the voltage obtained

    across the load is then independent of the line resistance which is the main factor in reducing the

  • 34

    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.

  • A.1

    Appendix I: Temperature Sensor Comparison

    Thermocouple PT100 Thermistor IC Sensor

    Advantages:

    Self Powered Most Stable High Output Most Linear

    Simple, Rugged And Inexpensive

    Most Accurate Fast Highest Output

    Wide Temperature Range

    More Linear Than Any Non-IC Sensor

    Two Wire Resistance Measurement

    Inexpensive

    Disadvantages:

    Non Linear Expensive Non Linear Limited Temperature

    Range

    Least Stable and Least Sensitive

    Current Source Required

    Limited Temperature Range

    Power Supply Required

    Low Voltage and Requires Reference

    Small Resistance Change

    Fragile and Self Heating

    Limited configurations

    Table 4. Temperature Sensor Comparison

  • A.2

    Appendix II. I2C Protocol

    I2C Overview:

    I2C is a bus defined by Philips providing a simple way to talk between ICs by using a

    minimum number of pins. The I2C protocol is a set of specifications to build a simple universal bus

    guaranteeing compatibility of parts (ICs) from different manufacturers. I2C protocol has simple

    Hardware and Software standards. The bus does not define any specific connector or wiring for

    interconnecting integrated circuits. Software defined has a simple set of rules which when followed

    can interface any two I2C compatible interconnected ICs. All I2C devices are designed to be able to

    communicate together on the same two-line bus and system functional architecture is limited only

    by the imagination of the designer.

    I2C features:

    Only two bus lines are required: a serial data line (SDA) and a serial clock line (SCL).

    Each device connected to the bus is software addressable by a unique address and simple

    master/slave relationships exist at all times; masters can operate as master-transmitters or

    as master-receivers.

    It is a true multi-master bus including collision detection and arbitration to prevent data

    corruption if two or more masters simultaneously initiate data transfer.

    Serial, 8-bit oriented, bi-directional data transfers can be made at up to 100 kbps in the

    Standard-mode, up to 400 kbps in the Fast-mode, or up to 3.4 Mbps in the High-speed

    mode.

    On-chip filtering (50 ns) rejects spikes on the bus data line to preserve data integrity.

    The number of ICs that can be connected to the same bus segment is limited only by the

    maximum bus capacitive loading of 400 pF.

    New bus extension & control devices help expand the I2C bus beyond the 400 pF limit of

    about 20 devices and allow control of more devices, even those with the same address.

    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.3

    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:

    Figure 12. I2C Timing Diagram

    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.4

    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.5

    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.6

    Appendix III: USB Descriptors

    During every enumeration, the device exchanges the following important descriptors that

    help the host controller understand which type of device it is communicating with, what should be

    the size of packets that will be available in one communication, what time interval must be

    maintained between two communications, what is the power requirement of the device, etc.

    Device Descriptor:

    This is the Descriptor that is first requested by the host after device has been detected as a

    Low Speed, Full Speed or High Speed device. In order to load a particular driver, the host generally

    considers the Product ID, Vendor ID and the Device Release Number. The Endpoint buffer size is

    kept 8 since larger size is not needed for the basic control transfers. The device class i.e. HID is

    specified in the Interface Descriptor and hence this field is left 0x00 here. Since the device class is

    left 0, the device subclass and protocol code is also left as 0x00. The total number of bytes in the

    entire descriptor is 18 and hence the size of the descriptor is 0x12.

    USB_DEVICE_DESCRIPTOR device_dsc=

    {

    0x12, // Size of this descriptor in bytes

    USB_DESCRIPTOR_DEVICE, // DEVICE descriptor type

    0x0200 // USB Spec Release Number in BCD

    format: USB2.0

    0x00, // Class Code

    0x00, // Subclass code

    0x00, // Protocol code

    0x08, // Max packet size for EP0

    0x04D8, // Vendor ID: Microchip Inc.

    0x003F, // Product ID: Custom HID device demo

    0x0002, // Device release number in BCD format

    0x01, // Manufacturer string index

    0x02, // Product string index

    0x00, // Device serial number string index

    0x01 // 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.7

    USB_CONFIGURATION_DESCRIPTOR config_dsc=

    {

    0x09, // Size of this descriptor in bytes

    USB_DESCRIPTOR_CONFIGURATION, // CONFIGURATION descriptor type

    0x29, // Total length of data for this

    configuration register and its

    subordinate registers

    1, // Number of interfaces in this cfg

    1, // Index value of this configuration

    0, // Configuration string index

    0xA0 // Attributes Bus Powered

    60 // 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, // Size of this descriptor in bytes

    USB_DESCRIPTOR_INTERFACE, // INTERFACE descriptor type

    0, // Interface Number

    0, // Alternate Setting Number

    2, // No. of endpoints in this interface

    3, // Class code: HID

    0, // Subclass code

    0, // Protocol code

    0 // 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.8

    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, // Size of this descriptor in bytes

    USB_DESCRIPTOR_ENDPOINT, //Endpoint Descriptor

    HID_EP | _EP_IN, //Endpoint Address HID_EP = 0x01

    _EP_IN = 0x80

    0x03, //Attributes Interrupt

    0x40, //size

    0x01 //Interval

    };

    USB_ ENDPOINT _DESCRIPTOR endpoint_dsc=

    {

    0x07, // Size of this descriptor in bytes

    USB_DESCRIPTOR_ENDPOINT, //Endpoint Descriptor

    HID_EP | _EP_OUT, //Endpoint Address HID_EP = 0x01

    _EP_OUT = 0x00

    0x03, //Attributes Interrupt

    0x40, //size

    0x01 //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, //Size of this descriptor in bytes

    DSC_HID, //HID descriptor type DSC_HID = 0x21

    0x11,0x01, //HID Spec Release Number in BCD

    format (1.11)

    0x00, //Country Code(0x00 for Not supported)

    1, //Number of class descriptors

    DSC_RPT, //Report descriptor type

    28, //Size of report descriptor in bytes

    0x00

    };

  • A.9

    Appendix IV: Linker Script

    Linker Script:

    The linker script gives the user an idea of how the code will get programmed into the

    microcontroller. PIC18F4550 has 32kB of flash memory (program memory) and 2kB of SRAM (data

    memory).

    Program Memory:

    The program memory is segmented as shown below. Here, memory segment from 0x00 to

    0x7FF is reserved for boot code so-that PIC can be programmed using USB. Hence all interrupt

    vector addresses are remapped from 0x800 to 0x829. The reset vector is remapped to 0x800, the

    high priority interrupt vector is remapped to 0x808 and the low priority interrupt vector is

    remapped to 0x818. Following this the program memory is present till all 32kByte locations are

    occupied. This is followed by 8 byte ID locations where the user can store the identification

    information of the PIC controller they are using. Then the 14 byte locations are reserved for

    configuration bits. Then the device ID is present in two locations. This is preprogrammed at the

    time of manufacturing and when read, it returns the Microchip code for identifying the type of PIC

    which is being used. Then we have the EEPROM which can be programmed if needed.

    CODEPAGE NAME=boot START=0x0 END=0x7FF PROTECTED

    CODEPAGE NAME=vectors START=0x800 END=0x829 PROTECTED

    CODEPAGE NAME=page START=0x82A END=0x7FFF

    CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED

    CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED

    CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED

    CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED

  • A.10

    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 START=0x0 END=0x5F

    DATABANK NAME=gpr0 START=0x60 END=0xFF

    DATABANK NAME=gpr1 START=0x100 END=0x1FF PROTECTED

    DATABANK NAME=gpr2 START=0x200 END=0x2FF

    DATABANK NAME=gpr3 START=0x300 END=0x3FF

    DATABANK NAME=usb4 START=0x400 END=0x4FF PROTECTED

    DATABANK NAME=usb5 START=0x500 END=0x5FF PROTECTED

    DATABANK NAME=usb6 START=0x600 END=0x6FF PROTECTED

    DATABANK NAME=usb7 START=0x700 END=0x7FF PROTECTED

    ACCESSBANK NAME=accesssfr START=0xF60 END=0xFFF PROTECTED

    STACK SIZE=0x100 RAM=gpr3

    SECTION NAME=USB_VARS RAM=usb4

    SECTION NAME=x_buf RAM=gpr1

  • A.11

    Appendix V. Bill of Material

    Quantity Component Part Ref/Value Cost (Rs.)

    Integrated Circuits:

    1 IC1 PIC18F4550 250

    1 IC2 PCF8574 50

    1 IC3 BQ32000 50

    1 IC4 24FC512 30

    1 IC5 OP07 5

    1 IC6 7805 15

    1 IC7 LM2662 25

    Resistors

    1 R1-R5,R13 1k 6

    6 R9, R10 4k7 2

    2 R6, R7 2k4 2

    1 R8 100 1

    2 R11, R12 47k 2

    1 RP1 RESPACK- 8 1k 3

    1 RP2 RESPACK- 8 4K7 3

    Capacitors

    2 C1, C2 33pF 1

    3 C3, C14, C15 47uF 3

    2 C4, C5 22uF 2

    2 C6, C7 220uF 2

    6 C8 C13 0.1uF 4

    1 C16 470nF 2

  • A.12

    Table 5. Bill of Material

    Diodes

    4 D1 D3,D8 LED-RED 2

    4 D4 D7 1N4007 8

    Transistors

    2 Q1, Q2 BC547 4

    Miscellaneous

    1 M1 MOV 40

    1 M2 SWITCH 5

    1 X1 CRYSTAL 20MHz 4

    1 X2 CRISTAL 32.786KHz 4

    1 J1 USB CONNECTOR 20

    1 P1 KEYPAD 4*4 120

    1 P2 LCD 16*2 130

    1 P3 PT100 200

    1 P4 LM35 40

    2 RL1, RL2 RELAY 5V 40

    1 S1 CELL 3V 15

    1 TR1 2300 > 9 0 9 75

    1 - WIRE CABLE 5

    1 - 15 PIN TERMINAL

    STRIP 30

    Box

    1 - BOX UNIT AND

    STICKERS 250

    TOTAL PRICE 1200

  • A.13

    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


Recommended