acoustic remote sensing

228
Acoustic Remote Sensing Developed By: Senior Design Group 7 University of Central Florida July 31, 2002

Upload: ralfwork

Post on 11-Nov-2014

108 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Acoustic Remote Sensing

Acoustic Remote Sensing

Developed By: Senior Design Group 7

University of Central Florida July 31, 2002

Page 2: Acoustic Remote Sensing

Executive Summary

Some of the oyster beds in Mosquito Lagoon are being destroyed. One possible cause of the destruction is the amount of boat traffic through the area. Passing boats disturb the sediments in the water, which agitate the oysters. The group will design the Acoustic Remote Sensing device to determine the distance of passing boats from the oyster beds. This stand-alone device will need to be lightweight and submersible in saltwater.

The device will utilize SOund NAvigation and Ranging (SONAR) technology. An

ultrasonic transducer will be used to calculate the distance by transmitting and receiving sound waves. The signal from the transducer will be sent to the microcontroller. For calculating range, the speed of sound in the water must be determined. The speed of sound in water is dependent on a few factors such as water temperature. The water temperature will be determined using a temperature sensor. The time between signal transmission and signal reception, along with the speed of sound in the water will be used to calculate the distance.

Once the distance has been determined, the information will be stored on a

removable memory device for later retrieval. A CompactFlash card will be the memory of choice due to is durability, compact size, and storage capacity. The distance, along with the date, time and water temperature, will be sent to the CompactFlash card for storage.

After a 24-hour period of time, the device will be retrieved and the memory

removed. A new memory card can be installed for another 24-hour period. At this time, the batteries can be replaced if needed. The memory card with the information will be taken and connected to a computer with a SanDisk memory card reader. The information will be transported into software that will utilize a Graphical User Interface (GUI) specifically designed for this project.

The GUI will access the information and allow the user to perform statistical

analysis. It will be able to calculate the mean, median, mode, variance and standard deviation. The GUI will also be capable of graphical analysis based on user inputs. Through these graphs, patterns over time may be realized, i.e., the time of day that experienced the most boat traffic.

In the end, we hope the device will help conserve the marine life in the ocean.

The device is not specifically designed for Mosquito Lagoon only. It will be capable of implementation in any shallow, salt-water areas.

Page 3: Acoustic Remote Sensing

TABLE OF CONTENTS CHAPTER 1: TRANSDUCER -------------------------------------------------------------------------- 1

1.1 Project Description-------------------------------------------------------------------------------- 2 1.2 Brief Theory Behind The Device -------------------------------------------------------------- 2 1.3 Physics of Sound----------------------------------------------------------------------------------- 3 1.4 Physics of SONAR systems -------------------------------------------------------------------- 6 1.5 Sound Vs. Other Options ------------------------------------------------------------------------ 9 1.6 Transducers --------------------------------------------------------------------------------------- 11

1.6.1 Introduction----------------------------------------------------------------------------------- 11 1.6.2 Transducer Applications ------------------------------------------------------------------ 13 1.6.3 Transducer Characteristics -------------------------------------------------------------- 13 1.6.4 Mechanical Characteristics of the Transducer -------------------------------------- 14 1.6.5 Electrical Characteristics ----------------------------------------------------------------- 17 1.6.6 Transducer Types -------------------------------------------------------------------------- 18 1.6.7 Transducer Comparisons----------------------------------------------------------------- 19

CHAPTER 2: DEVICE COMPONENTS------------------------------------------------------------ 26 2.1 The Microcontroller ------------------------------------------------------------------------------ 27

2.1.1 Introduction----------------------------------------------------------------------------------- 27 2.1.2 Microcontroller Considerations---------------------------------------------------------- 32 2.1.3 Microcontroller Notation Convention--------------------------------------------------- 34

2.2 The Crystal Oscillator --------------------------------------------------------------------------- 34 2.3 Capacitors and Resistors ---------------------------------------------------------------------- 35 2.4 Analog-to-Digital Converter-------------------------------------------------------------------- 36 2.5 Digital Potentiometer ---------------------------------------------------------------------------- 37 2.6 Operational Amplifier---------------------------------------------------------------------------- 39

CHAPTER 3: MEMORY ------------------------------------------------------------------------------- 40 3.1 Data Storage and Acquisition ----------------------------------------------------------------- 41

3.1.1 Introduction----------------------------------------------------------------------------------- 41 3.1.2 Memory Selection -------------------------------------------------------------------------- 41 3.1.3 CompactFlash vs. SmartMedia --------------------------------------------------------- 43 3.1.4 SanDisk Reader ---------------------------------------------------------------------------- 43 3.1.5 CompactFlash vs. MultiMediaCard----------------------------------------------------- 44

3.2 Interfacing CompactFlash and Microcontroller ------------------------------------------- 46 3.2.1 Introduction----------------------------------------------------------------------------------- 46 3.2.2 Pin Assignment ----------------------------------------------------------------------------- 47

CHAPTER 4: POWER SUPPLY--------------------------------------------------------------------- 52 4.1 Introduction ---------------------------------------------------------------------------------------- 53 4.2 Devices Requiring Voltage Supply ---------------------------------------------------------- 53 4.3 Overview of Power Supply for Submersible Watchdog--------------------------------- 54 4.4 Power Supply Considerations ---------------------------------------------------------------- 55 4.5 Current Supply Requirements ---------------------------------------------------------------- 59 4.6 Batteries-------------------------------------------------------------------------------------------- 60

4.6.1 Battery Types-------------------------------------------------------------------------------- 60 4.6.2 Battery Selection---------------------------------------------------------------------------- 61

4.7 Power Supply Configuration------------------------------------------------------------------- 64

Page 4: Acoustic Remote Sensing

4.8 Date/Time Recording --------------------------------------------------------------------------- 67 CHAPTER 5: BOX DESIGN -------------------------------------------------------------------------- 70

5.1 Introduction ---------------------------------------------------------------------------------------- 71 5.2 Types of Materials ------------------------------------------------------------------------------- 71 5.3 Material Comparison ---------------------------------------------------------------------------- 71 5.4 Box Building Considerations ------------------------------------------------------------------ 74

CHAPTER 6: PUTTING THEM ALL TOGETHER ---------------------------------------------- 76 6.1 Putting Them All Together --------------------------------------------------------------------- 77

6.1.1 CompactFlash ------------------------------------------------------------------------------- 77 6.1.2 Crystal Oscillator---------------------------------------------------------------------------- 77 6.1.3 Ultrasonic Transducer --------------------------------------------------------------------- 79 6.1.4 Microcontroller------------------------------------------------------------------------------- 79 6.1.5 Microchip’s 16F877 Features and Specifications----------------------------------- 79 6.1.6 Setting Up Registers----------------------------------------------------------------------- 80 6.1.7 I2C Mode Operation------------------------------------------------------------------------ 82 6.1.8 The Temperature Sensor ---------------------------------------------------------------- 84 6.1.9 Real Time Clock (RTC) Module--------------------------------------------------------- 85 6.1.10 LCD Display Module --------------------------------------------------------------------- 85 6.1.11 Operational Amplifier--------------------------------------------------------------------- 86 6.1.12 Curve Fitting-------------------------------------------------------------------------------- 87 6.1.13 Digital Potentiometers Configuration------------------------------------------------- 87 6.1.14 Function Generator----------------------------------------------------------------------- 88

6.2 The Overall Circuit ------------------------------------------------------------------------------- 88 CHAPTER 7: GRAPHICAL USER INTERFACE ------------------------------------------------ 93

7.1 Introduction ---------------------------------------------------------------------------------------- 94 7.1.1 Purpose of the system -------------------------------------------------------------------- 94 7.1.2 Scope of the system ----------------------------------------------------------------------- 94 7.1.3 Objectives and success criteria of the project --------------------------------------- 94 7.1.4 Definitions, acronyms and abbreviations --------------------------------------------- 94

7.2 Current System----------------------------------------------------------------------------------- 95 7.3 Proposed System -------------------------------------------------------------------------------101

7.3.1 Overview-------------------------------------------------------------------------------------101 7.3.2 Functional requirements -----------------------------------------------------------------101 7.3.3 Nonfunctional Requirements -----------------------------------------------------------102 7.3.5 Systems models ---------------------------------------------------------------------------103

CHAPTER 8: FINAL DESIGN AND IMPLEMENTATION CHANGES --------------------107 8.1 Tranducer -----------------------------------------------------------------------------------------108 8.2 Liquid Crystal Display --------------------------------------------------------------------------113 8.3 Power Supply ------------------------------------------------------------------------------------115 8.4 Box Design ---------------------------------------------------------------------------------------116 8.5 Synchronous Serial Port ----------------------------------------------------------------------116

8.5.1 SPI --------------------------------------------------------------------------------------------116 8.5.2 DS1722 Temperature Sensor ----------------------------------------------------------120 8.5.3 DS1305 Real-Time Clock and DS32KHZ Crystal Oscillator --------------------121

8.6 Memory--------------------------------------------------------------------------------------------122 8.7 Microcontroller -----------------------------------------------------------------------------------124

Page 5: Acoustic Remote Sensing

CHAPTER 9: ADMINISTRATIVE CONTENT ---------------------------------------------------125 8.1 Budget and Financing--------------------------------------------------------------------------126 8.2 Milestone Chart----------------------------------------------------------------------------------128 8.3 Group Member Backgrounds ----------------------------------------------------------------129 8.4 Contact Information-----------------------------------------------------------------------------131 8.5 Special Thanks ----------------------------------------------------------------------------------132

SUMMARY -----------------------------------------------------------------------------------------------133 APPENDIX -----------------------------------------------------------------------------------------------134

Page 6: Acoustic Remote Sensing

CHAPTER 1

TRANSDUCER

This section provides the information on transducers. It provides a background on sound propagation and transducers. Comparisons between available transducers and the chosen transducer will be made in this chapter.

1

Page 7: Acoustic Remote Sensing

1.1 Project Description The underwater sonar ranging system will determine the distance of an object in the saltwater. The concept is to use sound waves to measure the distance, and this device will record the data on to flash card. The flash card would then be retrieved, and the data will be analyzed on computer software with a Graphic User Interface. The program will have basic statistical tools. The device is to be submerged just under the water surface, so it will have to be waterproof. The standby time is expected to be more than 24 hours, and the minimum range will be 50 feet. This device will be a third generation device. The previous generation had a range of about 10 feet in air. This generation will offer a much better standby time, range, ease of use, and reliability. 1.2 Brief Theory Behind The Device SONAR stands for SOund NAvigation and Ranging. This method uses sound to determine range of an object, and now with more powerful signal processing, sonar can produce images of anything underwater. Given that the velocity of sound in water is almost a constant, the “ping” is sent out, and then will receive the echo. The time of flight that the ping takes to travel from transmitter back to the receiver is measured. By measuring the time of flight, the distance can be found by simply

Distance = Velocity of sound in water / ( 2 * Time of Flight) The quantity is divided by two because it is the distance for traveling back and forth. This method is similar to radar systems, except that radar systems use Radio Frequency (RF) instead of sound. Many people might ask why use sound instead of RF, optics, or other means. First of all, water is great for sound wave propagation. Modern optics can provide a very precise measurement in air, and other medians as long as they are transparent. Water ideally is clear and transparent, but natural water that has not been purified is rarely clear and pure. Therefore, optics is not a choice for our project, since mud can totally destroy the effective range of the device. RF is also another choice, but it still does not propagate well in water. Again, this will limit our range and efficiency of the device. Few more choices are available, but given the limited time and resources, using sonar is the most reasonable. It is already a proven technology, and has been used extensively from the Navy to the fishing industry. The frequency of sonar ranges from very low subsonic frequency to very high ultrasonic frequency. More detail will be explained in latter section.

2

Page 8: Acoustic Remote Sensing

1.3 Physics of Sound “A sound wave is a pressure disturbance which travels through a medium by means of particle interaction” (Halliday and Resnick 1997). A sound wave is produced due to the disturbance in pressure in a medium. The disturbance travels through the medium by the interacting of particles (Halliday and Resnick 1997). Sound waves have wavelength (λ), frequency (ƒ), intensity, and velocity (c). The wavelength of a sound wave is the length in which it travels in one wave cycle/period. The wavelength is measured in meters (m). The frequency of sound is the number of vibrations of a particle per unit of time. Frequency is measured in hertz (Hz). The intensity of a sound is the amplitude of the wave. Intensity is measured in decibels (dB). The velocity of sound is the rate at which vibrations propagate through a medium. Velocity is measured in meters per second (m/s). The velocity or speed of sound is dependent on the medium in which it travels. The speed of sound changes with the medium by either an increase or a decrease. The medium for the device is seawater. The speed of sound in air is approximately 340 m/s where as the speed of sound in water is faster, approximately 1500 m/s. Temperature, pressure, and salinity are the only factors that cause changes in the speed of sound in water. These factors are directly proportional with the speed as shown in Table 1.1; as the temperature or pressure increases, the speed of sound increases (Halliday and Resnick 1997). Speed of sound in salt water can be calculated using the following formula.

C= 1449.2 + 4.6T – 0.055T2 + 0.00029T3 + (1.34 – 0.01T)(S-35) + 0.016z (13)

C denotes the speed of sound in salt water in m/s. Temperature (T) is measured in degrees Celsius. Salinity (s) of the salt water is measured in parts per thousand (ppt). The depth (z) of the water at which the sound is traveling is measured in meters. Table 1.1: Correlation between increase of a factor and the increase of the speed of sound (Halliday and Resnick 1997)

Increase in Factor Increase in Speed Temperature 1 °C 3 m/s

Pressure 100 m of depth 1.7 m/s Salinity 1 part per thousand (ppt) 1.3 m/s

3

Page 9: Acoustic Remote Sensing

Figure 1.1: Speed of sound in saltwater versus the temperature of the water

The greatest change in speed is due to the change in temperature. Temperature

is usually measured in degrees Celsius (°C), however, it can be measured in Kelvin (K) also. The Celsius and Kelvin scales have a one to one correlation, meaning a change of 1 °C will change the Kelvin temperature by 1 K. Temperature has a drastic affect on the speed of sound because the temperature of water can change as much as 30 °C (Halliday and Resnick 1997). The colder the temperature of water will produce a more drastic change in the velocity. Figure 1.1 shows the relation ship between the speed of sound in saltwater and temperature. Temperature of the water can vary due to the weather and the water depth. Figure 1.2 shows the correlation between water temperature and the depth of the water.

4

Page 10: Acoustic Remote Sensing

Figure 1.2: Composite of salinity, pressure, and temperature versus depth (Garrison 2002)

Reprinted with permission

Pressure in salt water is the amount of force exerted by water on the sound wave. The deeper underwater the sound wave travels, the higher the pressure. The equivalent change in depth to change the propagation speed is more than 1524 meters (Halliday and Resnick 1997). As shown in Figure 1.2, pressure has a linear correlation with the depth of the water. The last factor that affects the speed of sound is salinity. Salinity is defined to be the number of grams of dissolved matter per kilogram of seawater and is measured in parts per thousand (ppt) or practical salinity units (psu). The more common measure is ppt, however, salinity can be unitless. Conductivity can be use to measure salinity. These calculations are not based on the mass of dissolved material and produce a unitless value for salinity. Density is also affected by salinity. The salinity of seawater does not vary greatly from place to place as formalized by the law of constant proportions. Differences in salinity can be caused by rain and freshwater runoff, decreasing the salinity, and evaporation, increasing the salinity. The weathering of continents and deep-sea vents produce salt and inject it into the oceans. The addition of salt to the oceans is a very slow process, in the order of 100,000 years. The rate at which the salt is mixed in with the seawater is much faster in comparison, on the order of 1,000 years. Sea salt is a combination of mainly Chlorine (Cl) and Sodium (Na) (Halliday and Resnick 1997). With the advancement of technology, scientists no longer have to measure salinity by evaporating seawater and weighing the residual. A faster method to measure salinity was devised by measuring one component of dissolved material and using this value to approximate the total amount of salinity. Another method is to measure the chlorinity, amount of chlorine, bromine, and iodine in the water, through titration with silver nitrate. The chlorinity (C) can be related to the salinity (S) by the following equation. Even with the availability of other methods, measuring salinity by measuring the conductivity of the water is the most popular method.

5

Page 11: Acoustic Remote Sensing

S = 1.80655C

Speed of sound in water is important for the operation of the transducer. Knowing that temperature, pressure, and salinity affect speed, methods to obtain these factors will be needed to obtain an accurate speed. The device will be only 1 meter below the surface making the depth a constant. An average salinity value will be obtained since salinity is pretty consistent through out the ocean. We will use a constant 34 ppt. Finally, the speed will only be dependent on the temperature of the water. A temperature sensor will be implemented in the device to retrieve the measurement.

1.4 Physics of SONAR systems SOund NAvigation and Ranging (SONAR) systems are similar to RAdio Detecting And Ranging (RADAR) and electro-optical systems. Sonar systems are fundamentally different from radar and electro-optical systems in that the energy is transferred by acoustic waves propagating in water. There are two types of sonar systems: active sonar and passive sonar. The difference between the two types is where the sound wave originates. The production of the acoustic wave is part of the sonar system in active sonar systems. The system must convert electrical energy from the transmitter into acoustical energy. The conversion can be achieved by using a device called a transducer. There are three types of transducers. One type is a hydrophone, which can only act as a receiver. A transducer that can only transmit a sound wave is called a projector. This implementation can be seen in Figure 1.3. The final type is a combination of the previous two types. Typically referred to as a transducer, it can both transmit and receive acoustic signals. This implementation can be seen in Figure 1.4. Transducers are the most popular choice for sonar systems (Halliday and Resnick 1997). Figure 1.3: Active sonar system using a transmitter and receiver

6

Page 12: Acoustic Remote Sensing

Figure 1.4: Active sonar system using a transducer

Unlike active sonar systems, the source of the sound wave in passive sonar systems is the target. A passive sonar system is shown in Figure 1.5. There are two main categories of passive sources: broadband and narrowband sources. Acoustic energy is produced over a broad range of frequencies by broadband sources. In contrast, narrowband sources only generate acoustic energy over a small range of frequencies (Halliday and Resnick 1997). Figure 1.5: Passive sonar system using a transducer

The transducer output is measured as a Sound Pressure Level (SPL). The intensity of the transmitted acoustic wave will represented as a function of distance traveled. The standard range for measuring SPLs is one meter from the source of the acoustic wave (Halliday and Resnick 1997). Sonar performance can be decreased by the introduction of noise. The ocean has numerous noise sources, however, only a few types produce the majority of the noise. Ambient noise, noise with no particular source or direction, represents the largest portion of noise present in the ocean. There are three main sources of ambient noise: surface activity, water traffic, and marine life. In local areas, the noise level is the same everywhere; therefore the SPL will be the same everywhere. Due to this trait of ambient noise, it is specified as a particular SPL (Halliday and Resnick 1997). Action occurring on the surface of the ocean, i.e., waves, is the most obvious source of ambient noise. The larger the wave, the greater amount of ambient noise is produced. Wind directly affects the surface state of the ocean by the production of waves. The sea state, a number between 0 and 9, is used to classify the condition of ocean’s surface. The surface activity can vary depending on the time of day, the season, and other conditions. Another way to predict the surface condition is by using

7

Page 13: Acoustic Remote Sensing

the Beaufort Wind Scale. It is a number ranging from 0 to 12 used to measure constant wind speed. The greater the wind speed produces greater surface action generating a greater amount of ambient noise. The frequency of the noise produced from the surface state is usually larger than 300 Hz (Halliday and Resnick 1997).

The second main contribution to ambient noise is water traffic, the movement of ships and boats in an area. An area will experience higher amounts of ambient noise if numerous ships travel through the area. Noise produced in this manner will a lower frequency than sea state noise, less than 300 Hz. Geographical considerations, such as busy harbors and connecting waterways, can help estimate the amount of water traffic for specific regions (Halliday and Resnick 1997). The final possible producer of ambient noise is marine life. This type of ambient noise is usually found in shallow tropical or semi-tropical waters. Since the source of this sound is living, it is highly unpredictable and has a wide variety of sources. The sources range from small biologics, i.e., the snapping shrimp, to the massive, such as dolphins and whales. Since the effects of biologics are only known once one is in the environment, it is impossible to estimate their contribution to ambient noise (Halliday and Resnick 1997). Transducers have to try and filter through the ambient noise to retrieve the true signal. By implementing a passive sonar system with a narrowband source to receive signals, the narrow beam width will allow more rejection of noise because ambient noise comes from all directions. This can be described mathematically with a logarithmic term called the directivity index (DI), 10 log (Gain). DI can only be used in sonar with the reception of energy. The SPL already factors in the gain achieved in transmission of acoustic waves (Halliday and Resnick 1997). For a transducer to detect the target, the amount of energy received by the transducer must exceed the noise level by a threshold. Signal-to-Noise Ratio (SNR) is the logarithmic representation of the ratio of signal-to-noise. The Detection Threshold (DT) is the minimum SNR required for detection. Detection will generally occur when SNR is greater than DT, about fifty percent of the time (Halliday and Resnick 1997). During transmission and reception of the acoustic wave, energy is lost. This lost acoustic energy is called transmission loss (TL). The energy loss is due to attenuation, energy spreading, and various other effects (Halliday and Resnick 1997). For an active sonar system, there is a two-way transmission loss. The target reflects energy. The reflection is called the target strength, (TS). The target strength is the source level after reflection. Target size, shape, and surface material affect the value of the target strength (Halliday and Resnick 1997).

Our device will be an active sonar system. Ultrasonic transducer, having a

frequency greater than 20 KHz, was chosen because it was capable of both transmitting and receiving an acoustic signal. We will use the transducer to calculate the distance

8

Page 14: Acoustic Remote Sensing

between the device and the target, a passing boat. Along with the speed of sound in salt water (C), the following equations will be used to calculate the distance. The Time of Flight (ToF) will be dependent on the Time of Echo (ToE) and the Time of Transmission (ToT).

ToF = ToE – ToT

Distance of Object (D) = *2

ToF C

1.5 Sound Vs. Other Options The frequency range chosen is in ultrasonic band. Ultrasonic means above the hearing range. The average normal hearing range for human is about 20 Hz to 20000 Hz, so anything above 20000 Hz is considered ultrasonic. Many animals navigate by ultrasonic such as bats, and some animals use the infrasonic range, below normal human hearing range, such as whales. Some animals use infrared to navigate and hunt such as snakes. Many methods are available for measuring distance. Most popular methods use optics, sound, and Radio Frequency (RF). Each will offer an advantage in one area and usually will have a disadvantage in other areas. Optics is great for air, and distant measurement. This probably can be credited to the invention of LASER, Light Amplification by Stimulated Emission of Radiation. Laser is different from other from other kinds of light because it is coherent. It contains only one wavelength, Lasers are especially great for distant measurement because it has zero divergent, in a plain words, it travels in a straight line. Other light sources, for example, like from a light bulb will spread, and a couple of feet away, the light will have about 3 feet radius of spread. Laser is also pretty unique in terms of its quality, as it is rarely naturally produced. The flaw with optics is that it is much more complex mechanical alignment to work with. If the mechanical alignments are not correct, the performance of the device will be greatly compromised. For example, if the Infrared transmitter-receiver pair is slightly misaligned, the measurements might not even come out at all. With the precise mechanical alignment is necessary, optics already has its complications. Therefore, the cost of developing an optics system is also very high due to precise mechanical system. A laser stand can cost from few hundred dollars to thousands of dollars, according to THORLABS’ catalog. The most important reason to avoid optics would come from its environment it will be in. This device will be submerged in the water, and it is required to be discrete. Most important reason would be that if the water is clear, there should not be many problems, but if the water is not clear, the range and integrity of the system will be reduced significantly. This device will be in the intercostals areas. Naturally, sand and mud is present, and if a boat pass by, it can stir up the sediments. That is very important since what we are going to measure is the distance from the device to the boat. Optics is not our choice.

9

Page 15: Acoustic Remote Sensing

Radio Frequency (RF) has been employed for many years for this purpose. This system has been proven effective, and reliable. One of the well-known derivatives of this system is RADAR, RAdio Detection And Ranging. The principal of operation is still the same as our sonar, and optics ranging system. It still uses the known velocity, and time of flight to acquire the distance. The frequency of transmission, and the frequency of reception, a shift in frequency, can also be used to determine the speed of the target. As in above systems including sonar, the target is characterized by its signature, and signal strength. The United States has the capability to identify the target detection as what type of airplane for example. This system is very reliable, and very effective even though it is a World War II technology. The radar system fits into our project in one aspect is that it is discrete, not many people has a high frequency radar detector. Well, why didn’t we use it? Probably a better question is, why does the Navy not use it for submarine warfare? Why do they use sonar? From our research, and knowledge, RF has such a high attenuation in water. The chart below will show how much water attenuates RF transmission. Figure 1.6: Attenuation of RF signal in water vs. frequency

Printed with permission from Naval Research Laboratory, Transmission Technology Branch Website

The vertical axis of this graph is in decibels/foot, and the horizontal axis is for frequency of transmission in MHz. In order that the RF to be useful for target detection, it will have to be in pretty high frequency range in order of few megahertz. Let’s pick the frequency to be 1 megahertz. The attenuation is already at 10 decibels per foot. Considering that decibel scale is logarithmic, this attenuation will then increase exponentially as the transmission frequency increases. Back to our example, the

10

Page 16: Acoustic Remote Sensing

number will work out to be about 31.6% of the original transmission power. That is only at 1 foot away from the transmitter. Our targeted range is to be at least 50 feet. Obviously to obtain that range requires a tremendous amount power of transmission, which will translate to a large amount of electrical power. Our target goal for stand-by time is a minimum of 24 hours. The graph answered the questions we imposed before. RF is ineffective in water.

Sonar is now our choice, and more likely our only choice for the ranging system. The most significant advantage of using sonar is that sound has excellent propagation property in water. Sound travels even faster and better is solid, but we will not be considering that case. The speed of sound in the air is about 343 meter per second while the speed of sound in water is about 1500 meter per second. Sound is a longitudinal wave. It creates pressure difference when it transmits. Conceptually, the closer the molecules, the better the transmission as the sound energy can be transferred to the next molecule easier. That is why you can hear a train coming from miles away by putting your ear onto the track. Another physics equation that cannot be ignored is

Velocity = Frequency X Wavelength

One property difference between sound in water, and sound in air, is that the wavelength will be longer.

1.6 Transducers 1.6.1 Introduction

Underwater transducers provide the essential link between power amplifiers and acoustic pressure outputs. For transceiver types, they also are the link between the received acoustic pressure and the receiver or pre-amplifier. Transducers involve a mixture of acoustical, electrical and mechanical properties such as beam pattern, impedance, corrosion resistance and weight. All of these properties involve a combination of electrical system design, mechanical engineering, chemical engineering and physics. In addition to these combinations of discipline there is the added concern of cost, specified requirements, and trade off. All of these things make choosing the best transducer for a specific application a challenging task (Halliday 1997) .

Underwater acoustic signals can be generated by converting electronic signals

into mechanical energy. This mechanical energy is then transmitted into the water via the transducer as a sound wave. Sound waves travel much quicker in water than in air because water is denser. Sound travels approximately 1500 meters per second in water, which is about five times faster than it would travel in air (“About Transducers” 2000) .

11

Page 17: Acoustic Remote Sensing

A transducer is an electromechanical device can either convert mechanical forces and displacements into electromagnetic energy, or convert electromagnetic energy into mechanical energy. A transducer converts electrical energy to mechanical energy, in which it is called an actuator, and converts mechanical energy to electrical energy and called a sensor. The main principle behind these devices is the piezoelectric effect, consisting of the generation of a change in electric field in the presence of strain in crystals, electrostriction, and magnetostriction. Changes in the dimension of certain materials lead to a change in their electrical or magnetic properties. Transducers convert energy through the coupling of a magnetic field. In a mechanical system, energy loss can occur because of the heat developed as a consequence of friction, while in an electrical system losses occur because of resistance. Below is a figure depicting the flow of energy from the electrical to the mechanical system, accounting for various losses (Rizzoni 2001) . Figure 1.7: Energy conversion diagram with related losses

Electrical System Coupling Field Mechanical System

Electrical EnergyInput

Useful MechanicalEnergy

Mechanical EnergyInput

Useful ElectricalEnergy

Friction Losses Resistive Losses Magnetic CoreLosses

Adapted from Principles of Electrical Engineering e-Text

As seen in Figure 1.7, when electrical energy is converted into useful mechanical

energy, or vice-versa, there are losses due to friction, resistance, and magnetic cores. All of these losses are in the form of heat loss. You want to avoid as much heat loss as possible because it is purely wasted energy.

The misconception of our project in comparison to the previous generation is that

majority of people think that we can just make the package waterproof, and drop it in the water, and it will work since sound propagates well in water. Though that sounds like it should work, and we wish it were that way, it is an absolute false assumption. Again, laws of physics are coming to work. If we carefully consider the property of water and air, especially viscosity, we will see that water has much higher viscosity than air. This translates to a simple example. If you wave your hand in the air, it does not take much

12

Page 18: Acoustic Remote Sensing

work since there is almost no resistance, but if you are to wave your hand in water at the same speed, it will take much more energy to do so. The transducers work by converting electrical energy (more appropriately signal) to mechanical energy (sound wave). Physics provide law of conservation of energy; all energy will be conserved if looked upon overall system. In the process of converting electrical energy to mechanical energy, the transducer will generate heat. Heat is the least useful form of energy, and is unwanted for our project. The output (sound), and the input (electrical current) would never reach a hundred percents efficiency. In water, more mechanical energy is needed. Therefore, more electrical energy will also be needed. For one, the air ultrasonic transducers would never have enough mechanical force to transmit loud enough in water. If we are to use air transmitter in water, we probably have to put so much current to it that the transmitter will just simply fail. 1.6.2 Transducer Applications

In military applications, underwater acoustic transducers are an important part of many naval sonar systems. Applications include anti-submarine warfare, torpedo countermeasures, mine hunting sonar systems, and communication links. Some commercial applications include oceanographic research establishments and the offshore oil industry. They employ underwater transducers for sub-bottom profiling, side-scan sonar sea floor mapping, ship tracking, and acoustic speedometers. The fishing industry utilizes forward-looking active transducers for spotting schools of fish. They use dual and split beam transducers for counting in fish population studies, detecting the sound intensity of rain on a water surface, and also for emulating the mating vocalizations of marine mammals (Intro to Ultrasonic 2000) . 1.6.3 Transducer Characteristics

As said before, transducers are an integral part of acoustic systems. Their parameters can be obtained from the overall system requirements. A general knowledge of these parameters and their relationships will make transducer choosing a little less complicated. The first consideration is the task of the transducer: projector for transmitting, hydrophone for receiving, or transducer for both transmitting and receiving (Kuntsal 1999) .

The transducer is a very essential component. The reason is because it will

determine the circuit configuration, and the most important signal will come from it, a target detection, and range. Therefore, picking a transducer is very important. The transducers have few properties that we should be considering. As a good engineering practice, we will do as we have done above, we will again compare the specifications to our environment of application and requirements. Few kinds of ultrasonic transducers are available. Transmitter – receiver pair (Tx-Rx), and transducer are to main types for physical consideration. The main distinction is that the transducers are transmitter and receiver built in to one package rather than two. Transducers are chosen for our project because we do not have to do the precise physical alignment, and they are compact. Tx-Rx requires a precise physical alignment. One advantage for Tx-Rx pair is that the

13

Page 19: Acoustic Remote Sensing

receiver tends to get fewer disturbances from the transducer when detecting a target because of the physical separation. Therefore, Tx-Rx pair usually has slightly more sensitivity than transducers. A requirement that cannot be neglected is that our transducer must be waterproof and made for underwater. Other physical characters are operating depth, operating temperature range, size, weight, and shape. Our operating depth should not be more than 10 feet below the surface, so any transducers made for under water would suffice this requirement. The temperature range is not really an important issue, since Florida is pretty warm. So if it operate from –10 degree Celsius up to 45 degree Celsius, the sensor should be fine. The size, weight, and shape would just have to be small because this device is to be one-man carry.

As mentioned above, the transducer converts mechanical energy to electrical

energy. Therefore, it will have a mechanical characteristics, and electrical characteristics. The mechanical characteristics would be the receiving sensitivity, transmission level (actually these two belong to both categories), Directivity Index, frequency of transmission, and propagation pattern. The electrical characteristics are operating voltage, operating current, signal input type, signal output type, impedance, and input power at transmission. Some manufacturers will provide the efficiency of the transducer, which is how effective it converts electrical energy to sound energy. We have found that most transducer would not even reach 30 percent. MEMS transducers, however, are very efficient as they are made from semiconductors. At this time MEMS transducers are mostly prototypes, and expensive. MEMS would have been ideal, but due to those factors, we cannot use MEMS transducers for our project. 1.6.4 Mechanical Characteristics of the Transducer The mechanical characters focus on sound wave properties from the transducers. Many other characters are neglected due to their irrelevance, and moreover, the manufacturers do not provide them for same reason. First one to be considered is the receiving sensitivity. This is usually given in decibel scale, which is calculated from volt per unit pressure (generally micro Pascal, uPa). From the unit, it is how much the transducer converts sound energy back to electrical energy. Therefore, the decibel unit is negative, since the ratio of voltage to microPascal is less than one. This should also be noted that the less negative, the more sensitive it is. If the transducer A has sensitivity of –18 dB, and transducer B has sensitivity of –40 dB, the transducer A will be more sensitive. This is essential because if the voltage given out from transducer A is, say, 30 times more than B, the transducer A would require less amplification. First of all, the amplification circuit from A will require less power than B. Second of all, and most important, the noise floor has to be considered.

These transducers most likely will give output in order of millivolts. In general,

noise is in about the same order, in millivolts. Noise will add to the output from the transducer. Say the noise is about 0.8 mV, the signal from A is about 30 mV, and the signal from B is 5 mV. It is quite obvious that if the output to target detection requires to be at least 100 mV, A would need about 3 times amplification while B would need about 20 times amplification. The noise in A would be amplified by factor of 3, therefore yields

14

Page 20: Acoustic Remote Sensing

0.8 x 3 = 2.4 mV while transducer B would yield 0.8 x 20 = 16 mV. Obviously this is not desirable as it can introduce false target detection, but some signal analysis can eliminate that. The detail explanation of signal analysis will be later explained. From the above example, the overall circuit, especially at interface between microcontroller and transducer must have a low Signal-to-Noise Ratio (SNR). This is also measured in decibels. Bottom line, more sensitivity will increase the range, and reliability.

The second mechanical output consideration is transmission level. This refers to the sound pressure level output, and it is also measured in decibels. Decibel scale is a logarithmic scale, and usually calculated from a ratio. In the cast of transmission level, this ratio is the inverse of receiving sensitivity, microPascal per unit volt, and the decibel number is always positive. By inspecting the ratio, it simply interprets how much sound pressure or loudness it can create given a certain voltage input. Intuitively, we would choose the one that is the loudest, highest dB, as sound level will decrease with distance. Since the receiver generates the voltage output from sound pressure level, we want that voltage to be as high as possible. One way to achieve that has been mentioned, by selecting high sensitivity transducer. Another way to obtain that is to transmit louder. The reason that these are desirable is as above, to get output above from noise floor as high as possible. We will attempt to transmit the highest intensity as possible in order to get the furthest the range from the transducer. It must be high enough for the wave to travel to the object of interest and back to the transducer. We hope to achieve a transmitting intensity of at least 150 dB.

Just as important is the transmitting sensitivity is the receiving performance of a

transducer. This is usually expressed as the open circuit voltage receiving sensitivity (OCV) (Kuntsal 1999) . It is the rms voltage output at the open circuit terminals of a transducer, in response to pressure amplitude of 1 µPa. The less negative the OCV of a transducer, the higher the output voltage for a given pressure level (Kuntsal 1999) . Of course our maximum ranging distance is also dependent on the sensitivity. Our system can only distinguish valid received signals beyond a certain threshold voltage.

As the seen in Figure 1.8, at higher frequency, less noise is present in the

environment. Again, we are optimizing the system for the least amount of false target. By operating at higher frequency band, the transducer compromises the effective range of operation, but it will have more imaging resolution. As a consensus between the group members, and the sponsor, we will operate at from 40 KHz to 50 KHz. This range of frequency does not have much natural noise in it, and our target minimum range of 50 feet can be achieve with reasonable effort. More importantly, our sponsor plans to have an imaging system eventually, so the transducer would need to have good resolution for image processing. Another consideration is the beam pattern. The beam pattern shows the relative amplitude of the acoustic pressure as a function of direction relative to the transducer. You can have either omni directional (spherical pattern), or unidirectional (directional beam). For our application we are choosing to use a unidirectional transducer in order to aim our device in a particular direction (Kuntsal 1999) .

15

Page 21: Acoustic Remote Sensing

In addition to beam pattern, the electro-acoustic efficiency of a projector is

important. The efficiency is defined as the ratio of the acoustic power generated to the total electrical power input. Efficiency varies with frequency and expressed as percentage. This efficiency can be maximized with techniques such as impedance matching and frequency tuning. Ideally we would like to have no energy loss, but this is impossible to obtain because of physical conditions (Kuntsal 1999) .

Directivity index and propagation pattern are actually very close to each other.

The word Directivity index is pretty self-explanatory. It is how direct is transducer transmitting the sound. Therefore, DI is very closely related to propagation pattern. Directivity index is given in decibels, but it is not a popular specification to give. The propagation pattern is more popularly given. This is given in +/- some degree quantity. This means how much it spreads from the aim axis to the –3 dB point. Sometime, the propagation pattern will simply just be a graph, which is very convenient. For our purposes, we are using directional transducer rather than omni-directional transducer. One of the specifications from our sponsor is that this device would aim at one direction. So the answer is quite obvious for what we are going to use.

The next consideration is the operating frequency. The transducer’s operating

frequency is usually the resonant frequency at which they provide the highest acoustic output. Most transducers, especially for underwater applications, operate in the ultrasonic range (above 20kHz). The operating frequency is important for maximum range, resolution, and noise considerations. A further range can be obtained from lower frequencies because the attenuation of sound waves in water increases with frequency. A better resolution can be obtained however with higher frequencies. By operating at higher frequency also provides another advantage. Natural noises are present everywhere, and especially near the coast. Most of the noises come from wind and surf. The intensity of ambient noise in the ocean can be as high as 20dB around the frequency range of 20 kHz. The intensity of decreases with increasing frequency, and is small enough to disregard about 40kHz (Kuntsal 1999) . We would like to obtain an underwater transducer that operates in the 45kHz to 50kHz range (Kuntsal 1999) . In addition to the parameters described above, consideration of cable type, connector type, and mounting scheme may also be important. These characteristics may not be much of a factor for our project. We know that our cable length will be very short. Cable length is usually a consideration for marine applications on boats where the transducer is mounted at large distances from the ranging board. The mounting scheme of the transducer will most likely not be much of a problem for us either. We will be designing a box in order to accommodate the transducer instead of installing the transducer on a preexisting surface. Other specific characteristics that will be very important to our device are size, weight, and ability to withstand environmental conditions. Because our device needs to be small enough and light enough to be

