team 10 - final report

Upload: richurachel

Post on 03-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/28/2019 Team 10 - Final Report

    1/93

    THE UNIVERSITY OF BRITISH COLUMBIA

    Electrical and Computer EngineeringEECE 474 INSTRUMENTATION DESIGN LABORATORY

    Team 10Glucose Level Monitoring and Predicting System

    Presents

    Preventing Blood Glucose Level fromFlying High

    Summer 2006

    Prepared by: Emily Chen

    Kaveh Farshad

    Mohammad IslamJames LeechCharles Lin

    Submitted to: Dr. Lee Iverson

    Dr. Lukas Chrostowski

  • 7/28/2019 Team 10 - Final Report

    2/93

    1

    ABSTRACT

    Our team created a device that predicts insulin (medication) dosage based on continuous

    blood glucose readings (a real time spontaneous system). Originally, we use a continuous

    sensor which we have access to so that we can continuously monitor blood glucose levels

    and find an algorithm to predict how high the glucose level will go up to. This has beenchanged to a one-time sensor. Knowing this level we can find how much insulin it takes

    to bring that level down spontaneously. For each patient there are known averages of howmuch insulin a patient needs to bring their sugar level down from glucose readings. The

    problem is that one time readings don't give the diabetic enough information to fully

    understand if the glucose level is going up or down or how high it will ultimately go.Furthermore, to actually find out how high the reading went, the diabetic would need to

    wait for an hour or so to see the final max glucose reading. By this time damage is

    already occurring to the body. Our team studied two methods to predict future glucose

    concentration. First model is the Minimal Model, and the second is the Neural NetworkModel. The Minimal Model will be integrated into our system, while we have made a

    Neural Network Model GUI using MatLab.

  • 7/28/2019 Team 10 - Final Report

    3/93

    2

    TABLE OF CONTENTS

    ABSTRACT 1

    LIST OF FIGURES 4

    1 INTRODUCTION 5

    2 PROJECT BACKGROUND 7

    3 SYSTEM OVERVIEW 9

    4 PHYSICAL IMPLEMENTATION 11

    5 HARDWARE DESIGN 12

    5.1 Continuous Glucose Monitoring Sensor (CGMS) 12

    5.1.1 The Circuitry of the Sensor 12

    5.2 Toshiba T6963C Controller LCD 24

    5.3 ATMEGA32 Microcontroller 24

    5.4 Internal Timer 25

    5.5 Precision Operational Amplifier 26

    5.6 Voltage Inverter 27

    5.7 Sine Wave Generator 28

    5.8 Analog to Digital Converter (ADC) 28

    5.9 Push Buttons for User Interface 29

    5.10 Power Supplies 30

    5.11 PCB Design 31

    6 SOFTWARE DESIGN 35

    6.1 Software Design for ATMEGA32 35

    6.2 LCD Software 35

  • 7/28/2019 Team 10 - Final Report

    4/93

    3

    6.3 Prediction Algorithm 37

    6.3.1 The Minimal Model 37

    6.3.2 Model Equation Prediction 39

    6.3.3 The Neural Network Model 42

    7 TESTING RESULTS 43

    7.1 Hardware Testing 43

    7.1.1 Virtual Testing of CGMS 45

    7.2 Algorithm Testing 49

    7.2.1 Testing the Minimal Model 49

    7.2.2 Testing the Neural Network Model 50

    8 ASSESSMENT AND ANALYSIS 55

    8.1 Hardware 55

    8.2 Software 56

    8.3 Ethics and Morals 56

    9 FINANCIAL ASSESSMENT 58

    10 CONCLUSION 59

    11 REFERENCES 60

    APPENDIX A 62

    APPENDIX B 65

  • 7/28/2019 Team 10 - Final Report

    5/93

    4

    LIST OF FIGURES

    Figure 1: Block Diagram of the System

    Figure 2: CGMS with Sensor and Needle Connected

    Figure 3: CGMS with Sensor and Needle Separated

    Figure 4: Schematic Diagram for the CGMSFigure 5: First Input Signal

    Figure 6: Observation of Sensor CircuitFigure 7: First Observed Signal

    Figure 8: Observation of Sensor Circuit after Modifications

    Figure 9: Second Observed SignalFigure 10: Observations of Sensor Circuit after 2nd Modification

    Figure 11: Third Observed Signal

    Figure 12: Sensor Circuit with Filter

    Figure 13: Second Input SignalFigure 14: Observations of Sensor Circuit with Filter

    Figure 15: Fourth Observed SignalFigure 16: Sensor Circuit with More FiltersFigure 17: Third Input Signal

    Figure 18: Output of Last Two Filters

    Figure 19: Output of the Final StageFigure 20: The LCD

    Figure 21: ATMEGA32 Chip

    Figure 22: 555 Timer as an OscillatorFigure 23: Circuit Schematic for Sine Wave Generator

    Figure 24: Circuit Schematic for Push Buttons

    Figure 25: Push Buttons on the System

    Figure 26: Connector PCBFigure 27: System Mounted onto Second PCB

    Figure 28: System Mounted onto Final PCB

    Figure 29: System with LCDFigure 30: Plasma Insulin vs. Time Graph

    Figure 31: First LCD Test

    Figure 32: LCD System TestFigure 33: Sensor Readings vs. Glucose Values

    Figure 34: Sensor Resistance

    Figure 35: Comparison between MiniMed Data and Simulated Results

    Figure 36: Comparisons of Both Models

    Figure 37: First Day Glucose DataFigure 38: Second Day Glucose Data

    Figure 39: Results from NNMFigure 40: Regression Analysis of the Data

    Figure 41: GUI of NNM

  • 7/28/2019 Team 10 - Final Report

    6/93

    5

    1. INTRODUCTION

    Diabetes mellitus exists as one of the most serious health issue in the world. There are

    two types of diabetes: type I and type II. Type I is most commonly found in childhood or

    and adolescent stages of people while type II is found in adults where bad diet and

    obesity are common factors. Since the body of patients who suffer from diabetes mellitus

    cannot produce insulin normally, type I patients need to test their blood glucose level

    after meal and inject a certain amount of insulin into their body, while type II patients

    take in anti-diabetic drugs orally.

    In the case of type I diabetic patients, after eating a meal, they have no way of

    knowing when their blood glucose level is going to peak; instead, they obtain a blood

    sample from their body after an arbitrary period of time and inject insulin accordingly.

    More often than not, this amount injected is incorrect because of the unknown trend in

    the glucose level. Moreover, there is a delay in which the insulin is absorbed by the body.

    If the patients check their blood glucose level again in a short while, they may find their

    glucose level actually have risen (or declined only slightly). They might inject more

    insulin which results in overdose and the blood glucose level will drop too low.

    This project aims to create an affordable system that can precisely determine the

    trend and the peak value of blood glucose level after a Type I diabetic patient consumes a

    meal. This can assist a patient in calculating the actual amount of insulin that he needs to

    inject in order to compensate for the maximum level. The Glucose Monitoring and

    Predicting System can prevent overdose of insulin by telling the patient not to inject

    anymore insulin when the glucose level is declining. Also, the system lessens the

  • 7/28/2019 Team 10 - Final Report

    7/93

    6

    pressure from repetitive calculations of insulin intake that a patient needs to do after

    meals.

    The system uses a continuous glucose sensor, a microcontroller, and a LCD for

    showing the data. The microcontroller takes in the analog signal that is detected by the

    sensor, and converts it to digital data. By collecting the first fifteen minutes of data after a

    patients meal, the microcontroller simultaneously displays the data using the LCD while

    it notices the trend and predicts the peak value. Moreover, our system can help

    calculating the amount of insulin that the patient needs to inject based on the patients

    weight and age.

    This report shows in details of our design, implementation, and test of the

    system. In the Project Background section, investigations of previously approached and

    designed diabetic devices with similar functionalities are provided. Moreover, their

    weaknesses in comparison to our project are stated. In the Design Requirement section, a

    more detailed design approach and related characteristics of the device is presented. Next,

    in the Results section, the pros and cons of our design and practical issues of such project

    is overviewed. Last but not least, the analysis shows some trouble shooting, moral issues,

    and implementations are further explained.

  • 7/28/2019 Team 10 - Final Report

    8/93

    7

    2. PROJ ECT BACKGROUND

    Currently companies are trying to manufacture artificial pancreas, which is very similar

    to our system. The artificial pancreas would be surgically embedded into a diabetic

    patients body. It would continuously monitor sugar levels and automatically inject

    insulin. However, there are no embeddable glucose monitors available currently.

    Furthermore, FDA approval is difficult to acquire for an embeddable device considering

    the possibility of malfunction, in which the system could manually inject deadly amounts

    of medication into the patient. Our product does not require FDA approval because there

    is no injection of medication. It is only giving a suggested value of insulin intake, which

    is similar to palm pilots that count carbohydrates for the patients. Moreover, even if

    companies were to develop the artificial pancreas technology in the near future, the

    product will be very unaffordable. Our product would serve the majority of diabetics for

    at least a few years and if the artificial pancreas is marketable, then it would serve all

    those who can't afford it which will be the majority.

    So far, the following Diabetes products are out in the market: Accu-Check Pocket

    Compass, Animas ezManager Plus, Clorie King, Diabetes Pilot, Elardo Diabetes Profiler,

    Freestyle Tracker, Glucobase PDA, GlucoseOne, HealthEngage, Personal Diary, and

    UTS Diabetes. They all take the patients records concerning the diet and the glucose

    readings at different times, and estimate the amount of insulin needed by the patient.

    Some of these products only state whether the patients glucose level is too high or low.

    However, they all lack a common factor: time efficiency. This is a very critical factor to

    ignore with diabetes. These devices give suggestions based on many years of trial and

    error analysis, but they are not spontaneously real time systems; therefore not comforting

  • 7/28/2019 Team 10 - Final Report

    9/93

    8

    for patients regarding time and performance. Patients are never aware of what is actually

    happening to their blood behavior regarding Glucose level with such devices.

    Our system is designed to learn about different patients. Since everyone reacts to

    glucose and insulin differently, the system fits different parameters that are required to

    maximize the performance of the prediction with respect to each individual and time.

    This is an advantage because the system is trained to discern each individuals body type

    rather than treat every patient based on just one model; thus it can give more accurate

    predictions and better suggestions.

  • 7/28/2019 Team 10 - Final Report

    10/93

    9

    3. SYSTEM OVERVIEW

    The Glucose Level Monitoring and Predicting System keeps records of past glucose level

    values. When a patient ingests food, the reaction of the glucose level will be recorded.

    The system can also predict the maximum value of the glucose level. The system takes

    the inputs of past blood glucose level, and new glucose levels, and feed these into a

    microcontroller that can predict the peak value after a meal. Also, a LCD will graphically

    show the data for the user. Moreover, it can calculate the amount of insulin that a patient

    needs to inject based on the patients body physical condition.

    The system will serve as an aiding equipment for diabetic patients. This system

    will consist of a MiniMed continuous glucose monitoring sensor that is inserted into the

    skin near the stomach area, a microprocessor/controller to calibrate the sensor readings

    relative to blood glucose and to predict based on the first 5 20 minutes of food ingestion

    how high the blood glucose level will ultimately go. Based on this maximum glucose

    level peak and specific patient information the controller will calibrate units of insulin per

    unit of blood glucose needed to lower sugar levels and this predicted insulin dosage will

    be displayed on an LCD display.

    Our goal for this project is to have a working system that monitors glucose levels

    and displays a graph of the results on an LCD display. Furthermore, the trend of glucose

    increase/decrease will be displayed along with an insulin dosage prediction. Preferably

    there will be a button that the user can push before eating so that the system knows that

    glucose spikes after that point are due to food digestion. The glucose level graph will be

    displayed continuously throughout the day. The following shows a block diagram of the

    system.

  • 7/28/2019 Team 10 - Final Report

    11/93

    10

    MiniMed CGMS

    Sensor

    Sensor datatransmitter

    Receiver andSignal Processor

    Microcontroller:-Receives sensor data

    -Calibrates glucose reading to sensorvalue-Predicts insulin dosage based on

    glucose trends-Outputs current glucose reading, trends,prediction, and previous values to LCD

    display

    LCD Display:

    Outputs glucose graph, current

    glucose value, predicted insulin

    dosage and an arrow indic ting trend

    (increasing/Decreasing glucos e

    readings)

    Wireless datatransmission

    Figure 1: Block Diagram of the System

  • 7/28/2019 Team 10 - Final Report

    12/93

    11

    4. PHYSICAL IMPLENTATION

    The system is a relatively small product that can be carried by a patient easily. The sensor

    is inserted to the patients body at the stomach region where it can read the blood glucose

    continuously. A few times a day the diabetic will manually check their glucose levels and

    enter them into the controller which will ensure the sensor is always calibrated. During a

    meal the diabetic would press a button to indicate they are about to eat, the controller

    would then use the next 5 to 15 minutes to make an insulin dosage prediction. Preferably,

    the diabetic would give half there usual dose of insulin a few minutes prior to eating and

    then the remaining portion would be calculated. All the results will be displayed real time

    to give the diabetic a good understanding of what is happening.

  • 7/28/2019 Team 10 - Final Report

    13/93

    12

    5. HARDWARE DESIGN

    The Glucose Level Monitoring and Predicting System is constructed with the following

    parts:

    1. MiniMed Continuous Glucose Monitoring Sensor (CGMS)

    2. Toshiba T6963C Controller LCD

    3. ATMEGA32 Microcontroller

    4. Internal Clocks

    5. Precision Operational Amplifier

    6. Voltage Inverter

    7. Sine Wave Generator

    8. Analog to Digital Converter (ADC)

    9. Push Buttons for User Interface

    10.Power Supplies

    11.PCB Design

    Detailed hardware designs of these components are described in the following

    subsections.

    5.1 MiniMedContinuous Glucose Sensor (CGMS)

    Our sensor consisted of three electrodes at the tip of its needle, Working electrode

    (WRK), Reference electrode (REF), and Counter electrode (CNT), as the needle is in

    contact with the interstitial fluid (ISF), the glucose in the ISF reacts with glucose Oxidase

    on the WRK to generate Gluconic Acid, further the pH in the ISF around the sensor

    decreases, which leads to changes in the potential by the Iridium Oxide on the CNT in

  • 7/28/2019 Team 10 - Final Report

    14/93

    13

    reference to the REF. As a result as the pH decreases, the voltage at the CNT increases.

    Therefore; the Glucose concentration can be estimated in referenced to the CNT voltage.

    The following shows pictures of the CGMS.

    Figure 2: CGMS with Sensor and Needle Connected

    Figure 3: CGMS with Sensor and Needle Separated

  • 7/28/2019 Team 10 - Final Report

    15/93

    14

    5.1.1 The Circuitry of the Sensor:

    R1 and R2 are resistors that form in the blood through the chemical reactions taken place

    upon contact with the chemicals on the three electrodes of the sensor.

    Figure 4: Schematic Diagram for the CGMS

  • 7/28/2019 Team 10 - Final Report

    16/93

    15

    We fed the signal below into the input of the system,

    0.000us 25.00us 50.00us 75.00us 100.0us 125.0us 150.0us 175.0us 200.0us

    250.0 V

    150.0 V

    50.00 V

    -50.00 V

    -150.0 V

    -250.0 V

    A: v3_1

    Figure 5: First Input Signal

    Further, the following signal was observed

    25kHz

    V3- 250/ 250V

    +V6

    535mV

    +VV5

    - 10V

    +V

    V410V

    +

    U2OPAMP5

    +V

    V2- 10V

    +V

    V110V

    +

    U1

    OPAMP5

    R31000

    R2

    5000k

    R13000k

    A

    Figure 6: Observation of Sensor Circuit

    0.000us 25.00us 50.00us 75.00us 100.0us 125.0us 150.0us 175.0us 200.0us

    500.0 V

    300.0 V

    100.0 V

    -100.0 V

    -300.0 V

    -500.0 V

    A: u1_6

    Figure 7: First Observed Signal

  • 7/28/2019 Team 10 - Final Report

    17/93

    16

    In the below schematic, the value of R2 has been changed to 8000 kOhms, which

    resembles an increase in glucose level of the blood, which would lead to a different

    output signal, as shown below,

    25kHz

    V3- 250/ 250V

    +V6

    535mV

    +VV5

    - 10V

    +V

    V410V

    +

    U2OPAMP5

    +V

    V2- 10V

    +V

    V110V

    +

    U1

    OPAMP5

    R31000

    R2

    8000k

    R13000k

    A

    Figure 8: Observation of Sensor Circuit after Modifications

    0.000us 25.00us 50.00us 75.00us 100.0us 125.0us 150.0us 175.0us 200.0us

    750.0 V

    500.0 V

    250.0 V

    0.000 V

    -250.0 V

    -500.0 V

    -750.0 V

    A: u1_6

    Figure 9: Second Observed Signal

  • 7/28/2019 Team 10 - Final Report

    18/93

    17

    It is noticeable that the peak to peak voltage value of the output signal has increased in

    comparison with the previous output signal

    25kHz

    V3- 250/ 250V

    +V6

    535mV

    +VV5

    - 10V

    +V

    V410V

    +

    U2OPAMP5

    +V

    V2- 10V

    +V

    V110V

    +

    U1

    OPAMP5

    R31000

    R2

    10000k

    R13000k

    A

    Figure 10: Observations of Sensor Circuit after 2nd Modification

    By increasing the R2 value even more, the peak to peak output signal increases more,

    showing that the glucose level has increased further, as shown below

    0.000us 25.00us 50.00us 75.00us 100.0us 125.0us 150.0us 175.0us 200.0us

    1.000kV

    0.750kV

    0.500kV

    0.250kV

    0.000kV

    -0.250kV

    -0.500kV

    -0.750kV

    -1.000kV

    A: u1_6

    Figure 11: Third Observed Signal

  • 7/28/2019 Team 10 - Final Report

    19/93

    18

    The following schematics are the modifications that we made into the design, which

    includes adding a filter to the output of the system.

    A

    C11uF

    +VV8

    - 10V

    +VV7

    - 10V

    +V

    V610V

    +V

    V510V

    +VV4

    - 10V

    +V

    V310V

    +

    U1DLT1014

    +

    U1CLT1014

    +

    U1ALT1014

    25kHz

    V2- 250m/ 250mV

    + V1. 5V

    R81000k

    R71000k

    R61000

    R430000k

    A

    A

    Figure 12: Sensor Circuit with Filter

    The input signal is presented in the graph below,

    0.000us 25.00us 50.00us 75.00us 100.0us 125.0us 150.0us 175.0us 200.0us

    250.0mV

    150.0mV

    50.00mV

    -50.00mV

    -150.0mV

    -250.0mV

    A: v2_1

    Figure 13: Second Input Signal

  • 7/28/2019 Team 10 - Final Report

    20/93

    19

    A

    C11uF

    +V V8- 10V

    +VV7

    - 10V

    +V

    V610V

    +V

    V510V

    +VV4

    - 10V

    +V

    V310V

    +

    U1DLT1014

    +

    U1CLT1014

    +

    U1ALT1014

    25kHz

    V2- 250m/ 250mV

    + V1. 5V

    R81000k

    R71000k

    R61000

    R430000k

    AA

    Figure 14: Observations of Sensor Circuit with Filter

    0.000us 25.00us 50.00us 75.00us 100.0us 125.0us 150.0us 175.0us 200.0us

    2.9650 V

    2.9625 V

    2.9600 V

    2.9575 V

    2.9550 V

    2.9525 V

    2.9500 V

    A: r4_2

    Figure 15: Fourth Observed Signal

    Finally, in order to get a DC signal, more filters had to be added to the design, as shown

    in the graphs and the schematics below, as the value of R7, equivalent to R2 in the

    original schematic, increases, the voltage value of the output signal decreases.

  • 7/28/2019 Team 10 - Final Report

    21/93

    20

    +VV12

    - 10V

    +V

    V1110V

    +C3

    50nF

    +

    U2BLT1014

    +

    C1

    100nF

    +VV10- 7V

    +V

    V38. 5V

    +VV9

    - 10V

    +V

    V420V

    +

    U2ALT1014

    C21uF

    +VV8

    - 10V

    +VV7

    - 20V

    +V

    V610V

    +V

    V520V

    +

    U1DLT1014

    + U1CLT1014

    +

    U1ALT1014

    25kHz

    V2- 2 50m/ 250mV

    +

    V1. 5V

    R1010000k

    R925k

    R522k

    R322kR220k

    R110k

    R85000k

    R7

    6000k

    R61000

    R410000k

    A

    Figure 16: Sensor Circuit with More Filters

    The below graph indicates the input signal fed into the system.

    0.000us 25.00us 50.00us 75.00us 100.0us 125.0us 150.0us 175.0us 200.0us

    250.0mV

    150.0mV

    50.00mV

    -50.00mV

    -150.0mV

    -250.0mV

    A: v2_1

    Figure 17: Third Input Signal

  • 7/28/2019 Team 10 - Final Report

    22/93

    21

    The graph below represents the output before going through the last two filters.

    0.000us 25.00us 50.00us 75.00us 100.0us 125.0us 150.0us 175.0us 200.0us

    -0.960 V

    -0.970 V

    -0.980 V

    -0.990 V

    -1.000 V

    A: r4_2

    Figure 18: Output of Last Two Filters

    The graph below presents the output signal at its final stage, representing a constant

    voltage value, indicating the glucose level.

    0.000us 25.00us 50.00us 75.00us 100.0us 125.0us 150.0us 175.0us 200.0us

    2.200 V

    2.100 V

    2.000 V

    1.900 V

    1.800 V

    A: r9_2

    Figure 19: Output of the Final Stage

    As R7 increases, the output voltage decreases, indicating the change in the glucose level,

    shown below,

  • 7/28/2019 Team 10 - Final Report

    23/93

    22

    +VV12

    - 10V

    +V

    V1110V

    +C3

    50nF

    +

    U2BLT1014

    +

    C1

    100nF

    +VV10- 7V

    +V

    V38. 5V

    +VV9

    - 10V

    +V

    V420V

    +

    U2ALT1014

    C21uF

    +VV8

    - 10V

    +VV7

    - 20V

    +V

    V610V

    +V

    V520V

    +

    U1DLT1014

    + U1CLT1014

    +

    U1ALT1014

    25kHz

    V2- 2 50m/ 250mV

    +

    V1. 5V

    R1010000k

    R925k

    R522k

    R322kR220k

    R110k

    R85000k

    R7

    8000k

    R61000

    R410000k

    A

    0.000us 25.00us 50.00us 75.00us 100.0us 125.0us 150.0us 175.0us 200.0us

    1.800 V

    1.700 V

    1.600 V

    1.500 V

    1.400 V

    A: r9_2

  • 7/28/2019 Team 10 - Final Report

    24/93

    23

    +VV12

    - 10V

    +V

    V1110V

    +C3

    50nF

    +

    U2BLT1014

    +

    C1

    100nF

    +VV10- 7V

    +V

    V38. 5V

    +VV9

    - 10V

    +V

    V420V

    +

    U2ALT1014

    C21uF

    +VV8

    - 10V

    +VV7

    - 20V

    +V

    V610V

    +V

    V520V

    +

    U1DLT1014

    + U1CLT1014

    +

    U1ALT1014

    25kHz

    V2- 250 m/ 250mV

    +

    V1. 5V

    R1010000k

    R925k

    R522k

    R322kR220k

    R110k

    R85000k

    R7

    10000k

    R61000

    R410000k

    A

    0.000us 25.00us 50.00us 75.00us 100.0us 125.0us 150.0us 175.0us 200.0us

    1.500 V

    1.400 V

    1.300 V

    1.200 V

    1.100 V

    A: r9_2

  • 7/28/2019 Team 10 - Final Report

    25/93

    24

    5.2 Toshiba T6963C Controller LCD

    One of our design goals is to produce a continuous glucose level graph along with the

    prediction of the peak value and peak time. For these reasons, we need a graphical LCD.

    We decided to use a 128 by 64 pixel graphic LCD with a Toshiba T6963C Controller.

    The reason that this is the favored LCD is because of the simplicity as well as the

    technicality for us to use. The controller has an onboard font-character generator that

    recognizes hexadecimal values from 00 to 7F as character values. These values are

    associated with the ASCII table ASCII VAL 20 hexadecimal. These will be discussed

    in more detail in the Software Design section. The following figure is a picture of the

    LCD.

    Figure 20: The LCD

    5.3 ATMEGA32 MicrocontrollerLike most of the small systems, a microcontroller is required to control many

    aspects of the functionality. For our system, we have chosen ATMEGA32 for our

  • 7/28/2019 Team 10 - Final Report

    26/93

    25

    microcontroller because it is capable of being programmed by C while having 32 output

    ports and 8 analog to digital conversion channels. Moreover, it has three timers, one of

    which is a 16-bit timer. The AVRISP programmer can also program this microcontroller

    easily once the programmer is installed on the computer. This is very beneficial while

    making changes in the design structure. The following is a figure of the ATMEGA32

    microcontroller.

    Figure 21: ATMEGA32 Chip

    Another reason that contributes to our choice of ATMEGA32 is because of the

    free WinAVR programming software available to us. This allows us to program the

    microcontroller in C. The advantage of using C is that we can use various libraries for

    analog to digital conversions, math functions, and delay routines. These libraries are very

    helpful towards our design. In the Software Design section, there is a more detailed

    description on how we implemented the microcontroller. The pin layout can be found in

    Appendix A.

    5.4 Internal TimersGlucose readings are averaged and outputted at certain set intervals. It is required

    to keep these intervals accurate by using an internal timer to count in 5 second intervals.

  • 7/28/2019 Team 10 - Final Report

    27/93

    26

    As mentioned previously, the ATMEGA32 has 3 internal timers where two are 8-bit

    timers and one is a 16-bit timer. The 16-bit timer allows for timer reset on compare,

    which means a top counting value can be set so that every time the counter reaches that

    top value, it resets itself. In order to calculate 5 seconds intervals accurately, the

    following formula is utilized:

    (1/clk)*NUM = 5sec, where NUM was calculated to be 625000.

    This value was stored in the output compare register. Every time the 16 bit timer reaches

    this value it resets and sets an output compare flag. Polling this flag, we can tell exactly

    when it has reached 5 seconds.

    5.5 Precision Operational Amplifiers

    When dealing with minuscule values such as nano-Amps, precision is an

    extremely important factor. Poor precision will result in very inaccurate results due to the

    low signal to noise ratio. An advantage of using precision operational amplifiers is that

    these operational amplifiers give low bias currents; thus there is less noise generated.

    Since we are dealing with just nano-Amps, we need very small bias currents in order to

    prevent saturation of sensor signals. While most operational amplifiers have bias currents

    in the range of micro-Amps, the LT1014 the precision operational amplifier we chose

    has bias currents in the range of only pico-Amps. The pin layout of LT1014 is shown in

    Appendix A.

  • 7/28/2019 Team 10 - Final Report

    28/93

    27

    5.6 Voltage Inverter

    Since there are negative voltage inputs for operational amplifiers, it is necessary

    to power them with a negative voltage supply. We have designed to use a 555 timer and

    relevant circuitry to invert an input voltage. This occurs in two steps: first the DC input is

    converted to AC, and then the AC is rectified to a negative voltage and fed into the

    operational amplifiers. We can see the bias voltage from the LCD.

    The 555 timer chip is used as an oscillator where the low cycle takes .693 * R2 *

    C1 seconds and the high cycle takes .693 * (R1+R2) * C1 seconds. The following values

    for R1, R2, and C1 are chosen to produce a square wave:

    Figure 22: 555 Timer as an Oscillator

    The two diodes and capacitors are used to convert the AC voltage back to a negative DC.

    When the AC output is high, diode 1 conducts and charges capacitor C2; when the output

    is low, diode 1 blocks voltage and the charged capacitors positive side now becomes the

    reference voltage. This means that that diode 2 will conduct, thus outputting a negative

    voltage.

  • 7/28/2019 Team 10 - Final Report

    29/93

    28

    5.7 Sine Wave Generator

    It is required to have an excitation voltage for the sensor. For this excitation

    voltage, we choose a sine wave with a frequency of roughly 25 KHz and a peak voltage

    of approximately 300 mV. We use two dual wideband operational amplifiers to generate

    this sine wave by converting the DC voltage into a pulse wave at desired frequency. Then,

    we send this signal through a low pass Salen-keys filter where the cutoff frequency is set

    to match the pulse wave frequency. This action modifies the pulse wave into a sinusoidal

    wave.

    We used CircuitMaker to design and test the circuit that has the functionality of

    above. A schematic diagram of the circuit under test is shown in the below figure. The

    operational amplifiers are LMH6622 with 160 MHz bandwidth.

    +V

    V5. 2V

    +VV4

    - 7V

    +V

    V38. 5V

    +VV2

    - 7V

    +V

    V18. 5V

    +C3

    1nF

    +C2

    2nF

    +C1

    1nF

    +

    U2

    LM118

    +

    U1

    LM118

    R62. 05k

    R52. 05k

    R41000

    R31000

    R21000

    R113k

    Figure 23: Circuit Schematic for Sine Wave Generator

    5.8 Analog to Digital Converter (ADC)

    Since the microcontroller works with digital data while the CGMS is working

    with analog data, we need to design an analog to digital converter (ADC). One channel of

  • 7/28/2019 Team 10 - Final Report

    30/93

    29

    the ADC of the microcontroller is used to convert sensor values to binary values. The

    concept is ADC compares the input voltage to a reference voltage that we supplied AVCC

    with. The ADC has 10-bit resolution. Therefore, each bit represents 4.8867 mV when 5

    volt reference is used.

    The ADC is accurate to +/- 2 significant digits as stated in the microcontroller

    datasheet. We have found no problem with this calibration as we only deal with only one

    decimal place. Moreover, our data value does not have to be extremely precise. In order

    to convert from binary value to decimal value, the former is multiplied by 0.0048867, or

    in our case, VRef/ 1024.

    5.9 Push Buttons for User Interface

    In order for the system to be interactive with the users, we need to provide a way

    of input. The users can use three push buttons for entering data into the microcontroller:

    two to scroll up and down the menu, or changing blood glucose, carbohydrates, or insulin

    values; while the third button is used to select or enter values. The following schematic is

    designed to connect the push buttons to the microcontroller:

    PORTB

    +V

    V6

    5V

    R71M

    S1

    Figure 24: Circuit Schematic for Push Buttons

    The microcontroller pins B0 B2 are used and set to 5 volts until any of the push buttons

    is pressed. When a button is pressed, the voltage is decreased to 0 volts. We have also

    implemented a 10 millisecond delay routine to allow debouncing of the buttons. The

  • 7/28/2019 Team 10 - Final Report

    31/93

    30

    following picture shows the integrated buttons of the system. For better visibility, the

    buttons are circled in red.

    Figure 25: Push Buttons on the System

    5.10 Power Supplies

    It did not take long before we realized that we need a power source for the system;

    actually two. There are two power supplies that drive the system. One 9V battery powers

    the microcontroller, the LCD, and the chips. We use a LM805 voltage regulator to

    regulate the voltage at 5V. The second power supply is a 1.55V coin battery. The main

    function is to supply nano-Amps of current to the sensor, and to decouple the sensor from

    the main power supply.

    We calculated the total power consumption of the system. When active, the

    system uses less than 45 mA in total (excluding the sensor). An average 9V battery would

    have a 16 hour life span when used continuously with our system.

  • 7/28/2019 Team 10 - Final Report

    32/93

    31

    5.11 PCB Design

    The Electrical Department is very generous in giving us three PCB submissions.

    However, since the first submission is quite early in the term, we did not have a circuit

    design for our system yet. Instead, we designed a small connector that we needed for the

    CGMS connection. This possible smallest PCB in the course history only has 3 lines.

    Because the pins on the CGMS are extremely small, it is nearly impossible to solder

    wires on. Moreover, we would have to repeat the soldering process for each sensor we

    test, which is very time consuming. Thus, we developed a small connector PCB. The

    following figure shows the actual connector PCB with wires.

    Figure 26: Connector PCB

    Next, we need to design a PCB that holds all of our components together. Our

    idea was to design the PCB so that all the chips and components are soldered onto the

    PCB. Also, we designed it in a way so that the LCD can be stacked with the PCB,

    forming some sort of box shape. Unfortunately, human beings are prone to make silly

    mistakes. Along with the time pressure of the second deadline, we accidentally reversed

  • 7/28/2019 Team 10 - Final Report

    33/93

    32

    the pins for the LCD connection. This error results in a system that looks like the

    following figure.

    Figure 27: System Mounted onto Second PCB

    Note that the PCB design was very simple comparing to the final one. This was because

    we have not tested the sensor completely and this circuit actually did not work. The only

    things that worked at this stage were the LCD and the microcontroller. The system was

    still capable of displaying data that we fed in from the computer.

    For the third PCB submission, we submitted more of the small connector PCB.

    Moreover, we have modified our circuit design. Many new components such as the new

    operational amplifiers, coin battery socket, sine wave generator, et cetera were put in.

    Also, we have fixed the LCD pin error mentioned above. The following figures show our

    final version of the PCB.

  • 7/28/2019 Team 10 - Final Report

    34/93

    33

    Figure 28: System Mounted onto Final PCB

    Figure 29: System with LCD

  • 7/28/2019 Team 10 - Final Report

    35/93

    34

    There is one thing interesting to note about our PCB design: the bottom plane for

    the PCB is all grounded. The reason for this is because the CGMS gives such little values,

    it is necessary for us to reduce noise at any cost. In this case, we have to sacrifice one

    side of the PCB to make everything ground. There is no voltage drop through different

    parts of the PCB, therefore we can minimize noise.

  • 7/28/2019 Team 10 - Final Report

    36/93

    35

    6. SOFTWARE DESIGN

    There are two distinct parts in the software design. One is coding for the hardware, while

    the other is the prediction algorithm. Coding for the hardware is the simpler of two. We

    were able to design codes that can perform tasks as graphing the LCD and reading

    voltage values from outside sources in just a few weeks. However, the prediction

    algorithm is the reason why this is not a two-month project.

    6.1 Software Design for ATMEGA32

    There are not many interesting things about the design for ATMEGA32. Most of

    the time, we just designed the microcontroller to read the values of each pin. There is one

    thing interesting however, is that we designed a 30th

    order FIR filter in order to get rid of

    the sensor noise. The filter is designed using MatLab, and the code is converted to C

    coding with the toolbox within the program.

    We used the first pin in port A for ADC. The first three pins of port B were used

    for obtaining data from the CGMS. All the port C pins are used for controlling the LCD

    while all the port D pins are used for data bus. The code of the microcontroller can be

    found in Appendix B.

    6.2 LCD Software

    The Toshiba T6963C driver has a 64Kb of external ram which is used for writing

    text or graphic values to the display. The memory is initialized into two areas: texts and

    graphs. Text based and graphic based pointers initially point to the starting address of

    these values. For the text memory, we allocated the first memory locations and set the

  • 7/28/2019 Team 10 - Final Report

    37/93

    36

    pointer to 0x0000 in hexadecimal. By using the following formula, we can calculate the

    maximum possible memory that we are able to use in the text mode:

    BYTES_PER_LINE = 128 / 8

    MAX_MEM = 16 * NUM_LINES, where NUM_LINES = 64

    Thus, the total memory utilizes 1024 bytes of data, or 0x100 in hexadecimal, while the

    graphic based address is set to 0x200.

    In order to write data to the LCD, we need to do the following:

    - Check to see if the controller is busy

    - Toggle control bits to write data mode

    - Write 8-bit data to data bus

    - Check to see if controller is busy

    - Toggle control bits to write command mode

    - Write 8-bit command to data bus

    We generalized these process using drivers for the controller. The drivers take the low

    level bit settings and create high level functions such as print_text, print_float, draw_line,

    et cetera.

    To graph the data onto the graphic LCD screen a graphing module was written

    which calculated the location of the pixel to be set based on the floating point value given.

    It calculated the location by dividing the float value by the value of how much each pixel

    was worth in terms of glucose measurements. This pixel would be set and the x axis is

    incremented. If the x-axis reaches of the screen, the graph is shifted to the left by 1

    byte (8 pixels) and the data is continuously graphed. Using this module allows us to

    graph data at any incoming rate below 1khz, therefore, the function generator could be

  • 7/28/2019 Team 10 - Final Report

    38/93

    37

    attached to the analog to digital converter and then function would be continuously

    displayed on the graph, being shifted every time it reached of the way across the screen

    to give the affect of a continuous graph.

    For glucose measurements, have high speed graphing is pointless. Therefore a

    timer is set up to count in 5 second intervals, those intervals are the counted and the used

    is given three rates at which the glucose information is displayed. The first rate is data

    every 30 seconds, the second is data every 1 minute and the third is data every 2 minutes.

    During the data collection period all the samples go through the 30th

    order FIR filter

    which has a cutoff frequency of 1Hz. After sampling these values are averaged for the

    selected time period and then displayed on the graph.

    6.3 Prediction Algorithm

    Since we are dealing with human body, it is quite difficult to model how a

    specific organ will behave at any time. Throughout our research, we have found quite

    interesting facts about type 1 diabetes patients and their blood glucose behavior.

    6.3.1 The Minimal Model

    There are several different approaches that we can follow in order to determine

    the peak of a persons blood glucose level. We have, however, chosen a model that is

    relatively easier than others: the Minimal Model. Due to the rules and regulations of

    health concerns, we could not gain access to a diabetic patient to help us with data

    collection. Therefore, most of the data used in our report can be found on other research

    papers.

  • 7/28/2019 Team 10 - Final Report

    39/93

    38

    As a second step to improve our prediction algorithm, we have integrated the

    minimal model with twelve more auxiliary relations. This makes a semi-closed loop

    algorithm for the control of blood glucose levels in diabetes.

    Our first designed model consists of the classic minimal model coupled with one

    more simple equation to take into account the effect of meal-intake. Differential

    equations used in our model are given below followed a by short description of the

    variables and parameters used in the equations.

    0Ggut(0);)()(

    )0(;)(

    )(

    0)0(;))((2)(2

    GG(0);)(

    )()]([

    ==

    =++=

    =+=

    =

    +++=

    tGgutKabstRgedt

    dGgut

    IoIVi

    tuIbIn

    dt

    dI

    XIbtISiptXpdt

    dX

    b

    V

    tGgutKabsGbSgtGtXSg

    dt

    dG

    G(t) is the plasma glucose concentration measured in (mgdl-1

    ) at time t; I(t) is the

    insulin plasma concentration measured in (mU lt -1); and X(t) is proportional to the

    concentration of insulin in the remote compartment. I(t) describes the insulin action and

    Ggut(t) is the glucose mass in the gut. Gb and Ib are baseline (pre-test) values for glucose

    and insulin concentrations. V is the Plasma glucose distribution volume per unit of body

    weight (dl kg-1

    ); p2 (min-1

    ) is the rate constant of the remote insulin compartment from

    which insulin action is emanated; Sg (min-1

    ) is glucose effectiveness; Si is insulin

    sensitivity; and Rge(t) (mg.min-1

    ) is the rate of gastric emptying. Kabs (min-1

    ) is the rate

    constant of glucose absorption from the gut into the systemic circulation. Furthermore, n

  • 7/28/2019 Team 10 - Final Report

    40/93

    39

    stands for insulin degradation constant; u(t) (mU/L/min) is insulin rate prescribed by the

    control algorithm; and Vi is the insulin distribution volume.

    After a short description of the parameters, we can start to investigate these

    differential equations. We have used, Rge(t) =Dke-kt

    , where D represents the amount of

    glucose ingested, is a constant to determine the shape of the curve, and k is the velocity

    (the rate of gastric emptying) constant.

    S.Natalucci et al. [] used to fit their model for glucose oral test. We have used the most

    commonly used values in literature to estimate our unknown parameters.

    We needed to test the minimal model. Since we cannot use a patient as a test

    subject, we bravely volunteered ourselves for this matter. The results of these tests will be

    provided in the Test Results section.

    6.3.2 Model Equations Prediction

    There are four differential equations along with twelve auxiliary relations and the

    and the experimental data from Guyton et al. The following equation determines the rate

    of change of plasma insulin.

    dA/dt = {(s . ts. (T50)

    s. D) / (t . [(T50)

    s+ t

    s]2} ke . A

    Where A is plasma insulin and ke is first-order elimination constant, t is time after

    injection and s characterizes time course of absorption. T50 is time interval to permit 50%

    of injected dose to be absorbed, and D is insulin dose. A linear dependency of T50 on dose

    is presented as T50(D) = a * D + b where a and b are parameters to characterize

    dependency of T50 on dose. Dividing plasma insulin by distribution volume for insulin

    yields plasma concentration at time t after injection, which leads to the equation

  • 7/28/2019 Team 10 - Final Report

    41/93

    40

    I(t) = A(t) / Vt ,

    I(t) is plasma insulin concentration and Vt is distribution volume for insulin. Further,

    insulin action is delayed relative to the time course of plasma insulin. The values and

    parameters to plot the following Plasma Insulin versus time graph were used from the

    Computer Simulation of Plasma Insulin and Glucose Dynamics After Subcutaneous

    Insulin Injection paper done by Markus Berger and David Rodbard.

    Figure 30: Plasma Insulin vs Time Graph

    Regarding interstitial fluid and receptors, any change in an active insulin

    concentration would be related to the change in plasma insulin as follows,

    dIe/dt = k1 . I(t) k2 . Ie(t)

    In the above equation, Ie is active insulin concentration in hypothetical remote

    compartment, I is plasma insulin concentration, and k1 and k2 are apparent first-order rate

    constants. Also, the plasma insulin concentration representing steady-state conditions at

    times t can be derived using,

  • 7/28/2019 Team 10 - Final Report

    42/93

    41

    Iss(t) = (k2 / k1 ) . Ie(t)

    Iss is plasma insulin concentration equivalent to steady-state insulin. Further, glucose

    utilization depends linearly on steady-state plasma insulin as shown below,

    Gout( Iss) = c . Iss + d

    Gout( Iss) is glucose utilization at plasma glucose concentration, c is slope representing

    insulin sensitivity, and d is intercept representing insulin-independent glucose utilization.

    Also, the equation below, represents the relationship between glucose utilization and

    plasma glucose concentration,

    Gout( G ) = (Vmax . G) / ( Km + G)

    Where Gout( G ) is glucose utilization at plasma insulin concentration, with glucose

    concentration G, Vmax is maximal glucose utilization for reference insulin concentration,

    and Km is glucose concentration for half- maximal response. By replacing Gout( Iss) with

    Gx and Gout( G ) by Ix, and combining the two above equations, we get the following,

    Gout( G, Iss) = {G . (c . Iss + d) . (Km + Gx ) } / { Gx . (Km + G) }

    Also the change in glucose concentration with time is given by the differential equation

    dG / dt = (Gin(t) + NHGB(t) Gout(t) Gren(t))/ VG

    where G is the plasma glucose level, G in is the systemic appearance of glucose via

    glucose absorption from the gut, Gout is the overall rate of peripheral and insulin-

    independent glucose utilization, NHGB is the net hepatic glucose balance, Gren is the rate

    of renal glucose excretion and VG is the volume of distribution for glucose. The net

  • 7/28/2019 Team 10 - Final Report

    43/93

    42

    hepatic glucose balance (mmolh-1

    ) was used as a function of the arterial blood glucose

    level, AG, and plasma insulin level, I.

    6.3.3 The Neural Network Model (NNM)

    As mentioned previously, there are other models which are used to calculate

    blood glucose level. We have found the Neural Network Model (NNM) quite interesting.

    This model is a toolbox integrated in MatLab

    . This model takes in input and normalizes

    the input in order to produce an output. For our case, we have inputs such as current

    blood glucose level, insulin level, insulin dosage, et cetera. The model normalizes these

    inputs using the mean standard deviation method. Then it feeds the output back to the

    input. The model has a hidden layer neuron which consists of 10 neurons for our case.

    Since we had no access to diabetic patients datas, we could only acquire old data used by

    other researchers. A 32-day set was used. We used 25 days of data for training, 5 for

    validating, and 2 for testing. The results will be discussed in the following section.

    The reason why we did not use this model for our system is because of the

    complexity. This model requires constant normalizing and denormalizing. Moreover, it

    requires an abundant source of past data for training. It is nearly impossible for us to get

    that many sources of data to train the model because most patients data are confidential.

    Therefore, we have just used the Minimal Model.

  • 7/28/2019 Team 10 - Final Report

    44/93

    43

    7. TESTING RESULTS

    There are two main aspects that we need to test for the system: Hardware and Algorithm.

    7.1 Hardware Testing

    We have tested our system through out different stages of the project. One of our very

    first tests was the LCD. After writing all the corresponding functions for text and graphic

    displays, we were able to display a sentence. This is shown in the picture below.

    Figure 31: First LCD Test

    After we have gotten the LCD working, we implemented the microcontroller so that it

    was able to display other information and graphs.

  • 7/28/2019 Team 10 - Final Report

    45/93

    44

    When we soldered all the components onto the PCB, we tested it once again. All

    the functions are working as desired. The three buttons can be used to control the menu

    and to enter values that are necessary. The following picture shows that we can enter the

    values to the system.

    Figure 32: LCD System Test

    The CGMS wasnt working as we expected. In fact, we have decided to get rid of

    the usage of the CGMS. One of the main reasons is because MiniMed

    refused to release

    any sort of information that can help us get the sensor working. In fact, they stated that

    the sensor is their intellectual property, which cannot be shared with us. The second

    reason is because the sensor uses chemical reactions. When the chemical gets used up,

    the resistance of the sensor will increase. This means that we have to calibrate it

    approximately every four hours, and the sensor is useless after three days. The way to

  • 7/28/2019 Team 10 - Final Report

    46/93

    45

    calibrate the sensor is by using the one-time sensor where the patient still has to puncture

    a hole in his finger. This defeats the whole purpose of using the CGMS. Therefore, we

    have switched our input data source from the CGMS to the one-time sensor.

    7.1.1 Virtual Testing of CGMS

    Although we have yet been able to get the sensor to precisely function, we were able to

    get a hold of some data that had both the MiniMed sensor readings in nAs and what they

    calculated those readings to be in glucose levels (mmol/ml). Running these values

    through an analysis program that we wrote in Python we were able to exact the method

    used to correlated sensor values to glucose values. MiniMed uses a 1st

    order straight line

    approximation as can be seen in the graph below:

    Sensor readings vs. Glucose Values

    y =1.4337x +1.0715

    0

    5

    10

    15

    20

    25

    0 5 10 15

    Sensor readings (nA)

    Glucosevalue(m

    m

    ol/m

    l)

    Series1

    Linear (Series1)

    Figure 33: Sensor Readings vs Glucose Values

  • 7/28/2019 Team 10 - Final Report

    47/93

    46

    The MiniMed continuous glucose sensor is a chemical sensor that degrades in sensitivity

    through-out its three day life span. The signal degradation is a byproduct of increasing

    resistance between the 3 sensor terminals. The following graph was taken from

    MiniMeds site and shows how the resistance changes over the sensors life span:

    Figure 34: Sensor Resistance

    To maintain sensor accuracy, MiniMed requires sensor recalibration every 4 hours,

    during which the intercept of the equation used to correlate sensor readings to glucose

    values is reset to match the change in resistance. To account for this resistance change in

    our glucose correlations we used a third term in the equation that corresponds to

    sensitivity decreases over the sensors life. The below plot was made by taking the sensor

    readings and using our equation for correlating sensor values to glucose values and then

    plotting them in green. The blue values are the ones that MiniMed calculated, and the

    blue dots represent the samples actual blood glucose continent. As you can see from the

    below graph our model match the persons actual values much closer then MiniMeds, but

    still follows the same patterns. The correlation between the two sets of data was .964

    which shows the strong relationship between our correlation model and MiniMeds.

  • 7/28/2019 Team 10 - Final Report

    48/93

    47

    Figure 35: Comparison between MiniMed Data and Simulated Results

    The following graph is our model without recalibration over a period of 3 days, while the

    MiniMed data is being recalibrated every 4 hours. As you can see our data begins to get

    off track but still remains within a reasonable percent error.

  • 7/28/2019 Team 10 - Final Report

    49/93

    48

    MiniMed model vs. Our model without using

    calibration periods

    0

    5

    10

    15

    20

    25

    1 71 141 211 281 351 421 491 561 631 701 771

    time

    Glucosevalue

    s

    MiniMed Model

    Our Model

    Figure 36: Comparisons of Both Models

    The correlation between these two sets of data is .8732 which shows definite relation

    between the two data sets. Furthermore, the average percent difference was 28%.

    To find the sensor value relationship we wrote a small program in Python to exact

    sections of increasing blood glucose levels during calibration periods, and then this

    information was entered into Matlab where polyfit was used to fit a 2nd

    order polynomial

    to the data. The following was the averaged polynomial equation that we obtained:

    Glucose = .0732*SensReading^2 -.8862*SensReading + C

    Where C is recalculated every time the user enters a manual blood glucose reading from a

    finger prick style glucometer.

  • 7/28/2019 Team 10 - Final Report

    50/93

    49

    7.2 Algorithm TestingWe have tested both the system algorithm, which is the Minimal Model, and the Neural

    Network Model. The NNM is performed using MatLab

    on computer.

    7.2.1 Testing the Minimal Model

    As we stated earlier, after our evaluation of the CGMS, we decided to change a

    method of acquiring blood glucose values. Instead of CGMS, we use a one-time sensor.

    With the help of the sensor, we conducted a controlled experiment which involves

    drinking a can of Coca Cola and measuring the blood glucose values before and after the

    ingestion. The data we acquired is shown in the below graphs. As we can see, the peak of

    the actual data matches the predicted values. There are some fluctuations in the second

    set data but it is more or less coherent.

    Figure 37: First Day Glucose Data

  • 7/28/2019 Team 10 - Final Report

    51/93

    50

    Figure 38: Second Day Glucose Data

    7.2.2 Testing the Neural Network Model

    Results from the NNM seem to be pretty promising based on the fact that it is necessary

    to have large sets of data in order to train the network. We have used a feed forward back

    propagation network that takes in the value of present glucose levels. The trangdm

    (Gradient descent with momentum back-propagation) learning algorithm is used in

    training our network. As mentioned earlier, we have 32 days of data which we used 25 of

    them to train our network (Performance was 0.074) and the rest of the data to test it.

    Results are shown in the graph below:

  • 7/28/2019 Team 10 - Final Report

    52/93

    51

    Figure 39: Results from NNM

    There is a point to be noted: we used mapstd function to normalize (scale) our data so we

    can feed these data to the neural network. In addition, output data was recovered using

    the reverse mapstd function. Our MatLab script is provided in Appendix B

    We have also done a regression analysis of our target data and predicted data,

    which is given below:

  • 7/28/2019 Team 10 - Final Report

    53/93

    52

    Figure 40: Regression Analysis of the Data

    As we know, a value of R=1 is known to be excellent. Our network performs with a R

    value of approximately 0.99, which is very impressive. However, as we have stated in the

    software design, we did not use this network as it needs larger data sets to be trained

    which we cant have. Moreover, the complexity of the program requires iterations after

    iterations. We are limited by our hardware since our system is incapable of running

    software like MatLab.

  • 7/28/2019 Team 10 - Final Report

    54/93

    53

    The liver can either produce or take up glucose depending on the blood glucose and

    plasma insulin levels. The net hepatic balance is calculated as the sum of gluconeogenesis,

    glycogen breakdown and glycogen synthesis derived from experimental data published in

    the literature. [2] We have used the data available from [3] to calculate the NHB values

    as a function of arterial glucose level and plasma insulin level I. The data set associated

    with this is given in the following table:

    Effectiveplasmainsulin

    (Sh*I/Ibasal)

    GL=3.15mmol/L

    0 291.6 160.0 78.3

    1 194.6 114.6 53.3

    2 129.3 66.0 -1.73 95.7 46.3 -54.3

    4 85.0 22.6 -76.0

    5 76.3 4.3 -8.06 69.0 -10.0 -92.0

    7 62.0 -25.3 -97.3

    8 52.0 -43.3 -101.0

    9 48.0 -47.3 -104.0

    10 41.7 -49.3 -106.7Table: Net hepatic glucose balance (mmol/hr)

    For any value of blood glucose level in between 0.825 and 2.475 was found using

    interpolation function in matlab (see appendix). The same idea was applied while finding

    NHB values for blood glucose levels in between 2.475 and 3.15. Sh is a patient specific

    parameter which a normalized value in between 0 and 1.

    Gren(t) is time dependant parameter which depends on how good is your liver behaving. If

    the blood glucose level crosses a certain threshold, glucose gets excreted into the urine.

  • 7/28/2019 Team 10 - Final Report

    55/93

    54

    Summing up all these equations and parameters we have made a simple GUI simulation

    model for diabetes patients from where one can approximate the behavior of blood

    glucose with time. (See appendix B for matlab code). A picture would look like as

    follows:

    Figure 41: GUI of NNM

  • 7/28/2019 Team 10 - Final Report

    56/93

    55

    8. ASSESMENT AND ANALYSIS

    This is a very challenging project, both in the hardware and software aspects of the

    system. Although we do not need to acquire FDA approval for this system, ethical and

    moral issues need to be considered, since this system is dealing with medical matters.

    8.1 Hardware

    The reason that contributes to the difficulty of the hardware aspect is that the

    CGMS we were working with deals with extremely small electrical values, for example

    nano-Amps. In order to overcome this problem, it is required to build an operational

    amplifier with a huge gain value. However, since the signal to noise ratio is very low, it is

    tremendously complicated to build a filter that can isolate the signal from the noise.

    Even though we have most of our hardware working, the CGMS still remains as a

    problem; more of a mystery perhaps. The fact that MiniMed is unwilling to relinquish

    any information about this product, we could only find a very simple schematic from the

    patent. The circuit, however, is not completely useful. We have done many tests with the

    sensors and we realized without any additional information about the chemistry

    component of the sensor, it is impossible for us to know how to calibrate the sensor. That

    being the case, we have decided to switch to a one-time sensor where a patient pricks

    himself and obtain a blood sample. This is just as good of an input as the CGMS because

    the concept is the same. The system takes in an input, and predicts the peak. It doesnt

    matter if the sensor is continuous or not. The one-time is actually more accurate in

    reading the blood glucose level values than the CGMS. Moreover, the CGMS has to be

    calibrated manually by the patient using the one-time sensor anyway.

  • 7/28/2019 Team 10 - Final Report

    57/93

    56

    8.2 Software

    The prediction algorithm is the main core of this project. It is not a two-month

    project. Instead, medical researchers have been working at similar tasks for a couple of

    decades. Even then, there is no algorithm that can exactly predict the glucose level. That

    being the case, our team took a different approach than the original. Realizing that it is

    nearly impossible to produce our own predicting algorithm, our team studied many

    papers and past algorithms that people have done previously. We learned about how

    human body works and how each parameters of the body affect the glucose level.

    Moreover, by taking our own blood samples, we successfully modified the algorithm so it

    can predict results that are quite convincing. This process can be justified because

    everybody has a different body. In order to reach maximum performance, the system

    needs to learn about how the patients body behaves when he intakes a meal. One

    problem is that no member in our group is diabetic. Therefore we cannot modify the

    algorithm for a diabetic case because we have no way to test it. However, we think that

    our model can work just as well with a diabetic patient.

    8.3 Ethics and Morals

    According to the first two codes of the Codes of Ethics of Engineers, an engineer

    has to hold paramount of safety, health, and welfare of the public while performing

    services only in areas of [his] competence. Since it is unsafe for circuitry to be

    connected to human body, we think it is best if we enter the blood glucose level before

    and after a meal into the system manually. This means that the user of this still have to

    puncture himself and obtain blood samples. As unattractive as the previous sounds,

  • 7/28/2019 Team 10 - Final Report

    58/93

    57

    however, the CGMS also requires a constant recalibration every four hours. The process

    of a patient puncturing himself is inevitable.

    Regarding the second code, we think that prior to the project, we dont have the

    rights to build such device. However, we have studied many published papers regarding

    diabetes, and have met with a few researchers such as Dr. Ezra Kwok and Dr. Chris

    McIntosh of the University of British Columbia, and Dr. Diane Finegood of the Simon

    Fraser University. We have gained a great deal of knowledge about diabetes; at least to

    an extent that is sufficient to develop our system. Therefore, we believe that we are

    competent of develop this system which may be able to help many patients.

    As far as morals are concerned, we think that our project comes from the origin of

    being helpful and beneficial to the diabetic society. We have put a great amount of hard

    work along with experiments which we perform on ourselves to ensure the quality of our

    system. The project is strongly based on good morals.

  • 7/28/2019 Team 10 - Final Report

    59/93

    58

    9. FINANCIAL ASSESSMENT

    Parts Price Ea. Quantity Subtotal

    Minimed Sensors $ 50.00 4 $ 200.00

    Toshiba T6963C Controller LCD $ 40.00 1 $ 40.00

    ATMEGA32 $ 8.27 2 $ 16.54

    Op Amp $ 5.17 4 $ 20.68

    555 Timer $ 1.06 5 $ 5.30

    LMH6622 High Speed Op Amp $ 5.32 2 $ 10.64

    Coin Battery Holder $ 0.93 2 $ 1.86

    9V Battery Holder $ 1.00 2 $ 2.00

    PCB ($1.00 / square inch) $ 1.00 60 $ 60.00

    Coin Battery $ 5.00 1 $ 5.00

    Buttons $ 0.25 3 $ 0.75

    AVR Programmer $ 34.00 1 $ 34.009V Battery $ 7.00 2 $ 14.00

    PCB Discount -$ 50.00 1 -$ 50.00

    TOTAL COST $ 360.77

  • 7/28/2019 Team 10 - Final Report

    60/93

    59

    10. CONCLUSION

    Throughout the past few months, we have learned how to cooperate together in a group

    project. From the beginning of the semester until the end, each of the stages of the project,

    such as deciding on what project to do; coming up with a proposal; deciding what

    hardware to use; designing the system; and putting the system together have been

    valuable lessons for each of us to learn. Also, we have learned about ethical issues that

    are dealt with when it comes to medical field. By meeting with the professional

    researchers, we also learned about the topic we were researching on.

    Moreover, we have concluded that companies that produce parts are reluctant in

    releasing their technology, even for researching purposes, because they are afraid of

    losing customers. We have found this quite depressing but we understand that it is how

    the world works.

    Each member of this team is proud of the system that the team produced. We truly

    believe that the system is beneficial to the diabetic society. If we have more time to

    perfect the system, it would certainly be one of the most helpful systems to diabetic

    patients.

  • 7/28/2019 Team 10 - Final Report

    61/93

    60

    11. REFERENCES

    1. Closed Loop System for Controlling Insulin Fusion. Patent. Medtronic MiniMed.

    California: 2000.

    2. E.D.Lehman and T.Deutsch. A physiological model of glucose-insulin interaction

    in type 1 diabetes mellitus. J.Biomed Eng 1992, Vol.14, May

    3. John R.Guyton, M.D., Richard O. Foster, M.S., J. Stuart Soeldner, M.D., Meng H.

    Tan, M.D., Charles B. Kahn, M.D., L. Koncz, M.D., and Ray E. Gleason, Ph.D.,

    Boston. A Model of Glucose-insulin Homeostasis in Man that Incorporates the

    Heterogeneous Fast Pool Theory of Pancreatic Insulin Release. Diabetes,

    VOL.27 NO. 10, October 1978

    4. F.Chee, T.Fernado and P.V. van Heerden. Simulation study on automatic blood

    glucose control. Seventh Australian and New Zealand Intelligent Information

    Systems Conference, 18-21 November 2001

    5. S.G.Mougiakakou, K.Prountzou, K.S.Nikita. A Real Time Simulation Model of

    Glucose-Insulin Metabolism for Type 1 Diabetes Patients. Engineering in

    Medicine and Biology 27th

    Annual Conference, Shanghai, China, September 1-

    4, 2005

    6. Markus Berger, MD, David Rodbard, MD. Computer Simulation of Plasma Insulin

    and Glucose Dynamics After Subcutaneous Insulin Injection. Diabetes Care,

    VOL.12, NO.10, November/December 1989

    7. Troy Bremer and David A. Gough. Is Blood Glucose Predictable From Previous

    Values. Diabetes, VOL.48, March 1999

    8. Erik Mosekilde, Klaus Skobvbo Jensen, Christian Binder, Stig Pramming, and

    Birger Thorsteinsson. Modeling Absorption Kinetics of Subcutaneous Injected

    Soluble Insulin. Journal of Pharmacokinetics and Biopharmaceutics, Vol.17,

    No.1, 19899. S.Natalucci, F.Di Nardo, P. Staffolani, C. De Marzi, P. Morosini and R. Burattini.

    Glucose Absorption and Insulin Sensitivity from Oral Glucose Tolerance Test.

    25th

    Annual International Conference of the IEEE EMBS, Cancum, Mexico,

    September 17-21, 2003

  • 7/28/2019 Team 10 - Final Report

    62/93

    61

    10. Michael E. Fisher. A Semiclosed-Loop Algorithm for the control of Blood Glucose

    Levels in Diabetics. IEEE Transaction on Biomedical Engineering, Vol.38,

    No.1, January 1991.

    11. Richard N. Bergman, Y. Ziya, Ider, Charles R. Bowden, and Claudio Coebelli.

    Quantitative Estimation of Insulin Sensitivity. 1979 the American Physiology

    Society.

  • 7/28/2019 Team 10 - Final Report

    63/93

    62

    Appendix A

    Pin Layout for ATMEGA32 Microcontroller:

  • 7/28/2019 Team 10 - Final Report

    64/93

    63

    Pin Layout for LT1014 Precision Operational Amplifier

  • 7/28/2019 Team 10 - Final Report

    65/93

    64

    PCB for the System

    PCB for the Connector

  • 7/28/2019 Team 10 - Final Report

    66/93

    65

    Appendix B

    NOTE: Not all codes are shown. Some extensive coding files are placed in the CD.

    Microcontroller Code in C

    For ADC

    /*! \file a2d.c \brief Analog-to-Digital converter function library. *///*****************************************************************************

    //

    // File Name : 'a2d.c'

    // Title : Analog-to-digital converter functions

    // Author : Pascal Stang - Copyright (C) 2002// Created : 2002-04-08

    // Revised : 2002-09-30

    // Version : 1.1

    // Target MCU : Atmel AVR series

    // Editor Tabs : 4//

    // This code is distributed under the GNU Public License// which can be found at http://www.gnu.org/licenses/gpl.txt

    //

    //*****************************************************************************

    #include #include

    #include

    #include "global.h"#include "a2d.h"

    // global variables

    //! Software flag used to indicate when

    /// the a2d conversion is complete.

    volatile unsigned char a2dCompleteFlag;

    // functions

    // initialize a2d convertervoid a2dInit(void)

    {

    sbi(ADCSR, ADEN); // enable ADC (turn on ADC power)cbi(ADCSR, ADFR); // default to single sample convert mode

    a2dSetPrescaler(ADC_PRESCALE); // set default prescalera2dSetReference(ADC_REFERENCE); // set default reference

    cbi(ADMUX, ADLAR); // set to right-adjusted result

    sbi(ADCSR, ADIE); // enable ADC interrupts

    a2dCompleteFlag = FALSE; // clear conversion complete flagsei(); // turn on interrupts (if not already

    on)

  • 7/28/2019 Team 10 - Final Report

    67/93

    66

    }

    // turn off a2d converter

    void a2dOff(void)

    {cbi(ADCSR, ADIE); // disable ADC interrupts

    cbi(ADCSR, ADEN); // disable ADC (turn off ADC power)

    }

    // configure A2D converter clock division (prescaling)

    void a2dSetPrescaler(unsigned char prescale){

    outb(ADCSR, ((inb(ADCSR) & ~ADC_PRESCALE_MASK) | prescale));

    }

    // configure A2D converter voltage referencevoid a2dSetReference(unsigned char ref)

    {

    outb(ADMUX, ((inb(ADMUX) & ~ADC_REFERENCE_MASK) | (ref

  • 7/28/2019 Team 10 - Final Report

    68/93

    67

    return (inb(ADCL) | (inb(ADCH)2; // return ADC MSB byte

    }

    //! Interrupt handler for ADC complete interrupt.

    SIGNAL(SIG_ADC)

    {

    // set the a2d conversion flag to indicate "complete"

    a2dCompleteFlag = TRUE;}

  • 7/28/2019 Team 10 - Final Report

    69/93

    68

    For LCD

    #include

    #include #include

    #include

    #include "T6963.h"

    void CheckBusy(void)

    {

    unsigned char data;

    WRITE_DATA(0xFF); //set all pull ups

    DATAIN; //set direction as inputdo {

    CD_CMD;

    RD_OFF;CE_OFF;

    asm ("nop");asm ("nop");

    asm ("nop");

    data=READ_DATA;

    CE_ON;RD_ON;

    } while((data & 0x03) != 0x03);

    DATAOUT;

    CE_OFF;

    }

    void WriteData(int byte)

    {CheckBusy();DATAOUT;

    WRITE_DATA(byte); // write value to data port

    CD_DATA;WR_OFF;

    CE_OFF;

    asm ("nop");

    asm ("nop");asm("nop");

    CE_ON; // return enable HIGH

    WR_ON;

    CD_CMD; // restore Write mode to inactiveCE_OFF;

    //added the CE's after}

    void WriteCommand(int byte){

  • 7/28/2019 Team 10 - Final Report

    70/93

    69

    CheckBusy();

    DATAOUT;

    WRITE_DATA(byte); // present data to LCD on PC's port pins

    CD_CMD; // control/status mode

    WR_OFF; // activate LCD write modeRD_ON;

    CE_OFF; // pulse ChipEnable LOW, > 80 ns, enables LCD I/O

    asm ("nop");asm ("nop");

    asm("nop");

    CE_ON; // disable LCD I/OWR_ON; // deactivate write mode

    CE_OFF;

    }

    unsigned char ReadData(void)

    {

    //get data byte from LCD moduleunsigned char lcd_byte;

    CheckBusy();

    CD_DATA; //data modeDATAIN;

    WR_ON; //make PC's port an input port

    RD_OFF; //activate READ mode

    CE_OFF; //enable chip, which outputs data

    asm ("nop");asm ("nop");

    lcd_byte= READ_DATA; //read data from LCD

    CE_ON; //disable chipRD_ON;

    CD_CMD;

    DATAOUT; //make 8-bit parallel port an output portCE_OFF;

    return lcd_byte;

    }

    void lcd_init(void) //initialize memory etc

    {

    INIT_CONTROL_PINS;

    DATAOUT;

    WR_ON;

    CD_CMD;

    RD_ON;CE_OFF;

    RESET_OFF;

    _delay_ms(1);

    RESET_ON;

  • 7/28/2019 Team 10 - Final Report

    71/93

    70

    WriteCommand(0x80); // mode set: Graphics OR Text, Internal CG ROM

    // for characters from 00-7F all the rest are user

    defined

    WriteData(G_BASE&0xFF);

    WriteData((G_BASE>>8)&0xFF);

    WriteCommand(0x42); // set graphics memory to address G_BASE

    WriteData(BYTES_PER_ROW & 0xFF); //currently set to 16 per row...

    WriteData(0x00);WriteCommand(0x43); // n bytes per graphics line

    WriteData(T_BASE&0xFF);

    WriteData((T_BASE>>8)&0xFF);

    WriteCommand(0x40); // text memory at address T_BASE

    WriteData(BYTES_PER_ROW & 0xFF);

    WriteData(0x00);WriteCommand(0x41); // n bytes per text line

    WriteCommand(0xA3); //cursor pattern select

    WriteCommand(0x00);

    WriteCommand(0x00);

    WriteCommand(0x21); //cursor position set

    WriteData(0x00);WriteData(0x00);

    WriteCommand(0x24); //put graphics pointer at (x,y) location

    WriteCommand(0x9F); // graph on, text on, cursor off. cursor on is 0x9F

    lcd_clear_graph();lcd_clear_text();

    //NOTES: TRY 9F for cursor and both graphics and text

    }

    void lcd_set_address(unsigned int addr) //Sets the address pointer

    {WriteData(addr & 0xFF);

    WriteData((addr >> 8)&0xFF);

    WriteCommand(0x24);

    }

    void lcd_xy(int x, int y) // set memory pointer to (x,y) position (text)

    {

    unsigned int addr;

    addr = T_BASE + (y * BYTES_PER_ROW) + x;

    lcd_set_address(addr); // set LCD addr. pointer

    }

  • 7/28/2019 Team 10 - Final Report

    72/93

    71

    void lcd_clear_graph(void) // clear graphics memory of LCD

    {

    unsigned int i;

    lcd_set_address(G_BASE); // addrptr at address G_BASE

    for (i=0;i> 3);lcd_set_address(addr); // set LCD addr. pointer

    WriteCommand(0xF8 | (7-(column & 0x07) )); // F8 is cmd for set pixel then set bit inside

    }

    void lcd_clrpixel(int column, int row)

    {unsigned int addr;

    if( (column>=XMAX) || (row>=YMAX) )return; //outside screen limits

  • 7/28/2019 Team 10 - Final Report

    73/93

    72

    addr = G_BASE + (row*BYTES_PER_ROW) + (column >> 3);

    lcd_set_address(addr); // set LCD addr. pointer

    WriteCommand(0xF0 | (7-(column & 0x07) )); // F0 is cmd for clr pixel then set bit inside..

    }

    void lcd_print_ram(int x,int y,char *string) // send string of characters to LCD

    {unsigned char i;

    unsigned char c;

    lcd_xy(x,y);

    for (i=0;string[i]!=0;i++)

    {c = string[i]; // convert ASCII to LCD char address

    if(c==0) break;

    c-=0x020;WriteData(c);

    WriteCommand(0xC0); // write character, increment memory ptr.}

    }

    void lcd_print_flash(int x,int y, const char *string) // send string of characters to LCD

    {

    int i;int c;

    lcd_xy(x,y);

    for (i=0; pgm_read_byte(&string[i])!=0;i++){

    c = pgm_read_byte(&string[i]) - 0x20; // convert ASCII to LCD char address

    if (c> 8);WriteCommand(0x24); //addrptr at address G_BASE

    for(i=0; i < 1024; i++){ //128x64=16 bytes * 64=1024

    WriteData(0xff);WriteCommand(0xc0); // write data, inc ptr.

    }

    }

  • 7/28/2019 Team 10 - Final Report

    74/93

    73

    void lcd_print_float(int x, int y, float value)

    {

    char value1, value2;

    char buffer[17];

    if (value < 10 && value >= 0)

    {value1 = (int)(value*1)%10;

    value2 = (int)(value*10)%10;

    sprintf(buffer, "%d.%d", value1, value2);}

    else if(value >=10 && value < 100)

    {

    value1 = (int)(value*1)%100;

    value2 = (int)(value*10)%100;

    sprintf(buffer, "%d.%d", value1, value2);}

    else if(value >=100 && value

  • 7/28/2019 Team 10 - Final Report

    75/93

    74

    lcd_setpixel(i, 10);

    }

    for(i=0;i

  • 7/28/2019 Team 10 - Final Report

    76/93

    75

    For Glucose Management

    #include

    #include

    #include #include

    #include

    #include "T6963.h"#include "a2d.h"

    #include "glucose.h"

    unsigned short adc_data; //to store 10 bit a2d binary value

    int main(void)

    {

    int count = 0; //used for checking every two minutes

    //variables

    float float_value; //Sensor value converted from ADCfloat sensVal;

    float glucVal;float intercept = 0; //intial value

    float lastSensVal = 0;

    float buttonPress;

    char buffer[10];

    unsigned int divisionCounter = 0; //to average sensValint counter;

    int mode = 0;

    int flag = SKIP;

    float ADBuffer[FIRORDER]; //buffer to hold incoming data

    //initialize devices

    init();

    lcd_init();a2dInit();

    //setup A2D values. Prescale 32 (can be 64 for more accuracy) and AVCC ref

    a2dSetPrescaler(ADC_PRESCALE_DIV64);a2dSetReference(ADC_REFERENCE_AVCC);

    plot_graph_axes(); //for glucose values/ predictions etc

    draw_boxes();

    //sample A2D values with 10 bit

    counter = 8; //counts time... 8 is the starting position of the graph

    //on the screen (pixel 8)

    //FILL UP BUFFER FIRST

    int i;

  • 7/28/2019 Team 10 - Final Report

    77/93

    76

    for(i = 0; i< (FIRORDER - 1); i++)

    {

    ADBuffer[i] = ((float)a2dConvert10bit(0))*.0048828;

    }

    //buffer full

    while(1)

    {

    buttonPress = 0;

    adc_data = a2dConvert10bit(0);float_value = ((float)adc_data)*.0048828; //.0048828; 5V/1024

    shift_buffer(&ADBuffer[0], float_value); //shifts buffer

    lcd_print_float(0,0, float_value);

    sensVal += FilterVal(&ADBuffer[0]); //add up all sensor values for two

    minutesdivisionCounter += 1;

    if ((TIFR& 0x10) == 0x10)

    {TIFR|=0x10; //reset the flag to zero

    count += 1; //add the count. 1 count = 5 secondssprintf(buffer, "%d", (count*5));

    lcd_print_ram(12, 0, buffer);

    //averages sensor values every x time period//and displays pixel and new information on display

    if(count == TIME30SEC) //30 seconds

    {lcd_clear_text();

    sensVal = (sensVal/divisionCounter);

    lastSensVal = sensVal;//linerglucVal = (SLOPE*sensVal*SENSFACTOR) + intercept;

    //polynomial

    //glucVal = a*sensVal*sensVal + b*sensVal + c;

    if(flag == ENTER){

    lcd_graph(counter, glucVal);

    lcd_print_float(12,2,sensVal); //print sens val in cornerlcd_print_float(5,0, glucVal);

    }

    else

    {

    flag = ENTER;}

    sensVal = 0;

    count = 0;divisionCounter = 0;

    //shifts graph if nearing edge

    if (counter == 120)

    {

  • 7/28/2019 Team 10 - Final Report

    78/93

    77

    shift_graph();

    counter = 112;

    }

    counter++;

    }}

    if((PINB& MENU) != MENU)

    {lcd_print_ram(3,3, "GLUCOSE");

    delay(5);

    while((PINB& MENU) == MENU)

    {

    if((PINB& PINUP) != PINUP){

    if(mode == 3)

    {mode = 1;

    }else

    {mode += 1;

    }

    lcd_clear_text();

    if(mode == 1){

    lcd_print_ram(3,3, "GLUCOSE");

    }else if(mode == 2)

    {

    lcd_print_ram(3,3, "INSULIN");}else if(mode == 3)

    {

    lcd_print_ram(3,3, "CARBS");

    }delay(5);

    }

    }

    delay(5);

    lcd_clear_text();

    if(mode == 1) //Calibrate sensor mode

    {

    buttonPress = getValue("ENTER GLUCOSE: ");

    intercept = setIntercept(buttonPress, lastSensVal);count = 0;

    sensVal = 0;flag = SKIP;

    lcd_clear_text();

    delay(5); //delay for debouncing

  • 7/28/2019 Team 10 - Final Report

    79/93

    78

    }

    if(mode == 2) //Enter carbs mode

    {

    buttonPress = getValue("ENTER CARBS: ");delay(5);

    }

    if(mode == 3) //enter insulin dosage mode

    {

    buttonPress = getValue("ENTER INSULIN: ");

    delay(5);

    }

    }

    //toggle backlight if first two buttons pressed simultanousely

    if((PINB& BACK) != BACK){

    BACKLIGHT_TOGGLE;delay(10);

    }

    }return 0;

    }

  • 7/28/2019 Team 10 - Final Report

    80/93

    79

    MatLab Script for the NNM

    Neural Network Code:

    Data Sets:

    Data Samples were taken every five (t) minutes.Glucose data (mmol/h):

    Glucose:

    [ 5. 2; 5. 3; 5. 4; 5. 7; 5. 7; 5. 8; 6; 6. 5; 7. 3; 8. 1; 8. 7; 9. 1; 9. 8; 10. 7; 10. 9; 11. 2; 11. 4;. . . 11. 5; 11. 2; 10. 9; 10. 5; 10. 4; 10. 2; 10; 9. 7; 9. 3; 8. 9; 8. 5; 8. 2; 7. 7; 7; 6. 4; 6; 5. 7; . . .

    5. 3; 5. 2; 5. 1; 5; 4. 7; 4. 3; 4. 1; 3. 9; 3. 9; 3. 9; 3. 9; 3. 8; 3. 9; 3. 9; 4; 4. 2; 4. 4; 4. 7; . . .

    4. 9; 5; 5; 4. 9; 4. 9; 5; 5; 5. 1; 5. 2; 5. 2; 5. 2; 5. 2; 5; 4. 9; 4. 9; 4. 9; 5; 5. 1; 5. 2; 5. 1; . . .

    5. 1; 5. 1; 5. 1; 5; 4. 9; 4. 9; 5; 5. 1; 5. 1; 5. 1; 5. 1; 5. 2; 5. 1; 5; 4. 9; 5; 11. 4; 11. 7; . . .

    11. 8; 11. 7; 11. 7; 11. 7; 12. 3; 13. 1; 13. 3; 12. 7; 14. 2; 14. 3; 14. 1; 13. 8; 13. 3; 13; . . .

    12. 8; 12. 5; 12. 7; 12. 9; 13; 13. 1; 13. 1; 13. 1; 13; 12. 8; 12. 5; 12. 4; 11. 1; 7; 6. 8; . . .

    6. 5; 6. 4; 6. 5; 6. 4; 6. 4; 6. 4; 6. 4; 6. 3; 6; 5. 7; 5. 3; 5. 1; 5; 4. 9; 4. 9; 5. 1; 5. 2; 5. 6; . . .

    5. 9; 6. 3; 6. 8; 7. 3; 7. 8; 8. 1; 8. 3; 8. 7; 9. 1; 9. 7; 10. 3; 10. 9; 11. 3; 11. 9; 12. 3; 13; . . .

    13. 4; 13. 8; 13. 7; 13. 4; 13. 2; 12. 9; 12. 4; 11. 9; 11. 2; 10. 5; 10; 9. 4; 9; 8. 7; 8. 4; . . .

    8. 2; 7. 8; 7. 8; 7. 7; 7. 5; 7. 5; 7. 4; 7. 5; 7. 4; 7. 4; 7. 3; 7. 2; 7; 6. 8; 6. 5; 6. 5; 6. 5; . . .

    6. 7; 6. 9; 7; 7. 2; 7. 4; 7. 5; 7. 7; 7. 9; 8. 1; 8. 1; 8; 8; 7. 8; 7. 5; 7. 4; 7. 3; 7. 3; 7. 1; . . . 6. 8; 6. 5; 6. 3; 6; 5. 9; 5. 8; 5. 8; 5. 9; 6. 1; 6. 3; 6. 5; 6. 7; 6. 9; 7. 1; 7. 2; 7. 2; 7; . . .

    6. 9; 6. 9; 6. 8; 6. 8; 6. 7; 6. 5; 6. 4; 6. 3; 6. 3; 6. 2; 6. 3; 6. 8; 7. 1; 7; 6. 7; 6. 2; 5. 9; . . .

    5. 8; 5. 6; 5. 6; 5. 6; 5. 6; 5. 6; 5. 4; 5. 2; 5. 2; 5. 2; 5. 1; 4. 9; 4. 7; 4. 6; 4. 3; 4. 2; 4. 3; . . .

    4. 3; 4. 3; 4. 3; 4. 3; 4. 3; 4. 3; 4. 4; 4. 4; 4. 4; 4. 4; 4. 3; 4. 3; 4. 3; 4. 3; 4. 4; 4. 4; 4. 4; . . .

    4. 4; 4. 4; 4. 3; 4. 2; 4. 2; 4. 2; 4. 3; 4. 4; 4. 6; 4. 6; 4. 6; 4. 4; 4. 4; 4. 4; 4. 6; 4. 7; 4. 7; . . .

    4. 6; 4. 6; 4. 7; 4. 7; 4. 7; 4. 7; 5. 1; 5. 8; 5. 7; 5. 3; 5; 4. 9; 4. 8; 4. 9; 5; 5. 1; 5. 2; 5. 3; . . .

    5. 4; 5. 4; 5. 7; 5. 8; 6; 6. 2; 6. 4; 6. 7; 6. 8; 6. 8; 6. 8; 6. 8; 6. 7; 6. 7; 6. 7; 6. 7; 6. 5; . . .

    6. 3; 6. 2; 6. 2; 6. 3; 6. 3; 6. 3; 6. 2; 6. 1; 6; 5. 9; 5. 8; 5. 7; 5. 6; 5. 4; 5. 3; 5. 1; 5; 4. 9; . . .

    4. 7; 4. 6; 4. 4; 4. 4; 4. 8; 5. 1; 5. 4; 5. 8; 6. 2; 6. 4; 6. 7; 7; 7. 1; 6. 8; 6. 7; 6. 5; 6. 2; . . .

    6. 2; 6. 2; 6. 2; 5. 3; 5. 2; 5. 2; 5. 4; 5. 6; 5. 7; 5. 9; 6. 1; 6. 2; 6. 1; 5. 8; 5. 4; 5. 2; 5; . . .

    4. 8; 4. 4; 4. 1; 3. 7; 3. 6; 3. 4; 3. 8; 4. 2; 4. 7; 5. 1; 5. 4; 5. 8; 6. 1; 6. 1; 6. 1; 6. 1; 6. 1; . . .

  • 7/28/2019 Team 10 - Final Report

    81/93

    80

    6. 1; 6; 5. 7; 5. 6; 5. 4; 5. 2; 5. 2; 5. 3; 5. 4; 5. 6; 5. 6; 5. 4; 5. 4; 5. 4; 5. 6; 5. 9; 6. 1; 6. 1; .. .

    6. 3; 6. 5; 6. 8; 7; 7. 3; 7. 5; 7. 5; 7. 5; 7. 7; 7. 5; 7. 5; 7. 3; 7. 1; 6. 9; 6. 7; 6. 4; 6. 2; 5. 9; .. .

    5. 8; 5. 8; 5. 9; 5. 6; 5. 1; 4. 9; 4. 7; 4. 4; 4. 3; 4. 4; 4. 3; 4. 2; 4. 1; 4. 1; 4. 1; 4; 4. 2; 4. 3; .. .

    4. 7; 5; 5. 2; 5. 3; 5. 6; 5. 6; 5. 7; 5. 7; 5. 7; 5. 6; 5. 6; 5. 4; 5. 4; 5. 3; 5. 3; 5. 6; 5. 8; 5. 9; .. .

    5. 9; 6. 1; 6. 3; 6. 5; 6. 8; 7. 1; 7. 3; 7. 4; 7. 7; 7. 8; 7. 9; 8. 1; 8. 3; 8. 5; 8. 4; 8. 1; 8; 8. 2; .. .

    8. 5; 9; 9. 2; 9. 1; 9; 9. 1; 9. 2; 9. 3; 9. 5; 9. 7; 9. 8; 9. 9; 9. 9; 10; 10; 9. 9; 9. 9; 10. 1; 10. 2; . . .

    10. 2; 10. 1; 10; 9. 8; 9. 5; 9. 4; 9. 4; 9. 2; 9. 1; 9; 9; 9; 8. 8; 8. 5; 8. 3; 8. 1; 7. 8; 9. 2; 9. 3;

    . . . 9. 4; 9. 3; 9. 2; 9. 1; 8. 9; 8. 5; 8. 3; 8. 1; 8; 7. 9; 7. 8; 7. 5; 7. 4; 7. 3; 7. 2; 7. 1; 7; 7. 1; 7. 1; . . .

    7. 1; 7; 6. 9; 6. 8; 6. 7; 6. 7; 6. 5; 6. 7; 6. 7; 6. 7; 6. 5; 6. 3; 6. 2; 6. 1; 6. 1; 5. 9; 5. 7; 5. 7; .. .

    5. 7; 5. 6; 5. 6; 5. 6; 5. 6; 5. 6; 5. 6; 5. 6; 5. 6; 5. 6; 5. 6; 5. 4; 5. 4; 5. 6; 5. 7; 5. 8; 5. 8; 5. 4; . . .

    5. 1; 4. 9; 4. 7; 4. 6; 4. 4; 4. 6; 4. 8; 5; 5. 2; 5. 4; 5. 7; 5. 9; 6. 1; 6. 4; 6. 8; 6. 8; 7; 7. 2; 7. 3; . . .

    7. 3; 7. 1; 6. 9; 6. 8; 6. 7; 6. 5; 6. 7; 6. 8; 6. 9; 6. 9; 6. 9; 6. 8; 6. 5; 6. 5; 6. 5; 6. 5; 6. 5; 6. 5; . . .

    6. 4; 6. 5; 6. 8; 7; 7. 2; 7. 5; 7. 9; 8. 1; 8. 2; 8. 2; 8. 1; 8; 7. 8; 7. 5; 7. 5; 7. 9; 8. 1; 8. 2; 8. 1; . . .

    8; 8; 8; 8; 8; 7. 5; 7. 4; 7. 5; 7. 5; 7. 5; 7. 4; 7. 2; 6. 8; 6. 4; 6. 1; 6; 5. 9; 5. 1; 5; 5; 5. 1; 5. 2; . . .

    5. 3; 5. 6; 5. 8; 5. 8; 5. 8; 5. 8; 5. 8; 5. 9; 5. 9; 6. 1; 6. 2; 6. 3; 6. 4; 6. 5; 6. 7; 6. 8; 6. 8; 6. 7; . . .

    6. 5; 6. 7; 6. 8; 7; 7. 1; 7. 2; 7. 2; 7. 4; 7. 7; 7. 9; 7. 5; 7. 2; 7. 1; 7. 2; 7. 5; 8. 1; 8. 2; 8. 1; .

    . .

    8. 1; 7. 8; 7. 8; 8. 3; 9; 9. 1; 8. 9; 8. 9; 9; 9. 1; 9. 2; 9. 2; 9. 2; 9; 8. 9; 8. 7; 8. 5; 8. 4; 8. 1; .. .

    7. 8; 7. 8; 7. 8; 7. 5; 7. 4; 7. 3; 7. 3; 7. 4; 7. 5; 8. 1; 8. 8; 9; 9. 1; 9. 1; 9. 1; 9. 1; 9. 1; 9; 8. 9; . . .

    8. 7; 8. 7; 8. 7; 8. 7; 8. 7; 8. 8; 8. 9; 9; 9; 8. 9; 8. 7; 8. 5; 8. 5] ;

  • 7/28/2019 Team 10 - Final Report

    82/93

    81

    Test Data:

    [ 8. 5; 8. 5; 8. 3; 7. 9; 7. 9; 8. 1; 8. 2; 8. 2; 8. 1; 8; 7. 9; 7. 8; 7. 7; 7. 5; 7. 5; 7. 4; 7. 3; 7. 1;. . .

    7. 1; 7; 6. 9; 6. 5; 6. 4; 6. 4; 6. 4; 6. 4; 6. 5; 6. 5; 6. 5; 6. 5; 6. 4; 6. 2; 6. 1; 6; 6; 5. 9; 6; . . .

    5. 8; 5. 6; 6. 4; 6. 3; 6. 2; 6. 2; 6. 3; 6. 3; 6. 2; 6. 1; 5. 9; 5. 8; 5. 8; 5. 8; 5. 9; 5. 9; 5. 8; . . .

    6; 6. 2; 6. 2; 6. 8; 7. 3; 7. 4; 7. 8; 7. 9; 7. 9; 7. 8; 7. 5; 7. 8; 8; 8; 7. 9; 7. 5; 7. 2; 7. 1; . . .

    7. 2; 7. 2; 6. 9; 6. 5; 6. 2; 6; 5. 8; 5. 6; 5. 4; 5. 2; 5; 5; 5; 4. 9; 4. 8; 4. 4; 4. 3; 4. 3; 4. 3; . . .

    4. 4; 4. 6; 4. 6; 4. 3; 4. 3; 4. 3; 4. 3; 4. 3; 4. 2; 4. 1; 4. 1; 4. 3; 4. 6; 4. 6; 4. 7; 4. 7; 4. 9; . . .

    5. 1; 5. 8; 6. 4; 6. 5; 6. 4; 5. 9; 5. 6; 5. 6; 5. 7; 5. 6; 5. 3; 5. 3; 5. 4; 5. 7; 5. 7; 5. 3; 4. 9; . . .

    4. 7; 4. 4; 4. 2; 4; 3. 8; 3