Data Files |
- Given a
situation in which you need to measure data and store the measurement
data in a computer file, you should be able to:
- Be able to convert data
from a character format to a numerical format within a program and to
realize when that occurs in a data gathering operation.
- Be able to convert data
from a numerical format to a character format within a program and to
realize when that occurs in a data gathering operation.
- Be able to write data to
a file in either format.
- Be able to predict the
size of the file.
We are going to start by looking at the first step in
the process - the measurement of data with an instrument. Even if you do not
run the data through a spreadsheet - or any other analysis program - the first
step is to measure things and convert the initial measurement to a digital
format. We will begin by looking at what happens as you use an A/D to convert a
measurement into a digital format.
Instrument Data - Background
Let's look at what happens when
you use an A/D.
- Let's say you wanted to build
an A/D that measured voltage from zero (0) to ten (10) volts and you wanted
it to have increments of a hundredth (0.01) of a volt.
- That would require you to be
able to distinguish 1000 different voltage steps.
- That situation almost always
means that you will need to have 10 bits in the A/D converter.
- to review A/D converters.
- Ten bits will give 1024
steps, so you could represent voltages like 0.00, 0.01, 0.02 . . . 10.23.
(Remember that is 1024 steps. Count the zero!) Remember, N bits can
represent numbers from 0 to 2N-1, and 210-1
= 1023.
There are also relations
between the accuracy of an A/D and the accuracy of a DVM. There are many other
questions that arise when you start using digital voltmeters. The answers to
questions about meters can be found in the lesson on DVMs.
What If
You Read Measurements And Store The Results In Data Files?
Let's assume that you're
measuring a DC voltage. You've written a C function called "MeasureDCVolts",
and you use it in this program segment.
float Volts;
Volts = MeasureDCVolts (instrumentHandle);
printf ("The measured voltage
is %f volts DC.", Volts);
What happens in this program segment?
Let's go through this one
line at a time. The first program line measures a voltage and stores the result
in a floating point variable "Volts".
Volts = MeasureDCVolts (instrumentHandle);
If the instrument is a 4-1/2
digit meter, using a 30 volt scale, then the result takes at least 15 bits.
That physical measurement determines how well you know the voltage. No matter
how you manipulate it after that it won't get any more accurate. A 4-1/2 digit
meter on a 30 volt scale will measure to within .001 volt, or 1 millivolt.
Now, when you take that
result and store it in a floating point variable, your're probably putting it
into 4 bytes, or 32 bits. That's a common way to represent a float variable.
You don't gain any precision when you do that. Sometimes the conversion will
give you trailing "9s" or a "1" after a string of zeroes when you print it.
That's irrelevant, but we do need to talk about what happens when you print
things.
You need to consider what
happens in a printf statement. Here's the code from the program segment.
printf ("The measured voltage is
%f volts DC.", Volts);
This line uses the value of the float
variable "Volts", and converts the numerical value it finds in "Volts" to a
string of characters. Then it puts those characters in the string surrounding
the "%f" and then it prints the characters. (The "%f" string gives the rule for
conversion.)
|