25
EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: Wi-Baby Team Members: Name: Zachary Kaufman Name: Aramis Alvarez Project Abstract: Our project consists of building an advanced baby-monitoring system. The system will comprise connected parts: diapers, a leg strap, and a control box. The diapers will be directly connected to the leg strap, and the leg strap will communicate wirelessly with the control box. Each diaper will contain a water sensor to detect if it needs to be changed. The leg strap will measure the baby’s pulse, temperature, and orientation to prevent crib death. The control box will contain a microphone to detect if the baby is crying. It will also contain the microcontroller and other hardware for displaying data and wirelessly transmitting the data to a server. The data can be viewed from an internet-connected device.

EEL 4924 Electrical Engineering Design (Senior Design ... · EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: ... Microphone/Noise

Embed Size (px)

Citation preview

Page 1: EEL 4924 Electrical Engineering Design (Senior Design ... · EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: ... Microphone/Noise

EEL 4924 Electrical Engineering Design

(Senior Design)

Final Design Report

23 April 2013

Project Name: Wi-Baby

Team Members:

Name: Zachary Kaufman Name: Aramis Alvarez

Project Abstract:

Our project consists of building an advanced baby-monitoring system. The system will comprise

connected parts: diapers, a leg strap, and a control box. The diapers will be directly connected to the leg

strap, and the leg strap will communicate wirelessly with the control box. Each diaper will contain a

water sensor to detect if it needs to be changed. The leg strap will measure the baby’s pulse,

temperature, and orientation to prevent crib death. The control box will contain a microphone to detect if

the baby is crying. It will also contain the microcontroller and other hardware for displaying data and

wirelessly transmitting the data to a server. The data can be viewed from an internet-connected device.

Page 2: EEL 4924 Electrical Engineering Design (Senior Design ... · EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: ... Microphone/Noise

University of Florida EEL 4924—Spring 2011 15-Apr-13

Electrical & Computer Engineering Page 2/25

Final Design Report: Wi-Baby

Contents Project Features ........................................................................................................................................... 3

Concepts and Technology ........................................................................................................................... 4 Water Sensor ........................................................................................................................................... 4 Diaper–Leg Strap Interconnect ............................................................................................................... 5 Pulse Sensor ............................................................................................................................................ 5 Temperature Sensor ................................................................................................................................ 5

Accelerometer ......................................................................................................................................... 5 Microphone/Noise Detection .................................................................................................................. 5 XBee ....................................................................................................................................................... 6 Wi-Fi Module.......................................................................................................................................... 6

LCD......................................................................................................................................................... 6 Microcontrollers ...................................................................................................................................... 6

Software ...................................................................................................................................................... 7 Cost Objectives ........................................................................................................................................... 8

Division of Labor ........................................................................................................................................ 9 Timeline ...................................................................................................................................................... 9 Product Images.......................................................................................................................................... 10

Schematics ................................................................................................................................................ 12 Printed Circuit Boards............................................................................................................................... 14

Software .................................................................................................................................................... 16

List of Figures and Tables

Figure 1. Wi-Baby Block Diagram ............................................................................................................. 4 Figure 2. Water Sensor ............................................................................................................................... 4

Figure 3. Diaper-Leg Strap Interconnect .................................................................................................... 5 Figure 4. Pulse Sensor................................................................................................................................. 5 Figure 5. Software Flowcharts .................................................................................................................... 7

Figure 6. Gantt Chart .................................................................................................................................. 9 Figure 7. Components of the Wi-Baby product. ....................................................................................... 10

Figure 8. Assembled Wi-Baby product. ................................................................................................... 10 Figure 9. Web interface for Wi-Baby. ...................................................................................................... 11 Figure 10. Log of Wi-Baby data on website. ............................................................................................ 11 Figure 11. Schematic for leg strap. ........................................................................................................... 12 Figure 12. Schematic for control box. ...................................................................................................... 13

Figure 13. PCB for leg strap. .................................................................................................................... 14 Figure 14. PCB for control box................................................................................................................. 15

Table 1. Partial List of Part Prices .............................................................................................................. 8 Table 2. Approximate Division of Labor .................................................................................................... 9

Page 3: EEL 4924 Electrical Engineering Design (Senior Design ... · EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: ... Microphone/Noise

University of Florida EEL 4924—Spring 2011 15-Apr-13

Electrical & Computer Engineering Page 3/25

Final Design Report: Wi-Baby

Project Features

The main objective of this project is to provide parents with peace of mind by continuously monitoring a

baby throughout the night. The system will monitor the baby for the following:

Heart rate

Temperature

Orientation

Wet Diaper

Noise (crying)

The monitored data will be available for viewing on an LCD on the control box. Additionally, all the

data will be transmitted to a remote server, so that it can be viewed on an internet connected device.

Page 4: EEL 4924 Electrical Engineering Design (Senior Design ... · EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: ... Microphone/Noise

University of Florida EEL 4924—Spring 2011 15-Apr-13

Electrical & Computer Engineering Page 4/25

Final Design Report: Wi-Baby

Concepts and Technology

The Wi-Baby system contains a number of interconnected sensors, processors, transmitters, and

receivers. A block diagram of the Wi-Baby system is shown in Figure 1.

Figure 1. Wi-Baby Block Diagram

Water Sensor The water sensor will be a simple PCB with traces in close

proximity that can be shorted by water, as shown in Figure 2. This,

in combination with a pull-up or pull-down resistor will implement

a very simple digital water sensor. This approach is favorable over

other approaches because of its low cost and simplicity. Since

diapers are disposable, any sensor incorporated into the diaper must

be very inexpensive. Another option would have been a sensor that

can measure relative humidity, but this would be much more

expensive. If mass produced, the simple PCB sensors could likely

be produced for less than a dollar each, providing a disposable

solution.

Figure 2. Water Sensor

Page 5: EEL 4924 Electrical Engineering Design (Senior Design ... · EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: ... Microphone/Noise

University of Florida EEL 4924—Spring 2011 15-Apr-13

Electrical & Computer Engineering Page 5/25

Final Design Report: Wi-Baby

Diaper–Leg Strap Interconnect The diapers will be connected to the leg strap with an auxiliary

cable like the one shown in Figure 3. This will provide a simple,

cost effective solution. The three wires inside the auxiliary cable

will be used as power, ground, and signal. Another option would

have been to make the connection wireless, but this would be

prohibitively expensive for the disposable diapers. Additionally,

this wire will be only a few inches long – from the bottom of the

diaper to the top of the leg. This will avoid any health hazard.

Pulse Sensor The pulse sensor to be used is shown in Figure 4. This sensor

consists of an LED and photodiode to detect heart rate when

against the skin. This sensor outputs an analog waveform of the

heart rate. A comparator input on the microcontroller will detect

how far apart the peaks of the waveform are to measure the

frequency. This sensor will have to be placed on the skin in a

location where pulse can be measured. This will likely require it to

be attached to the baby’s toe. However, since the distance from the

leg strap to the toe will be very short for a baby, this shouldn’t be

a problem.

Temperature Sensor The temperature sensor to be used is the DS600U. This integrated circuit measures temperature and

outputs an analog voltage proportional to the temperature. It will be interfaced with an A/D pin on the

microcontroller. Then, a simple formula can convert the voltage reading to a temperature value. This

sensor will need to be in contact with the baby’s skin to get an accurate reading. The measured

temperature on the surface of the baby’s skin will obviously not be equal to the internal temperature.

This sensor will just provide a metric to see if the baby is hot or cold so that parents can adjust the

temperature if needed.

Accelerometer The MMA7361 Triple Axis Accelerometer will be used to measure the baby’s orientation as either up or

down. In reality, only a single axis accelerometer is needed, but the triple axis version is less expensive.

This sensor will output an analog voltage proportional to the direction the baby is facing. An A/D pin on

the microcontroller will be able to measure the voltage and determine the baby’s orientation.

Microphone/Noise Detection The control box will contain a microphone and a noise detection circuit that will output a high analog

voltage if the noise is louder than a certain threshold. This can be used to determine if the baby is crying.

The processor will sample the value over a time period to distinguish actual crying from random noise.

Figure 3. Diaper-Leg Strap Interconnect

Figure 4. Pulse Sensor

Page 6: EEL 4924 Electrical Engineering Design (Senior Design ... · EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: ... Microphone/Noise

University of Florida EEL 4924—Spring 2011 15-Apr-13

Electrical & Computer Engineering Page 6/25

Final Design Report: Wi-Baby

XBee Two XBee 1mW – Series 1 modules will be used for communication between the leg strap and control

box. XBee was chosen for its simplicity. The processor in the leg strap will send its sensor data to the

control box via XBee. Then the control box will combine this data with the noise data. Making the

connection between the leg strap and control box wireless is to alleviate safety concerns. This will

prevent any long wires running to the baby. It will also provide the baby electrical isolation from the

control box, which is powered by an AC adapter.

Wi-Fi Module The RN-XV WiFly Module was chosen to transmit the data from the control box to a remove server on

the internet. This module provides a simple UART interface for transmitting data over Wi-Fi. Wi-Fi was

chosen because it is more reliable than using a cellphone network and it is available in most households.

LCD A Basic 20x4 Character LCD will be used to display the data on the control box. Since the data is also

viewable on the internet, there is no need for an intricate LCD display. A simple 4-line display should be

able to display all of the data on the control box. This will simply be used for debugging purposes, and

to provide a method for checking on the baby while in the same room.

Microcontrollers The microcontrollers in both the leg strap and control box will be of the MSP430 variety. Since neither

processor needs to be exceedingly powerful, the MSP430 is a good balance between performance and

low cost. Different varieties of the MSP430 will be used based on the features required in the leg strap

and in the control box. For instance, two UARTs will be required in the control box, one for the XBee

and one for the Wi-Fi module.

Page 7: EEL 4924 Electrical Engineering Design (Senior Design ... · EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: ... Microphone/Noise

University of Florida EEL 4924—Spring 2011 15-Apr-13

Electrical & Computer Engineering Page 7/25

Final Design Report: Wi-Baby

Software

The code running on each processor is outlined in the flowcharts of Figure 5. The leg strap continuously

calculates the pulse and stores it in memory. The Interrupt Service Routine (ISR) runs every 5 seconds

and sends the current readings from the sensors and the calculated pulse to the control box.

The control box waits until data is received from the leg strap, then it reads the noise detection data and

appends it to the data from the leg strap. All of this data is then updated on the LCD. Every three times

the LCD updates, the data will also be sent via Wi-Fi to the server (every 15 seconds).

Figure 5. Software Flowcharts

Page 8: EEL 4924 Electrical Engineering Design (Senior Design ... · EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: ... Microphone/Noise

University of Florida EEL 4924—Spring 2011 15-Apr-13

Electrical & Computer Engineering Page 8/25

Final Design Report: Wi-Baby

Cost Objectives

The final price of the Wi-Baby system, not including the price of the internet-connected device for

viewing data, is $317.37. A list of the part prices is shown in

Table 1. Most advanced baby monitors on the market range in price from $200-$400.

Table 1. Partial List of Part Prices

Part Cost/Unit Number Total Cost

MSP430F1611

MSP430F2274

$17.32

$6.30

1

1

$17.32

$6.30

Wi-Fi Module RN-XV-DS v0.3 $34.95 1 $34.95

XBee v1.xEx – 802.15.4 $23.28 2 $46.57

Water Sensor SEN11304P $3.53 1 $3.53

Pulse Sensor SEN11574 $24.95 1 $24.95

Temperature Sensor DS600 $4.90 1 $4.90

Accelerometer MMA7361L

Comparator LM311N

Advanced Circuits Leg Strap PCB

Advanced Circuits Control Box PCB

Resistors and Capacitors

$11.95

$0.91

$33.00

$33.00

$40.00

1

1

1

1

1

$11.95

$0.91

$33.00

$33.00

$40.00

Microphone CMA-4544

Voltage Regulator LM2940

Battery and Charger

$1.90

$1.65

$29.30

1

2

1

$1.90

$3.30

$29.30

LCD TC2004A-01 $21.99 1 $21.99

Packaging for Control Box $3.50 1 $3.50

Total $317.37

Part Cost/Unit Number Total Cost

MSP430F1611

MSP430F2274

$17.32

$6.30

1

1

$17.32

$6.30

Wi-Fi Module RN-XV-DS v0.3 $34.95 1 $34.95

XBee v1.xEx – 802.15.4 $23.28 2 $46.57

Water Sensor SEN11304P $3.53 1 $3.53

Pulse Sensor SEN11574 $24.95 1 $24.95

Temperature Sensor DS600 $4.90 1 $4.90

Accelerometer MMA7361L

Comparator LM311N

Advanced Circuits Leg Strap PCB

Advanced Circuits Control Box PCB

Resistors and Capacitors

$11.95

$0.91

$33.00

$33.00

$40.00

1

1

1

1

1

$11.95

$0.91

$33.00

$33.00

$40.00

Microphone CMA-4544

Voltage Regulator LM2940

Battery and Charger

$1.90

$1.65

$29.30

1

2

1

$1.90

$3.30

$29.30

LCD TC2004A-01 $21.99 1 $21.99

Packaging for Control Box $3.50 1 $3.50

Total $317.37

Page 9: EEL 4924 Electrical Engineering Design (Senior Design ... · EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: ... Microphone/Noise

University of Florida EEL 4924—Spring 2011 15-Apr-13

Electrical & Computer Engineering Page 9/25

Final Design Report: Wi-Baby

Division of Labor

Table 2 is a breakdown of each team member’s labor for each component of the project by approximate

percentage.

Table 2. Approximate Division of Labor

Timeline

Figure 6 is a Gantt chart of the timeline for the project.

Figure 6. Gantt Chart

Task Zachary Kaufman Aramis Alvarez

Preliminary Research on Wi-Baby 50% 50%

Noise Circuit (Bread Board) 20% 80%

Leg Strap (Bread Board) 50% 50%

Control Box (Bread Board) 50% 50%

Website Desgin/Coding 80% 20%

μP Code for Leg Strap 80% 20%

μP Code for Control Box 80% 20%

Altium PCB (Leg Strap) 20% 80%

Altium PCB ( Control Box) 20% 80%

Packaging 50% 50%

Test and Debug 50% 50%

Page 10: EEL 4924 Electrical Engineering Design (Senior Design ... · EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: ... Microphone/Noise

University of Florida EEL 4924—Spring 2011 15-Apr-13

Electrical & Computer Engineering Page 10/25

Final Design Report: Wi-Baby

Product Images

The components of the final Wi-Baby product are shown in Figure 7. This figure shows the control box,

the leg strap, and the smart diaper.

Figure 7. Components of the Wi-Baby product.

Additionally, Figure 8 shows the entire product with all connections made.

Figure 8. Assembled Wi-Baby product.

Page 11: EEL 4924 Electrical Engineering Design (Senior Design ... · EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: ... Microphone/Noise

University of Florida EEL 4924—Spring 2011 15-Apr-13

Electrical & Computer Engineering Page 11/25

Final Design Report: Wi-Baby

The web interface for Wi-Baby is shown in Figure 9. This interface shows the latest data. A log of

previous data can also be seen, as in Figure 10.

Figure 9. Web interface for Wi-Baby.

Figure 10. Log of Wi-Baby data on website.

Page 12: EEL 4924 Electrical Engineering Design (Senior Design ... · EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: ... Microphone/Noise

University of Florida EEL 4924—Spring 2011 15-Apr-13

Electrical & Computer Engineering Page 12/25

Final Design Report: Wi-Baby

Schematics

The schematic for the leg strap is shown below in Figure 11.

Figure 11. Schematic for leg strap.

Page 13: EEL 4924 Electrical Engineering Design (Senior Design ... · EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: ... Microphone/Noise

University of Florida EEL 4924—Spring 2011 15-Apr-13

Electrical & Computer Engineering Page 13/25

Final Design Report: Wi-Baby

The schematic for the control box is shown below in Figure 12.

Figure 12. Schematic for control box.

Page 14: EEL 4924 Electrical Engineering Design (Senior Design ... · EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: ... Microphone/Noise

University of Florida EEL 4924—Spring 2011 15-Apr-13

Electrical & Computer Engineering Page 14/25

Final Design Report: Wi-Baby

Printed Circuit Boards

The PCB for the leg strap is shown below in Figure 13.

Figure 13. PCB for leg strap.

Page 15: EEL 4924 Electrical Engineering Design (Senior Design ... · EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: ... Microphone/Noise

University of Florida EEL 4924—Spring 2011 15-Apr-13

Electrical & Computer Engineering Page 15/25

Final Design Report: Wi-Baby

The PCB for the control box is shown below in Figure 14.

Figure 14. PCB for control box.

Page 16: EEL 4924 Electrical Engineering Design (Senior Design ... · EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: ... Microphone/Noise

University of Florida EEL 4924—Spring 2011 15-Apr-13

Electrical & Computer Engineering Page 16/25

Final Design Report: Wi-Baby

Software

The code for the leg strap is provided here.

#include "msp430x22x2.h" void configRegs(); void sendData(); void sendChar(char c); char toASCI(int num); int tempArray[10] = {0,0,0,0,0,0,0,0,0,0}; //last 10 values int tempIndex = 0; //index of the pulseArray int pulse = 0; //pulse int water = 0; //is the diaper dirty? 1=yes 0=no int temp = 0; //averaged temperature int accel = 0; //accelerometer readeing 1=up, 0=down int val[3] = {0,0,0}; //accel, temp, pulse int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer configRegs(); double count = 0; while(1) { //Poll pulse until low while(val[2] > 850) __delay_cycles(10000); __delay_cycles(100000); //Poll pulse until high while(val[2] < 850) __delay_cycles(10000); //Start Timer B = 0 counting up TBCTL |= TBCLR; TBCTL |= MC_1; __delay_cycles(100000); //Poll pulse until low while(val[2] > 850) __delay_cycles(10000); __delay_cycles(100000); //Poll pulse until high while(val[2] < 850) __delay_cycles(10000); //Read Timer B and reset to 0 count = TBR; TBCTL |= TBCLR; __delay_cycles(100000); //Calculate pulse, store in the next spot in pulseArray double p = (60000000/(663 * count)); //557 pulse = (int)p; if (pulse > 999) pulse = 999; } }

Page 17: EEL 4924 Electrical Engineering Design (Senior Design ... · EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: ... Microphone/Noise

University of Florida EEL 4924—Spring 2011 15-Apr-13

Electrical & Computer Engineering Page 17/25

Final Design Report: Wi-Baby

#pragma vector=TIMERA0_VECTOR __interrupt void Timer_A (void) { double reading = (double)val[1]; //temp double r = 3.3 * (reading / 1023); //voltage double c = ((r * 1000) - 509)/6.45; //celcius double f = (c * 1.8) + 32; //farenheit tempArray[tempIndex] = (int)f; tempIndex++; if(tempIndex >= 10) tempIndex = 0; //average temp values int i; int total = 0; int counter = 0; for(i=0;i<10;i++) { if(tempArray[i] > 0) //add to total if not 0 { counter++; total += tempArray[i]; } } if (counter == 0) temp = 0; else temp = total/counter; int a = val[0]; //accel if(a > 0x250) accel=1; else accel=0; water = 0x01 & P1IN; sendData(); pulse=0; } void configRegs() { //Set up clocks DCOCTL = CALDCO_16MHZ; BCSCTL1 = CALBC1_16MHZ; BCSCTL1 |= DIVA_3; //Low freq mode, divide Aclk by 8 BCSCTL3 |= LFXT1S_2; //set low-freq clock source to VLOCLK //Set up pins P1SEL = 0; P2SEL = 0x7; //For A0-2 P3SEL = 0x30; //For UART P4SEL = 0x0; //Set up ADC ADC10CTL1 = INCH_2 + ADC10DIV_7 + CONSEQ_3; ADC10CTL0 = ADC10SHT_3 + MSC + REF2_5V + REFON + ADC10ON; ADC10AE0=0x07; ADC10DTC0 |= ADC10CT; //Continuous transfer ADC10DTC1 = 0x3; //3 locations ADC10SA = (unsigned int)&val[0]; //First location ADC10CTL0 |= ENC + ADC10SC; // Enable and start conversion

Page 18: EEL 4924 Electrical Engineering Design (Senior Design ... · EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: ... Microphone/Noise

University of Florida EEL 4924—Spring 2011 15-Apr-13

Electrical & Computer Engineering Page 18/25

Final Design Report: Wi-Baby

//Set up UART UCA0CTL1 = UCSSEL_2 + UCSWRST; //SMCLK (16 MHz), Reset enable UCA0CTL0 = 0; //no parity, LSB first, 8 bit, one stop, UART mode, Asynchronous UCA0BR1 = 0x6; UCA0BR0 = 0x83; //Baud rate = 16 MHz/0x683 = 9600 UCA0CTL1 &= 0xFE; //release reset //Set up TimerB TBCTL = TBSSEL_1; //ACLK TBCCR0 = 8440; //Timeout = 5 sec TBCCTL0 = 0; //Set up TimerA, interrupt TACCTL0 = CCIE; // TACCR0 interrupt enabled TACCR0 = 8440; //Count = 8440 (5 sec) (1688 = 1 Hz) TACTL = TASSEL_1 + MC_1; //ACLK, div by 1, upcount (clk = 500 Hz) __bis_SR_register(GIE); //General Interrupt Enable } void sendData() // <-PPP,TTT,A,W { sendChar('P'); sendChar('='); int x = (pulse/100); //if(x != 0) sendChar(toASCI(x)); x = (pulse/10); //if(x != 0) sendChar(toASCI(x)); x = (pulse); sendChar(toASCI(x)); sendChar('&'); sendChar('T'); sendChar('='); x = (temp/100); //if(x != 0) sendChar(toASCI(x)); x = (temp/10); //if(x != 0) sendChar(toASCI(x)); x = (temp); sendChar(toASCI(x)); sendChar('&'); sendChar('A'); sendChar('='); sendChar(toASCI(accel)); sendChar('&'); sendChar('W'); sendChar('='); sendChar(toASCI(water)); sendChar(' '); } void sendChar(char c) { while(IFG2 & 0x02 == 0); __delay_cycles(100000); UCA0TXBUF = c; }

Page 19: EEL 4924 Electrical Engineering Design (Senior Design ... · EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: ... Microphone/Noise

University of Florida EEL 4924—Spring 2011 15-Apr-13

Electrical & Computer Engineering Page 19/25

Final Design Report: Wi-Baby

char toASCI(int num) { char res; switch (num%10) { case 0: res = '0'; break; case 1: res = '1'; break; case 2: res = '2'; break; case 3: res = '3'; break; case 4: res = '4'; break; case 5: res = '5'; break; case 6: res = '6'; break; case 7: res = '7'; break; case 8: res = '8'; break; case 9: res = '9'; break; default: res = '0'; break; } return res; } #pragma vector=ADC10_VECTOR, NMI_VECTOR, PORT1_VECTOR, PORT2_VECTOR, TIMERA1_VECTOR, TIMERB0_VECTOR, TIMERB1_VECTOR, USCIAB0RX_VECTOR, USCIAB0TX_VECTOR, WDT_VECTOR __interrupt void ISR_trap(void) { // the following will cause an access violation which results in a PUC reset WDTCTL = 0; }

Page 20: EEL 4924 Electrical Engineering Design (Senior Design ... · EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: ... Microphone/Noise

University of Florida EEL 4924—Spring 2011 15-Apr-13

Electrical & Computer Engineering Page 20/25

Final Design Report: Wi-Baby

The code for the control box is provided here.

#include "msp430f1611.h" void configRegs(); void sendChar(char c); void lcd_command(char); void lcd_char(char); void lcd_init(void); void sendData(void); void updateLCD(void); char data[20] = {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '}; unsigned int index = 0; char uf_lcd_temp; int noise = 0; int update = 0; int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer configRegs(); lcd_init(); char temp; int flag; int noiseadc = 0; int noisecount = 0; while(1) { flag = TACTL & 0x0001; // Timer A flag if(flag == 0x0001) { noiseadc = ADC12MEM0 & 0x0FFF; if ((noiseadc > 0x400) && (noisecount < 100)) { noisecount++; } } flag = IFG1 & 0x0040; if(flag == 0x0040) { temp = U0RXBUF; data[index] = temp; index++; if(temp == ' ' || index >= 20) { index = 0; if (noisecount > 10) noise = 1; else noise = 0; noisecount = 0; updateLCD(); update++; if (update == 3) //update server every 3 times the LCD updates { update = 0;

Page 21: EEL 4924 Electrical Engineering Design (Senior Design ... · EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: ... Microphone/Noise

University of Florida EEL 4924—Spring 2011 15-Apr-13

Electrical & Computer Engineering Page 21/25

Final Design Report: Wi-Baby

sendData(); } } } } } //P=###&T=###&A=#&W=#&N=# //noise(1 yes, 0 no), orient(1 up, 0 down), int diaper(0 clean, 1 dirty) void sendData() { unsigned int i = 0; int done = 0; while(i < 20 && done == 0) { if (data[i] == ' ') { done = 1; } else { sendChar(data[i]); i++; } } sendChar('&'); sendChar('N'); sendChar('='); if(noise == 0) sendChar('0'); else sendChar('1'); } void updateLCD() { //line 1 lcd_char('H'); lcd_char('e'); lcd_char('a'); lcd_char('r'); lcd_char('t'); lcd_char(' '); lcd_char('R'); lcd_char('a'); lcd_char('t'); lcd_char('e'); lcd_char(':'); lcd_char(' '); lcd_char(' '); lcd_char(data[2]); lcd_char(data[3]); lcd_char(data[4]); lcd_char(' '); lcd_char(' '); lcd_char(' '); lcd_char(' ');

Page 22: EEL 4924 Electrical Engineering Design (Senior Design ... · EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: ... Microphone/Noise

University of Florida EEL 4924—Spring 2011 15-Apr-13

Electrical & Computer Engineering Page 22/25

Final Design Report: Wi-Baby

//line 3 lcd_char('O'); lcd_char('r'); lcd_char('i'); lcd_char('e'); lcd_char('n'); lcd_char('t'); lcd_char('a'); lcd_char('t'); lcd_char('i'); lcd_char('o'); lcd_char('n'); lcd_char(':'); lcd_char(' '); if(data[14] == '1') { lcd_char('U'); lcd_char('p'); lcd_char(' '); lcd_char(' '); } else { lcd_char('D'); lcd_char('o'); lcd_char('w'); lcd_char('n'); } lcd_char(' '); lcd_char(' '); lcd_char(' '); //line 2 lcd_char('T'); lcd_char('e'); lcd_char('m'); lcd_char('p'); lcd_char('e'); lcd_char('r'); lcd_char('a'); lcd_char('t'); lcd_char('u'); lcd_char('r'); lcd_char('e'); lcd_char(':'); lcd_char(' '); lcd_char(data[8]); lcd_char(data[9]); lcd_char(data[10]); lcd_char(' '); lcd_char(' '); lcd_char(' '); lcd_char(' '); //line 4 lcd_char('D'); lcd_char('i'); lcd_char('a');

Page 23: EEL 4924 Electrical Engineering Design (Senior Design ... · EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: ... Microphone/Noise

University of Florida EEL 4924—Spring 2011 15-Apr-13

Electrical & Computer Engineering Page 23/25

Final Design Report: Wi-Baby

lcd_char('p'); lcd_char('e'); lcd_char('r'); lcd_char(':'); lcd_char(' '); if(data[18] == '1') { lcd_char('D'); lcd_char('i'); lcd_char('r'); lcd_char('t'); lcd_char('y'); } else { lcd_char('C'); lcd_char('l'); lcd_char('e'); lcd_char('a'); lcd_char('n'); } lcd_char(' '); lcd_char(' '); if(noise == 0) { lcd_char('Q'); lcd_char('u'); lcd_char('i'); lcd_char('e'); lcd_char('t'); } else { lcd_char('N'); lcd_char('o'); lcd_char('i'); lcd_char('s'); lcd_char('e'); } } void sendChar(char c) { while(IFG2 & 0x20 == 0); __delay_cycles(100000); U1TXBUF = c; } void configRegs() { //Set up clocks DCOCTL = 0xE0; //4.885 MHz? DCO freq sel = 7 BCSCTL1 = 0x07; //4.885 MHz? RSEL = 7 //Set up pins P1SEL = 0x00; P2SEL = 0; P3SEL = 0xF0; //For UARTs

Page 24: EEL 4924 Electrical Engineering Design (Senior Design ... · EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: ... Microphone/Noise

University of Florida EEL 4924—Spring 2011 15-Apr-13

Electrical & Computer Engineering Page 24/25

Final Design Report: Wi-Baby

P4SEL = 0; //LCD P5SEL = 0x00; //MCLK 5.4 P6SEL = 0x01; //A0 //Set up UART0 -- XBee U0CTL = SWRST; //Reset on U0CTL |= CHAR; //8-bit char mode, 1 stop bit, no parity U0TCTL = 0x20; //BRCLK source = SMCLK U0BR0 = 0xFD; //4,885,000/9600 = 509 = 0x209 U0BR1 = 0x01; ME1 |= UTXE0 + URXE0; U0CTL &= 0xFE; //Reset off //Set up UART1 -- WiFi U1CTL = SWRST; //Reset on U1CTL |= CHAR; //8-bit char mode, 1 stop bit, no parity U1TCTL = 0x20; //BRCLK source = SMCLK U1BR0 = 0xFD; //4,885,000/9600 = 509 = 0x1FD U1BR1 = 0x01; ME2 |= UTXE1 + URXE1; U1CTL &= 0xFE; //Reset off //Set up timer TACTL = TASSEL_2 + ID_3 + MC_1; //SMCLK, div by 8, up mode TACCR0 = 0xFFFF; //approx 10 Hz //Set up ADC ADC12CTL0 = 0; ADC12CTL0 |= SHT1_4 + SHT0_4 + MSC + REF2_5V + REFON + ADC12ON; ADC12CTL1 = CSTARTADD_0 + SHP + ADC12DIV_7 + CONSEQ_2; ADC12MCTL0 = INCH_0; //end of seq (EOS), A0 ADC12CTL0 |= ENC + ADC12SC; //enable ADC and start conv } void lcd_command(char uf_lcd_x) { uf_lcd_temp = uf_lcd_x; P4OUT = 0x00; __delay_cycles(40000); uf_lcd_x = uf_lcd_x >> 4; uf_lcd_x = uf_lcd_x & 0x0F; uf_lcd_x = uf_lcd_x | 0x20; P4OUT = uf_lcd_x; __delay_cycles(40000); uf_lcd_x = uf_lcd_x & 0x0F; P4OUT = uf_lcd_x; __delay_cycles(40000); P4OUT = 0x00; __delay_cycles(40000); uf_lcd_x = uf_lcd_temp; uf_lcd_x = uf_lcd_x & 0x0F; uf_lcd_x = uf_lcd_x | 0x20; P4OUT = uf_lcd_x; __delay_cycles(40000); uf_lcd_x = uf_lcd_x & 0x0F; P4OUT = uf_lcd_x; __delay_cycles(40000); } void lcd_init(void){ P4DIR = 0x3F; // Set P4.0-4.5 to output (LCD)

Page 25: EEL 4924 Electrical Engineering Design (Senior Design ... · EEL 4924 Electrical Engineering Design (Senior Design) Final Design Report 23 April 2013 Project Name: ... Microphone/Noise

University of Florida EEL 4924—Spring 2011 15-Apr-13

Electrical & Computer Engineering Page 25/25

Final Design Report: Wi-Baby

lcd_command(0x33); lcd_command(0x32); lcd_command(0x2C); lcd_command(0x0F); lcd_command(0x01); lcd_command(0x06); lcd_command(0x0C); } void lcd_char(char uf_lcd_x){ uf_lcd_temp = uf_lcd_x; P4OUT = 0x10; __delay_cycles(4000); uf_lcd_x = uf_lcd_x >> 4; uf_lcd_x = uf_lcd_x & 0x0F; uf_lcd_x = uf_lcd_x | 0x30; P4OUT = uf_lcd_x; __delay_cycles(4000); uf_lcd_x = uf_lcd_x & 0x1F; P4OUT = uf_lcd_x; __delay_cycles(4000); P4OUT = 0x10; __delay_cycles(4000); uf_lcd_x = uf_lcd_temp; uf_lcd_x = uf_lcd_x & 0x0F; uf_lcd_x = uf_lcd_x | 0x30; P4OUT = uf_lcd_x; __delay_cycles(4000); uf_lcd_x = uf_lcd_x & 0x1F; P4OUT = uf_lcd_x; __delay_cycles(4000); } #pragma vector=ADC12_VECTOR, COMPARATORA_VECTOR, DACDMA_VECTOR, NMI_VECTOR, PORT1_VECTOR, PORT2_VECTOR, TIMERA0_VECTOR, TIMERA1_VECTOR, TIMERB0_VECTOR, TIMERB1_VECTOR, WDT_VECTOR, USART0RX_VECTOR, USART0TX_VECTOR, USART1RX_VECTOR, USART1TX_VECTOR __interrupt void ISR_trap(void) { // the following will cause an access violation which results in a PUC reset WDTCTL = 0; }