16

Page 22: Acoustic Remote Sensing

carried by a single person, we obviously have restrictions on size and weight. Our ideal transducer will have a diameter of less than 50mm and weigh less than 250 grams. Also we need a transducer that is specifically designed for operation in salt water so that it can withstand corrosion and shock vibration cause by water turbulence and marine life. 1.6.5 Electrical Characteristics

There are many electrical characteristics of transducers, however we are only interested in just a few when it comes to transducer selection for our project. One of the characteristics that is highly important is the frequency response of the transducer. A transducer is most efficient when excited to its resonant frequency. At the resonant frequency the transducer is converting as much mechanical energy as possible with as little loss as possible (Rizzoni 2001) . This is an important characteristic because when operating at this frequency the transducer shall transmit its highest intensity, its furthest distance, and be as efficient as possible with minimum heat loss.

Another important characteristic is complex impedance. An RLC circuit can

represent a transducer’s impedance. Its impedance is also important for its efficiency because when the impedance of the driver circuit is matched to the impedance of the transducer, maximum power transfer is obtained. If the complex impedance of the transducer is matched with its complex conjugate, the imaginary part of the complex impedance can be eliminated leaving only real resistive impedance that does not have any frequency or phase effects (Underwater 2000) .

An additional electrical characteristic is maximum input power. Because our

stand-by power supply needs to last a minimum of twenty-four hours, low power consumption is a big concern. We need to find a transducer that has as little power consumption as possible.

Along with power consumption, peak transmission voltage and current is also a

large concern. The previous prototype, Submersible Watchdog, used Polaroid’s 9000 transducer that has a maximum peak voltage of 400 V and a current of 2A. Although these demands are only present for a very short duration, they still put a major drain on the battery as well as possibly conflict with other components in the circuit if precautions are not taken.

One last electrical characteristic that is of importance to us is the input and output

type. We plan on using either a sine or square wave pulse repetition in order to drive the transducer. Therefore, we must make sure that the transducer will respond properly to this kind of input. We plan on sending either 12 or 16 pulses at the same frequency of the transducer’s operating frequency with a burst width of 0.267ms to 0.356ms. The output of the transducer is also of concern. It can either be digital or analog. We also need to determine how much voltage the transducer will output upon signal reception. Most transducers transmit voltages on the order of millivolts upon echo reception. This voltage is proportional to the time of flight of the echo. The further the echo travels, the

17

Page 23: Acoustic Remote Sensing

more attenuation of intensity, thus producing a smaller input intensity to the sensor. We shall need an amplifier that can adjust its gain with time in order to account for this decrease in voltage. The amplified signal will then be either fed directly into the CCP port of the PIC 16F877, or will pass through a Schmitt-trigger with a set threshold before reaching the CCP port. This is discussed in further detail in the section 6.1.3.

1.6.6 Transducer Types

There are many different types of transducers in production. One type of transducer is a contact transducer. These are single element longitudinal wave transducers. These transducers are rugged, durable, and highly wear resistant. They are used in direct contact for testing of metals, composites and plastics. Our transducer will be in direct contact with saltwater which promotes corrosion. Contact transducers must be in direct contact with a solid surface, therefore they do not meet our requirements. Applications of contact transducers include material inspection, thickness gauging, and detection of delamations (Ultrasonic 1999) .

Another type of transducer is a dual transducer. This type consists of two crystal

elements housed in the same casing. One transmits while the other receives. This Tx-Rx pair comes pre-aligned from the factory with fairly good precision. This would eliminate the complicated physical alignment of two individual transducers. Also, this design allows for good near surface resolution because there is no settling time involved, and there is reduced back scattering noise. However, these transducers are usually designed for applications in air and are not very rugged. So this transducer will not fit our application either. Some applications of dual transducers are wall thickness measurement crack detection in certain materials (Intro to Ultrasonic 2000) .

Immersion Transducers are another type of transducer designed specifically for

ultrasonic underwater applications. The transducer can be either partially or fully submersed in water. Some are designed for freshwater while others are specifically manufactured for use in salt water. Immersion provides a means of uniform coupling so that a single transducer can efficiently convert electric energy into mechanical energy as well as the converse. A focused immersion transducer can improve sensitivity and axial resolution by concentrating the sound energy in a small area. Applications include time of flight detection, amplitude based imaging, and high-speed flaw detection in piping (Ultrasonic 1999) . This is the exact type of transducer that we need for the Acoustic Remote Sensing project.

There are also transducers called Angle Beam Transducers and Wedges. These

are used to introduce a refracted shear wave into the test material. Advantages for using this type include improved delectability and interchangeable designs. Applications include inspection of flaws in and around welded areas. As you can tell from the applications this transducer would not be a good choice (Ultrasonic 1999) .

Another type is a delay line transducer, which provides versatility with a variety of

replaceable options. They use single element videoscan with a removable delay line,

18

Page 24: Acoustic Remote Sensing

protective membrane, and protective wear cap. These make a single transducer effective for a wide range of applications. They are designed for use in applications such as high precision thickness gauging of thin materials and delamination checks in composite materials (Intro to Ultrasonic 2000) . These transducers require surface contact also and would not be useful for our design purpose.

Also, there are transducers called high frequency transducers. These are

manufactured for immersion in liquids and have an operating frequency of 20 MHz or higher. This operating frequency is much too high for long-range underwater detection in our design. Signals with high frequencies have a very high attenuation and would only be useful for close range applications. A typical use of this type of transducer would be for close range detection. The high frequency allows for good resolution for imaging. Applications for high frequency transducers include materials analysis and microscopy (Ultrasonic 1999) . 1.6.7 Transducer Comparisons

The previous designers used Polaroid’s 9000 transducer and 6500 ranging module. The 9000 transducer was not specifically made for underwater applications, however they tried to implement it into an underwater design. They tried to match the impedance of the transducer, tune the frequency, and even increase the transmitting intensity and receiving sensitivity. However, all these attempts failed to produce good enough results. = \

Polaroid’s 6500 ranging module was originally designed to work with Polaroid’s

6000 model transducer. In order to adapt the ranging module to work with a 9000 series transducer, physical modifications are needed. The 9000 transducer operates at a different impedance and frequency, which require impedance matching and frequency tuning. These tasks can be done by changing the values of a few capacitors and by adding a resistor or two to the 6500 ranging module circuit. We have chosen not to continue with the rigorous efforts of the previous group in attempting to make this transducer work. Instead we have considered other transducers that are made specifically for underwater applications.

Suggestions from the designers of the previous prototype included: increase the

transmitting power from 108 dB to between 180 to 200 dB, increase the receiving sensitivity from –78 dB to between –150 to –175 dB, retain the analog to digital conversion for MCU interfacing and utilize a transducer designed for underwater use. We shall heed to all of these suggestions. We are going to attempt to acquire a transducer that was specifically designed for salt-water applications, and we will design a driving board that theoretically has enough transmitting power and receiving sensitivity as needed. Also, we are using a different microcontroller that utilizes a CCP port to directly interface with the analog output of the transducer. This will eliminate the digital chip for the driver board as was used on the 6500 ranging module. Depending on our

19

Page 25: Acoustic Remote Sensing

transducer selection we may or may not need an impedance matching or frequency tuning circuit. If we do need to design one, we will design it such that it will be easily adjustable to allow for fine-tuning of our transducer. This will also allow for replacement of the transducer if we choose to implement a different model.

While searching for underwater transducers, we came across Hexamite.com.

Their underwater ultrasonic transducers sound great for our system. There are only two downsides to their transducers. One reason is that this company is located in Australia and shipping quotes that we have gotten for shipping the products have been just as much as each transducer, around $70. Another turn off is that they only manufacture underwater sensors that operate at 23 kHz, 144 kHz, 170 kHz, and 220 kHz. The closest to our desired range of 45 kHz to 50 kHz, would be the 23kHz HE123TR (HE123TR 2001) .

The HE123TR made by Hexamite is designed for underwater applications.

It transmits a 155dB signal with a beam angle of ±35 degrees at 23.5 kHz. Its receiving sensitivity level is -30db/V/microbar. It can range from 0 to 1000m transceiver to transceiver operation, or echo from 0.1m to 500m. Hexamite’s web site claims that with reasonable efforts ranges of kilometers can be achieved. The HE123 series sensor is protected by a heavy-duty chromed brass housing with 1/8" or 3mm thick walls. This sensor can withstand submersion in water or seawater to a depth over 300m. Their price is around $80. They also make a signal conditioner, which has analog and digital outputs, as well as automated variable gain for echo reception. But the conditioner costs $299 (HE123TR 2001) . Figure 1.10: Hexamite’s HE123TR transducer

Reprinted with permission from Hexamite

Other transducers we took into consideration were Reson Inc.’s TC2084 and

TC2116. The TC2084 has an operating frequency of 33kHz and is used for underwater echo ranging for up to 700m. It has a transmitting intensity of 168 dB and a receiving sensitivity of –178 dB. The down side to this transducer is that it weighs 5 kg and also has a maximum input power of 1000W.

20

Page 26: Acoustic Remote Sensing

The TC2116 is a broadband transducer that can operate from 40 kHz to 100 kHz. It has a transmitting intensity of 172 dB and a receiving sensitivity of –177 dB. But, it is the same size as the TC2084 and also has a maximum input power of 1000W (Reson n.d.) . Figure 1.11: Reson’sTC2084 and TC2116 transducer

Reprinted with permission from Reson, Inc.

Other possible transducers are ones that are made for fish finders. Some major manufacturers of these types of transducers are Garmin, Furuno, and Raytheon Marine. Here is a table for comparison of transducers under consideration.

21

Page 27: Acoustic Remote Sensing

Table 1.2: Transducer comparison table

Mar

ine

Acou

stic

s Li

mite

d

6000

&

1000

0

133

/ -1

75 d

B

-

Larg

e R

ange

Mul

tiple

freq

.

$500

0 to

$1

0000

Lu

bell

LL-1

424

193

/ - d

B

1000

W

Sign

al

depe

nden

t

200

– 90

00 H

z

$525

0

Inte

rnat

iona

l Tr

ansd

ucer

C

orp.

ITC

-300

1

-

2000

W

-

17.5

kH

z

$500

0 to

$1

0000

R

eson

TC 2

024

173

/ -1

87 d

B

450

W

-

200

kHz

$582

R

eson

TC 2

127

181/

-187

dB

150

W

-

600

kHz

$877

R

eson

TC 2

111

163

/ -19

0 dB

50 W

-

200

kHz

$340

Man

ufac

ture

r

Mod

el

Tran

s / R

ec

Sens

itivi

ty

Pow

er

Con

sum

ptio

n

Max

Dis

t.

Ope

ratin

g Fr

eq

Cos

t

22

Page 28: Acoustic Remote Sensing

R

eson

TC21

15

168

/ -17

8 dB

1000

W

-

30 k

Hz

$1

600

Res

on

TC21

16

172

/ -17

7 dB

1000

W

-

50 k

Hz

$160

0

Res

on

TC 2

084

168

/ -17

8 dB

1000

W

-

33 k

Hz

$160

0

Po

laro

id

9000

108

/ -87

dB

25 W

-

45 k

Hz

$55

Hex

amite

HE1

23TR

155

/ -30

dB

Low

500

m

23 k

Hz

$80

Man

ufac

ture

r

Mod

el

Tran

s / R

ec

Sens

itivi

ty

Pow

er

Con

sum

ptio

n

Max

Dis

t.

Ope

ratin

g Fr

eq

Cos

t

Adapted from Submersible Watchdog documentation

23

Page 29: Acoustic Remote Sensing

After looking at Table 1.2 and searching the World Wide Web, we have found that Hexamite’s HE123TR is by for the best choice of transducer for ease of system integration, cost, and all the other table comparisons. The HE123TR has the following specifications: Table 1.3: HE123TR parameters

Reprinted with permission from Hexamite Table 1.4: HE123TR housing specifications

Parameters Values Units Operating Frequency 23.5 kHz

Input Voltage 26 (max) Volts (RMS)Output (SPL) @20V 155 DB Receive (Sensitivity) -30 dB/V/Ubar

Impedance 300 Ohm Beam Angle ±35 degrees Bandwidth 1 kHz

Settling Time 8 mS Temperature Table 1 -40 to 100 °C

Housing Description Units Material Type Brass

Protection NEMA 12 (IP68) Diameter 1.05 In Diameter 27 mm Length 1.6 In Length 41 mm

Leads Length (attached) 0.2 m Panel Nut Threads ¾" - 20 NPT

Reprinted with permission from Hexamite

24

Page 30: Acoustic Remote Sensing

Figure 1.12: Sample schematic for interfacing HE123TR transducer with Microchip’s PIC controller

Reprinted with permission from Hexamite

Figure 1.12 was obtained from Hexamite’s website. It shows a suggested interfa

F,

ce with the HE2XXTR transducer with Microchip’s PIC controller. In order toobtain the 23 kHz of oscillation you have to change two capacitors, C1 and C2 to 4nand two resistors, R1 to 3 kΩ and R2 to 5kΩ. Resistor R3 needs to be changed to around 50 kΩ in order to set the level for the analog comparator (HE123TR 2001) .

25

Page 31: Acoustic Remote Sensing

CHAPTER 2

DEVICE COMPONENTS

This chapter will discuss the brain of our device, the microcontroller. The topics that will be discussed include the basics behind a microcontroller, why we need a microcontroller, how we chose our microcontroller, and details on the PIC16F877. It will also be explain how the microcontroller will be interfaced with other components in the device. Other essential components of the device will also be presented. This information will cover the features of the system as a whole and the challenges that we faced in choosing the correct components.

26

Page 32: Acoustic Remote Sensing

2.1 The Microcontroller 2.1.1 Introduction This is obviously one of the main and crucial components of the project. The calculation of the distance, the control of the sonar ping, the data interface to the CompactFlash, and calibration will be done through this processor. To fit all these necessary functions, we have mainly considered Digital Signal Processor (DSP), Programmable Integrated Circuit (PIC), Field Programmable Gate Arrays (FPGA), and Application Specific Integrated Circuits (ASIC).

Digital Signal Processors are ideal for our project. DSP provides functionality of

signal analysis, control, data interface, and calculations. In general, DSP chips are very powerful and fast. They provide the necessary built-in signal processing functions such as Fast Fourier Transform, Auto-correlation, and filtering. DSP also has the capability to adapt to environments, also known as “Adaptive DSP”. For example, the filter coefficients can change during operation to provide the optimum signal transfer, while analog filters cannot provide this ability. Fast Fourier Transform, or FFT, is also great for determining the fundamental frequency. We would need this because our signal would transmit at about 45 kHz, and it will bounce back at a magnitude fraction of the outgoing signal plus noise. The noise component is unavoidable, and can produce unwanted results. What FFT can do is it can identify that the transmitted signal is at 45 kHz, and the echoed signal still has the fundamental frequency of 45 kHz. This can be seen in Figure 2.1.

Figure 2.1: Sinusoidal signal sin(45000t)+random noise

27

Page 33: Acoustic Remote Sensing

Figure 2.2: 1024 points FFT of the signal sin(45000t) + noise, note the positive and negative frequency components the 512th sample is the zero frequency

The second essential function is auto-correlation function. By the name, this function compares the similarities between two signals using statistics. This will verify that the transmitted and echo signals are similar to some degree, and hopefully this will be to the high degree. This technique is also used in returning radar signal verification.

The filtering of a signal can also be done on DSP chip. Infinite Impulse Response and Finite Impulse Response filters are two categories of DSP filters. The coefficients of these filters will determine the type of filter, i.e. Butterworth, Elliptical, etc. From researching, FIR is considered due to stability of this filter system because of the finite impulse response. The order of filter can also be easily change by changing the algorithm. The advantages over analog filters are obvious. First, component values do not change with time or environment, since DSP filters are purely algorithm. Second, the changes in DSP filters are done through algorithm, while analog filters require the change of component values and sometime, the circuit configuration. Third, analog filters cannot provide the “adaptive” capability.

DSP also offers control capability. It can control digital or analog systems. To control analog systems, it must employ digital-to-analog converter(s), and to obtain information from analog signal, this will require analog-to-digital converter. This provides us with almost unlimited control. DSP also provides serial and parallel interface to other components or processors. This would provide excellent interface to the CompactFlash.

28

Page 34: Acoustic Remote Sensing

We looked at the main manufacturers of DSP’s, Analog Devices Incorporated, Texas Instruments, and Motorola. All provided us with good resources for research. Analog Devices’ technical staff suggested us with SHARC 32-bit floating point DSP line, specifically, ADSP-21065L and ADSP-21061. ADSP-21065L has low voltage supply at 3.3 V. This SHARC DSP processor provides 66 Million Instructions Per Second, MIPS, and has 2 serial ports, and 544 Kbits onboard SRAM. Indeed, this is a very powerful processor, it can do 198 MFLOPS at 32-bit, just about 198 millions full word floating point multiplication operations in a second. ADSP-21061 also provides a very close specification to that. Both provide built in FFT algorithm, and easy additional RAM interface according to Analog Devices. Both chips can be entirely programmed in C Language (C). Traditionally, DSP had to be programmed partially in C and partially manufacturer’s assembly. Figure 2.3: Analog Devices ADSP-21065L DSP Processors

Texas Instruments suggested us with their popular TMS320C6000 line, also known as C6000 series. The representative pointed out TMS320C6711. T his DSP chip has 100 and 150 MHz clock rate, and provides 600 MFLOPS, and 900 MFLOPS respectively. It also has Institute of Electrical and Electronics Engineers (IEEE) 1149.1JTAG standard debugging interface. These can also be entirely implemented through C. C6000 has processors that can provide up to 4800 MIPS, but we considered that a waste of processing power for our project.

We got a chance to download Code Composer StudioTM, which is a Texas Instruments’ DSP development program. The program is very complex, as it can interface in real time with the DSP development boards and multiprocessing. We can view anything from memory management to registers, and processor workload. It is undoubtedly an excellent program. Code Composer StudioTM can also interface with MATLAB for data interface and more with MATLAB’s TI DSP toolbox. MATLAB’s TI Development ToolboxTM is very new product from MATLAB. This toolbox allows rapid prototyping of the DSP system especially on TMS320C6701EVM, and TMS320C6711DSK development boards. Instead of using a paragraph explaining how this works, we will only use few sentences to describe the process. Basically, a block diagram has to be drawn in the form of Z-transform, a discrete transform. MATLAB will then build the C/C++ code and arrange a memory map, program the DSP chip and then put the code in Code Composer Studio. This whole process can also be done in

29

Page 35: Acoustic Remote Sensing

minutes. We have also evaluated Analog Devices’ development program, Visual DSP++. This program is similar to TI’s program in terms of capability, but it was very unique in that it also had a statistical tool. This statistical tool measures processor(s) workload and also measures the code’s execution time; enable developers to find a pipeline within the code. We have also looked at Motorola DSP-56XXX series. They are also excellent DSP processors.

Programmable Integrated Circuits are our second choice. We look at Microchip’s product specifically because its popularity, great technical support as many users utilized them, and most importantly, the Senior Design lab has the capability of programming them. We first look at dsPIC line, as it offers both microcontroller’s functionality and DSP processing power. DSP, however, is not as powerful as pure DSP processors. We contacted Microchip, and were notified that dsPIC is not coming out in time for our project due date, so it is out of the picture. The representative suggested Microchip’s PIC16F877 microcontroller. After some research, we found that this is an ideal part to use. It has a Capture, Compare, Pulse Width Modulate ports, CCP. CCP ports let PIC control the signal trigger the transmission of the signal. CCP would then turn to capture mode waiting for the echo. Once it received the echo, it will then compare to get the time of flight. Its ease of programming with only 35 instruction words fits the timeframe of the project. The most important factor being cost, it only costs from $50 to $180 for the programming device. Table 2.1 compares all of the platforms.

FPGA’s are a bit costly for our project, they can run from $20 to almost a couple

of hundreds of dollars per device. FPGA also seems to be a bit difficult to develop given our requirement of measuring the time of flight, but one positive side is that the simulation programs are widely available such as MultiSIM 2001TM, ProtelTM, and many various VHSIC Hardware Description Language (VHDL) programs. ASICs are pretty much for custom made IC’s and will require great quantity and cost to develop.

30

Page 36: Acoustic Remote Sensing

Table 2.1: Comparison between different processing platforms Category\Platform Analog

Devices ADSP-21061

Analog Devices ADSP-21065

Texas Instruments TMS320C6711

Microchip PIC16F877

Platform DSP DSP DSP PIC

Clock Speed 50 MHZ 66 MHZ 150 MHZ 20 MHZ

Floating Point Performance

120 MFLOPS

198 MFLOPS

900 MFLOPS N/A

On Board Data/Program

RAM

1 Mbit 544 KBit 512 KBit 8 Kbyte (Program) 368 Byte

(Data) I/O 2 Serial

ports 2 Serial ports, 12 I/O pins,

and many more

SPI, and many more

SPI, I2C, USART, PSP

Package 240 QFP, 225 PBGA

208 QFP, 196 PBGA

256 PBGA 40 DIP, 40 PLCC, 40

QFP Development

Software Visual DSP++

Visual DSP++

Code Composer Studio V2.0

MPLAB IDE, and various third party compilers

Development Platform

ADDS-21061-

EZLITE or third party platforms

ADDS-21065L-

EZLITE or third party platforms

TMS320C6711DSK or

TMS320C6701EVM or third party

platforms

PICSTART plus, and

many third party

platforms. Development

Cost From $299

From $299

From $299 From free (homemade programmer)

JTAG Emulator port

Yes Yes Yes No, but have In Circuit

Debugger.

Our best choices are DSP and PIC. The more we research, the more we lean toward PIC. DSP programming board cost an average of about $2000 and sometimes would require additional purchase of emulator for debugging and coding programs. TI, ADI, and Motorola, however, offer evaluation boards, which are about $300 and up. These are great as they come with an emulator, most features enable software, DSP

31

Page 37: Acoustic Remote Sensing

chip, built-in RAM interface, parallel port interface to computer, and some additional features such as ADC, audio interface, etc. We contacted the manufacturers and asked for donation. We were successful with our attempts with Texas Instruments. Since our project is sponsored, and more of these ranging devices will be reproduced, we decide to go with PIC because it only costs about $10 for the chip. To reproduce the “brain”, the algorithm just has to be copied, and this is in the same manner with DSP. DSP, however, to purchase the programming board is about $2000, and each chip can be anywhere from $30 to over a thousand dollars. The evaluation boards are great, but starting cost is about $300 a board, and if 10 of these are required, that is $3000. In comparison to PIC, $180 at the most for programming device, and $10 per chip. To reproduce 10 “brains”, it will cost about $280 in contrast to a few thousand. We have also determined that DSP would be overkill in processing power for our purposes, and PIC offers our needed functions. Besides, to learn DSP algorithm thoroughly is an enormous task, especially for developing adaptive DSP. Of course, we have not forgotten about FFT, and autocorrelation functions, but we have found a Polaroid 6500 module, which will be described in a later section. FFT, and autocorrelation are not necessary once we use this Polaroid’s board. The important part for distance calculation is what affects the velocity of sound in water. The 16F877 can also implement 256 points FFT, but it is not as refined as can be done on DSP. 2.1.2 Microcontroller Considerations We have looked at a few microcontrollers available on the market. Each of them offers different advantages, and disadvantages. AtmelTM, Intel 8051TM, RabbitTM, MicrochipTM, OOPICTM, ParallaxTM and MotorolaTM make microcontrollers. One of the major reasons that we chose Microchip’s is because they have great support. We have found that Microchip is a popular choice for microcontrollers, and many people have used them. Table 2.2 compares the performance, and inputs and outputs lines. Table 2.2: Microcontroller Comparison

Atmel Microchip Parallax OOPIC Operating Frequency

Up to 12 MHz Up to 40 MHz Upto 20 MHz Upto 24 MHz

Configurable I/Os

15 I/O pins 33 I/O pins 16 + 1 I/O Pins 32 I/O Pins

Programming STK500 Kit and various third

party vendors

PICSTART Plus and various third

party vendors

BS2 Various third party vendors

Miscellaneous Features

Onboard ADCs Low power

consumption Various standard

parallel and serial I/Os

Onboard ADCs Low power

consumption Various standard

parallel and serial I/Os

LCD, I2C, and RS232

I2C

32

Page 38: Acoustic Remote Sensing

One more important factor that we should mention is that Senior Design lab has Microchip’s PIC programmer. So we do not have to purchase an additional PIC programmer if we use Microchip’s microcontroller. OOPIC seems very easy to program, and does not really need programming board. OOPIC only needs a parallel port cable to connect with it to program. The first generation of this device used OOPIC. It has high power consumption in comparison to Microchip’s microcontroller, 25 mA to less than 2 mA with Microchip. Atmel also has low power microcontroller, but the clock speed is much lower than Microchip’s, and it only has 20 I/O pins at their best (comparison was done at a comparable range of products to Mid-Range Microchip microcontrollers). Since CompactFlashTM card, temperature sensor, and ultrasonic transducer are going to be connected to this device, 20 I/O pins does not seem to serve our purpose. CompactFlashTM probably will occupy all the 20 available pins on Atmel’s microcontroller. Atmel’s fastest microcontroller is 4 MHz, while Microchip’s is 40 MHz. The one we are choosing operates at 20 MHz, which should be fast enough for our application. Motorola and Intel are out of question as many of us have gone through Computer System Design I, and Introduction to Computer Engineering. We all had consensus about not using these microcontrollers as they are mostly programmed in assembly with many instructional commands. Parallax’s microcontrollers have gained popularity lately as they can be programmed in Basic. They also use Microchip’s microcontrollers as the main processing unit. The problem again, is the number of I/O pins that they provided. They only have 20 I/O pins. Another advantage to Microchip is that it has only 35 instructional words to deal with. This would be fairly easy, even though it is in Microchip’s assembly.

Our choice has then come down to two of Microchip’s products. One is 16C765, and the other is 16F877. These two devices are very similar in terms of I/O pins. They both have 33 I/O pins. 16C765, however, seemed to offered an advantage with 4-wires USB Version 1.1 connectivity. This seemed great at first that it can directly interface with our CompactFlashTM card reader/writer that utilized USB serial port from the computer. Rather than directly connect with CompactFlashTM card, this would only take 4-wires to connect to it. This seemed like it will be our choice of microcontroller. One negative thing is that for the re-programmable version, 16C765 uses EPROM. EPROM has its disadvantage when the chip has to be re-programmed. It will take about half an hour to erase all the memory of EPROM by exposure to a strong Ultraviolet (UV) light. This can be quite a pain if we have to wait half an hour to re-program, especially when it is close to the project due date. Not to say that this will happen, but we prefer the FLASH memory version, a 16F877. To solve this problem, we planned to use 16F877 to develop algorithm that deals with everything else, but CompactFlashTM

interface. We contacted Microchip to see if the algorithm can be used by both without modifications.

After the contact, we learned some bad news. For one, 16C765 can only operate in Device Mode USB as the CompactFlashTM card reader/writer is. The problem with Device Mode is that USB devices need a host. The microcontroller has to be operating in Host Mode to connect to the CompactFlashTM reader/writer. The technical support representative also advises us that there is no way that we can make 16C765 operates in Host Mode USB. So now, the advantage that 16C765 seemed to

33

Page 39: Acoustic Remote Sensing

offer is gone. The 16C765, however, offers one more interface, Universal Asynchronous Receiver Transmitter (USART) also known as Serial Communication Interface (SCI), 16F877 offers a wide range of communication ports, Synchronous Serial Port (SSP) with SPITM master mode, I2C master and slave mode, USART, and Parallel Slave Port (PSP). 16F877 also offers better analog-to-digital converters with 8 channels 10 bit wide A/D. 16C765 has 8 channels 8 bit wide A/D. 16F877 has an edge of 2 bit resolution, though we might not need that much resolution, it is good to have. 16F877 also has more data memory, 368 bytes in comparison to 256 bytes with 16C765. 16C765 is actually a bit faster then 16F877 by 4 MHz. 16C765 can run at 24 MHz, while 16F877 can run at 20 MHz. We researched a little bit more and found out that if we want to program 16C765, we have to buy an upgrade kit for the PIC programmer. If we use 16F877, we do not have to. Our final decision is that we will be using 16F877 for its wide variety of interfaces, FLASH re-programmable memory, and the fact that the Senior Design laboratory has the PIC programmer without need for upgrading. It should also be pointed out that both of these have 2 Capture, Compare, PWM ports (CCP). These ports are crucial to our projects as they will be explained later. 2.1.3 Microcontroller Notation Convention This section is a requirement to prevent confusion when refer to certain register and bit of the microcontroller. Since the microcontroller has many registers, we will define how we are going to annotate them. The first will be register name. The second will be register bit set which will also be annotate with name and <n:m>, meaning from bit n to m where n is higher number. For example, T1CON:TMR1CS <1> means T1CON (timer1 control) register, bit 1 is TMR1CS (Timer1 clock source select bit). For full abbreviation and register information please refer to Microchip’s PIC16H87X datasheet. 2.2 The Crystal Oscillator The crystal oscillator is an essential component for our circuit. In fact, it is important to all digital circuits including microcontroller, microprocessor, and DSP. The purpose of crystal oscillator is to generate clock-timing signal. Inside the crystal oscillator is a quartz crystal element. The crystal will generate an oscillation if there is voltage applied at both terminals, and if there is no voltage, but something made it oscillate, it will generate voltage output. This is a piezoelectric effect. This probably sounds familiar, as some ultrasonic transducers are piezoelectric. The crystal is tuned to certain frequency, in our case; it will be at 20 megahertz, 16F877 microcontroller’s clock speed. When it comes to timing circuit, RC circuit comes to mind. The RC circuit with time constant, 1/RC, will serve the purpose. Again, this is not too practical because the tolerances of both resistor and capacitor add up significantly. Noise is also more likely to be generated from RC than crystal oscillator. Crystal oscillators also have less error. This is measure in parts per million, ppm. Some MIL-SPEC crystals have as little as 20

34

Page 40: Acoustic Remote Sensing

ppm error while the generally resistor is about 1% tolerance, and 5% tolerance for capacitors. Resistor and capacitor is then multiplied together for time constant causing the actually frequency output to have great error. For crystal oscillators, if it vibrates at 1 MHz with 20 ppm, it will have error of

1,000,000 x 20 x 10-6 = 20 Hz

This is obviously a great advantage compared to RC circuit. In the long run, crystal oscillator tends to last longer also as its tuning frequency is its physical character. For RC, the values can change over the time, and this will cause the time constant to change. Our crystal is chosen through Microchip’s specifications. They also called for two capacitors to connect on both sides of the crystal oscillator’s pins. These capacitors’ purpose is to stabilize the crystal, mainly to prevent the immediate voltage change on either pin. It should also be noted that the bigger the value of capacitors, the more stable the crystal. See the chart below for processor speed, and capacitor values. Table 2.3: Types of crystals and recommended capacitor values Oscillator Type Operating

Frequency C1 C2

32 kHz 33 pF 33 pF LP 200 kHz 15 pF 15 pF 200 kHz 47-68 pF 47-68 pF XT 4 MHZ 15 pF 15 pF 4 MHZ 15 pF 15 pF 8 MHZ 15-33 pF 15-33 pF

HS

20 MHZ 15-33 pF 15-33 pF LP – Low Power Oscillator XT – Crystal/Resonator HS – High Speed Crystal/Oscillator 2.3 Capacitors and Resistors Capacitors and resistors do not need much introduction. Hopefully, everyone is familiar with these. We, however, looked deeper into how to choose capacitors, and resistors. A lot more was discovered. It was not just to pick the right values with right wattage. Mostly the difference is in the construction of the devices, and the construction makes a big difference. For our peace of mind, we try to choose as many military specifications (MIL-SPEC) parts as possible, but it comes with a cost. MIL-SPEC parts are hard to find, and costly. If we can get it donated, we will use it, but if we cannot, we will use generic parts. MIL-SPEC parts are constructed better, have wider range of operating temperatures, and the best of all, lower tolerances.

35

Page 41: Acoustic Remote Sensing

Resistors are mostly used in the circuit as pull-up, pull-down resistors, gain control, and for sonar driver circuit. We have found that many resistors on the market that has been rated for 5% tolerance sometime has worse tolerance than 5%. We choose to use MIL-SPEC again, but if not possible, we will use 1% as the cost difference is justifiable. Since this circuit is going to run on mostly low current, ¼ watt resistors would suffice. We chose film and carbon filament type. 2.4 Analog-to-Digital Converter Even though this component is built into the microcontroller, it should be treated as it is a separate component. We were considering outboard ADC’s from Analog Devices, and Burr-Brown, now part of Texas Instruments. ADC in our circuit would have two main functions, one is to convert temperature data to the microcontroller, and the other is to convert ultrasonic signal into digital domain. The previous generation of this device has ADC running at about 10 kHz, according to onboard ADC from OOPIC with external reference voltage. We believe that this might be one of the flaws of the previous generation. The rule of thumb in digital signal processing is

f Nyquist = 2 x f max

The ultrasonic transducer was running at about 45 kHz, and the on board ADC was at 10 kHz. This does not meet Nyquist criteria. As the Polaroid board does not generate digital output, we believe that ADC should be at least 100 kHz, or 100000 samples per second to be useful.

Burr-Brown sent us a sample of TLC1518IDW, 10-bit 8-channel 400 kHz with SPITM serial interface. This ADC can run at different frequency other than 400 kHz. Analog Devices also sent us sample for AD 7829, 8-bit 8-channel 2 MHz ADC. The principal of operation for these devices are the same. Most ADC’s have external reference voltage input, and most will have an option to configure for internal reference voltage. The reference voltage will be the largest possible value represent in digital domain. The number of bits will determine the resolutions, and maximum number of quantized levels. For example, a 8-bit converter would have 28 = 256 quantized levels represent in binary from 0000 0000 to 1111 1111 or 0 to 255 in decimal notation. If the reference voltage is 2.56 volt, and the input to ADC is at 2.00 volt, the output would be 1100 1000 or 200 in decimal. The sampling of frequency is the same as samples per second. It means how many samples will be generate in one second, and how to choose sampling frequency has already been mentioned above. The number of channels can be determined by how many things need to be converted into digital domain, in our case, temperature, and ultrasonic output.

36

Page 42: Acoustic Remote Sensing

Figure 2.4: Burr-brown TLC1518IDW, Analog Devices AD7829, and AD9224

However, we researched further into the matter. Only ultrasonic output needs high conversion rate. The temperature sensor does not because the temperature sensor will measure the temperature of the water. Water cannot change temperature abruptly in natural conditions. So as long as the bit resolution is enough, sampling frequency does not matter much for temperature sensor. We contacted Microchip and found out a way to eliminate the usage of ADC in ultrasonic output line though the use of Capture, Compare, PWM (CCP) module. This will be later explained. To save power consumption and size, the decision is to use onboard 10-bit ADC on 16F877. The external converters would take extra power. The output from ultrasonic module would be to CCP port. 2.5 Digital Potentiometer As the name implies, this is a potentiometer with digital control. It has no moving parts. Instead of traditional mechanical potentiometer, we are using digital potentiometer. The only place this will be use in the circuit is the gain control for ultrasonic signal amplifier. The constant gain amplifier could be used for this purpose, but it probably would not be as effective. The purpose of variable gain amplifier over time is that given the ping is sent out, and come back, the further the ping goes, the weaker the signal. Therefore, if the ping comes back from short distance in comparison with the ping bounce back from long distance, the ping from shorter distance will have stronger magnitude. So the gain for short distance should less than the gain for longer distance. Given that sound travels in water at almost constant velocity, the gain versus time plot should be increasing rather than a constant gain. This will give us more effective range as long as the signal to noise ratio is not too low. To produce an automatic control of gain, we cannot use transitional mechanical potentiometer. First, a person cannot be there to turn and adjust the gain. Second, even if a person was there, the gain control will not be quick enough to increase in order of milliseconds, and accuracy of the gain will be hard to control with a person twisting the knob.

37

Page 43: Acoustic Remote Sensing

Figure 2.5: Analog Devices AD5242

The tolerance of the digital potentiometer is somewhere between 10 to 20 percent. Again, This tolerance is acceptable because it probably is much more accurate, as exact than a person turning the knob in milliseconds. According to the transducer manufacturer, the Hexamite HE123-TR should have a range of 500 meters. The velocity of sound is about 1500 meter/second. The time requires for the sound to travel from transmitter to the target and back is about 500*2/1500 = 0.666 seconds. So the gain must vary from the minimum to the maximum within this time frame. The digital potentiometers have specifications similar to analog potentiometers, but the differences are that they have control steps, and sweep type additional to maximum resistance values. The control steps are usually in the number in order of 2n where n is an integer. The control step varies from 8 to over 256 steps. The sweep type is usually either logarithmic or linear. As of this time we have not acquired the transducer, so we cannot test voltage output at different distances, and curve fitting to determine if we need linear or logarithmic type. The standard values are offered in digital potentiometer as in analog potentiometer. The manufacturers for which we considered their digital potentiometers are Microchip, Analog Devices, National Semiconductor, and Maxim IC. We are expecting to use 100 K potentiometer on the feedback path, and we might also need another one for forward path to create enough gain. The gain of the ultrasonic echo signal sometime can be up to 2000 times, but as mentioned before, the transducer is yet to be obtained.

One more specification that should be considered in choosing a digital

potentiometer is the bandwidth of the product. The digital potentiometers do not have problem operating at low frequency or DC, but it will have problem operating at higher frequency. The main difference between traditional variable resistors and these digital potentiometers that causes this problem is the semiconductor construction in comparison to carbon, film, wire wound filaments with traditional variable resistors. Wire-wound resistor can cause this problem slightly also. As the name implies, it is wound, so it forms an inductor. Resistors are usually connected in series, and an inductor in series will produce a low-pass filter effect. In case of digital potentiometer, it is the semiconductor that limits the high frequency range. One of the causes is the mobility of electrons in the semiconductor. The problem is well known in semiconductor business, and that is why for microwave or RF applications, specific types of semiconductor are required. AD5242 is chosen, an Analog Devices product. It comes with three different values, 10 KΩ, 100 KΩ, and 1 MΩ. We were going to choose 1 MΩ,

38

Page 44: Acoustic Remote Sensing

