|
Part 1: The Land of BL2000
by Fred Eady
Start ı Z-Worldıs
BL2000 ı C Meı ı Lock
and Load ı Acquire the Voltage Data
ı Transport and Display the Voltage Data
ı Just the Beginning ı Sources
and PDF
ACQUIRE THE VOLTAGE DATA
The first order of business is to collect
the sensor data. Dynamic C Premier includes library routines designed
to manipulate the Z-World BL2000 analog inputs. In addition, there
are plenty of examples included with the C package that actually work!
The abundance of working example code makes the development process
easier, making it possible for you to put the Z-World BL2000 to work
collecting voltages much quicker.
There are at least three functional ways
to acquire the analog data using the Dynamic C Premier analog input
library functions. One method clocks a native formatted command sequence
out to the TLC2543. For the BL2000, the returned value corresponds
to the voltage on the ADC input pin and is in a range of 0ı4095 (12
bits). Thatıs nice. The value returned is what Iım looking for, but
the clocking of the command is not quite what I want to do here. The
remaining two methods return an integer and a float, respectively,
representing the analog input voltage value.
As you can see in Listing
1, I chose the integer method.
The float routine actually converts the voltage to an actual voltage
and the integer code throws out the voltage in raw binary format like
the clocking method. In either case, I can convert the voltages to
ASCII format and ship them across the Internet to the Microsoft Win2k
server box. Because I know that the result has to be put into a spreadsheet
cell, I like the raw format because I can use formulas in the spreadsheet
to scale the raw cell value if necessary. Also, converting the float
voltage value to ASCII loses the decimal point in the translation.
There are tricks I can employ to retrieve the original value but Iım
not trying to put on a programming clinic here. So, simpler is better,
as far as Iım concerned.
Reading the Z-World BL2000ıs analog inputs
is easy. All you have to do is call the anaIn() function and
specify the analog channel that is to be read. In Listing 1, Iım reading
the three internal reference voltages at channels 11, 12, and 13.
Iım also taking readings from buffered and scaled inputs 0 and 1 and
unbuffered analog input 8. Iıve included some printf code to
show you the results returned by the ADC channels. Of course, the
final deployed code wonıt contain the print statements. Running the
Z-World BL2000 code in Listing 1 writes the text you see in Listing
2 to the Dynamic C Premier STDIO screen.
|
BL2000 RAW VOLTAGE READINGS
Rawdata count for ch0 is 0xEEB
Buffered
Rawdata count for ch1 is 0x1BB
Buffered
Rawdata count for ch8 is 0xF19
Not Buffered
Rawdata count for ch11 is
0x800 (Vref+ - Vref-)/2
Rawdata count for ch12 is
0x000 Vref-
Rawdata count for ch13 is
0xFFF Vref+
User closed session
|
|
Listing 2ıDynamic C Premier
provides an STDIO window to show the results of print statements
embedded in the code. This allows for easy debugging without
having to break out the scope or protocol analyzer.
|
After the voltages are gathered and converted
to ASCII, the next step in the process is to establish a TCP/IP session
between the Z-World BL2000 and Billıs server. Using the tcp_open
function, the Z-World BL2000 establishes a connection with a TCP/IP-based
Visual Basic application residing on the Win2k server. There is a
router and Ethernet LAN environment at the Z-World BL2000 side, which
gives you the freedom to use the Ethernet capability of the Z-World
BL2000 instead of dialing an ISP using phone lines and a modem to
transfer the voltage readings. Just a few lines of Dynamic C Premier
TCP/IP code puts the Z-World BL2000 on its local LAN. A router that
is designated as the gateway device in the Z-World BL2000 socket code
provides access to the Internet. In this configuration, the Z-World
BL2000 connects, takes voltage readings, and sends them back to the
Win2k server application.
When the data arrives at the Win2k server,
the ball is in the Microsoft serverıs court. At this point, thousands
of dollars of outlay for prepackaged data collection software is circumvented.
Anyone who works with Microsoft Office can put my solution to work.
A simple Visual Basic program is kicked
off on the Win2k server that accepts the ASCII voltage data from the
remote Z-World BL2000. The VB program receives the data via some simple
TCP/IP programming and puts the raw voltage data in a flat ASCII file.
Semicolons delimit the voltage readings when they leave the BL2000ıs
Ethernet port. The delimiter allows the readings to be imported from
the flat ASCII file directly to the cells of an Excel spreadsheet.
If you were wondering why I was sending voltage data unconverted as
an integer instead of a float in ASCII format, now it should all become
clear. Using a simple Excel macro, you can take the raw ASCII numbers
and import them into the Excel spreadsheet for manipulation there.
The burden of conversion and scaling is taken from the Z-World BL2000
and passed to the Excel internals.
To give Excel the correct cell formula,
you must know how the Z-World BL2000 ADC inputs are scaled. The numbers
delimited by semicolons in Photo 2 are from left to right:
- Negative voltage read from a serial
port transmit pin
- Positive voltage read from a power
supply pin
- High positive voltage read from a
battery supply
- BL2000 difference of the positive
and negative reference voltages divided by 2
- BL2000 negative reference voltage
- BL2000 positive reference voltage
 |
