Use of device
Project overview
Motivation
For our project, we wanted to create a solution to a real-world problem. Many biomedical devices, such as commercially available respiratory monitors, are designed for the developed world and require a stable power-supply to operate. We wanted to implement a solution that is adaptable to different environments.
Our device uses several concepts we learned not only this semester in ECE 4760, but also in other classes at Cornell. We use analog-to-digital conversions to sample readings from both the thermistor and the battery, pulse-width modulation to generate a signal for the speaker, and timers to switch between tasks. Our implentation also includes various analog circuitry for voltage regulation and signal amplification. Developing a robust and accurate respiratory monitor served to be a challenging, yet rewarding experience.
Previous Work
When doing research for this project, we came across several respiratory monitors using different sensors for measuring breathing. Other methods of monitoring respiratory rate include a chest force sensor (to detect force produced by chest movement), impedance pneumograph (which uses skin electrodes to calculate transthoracic impedance), and pulse oximetry (which measures O2 saturation in blood). While commercial devices to monitor respiratory rate exist, they use motion or force sensors to determine respiration rate. These monitors tend to be better suited for developed countries where a stable power supply is not a concern. We want to design our device geared to the needs of undeveloped areas. Therefore, we aimed for our thermistor monitor to be comparatively cheaper, easier to use, as well as reliable.
We also discovered another thermistor respiratory monitor research project. The design of the device differed from ours, in that it included two thermisors; one that remains in the outside environment for reference and one that goes inside the nostril.
High-Level Block Diagram
1. Thermistor Measurements
The resistance over the thermistor drops when its surrounding temperature increases, and goes back down when the temperature decreases. The voltage also, accordingly drops when a person exhales and rises when a person inhales. We use an operational amplifier to make the changes in temperature more apparent. The output of the amplifier is read into the microcontroller's ADC channel 0.
2. Voltage Measurements
Under battery operation, our device takes a voltage sample across the battery about every minute. Since our device uses a 9V battery, a voltage divider is used to drop the voltage so that it is about 2.2V at PINA1 (ADC channel 1).
3. Power
Our device can be powered through either a standard AC power suppy or a single 9V battery.
4. Turn On Display
To conserve power, the user must hold down a button to turn on the display to read the respiration rate. This prevents the user from leaving the display on by mistake and draining the battery.
5. Output Sound
There are two different alarms for our device generated by a piezoelectric speaker. The first is higher in pitch and alarms if the patient is not breathing. The second is a signal that the device is running on low battery. While the first alarm is a continous sound, the low-battery alert is a one second long tone.
6. Respiration Rate Display
Breathing rate is measured and displayed in breaths/min on an LCD. This allows whoever is monitoring the patient to see if the patient is breathing too fast or too slowly.
7. Measurement
This task does the actual calculation of the respiration rate using samples from ADC0.
Design Decisions
Microcontroller
When choosing a microcontroller for this project, we first wanted to find the smallest microcontroller possible so that it could be mounted right onto the device's mask. However, when identifying how many I/O ports and ADC channels would be neccessary for our project, we realized that the AtMega1284p microcontroller that we had been using all semester would be ideal.
Thermistor
During the initial stages of our project design we experimented with several thermistors and their placement on the device. Since a drastic temperature difference is not produced when a human breathes, we needed the smallest, and therefore most sensitive thermistor we could find. Larger thermistors we experimented with either could not detect a "breath" or had a very slow response time. We also thought a mask around the patient's nose and mouth would be the least intrusive placement of the thermistor.
Display
Because we wanted to design our device to be low-powered, choosing the right display for the respiratory rate was a concern. Orignally, we planned to use two 7-segment displays which turned on when the user pressed a button. However, we decided to use an LCD screen for a nicer display. In order to reduce power usage, the LCD only receives power when the user presses the display button, which reduces the load on the battery.
Standards
As a medical device, this respiratory monitor must meet regulatory requirements outlined by governments. This includes meeting HIPPA standards which protects individuals� medical records and other personal health information, including respiration rate. However, since we are not planning to store this information, this regulation should not be an issue. Before it can be sold commercially in the United States, the device would also need FDA approval.
Software Design & Implementation
Software Overview
The C programming language was used to program the MCU using the AVR Studio version 4.15 and was compiled using the WINAVR GCC C compiler. The software for the respiratory monitor contains 5 different tasks and 2 interrupt service routines (ISR). The first ISR is the Timer0 Compare Match Vector. This ISR activates every 16.4 ms and decrements three different timeout counters whenever it activates. It also zeroes the variable count (used to measure respiration rate) to prevent it from overflowing. Since the clock of the MCU is 16 MHz, we set the prescaler to 1024 and OCR0A to 255. Setting OCR0A to 255 means the ISR will activate every 256 clk cycles. The second ISR used was the AC ISR. This ISR activates when the onboard AC outputs a 1. This ISR was used to measure the respiration rate of the person. This will be described in detail below in the appropriate section.
Main
The main function initializes the device and then goes into the main loop. Both the low pass and high pass filters have very large time constants (22 seconds) and capacitors. This means that they will take an extremely long time to charge before the overall device can begin to work. This start up time was on the order of minutes, which was too long in our opinion. To solve this problem we created a separate circuit that would charge our capacitors using much smaller time constants. This was done in the first 10 lines of code in main before any other function was initialized. First, PinB5 and B4 are set to output. B5 is set to 0 V and B4 is set to 5 V. This essentially turns on the Vcc and ground for the charging capacitor circuit. The charging capacitor circuit is left on for 5 seconds before it is turned off. It is turned off by switching B4 and B5 to inputs. Afterwards the initialize functions are turned on and the while(1) loop begins.
The while-loop goes through a series of conditions to see if the device needs to call one of the tasks. The thermistor and sampling tasks are both timed, so if either timer count equals 0, the counter is reset and the task is called. The thermistor sampling task is called every second, while the battery sampling task is called every minute. The measure task is called when the measure_flag indicates that a measurement is ready to be taken. Lastly, the display task activates when the user holds down the display button.
Thermistor Sampling
Samples from the thermistor are taken through PINA0. First, the ADMUX register is set to turn on the left adjust result and external reference. The MCU then waits for a conversion to occur, and then sets the variable sample_old to the current sample and the sample variable to the high bits from the ADC. The absolute value of the difference between sample_old and sample is used to determine if the patient has stopped breathing. If this difference is less than or equal to 8, then this is considered a "no breath". If the MCU detects 10 consecutive "no breaths", a PWM signal is generated to produce a sound from the speaker. If the difference is above the tolerance, then the "no breath" counter variable c is reset to 0 and the PWM signal is set to be turned off.
The tolerance for the difference between breaths was found through experimentation. Looking at the ADC values on the UART, the range of the sampled values was 6-8 when a person was not breathing. To compensate for this fluctation, we compare the difference between consecutive thermistor samples against 8 instead of 0. We also decided to have a counter to keep track of the number of "no breaths" detected because depending on how a person is breathing, consecutive samples could fall into the tolerance range. Counting up to 10 consecutive "no breaths" drastically reduces the number of false positive alarms.
ADC sampling and PWM signal generation were concepts we learned earlier in the semester in Labs 2 and 3.
Battery Sampling
To take a sample from the battery, ADC channel 1 on PINA1 is turned on by setting the ADMUX register. The MCU waits for a conversion to occur and then sets the variable bat_samp to the high bits from the ADC. The sample is then compared to the ADC value that was found to correspond to a voltage of 7.6 V. During testing it was found that device operation becomes unstable at 7.5 V. Therefore, we decided to warn the user when the voltage of the battery becomes 7.6 V
If the battery sample is found to be less than or equal to the tolerance, then a PWM signal is generated, left on for about 1 second, and then is turned off. The PWM channel which produces a tone for a low-battery warning has a larger prescalar than the PWM channel to produce the alarm for when a patient is not breathing, making the low-battery tone lower in pitch.
Measuring Task
The respiratory rate is measured by using the AC and measuring the time difference between when the voltage across the thermistor crosses the reference voltage. The first part of this is done in the ISR. When the voltage across the thermistor crosses the reference voltage the AC ISR activates. It then stores the number of clk cycles into the variable tau2 and stores the number of clk cycles of the previous crossing in tau1. The difference between tau2 and tau1 is then stored in the variable period. In essence this ISR measures the difference in the number of clk cycles between two reference voltage crossings. Once this measurement is done the measure flag is set and the measure task is activated. In the measure task an average difference in clk cycles is calculated by doing a weighted average between the newly measured difference in clk cycles and the previous average difference in clk cycles. The weights are 0.75 of the previous average and 0.25 of the new difference. This weighted average is taken so that an average respiratory rate can be calculated. This average difference in clk cycles is then converted to respiratory rate in breaths per a min (bpm). This is done by converting the difference in clk cycles to minutes and taking the reciprocal. We take the reciprocal because the AC ISR is activated every breath, i.e. it measures the time for one breath.
While writing this code we ran into the problem that the AC ISR was activating several times per one crossing. This was happening because as our signal crossed the reference voltage the noise in our system caused the signal to cross the reference voltage several more times. To solve this when the AC ISR is activated the first time the first line in the ISR turns off the AC ISR and the flag called flag is set. Then in main there is an if statement that says if flag is set to 1, wait 10 ms, turn on the AC ISR and reset flag. The 10 ms delay is used to wait for our signal to cross the reference voltage far enough so that there is no interference from the noise.
Display Task
The display function is used to display the respiratory rate on the LCD when the user is holding down the LCD push button. This was achieved by having the display function activate when PinB1 was read as 1. When PinB1 is 1 the LCD is initialized and the value of the respiratory rate stored in the variable breathrate and written to the LCD buffer. This value was then displayed on the LCD.
Hardware Design & Implementation
1. Thermistor Measurement
We used a thermistor based measuring system to measure the breathing rate of the patients. The thermistor is mounted inside a mask which is worn by the patient. The mask is a standard nebulizer mask that is used by asthma patients. The thermistor is mounted inside the mask so that it is directly in front of the patient�s mouth. As the patient breaths the hot air from the patient�s breath changes the resistance (Rth) of the thermistor. As a result, the voltage across the thermistor (Vth) will also change proportionally to how the patient breaths. We can therefore use Vth as an indirect measurement of how the patient is breathing. To measure Vth we used a voltage divider as shown below in Figure 1.
When the thermistor is at room temperature its resistance is approximately 1.2 kΩ so we choose R1 to be 1 kΩ. This was chosen so that Vth would be about 2.5 V if no one was breathing on the thermistor. We wanted to have 2.5 V be our no breathing voltage so that extreme inhalations or exhalations could be detected with our device.
2. Thermistor Amplification
The thermistor we choose for our project was the NTHS0402 from Vishay Dale. This thermistor has a thermal time constant of 5 seconds which makes it extremely sensitive. During experimentation we found that the change in voltage from a person breathing on the thermistor was on the order of 10 mV. Since this was too small of a change to work with we decided to amplify this change by using an Op Amp with a high pass filter. An Op Amp alone will not suffice because it will amplify the entire signal whereas we only want to amplify the change in voltage. Literature research shows that the average adult male breaths about 15-20 breaths/min and the average infant breaths about 30-60 breaths/min. Our slowest desired period is about 4 seconds. We choose the time constant for our high pass filter to be 22 seconds. This means that any signal with a period less than 22 seconds will be amplified by our op amp. We choose 22 seconds so that our device could detect hyperventilation as well as normal breathing. The time constant was set to 22 seconds by choosing R2 to by 10 kΩ and C1 to 2200 µF as seen in Figure 2. The gain was then set to 4 by choosing R3 to be 30 kΩ.
The output of this circuit goes to both PortA0 and PortB2. PortA0 is the input to the ADC while PortB2 is the + reference pin for the AC (see software design section).
3. Analog Comparator
The respiratory rate is measured by using an analog comparator (AC) to compare the amplified voltage across the thermistor to a reference voltage. Since the respiratory signal is approximately equivalent to a sine wave with a DC offset, we choose the reference voltage to be at the DC offset. However, patients of different ages will have different steady state breathing temperatures. For example older patients will breath out more hot air than younger patients. This means that the DC offset will be lower than those of younger patients. To automatically determine the reference voltage for a patient we used a low pass filter shown below in Figure 3. This low pass filter has a time constant of 22 seconds which means it rejects all of the signals we are interested in. Since it rejects the respiratory signal the output of this filter must be at the average value of the incoming signal. As the incoming signal is equivalent to a sine wave with a DC offset, the average value of the signal is the DC. The output of this filter than goes into the voltage reference pin of the AC as shown in Figure 3. The respiratory signal comes from PortB2 and goes into both the filter and positive voltage pin of the AC of the MCU. To achieve a time constant of 22 seconds R4 is 100 kΩ and C2 is 220 µF.
4. Capacitor Charger
The time constant for the thermistor amplification circuit described above is 22 seconds which means it takes several minutes for the capacitor to charge up. During this charging period the device does not work properly because the capacitor is not fully charged. To decrease this charging time another circuit was added with a smaller resistor so that the time constant for charging would be faster. The charging capacitor schematic is shown below in Figure 4. When PortB4 and PortB5 are set to 5 V and 0 V respectively (see software design for further details) the capacitor begins to charge through R6. Both R5 and R6 are 330 Ω so that they would provide as little resistance as possible. The time constant for charging then becomes 0.73 seconds and the total time for charging is about 6 seconds. R5 is necessary to provide protect for PortB4 so that it is not damaged.
5. LCD Display Button
In order to conserve power the user must hold down a button to turn the LCD on. This way the LCD is not on when it is not being used and it cannot be left on by mistake. This was accomplished by connecting the LCD Vcc pin to the MCU Vcc via a push button as shown in Figure 5. When the button is pushed the LCD Vcc pin receives 5 V. Resistor 10 and Rsesistor 7 are needed to ensure that the voltage at the pink node is below the threshold voltage of the MCU pins. This way PortB1 will read 0 V when the button isn�t pushed and 5 V when the button is pushed. Both R10 and R7 are 330 Ω.
The LCD we used the MDL(s)-16264 LCD from Vartronix along with a 10 kΩ trimpot to control the contrast.
6. Battery Monitor
To measure the voltage of the 9 V battery we used a voltage divider along with a low pass filter as shown in Figure 6 below. The voltage divider is used to convert the voltage range from 0-9 V to 0-5 V so that the MCU will not be damaged. The ADC is then used convert the analog voltage to a digital format so that the MCU and analyze it. The purpose of the low pass filter is to eliminate any high frequency signals that might occur. The time constant of the filter is 1 µs and is achieved by setting C2 to 1 nF and R8 to 1 kΩ. R9 is set to 3 kΩ so that the voltage divider outputs ¼ of the original voltage.
Comments
Please log in or sign up to comment.