so we can obtain a gain of about 2000 with Rs = 500 Ohms, but the problem lies with –3 dB frequency at about 6 KHz. At that point, without considering the resistance, the signal is already 70% of the original signal. For 1 MΩ version at 50 KHz, sonar operating frequency, the gain is at –24 dB with value 80h setup in AD5242 according to its datasheet. This attenuation will give us more gain than 2000. We would like to have more linear control over digital potentiometers, so we decide to choose dual 100 KΩ in series, which will give maximum of 200 KΩ total resistance. Four of these devices can be connected together, and it will be explained later in section 6.1.3. 2.6 Operational Amplifier This amplifier is specifically for amplification of the incoming ultrasonic transducer. This is one of the few components that we will neglect the low power requirement. As we research about operational amplifier, we found that normally, if the amplifier is low noise, it will require much more power than lower power type, and the low power type has much more distortion and less Common Mode Rejection Ratio (CMRR). The CMRR is a ratio between common gain and differential gain, and it can be used for determine quality of differential amplifier. Low noise amplifier is chosen because the fact that the incoming echo will be in order of millivolts, and possibly microvolts. Therefore, a large gain is needed, and the noise can become a problem. As mentioned above, the signal to noise ratio needs to be as big as possible. The OPA277 from Burr-Brown has been chosen for this purpose due to its considerably low power requirements.

39

Page 45: Acoustic Remote Sensing

CHAPTER 3

MEMORY

This chapter will discuss the memory requirements for the device. It will review the available memory devices and the decisions that went into making our selection. The specifications for the CompactFlash card will be shown in great detail.

40

Page 46: Acoustic Remote Sensing

3.1 Data Storage and Acquisition 3.1.1 Introduction The device will collect data from the transducer and transmit it to the microcontroller. The microcontroller will then perform calculations to determine how far away an object is from the device. Once the calculations are complete, the data, time and date, and water temperature will need to be saved for later retrieval. If the information were saved to the microcontroller, the device would have to be removed from the water and transported to a computer to retrieve the information. Taking the data from the microcontroller and transmitting it to the computer would be difficult and tedious. The microcontroller also does not have a sufficient amount of memory to store data for 24 hours. Many factors restrict the type of memory utilized in the device. 3.1.2 Memory Selection The memory chosen must adhere to a few restrictions. The device must be lightweight and waterproof. The memory must be small enough to fit in the device. It also cannot require a large amount of power. The device will stay underwater for a long period of time; however, if the memory consumes too much power, a larger power supply will be needed and will require a larger, heavier device. The memory also needs to be transportable. The information from the device will be stored into the memory. After a specified length of time, the memory containing the data will be removed and replaced with new memory. The memory containing the data will be taken to a computer in a lab for analysis. Therefore, the memory must also be nonvolatile so the data will not be lost once the memory is removed and loses power (Huang 1996). There are three types of nonvolatile memory that were considered for the device. They are erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), and flash memory. Each one has its own advantages and disadvantages, which have been outlined in Table 3.1 on the following page. Flash memory was chosen as the memory to be implemented in the device due to the least number of disadvantages (Huang 1996). Since this is a second-generation prototype, and the flash memory selected previously was CompactFlash, the decision was made to stay with this choice to save money. Two CompactFlash cards and a CompactFlash reader were previously purchased decreasing the number of components that will be purchased for the third generation prototype. CompactFlash is the best choice out of the range of available CompactFlash cards because SanDisk, the inventor of CompactFlash cards, manufactures it (Huang 1996).

41

Page 47: Acoustic Remote Sensing

Table 3.1: Advantages and disadvantages of three types of nonvolatile memory

Memory Type Advantage Disadvantage EPROM - Erasable

- Capable of being reprogrammed

- Whole chip has to be erased to be reprogrammed

- Requires an EPROM programmer

- Needs an ultraviolet light to erase

- Must be removed to be erased

EEPROM - Can be erased electronically

- Capable of being reprogrammed

- Individual locations can be erased

- Requires an EEPROM programmer

- Limited number of times the chip can be reprogrammed

- Slow due to erasing and writing at the byte level

Flash - Can be erased

electronically - Does not need a

special programmer

- Can be programmed electronically

- Has the same density as EPROM

- Fast and easy to update due to erasing and writing in block size

- Individual locations cannot be erased

42

Page 48: Acoustic Remote Sensing

3.1.3 CompactFlash vs. SmartMedia Figure 3.1: CompactFlash Card Figure 3.2: SmartMedia Card

Reprinted with permission from Sandisk Reprinted with permission from Sandisk SanDisk developed CompactFlash cards in 1994. In November 1995, Toshiba produced its version of the CompactFlash card, the SmartMedia card. Even though SmartMedia was developed later than CompactFlash, it did not have all of the advantages of CompactFlash. The available range of SmartMedia memory size is less than CompactFlash cards. The largest available SmartMedia card is 128 megabytes whereas the maximum CompactFlash memory size is 1 gigabyte. The case of the CompactFlash is thicker, making it less easy to break than the SmartMedia card. The voltage requirements for both are either 3.3 volts or 5 volts depending on the card chosen. Both, however, do adhere to the guidelines designated by Personal Computer Memory Card International Association the guidelines (PCMCIA) making them capable of many universal applications. Even though both cards are compact in size and are lightweight, the CompactFlash card is the better choice (Tyson n.d.). 3.1.4 SanDisk Reader Figure 3.3: SanDisk Reader

Reprinted with permission from Sandisk The SanDisk reader is an external flash card reader that connects through a USB port to a computer. Even though it is called a reader, it does have the ability to write to the card also. The reader was developed so the device utilizing the memory would not have to connect to a computer directly to access the data. The SanDisk reader is easy to use allowing simple drag and drop technique to retrieve data from the card and place

43

Page 49: Acoustic Remote Sensing

it on the computer. The easy computer connection is also fifty times faster than using a serial cable. The SanDisk reader used by the previous group was the SDDr-05-01, which is no longer available from SanDisk. If more are needed than the SDDR-31 will need to be purchased instead. There does not see to be any difference between except for the reader case design (SanDisk n.d.). 3.1.5 CompactFlash vs. MultiMediaCard Figure 3.4: CompactFlash Card Figure 3.5: MultiMediaCard

Reprinted with permission from Sandisk Reprinted with permission from Sandisk Another possible choice for memory storage is the MultiMediaCard. It has all of the great advantages of CompactFlash. The size of a MultiMediaCard is much smaller than the matchbox sized CompactFlash. MultiMediaCards are about the size of a postage stamp. The size seems to be the only advantage over CompactFlash cards. The largest memory size of a MultiMediaCard is only 64 megabytes. It is also more expensive than CompactFlash. Another disadvantage of the MulitMediaCard is that the technical documentation costs about $500 whereas the technical documentation for the CompactFlash card is available free of charge, again, making CompactFlash the better memory choice (SanDisk n.d.).

44

Page 50: Acoustic Remote Sensing

Table 3.2: SanDisk CompactFlash card specification sheet (SanDisk n.d.)

System Performance Start-up Time Sleep to Write 2.5 msec max Sleep to Read 2.0 msec max

Reset to Ready 50 msec typical 400 msec max

Data Transfer Rate to/from Flash 20.0 MB/sec burst Data Transfer Rate to/from Host 16.0 MB/sec burst

Active to Sleep Delay Programmable Controller Overhead Command to DRQ <1.25 msec

Power Requirements

DC Input Voltage

Commercial 3.3V ± 5% 5V ± 10%

Industrial 3.3V ± 5% 5V ± 5%

Typical Power Dissipation

Sleep 200µA (3.3V) 500µA (5V)

Read 21-45 mA (3.3V) 34-75 mA (5V)

Write 21-60 mA (3.3V) 34-90 mA (5V)

Environmental Specifications

Temperature Operating Commercial 0 - 60º C

Operating Industrial -40 - 85º C Non-Operating Commercial -25 - 85º C

Non-Operating Industrial -50 - 100º C

Humidity Operating 8 - 95%, non-condensing

Non-Operating 8 - 95%, non-condensing Acoustic Noise (at 1 meter) 0 dB

Vibration Operating 15 G peak to peak max

Non-Operating 15 G peak to peak max Shock

Operating 2,000 G. max Non-Operating 2,000 G. max

45

Page 51: Acoustic Remote Sensing

Reliability and Maintenance MTBF (Mean Time Between Failures) >1,000,000 hours

Preventive Maintenance NONE

Data Reliability < 1 non-recoverable error in 10(14) bits read

Physical Specifications

Length 36.4 mm (1.433 in)

Width 42.8 mm (1.685 in)

Thickness (Body) 3.30 mm (0.130 in)

Thickness (Removable Edge) 3.94 mm (0.155 in )

Weight 11.4 g (0.40 oz )

3.2 Interfacing CompactFlash and Microcontroller 3.2.1 Introduction The microcontroller will be retrieving information from the transducer and calculating the distance an object is from the device. Once the distance is calculated, it, along with the date and time, need to be stored to memory, the CompactFlash card. The memory card will need to be interfaced to the microcontroller. CompactFlash cards have 50 female contacts divided into two rows of 25, each contact being 1.27 mm in width. A component consisting of 50 male pins is needed to retrieve that data from the card. One method of doing this is using an interconnect header. An interconnect header is basically just a collection of jumper pins. Pictured in Figure 3.6 is a typical interconnect header (CompactFlash n.d.).

One side of the interconnect header, side with the male pins, is connected into the CompactFlash card. The other side is soldered onto a board to be connected to the microcontroller. A board will be milled with lines to connect the header and the microcontroller. Once we have a way to connect the memory and the microcontroller, we must determine the best method to access the card. The microcontroller is 8-bit so we want a memory mode that is compatible with the 8-bit system. Common Memory mode is the best because it utilizes an 8-bit data bus whereas an IDE interface requires a 16-bit data bus.

46

Page 52: Acoustic Remote Sensing

Figure 3.6: Block diagram of interconnect header and CompactFlash card

Reprinted from Submersible Watchdog documentation 3.2.2 Pin Assignment The CompactFlash card has 50 possible connections, however, all of the pins will not be needed. Data will be transmitted to eight registers through eight data lines. The data lines are connected from port D (D07 – D00) of the CompactFlash card to the 8-bit wide parallel serial port of the microcontroller. Seven of the registers will be used for data, while the eighth register loads and executes the command. Only three address lines (A02 – A00) will be necessary to access the registers. The rest of the address lines (A10 – A03) will be hardwired to ground. The address lines are connected to port E on the microcontroller (Samuels 2002). To write to the card, data is placed on the data lines while the address of the register to which the information will be stored is placed on the 3 address lines. For the data to be transmitted from the microcontroller, the write enable signal (-WE) on the CompactFlash must be strobed low by the microcontroller. Every time –WE is strobed, the next byte to be written is loaded onto the data lines (Samuels 2002). Reading data from the CompactFlash card is takes a similar process as writing. Instead of loading the data lines, the address lines are loaded with the address of the data register that will be read. Then the microcontroller strobes the output enable signal (-OE) low by the microcontroller. The next byte in the register is read each time –OE is strobed (Samuels 2002). -OE and –WE are referred to as control lines. There are six control lines total for the CompactFlash card. These control lines communicates certain things about the card the microcontroller needs to know in order to read or write. The microcontroller needs to know, most of all, if there is a card to communicate with. The card detect line

47

Page 53: Acoustic Remote Sensing

(–CD1) tells the microcontroller when the CompactFlash card is fully inserted into the interconnect header. The card then needs to be enabled by the microcontroller by making the card enable line (-CE1) go high. Once the microcontroller enables the card, it needs to know if the card is ready to accept data. The ready/busy line (–RDY/BSY) is low when the card is busy; otherwise, the line will be high, waiting to receive data. Finally, the controller in the CompactFlash card can be reset if something goes wrong, by setting the reset line to high (CompactFlash n.d.). The CompactFlash card can become a high performance I/O device by configure the memory space (CompactFlash n.d.). Table 3.3 is a truth table of the register configurations. Register addresses begin at 000h. Table 3.3: Register address memory mapped decoding (CompactFlash n.d.) -REG A10 A9-A4 A3 A2 A1 A0 Offset -OE=0 -WE=0

1 0 X 0 0 0 0 0 Even RD Data Even WR Data1 0 X 0 0 0 1 1 Error Features 1 0 X 0 0 1 0 2 Sector Count Sector Count 1 0 X 0 0 1 1 3 Sector # Sector # 1 0 X 0 1 0 0 4 Cylinder Low Cylinder Low 1 0 X 0 1 0 1 5 Cylinder High Cylinder High

1 0 X 0 1 1 0 6 Select Card/Head

Select Card/Head

1 0 X 0 1 1 1 7 Status Command

1 0 X 1 0 0 0 8 Dup. Even RD Data

Dup. Even WR Data

1 0 X 1 0 0 1 9 Dup. Odd RD Data

Dup. Odd WR Data

1 0 X 1 1 0 1 D Dup. Error Dup. Features 1 0 X 1 1 1 0 E Alt Status Device Ctl 1 0 X 1 1 1 1 F Drive Address Reserved 1 1 X X X X 0 8 Even RD Data Even WR Data1 1 X X X X 1 9 Odd RD Data Odd WR Data

48

Page 54: Acoustic Remote Sensing

Table 3.4: CompactFlash card to microcontroller pin connections (Samuels 2002)

CompactFlash Pin Name

Pin #

Microcontroller Pin Name

Pin # External Signals

