Upload
khangminh22
View
0
Download
0
Embed Size (px)
Citation preview
A Compact Remote Data Acquisition System
Submitted by Yong Seng Chiah
Department of Mechanical Engineering
In partial fulfillment of the requirements for the Degree of Bachelor of Engineering
National University of Singapore
Session 2003/2004
Abstract
Microcontrollers are special purpose computers. They are usually small and low cost
to do one thing or a few things well. It is programmed to suit the needs of the users.
Microcontrollers are equipped with various abilities. They can be used for data
acquisition, processing and storage. Microcontrollers nowadays can even transmit
data over long distance via Ethernet. In the project, the transmission control
protocol/internet protocol (TCP/IP) and dynamic host configuration protocol (DHCP)
are used in programming the microcontroller to acquire analog signal and transmit
data over NUS network that acts as a DHCP server using TCP/IP.
The objective of programming microcontroller to these functionalities is to establish
a vibration sensing remote data acquisition and storage system. This system is able to
sense physical vibration and transmit data via Ethernet to a central monitoring
computer for storage. A proper setup of electrical devices in the laboratory is
required to create physical vibration and to produce a voltage range operational to
microcontroller. Dynamic C is the programming language used in microcontroller
while Ruby is used for windows programming on the central monitoring computer.
Various attempts and stages are implemented during the development of the system.
And one similar vibration sensing system using a microcontroller produced from the
same company as the project is discussed.
i
Acknowledgement
From the onset of the project to its conclusion, the author has sought the assistance
and advice from several people. Here, I would like to take this opportunity to extend
a note of appreciation to the following people for their invaluable help and guidance:
• Assistant Professor Lim Kian Meng, the project supervisor, who has provided
invaluable guidance and advice for the project.
• A/Prof. Teo Chee Leong, the co-supervisor, who has given precious advice
and suggestions for the project.
• A/Prof. Lim Siak Piang, the examiner, who has spent valuable time in
evaluating the project.
• Lab assistants in the Dynamics Laboratory, who have continuously given
support throughout the project.
ii
Contents
Abstract i
Acknowledgement ii
Contents iii
List of Figures v
List of Tables vi
1 Introduction 1
2 Review of commercial microcontrollers 3
3 Equipments 7
3.1 Introduction to microcontroller 7
3.1.1 Physical Characteristics 7
3.1.2 Applications/Uses 8
3.1.3 Features 8
3.2 Specifications of BL2500 with RN1200 A/D Expansion Card 10
4 Method 12
4.1 Dynamic C 12
4.1.1 Introduction 12
4.1.2 How microcontroller is programmed 13
4.2 Ruby Windows programming 16
4.2.1 Introduction 16
4.2.2 How central monitoring computer is programmed 16
iii
5 Results 20
5.1 Digital Data Transfer 20
5.2 TCP/IP Programming and Data Acquisition 22
5.3 A Real-time Ethernet Data Transfer System 22
5.4 Vibration Sensing Remote Data Acquisition and Storage System 24
6 Conclusion 26
References 29
Appendix A: Transmission Control Protocol/Internet Protocol (TCP/IP) 30
Appendix B: Dynamic Host Configuration Protocol (DHCP) 33
Appendix C: Program Codes for Microcontroller 35
Appendix D: Program Codes for Central Monitoring Computer 41
Appendix E: BL2500 Specifications 42
iv
List of Figures
Fig. 3.1: Quantization and sampling frequency. Fig. 3.2: The connection of BL2500 with RN1200 A/D expansion card. Fig. 4.1: Sequence of events programmed in central monitoring computer. Fig. 4.2: The connection between BL2500 with central monitoring computer Fig. 4.3: Sequence of events programmed in microcontroller. Fig. 4.4: Screenshot of text file created in central monitoring computer. Fig. 4.5: Screenshot of plots using Microsoft Excel for a sine wave input. Fig. 5.1: BL2500 digital outputs circuit. Fig. 5.2: Output window for microcontroller connected to ftp.hikago.flirble.org. Fig. 5.3: A real-time Ethernet data transfer system. Fig. 5.4: Vibration sensing remote data acquisition and storage System.
v
List of Tables
Table 2.1: Capabilities of the solutions and services provided by Z-world Table 4.1: Programmable voltage ranges and multipliers for RN1200. Table 5.1: The signal relationship between Dil switches, digital I/O’s and LED’s. Table 5.2: The models of electrical equipments used in the laboratory.
vi
1 Introduction
In many applications, data need to be transmitted over long distance for processing,
storage or display. In this project, a vibration sensing remote data acquisition and
storage system is developed. Initially, a microcontroller is programmed to support
dynamic host configuration protocol (DHCP). This configuration helps the
microcontroller to obtain its IP address on a DHCP server.
The microcontroller is also programmed at its analog port for analog signal
acquisition. The analog signal is obtained from the output of a charge amplifier that
is directly connected to a transducer (accelerometer) measuring vibration. The
vibration can be created from natural phenomenon like earthquake as well as any
artificial vibration created in laboratory.
The data received by the microcontroller will then be sent to a computer via Ethernet.
Due to this reason, the microcontroller is programmed for TCP/IP establishment. The
computer at the other end is also programmed for TCP/IP socket opening. It then
receives and records the data sent over from microcontroller.
The remote data acquisition and storage system can be used in many applications. In
the project, this system may be used to detect vibration for the countries experience
earthquakes. Microcontrollers can be located at different areas whereby each
1
microcontroller obtains its analog data (earthquake vibration) from transducers. Then
the data collected from each microcontroller will be sent via Ethernet to a computer
which acts as a central controlling unit. This computer can record or store each set of
the data separately or even combine them whenever necessary. The data recorded
can thus be processed, analyzed or saved for future use.
2
2 Review of commercial microcontrollers
Microcontrollers produced by 3 different companies were compared to determine
which was most suitable for the project. These 3 companies were Z-world, Axis
Communication and Scentech. Z-world is a single company provides its customers
the unique combination of hardware, software, and network technologies in
embedded system. Axis Communication provides variety of network solutions, one
of their operations is focus on embedded system, while Scentech is a relatively new
company in the same field. There are various products or microcontrollers produced
by these 3 companies. One microcontroller representing each company was chosen
for comparison. The microcontrollers chosen for comparison were respectively
named BL2500 Coyote, Gatemates-100, and Axis 82-developer board.
The comparison was done to the functionalities or features the 3 representative
microcontrollers have. Some of the typical features for comparison considerations
are the availability as well as the quality of microprocessor, memory, Ethernet port,
digital, analog I/O, serial ports, power consumptions and so on. A more complete set
of typical features available on microcontrollers is shown in Appendix E. Since each
microcontroller has their own strength in certain features over others, it is important
to know which features are important for the project. And since the project is related
to analog data acquisition, the availability of analog port is a crucial element to the
project. And this feature is only available on BL2500 Coyote. It was also found that
BL2500 uses Windows compatible system as its platform for software programming,
3
it is relatively easier as compared to Linux for the other two products. Furthermore,
BL2500 is a single-board computer capable to be connected with some other
expansion cards produced by Z-world to improve its functionalities and quality. In
the project, BL2500 is connected with an A/D expansion card called RN1200 to
improve its sampling rate.
The comparison was also done between companies. It was obvious that Z-world is a
better player in the field of providing solutions in embedded system.
Some of the reasons why Z-world is better than the other 2 companies are:
• It has detail information and documentation on its website
• It has industry-proven track record.
• It has a distributor in Singapore.
• It has comprehensive technical support and active technical support forum
4
Table below shows the capabilities of the solutions and services provided by Z-world
Table 2.1: Capabilities of the solutions and services provided by Z-world
Hardware Software Networking
Stand-alone embedded system
Integrated compiler, editor, debugger
Network-enable legacy or existing products and systems
Operators interfaces like keypad /display
Remote programming and debugging
Network-enable new product and system designs
High performance microprocessor, memories
Extensive application support
Remotely control and monitor devices and systems over a LAN or the Internet using standard web browsers
Logic level digital I/O Availability of demo programs and application templates
Send alerts for system changes and conditions
Industrialized digital I/O Extensive mathematics and function libraries
Display and update state on a web browser with HTTP forms
Analog I/O Multi-tasking support like costatements, cofunctions, and slicing
Transfer files with FTP and HTTP
Logic level serial ports – RS-232, RS485
High speed serial communication drivers
Send and receive e-mails with SMTP and POP3
Low power operation Facilities to add custom extension or modification to network libraries
Verify connection to host with PING
Character-based or graphic display – touchscreen, keypads
Ensure reliable full-duplex communications with TCP
The accessibility of information to the products and services offered by other
companies are relatively low as compared to Z-world.
5
Due to the reasons that Z-world provides better products and services, and BL2500
can provide all the functionalities and features needed in the project, it was selected
for development.
A survey was done to the microcontroller produced by Z-world to check if there is
any microcontroller used in a similar way as the project. It was found out that a
product called BL2510 has been used for earthquake detection in Japan. Geodetic
surveys are often used to measure tilt and movement of the earth's surface. One of
the methods of surveying is to collect tilt data via a network of Global Positioning
System (GPS) antennas. The system incorporates tilt-meters called clinometers
placed at the top of towers. The tower shifts as the ground shifts. Tilt caused by
earthquake, foundation vibration, collision, or wind loading results in a displacement
from a surveyed position. For example, one degree of tilt from a 4-meter tower
would produce a displacement of 7 centimeters. An organization has designed a
tiltmeter, based on a BL2510, that is used in a GPS geodetic array network in Japan.
The network can detect crustal strain in the Japanese island arc system.
The GPS antenna mentioned above is a liquid-filled electrolytic transducer
comprises the sensing element of the digital tiltmeter. The transducer is activated and
read by stable, low-noise electronics. The clinometer incorporates BL1510 to
perform A/D conversion, processes the analog data, provides digital I/O, and stores
calibration constants in non-volatile memory. Its resolution is better than 0.01 degree.
6
3 Equipments
3.1 Introduction to microcontroller
3.1.1 Physical Characteristics
Microcontrollers are computers used for special purposes. They are embedded inside
some devices (often a consumer product) so that they can control the actions of the
product. Microcontrollers are usually dedicated to do one task and run one specific
program. The program is stored in read-only memory (ROM) and generally does not
change.
Microcontrollers are often low-power devices. A desktop computer is almost always
plugged into a wall socket and might consume 50 watts of electricity. A battery-
operated microcontroller might consume 50 milliwatts. It also takes input from the
device it is controlling and controls the device by sending signals to different
components in the device.
A microcontroller is often small and low cost. The components are chosen to
minimize size and to be as inexpensive as possible. It can also be designed to be
robust in certain extreme conditions. For example, a microcontroller in an engine of
car can withstand high temperature.
7
3.1.2 Applications/Uses
There are many microcontrollers available in the market, the selection of
microcontrollers for development will be specifically depends on the applications
one uses it. In the industry, microcontrollers are widely used in machine control,
process control, remote monitoring, data acquisition/storage, sensor interface, touch-
screen programming, industrial automation, precision manufacturing, and so on. In
everyday life, the applications of microcontroller can be seen in electrical appliances
like microwave oven, washing machine and vending machine.
For example, the microcontroller inside a TV takes input from the remote control
and displays output on the TV screen. The controller controls the channel selector,
the volume and certain adjustments on the picture tube electronics such as color and
brightness. A microwave oven controller takes input from a keypad, displays output
on an LCD display and controls a relay that turns the microwave generator on and
off.
3.1.3 Features
The general functions available on microcontrollers include digital and analog data
acquisition and processing. And the general features or interfaces of a
microcontroller are ports with input/output pins for serial, parallel, and Ethernet data
reception and transmission.
8
The quality of a microcontroller depends on the speed and accuracy it handles data.
These qualities are supported by various aspects including the speed of
microprocessor, sampling rate and update rates for analog I/O ports. Some of the
other considerations in selecting a microcontroller are its minimum resolution,
memories for permanent and temporary data storage, power consumption and even
cost.
In this project, the microcontrollers must be equipped with analog port for analog
data processing. The processing quality will be related to a few factors. Sampling
rate is the number of samples taken per unit time. So the higher the sampling rate,
the higher range of frequency of analog input signal the microcontrollers can detect.
High sampling rate can also smooth analog signal since it obtains data at a smaller
time interval.
Figure 3.1: Quantization and sampling frequency
Sampling frequency (more segments per unit time produces smoother
graph)
Quantization
(more segm
ents per unit voltage increases accuracy)
Time
Voltage
9
One of the other factors which affects the accuracy and smoothness of analog signal
is the resolution of the analog port. Quantization is implemented to a range of
voltage a microcontroller processes. Quantization is a process in which the
continuous range of values of an analog signal is sampled and divided into non-
overlapping (but not necessarily equal) sub-ranges, and a discrete, unique value is
assigned to each sub-range. Thus, the higher number of bits an analog port can
process, the more accurate and smooth its analog data.
3.2 Specifications of BL2500 with RN1200 A/D Expansion
Card
The microcontroller chosen for the project is the BL2500 Coyote produced by Z-
world. Z-World is a company pioneer in the embedded controls industry, providing
high-performance reliable embedded control solutions since 1983. The Z-world
BL2500 chosen has all the general functions and features a microcontroller has. The
extra function BL2500 has over most of other microcontrollers in the industry is the
ability to be linked up with different peripheral boards to enhance its functionalities
and qualities.
In the project, BL2500 is linked with an A/D expansion card called RN1200. This
combination provides all the functionalities needed for the project. On the BL2500
itself, it has an Ethernet port that can be used to connect to network using a straight-
through Ethernet cable. The programming software of BL2500 is capable in
10
supporting TCP/IP. And on RN1200, it has analog inputs with sampling rate around
2.5 kHz, resolution of 11 bits which is 2048 steps in quantization and input voltage
range from 0V to 1V (single-ended). For 11 bits of resolution or 2048 steps within
the voltage range of 0-1V, the voltage for a single step is 0.4883mV.
The resolution, sampling rate, voltage range and Ethernet functionalities can
establish most of the applications related to Ethernet data acquisition and storage
system including the vibration sensing remote data acquisition system for earthquake.
The connection of BL2500 with RN1200 A/D expansion card
Straight-through Ethernet cable
BL2500 RN1200
Figure 3.2: The connection of BL2500 with RN1200 A/D expansion card
11
4 Method
4.1 Dynamic C
4.1.1 Introduction
Dynamic C is a programming software developed by Z-world. Dynamic C's
enhancements to standard C facilitate real-time programming on powerful embedded
systems. Language extensions include constructs for cooperative and preemptive
multi-tasking and protecting writes to variables during power failures. Libraries for
standard C functions, board-specific peripheral drivers, chip peripherals, and other
features are included in source code format. Assembly language programming is
fully supported, and Assembly code is easily mixed with C code for time-critical
applications.
Dynamic C is user-friendly program. Users can write, compile, and test C and
Assembly code without leaving the Dynamic C development environment.
Debugging occurs while the application runs on the target. Dynamic C runs on PCs
under Windows 95, 98, 2000, NT, ME, and XP. Programs are downloaded at baud
rates of up to 460,800 bps while the program compiles.
The libraries and functions calls needed for the project are related to analog data
acquisition, transmission, Ethernet enabling and dynamic host configuration protocol.
In the Ethernet data acquisition and storage system, there are two hosts that try to
12
establish connection via Ethernet. One host is the microcontroller playing its role as
client while the other host is a computer acts as a server.
4.1.2 How microcontroller is programmed
BL2500 is programmed to obtain an IP address from NUS network using DHCP
function calls. Usually, a client needs no fix IP address for TCP establishment, on the
other hand, a server (the central monitoring computer) needs a fix IP address so that
a client is acknowledged and able to request for TCP establishment.
DHCP IP request
Open port to connect target server
Request for TCP/IP connection
Close connection
Receive analog voltage signal from analog port
Send digitized data from buffer to socket interface
A/D conversion Send digitized data to socket buffer
Figure 4.1: Sequence of events programmed in microcontroller
13
BL2500 is programmed to assigns itself a port number in the range of 1025 to 65536.
The IP address and port number forms a basis for the formation of TCP socket for
BL2500 on the network. This socket is programmed to create an interface with the IP
address and port number (another pair of socket) which belongs to the central
monitoring computer (server). After the connection is established, both hosts are
ready for data transmission. While keeping the TCP/IP connection alive, BL2500
receives analog signal from its analog input pin and then outputs the data to central
monitoring computer via TCP/IP.
Figure 4.2: The connection between BL2500 with central monitoring computer
The operating voltage range for analog input pin of RN1200 on BL2500 is 0 to 1V
(This is actually a selected voltage range for operation in the project, since the range
has the highest Multiplier according to its Specification Sheet).
14
Table 4.1: Programmable voltage ranges and multipliers for RN1200
Voltage Range Multiplier
Single-Ended Differential
× 1 0-20 V ± 20 V
× 2 0-10 V ± 10 V
× 4 0-5 V ± 5 V
× 5 0-4 V ± 4 V
× 8 0-2.5 V ± 2.5 V
× 10 0-2 V ± 2 V
× 16 0-1.25 V ± 1.25 V
× 20 0-1 V ± 1 V
The analog voltage detected will then be sent for analog to digital conversion. The
digitized data will maintain its unit which is voltage by calling certain functions in
Dynamic C. It is the digitized data which will be used for data transmission and
storage.
15
4.2 Ruby Windows programming
4.2.1 Introduction
To program the central monitoring computer for data acquisition, Ruby is used.
Ruby is a fully object-oriented, dynamic scripting language which borrows some of
the best features from LISP, Smalltalk, Peral, CLU, and other languages, and blends
them into a harmonious whole. The design philosophy of Ruby encourages human-
oriented design, rapid development, and test-first coding.
Ruby programs are compact, yet very readable and maintainable. The syntax and
semantics are intuitive and very clean. Ruby is open source and freely available for
both development and deployment. Ruby can run at different platforms, those
platforms include Unix or Linux, Microsoft Windows, or specialized systems such as
BeOS and others.
4.2.2 How central monitoring computer is programmed
In the project, the central monitoring computer is programmed using Ruby to listen
on port 3000 (it can be any number in the range of 1025-65536 for personal purpose
of port opening). A computer runs on any DHCP enabled platform for its network
like Microsoft Windows will obtain IP address straight away from DHCP server. The
DHCP server in the project is the NUS network.
16
Wait for TCP/IP request
Receive digitized analog voltage signal
Open file
DHCP IP request
Listen on port 3000
Write date, time and data to file
Close connection
Figure 4.3: Sequence of events programmed in central monitoring computer
The computer keeps listening on its port until BL2500 sends a request for TCP/IP
establishment. When a request is obtained, a process called 3-way handshake occurs
to ensure the connection. The computer is also programmed to maintain TCP/IP
connections with BL2500 by calling certain functions in the TCP/IP libraries in
Ruby.
Once the TCP/IP connection is secured, the computer keeps waiting and receiving
whatever data sent over from BL2500. In this case, it is a digitized analog voltage
signal coming out from BL2500. The computer will then receive the signal and write
them straight away to a text (.txt) file for storage. The computer is programmed in
17
such a way that for every execution of file-writing, its date and time of the event is
recorded in the file itself.
Below shows the screenshot of the text file created by central monitoring computer:
Tue Mar 09 21:54:18 Malay Peninsula Standard Time 2004 0.019262 0.019262 0.019262 0.019262
Figure 4.4: Screenshot of text file created in central monitoring computer
This is an illustration saying that each 0.019262 above represents the voltage
obtained at the equal time interval (400 microseconds when sampling rate is 2.5
kHz). The data can anytime be reused, analyzed with any program or method. One of
the possible uses is to plot the data using Microsoft Excel to visualize the analog
vibration curve of an earthquake. The following figure is a screenshot of the plot
using Microsoft Excel for an input sine signal with peak-peak voltage 0.4-1.2V and
frequency 1 Hz into the analog input of BL2500 with sampling rate around 10 Hz.
18
00.20.40.60.8
11.21.4
0.1
0.3
0.5
0.7
0.9
1.1
1.3
1.5
1.7
1.9
2.1
2.3
2.5
2.7
2.9
3.1
3.3
3.5
3.7
3.9
Time (s)
Volta
ge (V
)
Figure 4.5: Screenshot of plots using Microsoft Excel for a sine wave input
There are 4 elements needed for TCP/IP socket establishment. The connection is
identified by server’s IP address, port number and client’s IP address, and port
number, the computer can actually establish connections with as many BL2500 as
possible using a single port number. Or it can be said that every single connection
with a client is using a single unique socket. Thus, the central monitoring computer
can simultaneously monitor, process and record the data transferred from many
clients.
19
5 Results
5.1 Digital Data Transfer
At the initial stage of the project, a program was written to test the digital parallel
I/O’s and the software. Dil switches were used to vary inputs and LED’s were used
to verify the output data. Table 5.1 shows the signal relationship between Dil
switches, digital I/O’s and LED’s that are connected based on the circuit on Figure
5.1 below.
Table 5.1: The signal relationship between Dil switches, digital I/O’s and LED’s
Mode Dil switches Inputs Outputs
(sinking)
LED (light when
output low)
1 Program Nil High Low On
2 Run Off (ungrounded) High Obtain high Off
3 Run On (grounded) Low Obtain low On
When an I/O is high, it has +K Volt which is around 5.0V, and when an I/O is low, it
is around 0V. Refer to row 1 in Table 5.1, in programming mode, the relationship
between inputs and outputs are independent. For BL2500, all inputs are high and all
outputs are low by default at program mode. The I/O states of high or low depend on
how the circuitry in the microcontroller is designed. The output circuitry can be
shown in Figure 5.1. In this project, LED is connected serially with a resistor
20
forming the ‘load’. Node A is always high since it is at +K Volt. There will be
current flow across node A and node B when ‘output’ is low. So, LED will be light
up in programming mode.
In run mode, the relationship between inputs and outputs will be no longer
independent, the output state of high or low will always be the same as the input state,
refer to row 2 in Table 5.1, when input is high, output obtains high, thus, LED will
be off. And when input is low, output obtains low, LED will be on. In this project,
the input states are controlled by Dil switches. Dil switches can be mechanically
switched on and off, which is correspondingly grounding and ungrounding the inputs.
Thus, BL2500 was programmed to transfer digital data via its parallel port.
A
Output
B
Figure 5.1: BL2500 digital outputs circuit
21
5.2 TCP/IP Programming and Data Acquisition
There are many servers providing their applications through TCP/IP on the internet,
these servers include Telnet, FTP, HTTP, SMTP and so on. BL2500 was
programmed to be a client capable of resolving server’s IP address and do 3-way
handshaking for TCP/IP establishment. In the program, it also made a string request
which prints out the announcements made by server.
One of the examples of the output window when BL2500 is connected to an FTP
server at ftp.hikago.flirble.org is shown bellow. This FTP server allows users to
download movies.
My IP address is 172.19.179.20 212.134.1.34 is the address resolved from server. Waiting for connection... Established OK! The number of bytes written was 9 220- Hikaru No Go FTP archive ftp.hikago.flirble.org --------------------------------------------------------------------------- There is a limit of 300 anonymous connections. No more than 3 concurrent connections are allowed from each IP address. Please be kind to other users and do not try to open connections, you will not succeed. 220 ProFTPD 1.2.9 Server (ftp.hikago.flirble.org) [ftp.hikago.flirble.org]
Figure 5.2: Output window for microcontroller connected to ftp.hikago.flirble.org
5.3 A Real-time Ethernet Data Transfer System
During the phase of developing the vibration sensing remote data acquisition and
storage system, a supplementary system is built. The supplementary system is a real-
time Ethernet data transfer system.
22
User interface device A
Microcontroller A
User interface device B
Microcontroller B
Ethernet
A Real-time Ethernet Data Transfer System
Figure 5.3: A real-time Ethernet data transfer system
The system uses microcontroller A to obtain data from user interface device A which
is a signal source, and microcontroller B sends out signal to a user interface device B
real-time. The real-time Ethernet data transfer system has been tested by receiving
signal from signal generator and transmitting signal to oscilloscope.
One of the applications of a real-time Ethernet data transfer system is to establish an
Ethernet telephone. This can be done when user interface device A and B are both
sets of microphone and speaker (In this case, the output signal of microphone needs
to be connected to voltage amplifier since its output voltage range is small). The
sound frequency human-being can hear is at the range of 20 to 20,000Hz. FM radio
stations usually carry sounds from 50 Hz to 15 kHz. Though BL2500 with RN1200
A/D expansion card has sampling frequency of 2.5 kHz, its update frequency for
D/A conversion is only 10Hz, thus the Ethernet telephone system is not implemented
in the project.
23
5.4 Vibration Sensing Remote Data Acquisition and Storage
System
Oscillator Shaker with accelerometer Charge Amplifier
Voltage amplifier DC generator Microcontroller
Ethernet Computer
Figure 5.4: Vibration sensing remote data acquisition and storage System
24
This diagram shows the setup of electrical devices in the laboratory to create and
detect physical oscillation and to produce an analog output voltage that is operational
to BL2500 with RN1200 A/D expansion card.
Physical oscillation on shaker is activated by oscillator. For instance, when the
oscillator sends a sinusoidal signal to shaker, the shaker shakes in a sinusoidal form.
The accelerometer then plays its role as transducer to measure the acceleration of the
shaker. The relationship between the acceleration and its amplitude in the example
given above will be, a = -Aω2sin(2πft). Charge amplifier then outputs the
acceleration signal in voltage form to voltage amplifier.
The analog output signal for charge amplifier is in the range of 0-30mV, this range
of voltage is too small as compared to operational analog input voltage ranges for
RN1200. RN1200 voltage ranges are programmable 0-1V, 2V, 5V, 10V, 20V DC
(single ended) or ±1V, ±2V, ±5V, ±10V, ±20VDC (differential), none of them are in
the milivolt range, thus charge amplifier output voltage range has to be amplified.
With the maximum gain of 15, analog voltage range from charge amplifier is
amplified from 0-30mV to 0-0.45V by using a voltage amplifier. The most suitable
analog input operating voltage range for RN1200 is programmed at 0-1V. A DC
generator is used to overcome the internal DC voltage offset caused by voltage
amplifier and to bias negative voltage.
25
Table 5.2: The models of electrical equipments used in the laboratory
Equipment Brand Type
Oscillator Hewlet Packard 35670A
Shaker Ling Dynamic System V101
Accelerometer Brüel & Kjær 4393
Charge Amplifier Brüel & Kjær 2635
Voltage Amplifier LDS Pa25E
DC Generator TRIO PR-601A
26
6 Conclusion
In the project, programming in microcontroller and computer has been done to
achieve the objective of establishing a vibration sensing remote data acquisition and
storage system. For the programming part in the project, there are various issues
needed to be taken care. These issues are related to analog data acquisition,
transmission and storage as well as TCP/IP related DHCP, socket opening and
establishment. Dynamic C is used for microcontroller programming while Ruby is
used for windows programming in the central monitoring computer. These two
programming languages as well as TCP/IP and DHCP are studied to form the
knowledge basis for the project.
The vibration sensing remote data acquisition and storage system can be used to
detect vibrations including earthquake. An accelerometer is used to measure
vibration. The measured vibration will be output to a microcontroller that is
programmed to receive and process the data. In the laboratory, a proper setup of
electrical equipments is required to create physical vibration and to produce an
operational voltage range for the microcontroller. The setup of electrical equipments
involves oscillator, shaker, accelerometer, charge amplifier, voltage amplifier and
DC generator.
27
Ultimately, physical vibration created in the laboratory will be detected and analog
signal is transmitted to microcontroller. Through Ethernet, data is transferred from
microcontroller to a central monitoring computer. The computer is programmed to
store the data in a text file. Date and time of event will also be recorded in the file
itself. The data recorded can thus be processed, analyzed or saved for future use.
During the development stages, the microcontroller has been programmed to perform
different tasks. Digital data transmission has been done in the microcontroller via
Ethernet. Through the internet, the microcontroller is also able to connect to FTP.
During the development phase, another supplementary system called real-time
Ethernet data transfer system is built. This system can connect a user interface
devices at each end of the system to transfer analog signal real-time. One of the
examples of the uses of this system is to establish an Ethernet telephone.
28
References
[1] Loshin, Peter, “TCP/IP for Everyone”. Academic Press Limited, London, 1995.
[2] Alcott, Neall, “DHCP for Windows 2000”. O’Reilly & Associates Inc, USA,
2001.
[3] Thomas, David and Hunt, Andrew, “Programming Ruby”, Addison-Wesley,
New York, 2001.
[4] Fulton Hal, “The Ruby Way”. Sams Publishing, USA, 2001.
[5] Z-world Engineering, “BL2500 Coyote C-Programmable Single-Board Computer
with Ethernet Reference Manual”, revision 8.1, 2003
[6] Z-world Engineering, “RN1200 A/D Expansion Card Reference Manual”,
revision 8.1, 2003
[7] Z-world Engineering, “Dynamic C Technical Reference Windows-Integrated C
Development Environment for Embedded System”, version 8.1, 2003
[8] Z-world Engineering, “Dynamic Function Reference for Real-Time Embedded
Systems”, revision 8.1, 2003
29
Appendix A: Transmission Control Protocol/Internet
Protocol (TCP/IP)
A network is a system of hardware and software, put together for the purpose of
communication and resource sharing. Network technologies can be classified into
two basic groups, LAN or WAN. Local area network (LAN) technologies connect
many devices that are relatively close to each other, usually in the same building
while a WAN must be able to connect an arbitrary number of sites across an arbitrary
distance, with an arbitrary number of computers at each site.
Ethernet is a local area technology, with networks traditionally operating within a
single building, connecting devices in close proximity. At most, Ethernet devices
could have only a few hundred meters of cable between them, making it impractical
to connect geographically dispersed locations. But modern advancements have
increased these distances considerably, allowing Ethernet networks to span tens of
kilometers.
The protocol selected for the communications between hosts via Ethernet in the
project is TCP/IP. TCP stands for Transmission Control Protocol while IP is Internet
Protocol. TCP packages its data into segments containing both data and session
control information. It provides end-to-end reliability, requiring that communicating
hosts coordinate and agree to make connections and acknowledge receipt of network
30
traffic. It also uses several techniques to maximize the performance of the connection
by monitoring the connection to make sure that TCP segments are neither too large
nor too small and are bring transmitted neither too fast nor too slow for the virtual
circuit between the two hosts.
TCP connections act as if there were a hard-wired connection between processes on
the two connected hosts. Each TCP connection starts out with a negotiation between
the two hosts to open the connection – each host has to agree to participate. The TCP
virtual circuit is similar to a telephone link: one person initiates the telephone call,
but the person at the other end has to answer the phone. A conversation ensues if
both individuals agree to start and continue a conversation.
Each connection is identified uniquely with a combination of each host’s IP address
and port number for the connection. The combination of these two pairs of IP
address and TCP port numbers, or two TCP sockets, uniquely identifies each TCP
connection. A single host can maintain more than one TCP connection through a
single TCP port because incoming TCP segments are differentiated by different
source sockets (different clients’ IP addresses). This is useful to servers, which need
to manage connections to multiple concurrent clients, as well as to clients that may
want to keep multiple client sessions with different servers.
31
Port numbers are the mechanism for identifying particular client and server
applications. Servers select a port to wait for a connection. Most services have well-
known port numbers. For example, HTTP uses port 80. When a web browser (the
client) requests a web page it specifies port 80 when contacting the server. Clients
usually have ephemeral port numbers since they exist only as long as the session
lasts.
Some of the common well-known TCP port numbers are listed in the table below.
Port Number Listening Application
7 Echo request
20/21 File Transfer Protocol (FTP)
23 Telnet
25 Simple Mail Transfer Protocol (SMTP)
53 Domain Name Server
80 HTTP Server
The range of port number free to be used for personal purposes is from 1025 to
65536. In the project, the central monitoring computer (server) is programmed in
opening its port at a fix port number 3000.
32
Appendix B: Dynamic Host Configuration Protocol
(DHCP)
In general, the Ethernet data acquisition and storage system can be established in
different types of network. In the project, the network in use is the Local Area
Network service provided by National University of Singapore. One of the features
NUS network has is DHCP. DHCP is a method for a device to assign its network
configuration information from a central server. The advantages of implementing
DHCP include:
• DHCP allows administrators to control configuration parameters on their
network.
• Clients using DHCP can be dynamically configured. This allows additions
and changes to networks without the need to visit each individual host or
work-station.
• For fault tolerance, multiple DHCP server can service one or more subnets.
• DHCP servers can service more than one subnet (routed).
• DHCP provides a dynamic database for IP address allocation. These IP
addresses, when no longer in use, can also be reclaimed via lease duration
• Clients can continue to use a DHCP-allocated IP address even after the client
is rebooted.
33
In order to obtain IP addresses from NUS network, BL2500 is programmed to be a
DHCP client. The DHCP client, is the software portion of an operating system that is
designed to request IP addresses and other related configuration information. Once it
receives the requested information, the software reconfigures the operating system.
There are actually 3 main components in a DHCP conversation. The first component
is the DHCP client as described above. The second component, the DHCP server, is
a program that listens for requests from DHCP clients on the network and supplies
them with the information that is requested. The DHCP server is maintained by a
network administrator.
The third component is the DHCP relay agent. The DHCP relay agent listens for
DHCP broadcasts on its local subnets. The DHCP relay agent is configured with IP
addresses of DHCP servers. IF it receives a DHCP broadcast from a DHCP client,
the DHCP relay agent will send the request as a unicast message directly to a DHCP
server.
34
Appendix C: Program Codes for Microcontroller
#class auto #define TCPCONFIG 5 #define DHCP_NUM_SMTP 1 #define DHCP_NUM_ROUTERS 2 // Get up to 2 routers (gateways) if possible #define DHCP_NUM_DNS 2 // Get up to 2 DNS (Domain Name System) servers if possible #define DHCP_NUM_QOTD 2 #define MAX_COOKIES 2 // Also need to tell main tcp lib (default is 1). #define DHCP_MINRETRY 5 #define DHCP_USE_TFTP (3*512+5) #define TFTP_ALLOW_BUG // Work-around certain TFTP server upload bug #define DHCP_CLASS_ID "Rabbit-TCPIP:Z-World:DHCP-Test:1.0.0" // This macro causes the MAC address to be used as a unique client // identifier. #define DHCP_CLIENT_ID_MAC #define WEBSITE "172.19.53.40" //either nameserver or address of server #define PORT 3000 // server port number #memmap xmem //All C functions not declared as root go to extended memory #use "dcrtcp.lib" static void print_results(void) { auto long tz; auto word i; printf("Network Parameters:\n"); printf(" My IP Address = %08lX\n", my_ip_addr); printf(" Netmask = %08lX\n", sin_mask); if (_dhcphost != ~0UL) { if (_dhcpstate == DHCP_ST_PERMANENT) { printf(" Permanent lease\n"); } else { printf(" Remaining lease = %ld (sec)\n", _dhcplife - SEC_TIMER); printf(" Renew lease in %ld (sec)\n", _dhcpt1 - SEC_TIMER); } printf(" DHCP server = %08lX\n", _dhcphost); printf(" Boot server = %08lX\n", _bootphost); } if (gethostname(NULL,0)) printf(" Host name = %s\n", gethostname(NULL,0)); if (getdomainname(NULL,0)) printf(" Domain name = %s\n", getdomainname(NULL,0)); if (dhcp_get_timezone(&tz))
35
printf(" Timezone (fallback only) = %ldh\n", tz / 3600); else printf(" Timezone (DHCP server) = %ldh\n", tz / 3600); for (i = 0; i < *_last_nameserver; i++) printf(" DNS server #%u = %08lX\n", i+1, def_nameservers[i]); if (_smtpsrv) printf(" SMTP server = %08lX\n", _smtpsrv); for (i = 0; i < _last_cookie; i++) printf(" Cookie server #%u = %08lX\n", i+1, _cookie[i]); ip_print_ifs(); router_printall(); } main() { longword st; longword rls; char bounced; char pboot; char putback; struct tftp_state ts; int status; word bflen; tcp_Socket *socket; //declare a socket to use- it is a pointer to socket structure char writebuffer[1024]; char serverbuffer[1024]; float inputvalue; longword ip; brdInit() ; pboot = false; // Not yet printed boot file putback = false; // Not yet echoed boot file to server bounced = false; // Not yet released/re-acquired DHCP parameters // Set runtime control for sock_init()... ifconfig(IF_DEFAULT, // (DHCP only works on default interface) IFS_DHCP_TIMEOUT, 6, // Specify timeout in seconds IFS_DHCP_FALLBACK, 1, // Allow use of fallbacks to static configuration IFS_ICMP_CONFIG, 1, IFS_END); printf("Starting network (max wait %d seconds)...\n", _bootptimeout); brdInit(); status = sock_init(); switch (status) { default: break; case 1: printf("Could not initialize packet driver.\n");
36
exit(1); case 2: printf("Could not configure using DHCP.\n"); break; // continue with fallbacks case 3: printf("Could not configure using DHCP; fallbacks disallowed.\n"); exit(3); } if (_dhcphost != ~0UL) printf("Lease obtained\n"); else { printf("Lease not obtained. DHCP server may be down.\n"); printf("Using fallback parameters...\n"); } print_results(); rls = SEC_TIMER + 90; // In 1.5 minutes relinquish lease. for (;;) { // Check lease has not expired if (!tcp_tick(NULL)) { printf("Network down; bringing up in 2 secs...\n"); st = SEC_TIMER + 2; while (SEC_TIMER < st); if (!(status = dhcp_acquire())) { printf("Network back up\n"); print_results(); } else if (status == 1) { printf("Network back up but with DIFFERENT IP address\n"); print_results(); } else { printf("Network lost. DHCP server probably down.\n"); exit(78); } } // Some time after boot, "bounce" the network (just once). if (!bounced && SEC_TIMER > rls) { bounced = true; //dhcp_release(); ifconfig(IF_DEFAULT, IFS_DHCP, 0, IFS_END); printf("Network relinquished; re-acquiring in 3 secs...\n"); ip_print_ifs(); st = SEC_TIMER + 3; while (SEC_TIMER < st); //if (!(status = dhcp_acquire())) { if (!(status = ifconfig(IF_DEFAULT, IFS_DHCP, 1, IFS_END))) { printf("Lease re-acquired\n"); print_results(); }
37
else if (status == 1) { printf("Hmmm... lease re-acquired with DIFFERENT IP address\n"); print_results(); } else { printf("Whoops! Lost network. DHCP server probably down.\n"); exit(79); } } // When we first get the boot file, print its length. _bootpdone is // a global variable which gets set to 1 if the bootfile has been // downloaded, 2 if there was no bootfile specified, or // 0 if bootfile status not yet known. if (!pboot && _bootpdone) { pboot = true; if (_bootpdone == 2) printf("No network boot file configured by server\n"); else { printf("Network boot file:\n"); if (_bootperror && _bootperror != -5) printf(" Error code %d: %s\n", _bootperror, _bootperror == -1 ? "Server denied access" : _bootperror == -2 ? "Could not contact server" : _bootperror == -3 ? "Timed out" : "unknown error" ); else { printf(" Length = %u\n", _bootpsize); if (_bootperror == -5) printf(" File was truncated\n"); putback = true; } } } // Once we have the boot file, echo it back to the server. Sometimes, for // a length which is not an exact multiple of 512, an error condition will // be returned. This happens when the server is non-RFC compliant and // does not wait around to ACK the last packet. It's not our fault! if (putback) { putback = false; ts.state = 1; // Write ts.buf_addr = _bootpdata; ts.buf_len = _bootpsize; ts.my_tid = 0; ts.sock = NULL; // use DHCP one ts.rem_ip = 0; // use bootp server ts.mode = TFTP_MODE_OCTET; strcpy(ts.file, "/tftpboot/echo"); printf("Sending boot file back as %s\n", ts.file); // This uses the non-blocking TFTP functions, but in a blocking
38
// manner. It would be easier to use tftp_exec(), but this // doesn't return the server error message. if (!tftp_init(&ts)) { while ((status = tftp_tick(&ts)) > 0); // Loop until complete if (!status) printf("Upload completed\n"); else { printf("Upload failed: code %d\n", status); if (status == -1) printf(" Message from server: %s\n", ts.file); } } else printf("Error: could not use dchp socket for tftp\n"); // Now we do it again, using tftp_exec(). //bflen = _bootpsize; //status = tftp_exec(1,_bootpdata,&bflen,1,NULL,"/tftpboot/echo2",NULL); //printf("echo2 uploaded: status = %d\n", status); } break; } while (1){ ip=resolve(WEBSITE); //convert dotted ip address or host name to longword if(ip==0) printf("couldn't resolve IP adress\n"); else printf("%s is the address resolved from server.\n", inet_ntoa(serverbuffer,ip)); if (tcp_open(&socket,0,ip,PORT,NULL)) //socket/our port/destIP/destPort/Fcall or Tobuffer printf ("tcp_open works!\n"); else printf("Failed to open\n"); printf("Waiting for connection...\n"); while(!sock_established(&socket)) { if (!tcp_tick(&socket)) { printf("Failed to establish\n"); break; }} if (sock_established(&socket)) { printf("Established OK!\n"); // do whatever needs to be done... } while(tcp_tick(&socket)){ inputvalue = anaInVolts(0); printf ("The value obtained from ocillator is %f\n", inputvalue); pwmOutVolts(1, inputvalue);
39
sprintf (writebuffer, "%f", inputvalue); sock_write(&socket, writebuffer,sizeof (writebuffer)-1); break; } sock_abort(&socket); printf("Connection closed...\n\n"); }//end of the Ultimate while loop }
40
Appendix D: Program Codes for Central Monitoring
Computer
require "socket" PORT = 3000 server = TCPServer.new(PORT) message = "you are connected to server" j =0 #counter for newline date=1 k=0 # for 3 times data acquisition while (session = server.accept) session.puts(message) #notification for client data = session.gets disk=File.new("foolfile2.txt","a+") if date==1 then disk.puts "\n" disk.puts Time.new date = 0 end i = 0 while i<8 disk.putc(data[i]) i+= 1 j+=1 if j == 8 then disk.puts "\n" j=0 end end disk.close session.close end
41
Appendix E: BL2500 Specifications
Feature BL2500
Microprocessor Rabbit 3000® at 29.4 MHz Ethernet Port 10Base-T, RJ-45 Flash Memory 256K standard, 512K (2 × 256K) option SRAM 128K standard, 512K option Backup Battery 3 V lithium coin type, 1000 mA·h,
supports RTC and SRAM LEDs 4, user-programmable
Digital Inputs 15 protected to ±36 V DC, 1 protected
from -36 V to +5 V DC, switching threshold is 1.5 V nominal
Digital Outputs 8: sink up to 200 mA each, 36 V DC max.
Analog Inputs One 10-bit resolution, 8-bit accuracy, input range 0.1-3.1 V, 10 samples/s
Analog Outputs Two 9-bit PWM, 0.1-3.1 V DC, worst-case 17 ms settling time to within 5 mV of final value (built-in RC settling time constant = 2.5 ms)
Serial Ports
6 serial ports:
• one RS-485 • two RS-232 or one RS-232 (with
CTS/RTS) • one clocked serial port
multiplexed to two RS-422 SPI master ports*
• one CMOS level asynchronous or clocked serial port
• one serial port dedicated for programming/debug
Serial Rate Max. asynchronous rate = CLK/8, Max. synchronous rate = CLK/2
Real-Time Clock Yes
42
Timers Five 8-bit timers (four cascadable from the first), one 10-bit timer with 2 match registers
Watchdog/Supervisor Yes Power 8-40 V DC (RabbitNet peripheral boards
are limited to 32 V DC max.)
1 W typ. with no load Temperature -40°C to +70°C Humidity 5% to 95%, noncondensing Connectors Molex-type connectors:
five polarized 9-position terminals with 0.1" pitch two 2-position power terminals with 0.156" pitch two 4-position terminals with 0.156" pitch
Unit Size 3.95" × 3.95" × 1.16" (100 mm × 100 mm × 29 mm)
43