| Photo 2ı This is more for clarity
than anything else. Excel recognizes the semicolons as field
delimiters when importing ASCII files into a spreadsheet. |
Every analog input is scaled even if
it is not buffered. Analog inputs 0ı3 are buffered and scaled using
an LMC660 op-amp. The Z-World BL2000 positive voltage supply is the
op-ampıs power source. A 200-kilohm resistor in the feedback path
is used with a 1-megohm resistor on the inverting input pin to scale
the input voltage by a factor of 0.2. The 12-bit ADC IC is referenced
with 4.096 VDC. This results in a one-LSB change representing 0.001
V. Adjusting this with the op-amp scaling value, each ADC step becomes
0.005 V. This results in a measurement range of 0 to 20.48 V. Because
the first four ADC inputs are designed to measure negative voltages,
the non-inverting inputs of the LMC660 are biased at 1.707 VDC to
place the zero point in the center of the 20.48-V range. This biasing
action results in a measurement range of ı10.24 to 10.23 VDC.
Letıs compute the first value using what
we know about the buffered and scaled analog inputs. The number of
steps is represented by the far left number, 3819 decimal. We know
our zero point is halfway, or 2048 steps. The difference from halfway
is 2048 ı 3819 = ı1771. Each step is equivalent to 0.005 VDC. So,
ı1771 ı 0.005 = ı8.855 VDC. Using my uncalibrated digital VOM, I measured
ı8.863 V across the screw-downs connected to the serial port transmit
pin.
We already know the next voltage must
be positive because the bit count is less than 2048. Using the same
algorithm from the previous example, you can compute the distance
from relative zero as 2048 ı 443 = 1605. Applying the scaling value
of 0.005 V per step, you come up with 1605 ı 0.005, or 8.025 VDC.
Again, applying my uncalibrated measuring stick, I read 7.949 across
analog input 1 to analog ground. Both readings contain a 1% error
factor when the actual uncalibrated VOM reading is compared to the
BL2000 output.
The third bit reading was taken from
a pack of five 9-V batteries connected in series. Channel 8 of the
Z-World BL2000 ADC subsystem is rated for a dynamic range of 0 to
49.15 VDC. This equates to 0.012 V per bit. The scaling factor is
achieved using a voltage divider consisting of an 11.0-kilohm 1% input
resistor in series with a 1.0-kilohm 1% resistor to analog ground.
The ADC input is taken from the center point of the voltage divider.
You can now compute the battery pack voltage as follows:
3865 ı 0.012 = 46.38 VDC
Applying my uncalibrated VOM reading
of 46.68 V as the absolute reference again puts the Z-World BL2000
reading of 46.38 V within the 1% accuracy area.
The final three readings are the internal
ADC reference voltages. A bit count of 2048 represents half of the
reference voltage of 4.096 VDC using a bit value of 0.001 V. Moving
one number to the right, ground is 0 V. Finally, the reference voltage
is sampled and, as expected, all 12 bits of the ADC fire off to give
you 0xFFF, or 4095 decimal. Again, the actual application will not
contain the pretty VB window, but the contents of the VB window are
written to the file just as you see them in Photo 2. Listing
3 is the tale of the tape for
the VB code.
PREVIOUS
NEXT
Circuit Cellar provides up-to-date information for engineers. Visit
www.circuitcellar.com for
more information and additional articles.
For subscription information, call (860) 875-2199, subscribe@circuitcellar.com
or subscribe online.
ıCircuit Cellar, the Magazine for Computer Applications. Posted with
permission. |