GND 1 N/A N/A Connects to ground D03 2 RD3/PSP3 22 D04 3 RD4/PSP4 27 D05 4 RD5/PSP5 28 D06 5 RD6/PSP6 29 D07 6 RD7/PSP7 30 CE1 7 RB0/INT 33 A10 8 N/A N/A Connects to ground OE 9 RB3/PGM 36 A09 10 N/A N/A Connects to ground A08 11 N/A N/A Connects to ground A07 12 N/A N/A Connects to ground Vcc 13 N/A N/A Connects to Vcc A06 14 N/A N/A Connects to ground A05 15 N/A N/A Connects to ground A04 16 N/A N/A Connects to ground A03 17 N/A N/A Connects to ground A02 18 RE2/*CS/AN7 10 A01 19 RE1/*WR/AN6 9 A00 20 RE0/*RD/AN5 8 D00 21 RD0/PSP0 19 D01 22 RD1/PSP1 20 D02 23 RD2/PSP2 21 WP 24 N/A N/A Connects to Vcc CD2 25 N/A N/A

CD1 26 RB1 34 10KΩ Pull-up resistor from CD1 to Vcc

D11 27 N/A N/A D12 28 N/A N/A D13 29 N/A N/A D14 30 N/A N/A D15 31 N/A N/A CE2 32 N/A N/A Connects to Vcc VS1 33 N/A N/A

IORD 34 N/A N/A IOWR 35 N/A N/A

WE 36 RB4 37 RDY/BSY 37 RB5 38

Vcc 38 N/A N/A Connects to Vcc CSEL 39 N/A N/A Connects to ground VS2 40 N/A N/A

49

Page 55: Acoustic Remote Sensing

RESET 41 RB2 35 WAIT 42 N/A N/A

INPACK 43 N/A N/A REG 44 N/A N/A Connects to Vcc BVD2 45 N/A N/A BVD1 46 N/A N/A D08 47 N/A N/A D09 48 N/A N/A D10 49 N/A N/A GND 50 N/A N/A Connects to ground

50

Page 56: Acoustic Remote Sensing

Figure 3.7: Schematic of the CompactFlash card to the microcontroller (Samuels 2002)

47

48

8

20

25

16

28

4

1

2

3

5

6

7

9

10

11

13

14

15

17

1819

43

42

41

39

38

37

35

34

33

31

30

29

27

26

22

23

24

21

46

45

44

40

36

32

12

50

49

47

48

8

20

25

16

28

4

2

3

5

6

7

9

10

11

13

14

15

17

18

19

43

42

41

39

38

37

35

34

33

31

30

29

27

26

22

23

24

21

46

45

44

40

36

32

12

50

49

47

48

8

20

25

16

28

4

1

3

5

6

7

9

10

11

13

14

15

17

18

19

43

42

41

39

38

37

35

34

33

31

30

29

27

26

22

23

24

21

46

45

44

40

36

32

12

50

49

A11

A11

A11

A11

A11

A11

A11

A11

A11

A11

A11

A11

A11

A11

A11

A11

A11

A11

A11

A11

A11

A11

RB235

RB538

RB437

RB134

RD2/PSP221

RD1/PSP120

RD0/PSP019

RE0/RD/AN58

RE2/CS/AN710

RB0/INT33

RD7/PSP730

RE1/WR/AN69

RD6/PSP629

RD5/PSP528

RD4/PSP427

RB3/PGM36

2RD3/PSP3

221

Com

pact

Flas

h C

ard

Inte

rcon

nect

Hea

der

PIC

16F8

77

51

Page 57: Acoustic Remote Sensing

CHAPTER 4

POWER SUPPLY

This chapter will discuss the power supply options available at our disposal. The power supply needed for the device is DC power. The type of batteries needed and the power consumption of each component will be discussed throughout. The use of voltage regulators will be reviewed and why they are needed for the device.

52

Page 58: Acoustic Remote Sensing

4.1 Introduction

One of the most important parts of our device is the power supply. Without a source of energy none of the other parts would function. So the power supply is the heart and the soul of the Acoustic Remote Sensing device. In order for our device to be stand-alone, it needs an energy storage device that can supply a direct current (DC) supply of voltage. In other words, we need a DC battery. Choosing the correct power supply is important. When choosing our supply we need to consider all of the different devices that need a power source. All of the parts that are connected to the same source may demand more current than other devices, which may have effects on the sources ability to meet the demands. Additionally, our device specifications require that the power supply last for a minimum of twenty-four hours. 4.2 Devices Requiring Voltage Supply

The majority of our devices for our project require a power supply. These devices are:

Microcontroller (PIC16F877) Transducer (HE123TR) Removable Flash Card (SanDisk 48 MB CompactFlash) Temperature Sensor (AD22100KT) Real-time Clock/Calendar (DS1678) Operational Amplifier (OPA277) Liquid Crystal Display (LCD) (LM2052) LCD driver (Hitachi HD44780) Pull up for I2C lines, CD1 pin on the Compact Flash, and other data

lines that require external pull up resistors.

The microcontroller, transducer, removable flash card, temperature sensor, real-time clock/calendar, liquid crystal display, LCD driver, and pull up lines can all operate with a five-volt DC supply. The remaining device, the operational amplifier, has different requirements. For the op-amp, in order to retain both the positive and negative cycles of the signal received from the transducer, it requires a positive and negative supply voltage. A solution for voltage distribution will be discussed within the next few sections.

The devices listed above can be separated into two categories: digital (logic) or analog devices. In practice, it is generally a good idea to have separate grounds for logic devices and for analog devices. This helps to reduce some of the noise that can be caused by connecting all these devices to the same common ground. Logic devices utilize the ground for representing logic low, where the analog devices merely have a positive supply voltage and a ground for current flow. The devices that fall into the logic category are:

53

Page 59: Acoustic Remote Sensing

Microcontroller Compact Flash Real-time Clock/Calendar LCD

The devices that fall into the analog category are:

Transducer Temperature Sensor Operational Amplifier (op-amp)

These devices will all be connected to the positive and negative terminals of the

battery, but the negative terminal of the battery will have two parallel connections. One for the analog ground and the other for the digital ground. This should reduce some noise for representation of logic low. 4.3 Overview of Power Supply for Submersible Watchdog

The previous generation prototype, the Submersible Watchdog, did not have as many devices that our prototype will have. The devices that they needed to supply power to were their microcontroller (00PIC 16C84), the transducer driver board (Polaroid 6500 Ranging Module), and the Compact Flash Card (SanDisk 48MB).

The OOPIC 16C84 required 6 to 40 V of DC voltage with a current supply of 300 mA. The OOPIC had a power dissipation of close to one Watt. This built in regulator for the microcontroller board did not provide a sufficient amount of current, so they replaced the regulator with a 7805 regulator from National Semiconductor. Their final design used a separate power supply for the microcontroller. They used a 9 V Duracell battery.

The Polaroid 6500 ranging module and Polaroid 9000 transducer were each connected to a separate power supply. The 6500-driver board required a power supply of 4.5 to 6.8 volts with a current of 2 A. The transducer needs a 400 Vp-p pulse train during transmission with a DC bias of 200 V just after transmission.

The SanDisk CompactFlash card from the previous generation is the same card

that we will be using. They connected the flash card to the same supply as the 6500 driver board. The Compact Flash requires a power supply of 5 V and 46 to 90 mA of current.

For the supply to the Compact Flash and the driver board, they connected two 9

V Duracell batteries in series (18 V) to a switching regulator. The switching regulator uses an inductor, transformer, and capacitors to convert unregulated DC input voltage to regulated DC voltage. Switching is done via a power transistor that supplies power

54

Page 60: Acoustic Remote Sensing

when it is demanded. The main reason they chose to use a switching regulator was so they could adjust the output voltage and current. Figure 4.1 is a block diagram of their switching regulator. Figure 4.1: Basic switching regulator Unregulated Regulated

Switch Diode Clam

Filter DC Input DC Output

p

Duty Cycle Control

SamplingCircuit Oscillator

Power

Reprinted with permission from Submersible Watchdog documentation.

The power supply for Submersible Watchdog, consisting of three Duracell 9 V batteries, one for the microcontroller and two for supply to all other devices, only had a stand-alone power supply lasting for approximately four hours. This supply is definitely not good enough for our design. The short battery life is most likely due to their components. The 6500 ranging module drains an enormous 2 A of current during transmission. That is a lot of energy taken from the battery. This is such a high of a demand that they needed a separate power supply for the microcontroller. The OOPIC even demands a lot of current as well. It consumes about 300 mA. That is a lot of power consumption for a microprocessor. In addition to these devices, the compact flash drains another 46 to 90 mA. So during the maximum current drain periods they have 2 A + 90 mA + 300 mA = 2.39 A. 4.4 Power Supply Considerations

Our design plans on utilizing devices that have the lowest power consumption. If we want to meet the minimum twenty-four hour requirement with even more devices than the previous prototype, all our devices must require very low current on the order of milliamps or even microamps. The power consumption of each of the devices in the Acoustic Remote Sensing device will now be considered. First, the brain of our device will be the PIC16F877 microcontroller from Microchip Technology, Inc. This is a low power device, especially when compared to the OOPIC 16C84. Table 1 is a table of the electrical characteristics gathered from the data sheet obtained from Microchip Technology, Inc (PIC16F877 2002) .

55

Page 61: Acoustic Remote Sensing

Table 4.1: Electrical characteristics of the PIC16FXX family

PIC16F877 (Commercial, Industrial)

Standard Operating Temperature -40°C to 85°C for industrial 0°C to 70°C for commercial

Supply Current Parameter Number Symbol Characteristic /

Device Min Typ Max UnitsConditions

D010 Ico 16LF87X - 0.6 2.0 mA

XT, RC osc configuration Fosc = 4MHz, Vdd = 3.0 V

D010 Ico 16F87X - 1.6 4.0 mA

RC osc configuration

Fosc = 4 MHz, Vdd = 5.5 V

D010A Ico 16LF87X - 20 35 µA

LP osc configuration

Fosc = 32kHz, Vdd = 3.0 V,

WDT disabled

D013 Ico 16F87X - 7 15 mA

HS osc configuration

Fosc = 20 MHz, Vdd = 5.5

V

D015 BOR Brown-out Reset Current - 85 200 µA BOR enabled,

Vdd = 5.0 V Adapted from Microchip Technology, Inc.

From Table 4.1, on the line labeled D013, operating a 16F87X processor at Fosc

= 20 MHz, with a supply voltage of 5.5 V, there is a maximum supply current of 15 mA. Even though we will be supplying only 5.0 V, the supply current is very similar. This is considerably lower than that of the OOPIC with was 300 mA. Its standby supply current is very low as well, on the order of microamps. The PIC controller operates with a 5 V power supply. The input voltage pin will also be connected to the active low RESET pin (PIC16F877 2002) .

The next major component is the transducer. Instead of Polaroid’s 9000 transducer and 6500 ranging module, we will be using Hexamite’s HE123TR transducer. The following table shows some of the parameters for this transducer.

56

Page 62: Acoustic Remote Sensing

Table 4.2: Hexamite’s HE123TR transducer parameters

Parameters Values Units

Operating Frequency 23.5 kHz Input Voltage 26 (max) Volts (RMS)

Output (SPL) @20V 155 Db Receive (Sensitivity) -30 db/V/Ubar

Impedance 300 Ohm Beam Angle ±35 Degrees Bandwidth 1 kHz

Settling Time 8 MS Temperature Table 1 -40 to 100 °C

Reprinted with permission from Hexamite. From Table 4.2 you can notice that the HE123TR can handle an input voltage up

to 26 V. However, for our design we can operate the transducer with only a 5 V input. After contacting Hexamite, we learned that the maximum current drain during signal transmission only 40 mA. This is extremely low considering that the Polaroid 9000 transducer required 400 V and 2 A (HE123TR 2001) .

We are using the same flash card as the Submersible Watchdog. Table 4.3 shows the power requirements for the SanDisk 48MB CompactFlash. Table 4.3: Power requirements for SanDisk Compact Flash card

Power Requirements

Power Dissipation (mA)

@ 3.3 V @ 5 V Manufacturer DC Input Voltage

(V) Sleep Read Write Sleep Read Write

3.3 (±5) SanDisk

5.0 (±10) 0.2 32 - 45 32 - 60 0.5 46 - 75 46 - 90

Reprinted from Submersible Watchdog documentation.

As you can see from Table 4.3, with a 5 V power supply the Compact Flash has a maximum current drain 46 to 90 mA on its write cycle. We will most likely not use the read cycle for our device, and when it is in sleep mode it only needs a supply of 0.5 mA.

57

Page 63: Acoustic Remote Sensing

Another power supply concern to note about the flash card is that it requires an additional 5 V supply and pull up resistor for the CD1 pin. We can just connect the resistor to the 5 V supply that will already be connected to the card.

The temperature sensor also requires a 5 V power supply. The temperature sensor we have chosen to use is Analog Devices AD22100KT. This device has low power consumption as well. Table 4.4: Chip specifications for AD22100 temperature sensor (Ta = 25°C and V+ = 5.0 V)

Parameter Min Typ Max Units Transfer Function Vout = (V+5V) x [1.375 +

22.5mV/°C x Ta] V -

Temperature Coefficient (V+/5V) x 22.5 MV/°C Output Characteristics:

Error

Nominal Output Voltage

- -

±0.5

1.938

±2.0

-

°C

V

Power Supply: Operating Voltage

Quiescent Current

4.0

-

5.0

500

6.0

650

V

µA Temperature Range:

Guaranteed Temp Range

Operating Temperature Range

-

-50

25

-

-

150

°C

°C

Adapted from Analog Devices, Inc.

From Table 4.4 you can see that with a power supply of 5 V, the quiescent supply current is only 500 µA. This is a relief because it is so low that we can almost exclude it from our total power consumption consideration (Voltage 2002) .

The next power consuming device we will consider is the operational amplifier required for signal conditioning of the received signal from the transducer. We will be using a low noise, high precision op-amp made by Texas Instruments. Noise filtering is usually a trade off with power consumption, however, the op-amp we will be using, Texas Instrument’s OPA277, will be connected to a ±4.5 V supply and will have less than 800 µA of current consumption (OPA227 2002) . This should also have a very little affect on the power consumption. The next component is the real-time clock/calendar, DS1678 made by Dallas Semiconductor (Maxim IC). This device also operates with a 5 V power supply. Again, this also requires resistors that pull the data lines up to 5 V. We can just connect the resistors to the existing power supply connection (Real Time 2002) .

58

Page 64: Acoustic Remote Sensing

Table 4.5: DC Electrical characteristics for DS1678

Parameter Symbol Min Typ Max Units Input Leakage I -1.0 - 1.0 µA LILogic 0 Output V - - 0.4 V OLI = 4 mA OLActive Supply

Current ICCA - 1 2 mA

Battery Standby Current

(Oscillator On)

IOSC - 300 500 nA

Battery Standby Current

(Oscillator Off)

IBAT - 50 150 mA

Power-Fail Voltage VPF 1.216 x VBAT 1.25 x VBAT BAT V 1.284 x V

Adapted from Maxim Integrated Products. From Table 4.5 you can see that the active supply current is a maximum of 2 mA

but typically around 1 mA. This will also need a back up battery in order to retain the calendar information. A lithium 3 V small cell battery is connected to one of the pins and is only used when the 5 V supply voltage becomes lower than the 3 V battery back up supply. This clock also requires a crystal oscillator for operation. Dallas Semiconductors manufactures the DS32KHZ crystal oscillator chip. This chip can run off the same 5 V supply that connects to the DS1678. It also requires that several of its pins be connected to ground (DS32KHZ 2002) .

The final device that we must consider for total power consumption is the LCD. The LCD we have chosen is the LM2052 made by Densitron Technologies. The LCD screen is another device that operates with a 5 V supply voltage and its current consumption is on the order of milliamps. From the data sheet for the LM2052 provided by Densitron Technologies, the supply current for the 5 V supply voltage at 25ºC is only 1 mA. The LCD requires an LCD driver in order for the display to work. We have chosen to use Hitachi’s HD44780 LCD driver. This driver operates on a 5 V supply also that is distributed to four different voltage inputs through resistors. The total supply current is a maximum of 0.3 mA and typically 0.15 mA (LM2052 2002) . 4.5 Current Supply Requirements

After consideration of all the devices that shall be connected to the power supply, a total maximum supply current can be calculated as 15 mA + 40 mA + 90 mA + 500 µA + 2 mA + 800 µA + 1 mA + 0.15 mA = 0.14825 A or 148.25 mA. For the worst case scenario the maximum current drain is less than 150 mA. If you consider that the 40 mA from the transducer is only required for a miniscule amount of time, and that the devices are in sleep mode for a certain amount of time as well, then the average current

59

Page 65: Acoustic Remote Sensing

over time would be around 100 mA. With a 100 mA constant drain, we would need a battery with a capacity of about 2400 mAh in order to last twenty-four hours. Either a singe battery with this capacity could be used, or we could connect batteries in parallel in order to obtain a higher current capacity with the same voltage. 4.6 Batteries 4.6.1 Battery Types The next section will deal with battery selection. For our battery supply to last a minimum of 24 hours, we need a battery that can supply enough voltage and current to keep all the devices running. When choosing a battery, first you must consider two categories: disposable primary cell and rechargeable secondary cell.

There are several types of batteries that fall into these two categories. In the primary category we have battery types such as Carbon-Zinc, Alkaline, Lithium, Manganese Dioxide, Silver Oxide, and Zinc-air. In the rechargeable category we have types such as Nickel-Metal Hydride (Technical 2002) .

Carbon-Zinc batteries provide an inexpensive power source for devices that require a light to moderate drain. Characteristics of these battery types vary in rate and rate capability, as well as ampere-hours. The voltage versus service hour plot has a very prominent slope and would not be good for devices that require a constant source of power. These batteries are also easily affected by temperatures and storage conditions, as well as being susceptible to leakage if not removed after exhaustion of service life (Technical 2002) . It appears that this type of battery would not be a good source for our design because temperature can change quite a bit throughout the course of a day, and we need a steady source of energy. Alkaline batteries are designed for a high rate portable power source. They provide an economic source for devices that require high current and continuous use. They are relatively insensitive to discharge rate and duty cycle. They have better discharge rate than Carbon-Zinc and a more stable voltage supply over time. However their discharge curve is still sloped and may not be suitable for some applications (Technical 2002) . The discharge curve for this type of battery may have a small enough slope as to not affect our device. So this type of battery may be a good choice. They are available in voltages ranging from 1.5 to 12 V. Lithium batteries outlast premium alkaline batteries substantially over a wide range of applications. They provide a relatively flat discharge voltage profile over a wide range of discharge conditions. They can have a shelf life up to ten years. Lithium batteries can operate in temperatures ranging from -40ºC to 60ºC. These batteries are also classified as Non-Hazardous Solid Waste so there is no special method of disposal needed (Technical 2002) . This battery is light weight and a 9 V battery can provide up to 1200 mAh. Lithium batteries sound great for our application. Seems to suit just about all of our needs.

60

Page 66: Acoustic Remote Sensing

Manganese-dioxide batteries provide an economical power source for devices that do not require flat voltage discharge curve characteristics. They should only be used in applications that are recommended by manufacturers. They do have a good resistance to shock, vibration, and acceleration (Technical 2002) . This type of battery does not meet the specifications for our design. Silver-oxide batteries are similar to Manganese-dioxide batteries except that they have a flatter discharge curve. These batteries are mainly used in small devices such as watches and calculators (Technical 2002) . These do not meet our specifications because they are mainly designed to produce 1.5 V. Zinc-air batteries are mainly designed for hearing-aid applications. They have the highest capacity to volume ratio for miniature batteries. They can be activated by removing an adhesive covering to allow air to flow into the battery housing. They must have oxygen to operate. They also are mainly designed for 1.5 V systems (Technical 2002) . The other option of battery would be a rechargeable battery. Although they are more expensive initially requiring the purchase of a charger, they can be more cost effective in the long run for applications that require frequent battery changes. The most common type of rechargeable batter is the Nickel-metal Hydride battery. This battery has improved capacity ratings from the Nickel-Cadmium batteries that were the popular rechargeable batteries a few years ago. Under most conditions the voltage characteristic curve is relatively flat. This is suitable for most electronic applications. They can be reused over and over again and recharge within a few hours. The downside to this type of battery however, is that its nominal voltage for a 9 V battery is only 7.2 V. Also, they can only provide around 150 mAh for a 9 V supply (Technical 2002) . This is too small for our application. 4.6.2 Battery Selection After consideration of different battery types, it is clear that Lithium batteries outperform the other types and are best suited for the Acoustic Remote Sensing device. Next we will obtain specifications of Lithium batteries from different companies and compare prices and availabilities.

61

Page 67: Acoustic Remote Sensing

Table 4.6: Lithium battery comparison table

Information obtained from Energizer, Panasonic, Ultralife, Sanyo, and Kodak companies

Ener

gize

r

L522

1200

9

34.4

26.3

16.9

48.5

$6 (2

)

Pana

soni

c

BR-C

5000

3

42.0

-

26.0

dia

50.5

$22.

95 (1

)

Ultr

alife

U9V

L-BP

1200

9

61.2

26.5

17.5

49.2

$5.8

5 (1

)

Sany

o

CR

2350

0SE

5000

3

42.0

-

23.0

dia

50.0

-

Koda

k

K223

LA

1550

6

37.0

34.1

19.5

38.0

$6.8

5 (1

)

Koda

k

K123

LA

1550

3

16.0

-

17.0

dia

34.2

$3.7

4 (1

)

Pana

soni

c

CR

3032

bu

tton

cell

500 3 7.1 -

30.0

dia

0.2

$6.9

9

Pana

soni

c

CR

2354

bu

tton

cell

560 3 5.9 -

23.0

dia

0.5

$4.9

9

Bra

nd

Mod

el

Cap

acity

(m

Ah)

Nom

inal

Vo

ltage

(V

)

Wei

ght

(g)

Leng

th

(mm

)

Wid

th

(mm

)

Hei

ght

(mm

)

Cos

t (Q

ty)

62

Page 68: Acoustic Remote Sensing

Here is a list of some rechargeable Ni-MH batteries: Table 4.7: Rechargeable batter comparison table

Brand Radio Shack Radio Shack Radio Shack Radio Shack

Model 23-331 23-529 23-519 D Cell

23-520 C Cell

Capacity (mAh) 1600 150 4500 3000

Nominal Voltage

(V) 9.6 8.4 1.2 1.2

Weight (g) 340.0 60.0 73.0 60.0

Length (mm) - 25.0 - -

Width (mm) 68.0 17.0 34.2 26.2

Height (mm) 100.0 50.0 61.5 50.0

Cost (QTY)

$24.99 (1)

$8.99 (1)

$11.24 (2)

$11.24 (2)

Information obtained from Radio Shack.

After comparing several battery choices, it seems that the best choice of battery for our main supply is the Lithium Ultralife U9VL-BP, or rechargeable Radio Shack 23-331. If we need 2400 mAh, we would require two 23-331 rechargeable battery packs or two Ultralife U9VL-BP batteries. Because the capacity of these batteries alone does not meet the 2400mAh requirement, we can connect two of these batteries in parallel in order to double the capacity. For the rechargeable battery pack, we would need an additional two batteries so that we could still operate the device while the first two were recharging. So the total initial cost for buying the 23-331 power supply would be $24.99 x 4 plus $9.99 for the charger. This would be a total of $99.96 + tax. The second option would initially cost $5.85 x 2 = $11.70 plus tax. The initial cost would be much cheaper to go with the Ultralife battery. After a brief economic analysis, if the rechargeable battery packs last for just one year, our total cost for the year would still be $100.00 for batteries. But if we have to replace the Lithium batteries every twenty-four hours, in one

63

Page 69: Acoustic Remote Sensing

year it would cost $11.70 x 365 = $4270.50. This is a very large difference in annual cost. So it would be better to use the rechargeable packs if our device was going to be used on a daily basis. For our prototyping purposes, we will choose to go with the Ultralife U9VL-BP batteries because we expect at most the use of 6 batteries. We are choosing Panasonic’s CR2354 button cell for the back up battery needed for the DS1678 real time clock/calendar. The capacity for this battery is so good that one battery would most likely last for years. 4.7 Power Supply Configuration Now that we have chosen our power supplies, we need to figure out how we can supply 5 V to our devices from a 9 V battery. One option would be to do a simple voltage divider using two resistors. However, this can prove to be unreliable because of transistor tolerances and because a battery’s voltage output can fluctuate. Another option would utilize a voltage regulator. A voltage regulator takes a relatively wide range of voltage inputs, and outputs a stable regulated set value. In the case of our device, we need a regulator that can accept a 9 V input and output 5 V. Table 4.8 displays a few regulators we considered for our device. Table 4.8: Voltage regulator comparison table

Manufacturer Model Input

Voltage Range

Output Voltage

Maximum Current Output

Cost

National Semiconductor LM7805C 7.5 to

35.0 V 4.8 to 5.2 V 1 A Discontinued

National Semiconductor LM109 7.5 to

35.0 V 4.8 to 5.2 V 1 A $5.25

(500) Texas

Instruments UA7805CKC 7.0 to 25.0 V

4.8 to 5.2 V 1.5 A $17.50

(50) Texas

Instruments UA7805CKTE 7.0 to 25.0 V

4.8 to 5.2 V 1.5 A $960

(2000)

Information obtained from National Semiconductor, Inc. and Texas Instruments.

The more current the regulator can supply, the better it is for our project design. Therefore we have chosen to go with Texas Instruments as our supplier for 5 V regulators. The UA7805CKTE is designed with a heat sink. Heat sinks increase the efficiency by dissipating and reducing the heat loss during energy transfer. This makes the UA7805CKTE look better than the UA7805CKC with the plastic flange mount. But after looking at their price and availability it seems the minimum order they sell of UA7805CKTE is 2000 units at 48 cents each. This is far more than we would ever need. One good thing is that Texas Instruments will send a maximum of 6 samples per week. If we put in enough requests, we could most likely obtain enough regulators to build several more projects. We ordered samples from them for our prototype design. After ordering the samples, come to find out, the UA7805CKTE has short surface mount

64

Page 70: Acoustic Remote Sensing

pins. So, because it is hard to solder and they do not sell them in small numbers, we have decided to go with the UA7805CKC. They do have long dual in line package pins and also can be ordered in a package as small as 50 units at 35 cents each (UA7805 2002) .

Now that we have our 5 V regulator chosen, we have to consider a few components to add to the regulator for proper operation. From Texas Instruments data sheet, the UA7805CKC works best with capacitors attached to both the input and the output lines down to ground (UA7805 2002) . This will reduce the fluctuation in voltage supply that a battery may experience. Also, since our microprocessor needs a more steady voltage supply than any other device, we are using a separate regulator just for our PIC16F877. So we will have two regulators; one to step down the voltage for the microprocessor and the other for supplying voltage to the transducer, temperature sensor, real-time clock/calendar, LCD module, LCD driver, and CompactFlash card. For the microprocessor regulator we will also choose higher capacitor values to connect to the input and output of the regulator to reduce voltage fluctuations. We will use a 3.3µF and a 1µF capacitor in the configuration seen in Figure 4.2. Figure 4.2: Voltage regulator configuration for supply to the microcontroller

UA7805CKCInput Voltage Output Voltage

3.3µF 1µF

1N4001

A 1N4001 diode is added between the output and the input for reverse bias

protection. We found this configuration in Texas Instruments data sheet also. If the input voltage to the regulator collapses faster than the output voltage, the emitter-base junction could break down and be damaged (UA7805 2002) . For the other regulator we will use smaller capacitance values, 0.33 µF and 0.1µF. Figure 4.3 shows the configuration with the smaller capacitor values.

65

Page 71: Acoustic Remote Sensing

Figure 4.3: Voltage regulator configuration for supply to all circuit devices excluding the microcontroller

UA7805CKCInput Voltage Output Voltage

0.33µF 0.1µF

1N4001

The smaller capacitances are chosen because a very large capacitance is not needed for the devices the regulator is supplying. Smaller capacitance values are usually more common and sometimes cost less. We will use Aluminum-Electrolytic capacitors because they have a long life span and have stable temperature characteristics. The input capacitor is larger than the output capacitor to allow the input side of the regulator to store more energy in order to attempt to keep current flowing in the correct direction.

We have discussed the voltage supply for everything except the operational amplifier. For supplying voltage for the op-amp, a simple circuit resistor circuit will be needed in order to supply a positive and negative voltage to the amp. From our source of 9 V, we will be able to obtain +4.5 V and –4.5 V with the circuit shown in Figure 4.4. Figure 4.4: Op-amp supply voltage circuit

66

Page 72: Acoustic Remote Sensing

Voltage is merely a reference from one point to another. With ground in between

the two 1kΩ ± 1% resistors, the voltage from positive terminal of the battery to this ground connected to the positive terminal of the op-amp is 4.5 V. Just in the same manner, the voltage from the negative terminal of the battery to the same ground is –4.5 V. 4.8 Date/Time Recording

In order to record a date and time for each object that the Acoustic Remote Sensing device detects, we will need a calendar and a clock. A calendar can be kept in several ways. One way is to write a calendar program that can be stored in the microcontroller. By using one of the microprocessor’s internal clocks with 32.768 kHz crystal, we could develop a program that changes days when the timer counts twenty-four hours. However, a calendar program is not very simple. You have to account for leap years and the different number of days in every month. Therefore a program of this sort would take lots of programming memory as well as processing power from our PIC16F877. Therefore, we sought out an alternative. After browsing the Internet, we found two real-time clock/calendars. One is the PCF8563 made by Philips Semiconductors, Inc. This module has very low power consumption, programmable clock output, interrupt output, and a low voltage detector. All addresses and data are transferred via I2C bus with a maximum speed of 400kbits/second (PCF8563 2002) .

We also found the DS1678 Real Time Event Recorder manufactured by Dallas Semiconductor (Maxim IC). The DS1678 is a real-time clock that records the time and date of non-periodic interrupts. This device has the following features:

• Records second, minute, hour, date, day of the week, month, year and century of the first event

• Subsequent events trigger recording from the 16-bit elapsed time counter into the 2048 bytes of event log memory

• Allows for 1025 events to be logged in read-only non-volatile memory • All values are handled in BCD format • Year 2000 compliant • Controlled with I2C bus • Supply voltage 5 V • 3 V back up battery connection

After careful consideration, we have chosen to go with Dallas Semiconductors’

DS1678. They provide great support and also provide free samples. This module is essential to our project, as it will record the time of detection onto the Compact Flash card. Time is accurately kept by using a 32.768 kHz quartz crystal. The 32.768 kHz crystals are known as clock crystals for a good reason. The instructional cycle for one of these crystals is 122.0703 µs. That does not sound good, but consider that there will be 1 / 122.0703 µs = 8192 instruction cycles in 1 second. This will give us an accurate timekeeper. With a 150 µA supply for high accuracy, we can obtain accuracy up to 1

67

Page 73: Acoustic Remote Sensing

minute per year. However, this error value would be true if our device operated at a constant temperature. After reading Maxim IC’s data sheet, they discussed how crystal frequency changes with temperature. The data sheet gives accuracy of the timer subjected to its maximum and minimum operating temperatures from -40°C to 85°C as ±4 minutes per year. Since our device will be subjected to temperatures in the range of 0°C to 40°C, we could still obtain accuracy within 4 minutes per year. The crystal oscillator must have a capacitance of 6pF. We have chosen to use Maxim IC’s DS32KHZ crystal. This crystal is specifically designed for use with their Real Time Clocks and can be used without any calibration required. It has low power consumption and can also come in a DIP package for easy soldering (Real Time 2002) . The DS1678 is easily interfaced with only three pin connections from the microcontroller. Figure 4.5 shows the pin layout of the DS1678. Figure 4.5: Pin assignment for DS1678 Real Time Event Recorder

Adapted from Maxim Integrated Products. The X1 pin is the crystal input and X2 is the crystal output. The application data sheet notes that we must etch a guard ring around the connection of the crystal to pins X1 and X2. This guard ring is connected to ground and it protects these high impedance pins and the crystal area from high frequency signals that can alter the crystals operation. The pin labeled VBAT is connected to 3 V battery back up and GND is connected to ground. VCC is connected to 5 V supply while the three pins INT, SCL, and SDA are used to control the device (Real Time 2002) .

INT is the interrupt input/output pin that will be activated by the PIC controller to

notify the Real-Time Clock (RTC) that the first event has occurred and should be logged. Once the pin is activated, the event will be recorded into Event Log Memory

68

Page 74: Acoustic Remote Sensing

and the Counter Register will be incremented by one. INT can be activated by a rising edge, falling edge, or both. We will choose to activate with rising edge detection (Real Time 2002) .

The pin SCL is the 2-wire Serial Clock Input. This is the serial clock input for the

2-wire synchronous communication channel. This connection requires an external pull up resistor. The SDA pin is the 2-wire Input/Output. It is the data input/output pin for the 2-wire synchronous communication channel. This connection also requires an external pull up resistor. We will use a 4.7kΩ resistor connected to the 5 V VCC (Real Time 2002) .

The operation of this device is simple. When the first event occurs, the device logs the second, minute, hour, date, day of the week, month, year and century of the first event. Then the 16-bit counter is activated after all subsequent events, which counts the elapsed time since the last event occurred. This time is then stored into event log memory. Three resolutions can be obtained with this device. You can obtain resolution down to the hour with a maximum of 7.5 years between events, a resolution down to the minute with a maximum lapse of 45.5 days between events, or down the nearest second allowing a maximum of 18.2 hours between events. Choosing the resolution for the device is simple because our device will only be operating a minimum of twenty-four hours and need a resolution to the nearest second. We will activate the INT pin using rising edge detection. This means that after every INT signal is received, the device will store the elapsed time from the last INT signal into event log memory (Real Time 2002) .

The DS1678 operates as a 2-wire serial bus slave device to which data is transferred most significant bit first. It has an automatic low voltage detector that automatically switches to battery backup if the input voltage drops below 1.25 x VBAT. It will also transfer back to VCC when input rises above VBAT + 0.2 V. All the events that are logged into the event log memory can be accessed through the serial data line, SCL. The event log memory can either be accessed while the device is still counting or after the mission in progress has ended. The clock can either be stopped after the maximum 1024 events have been logged or it can roll over and overwrite the previous data (Real Time 2002) . We will most likely have the clock stop if a maximum number of events occur.

69

Page 75: Acoustic Remote Sensing

CHAPTER 5

BOX DESIGN

This chapter will discuss the container that will hold all of the electrical components, the box design. The box will be submersible and non-corrosive. The possible materials available for the design will be considered and chosen based on how they meets the specified requirements.

70

Page 76: Acoustic Remote Sensing

5.1 Introduction The container for our device is very important. We cannot just enclose our

circuitry in just any material and toss it in salt-water. The material we choose for our design must meet several specifications. First of all, it must be waterproof. There are many solid materials that are non-porous and would do a great job keeping water molecules from penetrating the interior, and with many different sealants we could make a pretty descent watertight container. But being waterproof is not the only requirement; our container must also be highly resistant to corrosion. 5.2 Types of Materials

There are many types of metals like chrome brass, chrome copper, nickel brass, and polished copper that claim to be rust proof, but this is based on the material being in a mostly dry, salt-free environment. When placed directly in salt water for a long period of time most of these metals will eventually corrode, rust, and need to be replaced. So this steers us into the direction of plastics. Plastics are flexible, mostly non-conductive, corrosion resistant, and also provide great waterproofing capabilities. But the fact is that most plastics are not very rigid. We need a material that can withstand very harsh conditions, mistreatment, and large forces of pressure. Our device might be dropped on the ground, chewed on by fish or other aquatic life, or even run over by boats. We found some rigid materials from GE Structured Product’s web site. Some materials that seemed really promising were, GEPAXTM, LEXAN®, LEXGARD®, NIMpact®, ULTIM®, and VEROLITE® (General Electric 2001) . 5.3 Material Comparison Each of the materials listed in the previous section has different characteristics. Some of the characteristics that we need to consider are impact resistance, chemical resistance, temperature resistance, colors available, clarity, and weatherability. Impact resistance is important because of the reasons mentioned in the previous paragraph. Our device casing needs to provide protection for the internal electric components. Chemical resistance and weatherability are two factors that give us some insight on how non-corrosive the material would be to salt water. Salt water can be a harsh detergent on many materials, and for durability purposes we need a material that can withstand these conditions over a long period of time. So the more weatherable and resistive the material is to chemicals the better. Another important characteristic is temperature resistance. Although our device will only be subjected to the temperatures of warm Florida waters, about 10°C to 35°C, the temperature changes might have slight effects on the electronic components of our device. We would like to have as constant an operating temperature as possible for all the components except the temperature sensor of course. Additionally, clarity and color availabilities are also considered. Our sponsor has mentioned that for application purposes our device needs to be as undetectable as possible from campers, boaters, swimmers etc. If our device is unseen, more than likely it will not be tampered with. Also, if boaters know that a device is monitoring their activities, they will be more prone to deviate from their normal speed

71

Page 77: Acoustic Remote Sensing

and path of travel. We want to be able to monitor the typical boat traffic as it usually is. Because our device will be at a rather shallow depth, the choices of color and clarity will affect the amount of sunlight that is reflected from the material. We have to keep in mind that even though a darker color may be less detectable, it will absorb more heat. The following table is a comparison of the few characteristics listed above for several materials made by General Electric Company’s GE Structured Product line.

From Table 5.1, it seems that the two best materials that suit our design criteria are ULTIM® and LEXAN®. ULTIM®, or Ultem-Polyetherimide (PEI), is an amorphous thermoplastic that maintains its strength and rigidity at high temperatures. Its electrical properties are maintained throughout temperature and frequency variations. Chemical resistance and FDA compliance make it an ideal material for numerous applications in the medical and food processing industries. In addition, its exceptional flame retardance supports aircraft/aerospace applications (General Electric 2001) .

LEXAN® is a polycarbonate sheet that offers the highest impact strength of any

transparent glazing product. It has 250 times the impact strength of glass and 30 times that of acrylic. The entire family of LEXAN® polycarbonate sheet products offers lightweight, energy efficiency and excellent weatherability, plus abrasion resistance and clarity rivaling glass (General Electric 2001) .

Our sponsor, Paul Anderson, notified us that he has LEXAN® readily available in the machine shop at UCF. Because we can acquire this material very easily we have chosen to go with clear LEXAN®. We think that the clear LEXAN® will be good for our prototype because it will allow for easier presentation. With a clear casing, all our internal electronics can be easily inspected during presentations.

72

Page 78: Acoustic Remote Sensing

Table 5.1: Box design material comparison table

GEP

AXTM

Exce

llent

Exce

llent

Goo

d

Exce

llent

Fair

Yes

LEXA

Exce

llent

Exce

llent

Fair

Fair

Exce

llent

Yes

LEXG

ARD

®

Exce

llent

-

Goo

d

-

Exce

llent

No

NIM

pact

®

Exce

llent

Exce

llent

Fair

Fair

Exce

llent

Yes

ULT

IM®

Exce

llent

Exce

llent

Exce

llent

Fair

Fair

Yes

VER

OLI

TE®

Exce

llent

Exce

llent

Goo

d

Goo

d

Goo

d

Yes

Mat

eria

l

Impa

ct

Res

ista

nce

Tem

pera

ture

R

esis

tanc

e

Che

mic

al

Res

ista

nce

Wea

ther

-ab

ility

Cla

rity

Col

ors

Ava

ilabl

e

Information obtained from GE Structured Products

73

Page 79: Acoustic Remote Sensing

5.4 Box Building Considerations

Now that we have chosen a material, there are still two more concerns. Because LEXAN® is manufactured in large sheets, how will we be able to design a box? Also, how will we be able to make our flash card and battery easy to get to for removal or replacement? The first question can be easily answered. Mr. Anderson told us that cutting and drilling the material would be very easy. The machine shop in the Engineering II building at UCF has a CNC milling machine. A CNC milling machine is a programmable automated cutting tool. You can build almost any three dimensional object with ease. Just specify x, y, z coordinates of each cut and drill hole, then the automated device will work its wonders with little or no further user input.

Our device has to be small enough for one person to carry. We have limited

ourselves to a size of no larger than 6 in. by 12 in. by 18 in. Once we have cut out a box of dimension that fit these criteria, we will need to drill holes for mounting the circuit boards, battery mounts, lid fasteners, and temperature sensor.

Mounting the temperature sensor is another key issue. This device monitors the

surrounding temperature via direct contact. We need to measure the water temperature, and because LEXAN® is resistive to temperature, the water temperature cannot be measured accurately from within the device. The temperature sensor itself is not fully waterproof either. However, as long as the sensor’s metal pins are not in contact with the salt water, the device should be okay. We plan on drilling a hole on either the side or bottom of our casing in order to allow the tip of the temperature sensor to be in contact with the surrounding water. We will need to apply sealant around this hole to keep the water from leaking into the box.

Our other concern, making the flash card and batteries accessible, can be taken

care of by allowing the casing to have a removable cover. We will have a lid that can be tightly secured by either screws or bolts. We think that galvanized wing nuts would allow for easy removal of the cover without the need of any tools. In addition, the galvanizing should protect the nuts and bolts from premature corrosion. Between the lid and the casing we will need a seal as well. We cannot use permanent sealing because the lid will need to be removed regularly. We can either use a rubber seal or cork. We could use the CNC machine to mill a trench on both the lid and the top of the casing where a thin strip of rubber could be laid within. We could also cut out either a rubber or cork gasket. The previous prototype used a cork gasket and we think that should do the job.

Mounting the transducer to the box is another design issue. The transducer

needs to be located where it has direct contact with the water. The best mounting position would be flush with the outside edge of the box. If it protrudes out of the side, there would not be enough rigid support for the transmitting cone. Also, it would be at risk of getting damaged. If it where flush against the inside edge of the box, the transmitted signal may get reflected off the edges of the box and change the transducer’s beam pattern. This would also reduce the receiving sensitivity as well.

74

Page 80: Acoustic Remote Sensing

There is also the option of designing an acoustic horn to mount on the outside of the box. This allows for more directivity and sometimes an increase in transmitting intensity. However, this could have adverse affects on the receiving sensitivity. We will therefore mount the transducer so it is flush with the outside wall and we will not use an acoustic horn. We will also have to make sure and apply sealant around the edge of the transducer to keep water out of the box.

75

Page 81: Acoustic Remote Sensing

CHAPTER 6

PUTTING THEM ALL TOGETHER

This chapter will show how the device will be put together. Block diagrams of both the software and hardware implementation will be presented. This chapter will present an overall schematic of the device.

76

Page 82: Acoustic Remote Sensing

6.1 Putting Them All Together 6.1.1 CompactFlash All the major components have now been identified. It is time to put them all together for the bigger picture. The CompactFlash card will take up most of the interface I/O pins on the microcontroller. The CompactFlash will be running in Common Memory Mode. In this mode, the card would only need 8-bit data bus, and few control and peripheral lines. Three of I/O’s will be used for addressing (A0 to A2) on the CompactFlash. The other 8 I/O’s will be for data lines (D0 to D7) to CompactFlash. The peripheral lines are Card Detect (CD1 and CD2), Write Enable (WE), Card Enable (CE1 and CE2), Output Enable (OE), Ready/Busy (RDY/BSY), and Reset (RESET). Some of these outputs can be eliminated, since some are features that we might not need. One of the Card Detect (CD1 and CD2) lines can be removed, since they both are connected to ground internally, only one is needed to determine if the card is present. From looking at extensive truth tables from CompactFlash Association, and SANDISKTM CompactFlash specification, we determined that we only need one Card Enable line (CE1). We do not need CE2. CD1 line can also be let alone, but we think it is a good feature to have card detect, so the 16F877 will not write unless the card is there. The RESET line can also be disregarded. This line is for resetting the controller inside the CompactFlash. Again, we think that having 16F877 reset the CompactFlash at the power up is another nice feature. Ready/Busy is good to have as indicator to microcontroller before sending another set of data. So the essential lines are data lines (D0-D7), address lines (A0-A2), Card Detect (CD1), Write Enable (WE), Card Enable (CE1), Output Enable (OE), Ready/Busy (RDY/BSY), and Reset (RESET). Total usage is 17 I/O pins out of 33 I/O pins. The eight data lines (D0-D7) will be configured as output for writing the data at port D. Port D is an 8-bit wide parallel port, and it can be used in Parallel Slave Port (PSP) mode. We are not going to use PSP mode, but we are going to use parallel data scheme to the CompactFlash. The reason is if PSP mode is used, port E, which has 3 pins, will be automatically configured for Read, Write, and Chip Select lines. Port E will be used for address lines connecting to A0-A2 on CompactFlash. The CompactFlash does have Output Enable (OE), and Read Enable (RE) lines, but the timing setup for CompactFlash was not for PSP type parallel. Therefore, using 16F877 in PSP mode is pointless to communicate with CompactFlash. 6.1.2 Crystal Oscillator Two crystals would be needed to run a master clock, and an internal timer. The master clock will be operating at 20 MHz for shortest instructional cycle time, if operating at 20 MHz, the instructional cycle would be at 200 nS. Although operating at lower master clock frequency would save power, we decided to go to the maximum capability of the microcontroller. Power saving can be done through some other means rather than just operating at lower clock speed. The device can use SLEEP mode when 16F877 is not doing any task. For example, after the ping the device can be in SLEEP

77

Page 83: Acoustic Remote Sensing

mode since it is just waiting for the ping to return. The interrupt request routine can be made such that it will wake up upon the echo coming back or after a certain time period. Besides, the power difference at different clock speed is in order of about 10 to 20 milliamps, so it is little sacrifice for speed. 10 to 20 milliamps is about as much power it takes to light a Light Emitting Diode, LED. The second oscillator for timer1 will be for Capture, Compare, PWM port. Both CCP ports will use either internal clock signal (in our case, this will be at 20 MHz since we chose external oscillator) or from another external crystal oscillator. As mentioned before, our project is time sensitive, so accurate time is needed. We are choosing a crystal at 400 kHz. The reason is that timer1 is a 16-bit counter that can count from 0h0000 to 0hFFFF. The counter will increase every instructional cycle (through 20 MHz master clock) or external timer1 oscillator input. The register can be set in T1CON:TMR1CS <1> to 1 to enable external clock source at pin 15, RC0/T1OSO/T1CKI. If this bit is set to 0, it will increment every 20MHz/4, or 200 nS. The reason we need another external clock source might not be so obvious, but as we inspect the counter we notice that it can count 0hFFFF times or 65535 times. The maximum time before the timer1 will overflow is 65535 X 200 nS = 13.107 mS. The prescaler can be used to extend that time. The prescaler at T1CON: T1CKPS1:T1CKPS0 <1:0> can be set at the highest value at 1:8. The timer will count every 8 instructional cycles, that extends the time before overflowing to 13.107 mS X 8 = 104.86 mS. This does not seem to have anything wrong, but considering our transducer with range of 500 meter, and the average velocity of sound at 1500 m/s, the sound would only be able to travel 1500 m/s X 104.86 mS = 157.29 meters. The sound has to travel back and forth so the range is reduced by half, becomes 78.65 meters. This meets our specification, but it is not maximizing the devices’ capabilities. As mentioned before, we calculated time travel back and forth at 500 meters comes out to be about 0.666 second. So timer1 would have to overflow at 0.666 second after ping is sent out. Once timer1 overflow, then it can be checked as no target detection, and more importantly, no distance calculation, no date/time stamp. After giving enough time for settling time of all devices, we will then send another ping. At this point we will demonstrate how we came up with 100 kHz crystal frequencies. We know that we need 0.666 seconds before it overflows, and we know that the counter can count 65535 times before overflow. Each increment would have to change at 0.666/65535 = 0.000010163 second. We will inverse that to get the actual crystal oscillator, which is at 98.396 kHz. The more realistic value would be at 100 kHz. To check the answer, the period of the clock would be 1/100000 = .00001 second. The clock would overflow at 65535 X .00001 = 0.65535 second. Note that when use internal clock, the timer1 will increment at FOSC/4 or 200 nS while using external clock source will increment every rising edge of the clock source input.

78

Page 84: Acoustic Remote Sensing

6.1.3 Ultrasonic Transducer The one of the most important pieces of the project is the transducer. Fortunately, this will be a major upgrade from the previous generation in terms that it is much more efficient, and sensitive. The transducer barely needs a driving circuit because it is piezoelectric in nature. All it needs is a 5 V supply to it, and it will work. At the transmission, it needs only about 125 mA at 5 V compares to the previous driving circuit will generate 400 V and 2 A. The first generation takes almost 800 W of power at transmission. Our transducer only takes 0.625 W. This is our major power advantage. The driving circuit is no more than an electronic switch that will simply turn on when the microcontroller sends a ping. The receiving circuit is a variable gain amplifier as mentioned in digital potentiometer section. The output from the amplifier would then be sent to CCP port on the microcontroller. Once CCP port receives target detection, it will send an interrupt to timer1. Timer1 will then measure the time elapsed since ping was sent out, get the immediate temperature. The distance would then be calculated. Time/date, temperature and distance will then be recorded onto CompactFlash. 6.1.4 Microcontroller Microcontroller is the brain of our project. It will be very complicated to explain every connection on 40 pins on sheets of paper. Some of the connection has already been described. Rather, the schematic will be shown. At this point, the development of the microcontroller, and more in depth operation of it will be presented. 6.1.5 Microchip’s 16F877 Features and Specifications Core Features:

• 20 MHz 8-bit bus RISC CPU • 200 nS instruction cycle • 8K x 14 words FLASH program memory • 368 x 8 RAM Data Memory • 256 x 8 bytes EEPROM memory • Low power high speed CMOS/EEPROM • Selectable oscillator options • 14 sources interrupt capability • Power-on Reset (POR) • Brown-out Reset (BOR) circuitry • SLEEP mode • High Sink/Source current @ 25 mA • Low power consumption • In Circuit Debugging • In Circuit Serial Programming

79

Page 85: Acoustic Remote Sensing

Peripheral features:

• 3 Timers plus Watchdog Timer (WDT) • Two Capture, Compare, Pulse Width Modulate (CCP) ports • 8-channels 10-bit A/D converter • SPItm and I2Ctm serial ports • Universal Synchronous Asynchronous Receiver Transmitter (USART) • Parallel Slave Port (PSP) with external Read, Write, and Chip Select • Selectable operating frequency, maximum of 20 MHz • 35 instructional commands • 8 levels operating system stack

For the development of Microchip’s microcontroller, a programmer is required. Microchip provides a free assembler, MPLAB IDE. This is also a simulator to a specific chip. The programming will be done in assembly, but other languages are also options. The microcontroller programmer can be purchased through Microchip or third party supplier. Microchip recommends PICSTART PLUS since it can program wide range of microcontrollers for a low cost. Senior Design lab already has PICSTART PLUS kit plus BASIC PRO compiler, and soon to purchase C compiler. 6.1.6 Setting Up Registers First step to programming is to decide which port we will use, the purpose, its configuration, and external connection. Once the port configuration is determined, the registers have to be loaded accordingly. Microchip 16F877 has two sets of registers. One is General Purpose Register, and another is Special Function Register. To put in plain words, Special Function Register (SFR) is for configuration and data of peripheral ports while General Purpose Register (GPR) is for general interrupts, and flags. The registers and data are in four different banks of memory, bank0 to bank3. The access mode to these banks can be either direct addressing or indirect addressing. The bank can be selected at STATUS: IRP<7> for indirect addressing, and STATUS: RP1:RP0 <6:5> for direct addressing. Probably the most important is when 16F877 first power up, the register will be at default, and we have to set the register to the configuration that we need. Table 6.1 shows the status register. Table 6.1: Status Register (Address 03h, 83h, 103h, 183h) Bank 0 to 3 7 6 5 4 3 2 1 0 IRP RP1 RP0 *TO* *PD* Z DC C Bit 7 IRP Register Bank Select Bit (indirect addressing only) 0 = bank 2,3 (100h – 1FFh) 1 = Bank 0,1 (00h – FFh) Bit 6 - 5 RP1:RP0 Register Bank Select Bit (Direct Addressing) 11 = Bank3 (180h – 1FFh) 10 = Bank2 (100h – 17Fh)

80

Page 86: Acoustic Remote Sensing

01 = Bank1 (80h – FFh) 00 = Bank0 (00h – 7Fh) Bit 4 *TO* Time Out Bit 1 = After Power-up, clear watchdog timer or sleep 0 = a WDT timeout occurred Bit 3 *PD* Power-down Bit 1 = After power-up or by CLRWDT instruction 0 = By SLEEP instruction Bit 2 Z Zero Bit 1 = Zero is result of arithmetic operation 0 = Zero is not a result of arithmetic operation Bit 1 DC Digit Carry/*Borrow* 1 = A Carry out from 4th low order occurred 0 = No carry out from 4th order occurred Bit 0 C Carry/*Borrow* Bit 1 = A Carry out of MSB occurred 0 = No carry out of MSB occurred About a little over fifty registers are in 16F877, so we will only stress on the essential ones. Many registers’ bits are for configuring the clock to have either rising edge detect or falling edge detect. Another type of configuration for the timers is prescalers. These have already been explained above. As mentioned before, we will be using one of the CCP ports. The Capture, Compare, PWM port requires to be used with timer1 if used in either capture or compare mode, but for PWM generation, it will need timer2. This configuration cannot be changed. We calculated the crystal so the timer1 counter will overflow at about 0.666 second. This requires that once timer1 overflows, it will generate interrupt to the microcontroller to give the condition “no target detect”. If that is established, the 16F877 will wait until all components stabilize, and then send out another ping. Two registers must be set to generate the interrupt. First, 16F877 must enable peripheral ports interrupt to enable at INTCON: PEIE<6>, Interrupt Control register at bit 6, Peripheral Interrupt Enable bit. Second, CCP and timer1 must generate interrupt either for detection or non-detection. These can be set at PIE1: CCP1IE<2> for CCP, and PIE1: TMR1IE<0> for non-detection, Peripheral Interrupt Enable register at CCP1 Interrupt Enable bit, and Timer1 Overflow Interrupt Enable bit respectively. This is done so that if CCP detect a signal, it will then start the distance calculation, acquire temperature, and acquire time and date, and then record to CompactFlash routine. The CCP and timer0 interrupts have now been established. The CCP port itself now has to be configured for Capture mode. This will be done at CCP1CON: CCP1M3: CCP1M0<3:0>, CCP1 Control at bit 0 to 3, for CCP Mode select at 0101. This will set CCP1 to detect in Capture Mode, every rising edge. Numerous modes of operations are configurable for CCP port. After setting CCP1 to be in Capture Mode, we will also have to generate interrupt once CCP1 detects a target. This interrupt enable will be set at PIR1: CCP1IF<2>, Peripheral Interrupt at bit <2>, CCP1 Interrupt Flag bit. If CCP1

81

Page 87: Acoustic Remote Sensing

operates in Capture Mode, it captures timer1’s value at that time; hence the time difference between the ping signal was sent out to the target detection time. This value will be used to calculate distance. It is critical to know that what CCP operating mode is utilized because if PWM mode is used, this register will be completely neglected. The CCP port is now ready to be used, but we still have CompactFlash, temperature sensor, and digital potentiometer ports still to be configured. The CompactFlash will be occupying at port D, port E, and partially port B. Port D will be our data bus line while port E is for addressing. Port E will be for peripherals of CompactFlash such as card detection, CompactFlash controller’s reset, and ready/busy signal. Since we are not going to use Parallel Slave Port mode (PSP), we do not have to set that up. Instead there is really nothing to setup, but we have to note to important registers associated with port D. The first one is PORTD register, which is a data latch when written, and will acquire the data at all 8 pins when read and save it on this register (1 is for input, 0 is for output). Second is TRISD register, which is a data direction control register. Port E, the address lines, will be configured the same way as port D, as a regular I/O line. The associated registers are PORTE, and TRISE which does exactly same thing as PORTD, and TRISD registers, but they are for port E, and are 3-bit wide. Port B will also be configured as regular I/O also. The temperature sensor, digital potentiometer, and time/date module can be used on the same port, I2C. I2C was originally developed by Philips Corporation 20 years ago. It was meant to be used with appliances, but lately it has become a popular bus line for microcontrollers, other embedded systems, and their peripherals. The 16F877 has I2C output that can operate as Master or Slave Mode. The good thing about this port is that instead of having many I/O pins taken away by hooking up each one separately, we can multiplex or use a port switcher for I2C. This allows us to connect up to 8 devices through the use of only 2-wires plus ground. The temperature sensor can also be connected this way, but we are choosing onboard ADC. 6.1.7 I2C Mode Operation I2C is a bus invented by Philips Corporation. This bus has been around for about 20 years, so plenty of I2C devices are available. Another bus that is popular in microcontrollers and DSP processors is SPI bus which 16F877 also supports. I2C has two modes, slave and master mode. The devices will be operating in slave mode. The 16F877 will be operating in master mode to control all the devices’ functions and controls. Digital potentiometers, temperature sensors, real time clock module, and LCD driver will be operating in slave mode. Each device will have its own unique address. Philips must give an address to only one specific device, so it will not cause conflict with other devices. The exception applies to some devices because they need to use multiple addresses on the same bus. In our case, this will be digital potentiometer. For more detailed discussion, please refer to our “Digital Potentiometer Configuration” section.

82

Page 88: Acoustic Remote Sensing

The 16F877 must be set up to operate in this mode, and again, the registers have to be set up for I2C. First, interrupt (if needed) can be set up through INTCON<7:6>, PIR1<3>, and PIE1<3>. Bus Collision flag and interrupt can also be set up through PIR2<3>, and PIE<3> in case of conflict in transmission or receiving. Once the interrupts and flags have been set, the I2C itself must be turned on. Unfortunately, I2C and SPI are on the same pins, so only one or the other must be chosen. The most critical register is the SSPCON as it will determine what mode 16F877 will operate, whether it will be I2C or SPI in either Master or Slave mode. I2C and SPI bus are collectively called Synchronous Serial Port (SSP) on 16F877 datasheet. As the name suggested, these are clocked data lines. To operate in I2C, SSPCON: SSPM3:SSPM0<3:0> must be set at 1000 for I2C Master Mode. Two other relevant registers are SSPSTAT, and SSPCON2. SSPSTAT is a query register for status of the SSP module. SSPCON2 is for controlling, but for like transmitting or receiving mode. I2C has a very simple algorithm in sending or receiving data. The bus works more like a shout and response system. The master device will initiate START condition, and then will send a 7-bit address out. Since each device will have a unique address, and if the address is valid, the Slave device will the ACKNOWLEDGE (ACK) the call. If it is not valid address, the system does not work. What this system enables us to do is to connect the devices in parallel with each other. Since only one device will acknowledge, given correct configuration, the data will only be going in and out of only one device. To send or receive from different device, different address will have to be transmitted after START condition. This is in the way cumbersome, but for hardware implementation, it is simple, no jumpers needed. Two lines are associated with I2C operation, SCL and SDA. SCL is a serial clock line to provide synchronous transmission. SDA is a data line. This data line is bi-directional, but it can only go one way at a time. If the SDA is transmitting, it cannot receive at the same time, and vice versa. The data will be buffered in a register before a transmission just as all other ports do. The very same buffer, SSPBUF, also buffers the incoming data when receiving. Another buffer, SSPADD, is a buffer for holding slave address. If new address is needed, it will be programmed here. In other word, if new device needed to be communicating with master device, this register will be programmed with that device’s address. The overall I2C transmission scheme displayed in Table 6.2. Table 6.2: I2C transmission scheme S 7-bit Address A Instructions A Data A P That is, of course, a very generic form of it. S is a start condition, A is acknowledge, and P is a stop condition. For transmission mode, the instruction will be slightly different, and vice versa with receiving mode. The Acknowledge bit is more like a confirm that it has receive a full set of address/data/instruction.

83

Page 89: Acoustic Remote Sensing

6.1.8 The Temperature Sensor

The temperature sensor will be connected to one of the onboard ADC on 16F877. Therefore, the register has to also be configured. Once the system has completed all other boot-up configuration, the ADC will be set. The ADCON0 register contains all important configuration bits. The first one is ADCON0: ADON<0>. This bit turns on the ADC. Second configuration is configuring ADC time clock at ADCON0: ADCS1:ADCS0<7:6>. The third, and the most crucial is ADCON0: CHS2:CHS0<5:3>, Analog Channel Select bit. These 3 bits can be set to acquire data from one of the eight available channels. So the temperature sensor can be at any of these channels. The temperature sensor itself is very simple to use. It has 3 pins, one is for ground, one is for Vsupply, and one is for Vout. As per Analog Devices specification sheet, the AD22100KT requires supply of 5 volts, same as the microcontroller. The operating temperature range is from –50 Celsius to 150 Celsius. The output will very from 0.250 to 4.75 volt respectively. The most important information from the specification sheet, however, is the transfer function. AD22100KT has the following transfer function.

VOUT = (V+/5V) X [1.375 V + (22.5mV/C) X TA]

Solving the equation, TA

can be obtained since VOUT and V+ would be known variables. The following equation is obtained for actual voltage out to temperature conversion.

TA = [VOUT – 1.375] X 1/(22.5 mV/C)

The value of VOUT, however, will be in digital form, and will be proportional to VREF of the ADC. This value will not obtained unless the target is present. So to save power, ADCON0: ADON<0> can be set at 0 until the target detection, then the microcontroller will turn on ADC module and acquire the data. The temperature information will be used for velocity of sound in water compensation, and will also be recorded as another preliminary data. Figure 6.1: Analog Devices AD22100KT, and AD22100AT

84

Page 90: Acoustic Remote Sensing

6.1.9 Real Time Clock (RTC) Module The timing module will be also on I2C port. This port only uses 2 wires, and it is also known as 2-wire bus. I2C can be multiplexed, and this is supported by both the microcontroller and I2C standard. 16F877 allows considerably easy addition of I2C slave devices, such as LCD controller, temperature sensor, Real Time Clock module, digital potentiometer, and many other devices. I2C devices also have their own specific addresses, and by having their own addresses, that prevents register and data transfer conflict. The RTC will be connected through the multiplexer. By doing this, we are only using 2 I/O lines instead of many for each separate device. I2C can be multiplexed for up to 8 slave devices. This opens the room for expansion through both 16F877, and other I2C devices without sacrificing anymore I/O’s on 16F877. The RTC registers will have to also be configured for time of day, and date initially. The DS1678 by Maxim is the RTC that we chose. DS1678 has a pin for battery backup whenever input voltage is lower than battery backup, it will use power from battery. This simplifies the schematic further because usually battery backup system is another circuit by itself. The battery backup is good for the clock because the user will not have to set the clock every time the main battery is changed. The DS1678 will also drive the timing crystal without external source at anytime, including during backup power.

Along with the RTC module, DS32kHz will be connected to it. The battery backup will also have to be connected to this temperature compensated oscillator. This crystal will provide 32.768 kHz clock signal to the RTC module. This device provides excellent accuracy to the RTC at +- 1 minute/year at 0 to 40 Celsius, or +- 2 ppm. This tolerance is more than what we needed in our project, but it does compliment to the quality of our project. The clock will run on this RTC module as it can provide month, day, year, hour, minute, and seconds of the day. Once the target is detected, the 16F877 will call upon this device to acquire the time and date, and then record it onto CompactFlash. 6.1.10 LCD Display Module

The LCD module is there, but not because of utilization since this is going to be a stand-alone and self-running unit. The LCD display eases the troubleshooting step, and initial set up. The clock will be display on there, and at the user’s setting; the range of the target will be there. The user can also set the clock, and this month/day/year and time of day will be set through LCD. The user will not know what date it is being setup without a screen, but once the time and date is set, it probably does not need to be set again. The Real Time Clock has a battery backup that will provide power in case the main battery is completely discharged. Densitron’s LM2025 has been chosen for this. Mainly, the difference between LCD screens is at the controller. This module is recommended to be controlled by Hitachi HD47780 controller. Some other standards controllers are Epson, Sharp, and Philips. Each controller uses different size bus, and type of bus. The most important is the ASCII table display. HD47780 has full English letters support, numbers, and some Japanese characters. A very attractive feature on this controller is that it allows 4-bit interface with microcontrollers.

85

Page 91: Acoustic Remote Sensing

LM2025 is a 2 line by 20 characters LCD module. The microcontroller will send data through 8-bit wide or 4-bit wide parallel depending on HD47780 configuration. Some controller can only run in 8-bit wide parallel mode. This is one of the reasons why we chose this controller, Hitachi HD47780. Each position of the screen will have its own address in the memory, and the memory address will contain a value. So line 1 character 1 will have one value. The LCD screen works like a memory bank. The value in certain memory position is the character to be displayed, and the memory location corresponds to the physical character position. Therefore, 2 X 20 LCD will have minimum of 40 memory addresses, which can contain minimum of 40 different values. The memory positions are usually in 8-bit format, and the value in the address is also 8-bit. This 8-bit possible address’s value usually represent ASCII table, but most of the time it is partial ASCII table with some user-custom letters. The overall operation is that the microcontroller has to program the 8-bit location on the display, and then program 8-bit value for character to be displayed. The location of the cursor will now shift by changing the memory address. For our operation we will use only 4-bit parallel connection. The reason again is for upgradeability, and flexibility of the I/O pins. Speed of the display is not really our concern. As mentioned before, the user will not be looking at the display much since this is supposed to record the data to the CompactFlash card. The user will look more at the outcome data more than LCD screen. The data will be displayed on the analysis application. The power supply will be 5 V as indicated by the specification sheet. 6.1.11 Operational Amplifier This operational amplifier will be set up specifically to amplify the signal from the transducer. The signals received are expected to be in order of microvolts to a few millivolts. The gain will be in order of thousands, and that is why we chose low noise amplifier. The non-inverting amplifier configuration is utilized to keep the signal in phase with the original input signal. The feedback path will have a digital potentiometer to vary the gain over time. The potentiometer will be controlled by the microcontroller. We have 1 MOhms digital potentiometer, and if we use 1 kOhms for another resistor, this should give us the gain up to 1000 times, but we might need more. At this time, 1 Mohms resistor might be a little bit too high, and we are concerned about noise. The formula for gain of the amplifier is following:

Av = 1 + Rf/Rs

Where Rf is feedback path resistor, and Rs is the input resistor. We can also use digital potentiometer for Rs for larger gain with smaller values of digital potentiometers. At present time, the maximum gain, and minimum gain has not yet been established. The experimental values of the voltage output from the transducer at different distances will have to be obtained in order to determine the maximum and minimum gain. The method for obtaining this will be explained in Curve Fitting section.

86

Page 92: Acoustic Remote Sensing

6.1.12 Curve Fitting Curve fitting is done primarily for two purposes. One is to determine the maximum, and minimum gain. This can be easily done by measure the closest distance signal response from the transducer, and determine the input needed for CCP port, vice versa. Second, and more important reason is to find out whether linear gain over time or logarithmic gain overtime will be needed for the amplifier. We are expecting that we are going to use logarithmic scheme, as many attenuation are exponential decay. We are trying to keep the output from the amplifier to CCP to be at a constant level, and keep the signal clean from noise to prevent false target. 6.1.13 Digital Potentiometers Configuration As mentioned before, these will control the gain of an amplifier. So the sweep hand, and one of the two terminals will be connected. This will be on the feedback path of an operational amplifier. AD5242 will have two serial bus wires to the microcontroller. The microcontroller will control the adjustable value through these 2 wires, SCLK and SDA. The I2C devices have their own unique address. These devices will be connected in parallel, but they won’t be operating at the same time. The microcontroller will send out the START signal along with the ADDRESS. If the address matches, that device will send ACK, acknowledge signal. The microcontroller will then send the data or receive from it. AD5242 comes with to address lines, A0 and A1. These address lines can be tied to either ground or Vsupply to generate 0 or 1 in digital domain, and they will be the last two address bits. Table 6.3: 8-bit address after START initiation 0 1 0 1 1 A1 A0 R/*W*

Table 6.3 shows the following 8-bits after START signal was initiated. The last

bit, R/*W*, is the READ/WRITE bit. This bit allows user to read the value that the digital potentiometer is currently at. Obviously, this potentiometer can have one of these 4 addresses, 0101100, 0101101, 0101110, and 0101111 respectively. So 4 of these devices can be connected in parallel with no conflict or need of multiplexing. The AD5242 also offers *SHDN*, a shutdown pin. This pin is active low, so in order for it to be turned on all the time, it will need to be connected to the Vsupply. Of course the microcontroller can turn it on and off when it is needed to save some power, but it only uses from 0.1 µA typically to 50 µA maximum rating. This is really a low power device. So to save I/O pins on the microcontroller, and since it was such little power to be saved, we will have these to be constantly on.

87

Page 93: Acoustic Remote Sensing

6.1.14 Function Generator Since our transducer requires a waveform input at specific voltage, current, waveform, and frequency, this is more easily done with compact function generator. It will be tuned at 23.5 kHz, and the output amplitude will be at 2 Vp-p. This signal will be amplified by the dedicated amplifier to give a maximum rating to the transducer at 50 Vp-p. The function generator is a module from Maxim Integrated Products, Inc, also known as Dallas Semiconductors. MAX038 is the function generator capable of generating waveform from frequency of 0.1 Hz to 20 MHz. All the standard waveforms are included, such as triangular, square, sine, pulse, and sawtooth. The duty cycle can also be adjusted from 15% to 85%. It can also be used as Pulse Width Modulator, Voltage Controlled Oscillator, Frequency Shift Keying modulator, and many other applications. This gives us flexibility to control our transducer whether we can send sine or square wave output to it, and being able to adjust the duty cycle of the input signal to the transducer. The 16F877 can also generate square wave with duty cycle adjustment, but it actually has to be done through either CCP port in PWM mode, but in our case, it will be CCP2 as CCP1 has already been used for transducer input. Pulse Width Modulation mode generate square wave, and duty cycle can also be programmed. We did not use onboard PWM because it does not give us the flexibility that MAX038 gives us, and pin RC1/T1OSI/CCP2 has already been used for 400 kHz crystal oscillator for CCP1 timing purposes. Although 400 kHz crystals can be eliminated by concatenating timer0 to be 24-bit counter instead of 8-bit counter, but easier solution is sought after by using 400 kHz. This still opens an option if a situation arises that we need CCP2, we would have to remove 400 kHz crystals, and do so to open up the pin. 6.2 The Overall Circuit Other than the connections mentioned above, few more things area added to the circuit as a protective measurements. Shunting capacitors are added at crucial points of the circuit. This is done to prevent sudden voltage drop in the circuit. We decide not to choose too big of a value because the start up time will be longer, and more importantly, if the circuit has a short, bigger capacitor will do more damage than smaller one. As long as the capacitor can prevent sudden voltage drop for a very short time, it is fine. We anticipate this for when sending sonar ping out because that will be the time that the circuit will consume most current. The capacitor values are in the range of about few microfarads.

Few diodes are also added to the circuit to prevent and absorb some of the backflow current. This has already been explained in the “Power Supply” section. The bus, and some of the output lines required pull-up resistors due to open-collector output. The circuit will have two voltage sources. One will supply the whole circuit, while the other is a battery backup for Real Time Clock module. Few switches are also used for master power, reset, and clock setting. As mentioned before, this device will be battery operated.

88

Page 94: Acoustic Remote Sensing

The 16F877 will be in 40 pins Dual Inline Package (DIP). The socket will be installed for easy removal and installation, and to avoid the heat from the soldering gun for initial solder. Few other components cannot use sockets, as they are surface mount. The main battery will have connection terminals to it. The battery backup is a watch battery, and it will have its own socket in case it needs to be replaced, but it does not need not to be replaced often. The RTC only uses few microamps in power backup mode, and the capacity of the lithium battery is about 500 mAh. This should give us a long back up time. The temperature sensor will not be mounted on the Printed Circuit Board (PCB) because it has to be measuring environmental temperature. The temperature sensor is in transistor package, TO-92. There would be 3 wires running to it, supply voltage, output voltage, and ground. This temperature is expected to be mount to the inside wall of the box.

The sonar module will be mount through a hole, but the transducer will seal the box. The front of the transducer will be exposed to the water because the sound wave will not propagate efficient enough through the wall of the box. Either square or sine wave can be used to oscillate the ultrasonic transducer. The LCD screen will be visible, but it will be inside the box. Other components will be mount on the PCB for neatness.

89

Page 95: Acoustic Remote Sensing

Figure 6.2: Hardware Block Diagram

TemperatureSensor

(AD22100KT)

Sonar Transducer(HE123TR)

A/D Converter

SanDISK Memorycard

PC data acquisition fromthe memory card

Microcontroller (PIC16F877)

Distance calculationalgorithms with

temperaturecompensation

Interface

Sonar Reflection(Analog) Temperature Output

(Analog)

TemperatureDigital Data

USBSerialPort

PhysicalMemory Card

Removal

Analog Signal

Digital Signal

Serial Port

Physical Transfer

Real TimeClock/Calandar

(DS1678)

A/D Converter

90

Page 96: Acoustic Remote Sensing

Figure 6.3: Software Block Diagram

PC data retrievalfrom the memory

card

Import into a GUI

GraphicalAnalysis

StatisticalCalculations

Analog Signal

Digital Signal

Serial Port

Physical Transfer

91

Page 97: Acoustic Remote Sensing

92

Page 98: Acoustic Remote Sensing

CHAPTER 7

GRAPHICAL USER INTERFACE

This chapter discusses how the computer will access the data. A Graphical User Interface (GUI) will be specifically designed for application with the Acoustic Remote Sensing device. Possible platforms for the GUI will be discussed and which platform will best meet our needs.

93

Page 99: Acoustic Remote Sensing

7.1 Introduction 7.1.1 Purpose of the system

The purpose of this GUI is to be able to retrieve data from a compact flash card reader by using a SanDisk Universal Serial Bus (USB) device. 7.1.2 Scope of the system

This system will allow the user to generate important data graphically. They will be able to analyze the data using this software and generate graphs with this software. The user will also be able to open the same file in Microsoft® Excel and be able to use Excel’s features and graph and analyze also if the user desires. 7.1.3 Objectives and success criteria of the project

The user will take data from a flash card reader by using a SanDisk USB device and retrieve data from it. This data then will be analyzed to measure the following: (1) Distance vs. Time and (2) Temperature vs. Time. All the data is coming from an underwater ranging device to measure the amount of boats that are in an area at a particular time. This data will be saved to a flash card on this device. 7.1.4 Definitions, acronyms and abbreviations

J.D.K. = Java Development Kit J.V.M. = Java Virtual Machine G.U.I. = Graphical User Interface V. I. = Virtual Instruments M.F.C. = Microsoft® Foundation Class D.L.L. = Dynamic Linked Libraries G.P.I.B = General Purpose Interface Bus (IEEE 488) V.X.I. = VME extensions for Instrumentation P.X.I. = PCI extensions for Instrumentation USB = Universal Serial Bus LED = Light Emitting Diode FAT = File Allocation Table

94

Page 100: Acoustic Remote Sensing

7.2 Current System

The current software system in place was created in MATLAB®. The user has to have MATLAB® installed and experience with MATLAB®. If they pass the previous specifications then the system was accessed in one of two modes. The two modes are (1) New and (2) Existing. Figure 7.1: The current system’s two modes

Reprinted from Submersible Watchdog Interface User’s Manual In the new mode you have to create a file with a date and time stamp. The time stamp has to be in format of the 24 hour clock not the 12 hour clock. Figure 7.2: The current system’s setup with the time being in the format of a 24 hour clock

Reprinted from Submersible Watchdog Interface User’s Manual

95

Page 101: Acoustic Remote Sensing

Figure 7.3: Confirmation of the location, filename, date and time

Reprinted from Submersible Watchdog Interface User’s Manual After the time and date stamp is set, the user has to import the data file, which is in a text format, from the SanDisk device. Figure 7.4: Current System’s flash file structure in text format, all you do is choose one of the files to be imported

Reprinted from Submersible Watchdog Interface User’s Manual

96

Page 102: Acoustic Remote Sensing

Figure 7.5: Current System’s Output display

Reprinted from Submersible Watchdog Interface User’s Manual

97

Page 103: Acoustic Remote Sensing

Figure 7.6: Shows how to change unit of distance

Reprinted from Submersible Watchdog Interface User’s Manual Figure 7.7: Shows the units of distance changed

Reprinted from Submersible Watchdog Interface User’s Manual

98

Page 104: Acoustic Remote Sensing

Figure 7.8: Shows how to Change to Bar Graph

Reprinted from Submersible Watchdog Interface User’s Manual Figure 7.9: Shows how to reset a graph to the default graph

Reprinted from Submersible Watchdog Interface User’s Manual

99

Page 105: Acoustic Remote Sensing

After the file is imported, the software then analyzes the data and generates graphs and statistical data. The user can edit for his/her statistical and output specifications. After the user is satisfied with the data analyzes then he/she can save the file in a *.swi format, which is specific for this software package. Figure 7.10: Shows how to save a file

Reprinted from Submersible Watchdog Interface User’s Manual In the existing mode all he/she will have to do is open a previous *.swi formatted file and can look at the data. The user can then change the output format. The data can be edited and reformatted for their specification. The new information can then be resaved as a different file. Figure 7.11: Shows how to open a file that was previously saved

Reprinted from Submersible Watchdog Interface User’s Manual

100

Page 106: Acoustic Remote Sensing

7.3 Proposed System 7.3.1 Overview

For the GUI portion of this project we are considering the following compilers and software packages: Java jdk 1.4.0, MATLAB® student edition and LabVIEW student edition. The compiler and software package that we are going to be using is MATLAB. The reason will be discussed in the MATLAB section. Why not LABVIEW

The main reason we were considering LabVIEW is because of its data acquisitions tools. The other reasons we are going to be using LabVIEW are as follows: (1) other companies are using it so when we go looking for a job it will look good on a resume, (2) since we are taking Senior Design II in the summer we have time constraints, because of the time constraints, we can prototype, design, test and implement our product and cut our time by a factor of 4 to 10 this according to LabView’s User’s Manual. After finding out exactly what the sponsor wants we had to change our GUI programming to MATLAB. The reasoning behind that in LabVIEW the user could not choose different types of graphs at a specific distance and time in the same package. While in MATLAB this could be easily accomplished using the GUIDE program built into MATLAB to make GUI’s. This will be discussed in more detail in the MATLAB section. Why MATLAB vs. LABVIEW

The main reason we choose MATLAB after starting with LABVIEW was it has an easy learning curve how to program GUI’s. Since we had a compact time to get a working GUI up to specifications with the sponsor we had no other alternative, but to use MATLAB. With LABVIEW the user will not be able to predefine specific data with a period of time and a range of distance and plot distance vs. time or time vs. distance at the same time, while MATLAB can do this. 7.3.2 Functional requirements

Acoustic Remote Sensing is a device that detects motion underwater. For example this device is placed underwater it will ping to detect motion and save data to a flash card on the system. The data that will be saved as follows: time and date stamp, amount of pings per hour. Then the flash card data will be imported via an USB port by MATLAB’s GUI system that was previously programmed and it will analyze the data obtained from the flash card.

101

Page 107: Acoustic Remote Sensing

7.3.3 Nonfunctional Requirements User interface and human factors

The interface that will be used for the Acoustic Remote Sensor is an USB connection on the physical level. The level the user needs to be is an average user. The definition of an average user is he/she should be able to have prior knowledge of how to use of at least Microsoft Windows 95, how to use a mouse, and how to open and close a file. They will also have to have MATLAB experience and ability to import a file into an application. Hardware Consideration

The minimum requirements for MATLAB for the Windows NT/9x/ME/2000/XP Platform are as follows:

• Microsoft Windows 95, Windows 98, Windows Me, Windows NT 4.0 (with Service Pack 5, 6a), or Windows 2000

• Intel-based Pentium, Pentium Pro, Pentium II, Pentium III, or AMD Athlon personal computer

• CD-ROM drive for installation, program execution, and online documentation • Netscape Navigator 4.0 or higher, or Microsoft Internet Explorer 4.0 or higher is

required • Microsoft Word 7.0 (Office 95), Word 8.0 (Office 97), or Office 2000 is required to

run the MATLAB® Notebook • Microsoft Word 7.0 (Office 95), Word 8.0 (Office 97), or Office 2000 is required to

run the MATLAB® Notebook The Minimum requirements for MATLAB for LINUX

• Linux 2.2.x kernel • Intel-based Pentium, Pentium Pro, Pentium II, Pentium III, or AMD Athlon

personal computer • X Windows (X1 1R6) • 110 MB free disk space for MATLAB and Simulink® • 64 MB memory; additional memory strongly recommended • 64 MB swap space • CD-ROM drive for installation and online documentation • Netscape Navigator 4.0 or higher is required to view online documentation • Adobe Acrobat Reader is required to view and print any MATLAB online

documentation that is in PDF format

102

Page 108: Acoustic Remote Sensing

7.3.5 Systems models Scenarios Scenario Name: dataacquisition Participating Actor: John: User Instances Flow of Events: 1. John does a proper shut down of the Acoustic Remote Sensor

2. He then takes the flash card out of the device and puts it in the flash card reader provided from Sandisk

3. Retrieves the data and the software outputs statistical data and saves it.

5. He then opens it up and formats the data specifically for his research.

7. Prints and Saves the graphs. GUI Mock-ups The following are GUI mockups of what it would of looked like if we programmed the GUI in Java. This is also before what the sponsor actually told the specs of the GUI. The GUI mockups for the final product will be shown in the user’s manual. Figure 7.20: Login Screen Acoustic Remote Sensor Software Version 1.0

Welcome

User Name

Password

OK Cancel

103

Page 109: Acoustic Remote Sensing

Figure 7.21: Import *.txt from Flash Card Acoustic Remote Sensor Software Version 1.0

FileNew

Open

Close

Save

Save as

r:\dat00.txt

Figure 7.22: Choose Statistical Info, if incorrect filename go back to Figure 7.21 Acoustic Remote Sensor Software Version 1.0

Time vs. Temperature

Minimum Range

Maximum Range

Duration of Time

Mean

Variance

Number of Objects Detected

Standard Deviation

< Back OK

Filename

104

Page 110: Acoustic Remote Sensing

Figure 7.23: Confirm Statistical data, if not then go back to Figure 7.22 Acoustic Remote Sensor Software Version 1.0

Confirm

Yes< Back

Figure 7.24: Confirm Statistical data, if not then go back to Figure 7.23 Acoustic Remote Sensor Software Version 1.0

Yes< Back

Confirm Calculations

105

Page 111: Acoustic Remote Sensing

Figure 7.25: Save as *.xls file

c:\dat00.xls

Acoustic Remote Sensor Software Version 1.0

CalculationsFile

New

Open

Close

Save

Save as

106

Page 112: Acoustic Remote Sensing

CHAPTER 8

FINAL DESIGN AND IMPLEMENTATION CHANGES

Our original design from the previous semester went through a few modifications as we began to build and implement our device. Through trial and error, testing, and additional research we changed just a few of our components but still met our original specifications. The following chapter details the entire final design configuration and explains why each modification and/or correction was necessary. It also entails upgrades and recommendations for future prototype generations.

107

Page 113: Acoustic Remote Sensing

8.1 Tranducer

The transducer is probably the most important part of our device. It serves as the main function of our sonar project. In our original design we had decided to use Hexamite’s HE123TR. However, we decided to find another company because the Australian company was very difficult to get in touch with. We did not want to risk not having good technical support. After careful consideration we found a company called AIRMAR Technology Corporation. They specialize in ultrasonic transducers and also make custom orders. Our original optimal frequency of operation for the transducer was 50 kHz. The HE123TR was lower and would be more susceptible to noise. We first got an estimate from AIRMAR to build a 50 kHz transducer with low power consumption, current on transmission less than 1 A, compact size, easy mounting, and low cost. They quoted us one that would fit these specifications at $110. This is a little more expensive than the HE123TR but fits our desired specifications. We had them rush the order so that we could obtain it on time to finish the project. For more specifications on this particular transducer you will have to contact our sponsor Paul Anderson, as he ordered the parts for us and did not give us a copy of the data sheet. Figure 8.1: AIRMAR 50 kHz custom transducer

Along with the transducer we also ordered a T1 Ranging Module from them.

This module is a driver board that has onboard regulation, ping control, filtering, and amplification. There is a selectable receiver gain of x1, x10, x100, x1000. One minor

108

Page 114: Acoustic Remote Sensing

modification to the board had to be done in order to control the ping manually. The upper lead on resistor 9 needed to be de-soldered, and the pulse generation line from the microcontroller attaches to this end of the resistor. If the upper resistor lead is connected back to the board the board will ping automatically. The driver board is very low power compared to many other transducer systems. With a 12 to 24 V supply voltage, it pings the transducer with a 400 Vp-p signal with current consumption of only 150 mA at transmission. The transducer is wired directly to the board with three wires. The transducer has both a negative wire and a positive wire that connects to the two pins on the top right side of the board. The common ground (non-insulated) wire connects to the supply ground. Our microcontroller has a timing algorithm that generates a three square wave pulse to R9 on the ranging module. This pulse is a 50 percent duty cycle signal with a frequency of 50 kHz and amplitude of 5V. When on automatic ping control the pulse sent to the transducer is 8 V. We could increase our amplitude to get a further ranging distance, but at the same time it would create more ringing after transmission and we would get a larger minimum distance. Figure 8.2: T1 Ranging Module

We decided not to use digital controlled potentiometers for adjustable gain

amplifiers over time. After connecting the different echo gains from the driver board to an oscilloscope, we found that the echo x10 was the signal with the least amount of noise. However, the output of this signal had amplitude on the order of millivolts that was hardly detectable by our microcontroller. We then found that by amplifying the x10 echo through an additional external amplifier with a gain of 100 produced a cleaner signal that just using the x1000 amplification straight from the board. We tested several operational amplifiers including OPA277, OPA227, TLC2201, OP07, OPA2277, and

109

Page 115: Acoustic Remote Sensing

OPA631. The best configuration incorporated the OPA277. This op-amp is a low noise, high precision op-amp that we obtained from Texas Instruments. We used a simple negative feedback configuration with a gain of –Rf / Ri. Where Rf is 470 kΩ and Ri is 4.7 kΩ. From observing the output of this amplified signal on the oscilloscope, we noticed that the transducer had resonance and ringing after the ping for about 15 to 20 ms before settling down. After the signal settled down there is a noise floor from –100 to +100 mV . The detected target echo spikes were as high as 4 V. The further the target is, the longer the sound wave has to travel, and the more attenuation of signal. Some targets that were nearly 50 ft in air from the transducer had an echo return spike just above the 100 mV noise floor. Because our microcontroller’s Schmitt trigger input is preset to 2.5 to 2.7 V, most of the further signals cannot be detected. Therefore, we decided to pass the output of the OPA277 through an adjustable comparator so that we could trigger small voltages to 5 V logic that our microcontroller could recognize. We decided to use the LM393 from ST Microelectronics for this purpose. We connected the output of the OPA277 to the positive input of the comparator. Then we used a voltage divider resistive network with a 20 KΩ potentiometer to adjust the negative input value from 50 to 150 mV. This would allow us the filter out the noise floor and only detect valid targets. Figure 8.3: Op-amp and comparator circuit configuration

The output of the comparator connects directly to the CCP port on the

PIC16F877. The CCP stands for Compare, Capture, Pulse Width Modulate. This port utilizes a 2 byte timer called timer1. After a ping is sent to the transducer, we start

110

Page 116: Acoustic Remote Sensing

timer1. This timer increments every instruction cycle and if it overflows then a target was not detected. In this case, we just send another ping. If the CCP port detects a rising edge signal (software configurable) then it generates an interrupt. Our interrupt handler routine stops the timer, stores the time, uses the time to calculate the distance of the detected object, displays the date/time, temperature, and distance on the LCD, and also dumps this data to a memory card.

For configuring the CCP port, minor calculation is needed to determine what is

the desired timer speed. It can either sync to an external oscillator or to the master clock. The maximum cycle increments that can be stored in the 2 byte timer is 65,536 before it overflows. Our specifications called for a maximum detection distance of 50 m and the speed of sound in salt water is approximately 1500 m/s. Using these values we can calculate the necessary clock speed.

m 11500 × × 65535 cycles cyclessec 50 m = 983025 1 MHz2 s

≈ec

At first we planned on synching the timer1 oscillator to an external 1 MHz crystal oscillator. But after reading the PIC16F877 specification sheet we realized that the external oscillator could only support up to 200 kHz. If we wanted to sync with the internal oscillator, we could use either 1:4 or 1:8 prescaler. The prescaler is a prescale instruction cycles. The instruction cycles are one fourth of the master clock. So a 1:4 prescaler with the master clock running at 20 MHz would give a maximum detection distance of 39.32 m. A 1:8 prescaler would give a maximum range of 78.64. After finding this out we decided to operate our master clock at a slower speed. We could have operated at 16 MHz with a 1:4 prescale or even 8 MHz with a 1:2 prescale. But we decided to drop the frequency all the way down to 4 MHz with a 1:1 prescale. Our reason for doing this is because when you operate at 4 MHz, you no longer have to operate in high speed (HS) mode on the microcontroller. We were able to set the mode to XT which has much lower power consumption.

One of the other issues we had to take into account was the ringing and resonance after transmission. One option that we could have tried was to blank the transducer out by applying a DC voltage right after transmission. However, we just decided to ignore the ringing by using a static software delay. We just added a delay of about 22 ms before enabling the CCP interrupt enable bit in order to give the transducer echo time to settle. This works just fine but also gives us a minimum distance of only 15 m.

111

Page 117: Acoustic Remote Sensing

Figure 8.4: Analog echo return from the OPA277 Figure 8.4 shows the analog echo return from the OPA277 output. The time scale on the oscilloscope is 10 ms/div. You can see the ringing lasts about 20 ms before settling down. So we have a delay set at 22 ms, and notice the spike at around 25 ms, that is a valid target. The target is almost as close as possible for our detection. Figure 2.5 shows the digital out put of the LM393. Notice that all the noise triggers to comparator to 5 V, then after about 20 ms the transducer settles and the comparator gives 0 V out. Because the noise floor is now filtered out, only valid target detections will trigger the comparator. The time scale on this picture is 5 ms/div. The ringing seems to settle out a around 15 ms on this tuned trigger level. There is a target detection at roughly 24 ms after the ping. Adjusting the potentiometer on the LM393 will increase or decrease the trigger level. If you increase the trigger level, the ringing that triggers will be reduced, but the detection level will increase giving you a shorter range. Just the opposite occurs if the trigger level is decreased.

112

Page 118: Acoustic Remote Sensing

Figure 8.5: Digital echo return from the LM393 output 8.2 Liquid Crystal Display

We still feel the best way to trouble shoot our device, and to set the date and time on the real-time clock is the use of and LCD. After researching many LCDs we found that the Hitachi HD44780 was a very popular and easy to use LCD controller. So we searched for LCD modules that used this particular controller. We originally said we were going to use Densitron’s 2x20 line LM2025. This was a good character LCD, however we could not obtain free samples of these devices and they cost around $25 each. We discovered that a local electronics store here in Orlando named Skycraft Surplus store sold Optrex 16207 16x2 character LCD modules for only $2 each. This module utilizes the HD44780 controller and also has a full spec sheet online.

The Optrex 16207 module seemed to be our best choice. It has an operating

temperature from 0°C to 40°C. It runs on 5 V supply and 5 V logic. It has a total of 32 characters on two lines. The pin configuration of this LCD is shown in figure 3.1.

113

Page 119: Acoustic Remote Sensing

Figure 8.6: Optrex 16207 LCD module pin configuration We are using a 4-bit interface with this device in order to save pin connection on our microcontroller. Along with the four data lines two additional lines, enable and register select, are necessary for operation. Read/Write (R/W) is tied to ground because we are always writing to the module. PORTA on our microcontroller had exactly six pins so our LCD fit very nicely on this port. In order for us to use PORTA we had to configure this port in our boot up sequence. This port is the analog to digital converter port. We are not using any A/D converters so we set register ADCON1 to b’00000110’ which sets all the pins to digital I/O. Another note we had to consider is that PORTA, pin 4 is open drain type and requires a pull-up resistor. We used a value of 4.7 kΩ. We originally had the contrast control as shown above using a potentiometer, but we found that tying the VEE to ground gave the maximum contrast and worked just fine. This reduced the amount of hassle and parts that could go bad. We considered using a backlight module as well, but for the same reason just stated in the previous sentence we decided not to complicate things. Also, a backlight is not necessary because the LCD on this device is only for trouble shooting being that it will be underwater.

114

Page 120: Acoustic Remote Sensing

Operating the LCD with the microcontroller was fairly simply. We just had to adhere to the timing requirements. Some of these requirements are as follows:

- Power-up delay -> 40 ms - Enable pulse width -> 230 ns (time that enable should stay high) - Enable cycle time -> 500 ns (time in between enable pulses)

After testing the LCD we found that no delay was required after writing to the data register, but when writing to the command register we needed a minimum of a 50 ms delay. Figure 3.2 shows an 4-bit interface diagram. Register Select (RS) is high when writing to the data register and low when writing to the command register. The upper four bits are put on the data lines first, the enable line is strobed high, then the lower four bits are put on the port, and enable is strobed again. Figure 8.7: Timing diagram showing a 4-bit interface with the LCD

RS

R/W

DB7

DB6

DB5

DB4

E

D7 D3

D6 D2

D5 D1

D4 D0

8.3 Power Supply

There are a few considerations for our power supply requirements. We need a stand-alone DC supply. We need a stable 5 V supply to nearly all of our components except the driver board for the transducer that requires 12 to 24 V. We need a back up battery for the DS1305 and the DS32KHZ. We have a reduced requirement approved by our sponsor of 12 hours of continuous operation. We want a battery that is easy to replace and cost efficient. Our original design did not require and voltage above 5 V. Therefore we had settled on two Ultralife 9V lithium battery for our main supply. For our back-up battery we decided on using a Panasonic CR2354. After we decided to use the T1 Transducer module we realized that a different battery type needed to be considered. We decided that the best choice for our main power supply would be a motorcycle or alarm battery. We found a Panasonic LC-R125P1 12 volt 5 Ah gel cel battery and www.allelectronics.com. This battery is rechargeable and nonspillable. It is

115

Page 121: Acoustic Remote Sensing

only 3.5” x2.7”x4” in size. These batteries only cost $15 and ship within 24 to 48 hours. This battery would have lasted a couple of days in our device because we measured an average of just over 100 mA of current drain in our final prototype. Its size would easily fit in the dimensions of box that we want. For our real-time clock back-up battery, we decided to use an Energizer CR2450. This battery seemed more common and more readily available. This battery has a 500 mAh capacity which should last several months of operation. In addition to these two batteries, we realized that we also needed an isolated power supply to run our operational amplifier. The power supply voltage for the amp is a standard 9 V battery. We recommend the Ultralife 9V lithium because it has the more capacity than most batteries on the market. Although, rechargeable batteries would be more efficient so we would also recommend those as well. Because our sponsor built a box smaller than the dimensions we wanted, our selection for our main battery would not fit in the box with all the other components. He went ahead and ordered some specialized electronics batteries that have to be ordered through mail. We need (4) 3.6 V lithium “AA” size batteries. These provide only 2100 mAh. This is the main reason we had to reduce our specification on continuous operation. Our goal was twenty-four hours of operation which required at least 2400 mAh capacity. We told our sponsor this but he wanted to use the batteries he ordered which are not rechargeable either. 8.4 Box Design

For the box design, we still decided to use Lexan for our waterproof casing. However we found out that it is resistive to temperature. This means that we may not get accurate water temperature. We could have used PVC piping or plexiglass but our sponsor wanted to use the CNC milling machine to build a box out of Lexan. We didn’t know that our box would cost over $600 to build. We wanted a box that was more the size of the previous generations. The dimensions we wanted were 8”x5”x4”. However he made a box that is approximately 4”x6”x4.5”. This was not much room to fit the transducer, power supply, plus our PCB board. We ended up cramming it all in there and it didn’t turn out looking as nice as we had hoped. 8.5 Synchronous Serial Port 8.5.1 SPI

After further research, we found that SPI device is a little bit easier to use than I2C device, and more importantly the MultiMediaCard, MMC, can run in SPI mode. SPI requires less registers and flags to check. Unfortunately we had to change to CompactFlash memory card interface instead of MMC. SPI bus also offers more speed than I2C, where I2C has maximum speed of 400 kHz for 16F877. PIC16F877’s SPI device is capable to run at 5 MHZ, but the speed of the bus depends mostly slave device’s maximum speed. The chart below summarizes the slave devices’ bus specification.

116

Page 122: Acoustic Remote Sensing

Table 8.1: SPI device chart SPI Device Maximum Bus

Speed Logic Level Voltage

SPI Mode

DS1305 Real Time Clock

5.0 MHZ 5.0V or less 2 or 3

DS1722 Digital Thermometer

2.0 MHZ 5.0V or less 2 or 3

The first step of establishing a bus is to set the SSPSTAT, SSP Status register, and SSPCON, SSP control register according to the slave devices. The 16F877 will be operating in master mode, which it will neglect pin 7, SS, slave select. We would choose ours to be operating in Mode3. The figure below Figure 8.8: Clock mode diagram

The clock modes are selected through SSPCON, CKP (or SSPCON, bit 4) where clock polarity (CKP) is normally high (the clock polarite bit is set to one), and SSPSTAT, CKE (or SSPSTAT, bit 6) clock edge bit is set to zero. The actual assembly code for configuring both registers is below. movlw b’00110001’ movwf SSPCON movlw b’10000000’ movwf SSPSTAT

117

Page 123: Acoustic Remote Sensing

The SSP is now set for 1/16 speed of the master clock, SPI Master Mode, and SPI Mode3. The clock mode explanation in previous page had a slight mistake in Mode3. SSPCON2 register in 16F877 is not used because it deals with I2C operation mode. As a note to the reader, since SPI is a Motorola bus protocol, most of specification sheets and example codes will refer the clock modes setting through CPOL and CPHA bits where CPOL stands for Clock Polarity bit, and CPHA is Clock Phase bit. The notation of CPHA is not directly translated to Microchip’s CKE. Microchip has a presentation about SPI bus available for download that will explain further on this issue. SPI bus only requires one major flag to be read, Buffer Full flag in SSPSTAT register. This flag will have to be clear every time the data is sent. If this flag is not clear, the Synchronous Serial Port, SSP will be disabled or operate incorrectly. The only way to clear this flag is by reading SSPBUF, SSP buffer register even if the data is not being used. This is very important because if a command such as bcf SSPBUF, BF was used the bus will also operate incorrectly or not at all. The correct command to use will be movf SPPBUF,W movwf W,data where the second command is optional if we are sending the data. Note that every time SSPBUF is filled, this flag will be set whether read or write to or from SPI slave device. This can be easily observed in MPLAB simulator. To write the data to the device, the chip select line will first has to be asserted. Most of the slave devices will have CS or CE, and most of the time they are inverted, the CS is active low. Once the CS line has been asserted, the data will be then move to SSPBUF register, which is a shift register. This register shifts the data out on the SDO line. Once the transmission is completed, the BF flag bit will be set. Since our clock is running at 1/16 of the master clock, it will take 32 instructional cycles to finish one write cycle. The programmer can do other instructions while waiting for flag bit to clear. In our code, however, we use nop, no operations, command. The chart below summarizes the write operation.

118

Page 124: Acoustic Remote Sensing

Figure 8.9: Timing diagram for SPI write

Note that the data is transmitted MSB first, and this distinguished between SPI and 3-wire serial communication. Our slave devices are special and simple protocol. The first byte will be the address to write to and the second byte will be the data to that address. After the chip select line is de-assert, the slave device will update the data. After every byte is sent, BF flag is set, and will have to be software cleared as mentioned above. The example code is below. bsf PORTB,5 ;assert CS high (PORTB pin 5) movlw b’11110000’ ;put address in W register call spi_out movlw b’00001111’ put data in W register call spi_out bcf PORTB,5 ;de-assert CS line where spi_out is our subroutine in the code, which can be looked at in the appendix. The subroutine simply move the data that is already in W register to SSPBUF, and then wait another 32 instructional cycles. To read from the slave device, the master will have to assert chip select line. After the assertion, the address to read will be sent, and then the master will provide another 8 clock cycles for the slave device to respond back. The master can then de-assert the CS line, and move the data to appropriate memory location. The picture below shows the process.

119

Page 125: Acoustic Remote Sensing

Figure 8.10: Timing diagram for SPI read

To provide another 8 clock cycles, the data 0b00000000 will simply has to be send to SSPBUF. The example code is shown here. bsf PORTB,5 movlw b’11110000’ ;the address call spi_out movlw b’00000000’ ;the “dummy” bit call spi_out bcf PORTB,5 movf SSPBUF,W ;data remains in SSPBUF movwf data_in move the data from W to data_in As a note for troubleshooting, First, the SCK line does not always have to be active. In other words, the clock line is not on all the time. For example, after first byte has been written, the second byte does not have to come immediately. It can be a very long period of time before second byte write starts as long as CS line still asserted. Second, the data always latched on the opposite edge of the transmission edge. In our case, we have rising edge transfer, so the data will latch (change) on the falling edge. Third, the SPI communication is an exchange of data. For every bit out, there will be a bit in. 8.5.2 DS1722 Temperature Sensor Maxim IC’s DS1722 is a digital output temperature sensor. It can withstand the temperature range of -55 C to 120C. It also provides SPI output for the 16F877. DS1722 has to be configured for SPI mode, and interface voltage at 5V.

120

Page 126: Acoustic Remote Sensing

Figure 8.11: DS1722 connection figure

The serial mode has to be connected to 5V, and same as VCCIF line. The SDO will connect to master SDI line, and the SD1722’s SDI will connect to 16F877’s SDO. The next step is to software configured for operation. DS1722 can operate in both continuous read mode or 1SHOT read mode. This can be set in configuration register. We chose continuous read mode because we want the data to be readily available at the time of target detection. 1SHOT read mode requires a certain fixed length of time before the data will be available. We will be using only 8-bit resolution. 12-bit resolution, however, is available, but our software does not support it. For software configuration, the 16F877’s code is below. bsf PORTB,2 ;assert chip select movf SSPBUF,W movlw b'10000000' ;call address to write call spi_out movf SSPBUF,W movlw b'11100000' ;configure temp sensor...8-bit continuous ;read mode call spi_out bcf PORTB,2 The configuration address for write is 0b10000000. To read the temperature, we have to read at address 0b00000010. DS1722 will then respond with appropriate temperature. This temperature will be used in calculation of the speed of sound. 8.5.3 DS1305 Real-Time Clock and DS32KHZ Crystal Oscillator DS1305 is for timekeeping, and 16F877 will record the time and date of the detection. It can operate in 12 hours mode or 24 hours mode. Before the chip can be used, the DS1305 will also have to be configured at the boot-up sequence of the device.

121

Page 127: Acoustic Remote Sensing

The boot-up will configure DS1305 to 24 hours military time format, and enable oscillator. The chip will also have to be hardware configured similar to DS1722. Figure 8.12: DS1305 and DS32KHZ hardware configuration

SERMODE and VCCIF pins are connected to 5V for SPI mode, and 5V logic respectively. The battery backup is used, so the user will only have to set the time once as long as one of the power sources is available. DS32KHZ is very simple to use, the power is connected to it, and it will provide 32.768 Khz output. The test pins will have to be connected to ground. The DS32KHZ is a temperature compensated crystal oscillator that can keep accurate timing upto one minute of error per year. DS1305 has to be configured to address 0b10001111 with data 0b00000000 for enable oscillator, and disable write protect, and then we have to set to 24 hours mode at address 0b10000010 with data 0b00000000. The DS1305 is now ready to use. The time setting will be done through two buttons, and time setting mode. In this mode, the user will set the time through LCD screen, and the 16F877 will write to appropriate address to set time and date. As a note, the DS1305’s time registers (Hours, Minutes, Seconds, Month, Day, and Year) are in Binary Coded Decimal format. So a conversion of BCD to ASCII (for LCD and data recording) and binary to BCD is required (in time setting mode). 8.6 Memory

After endless searches on the internet we finally found a complete MultiMediaCard specification sheet. We decided after reading the spec sheet to try to

122

Page 128: Acoustic Remote Sensing

use MMC instead of CF due to the fewer number of connections to the microcontroller and the miniature size. MultiMediaCard mode was the mode we had chosen to implement on the MMC which only allowed 512 bytes of data to be saved to the card at a time. This required the use of an external memory source. We chose FRAM because it could be implemented on the SPI bus and also it had the memory requirements that were needed. Unfortunately once we had programmed the PIC to interact with the MMC and write data, the MMC would not respond correctly. There was not sufficient documentation on MMC and the coding of the MMC in PIC assembly to trouble shoot with. We are not sure if the problem was with our code or the wiring of the MMC. Due to these problems, we returned to our original design and implemented the CompactFlash. Please refer to Chapter 3 for the specifications about the CF. The information from the PIC is saved the CompactFlash card in an ASCII text file format. The information was saved in the following format: MM,DD,YY,HH,MM,SS,TT,DD,000 The three zeros at the end are used to help keep track of how many times the card writes or how much data has been saved. Each detection is saved to a different line to easily distinguish the detections. There are three modes in which CompactFlash operates: I/O mode, Memory mode, and True IDE mode. Memory mode is the default of the CompactFlash. It does not require the card to be configured a certain way. It also was the easiest way to write and read the card. For these reasons, we decided to operate the CompactFlash in memory mode. Since we are operating in memory mode, we will use memory mapped addressing. There are two different modes to address : Logical Block Addressing (LBA) and Cylinder/Head/Sector (C/H/S) mode. LBA addressing was used because it was easy to understand. The addresses start at zero and end at the last sector number. Once a sector was full, the address would have to be incremented by one. If C/H/S was used, the cylinder and head number would also have to be incremented once each are full. With LBA we only have to worry about sector number. The CompactFlash card is formatted in FAT16. This was new to everyone in the group and was a learning experience for everyone. Within the FAT, where the filename and data can be saved can be determined either directly from certain offset or with a combination of offsets. The filename, date, time, and file size is saved in a different location from the data called the root directory. This section of the card points to where the data for that file is stored on the card. The root directory can be determined by the number of FATS times the sectors per FAT plus the number of reserved sectors. The following equations calculates the location of the root directory using the offsets: Root directory = 10h * 16h + OEh The data for the files is then saved 32 sectors away from the root directory. We encountered problems when saving a text file. The file would be created but not always

123

Page 129: Acoustic Remote Sensing

available. The computer was not always able to access the file because it would read the file as being corrupt. We went around this problem by saving a file larger than the file we want to write to the CompactFlash first. The data in this file was over written by the data sent from the microcontroller. We never encounter any errors using this method. 8.7 Microcontroller The microcontroller we eneded up using was the PIC16F877. We chose this pic because it has 33 I/O pins, low power consumption, and two capture/compare/PWM ports. It also has an operating frequency up to 20 MHz, however, we are operating our device at 4 MHz. It also has 8 kB of FLASH re-programmable memory, 368 bytes of RAM, and is capable of an SPI interface. The 16F877 requires a 5 V power supply but needs a 4.7 kΩ pull-up resistor on the master clear pin. We will use a 4 MHz crystal for the master clock. The crystal needs to have two 33 pF capacitors connected to ground to stabilize the crystal. The microcontroller as said before is the brain of ARS. It tells everything what to do. It will initialize all and configure the slave devices on power up. It will then begin sending a square wave pulse from a two opamp circuit for the ping. The microcontroller will continue to do this until there is a detection on the CCP pin. Once there is a target detection, the microcontroller will use the obtained time of flight and calculate the distance. It will then display the date, time, temperature, and distance on the LCD for troubleshooting and it will then send the data to the CompactFlash card for saving. The programming of the microcontroller was done all in Microchip’s assembly using MPLAB IDE 5.61.00. Microchip’s assembly only uses 35 instructions. Our program has 3,054 lines of codes including 68 functions and 65 variables. To get the program onto the chip a special programmer was needed. We used the EPIC programmer that connects to the computer through a parallel port and can program the chip in less than 20 seconds. The language was not very difficult to learn The only difficulties we encountered was doing math functions. Microchip’s assembly only has add and subtract functions. We needed to multiply numbers so we used Microchip’s application notes. They have ready to use code to perform the math operations that were needed to calculate the speed of sound in salt water.

124

Page 130: Acoustic Remote Sensing

CHAPTER 9

ADMINISTRATIVE CONTENT

This chapter contains our administrative concerns. The success of the design was based upon the ability to allocate our resources effectively. This chapter will present our financing and design expenses. This section also includes our milestone chart, contact information, and personnel biographies.

125

Page 131: Acoustic Remote Sensing

8.1 Budget and Financing The following chart is a forecast of the cost of the device. Mr. Paul Anderson is funding the project. These are preliminary prices because we have not decided on all of the final parts we will use. We are also in the process of getting parts donated, which will also affect the final budget. Table 8.1: Forecasted Budget

Number

of Items

Unit Cost Total Cost

Hardware Microcontroller (PIC16F877) 2 $5.56 $0

(donated by Microchip) AIRMAR Custom

Underwater Ultrasoncic Transducer

2 $110 $220

AIRMAR T1 Transceiver Module 1 $99 $99

Temperature Sensor (DS1722) 2 $1.32 $0

(donated by Maxium) LCD

(Optrex 16207) 4 $2.00 $8

Comparator (TI LM393N) 3 .18 $0

(donated by Texas Instruments) Crystal 4 MHz 8 MHz 20 Mhz

4 4 4

$3.00 $3.00 $3.00

$12 $12 $12

Wire Wrap Board 1 $2.79 $2.79 Battery

(Tadiran Lithium TL-2100)

4 $7.50 $30

Battery (Energizer CR2450) 1 $2.99 $3

Real Time Event Recorder (DS1305)

2 $3.47 $0 (donated by Maxim)

Crystal Oscillator (DS32khz) 2 $3.75 $8

Operational Amplifier (OPA227P) 1 $2.23 $0

(donated by Texas Instruments) Voltage Regulator (UA7805CKC 5V) 4 $0.35 $0

(donated by Texas Instruments) Waterproof Box 1 $462.50 $462.50

126

Page 132: Acoustic Remote Sensing

LEXAN® Sheet $200 $200

CompactFlash Card 1 $30 $0 (previous generation)

CompactFlash Card Reader 1 $18 $0

(previous generation)

Interconnect 1 $20 $0 (previous generation)

Software Matlab

1 $99 $0 (owned by UCF)

Misc. $100 $80

Total Cost $1149.29

127

Page 133: Acoustic Remote Sensing

8.2 Milestone Chart

ID Milestone Start Finish DurationMar 2002 Jul 2002Apr 2002 Jun 2002May 2002

3/313/3 4/28 7/215/263/24 4/7 5/12 6/94/142/24 6/306/23 7/286/2 7/75/54/21 6/163/10 5/193/17 7/14

1 1.43w3/6/20022/25/2002Physics Research - UnderwaterAcoustics

4.29w4/25/20023/27/2002Temperature Sensor Calibration andTesting

8 4.29w6/23/20025/25/2002Sonar Sensor Calibration and Testing

11 1w3/18/20023/12/2002PIC Chip Acquisition and EvaluationBoard Acquisition

16 2w3/25/20023/12/2002Identify Software Needs

19 1w3/10/20023/4/2002Power Supply Research

23 6.71w4/22/20023/7/2002Documentation SD 1

25 5.71w7/30/20026/21/2002Testing, Evaluation, Redesign

Sonar Sensor Research

3

2 1w3/10/20023/4/2002Temperature Sensor Research

1w3/18/20023/12/2002Temperature Sensor Acquisition

4

7

6

1w5/26/20025/20/2002Sonar Sensor Acquisition

5 3.57w6/20/20025/27/2002Temperature Sensor Installation andIntegration

1w3/10/20023/4/2002Sonar Sensor Research

9 1.57w7/30/20027/20/2002Sonar Sensor Installation andIntegration

10

.29w7/31/20027/30/2002Documentation SD2

1w3/10/20023/4/2002PIC Chip Research and PartsIdentificaiton

12 11w7/26/20025/11/2002PIC Chip Algorithm Developement

14

13 .43w7/22/20027/20/2002PIC Chip port communication toSANdisk

2.86w5/31/20025/12/2002PIC Chip Data Acquisition Testing

15 3.57w6/20/20025/27/2002PIC Chip Installation and Integration

18

17 3.29w4/20/20023/29/2002Software Platform Identfication

8.57w7/26/20025/28/2002Software Coding and Testing

20 .57w6/29/20026/26/2002Power Supply Acquisition

21 4.29w5/9/20024/10/2002DC/DC Conversion

22 9.29w9/28/20027/26/2002Power Supply Installation andIntegration

24

128

Page 134: Acoustic Remote Sensing

8.3 Group Member Backgrounds Corey A. Smith

Born and raised in Denver, CO. Moved to Winter Haven, FL at the age of 18. Attended Polk Community College where I received my AA degree. I then transferred to the University of Central Florida where I am currently seeking a Bachelor’s degree in Computer Engineering. James W. Coots

Grew up in San Antonio, TX and moved to Crestview, FL during my junior year in high school. I moved to Orlando, FL to attend the University of Central Florida. I am currently seeking my Bachelor’s degree in Electrical Engineering.

129

Page 135: Acoustic Remote Sensing

Stacy Jimerson

Grew up in Georgia until the age of 8 when I moved to Jacksonville, FL. After graduating form high school, I moved to Orlando to attend the University of Central Florida. I am currently a senior in the School of Electrical Engineering and Computer Science. I hope to receive my Bachelor’s Degree in Electrical Engineering.

Akradanai Viranuvatti

Moved from Bangkok, Thailand at the age of 14. Moved to Kentucky, and then to Longwood, FL. Attended University of Florida then transfer to University of Central Florida. Major in Electrical Engineering.

130

Page 136: Acoustic Remote Sensing

8.4 Contact Information Corey A. Smith Senior Computer Engineering E-mail: [email protected] Phone: 407-737-9287 James W. Coots Senior Electrical Engineering E-mail: [email protected] Phone: 407-249-8431 Stacy Jimerson Senior Electrical Engineering E-mail: [email protected] Phone: 407-257-8046 Akradanai Viranuvatti Senior Electrical Engineering E-mail: [email protected] Phone: 407-328-4450

131

Page 137: Acoustic Remote Sensing

8.5 Special Thanks Mr. Paul Anderson and Department of Mechanical Engineering Dr. Samuel Richie (Dr.) Murad Qahwash Christina Peterson at Texas Instruments University Relations (DSP Division) for commitment to donate DSP evaluation boards. Texas Instruments’ Technical Support Texas Instruments parts sample request Analog Devices Technical Support Department Analog Devices parts sample request Microchip’s Technical Support Team Gary Vest, Regional Sales Manager (SE) for Microchip, for commitment to donate PIC16F877, and miscellaneous parts. Philips Semiconductor Technical Support Maxim IC parts sample request Fairchild Semiconductor for donating diodes. Seiko Technical Support Giles Jonsson at Hexamite Max Dysh Timothy Roberts Steve Rotolante

132

Page 138: Acoustic Remote Sensing

SUMMARY The Acoustic Remote Sensing device will measure the distance of passing boats from the device in Mosquito Lagoon. The device will be lightweight requiring only one person to transport it to the lagoon. It will be submersed under water so the container will be waterproof and non-corrosive. The box will contain all the components required to make the device work. The ultrasonic transducer will transmit a signal when a boat passes the device. The returning signal will be received by the transducer and sent to the microcontroller. The water temperature will be obtained from a temperature sensor connected to the microcontroller. The microcontroller will use the time of flight, the speed of sound in water, and water temperature to calculate the distance. The distance, temperature, time, and date will be transmitted from the microcontroller to the CompactFlash card. Since the CompactFlash card is non-volatile memory, it can be removed without losing the stored data. The data will be removed from the device and connected to a computer through a SanDisk reader. The information will be uploaded into a GUI, specially designed for implementation with the device, for analysis. The GUI will perform statistical analysis on the uploaded data. Mean, variance, mode, median, and standard deviation will be calculated. Besides the standard statistical analysis, the GUI will allow for user-defined statistics. The user will be able to ask for the time of day that experienced the most amount of boat traffic and other possible patterns. This device is intended to track the boat traffic near oyster beds. Hopefully with the data obtained with the device will help scientists determine if the traffic is the cause for the oyster bed destruction. Information from the device will help determine if precautions need to be taken in the area such as speed limits. Although this device was designed with Mosquito Lagoon in mind, this device can be implemented in any shallow, saltwater area with only a few minor adjustments.

133

Page 139: Acoustic Remote Sensing

APPENDIX

134

Page 140: Acoustic Remote Sensing

REFERENCE

18F877 with CompactFlash

http://www.eetasia.com/ART_8800022615_499481,499491.HTM “About Transducers.” http://www.itc-transducers.com/168-0009.htm. International

Transducer Corporation, 2000. AD21161_Audio_Tutorial from

http://www.analog.com/library/applicationNotes/dsp/32_Processors/21161_Audio_Tutorial.pdf

Capture mode

http://www.microchip.com/download/lit/suppdoc/toots/ccpwm.pdf CCPWM

http://www.microchip.com/download/appnote/pic16/00588b.pdf Choosing crystal and setup reset circuit.

http://www.microsoft.com/hwdev/download/hardware/FATGEN103.doc CompactFlash Association

http://www.compactflash.org/cgi-bin/specdl2.cgi Connecting LED

http://www.siriusmicro.com/projects/b1.pdf “DS1678: Real Time Event Recorder.” http://dbserv.maxim-

ic.com/quick_view2.cfm?qv_pk=2753. Maxim Integrated Products, 2002. “DS32KHZ: 32.768 kHz TCXO.” http://dbserv.maxim-

ic.com/quick_view2.cfm?qv_pk=2940. Maxim Integrated Products, 2002. Eastman Kodak Company. http://www.kodak.com/. FAT spec

http://www.microchip.com/download/appnote/devspec/17cxx/misc/00545d.pdf “General Electric Company. “http://www.gestructuredproducts.com/sp1/gesp/index.jsp.

GE Structured Products, 2001. Halliday, David and Robert Resnick et. Al. Fundamentals of Physics, Fifth Edition.

John Wiley & Sons, Inc., New York, 1997: Pg. 831.

135

Page 141: Acoustic Remote Sensing

“HE123TR: Underwater Ultrasonic Transceiver.” http://www.hexamite.com/. Hexamite, 2001.

Horton, I. Begging Java 2. Wrox Press Ltd, Canada, 2000. Huang, H. W. MC 68HC11: An Introduction, West Publishing, 1996. “Introduction to Ultrasonic Testing.”

http://www.cnde.iastate.edu/ncce/UT_CC/Sec.3.1.4/Sec.3.1.4.html. Center for Nondestructive Evaluation, Iowa State University, Ames, IA, 2000.

Kozieroh, C. M. http://www.pcguide.com/ref/hdd/file/ Kuntsal, E. and W. A. Bunker. “Guidelines for Specifying Underwater Electro- Acoustic

Transducers.” http://www.itc-transducers.com/guidline.doc. 1999. “LM2052: Alphanumeric Liquid Crystal Display.” http://www.densitron.com/cgi-

bin/dregister.cgi?pdf=lm2052&status=2. Densitron Technologies Inc., 2002. Marine Acoustics Limited. http://www.marine-acoustics.co.uk/Products/. MATLAB-The Language of Technical Computing: Getting Started with MATLAB. The

Math Work, Inc. 2000. Multiplication and division algorithm development guide

http://www.siriusmicro.com/projects/b2.pdf National Inustruments-LabVIEW: Getting Started with LabVIEW. National Instruments

Corp. 2000. Nilsson, James and Susan Riedel. Electric Circuits Sixth Edition. Prentice Hall, New

Jersey, 2001: pg. 513. “OPA227: High Precision, Low Noise Operational Amplifier.”

http://focus.ti.com/docs/prod/productfolder.jhtml?genericPartNumber=OPA227. Texas Instruments, 2002.

Oscillator

http://developer.intel.com/design/chipsets/applnots/29227602.pdf Panasonic Batteries. http://www.panasonic.com/. “PCF8563 Real Time Clock /Calendar.”

http://www.semiconductors.philips.com/pip/PCF8563P/F4s. Koninklijke Philips N.V., 2002.

136

Page 142: Acoustic Remote Sensing

“PIC16F877: PIC Microcontrollers.” http://www.microchip.com/1010/pline/picmicro/category/embctrl/14kbytes/devices/16f877/index.htm. Microchip Inc., 2002.

Radio Shack Batteries.

http://www.radioshack.com/category.asp?catalog%5Fname=CTLG&category%5Fname=CTLG%5F001%5F004%5F005%5F000&Page=1.

Reson Inc. http://www.reson.com/. Rizzoni, Giorgio. Principles and Applications of Electrical Engineering e-Text. McGraw

Hill, 2001: Pgs. 798-800. Samuels, M. PIC a CompactFlash Card.

http://www.chipcenter.com/circuitcellar/february01/c0201ms1.htm Sandisk interface with MCU

http://www.sandisk.com/tech/product_man-main.asp Sandisk CompactFlash datasheet Technical reference sheet

http://www.siriusmicro.com/projects/i3multdiv.html SanDisk Corporation. http://www.sandisk.com

Sanyo Batteries. http://www.sanyo.com/industrial/batteries/index.html. “Technical Information: Battery Engineering Guide.” http://data.energizer.com.

Eveready Battery Company, 2002. Tyson, J. How Flash Memory Works. http://www.howstuffworks.com/flash-memory.htm “UA7805 Fixed 5V Positive Voltage Regulator”

http://focus.ti.com/docs/prod/productfolder.jhtml?genericPartNumber=UA7805 Texas Instruments, 2002.

Ultralife Batteries Inc. http://www.ulbi.com/. “Ultrasonic transducers.”

http://www.panametrics.com/div_ndt/pages/products/transducers/index.shtml. NDT Panametrics, 1999.

“Underwater Applications.” http://www.itc-transducers.com/168-0018.htm. International

Transducer Corporation, 2000. “Underwater Speakers.” http://www.lubell.com/. Lubell Labs, 2002.

137

Page 143: Acoustic Remote Sensing

“Voltage Output Temperature Sensor With Signal Conditioning.”

http://products.analog.com/products/info.asp?product=AD22100. Analog Devices Inc., 2002.

138

Page 144: Acoustic Remote Sensing

;*********************************************************************************************** ;This program is part of the Acoustic Remote Sensing project. ARS is a sonar ranging device ;that utilizes a PIC16F877 at 4MHz MCU to interface with 50KHz underwater transducer. Also installed in ;this device is an Optrex 16207 16x2 LCD module, 2 control buttons, and an SPI bus that ;interfaces with a DS1305 MaximIC Real-Time Clock, FM25640 Ramtron 64KB FRAM, a DS1722 MaximIC ;temperature sensor, and a SanDisk MulitMediaCard. ; ;Code generated by Akradanai Viranuvatti, Stacy Jimerson, and James Coots. ;*********************************************************************************************** ;List of functions: ;reset, iterrupt, incihr, setihr, start, booty, bank0, bank1, bank2, bank3, cnfg, ;spi_out, spi_in, spidly, shtdly, lngdly, vardly, send, lcd_init, outsp, outcma, ;outcol, outslsh, lcddisp, nxtln, lcdclr, lcdhom, bcksp, mode0, mode1, mode2, ;mode3, w_rtc, r_rtc, bcdtoasc, set_hmth, set_lmth, set_hday, set_lday ;set_hyr, set_lyr, set_hhr, set_lhr, set_hmin, set_lmin, update, combmth, combday ;combyr, combhr, combmin, set_hmth, set_lmth, set_hday, set_lday, set_hyr, set_lyr, ;set_hhr, set_lhr, set_hmin, set_lmin, update, combmth, combday, combyr, combhr, ;combmin, main ;*********************************************************************************************** list p=16f877 include <p16f877.inc> ;**************************Variables********************************* cblock h'20' ;store variable block at 0x20 count1 ;used for shtdly and lngdly count2 ;used in lngdly h_tmr1 ;used to store timer1 upper byte l_tmr1 ;used to store timer1 lower byte x1 ;used for PWM, and other temporary variables x2 ;used for PWM, and other temporary variables disp ;used to display on LCD conv ;used for converting bcd and binary to ascii hold ;used for holding upper byte in bcdtoasc store ;used for converting BCD to ascii h_byte ;used for storing converted upper ascii byte l_byte ;used for storing converted lower ascii byte h_mth ;upper byte for ascii month l_mth ;lower byte for ascii month h_day ;upper byte for ascii day

139

Page 145: Acoustic Remote Sensing

l_day ;lower byte for ascii day h_yr ;upper byte for ascii year l_yr ;lower byte for ascii year h_hr ;upper byte for ascii hour l_hr ;lower byte for ascii hour h_min ;upper byte for ascii minute l_min ;lower byte for ascii minute h_sec ;upper byte for ascii second l_sec ;lower byte for ascii second bintemp h_temp ;upper byte for ascii temperature l_temp ;lower byte for ascii temperature dat ;used as holder for mux bcdmth ;used for month in BCD bcdday ;used for day in BCD bcdyr ;used for year in BCD bcdhr ;used for hour in BCD bcdmin ;used for minute in BCD flags1 ;all bits used as flags to mark which date/time variable is being set flags2 ;bits 0 and 1 used as flags to mark which date/time variable is being set ;bit 7 used to move to next variable data_hi data_lo ;used to store data read from the CF sectcnt_hi sectcnt_lo ;used to store the sector count variable to calculate data storage position storage_hi storage_lo ;used to store position of data storage sector byte_cnt ;used to store how many bytes are written track_sec ;used to track the number of sectors written to calculate file size ;43 variables so far 7/21/02 endc MSB equ 7 LSB equ 0 ; define commonly used bits ; STATUS bit definitions #define_C STATUS,0 #define_Z STATUS,2 #define P16_MAP1 0 #define P16_MAP2 1

140

Page 146: Acoustic Remote Sensing

;********************************************************************************************* ; ; FLOATING POINT SPECIFIC DEFINITIONS ; ; literal constants ; EXPBIAS equ D'127' SIG_FIG equ 4 ;set SIG_FIG equal to the number of ;significant figures in your decimal number ;for example: ones, tenths,hundredths, ;thousandths, requires 4 sig figs ; ; ; bcf STATUS,RP1 ; bsf STATUS,RP0 ;ACCB7 equ 0x60 ;ACCB6 equ 0x61 ACCB5 equ 0x5C ACCB4 equ 0x5D ACCB3 equ 0x5E ACCB2 equ 0x5F ACCB1 equ 0x60 ACCB0 equ 0x61 ACC equ 0x61 ; most significant byte of contiguous 8 byte accumulator ; SIGN equ 0x63 ; save location for sign in MSB ; ;TEMPB3 equ 0x70 ;TEMPB2 equ 0x71 TEMPB1 equ 0x64 TEMPB0 equ 0x65 TEMP equ 0x66 ; temporary storage ; ; binary operation arguments ; ;AARGB7 equ 0x60 ;AARGB6 equ 0x61 AARGB5 equ 0x5C AARGB4 equ 0x5D AARGB3 equ 0x5E AARGB2 equ 0x5F AARGB1 equ 0x60 AARGB0 equ 0x61

141

Page 147: Acoustic Remote Sensing

AARG equ 0x61 ; most significant byte of argument A ; BARGB3 equ 0x67 BARGB2 equ 0x68 BARGB1 equ 0x69 BARGB0 equ 0x6A BARG equ 0x6A ; most significant byte of argument B ; ; Note that AARG and ACC reference the same storage locations TARG1 equ 0x6E TARG0 equ 0x6F TEXP equ 0x70 ; Temperature floating point R1ARG1 equ 0x71 R1ARG0 equ 0x72 R1EXP equ 0x73 ; Result of 4.61*T or C3*T R2ARG1 equ 0x74 R2ARG0 equ 0x75 R2EXP equ 0x76 ; Result of 0.055*T^2 or C2*T^2 R3ARG1 equ 0x77 R3ARG0 equ 0x78 R3EXP equ 0x79 ; Result of 0.00029*T^3 or C1*T^3 digit_count equ 0x7A tens equ 0x7C ones equ 0x7D tenths equ 0x7E hundredths equ 0x7F ;(((((((((((((((((((((((ADDRESSES above should be in bank 1))))))))))))))))))))))) ;********************************************************************************************* ; ; Floating POINT SPECIFIC DEFINITIONS...........corrected by too ; ; remainder storage ; ;REMB3 equ 0x60 ;REMB2 equ 0x61 REMB1 equ 0x5C REMB0 equ 0x5D ; most significant byte of remainder LOOPCOUNT equ 0x7B ; loop counter ; ;********************************************************************************************* ;

142

Page 148: Acoustic Remote Sensing

; FLOATING POINT SPECIFIC DEFINITIONS ; ; literal constants ; ; biased exponents ; EXP equ 0x62 ; 8 bit biased exponent AEXP equ 0x62 ; 8 bit biased exponent for argument A BEXP equ 0x6B ; 8 bit biased exponent for argument B ; ; floating point library exception flags ; FPFLAGS equ 0x6D ; floating point library exception flags IOV equ 0 ; bit0 = integer overflow flag FOV equ 1 ; bit1 = floating point overflow flag FUN equ 2 ; bit2 = floating point underflow flag FDZ equ 3 ; bit3 = floating point divide by zero flag NAN equ 4 ; bit4 = not-a-number exception flag DOM equ 5 ; bit5 = domain error exception flag RND equ 6 ; bit6 = floating point rounding flag, 0 = truncation ; 1 = unbiased rounding to nearest LSB SAT equ 7 ; bit7 = floating point saturate flag, 0 = terminate on ; exception without saturation, 1 = terminate on ; exception with saturation to appropriate value ;********************************************************************************************* last_digit set hundredths ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ org 0x00

143

Page 149: Acoustic Remote Sensing

reset bcf PCLATH,4 bsf PCLATH,3 ;change to page 0 goto main ;********************Interrupt Handling Routines********************** org 0x04 interrupt bcf PCLATH,3 ;change to page 0 bcf STATUS,RP0 ;change to bank0 bcf T1CON,TMR1ON ;stop timer1 bcf PCLATH,3 ;change to page 0 bcf STATUS,RP0 ;change to bank0 btfsc PIR1,CCP1IF ;test if CCP caused interrupt goto ccp1ihr btfsc PIR1,TMR1IF ;test if TMR1 overflow caused interrupt goto tmr1ihr btfsc INTCON,INTF ;test if button on RB0 was pushed for increment goto incihr btfss INTCON,RBIF ;test if button on RB7 was pushed for set or shutdown retfie bcf STATUS,RP0 ;change to bank0 bcf PCLATH,3 ;change to page0 btfsc PORTD,7 ;test switch for set time mode or standard mode goto setihr ;if time mode, button used to set time,date, etc. goto shtdwn1 ;if standard mode, sends 512 bytes of zeros to fram ccp1ihr bcf PCLATH,3 ;change to page 0 bcf STATUS,RP0 ;change to bank0 bcf PIR1,CCP1IF ;clear interrupt flag movf TMR1H,W movwf h_tmr1 ;store upper byte of tmr1 movf TMR1L,W movwf l_tmr1 ;store lower byte of tmr1 clrf TMR1L clrf TMR1H bsf PCLATH,3 ;change to page 1 call distn bsf PCLATH,3 ;change to page 1 call float_ascii bsf PCLATH,3 ;change to page 1 call dat_disp ;display results on LCD bcf PCLATH,4 bsf PCLATH,3 ;change to page 1

144

Page 150: Acoustic Remote Sensing

call dat_dump bcf STATUS,RP0 ;change to bank0 bsf flags1,0 bsf STATUS,RP0 ;change to bank1 bcf PIE1,CCP1IE ;disable ccp interrupt bsf PCLATH,3 ;change to page 1 bcf STATUS,RP0 ;change to bank0 retfie tmr1ihr ;if timer1 overflows, not target was detected bcf STATUS,RP0 ;change to bank0 bcf PIR1,TMR1IF ;clear interrupt flag bcf T1CON,TMR1ON ;stop timer1 clrf TMR1H clrf TMR1L ;clear timer to restart call lngdly call lngdly bcf STATUS,RP0 ;change to bank0 bsf flags1,0 bsf PCLATH,3 ;change to page 1 retfie incihr bcf INTCON,INTF ;clear interrupt flag bcf PCLATH,3 ;change to page 0 bcf STATUS,RP0 ;change to bank0 incf store,F ;increment value movf store,W andlw b'00001111' sublw .10 ;value rolls over from 9 to 0 btfss STATUS,Z goto notten clrf store bsf store,5 bsf store,4 notten call lngdly retfie setihr bcf INTCON,RBIF ;clear interrupt flag bcf PCLATH,3 ;change to page0 bcf STATUS,RP0 ;change to bank0 btfss flags1,0 ;test if upper month is being set goto lmthvar movf store,W movwf h_mth

145

Page 151: Acoustic Remote Sensing

call combmth ;combine new upper month with old lower month call w_rtc ;send new value to the RTC goto novar lmthvar btfss flags1,1 ;test if lower month is being set goto hdayvar movf store,W movwf l_mth call combmth ;combine new lower month with old upper month call w_rtc ;send new value to the RTC goto novar hdayvar btfss flags1,2 ;test if upper day is being set goto ldayvar movf store,W movwf h_day call combday ;combine the new upper day with the old lower day call w_rtc ;send new value to the RTC goto novar ldayvarbtfss flags1,3 ;test if lower day is being set goto hyrvar movf store,W movwf l_day call combday ;combine the new lower day with the old upper day call w_rtc ;send new value to the RTC goto novar hyrvar btfss flags1,4 ;test if the upper year is being set goto lyrvar movf store,W movwf h_yr call combyr ;combine new upper year with old lower year call w_rtc ;send new value to the RTC goto novar lyrvar btfss flags1,5 ;test if lower year is being set goto hhrvar movf store,W movwf l_yr call combyr ;combine new lower year with old upper year call w_rtc ;send new value to the RTC

hhrvar btfss flags1,6 ;test if upper hour is being set goto lhrvar movf store,W movwf h_hr call combhr ;combine new upper hour with old lower hour call w_rtc ;send new value to the RTC goto novar

goto novar

lhrvar btfss flags1,7 ;test if lower hour is being set

146

Page 152: Acoustic Remote Sensing

goto hminvar movf store,W movwf l_hr call combhr ;combine new lower hour with old upper hour call w_rtc ;send new value to the RTC goto novar hminvar btfss flags2,0 ;test if the upper minute is being set goto lminvar movf store,W movwf h_min call combmin ;combine new upper minute with old lower minute call w_rtc ;send new value to the RTC goto novar lminvar btfss flags2,1 ;test if the lower minute is being set goto novar movf store,W movwf l_min call combmin ;combine new lower minute with old upper mintue call w_rtc ;send new value to RTC goto novar novar bsf flags2,7 ;set flags2, bit7 to go to the next variable retfie ;***********Port and Timer Clearing Before Boot Up*************** start call bank0 clrf PORTA clrf PORTB clrf PORTC clrf PORTD clrf PORTE ;clear all ports in bank0 clrf TMR0 clrf TMR1L clrf TMR1H clrf TMR2 ;reset all timers in bank0 call bank1 clrf TRISA clrf TRISB clrf TRISC clrf TRISD ;I/O lines for CF clrf TRISE clrf SSPSTAT ;clear all port I/O controls and the SSPSTAT register in bank1 return

147

Page 153: Acoustic Remote Sensing

;************Boot Up Sequence****************** booty call bank1 movlw b'11101000' movwf OPTION_REG ;PORTB pull-ups disabled, interrupt on rising edge of RB0 movlw b'00000000' movwf PIE1 ;set CCP1 interrupt disable, set tmr1 interrupt disable movlw b'00000110' movwf ADCON1 ;set all PORTA pins as digital I/O clrf PIE2 ;clear, not using timer2 movlw b'01010100' movwf TRISC ;RC2 input for CCP1, RC3 Serial CLK, RC4 input for SDI, RC5 SD0, RC6 input RDY/BSY, RC7 MUX CE movlw b'10000000' movwf SSPSTAT ;sample at end of data, on rising edge, mode0 default movlw b'10000001' movwf TRISB ;configure RB7 and RB0 as inputs for buttons movlw b'00000010' movwf TRISE ;PWM is RE0, RE1 is slide switch, RE2 is nothing call bank0 clrf STATUS ;clear first three bits of STATUS clrf PIR1 ;clear all interrupt flags clrf PIR2 ;clear all interrupt flags movlw b'11011000' movwf INTCON ;set global, peripheral, RB0, and RB port change interrupt enable movlw b'00110001' movwf SSPCON ;set SPI for Fosc/16, enable serial port, clk idle state is high movlw b'00000000' movwf T1CON ;set timer1 to sync with internal clock source at 1MHz,1:1 prescale movlw b'00000101' movwf CCP1CON ;set CCP = capture mode, rising edge return ;***********General Register and Memory Subroutines*************** bank0 bcf STATUS,RP0 bcf STATUS,RP1 return ;subroutine to switch to bank0 bank1 bsf STATUS,RP0 bcf STATUS,RP1 return ;subroutine to switch to bank1 bank2

148

Page 154: Acoustic Remote Sensing

bcf STATUS,RP0 bcf STATUS,RP1 return ;subroutine to switch to bank2 bank3 bsf STATUS,RP0 bsf STATUS,RP1 return ;subroutine to switch to bank3 ;***************SPI configuration***************** cnfg call bank0 bcf PCLATH,3 ;change to page 0 temp bcf PORTB,2 ;reset RB2 (chip select), noninverting nop nop nop bsf PORTB,2 ;assert chip select movf SSPBUF,W movlw b'10000000' ;call address to write call spi_out movf SSPBUF,W movlw b'11100000' ;configure temp sensor...8-bit continuous read mode call spi_out bcf PORTB,2 ;reset temp sensor CS movf SSPBUF,W rtc bcf PORTB,3 ;reset RD3 (chip select), noninverting nop nop nop bsf PORTB,3 ;assert chip select movf SSPBUF,W movlw b'10001111' ;call address to write call spi_out movf SSPBUF,W movlw b'00000000' ;configure rtc to enable oscillator, disable write protect call spi_out movf SSPBUF,W movlw b'10000010' ;call address for Hours call spi_out movf SSPBUF,W movlw b'00000000' ;set to 24 Hr mode call spi_out bcf PORTB,3 ;reset rtc CS movf SSPBUF,W return

149

Page 155: Acoustic Remote Sensing

;**********************Compact Flash Initialization**************************** cf_init movlw b'00011000' movwf dat,F bsf PCLATH,3 ;change to page1 call mux ;set OE and WE high because they are active low ;Reset the card movlw b'00111000' movwf dat call mux ;assert the CF card RESET line movlw b'00011000' movwf dat call mux ;de-assert the CF card RESET line lngdly lngdly lngdly lngdly lngdly ;Read the FAT for filename and data storage position movlw b'00000000' movwf PORTD movlw b'00011110' movwf dat call mux call cf_write ;head/drive register zero movlw b'00011101' movwf dat call mux call cf_write ;cylinder high register zero movlw b'00011100' movwf dat call mux call cf_write ;cylinder low register zero movlw b'00011011' movwf dat call mux call cf_write ;sector number register zero movlw b'00011010' movwf dat

150

Page 156: Acoustic Remote Sensing

call mux call cf_write ;sector count register zero movlw 0x20 movwf PORTD movlw b'00011111' movwf dat call mux call cf_write ;send read sector command to fill buffer movlw b'00011000' movwf dat call mux ;set up to read data register movlw .13 ;skip this many words movwf x1 trunc1 call cf_read decfsz x1,F goto trunc1 ;read, but skip over number of bytes in x1 call cf_read movf data_lo,W movwf sectcnt_lo movf data_hi,W movwf sectcnt_hi ;read offset 14 to obtain the sector count ;calculate the sector for the filename ;calculate the sector for the data storage location ;write head,cylinder,sector etc. for data location movlw 0x30 ;write register with erase movwf PORTD movlw b'00011111' movwf dat call mux call cf_write ;send write sector command movlw b'00011000' movwf dat call mux ;prepare to write to data sector ;stay in write mode

151

Page 157: Acoustic Remote Sensing

movlw .16 movwf byte_cnt ;initialze byte_cnt for 512 bytes written after exactly 16 data dumps clrf track_sec ;reset track of total sectors written return ;*****************************SPI Commands************************************* ;transmit spi command: Make sure to clear SSPBUF and spi_out ;put command or data to send in w first movwf SSPBUF ;move data to buffer call spidly ;wait 32 clock cycles return spi_in movlw b'00000000' movwf SSPBUF ;send 8 clock pulses for data transmit call spidly chkbf btfss SSPSTAT,BF ;wait until buffer is full goto chkbf movf SSPBUF,W ;move received data to w register return spidly movlw b'00001001' ;use 9 counts for delay movwf x1 spisub decfsz x1,F goto spisub ;SPI timing delay - 32 cycles return ;********************Delay Routines******************************** shtdly clrf count1 ;short delay -> 255.5us at 4 MHz shdl incfsz count1,F goto shdl return lngdly clrf count1 ;long delay -> 65.2ms at 4 MHz clrf count2 lndl incfsz count1,F goto lndl incfsz count2,F goto lndl return

152

Page 158: Acoustic Remote Sensing

vardly decfsz x1,F ;variable delay requires that x1 is set to a desired value goto vardly ;before calling decfsz x2,F goto vardly return ;2us to 65.2ms at 4 MHz ;********************LCD Functions********************************* ; LCD on PORTA -> '0,0,E,RS,DB7,DB6,DB5,DB4' send ;data to be sent to LCD must be put on PORTA before call bank0 ;this function is called bcf PCLATH,3 ;change to page 0 bsf PORTA,5 ;assert enable call shtdly bcf PORTA,5 ;de-assert enable return lcd_init call lngdly ;lcd power on delay call bank0 bcf PCLATH,3 ;change to page0 movlw b'00000010' movwf PORTA ;first command sets LCD to 4-bit mode call send movlw b'00000000' movwf PORTA call send movlw b'00001100' movwf PORTA ;turn display on, cursor off, blink off call send movlw b'00000010' movwf PORTA call send movlw b'00001000' movwf PORTA ;set to two line display and 5x8 character font call send call lcdclr ;clear lcd data memory return ;*******************LCD Output Funcitons******************* outsp call bank0

153

Page 159: Acoustic Remote Sensing

movlw b'00010001' movwf PORTA call send movlw b'00011111' movwf PORTA ;single space call send return outcma call bank0 movlw b'00010010' movwf PORTA call send movlw b'00011100' movwf PORTA ;comma call send return outcln call bank0 movlw b'00010011' movwf PORTA call send movlw b'00011010' movwf PORTA ;colon call send return outslsh call bank0 movlw b'00010010' movwf PORTA call send movlw b'00011111' movwf PORTA ;slash call send return outdot call bank0 movlw b'00010010' movwf PORTA call send movlw b'00011110' movwf PORTA ;decimal point call send

154

Page 160: Acoustic Remote Sensing

return ;********************************LCD Variable Display Function******************************** lcddisp ;displays variable single digit binary numbers 0-9 bcf PCLATH,3 ;change to page0 call bank0 ;value to be displayed must be put is variable: disp movlw b'00010011' ;before this function is called movwf PORTA call send movf disp,W andlw b'00001111' addlw b'00010000' movwf PORTA call send return ;************ LCD command routines************* nxtln call bank0 movlw b'00001100' movwf PORTA call send movlw b'00000000' movwf PORTA call send ;next line call lngdly return lcdclr call bank0 movlw b'00000000' movwf PORTA call send movlw b'00000001' movwf PORTA ;clear screen, set cursor to address 0 call send call lngdly return lcdhom call bank0 movlw b'00001000' movwf PORTA call send movlw b'00000000' movwf PORTA ;move cursor to home position call send

155

Page 161: Acoustic Remote Sensing

call lngdly return bcksp call bank0 movlw b'00000001' movwf PORTA call send movlw b'00000000' movwf PORTA ;move one space back call send call lngdly return ;***********************PWM (ping)****************************** ping bcf PCLATH,3 ;change to page0 bcf STATUS,RP0 ;change to bank0 movlw b'00000011' movwf x2 ;set x2 = 3 for 3 periods of PWM ping1 movlw b'00000001' movwf x1 ;set x1 = 15 for 50 instructional cycles for high period of 10uS bsf PORTE,0 ;set PORTE high pdly1 decfsz x1,F goto pdly1 ;PORTE high for 10uS clrf x1 incf x1,F ;set x1 = 15 for 50 instructional cycles for high period of 10uS nop nop nop nop nop bcf PORTE,0 ;set PORTE low pdly2 decfsz x1,F goto pdly2 nop nop decfsz x2,F goto ping1 ;goto ping return ;****************Temperature Sensor Functions*************************** tmp_rd call bank0 bcf PCLATH,3 ;change to page0 bcf PORTB,2 ;reset CS for temp sensor nop

156

Page 162: Acoustic Remote Sensing

nop nop bsf PORTB,2 ;assert CS movf SSPBUF,W movlw b'00000010' ;call address to read call spi_out movf SSPBUF,W call spi_in bcf PORTB,2 ;clear CS movwf bintemp movwf conv ;place recieved data in conv for ascii conversion call bintoasc ;convert binary temp into ascii movf h_byte,W movwf h_temp ;store first ascii digit in h_temp movf l_byte,W movwf l_temp ;store second ascii digit in l_temp return ;*********************Real Time Clock Interface******************** w_rtc ;This function writes the date and time to the RTC bcf STATUS,RP0 ;change to bank0 bcf PCLATH,3 ;change to page0 bcf PORTB,3 ;reset CS nop nop nop bsf PORTB,3 ;set CS movf SSPBUF,W wr_mth movlw b'10000101' ;call address to write month call spi_out movf SSPBUF,W movf bcdmth,W ;month in BCD format call spi_out bcf PORTB,3 ;reset CS nop nop nop bsf PORTB,3 ;set CS movf SSPBUF,W wr_daymovlw b'10000100' ;call address to write day call spi_out movf SSPBUF,W movf bcdday,W ;day in BCD format call spi_out bcf PORTB,3 ;reset CS

157

Page 163: Acoustic Remote Sensing

nop nop nop bsf PORTB,3 ;set CS movf SSPBUF,W wr_yr movlw b'10000110' ;call address to write year call spi_out movf SSPBUF,W movf bcdyr,W ;year in BCD format call spi_out bcf PORTB,3 ;reset CS nop nop nop bsf PORTB,3 ;set CS movf SSPBUF,W wr_hr movlw b'10000010' ;call address to write hour call spi_out movf SSPBUF,W movf bcdhr,W ;hour in BCD format call spi_out bcf PORTB,3 ;reset CS nop nop nop bsf PORTB,3 ;set CS movf SSPBUF,W wr_min movlw b'10000001' ;call address to write minute call spi_out movf SSPBUF,W movf bcdmin,W ;minute in BCD format call spi_out bcf PORTB,3 ;reset CS nop nop nop bsf PORTB,3 ;set CS movf SSPBUF,W return ;This function reads the date and time for the RTC and r_rtc ;stores these values in ascii format bcf STATUS,RP0 ;change to bank0 bcf PCLATH,3 ;change to page 0 bcf PORTB,3 ;reset CS

158

Page 164: Acoustic Remote Sensing

nop nop nop bsf PORTB,3 ;set CS movf SSPBUF,W rd_mth movlw b'00000101' ;call address to read month call spi_out movf SSPBUF,W call spi_in bcf PORTB,3 ;reset CS movwf conv call bcdtoasc ;convert BCD to ascii movf h_byte,W movwf h_mth ;store first ascii digit movf l_byte,W movwf l_mth ;store second ascii digit bsf PORTB,3 ;set CS movf SSPBUF,W rd_day movlw b'00000100' ;call address to read day call spi_out movf SSPBUF,W call spi_in bcf PORTB,3 ;reset CS movwf conv call bcdtoasc ;convert from BCD to Binary movf h_byte,W movwf h_day ;store first ascii digit movf l_byte,W movwf l_day ;store second ascii digit bsf PORTB,3 ;set CS rd_yr movlw b'00000110' ;call address to read year call spi_out movf SSPBUF,W call spi_in bcf PORTB,3 ;reset CS movwf conv call bcdtoasc ;convert BCD to ascii movf h_byte,W movwf h_yr ;store first ascii digit movf l_byte,W movwf l_yr ;store second ascii digit bsf PORTB,3 ;set CS rd_hr movlw b'00000010' ;call address to read hour

159

Page 165: Acoustic Remote Sensing

call spi_out movf SSPBUF,W call spi_in bcf PORTB,3 ;reset CS movwf conv call bcdtoasc ;convert from BCD to Binary movf h_byte,W movwf h_hr ;store first ascii digit movf l_byte,W movwf l_hr ;store second ascii digit bsf PORTB,3 ;set CS rd_min movlw b'00000001' ;call address to read minute call spi_out movf SSPBUF,W call spi_in bcf PORTB,3 ;reset CS movwf conv call bcdtoasc ;convert from BCD to Binary movf h_byte,W movwf h_min ;store first ascii digit movf l_byte,W movwf l_min ;store second ascii digit bsf PORTB,3 ;set CS rd_sec movlw b'00000000' ;call address to read second call spi_out movf SSPBUF,W call spi_in bcf PORTB,3 ;clear CS movwf conv call bcdtoasc ;convert from BCD to Binary movf h_byte,W movwf h_sec ;store first ascii digit movf l_byte,W movwf l_sec ;store second ascii digit return ;***********************************Shutdown sequence**************************************** shtdwn1 bcf STATUS,RP0 ;change to bank0 bsf PCLATH,3 ;change to page1 ;fill buffer with zeros

160

Page 166: Acoustic Remote Sensing

;send last sector ;increment track_sec ;calculate the file size using 512*track_sec ;get back to FAT sector ;write filename at offset 32 ;skip to offset for filesize ;write file size call lcdclr movlw b'00010101' movwf PORTA call send movlw b'00010011' movwf PORTA ;S call send movlw b'00010100' movwf PORTA call send movlw b'00010001' movwf PORTA ;A call send movlw b'00010100' movwf PORTA call send movlw b'00010110' movwf PORTA ;F call send movlw b'00010100' movwf PORTA call send movlw b'00010101' movwf PORTA ;E call send call outsp

161

Page 167: Acoustic Remote Sensing

movlw b'00010101' movwf PORTA call send movlw b'00010100' movwf PORTA ;T call send movlw b'00010100' movwf PORTA call send movlw b'00011111' movwf PORTA ;O call send call outsp movlw b'00010101' movwf PORTA call send movlw b'00010100' movwf PORTA ;T call send movlw b'00010101' movwf PORTA call send movlw b'00010101' movwf PORTA ;U call send movlw b'00010101' movwf PORTA call send movlw b'00010010' movwf PORTA ;R call send movlw b'00010100' movwf PORTA call send movlw b'00011110' movwf PORTA ;N call send call outsp movlw b'00010100'

162

Page 168: Acoustic Remote Sensing

movwf PORTA call send movlw b'00011111' movwf PORTA ;O call send movlw b'00010100' movwf PORTA call send movlw b'00010110' movwf PORTA ;F call send movlw b'00010100' movwf PORTA call send movlw b'00010110' movwf PORTA ;F call send bsf STATUS,RP0 ;change to bank1 movlw b'00000000' movwf INTCON ;turn off interrupts so it can't wake up sleep ;***********************************Value Conversions**************************************** ;value to be converted must be stored in conv before this ;fuction is called. It is converted to ascii and bcdtoasc bcf STATUS,RP0 ;change to bank0 bcf PCLATH,3 ;change to page0 ;stored in h_byte and l_byte swapf conv,W andlw b'00001111' ;strip off upper bits addlw b'00110000' ;complete ascii value movwf h_byte ;store first ascii digit movf conv,W andlw b'00001111' ;strip off lower bits addlw b'00110000' ;complete ascii value movwf l_byte ;store second ascii digit return ;value to be converted must be stored in conv before this ;function is called. It is converted from binary to ascii and

163

Page 169: Acoustic Remote Sensing

bintoasc ;stored in h_byte and l_byte bcf STATUS,RP0 ;change to bank0 bcf PCLATH,3 ;change to page0 clrf h_byte clrf l_byte movlw .10 movwf count1 ;count1 is used to determine upper byte incrementing btfss conv,7 goto bsix movlw .128 movwf x1 ;bit 7 is 128 in decimal call change bsix btfss conv,6 goto bfive movlw .64 movwf x1 ;bit 6 is 64 in decimal call change bfive btfss conv,5 goto bfour movlw .32 movwf x1 ;bit 5 is 32 in decimal call change bfour btfss conv,4 goto bthree movlw .16 movwf x1 ;bit 4 is 16 in decimal call change bthree btfss conv,3 goto btwo movlw .8 movwf x1 ;bit 3 is 8 in decimal call change btwo btfss conv,2 goto bone movlw .4 movwf x1 ;bit 2 is 4 in decimal call change bone btfss conv,1 goto bzero

164

Page 170: Acoustic Remote Sensing

movlw .2 movwf x1 ;bit 1 is 2 in decimal call change bzero btfss conv,0 goto nomore movlw .1 movwf x1 ;bit 0 is 1 in decimal call change nomore movlw b'00110000' addwf h_byte,F addwf l_byte,F ;complete ascii values return change bcf STATUS,Z loop incf l_byte,F decf count1,F btfss STATUS,Z ;check if upper byte needs to be increments after lower goto no_tens ;byte exceeds 9 incf h_byte,F clrf l_byte movlw .10 movwf count1 no_tens decf x1,F ;x1 adds the total values from each bit btfss STATUS,Z goto loop return ;**********************Time Setting Functions********************** ;The set functions will stay in sleep mode until the ;interrupt buttons are pressed. The function will continue ;to loop after the increment button is pressed and will ;go to the next set function after the set button is pressed

udhmth call lcdclr call update ;update the date and time

set_hmth bsf flags1,0 ;flags1, bit0 is set to flag h_mth movf h_mth,W movwf store ;store is used for the current variable being changed

call nxtln bcf flags2,7 ;flags2, bit7 is set when ready for the next function call bank0

165

Page 171: Acoustic Remote Sensing

movlw b'00010100'

call send

call send

call bcksp

movf l_mth,W

bcf flags2,7 call bank0

movwf PORTA call send movlw b'00011101' movwf PORTA ;M

movlw b'00010111' movwf PORTA call send movlw b'00010100' movwf PORTA ;t call send movlw b'00010110' movwf PORTA

movlw b'00011000' movwf PORTA ;h call send call outsp ;space movf store,W movwf disp call lcddisp ;display changing variable movf l_mth,W movwf disp call lcddisp ;display l_mth

call bcksp ;leave cursor under variable to be changed sleep ;sleep until button is pressed nop nop btfss flags2,7 ;test if variable has been set and the next one can be changed now goto udhmth bcf flags2,7 bcf flags1,0 ;clear flags1, bit0 to notify h_mth is no longer being changed return set_lmth bsf flags1,1 ;flags1, bit1 is set to flag l_mth

movwf store udlmth call lcdclr call update call nxtln

movlw b'00010100'

166

Page 172: Acoustic Remote Sensing

movwf PORTA call send movlw b'00011101' movwf PORTA ;M call send

movlw b'00010100'

movwf disp

call bcksp

bcf flags2,7

movf h_day,W

call bank0

movlw b'00010111' movwf PORTA call send

movwf PORTA ;t call send movlw b'00010110' movwf PORTA call send movlw b'00011000' movwf PORTA ;h call send call outsp movf h_mth,W movwf disp call lcddisp movf store,W

call lcddisp

sleep nop nop btfss flags2,7 goto udlmth

bcf flags1,1 return set_hday bsf flags1,2 ;flags1, bit2 is set to flag h_day

movwf store udhday call lcdclr call update call nxtln bcf flags2,7

movlw b'00010100' movwf PORTA call send

167

Page 173: Acoustic Remote Sensing

movlw b'00010100' movwf PORTA ;D call send movlw b'00010110'

movwf PORTA

movf store,W

call bcksp

bcf flags2,7

movf l_day,W

movwf PORTA call send movlw b'00010001' movwf PORTA ;a call send movlw b'00010111'

call send movlw b'00011001' movwf PORTA ;y call send call outsp

movwf disp call lcddisp movf l_day,W movwf disp call lcddisp

call bcksp sleep nop nop btfss flags2,7 goto udhday

bcf flags1,2 return set_lday bsf flags1,3 ;flags1, bit3 is set to flag l_day

movwf store udlday call lcdclr call update call nxtln bcf flags2,7 call bank0 movlw b'00010100' movwf PORTA call send movlw b'00010100'

168

Page 174: Acoustic Remote Sensing

movwf PORTA ;D call send movlw b'00010110' movwf PORTA call send movlw b'00010001' movwf PORTA ;a call send movlw b'00010111' movwf PORTA call send movlw b'00011001' movwf PORTA ;y call send call outsp movf h_day,W movwf disp call lcddisp movf store,W movwf disp call lcddisp call bcksp sleep nop nop btfss flags2,7 goto udlday bcf flags2,7 bcf flags1,3 return set_hyr bsf flags1,4 ;flags1, bit4 is set to flag h_yr movf h_yr,W movwf store udhyr call lcdclr call update call nxtln bcf flags2,7 call bank0 movlw b'00010101' movwf PORTA call send movlw b'00011001' movwf PORTA ;Y call send

169

Page 175: Acoustic Remote Sensing

movlw b'00010111' movwf PORTA call send movlw b'00010010'

btfss flags2,7 goto udhyr

call send

movwf PORTA ;r call send call outsp call outsp movf store,W movwf disp call lcddisp movf l_yr,W movwf disp call lcddisp call bcksp call bcksp sleep nop nop

bcf flags2,7 bcf flags1,4 return set_lyr bsf flags1,5 ;flags1, bit5 is set to flag l_yr movf l_yr,W movwf store udlyr call lcdclr call update call nxtln bcf flags2,7 call bank0 movlw b'00010101' movwf PORTA call send movlw b'00011001' movwf PORTA ;Y

movlw b'00010111' movwf PORTA call send movlw b'00010010' movwf PORTA ;r call send

170

Page 176: Acoustic Remote Sensing

call outsp

movf store,W

nop

return

bcf flags2,7

movlw b'00011000'

movlw b'00010010'

call outsp movf h_yr,W movwf disp call lcddisp

movwf disp call lcddisp call bcksp sleep

nop btfss flags2,7 goto udlyr bcf flags2,7 bcf flags1,5

set_hhr bsf flags1,6 ;flags1, bit6 is set to flag h_hr movf h_hr,W movwf store udhhr call lcdclr call update call nxtln

call bank0 movlw b'00010100' movwf PORTA call send

movwf PORTA ;H call send movlw b'00010111' movwf PORTA call send

movwf PORTA ;r call send call outsp call outsp movf store,W movwf disp call lcddisp movf l_hr,W movwf disp

171

Page 177: Acoustic Remote Sensing

call lcddisp call bcksp call bcksp sleep nop nop btfss flags2,7 goto udhhr bcf flags2,7 bcf flags1,6 return set_lhr bsf flags1,7 ;flags1, bit7 is set to flag l_hr movf l_hr,W movwf store udlhr call lcdclr call update call nxtln bcf flags2,7 call bank0 movlw b'00010100' movwf PORTA

movwf PORTA

movwf PORTA ;r

movf h_hr,W

nop

call send movlw b'00011000' movwf PORTA ;H call send movlw b'00010111'

call send movlw b'00010010'

call send call outsp call outsp

movwf disp call lcddisp movf store,W movwf disp call lcddisp call bcksp sleep

nop btfss flags2,7

172

Page 178: Acoustic Remote Sensing

goto udlhr bcf flags2,7

movwf store

bcf flags2,7 call bank0

call send movlw b'00011101'

call send

call send movlw b'00010110' movwf PORTA

call send

movwf disp call lcddisp movf l_min,W movwf disp call lcddisp call bcksp

sleep nop nop

bcf flags1,7 return set_hmin bsf flags2,0 ;flags2, bit0 is set to flag h_min movf h_min,W

udhmin call lcdclr call update call nxtln

movlw b'00010100' movwf PORTA

movwf PORTA ;M

movlw b'00010110' movwf PORTA call send movlw b'00011001' movwf PORTA ;i

call send movlw b'00011110' movwf PORTA ;n

call outsp movf store,W

call bcksp

btfss flags2,7 goto udhmin

173

Page 179: Acoustic Remote Sensing

bcf flags2,7

bsf flags2,1 ;flags2, bit1 is set to flag l_min

movlw b'00011101' movwf PORTA ;M call send movlw b'00010110' movwf PORTA

movlw b'00011001'

movwf PORTA

call lcddisp

btfss flags2,7

bcf flags2,0 return

set_lmin

movf l_min,W movwf store udlmin call lcdclr call update call nxtln bcf flags2,7 call bank0 movlw b'00010100' movwf PORTA call send

call send

movwf PORTA ;i call send movlw b'00010110'

call send movlw b'00011110' movwf PORTA ;n call send call outsp movf h_min,W movwf disp

movf store,W movwf disp call lcddisp call bcksp sleep nop nop

goto udlmin bcf flags2,7 bcf flags2,1

174

Page 180: Acoustic Remote Sensing

return update call r_rtc movf h_mth,W movwf disp call lcddisp ;display first digit

call lcddisp ;display second digit

movf h_day,W

movf l_day,W

call lcddisp ;display second digit

movwf disp

movf l_yr,W

call outsp

movwf disp

movwf disp call lcddisp ;display second digit return

combmth swapf h_mth,W andlw b'11110000' movwf bcdmth movf l_mth,W

movf l_mth,W movwf disp

call outslsh

movwf disp call lcddisp ;display first digit

movwf disp

call outslsh movf h_yr,W

call lcddisp ;display first digit

movwf disp call lcddisp ;display second digit

movf h_hr,W

call lcddisp ;display first digit movf l_hr,W movwf disp call lcddisp ;display second digit call outcln movf h_min,W movwf disp call lcddisp ;display first digit movf l_min,W

;The following combine functions form BCD mth,day,yr,hr,min

175

Page 181: Acoustic Remote Sensing

andlw b'00001111' addwf bcdmth,F return combday

andlw b'11110000'

movf l_day,W andlw b'00001111'

return

andlw b'11110000'

andlw b'00001111'

andlw b'11110000'

andlw b'11110000' movwf bcdmin movf l_min,W andlw b'00001111'

return

;;;;;;;;;;;;;;;;;;;;;;Fixed point divide routine for float_ascii conversion;;;;;;;;;;;;;;;

swapf h_day,W

movwf bcdday

addwf bcdday,F

combyr swapf h_yr,W

movwf bcdyr movf l_yr,W

addwf bcdyr,F return

combhr swapf h_hr,W

movwf bcdhr movf l_hr,W andlw b'00001111' addwf bcdhr,F return

combmin swapf h_min,W

addwf bcdmin,F

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;FXD46.a16;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; RCS Header $Id: fxd46.a16 2.3 1996/10/16 14:23:57 F.J.Testa Exp $

176

Page 182: Acoustic Remote Sensing

; Output: quotient AARG/BARG followed by remainder in REM

; It is useful to note that the additional unsigned routines requiring a non-power of two

; performance.

; ; FXD2416S 454 24 bit/16 bit -> 24.16 signed fixed point divide

; FXD2315U 407 23 bit/15 bit -> 23.15 unsigned fixed point divide

;**********************************************************************************************

; Min Timing: 16+6*21+20+20+6*21+20+20+6*21+20+3 = 497 clks

RLF AARGB0,W RLF REMB1, F MOVF BARGB1,W SUBWF REMB1, F

BTFSS _C

; $Revision: 2.3 $ ; 24/16 PIC16 FIXED POINT DIVIDE ROUTINES ; ; Input: fixed point arguments in AARG and BARG ;

; ; All timings are worst case cycle counts ;

; argument can be called in a signed divide application where it is known that the ; respective argument is nonnegative, thereby offering some improvement in

; ; Routine Clocks Function

; ; FXD2416U 529 24 bit/16 bit -> 24.16 unsigned fixed point divide ;

;**********************************************************************************************

UDIV2416L macro

; Max Timing: 16+6*22+21+21+6*22+21+21+6*22+21+8 = 525 clks

; PM: 14+31+27+31+27+31+8 = 169 DM: 8

CLRF TEMP

MOVF BARGB0,W

177

Page 183: Acoustic Remote Sensing

INCFSZ BARGB0,W

CLRW

MOVLW 7

RLF TEMP, F

MOVLW 1

MOVF BARGB0,W

DECFSZ LOOPCOUNT, F

SUBWF REMB0, F

BTFSS _C MOVLW 1 SUBWF TEMP, F RLF AARGB0, F

MOVWF LOOPCOUNT LOOPU2416A RLF AARGB0,W RLF REMB1, F RLF REMB0, F

MOVF BARGB1,W BTFSS AARGB0,LSB GOTO UADD46LA SUBWF REMB1, F MOVF BARGB0,W BTFSS _C INCFSZ BARGB0,W SUBWF REMB0, F CLRW BTFSS _C

SUBWF TEMP, F GOTO UOK46LA

UADD46LA ADDWF REMB1, F

BTFSC _C INCFSZ BARGB0,W ADDWF REMB0, F CLRW BTFSC _C MOVLW 1 ADDWF TEMP, F UOK46LA RLF AARGB0, F

GOTO LOOPU2416A

178

Page 184: Acoustic Remote Sensing

RLF AARGB1,W RLF REMB1, F RLF REMB0, F RLF TEMP, F MOVF BARGB1,W BTFSS AARGB0,LSB GOTO UADD46L8 SUBWF REMB1, F MOVF BARGB0,W BTFSS _C INCFSZ BARGB0,W SUBWF REMB0, F CLRW BTFSS _C

INCFSZ BARGB0,W ADDWF REMB0, F

BTFSS AARGB1,LSB

BTFSS _C

MOVLW 1 SUBWF TEMP, F GOTO UOK46L8 UADD46L8 ADDWF REMB1, F MOVF BARGB0,W BTFSC _C

CLRW BTFSC _C MOVLW 1 ADDWF TEMP, F UOK46L8 RLF AARGB1, F MOVLW 7 MOVWF LOOPCOUNT LOOPU2416B RLF AARGB1,W RLF REMB1, F RLF REMB0, F RLF TEMP, F MOVF BARGB1,W

GOTO UADD46LB

SUBWF REMB1, F MOVF BARGB0,W

INCFSZ BARGB0,W

179

Page 185: Acoustic Remote Sensing

SUBWF REMB0, F CLRW

MOVLW 1

GOTO UOK46LB

UADD46LB ADDWF REMB1, F

ADDWF REMB0, F

BTFSC _C

CLRW

BTFSS _C

SUBWF TEMP, F

MOVF BARGB0,W BTFSC _C INCFSZ BARGB0,W

CLRW

MOVLW 1 ADDWF TEMP, F UOK46LB RLF AARGB1, F DECFSZ LOOPCOUNT, F GOTO LOOPU2416B RLF AARGB2,W RLF REMB1, F RLF REMB0, F RLF TEMP, F MOVF BARGB1,W BTFSS AARGB1,LSB GOTO UADD46L16 SUBWF REMB1, F MOVF BARGB0,W BTFSS _C INCFSZ BARGB0,W SUBWF REMB0, F

BTFSS _C MOVLW 1 SUBWF TEMP, F GOTO UOK46L16 UADD46L16 ADDWF REMB1, F MOVF BARGB0,W BTFSC _C INCFSZ BARGB0,W ADDWF REMB0, F

180

Page 186: Acoustic Remote Sensing

CLRW

ADDWF REMB0, F

BTFSC AARGB2,LSB

BTFSC _C MOVLW 1 ADDWF TEMP, F UOK46L16 RLF AARGB2, F MOVLW 7 MOVWF LOOPCOUNT LOOPU2416C RLF AARGB2,W RLF REMB1, F RLF REMB0, F RLF TEMP, F MOVF BARGB1,W BTFSS AARGB2,LSB GOTO UADD46LC SUBWF REMB1, F MOVF BARGB0,W BTFSS _C INCFSZ BARGB0,W SUBWF REMB0, F CLRW BTFSS _C MOVLW 1 SUBWF TEMP, F GOTO UOK46LC UADD46LC ADDWF REMB1, F MOVF BARGB0,W BTFSC _C INCFSZ BARGB0,W

CLRW BTFSC _C MOVLW 1 ADDWF TEMP, F UOK46LC RLF AARGB2, F DECFSZ LOOPCOUNT, F GOTO LOOPU2416C

GOTO UOK46L

181

Page 187: Acoustic Remote Sensing

MOVF BARGB1,W ADDWF REMB1, F MOVF BARGB0,W BTFSC _C INCFSZ BARGB0,W ADDWF REMB0, F UOK46L endm

; Max Timing: 2+497+2 = 501 clks

;******************************24 bit floating point routines*****************************

;********************************************************************************************** ;********************************************************************************************** ; 24/16 Bit Unsigned Fixed Point Divide 24/16 -> 24.16 ; Input: 24 bit unsigned fixed point dividend in AARGB0, AARGB1,AARGB2 ; 16 bit unsigned fixed point divisor in BARGB0, BARGB1 ; Use: CALL FXD2416U ; Output: 24 bit unsigned fixed point quotient in AARGB0, AARGB1,AARGB2 ; 16 bit unsigned fixed point remainder in REMB0, REMB1 ; Result: AARG, REM <-- AARG / BARG ; Max Timing: 2+525+2 = 529 clks

; PM: 2+169+1 = 172 DM: 8 FXD2416U CLRF REMB0 CLRF REMB1 UDIV2416L RETLW 0x00

182

Page 188: Acoustic Remote Sensing

; RCS Header $Id: fp24.a16 2.7 1996/10/07 13:50:29 F.J.Testa Exp $ ; $Revision: 2.7 $ ; PIC16 24 BIT FLOATING POINT LIBRARY ; ; Unary operations: both input and output are in AEXP,AARG ; ; Binary operations: input in AEXP,AARG and BEXP,BARG with output in AEXP,AARG ; ; All routines return WREG = 0x00 for successful completion, and WREG = 0xFF

; 0 1

;

; for an error condition specified in FPFLAGS. ; ; All timings are worst case cycle counts ; ; Routine Function ; ; FLO1624 16 bit integer to 24 bit floating point conversion ; FLO24 ; ; Timing: RND ; 0 1 ; ; 0 83 83 ; SAT ; 1 88 88 ; ; NRM2424 24 bit normalization of unnormalized 24 bit floating point numbers ; NRM24 ; ; Timing: RND

; ; 0 72 72 ; SAT ; 1 77 77 ; ; INT2416 24 bit floating point to 16 bit integer conversion ; INT24 ; ; Timing: RND ; 0 1

; 0 83 89 ; SAT

183

Page 189: Acoustic Remote Sensing

; 1 83 92 ; ; FLO2424 24 bit integer to 24 bit floating point conversion ; ; Timing: RND ; 0 1 ; ; 0 108 117 ; SAT ; 1 108 123 ; ; NRM3224 32 bit normalization of unnormalized 24 bit floating point numbers ; ; Timing: RND ; 0 1

; INT2424 24 bit floating point to 24 bit integer conversion

; Timing: RND

; ; 0 94 103 ; SAT ; 1 94 109 ;

; ; Timing: RND ; 0 1 ; ; 0 105 113 ; SAT ; 1 105 115 ; ; FPA24 24 bit floating point add ; ; Timing: RND ; 0 1 ; ; 0 197 208 ; SAT ; 1 197 213 ; ; FPS24 24 bit floating point subtract ;

; 0 1 ; ; 0 199 240 ; SAT ; 1 199 215

184

Page 190: Acoustic Remote Sensing

; ; FPM24 24 bit floating point multiply ; ; Timing: RND ; 0 1 ; ; 0 298 309 ; SAT ; 1 298 313 ; ; FPD24 24 bit floating point divide ; ; Timing: RND ; 0 1 ; ; 0 472 494 ; SAT ; 1 472 498 ; ;********************************************************************************************** ;********************************************************************************************** ; ; 24 bit floating point representation ; ; EXPONENT 8 bit biased exponent ; It is important to note that the use of biased exponents produces ; a unique representation of a floating point 0, given by ; EXP = HIGHBYTE = LOWBYTE = 0x00, with 0 being the only ; number with EXP = 0. ; ; HIGHBYTE 8 bit most significant byte of fraction in sign-magnitude representation, ; with SIGN = MSB, implicit MSB = 1 and radix point to the right of MSB ; ; LOWBYTE 8 bit least significant byte of sign-magnitude fraction ; ; EXPONENT HIGHBYTE LOWBYTE ; ; xxxxxxxx S.xxxxxxx xxxxxxxx ; ; | ; RADIX ; POINT

185

Page 191: Acoustic Remote Sensing

; ;********************************************************************************************** ;********************************************************************************************** ; Integer to float conversion

MOVF AARGB0,W

; Input: 16 bit 2's complement integer right justified in AARGB0, AARGB1 ; Use: CALL FLO1624 or CALL FLO24 ; Output: 24 bit floating point number in AEXP, AARGB0, AARGB1 ; Result: AARG <-- FLOAT( AARG ) ; Max Timing: 11+72 = 83 clks SAT = 0 ; 11+77 = 88 clks SAT = 1 ; Min Timing: 7+14 = 21 clks AARG = 0 ; 7+18 = 25 clks ; PM: 11+26 = 37 DM: 6 ;---------------------------------------------------------------------------------------------- FLO1624 FLO24 MOVLW D'15'+EXPBIAS ; initialize exponent and add bias MOVWF EXP

MOVWF SIGN BTFSS AARGB0,MSB ; test sign GOTO NRM2424 COMF AARGB1,F ; if < 0, negate and set MSB in SIGN COMF AARGB0,F INCF AARGB1,F BTFSC _Z INCF AARGB0,F ;********************************************************************************************** ; Normalization routine

186

Page 192: Acoustic Remote Sensing

; Input: 24 bit unnormalized floating point number in AEXP, AARGB0, AARGB1, ; with sign in SIGN,MSB and other bits zero. ; Use: CALL NRM2424 or CALL NRM24

; 10+6+7*7+1+11 = 77 clks SAT = 1

MOVF AARGB0,W ; test if highbyte=0

GOTO RES024

SUBWF EXP,F BTFSS _Z

NORM2424A BTFSC AARGB0,MSB ; if MSB=1, normalization done

GOTO NORM2424A

; Output: 24 bit normalized floating point number in AEXP, AARGB0, AARGB1 ; Result: AARG <-- NORMALIZE( AARG ) ; Max Timing: 10+6+7*7+7 = 72 clks SAT = 0

; Min Timing: 14 clks AARG = 0 ; 5+9+4 = 18 clks ; PM: 26 DM: 6 ;---------------------------------------------------------------------------------------------- NRM2424 NRM24 CLRF TEMP ; clear exponent decrement

BTFSS _Z GOTO NORM2424 MOVF AARGB1,W ; if so, shift 8 bits by move MOVWF AARGB0 BTFSC _Z ; if highbyte=0, result=0

CLRF AARGB1 BSF TEMP,3 NORM2424 MOVF TEMP,W

BTFSS _C GOTO SETFUN24 BCF _C ; clear carry bit

GOTO FIXSIGN24 RLF AARGB1,F ; otherwise, shift left and RLF AARGB0,F ; decrement EXP DECFSZ EXP,F

187

Page 193: Acoustic Remote Sensing

GOTO SETFUN24 ; underflow if EXP=0 FIXSIGN24 BTFSS SIGN,MSB BCF AARGB0,MSB ; clear explicit MSB if positive RETLW 0 RES024 CLRF AARGB0 ; result equals zero CLRF AARGB1 CLRF AARGB2 ; clear extended byte CLRF EXP RETLW 0

; Integer to float conversion

; Output: 24 bit floating point number in AEXP, AARGB0, AARGB1

;----------------------------------------------------------------------------------------------

;********************************************************************************************** ;**********************************************************************************************

; Input: 24 bit 2's complement integer right justified in AARGB0, AARGB1, AARGB2 ; Use: CALL FLO2424

; Result: AARG <-- FLOAT( AARG ) ; Max Timing: 14+94 = 108 clks RND = 0 ; 14+103 = 117 clks RND = 1, SAT = 0 ; 14+109 = 123 clks RND = 1, SAT = 1 ; Min Timing: 6+28 = 34 clks AARG = 0 ; 6+22 = 28 clks ; PM: 14+51 = 65 DM: 7

FLO2424 MOVLW D'23'+EXPBIAS ; initialize exponent and add bias MOVWF EXP CLRF SIGN BTFSS AARGB0,MSB ; test sign GOTO NRM3224 COMF AARGB2,F ; if < 0, negate and set MSB in SIGN

188

Page 194: Acoustic Remote Sensing

COMF AARGB1,F COMF AARGB0,F INCF AARGB2,F BTFSC _Z INCF AARGB1,F BTFSC _Z INCF AARGB0,F BSF SIGN,MSB ;**********************************************************************************************

; Use: CALL NRM3224

; Max Timing: 21+6+7*8+7+4 = 94 clks RND = 0

; 5+9+4+4 = 22 clks

MOVF AARGB0,W ; test if highbyte=0

; Normalization routine ; Input: 32 bit unnormalized floating point number in AEXP, AARGB0, AARGB1, ; AARGB2, with sign in SIGN,MSB

; Output: 24 bit normalized floating point number in AEXP, AARGB0, AARGB1 ; Result: AARG <-- NORMALIZE( AARG )

; 21+6+7*8+20+4 = 103 clks RND = 1, SAT = 0 ; 21+6+7*8+19+11 = 109 clks RND = 1, SAT = 1 ; Min Timing: 22+6 = 28 clks AARG = 0

; PM: 51 DM: 7 ;---------------------------------------------------------------------------------------------- NRM3224 CLRF TEMP ; clear exponent decrement

BTFSS _Z GOTO NORM3224 MOVF AARGB1,W ; if so, shift 8 bits by move MOVWF AARGB0 MOVF AARGB2,W MOVWF AARGB1 CLRF AARGB2 BSF TEMP,3 ; increase decrement by 8 MOVF AARGB0,W ; test if highbyte=0

189

Page 195: Acoustic Remote Sensing

BTFSS _Z GOTO NORM3224 MOVF AARGB1,W ; if so, shift 8 bits by move MOVWF AARGB0 CLRF AARGB1 BCF TEMP,3 ; increase decrement by 8 BSF TEMP,4 MOVF AARGB0,W ; if highbyte=0, result=0 BTFSC _Z GOTO RES024 NORM3224 MOVF TEMP,W SUBWF EXP,F

BCF _C ; clear carry bit

BTFSS AARGB1,LSB GOTO FIXSIGN24

INCF AARGB0,F

INCF EXP,F BTFSC _Z ; check for overflow

BTFSS _Z BTFSS _C GOTO SETFUN24

NORM3224A BTFSC AARGB0,MSB ; if MSB=1, normalization done GOTO NRMRND3224 RLF AARGB2,F ; otherwise, shift left and RLF AARGB1,F ; decrement EXP RLF AARGB0,F DECFSZ EXP,F GOTO NORM3224A GOTO SETFUN24 ; underflow if EXP=0 NRMRND3224 BTFSC FPFLAGS,RND

BTFSS AARGB2,MSB ; round if next bit is set GOTO FIXSIGN24 INCF AARGB1,F BTFSC _Z

BTFSS _Z ; has rounding caused carryout? GOTO FIXSIGN24 RRF AARGB0,F ; if so, right shift RRF AARGB1,F

GOTO SETFOV24 GOTO FIXSIGN24

190

Page 196: Acoustic Remote Sensing

;********************************************************************************************** ;**********************************************************************************************

; Use: CALL INT2416 or CALL INT24

; 29+6*6+5+19 = 89 clks RND = 1, SAT = 0 ; 29+6*6+5+22 = 92 clks RND = 1, SAT = 1 ; Min Timing: 18+5+7 = 30 clks ; PM: 63 DM: 6 ;---------------------------------------------------------------------------------------------- INT2416 INT24 MOVF EXP,W ; test for zero argument BTFSC _Z RETLW 0x00 MOVF AARGB0,W ; save sign in SIGN

BSF AARGB0,MSB ; make MSB explicit

SUBWF EXP,F

GOTO SETIOV16

INCF EXP,F

SUBWF EXP,W

; Float to integer conversion ; Input: 24 bit floating point number in AEXP, AARGB0, AARGB1

; Output: 16 bit 2's complement integer right justified in AARGB0, AARGB1 ; Result: AARG <-- INT( AARG ) ; Max Timing: 29+6*6+5+13 = 83 clks RND = 0

MOVWF SIGN

MOVLW EXPBIAS+D'15' ; remove bias from EXP

BTFSS EXP,MSB

COMF EXP,F

MOVLW 8 ; do byte shift if EXP >= 8

BTFSS _C

191

Page 197: Acoustic Remote Sensing

GOTO TSHIFT2416 MOVWF EXP

MOVWF AARGB1

GOTO TSHIFT2416

RLF AARGB1,F ; rotate next bit for rounding

MOVF EXP,W

BCF _C

TSHIFT2416 MOVF EXP,W ; shift completed if EXP = 0

GOTO SHIFT2416OK

SHIFT2416 BCF _C

RRF AARGB1,F

GOTO SHIFT2416

SHIFT2416OK BTFSC FPFLAGS,RND

GOTO INT2416OK

INCF AARGB1,F

INCF AARGB0,F

BTFSC AARGB0,MSB ; test for overflow

RLF AARGB1,F ; rotate next bit for rounding MOVF AARGB0,W

CLRF AARGB0 MOVLW 8 ; do byte shift if EXP >= 8 SUBWF EXP,W BTFSS _C

MOVWF EXP

CLRF AARGB1

BTFSS _Z

GOTO SHIFT2416OK

BTFSC _Z

RRF AARGB0,F ; right shift by EXP

DECFSZ EXP,F

BTFSS AARGB1,LSB

BTFSS _C ; round if next bit is set GOTO INT2416OK

BTFSC _Z

GOTO SETIOV16 INT2416OK BTFSS SIGN,MSB ; if sign bit set, negate RETLW 0 COMF AARGB1,F COMF AARGB0,F INCF AARGB1,F

192

Page 198: Acoustic Remote Sensing

BTFSC _Z INCF AARGB0,F RETLW 0 SETIOV16 BSF FPFLAGS,IOV ; set integer overflow flag BTFSS FPFLAGS,SAT ; test for saturation RETLW 0xFF ; return error code in WREG CLRF AARGB0 ; saturate to largest two's

; Input: 24 bit floating point number in AEXP, AARGB0, AARGB1

BTFSS SIGN,MSB ; complement 16 bit integer MOVLW 0xFF MOVWF AARGB0 ; SIGN = 0, 0x 7F FF MOVWF AARGB1 ; SIGN = 1, 0x 80 00 RLF SIGN,F RRF AARGB0,F RETLW 0xFF ; return error code in WREG ;********************************************************************************************** ;********************************************************************************************** ; Float to integer conversion

; Use: CALL INT2424 ; Output: 24 bit 2's complement integer right justified in AARGB0, AARGB1, AARGB2 ; Result: AARG <-- INT( AARG ) ; Max Timing: 41+6*7+6+16 = 105 clks RND = 0 ; 41+6*7+6+24 = 113 clks RND = 1, SAT = 0 ; 41+6*7+6+26 = 115 clks RND = 1, SAT = 1 ; Min Timing: 5 clks ; PM: 82 DM: 6 ;---------------------------------------------------------------------------------------------- INT2424 CLRF AARGB2

193

Page 199: Acoustic Remote Sensing

MOVF EXP,W ; test for zero argument BTFSC _Z RETLW 0x00 MOVF AARGB0,W ; save sign in SIGN MOVWF SIGN BSF AARGB0,MSB ; make MSB explicit MOVLW EXPBIAS+D'23' ; remove bias from EXP SUBWF EXP,F BTFSS EXP,MSB GOTO SETIOV24 COMF EXP,F INCF EXP,F MOVLW 8 ; do byte shift if EXP >= 8 SUBWF EXP,W BTFSS _C GOTO TSHIFT2424 MOVWF EXP RLF AARGB2,F ; rotate next bit for rounding MOVF AARGB1,W MOVWF AARGB2 MOVF AARGB0,W MOVWF AARGB1 CLRF AARGB0 MOVLW 8 ; do another byte shift if EXP >= 8 SUBWF EXP,W BTFSS _C GOTO TSHIFT2424 MOVWF EXP RLF AARGB2,F ; rotate next bit for rounding MOVF AARGB1,W MOVWF AARGB2 CLRF AARGB1 MOVLW 8 ; do another byte shift if EXP >= 8 SUBWF EXP,W BTFSS _C GOTO TSHIFT2424 MOVWF EXP RLF AARGB2,F ; rotate next bit for rounding CLRF AARGB2 MOVF EXP,W BTFSS _Z

194

Page 200: Acoustic Remote Sensing

BCF _C GOTO SHIFT2424OK TSHIFT2424 MOVF EXP,W ; shift completed if EXP = 0 BTFSC _Z GOTO SHIFT2424OK SHIFT2424 BCF _C RRF AARGB0,F ; right shift by EXP RRF AARGB1,F RRF AARGB2,F DECFSZ EXP,F GOTO SHIFT2424 SHIFT2424OK BTFSC FPFLAGS,RND BTFSS AARGB2,LSB GOTO INT2424OK BTFSS _C GOTO INT2424OK INCF AARGB2,F BTFSC _Z INCF AARGB1,F BTFSC _Z INCF AARGB0,F BTFSC AARGB0,MSB ; test for overflow GOTO SETIOV24 INT2424OK BTFSS SIGN,MSB ; if sign bit set, negate RETLW 0 COMF AARGB0,F COMF AARGB1,F COMF AARGB2,F INCF AARGB2,F BTFSC _Z INCF AARGB1,F BTFSC _Z INCF AARGB0,F RETLW 0 IRES024 CLRF AARGB0 ; integer result equals zero CLRF AARGB1 CLRF AARGB2 RETLW 0 SETIOV24 BSF FPFLAGS,IOV ; set integer overflow flag BTFSS FPFLAGS,SAT ; test for saturation

195

Page 201: Acoustic Remote Sensing

RETLW 0xFF ; return error code in WREG CLRF AARGB0 ; saturate to largest two's BTFSS SIGN,MSB ; complement 24 bit integer MOVLW 0xFF MOVWF AARGB0 ; SIGN = 0, 0x 7F FF FF MOVWF AARGB1 ; SIGN = 1, 0x 80 00 00 MOVWF AARGB2 RLF SIGN,F RRF AARGB0,F RETLW 0xFF ; return error code in WREG ;********************************************************************************************** ;********************************************************************************************** ; Floating Point Multiply ; Input: 24 bit floating point number in AEXP, AARGB0, AARGB1 ; 24 bit floating point number in BEXP, BARGB0, BARGB1 ; Use: CALL FPM24 ; Output: 24 bit floating point product in AEXP, AARGB0, AARGB1 ; Result: AARG <-- AARG * BARG ; Max Timing: 25+15*16+15+18 = 298 clks RND = 0 ; 25+15*16+15+29 = 309 clks RND = 1, SAT = 0 ; 25+15*16+15+33 = 313 clks RND = 1, SAT = 1 ; Min Timing: 6+5 = 11 clks AARG * BARG = 0 ; 24+15*11+14+15 = 218 clks ; PM: 80 DM: 11 ;---------------------------------------------------------------------------------------------- FPM24 MOVF AEXP,W ; test for zero arguments BTFSS _Z MOVF BEXP,W BTFSC _Z GOTO RES024

196

Page 202: Acoustic Remote Sensing

M24BNE0 MOVF AARGB0,W XORWF BARGB0,W MOVWF SIGN ; save sign in SIGN MOVF BEXP,W ADDWF EXP,F MOVLW EXPBIAS-1 BTFSS _C GOTO MTUN24 SUBWF EXP,F BTFSC _C GOTO SETFOV24 ; set multiply overflow flag GOTO MOK24 MTUN24 SUBWF EXP,F BTFSS _C GOTO SETFUN24 MOK24 MOVF AARGB0,W MOVWF AARGB2 ; move result to AARG MOVF AARGB1,W MOVWF AARGB3 BSF AARGB2,MSB ; make argument MSB's explicit BSF BARGB0,MSB BCF _C CLRF AARGB0 ; clear initial partial product

MOVLW D'16' CLRF AARGB1

MOVWF TEMP ; initialize counter MLOOP24 BTFSS AARGB3,LSB ; test next bit GOTO MNOADD24 MADD24 MOVF BARGB1,W ADDWF AARGB1,F MOVF BARGB0,W BTFSC _C INCFSZ BARGB0,W ADDWF AARGB0,F MNOADD24 RRF AARGB0,F RRF AARGB1,F RRF AARGB2,F

197

Page 203: Acoustic Remote Sensing

RRF AARGB3,F BCF _C DECFSZ TEMP,F GOTO MLOOP24 BTFSC AARGB0,MSB ; check for postnormalization GOTO MROUND24 RLF AARGB2,F RLF AARGB1,F

DECF EXP,F

GOTO MUL24OK

BTFSS FPFLAGS,SAT ; test for saturation

MOVLW 0xFF MOVWF AEXP ; saturate to largest floating MOVWF AARGB0 ; point number = 0x FF 7F FF

RLF AARGB0,F

MROUND24 BTFSC FPFLAGS,RND BTFSS AARGB1,LSB GOTO MUL24OK BTFSS AARGB2,MSB ; round if next bit is set GOTO MUL24OK INCF AARGB1,F BTFSC _Z INCF AARGB0,F BTFSS _Z ; has rounding caused carryout?

RRF AARGB0,F ; if so, right shift RRF AARGB1,F INCF EXP,F BTFSC _Z ; check for overflow GOTO SETFOV24 MUL24OK BTFSS SIGN,MSB BCF AARGB0,MSB ; clear explicit MSB if positive

RETLW 0 SETFOV24 BSF FPFLAGS,FOV ; set floating point underflag

RETLW 0xFF ; return error code in WREG

MOVWF AARGB1 ; modulo the appropriate sign bit RLF SIGN,F RRF AARGB0,F RETLW 0xFF ; return error code in WREG

198

Page 204: Acoustic Remote Sensing

;********************************************************************************************** ;********************************************************************************************** ; Floating Point Divide ; Input: 24 bit floating point dividend in AEXP, AARGB0, AARGB1 ; 24 bit floating point divisor in BEXP, BARGB0, BARGB1 ; Use: CALL FPD24 ; Output: 24 bit floating point quotient in AEXP, AARGB0, AARGB1 ; Result: AARG <-- AARG / BARG ; Max Timing: 32+13+15*26+25+12 = 472 clks RND = 0 ; 32+13+15*26+25+34 = 494 clks RND = 1, SAT = 0 ; 32+13+15*26+25+38 = 498 clks RND = 1, SAT = 1 ; Min Timing: 7+5 = 12 clks ; PM: 120 DM: 11 ;---------------------------------------------------------------------------------------------- FPD24 MOVF BEXP,W ; test for divide by zero BTFSC _Z GOTO SETFDZ24 MOVF AEXP,W BTFSC _Z GOTO RES024 D24BNE0 MOVF AARGB0,W XORWF BARGB0,W MOVWF SIGN ; save sign in SIGN BSF AARGB0,MSB ; make argument MSB's explicit BSF BARGB0,MSB TALIGN24 CLRF TEMP ; clear align increment MOVF AARGB0,W MOVWF AARGB2 ; test for alignment MOVF AARGB1,W MOVWF AARGB3

199

Page 205: Acoustic Remote Sensing

MOVF BARGB1,W SUBWF AARGB3, f MOVF BARGB0,W BTFSS _C INCFSZ BARGB0,W SUBWF AARGB2, f CLRF AARGB2 CLRF AARGB3 BTFSS _C GOTO DALIGN24OK BCF _C ; align if necessary RRF AARGB0,F RRF AARGB1,F RRF AARGB2,F MOVLW 0x01 MOVWF TEMP ; save align increment DALIGN24OK MOVF BEXP,W ; compare AEXP and BEXP SUBWF EXP,F BTFSS _C GOTO ALTB24 AGEB24 MOVLW EXPBIAS-1 ADDWF TEMP,W ADDWF EXP,F BTFSC _C GOTO SETFOV24 GOTO DARGOK24 ; set overflow flag ALTB24 MOVLW EXPBIAS-1 ADDWF TEMP,W ADDWF EXP,F BTFSS _C GOTO SETFUN24 ; set underflow flag DARGOK24 MOVLW D'16' ; initialize counter MOVWF TEMPB1 DLOOP24 RLF AARGB3,F ; left shift RLF AARGB2,F RLF AARGB1,F RLF AARGB0,F RLF TEMP,F

200

Page 206: Acoustic Remote Sensing

MOVF BARGB1,W ; subtract SUBWF AARGB1,F MOVF BARGB0,W BTFSS _C INCFSZ BARGB0,W SUBWF AARGB0,F RLF BARGB0,W IORWF TEMP,F BTFSS TEMP,LSB ; test for restore GOTO DREST24 BSF AARGB3,LSB GOTO DOK24 DREST24 MOVF BARGB1,W ; restore if necessary ADDWF AARGB1,F MOVF BARGB0,W BTFSC _C INCF BARGB0,W ADDWF AARGB0,F BCF AARGB3,LSB DOK24 DECFSZ TEMPB1,F GOTO DLOOP24 DROUND24 BTFSC FPFLAGS,RND BTFSS AARGB3,LSB GOTO DIV24OK BCF _C RLF AARGB1,F ; compute next significant bit RLF AARGB0,F ; for rounding RLF TEMP,F MOVF BARGB1,W ; subtract SUBWF AARGB1,F MOVF BARGB0,W BTFSS _C INCFSZ BARGB0,W SUBWF AARGB0,F RLF BARGB0,W IORWF TEMP,W ANDLW 0x01

201

Page 207: Acoustic Remote Sensing

ADDWF AARGB3,F BTFSC _C INCF AARGB2,F BTFSS _Z ; test if rounding caused carryout GOTO DIV24OK RRF AARGB2,F RRF AARGB3,F INCF EXP,F BTFSC _Z ; test for overflow GOTO SETFOV24 DIV24OK BTFSS SIGN,MSB BCF AARGB2,MSB ; clear explicit MSB if positive MOVF AARGB2,W MOVWF AARGB0 ; move result to AARG MOVF AARGB3,W MOVWF AARGB1 RETLW 0 SETFUN24 BSF FPFLAGS,FUN ; set floating point underflag BTFSS FPFLAGS,SAT ; test for saturation RETLW 0xFF ; return error code in WREG MOVLW 0x01 ; saturate to smallest floating MOVWF AEXP ; point number = 0x 01 00 00 CLRF AARGB0 ; modulo the appropriate sign bit CLRF AARGB1 RLF SIGN,F RRF AARGB0,F RETLW 0xFF ; return error code in WREG SETFDZ24 BSF FPFLAGS,FDZ ; set divide by zero flag RETLW 0xFF ;********************************************************************************************** ;********************************************************************************************** ; Floating Point Subtract

202

Page 208: Acoustic Remote Sensing

; Input: 24 bit floating point number in AEXP, AARGB0, AARGB1 ; 24 bit floating point number in BEXP, BARGB0, BARGB1 ; Use: CALL FPS24 ; Output: 24 bit floating point sum in AEXP, AARGB0, AARGB1 ; Result: AARG <-- AARG - BARG ; Max Timing: 2+197 = 199 clks RND = 0 ; 2+208 = 210 clks RND = 1, SAT = 0 ; 2+213 = 215 clks RND = 1, SAT = 1 ; Min Timing: 2+12 = 14 clks ; PM: 2+112 = 114 DM: 11 ;---------------------------------------------------------------------------------------------- FPS24 MOVLW 0x80 XORWF BARGB0,F ;********************************************************************************************** ; Floating Point Add ; Input: 24 bit floating point number in AEXP, AARGB0, AARGB1 ; 24 bit floating point number in BEXP, BARGB0, BARGB1 ; Use: CALL FPA24 ; Output: 24 bit floating point sum in AEXP, AARGB0, AARGB1 ; Result: AARG <-- AARG - BARG ; Max Timing: 25+28+6*6+5+31+72 = 197 clks RND = 0 ; 25+28+6*6+5+42+72 = 208 clks RND = 1, SAT = 0 ; 25+28+6*6+5+42+77 = 213 clks RND = 1, SAT = 1 ; Min Timing: 8+4 = 12 clks ; PM: 112 DM: 11 ;----------------------------------------------------------------------------------------------

203

Page 209: Acoustic Remote Sensing

FPA24 MOVF AARGB0,W ; exclusive or of signs in TEMP XORWF BARGB0,W MOVWF TEMP CLRF AARGB2 ; clear extended byte CLRF BARGB2 MOVF AEXP,W ; use AARG if AEXP >= BEXP SUBWF BEXP,W BTFSS _C GOTO USEA24 MOVF BEXP,W ; use BARG if AEXP < BEXP MOVWF AARGB4 ; therefore, swap AARG and BARG MOVF AEXP,W MOVWF BEXP MOVF AARGB4,W MOVWF AEXP MOVF BARGB0,W MOVWF AARGB4 MOVF AARGB0,W MOVWF BARGB0 MOVF AARGB4,W MOVWF AARGB0 MOVF BARGB1,W MOVWF AARGB4 MOVF AARGB1,W MOVWF BARGB1 MOVF AARGB4,W MOVWF AARGB1 USEA24 MOVF BEXP,W ; return AARG if BARG = 0 BTFSC _Z RETLW 0x00 MOVF AARGB0,W MOVWF SIGN ; save sign in SIGN BSF AARGB0,MSB ; make MSB's explicit BSF BARGB0,MSB MOVF BEXP,W ; compute shift count in BEXP SUBWF AEXP,W MOVWF BEXP BTFSC _Z

204

Page 210: Acoustic Remote Sensing

GOTO ALIGNED24 MOVLW 8 SUBWF BEXP,W BTFSS _C ; if BEXP >= 8, do byte shift GOTO ALIGNB24 MOVWF BEXP MOVF BARGB1,W ; keep for postnormalization MOVWF BARGB2 MOVF BARGB0,W MOVWF BARGB1 CLRF BARGB0 MOVLW 8 SUBWF BEXP,W BTFSS _C ; if BEXP >= 8, BARG = 0 relative to AARG GOTO ALIGNB24 MOVF SIGN,W MOVWF AARGB0 RETLW 0x00 ALIGNB24 MOVF BEXP,W ; already aligned if BEXP = 0 BTFSC _Z GOTO ALIGNED24 ALOOPB24 BCF _C ; right shift by BEXP RRF BARGB0,F RRF BARGB1,F RRF BARGB2,F DECFSZ BEXP,F GOTO ALOOPB24 ALIGNED24 BTFSS TEMP,MSB ; negate if signs opposite GOTO AOK24 COMF BARGB2,F COMF BARGB1,F COMF BARGB0,F INCF BARGB2,F

BTFSC _Z INCF BARGB1,F BTFSC _Z INCF BARGB0,F

AOK24 MOVF BARGB2,W ADDWF AARGB2,F

205

Page 211: Acoustic Remote Sensing

MOVF BARGB1,W BTFSC _C INCFSZ BARGB1,W ADDWF AARGB1,F MOVF BARGB0,W BTFSC _C INCFSZ BARGB0,W ADDWF AARGB0,F BTFSC TEMP,MSB GOTO ACOMP24 BTFSS _C GOTO NRMRND3224 RRF AARGB0,F ; shift right and increment EXP RRF AARGB1,F RRF AARGB2,F INCFSZ AEXP,F GOTO NRMRND3224 GOTO SETFOV24 ACOMP24 BTFSC _C GOTO NRM3224 ; normalize and fix sign COMF AARGB2,F COMF AARGB1,F ; negate, toggle sign bit and COMF AARGB0,F ; then normalize INCF AARGB2,F BTFSC _Z INCF AARGB1,F BTFSC _Z INCF AARGB0,F MOVLW 0x80 XORWF SIGN,F GOTO NRM24 ;********************************************************************************************** ;sqr24 24-bit square algorithm ;instructional cycles - who cares, it does faster than you can count anyway ;use: call sqr24 ;place variables in BEXP, BARGB0, BARGB1 ;result in BEXP, BARGB0, BARGB1 ; ;

206

Page 212: Acoustic Remote Sensing

;********************************************************************************************** sqr24 movf AEXP,W movwf BEXP ;copy variable movf AARGB0,W movwf BARGB0 ;copy variable movf AARGB1,W movwf BARGB1 ;copy variable call FPM24 return ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ; PAGE BREAK ;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ org 0x800 ;*********************************Distance calculation**************************** distn bcf PCLATH,4 bcf PCLATH,3 ;change to page 0 call tmp_rd bcf STATUS,RP0 ;change to bank0 movf bintemp,W ;get temperature movwf AARGB1 movlw b'00000000' movwf AARGB0 ; movlw b'00000000' ; movwf AEXP call FLO1624 ;convert to floating point movf AEXP,W ;move temperature exponent movwf TEXP movf AARGB0,W ;move mantissa movwf TARG0 movf AARGB1,W ;move mantissa movwf TARG1 movlw b'10000001' ;move C3 Exponent movwf BEXP movlw b'00010011' ;move C3 movwf BARGB0 movlw b'10000101' ;move C3 movwf BARGB1

207

Page 213: Acoustic Remote Sensing

call FPM24 ;multiply C3*T movf AEXP,W ;move result of mult movwf R3EXP movf AARGB0,W ;move mantissa movwf R3ARG0 movf AARGB1,W ;move mantissa movwf R3ARG1 movf TEXP,W ;move exponent for T^2 calculation movwf AEXP movf TARG0,W ;move mantissa movwf AARGB0 movf TARG1,W ;move mantissa movwf AARGB1 call sqr24 movlw b'01111010' ;move C2 Exponent movwf BEXP movlw b'01100001' ;move C2 movwf BARGB0 movlw b'01000111' ;move C2 movwf BARGB1 call FPM24 ;multiply C2*T^2 movf AEXP,W ;move result of mult to R2 movwf R2EXP movf AARGB0,W ;move mantissa movwf R2ARG0 movf AARGB1,W ;move mantissa movwf R2ARG1 movf TEXP,W ;move exponent movwf AEXP movf TARG0,W ;move mantissa movwf AARGB0 movf TARG1,W ;move mantissa movwf AARGB1 call sqr24 movf TEXP,W ;move exponent movwf BEXP movf TARG0,W ;move mantissa movwf BARGB0 movf TARG1,W ;move mantissa movwf BARGB1 call FPM24 ;remained from T^2 is in B, so move another T in and mult to get T^3

208

Page 214: Acoustic Remote Sensing

movlw b'01110011' ;move exponent of C1 to BEXP, T^3 remain in AEXP movwf BEXP movlw b'00011000' ;move C1 movwf BARGB0 movlw b'00001011' ;move C1 movwf BARGB1 call FPM24 ;multiply C1*T^3 movf AEXP,W ;move result of mult to R1 movwf R1EXP movf AARGB0,W ;move mantissa movwf R1ARG0 movf AARGB1,W ;move mantissa movwf R1ARG1 movf R1EXP,W ;move exponent of R1 to A movwf AEXP movf R1ARG0,W ;move mantissa movwf AARGB0 movf R1ARG1,W ;move mantissa movwf AARGB1 movf R2EXP,W ;move exponent of R2 to B movwf BEXP movf R2ARG0,W ;move mantissa movwf BARGB0 movf R2ARG1,W ;move mantissa movwf BARGB1 call FPS24 ;add R1-R2 movf R3EXP,W ;move exponent of R3 to B movwf BEXP movf R3ARG0,W ;move mantissa movwf BARGB0 movf R3ARG1,W ;move mantissa movwf BARGB1 call FPA24 ;add (R1-R2)+R3 movlw b'10001001' ;move C4 exp movwf BEXP movlw b'00110100' ;move C4 movwf BARGB0 movlw b'11111011' ;move C4 movwf BARGB1 call FPA24 ;add (R1-R2)+R3+C4 movf AEXP,W ;move result to R1 (at this time is the velocity) movwf R1EXP movf AARGB0,W ;move mantissa movwf R1ARG0 movf AARGB1,W ;move mantissa

209

Page 215: Acoustic Remote Sensing

movwf R1ARG1 movlw b'00000000' movwf AARGB0 movf h_tmr1,W movwf AARGB1 movf l_tmr1,W movwf AARGB2 call FLO2424 ;convert 16 bit timer1 to FP (note that subroutin takes 2's complement, so MSByte is all zeros) movlw b'01101011' ;Exponent of time, 1uS multiplier movwf BEXP movlw b'00000110' ;Argument1 movwf BARGB0 movlw b'00110111' ;Argument0 movwf BARGB1 call FPM24 movf R1EXP,W ;exponent of velocity movwf BEXP movf R1ARG0,W ; movwf BARGB0 movf R1ARG1,W ; movwf BARGB1 call FPM24 ;at this point, should be d*2 movlw b'10000000' ;Exponent of 2 movwf BEXP movlw b'00000000' ;Argument1 movwf BARGB0

movwf R1ARG0

movlw b'00000000' ;Argument0 movwf BARGB1 call FPD24 ;now it should be d and result will save in R1 movf AEXP,W ;move distance to R1 movwf R1EXP movf AARGB0,W ;move mantissa

movf AARGB1,W ;move mantissa movwf R1ARG1 movlw b'00000000' movwf AARGB2

210

Page 216: Acoustic Remote Sensing

return ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;floasc.inc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;**************************************************************************** ;* Floating Point to ASCII ;* ;* INPUT: 32 bit floating point number in AEXP, AARGB0, AARGB1, AARGB2 ;* For this example, the number must be between 0.000 and 9.999. ;* (You can easily change the number range to suit your needs.) ;* ;* OUTPUT: ones, tenths, hundredths, thousandths (ASCII digit in each) ;* ;* ;* USED: INDF,FSR,AARG,BARG,REMB,digit_count ;* ;* PROCEDURE: The floating point number in AARG is multiplied by 1000. ;* Then the product is divided by 10 three times. After each ;* divide, the remainder is kept. ;* ;* After each digit is obtained, 30H is added to it to make it ;* an ASCII representation of that number. Then, the ASCII ;* value is stored in register RAM at the locations specified ;* in the "cblock." ;* ;* Note: The ASCII decimal point is not generated by this routine. ;* You must output the decimal point in the correct decimal ;* position for your application. For this example, the ;* decimal point is after the first digit: ones. ;* ;* The following files are needed for this routine to function. ;* p16c74a.inc -- or any other midrange processor include file ;* include the processor file in your "main" file ;* ;* math16.inc -- constant and variable definitions for ;* AN575 floating point routines and ;* AN617 fixed point routines, both are used ;* in this float to ASCII routine ;* "include" this file in your "main" program ;* ;* fxd26.a16 -- fixed point 32/16 divide, included at the end ;* of this routine. ;* ;* fp32.a16 -- 32 bit float to 32 bit integer conversion

211

Page 217: Acoustic Remote Sensing

;* included at the end of this program. ;* ;**************************************************************************** float_ascii bcf PCLATH,4 bcf PCLATH,3 ;change to page 0 bcf STATUS,RP0 ;change to bank0 movlw 0x85 ;BARG= 100 decimal (floating point) movwf BEXP ;fprep.exe was used to get this movlw 0x48 ;floating point representation of 1000 movwf BARGB0 movlw 0x00 movwf BARGB1 movlw 0X00 movwf BARGB2 call FPM24 ;AARG = AARG * 1000 call INT2424 ;AARG <-- INT( AARG ) movlw last_digit movwf FSR ;pointer = address of smallest digit movlw SIG_FIG ;load counter with the number of movwf digit_count ;significant figures the decimal number flo_asclp bcf STATUS,RP0 ;change to bank0 clrf BARGB0 ;Make the divisor 10. movlw d'10' movwf BARGB1 bcf PCLATH,3 ;change to page0 call FXD2416U ;divide (32 bit fixed) / 10 (to get remainder) movf REMB1,w ;put remainder in w register movwf INDF ;put number into appropriate digit position movlw 0x30 addwf INDF,f ;add 30H to decimal number to convert to ASCII decf FSR,f ;move pointer to next digit

212

Page 218: Acoustic Remote Sensing

bsf PCLATH,3 ;change to page1 decfsz digit_count,f goto flo_asclp return ;*********************************************************************************************************** ;display date, time, temperature, and distance data on the LCD dat_disp bcf PCLATH,4 bcf PCLATH,3 ;change to page 0 bcf STATUS,RP0 ;change to bank0 call r_rtc ;read date and time call tmp_rd ;read temperature call lcdhom movf h_mth,W movwf disp call lcddisp ;display first digit movf l_mth,W movwf disp call lcddisp ;display second digit call outcma movf h_day,W movwf disp call lcddisp ;display first digit movf l_day,W movwf disp call lcddisp ;display second digit call outcma movf h_yr,W movwf disp call lcddisp ;display first digit movf l_yr,W movwf disp call lcddisp ;display second digit call outcma movf h_hr,W movwf disp call lcddisp ;display first digit movf l_hr,W movwf disp call lcddisp ;display second digit call outcma

213

Page 219: Acoustic Remote Sensing

movf h_min,W movwf disp call lcddisp ;display first digit movf l_min,W movwf disp call lcddisp ;display second digit call nxtln movf h_sec,W movwf disp call lcddisp ;display first digit movf l_sec,W movwf disp call lcddisp ;display second digit call outcma movf h_temp,W movwf disp call lcddisp ;display first digit movf l_temp,W movwf disp call lcddisp ;display second digit call outcma movf 0x7C,W movwf disp call lcddisp ;display first digit movf 0x7D,W movwf disp call lcddisp ;display second digit call outdot movf 0x7E,W movwf disp ;display third digit call lcddisp movf 0x7F,W movwf disp ;display fourth digit call lcddisp call lngdly call lngdly call lngdly return ;**********************************Compact Flash Code********************************** dat_dump bsf PCLATH,3 ;change to page1 movf l_mth,W movwf PORTD

214

Page 220: Acoustic Remote Sensing

call cf_write movf h_mth,W movwf PORTD call cf_write movlw b'00101100' ;comma movwf PORTD call cf_write movf l_day,W movwf PORTD call cf_write movf h_day,W movwf PORTD call cf_write movlw b'00101100' ;comma movwf PORTD call cf_write movf l_yr,W movwf PORTD call cf_write movf h_yr,W movwf PORTD call cf_write movlw b'00101100' ;comma movwf PORTD call cf_write movf l_hr,W movwf PORTD call cf_write movf h_hr,W movwf PORTD call cf_write movlw b'00101100' ;comma movwf PORTD

call cf_write

215

Page 221: Acoustic Remote Sensing

movf l_min,W movwf PORTD call cf_write movf h_min,W movwf PORTD call cf_write movlw b'00101100' ;comma movwf PORTD call cf_write movf l_sec,W movwf PORTD call cf_write movf h_sec,W movwf PORTD call cf_write movlw b'00101100' ;comma movwf PORTD call cf_write movf l_temp,W movwf PORTD call cf_write movf h_temp,W movwf PORTD call cf_write movlw b'00101100' ;comma movwf PORTD call cf_write movf 0x7C,W movwf PORTD call cf_write movf 0x7D,W movwf PORTD call cf_write movlw b'00101110' ;decimal point movwf PORTD

216

Page 222: Acoustic Remote Sensing

call cf_write movf 0x7E,W movwf PORTD call cf_write movf 0x7F,W movwf PORTD call cf_write movlw b'00101100' ;comma movwf PORTD call cf_write movlw 0x20 ;NEXT LINE movwf PORTD call cf_write movlw b'00101100' ;comma movwf PORTD call cf_write movlw b'00110000' ;zero movwf PORTD call cf_write movlw b'00110000' ;zero movwf PORTD call cf_write movlw b'00110000' ;zero movwf PORTD call cf_write movlw b'00110000' ;zero movwf PORTD call cf_write movlw b'00110000' ;zero movwf PORTD call cf_write ;last comma and five zeros are to fill for total of 32 bytes written ;buffer full after 16 data dump function calls decfsz byte_cnt,F goto next_sect

217

Page 223: Acoustic Remote Sensing

return next_sect movlw .16 movwf byte_cnt ;track 512 bytes incf track_sec,F ;track total sectors written incf storage_lo,F btfsc STATUS,Z incf storage_hi,F movlw b'00000001' movwf PORTD movlw b'00011110' movwf dat call mux call cf_write ;head/drive register zero movlw b'00000000' movwf PORTD movlw b'00011101' movwf dat call mux call cf_write ;cylinder high register zero movlw b'00000000' movwf PORTD movlw b'00011100' movwf dat call mux call cf_write ;cylinder low register zero movlw b'00000000' movwf PORTD movlw b'00011011' movwf dat call mux call cf_write ;sector number register zero movf track_sec,W movwf PORTD movlw b'00011010' movwf dat call mux call cf_write ;sector count register zero movlw 0x30 ;write register with erase

218

Page 224: Acoustic Remote Sensing

movwf PORTD movlw b'00011111' movwf dat call mux call cf_write ;send write sector command movlw b'00011000' movwf dat call mux ;prepare to write to data sector ;stay in write mode

bsf PCLATH,3 ;change to page1

return check_ready bcf STATUS,RP0 ;change to bank0 BTFSS PORTC,6 ;check if busy bsf PCLATH,3 ;change to page1 goto check_ready ;loop until ready return ;cf_write sends the data on the I/O lines cf_write

call check_ready ;check for ready movlw b'11110111' andwf dat,F call mux ;de-assert WE movlw b'00001000' addwf dat,F call mux ;assert WE return ;cf_read reads the desired data and store it in data_lo and data_hi cf_read bsf STATUS,RP0 ;change to bank1 movlw b'11111111' movwf TRISD ;change PORTD to all inputs bcf STATUS,RP0 ;change to bank0 movlw b'11101111' andwf dat,F bsf PCLATH,3 ;change to page1 call mux ;de-assert OE movf PORTD,W movwf data_lo ;move data read to data_lo movlw b'00010000' addwf dat,F

219

Page 225: Acoustic Remote Sensing

call mux ;assert OE

movf dat,W

bcf PCLATH,4

bsf SSPCON,CKP ;clock normally high

call check_ready ;wait for card ready movlw b'11101111' andwf dat,F call mux ;de-assert OE movf PORTD,W movwf data_hi ;store data read to data_hi movlw b'00010000' addwf dat,F call mux ;assert OE bsf STATUS,RP0 ;change to bank1 clrf TRISD ;change back to all outputs return ;***********************************MUX CODE******************************************* mux bcf PCLATH,4 bcf PCLATH,3 ;change to page 0 call bank1 bsf SSPSTAT,CKE ;rising edge transfer call bank0 bcf SSPCON,CKP ;clock normally low call bank1 movlw b'11000000' movwf SSPSTAT call bank0 bsf PORTC,7 ;clear cs (inverting) nop nop nop bcf PORTC,7 ;assert CS

movwf SSPBUF call spi_out movf SSPBUF,W bsf PORTC,7 ;de-assert chip select line

bcf PCLATH,3 ;change to page 0 call bank1 bcf SSPSTAT,CKE ;rising edge transfer call bank0

220

Page 226: Acoustic Remote Sensing

bcf PCLATH,4

call shtdly ;power up delay

btfss PORTD,7 ;test switch for set time mode or standard mode

call combmth ;fill bcd variables for writing to RTC

call set_hhr ;set upper value of hour

bsf PCLATH,3 ;change to page 1 return

;********************Programming Main Section********************** main bcf PCLATH,4 bcf PCLATH,3 ;change to page 0

call start ;port and tris clear call booty ;boot up sequence call lcd_init ;initialize lcd call cnfg ;configure SPI devices call cf_init bcf PCLATH,4 bsf PCLATH,3 ;change to page 1 incase regmode is called

goto regmode setmode bcf PCLATH,4 bcf PCLATH,3 ;change to page 0 movlw b'00000000' movwf PORTA call send movlw b'00001101' movwf PORTA ;turn display on, cursor off, blink on call send call r_rtc ;read real-time clock

call combday call combyr call combhr call combmin clrf flags1 ;bits of flags1, flags2 used to track which variable is changed clrf flags2 ;flags2, bit7 is used to move to next variable call set_hmth ;set upper value of month call set_lmth ;set lower value of month call set_hday ;set upper value of day call set_lday ;set lower value of day call set_hyr ;set upper value of year call set_lyr ;set lower value of year

call set_lhr ;set lower value of hour call set_hmin ;set upper value of minutes call set_lmin ;set lower value of minutes

221

Page 227: Acoustic Remote Sensing

call lcdclr regmode bcf PCLATH,4

call send movlw b'00001100'

movwf 0x7C

call ping ;send ping

movlw d'255'

bsf PIE1,TMR1IE

bsf PCLATH,3 ;change to page 1

bcf PCLATH,3 ;change to page 0 bcf INTCON,INTE ;turns off the RB0 interrupt button movlw b'00000000' movwf PORTA

movwf PORTA ;turn display on, cursor off, blink off call send movlw b'00110000'

movlw b'00110000' movwf 0x7D movlw b'00110000' movwf 0x7E movlw b'00110000' movwf 0x7F ;initialize distance to zero bcf PCLATH,4 bsf PCLATH,3 ;change to page 1 call dat_disp here bcf PCLATH,4 bcf PCLATH,3 ;change to page 0 call bank0 clrf flags1 ;Bit 0 used to mark timer/ccp interrupt occurred

bsf T1CON,TMR1ON ;start timer1

movwf x1 movlw d'21' movwf x2 ;delay to ignore ringing call vardly ; bsf STATUS,RP0 ;change to bank1

bcf STATUS,RP0 ;change to bank0 bcf PIR1,CCP1IE bsf STATUS,RP0 ;change to bank1 bsf PIE1,CCP1IE ;enable ccp interrupt (NOTE: timer1 overflow interrupt always enabled) slp bcf STATUS,RP0 ;change to bank0

btfss flags1,0 goto slp ;wait for timer overflow or ccp interrupt bsf PCLATH,3 ;change to page 1 bsf STATUS,RP0 ;change to bank1

222

Page 228: Acoustic Remote Sensing

bcf PIE1,CCP1IE bcf PIE1,TMR1IE ;disable interrupts goto here ;infinite cycle until shutdown END

223