This is only a preview of the February 2011 issue of Silicon Chip. You can view 32 of the 104 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Items relevant to "LED Dazzler: A Driver Circuit For Really Bright LEDs":
Items relevant to "Build A 12/24V 3-Stage Solar Charge Controller":
Items relevant to "Simple, Cheap 433MHz Locator Transmitter":
Items relevant to "Digital/Analog USB Data Logger, Pt.3":
Purchase a printed copy of this issue for $10.00. |
Universal USB
Data Logger; Pt.3
In this third and final article on the USB
Data Logger, we describe how to use the
accompanying Windows host software.
This software allows you to edit and test
scripts, upload them to the logger and
change its settings.
By MAURO GRASSI
A
S EXPLAINED previously, scripts
are used tell the Data Logger
which sensor(s) are attached, how to
query them, what the readings mean,
how often to log the data and the data
format to use.
If you have not already prepared a
memory card, you can format it with
a FAT or FAT32 file system (a quick
format is OK) before plugging it into
the Data Logger, with the power off.
Having installed the host software and
driver (see Pt.2), plug the Data Logger
into your PC and launch the software
by double-clicking the .exe file.
What the software does
Essentially, the Windows host software is a “development environment”
which allows you to write scripts,
upload them to the Data Logger and
test them. It also allows you to monitor scripts as they run and download
logged data over the USB interface. In
addition, you can change the Data Logger’s settings from the host software.
Since complex scripts can be difficult to debug when running on the
Data Logger itself, the software allows
you to “simulate” the scripts, running
them on the host PC to see what they
76 Silicon Chip
do. Scripts can be simulated at an accelerated rate which is useful for those
scripts which involve long delays.
Note that because simulated scripts are
run on the host PC, they can not access
the sensors as they can on the Data
Logger. For example, if a simulated
script reads from an analog input, the
result is always zero.
User interface
The interface for the Windowsbased host software is shown in Fig.11.
When plugged into a USB port, the
Data Logger is detected automatically.
Its firmware version and the connection status are shown in the window
title bar, at top.
The main window has a number
of sub-windows. The script editor
sub-window is at upper left and this
is where scripts can be created or
modified. The log sub-window below
it allows you to keep track of program
actions as they take place. There are
some buttons between the two which
clear the log window and perform
other common actions.
At lower right is the console subwindow, which has a grey background.
It allows you to see what a script is log-
ging as it runs or is simulated, which
is useful for testing complex scripts
(more on that later). Above the console
are several buttons, used to control the
simulation.
At far upper right are the Data Logger settings and below them the Host
Settings, which apply to the PC host
software.
To the left of the settings are four
additional sub-windows (two red, two
green) which allow you to see the files
and scripts stored on the Data Logger
and on your host computer (respectively). They also allow you to manage
scripts, including transferring them to
and from the Data Logger.
Settings
The device settings (at upper right
of Fig.11) are stored on the Data Logger, both in a file on the memory card
and in its internal FLASH memory. If
the file on the memory card becomes
corrupted or the card is removed, the
Logger relies on its internally stored
settings. Otherwise, the settings on the
memory card are used.
You can copy the settings between
the Data Logger and the host PC via
the Host and Device menus. It is also
siliconchip.com.au
Fig.11: this is the user interface for the PC host software. This lets you edit, compile and upload scripts to the USB Data
Logger via the USB interface. It also allows you to change settings and to download log files.
possible to restore the settings to the
defaults using these menus. They work
as follows:
Auto Time: when enabled, the PC host
automatically sets the real-time clock
in the Data Logger whenever they are
connected. Without this option you
can synchronise the time manually
via the “Time” menu.
System Log: when enabled, the Data
Logger will note special events in a
log file on the memory card (syslog.
txt). This is useful for troubleshooting but slows the Data Logger down
and increases its power consumption.
The contents of this file can be read or
cleared through the host software via
the Device menu when the Data Logger
is plugged in.
System Log USB: when enabled, as
well as logging to the “syslog.txt” file
on the memory card, the Data Logger
also sends system log messages over
the USB serial interface and the host
software diplays them in the console
sub-window.
Undervoltage: when this is enabled
and the battery voltage drops below the
specified level, the Data Logger goes
into sleep mode, minimising power
consumption. This is recommended
siliconchip.com.au
in order to avoid over-discharging the
battery. Remember that this voltage
does not take into account the voltage
drop across the Schottky diode from
the battery (the default setting is 1.8V
as shown).
menu to provide the best legibility
with your display.
If you are using a third-party text
editor, the easiest way to upload the
script is to paste it into the text editor
window and then proceed from there.
Editor window
File browser
You can use any text editor you like
to write scripts but for convenience,
the host software has a built-in editor,
allowing small script changes to be
made and then immediately simulated or uploaded to the Data Logger
for testing. The script is shown in the
upper left window and most of the associated commands are located in the
“File” menu above it. The editor font
size can be changed via the “Window”
As mentioned, the two red and two
green sub-windows towards the upper
right are the file and script browsers.
The red windows show directories,
log files and scripts on the Data Logger while the green windows show the
same information for the host computer. Using these windows, you can
browse the contents of both devices
and transfer files between the two.
In each case the left-most window
Where To Buy Kits & PC Boards
A complete kit of parts for the USB Data Logger is being produced by
Altronics and should be available shortly after this issue appears.
In addition, readers will be able to purchase the PC board from SILICON CHIP.
This board is double sided, with plated through-holes and features a solder
mask, FR-4 fibreglass substrate, tinning and 1oz copper tracks.
The PC boards are available for $A25 (including GST) plus $A10 postage
per order. Postage is $A12 to NZ or $A18 elsewhere.
February 2011 77
Fig.12: this interface appears if the PC host software is
launched with the bootloader running. This then allows
you to update the firmware in the USB Data Logger.
shows the file system directory structure and files (including log files)
while the right-most window shows
the loaded scripts (more on that later).
Up to eight script files at a time can be
loaded on the Data Logger and each is
assigned a unique number, which is
also shown.
Local files are stored in the same
directory as the host software. In
both cases, the file lists are sorted
alphabetically. Directories are shown
in square brackets and directories and
files can be opened by double-clicking
them. Scripts are opened in the editor
window. Right-clicking on a file gives
a context menu with additional options. This includes options to initiate
file transfers between the Data Logger
and host PC.
Note that while this is a very convenient way to access log files on the
Data Logger, for large log files (15MB
or more) it can be faster to remove the
memory card from the Data Logger
and use a USB card reader to transfer
them instead. This is because the Data
Logger’s USB transfer speed is limited
by the PIC18F2753’s small amount of
RAM (Random Access Memory) and
modest clock speed.
Compiling scripts
Before a script can be tested or
78 Silicon Chip
Fig.13: after selecting a hex file and clicking “Yes” (see
Fig.12), the new firmware is uploaded to the logger and a
progress bar is displayed at the bottom of the window.
used, it must be loaded into the editor
window and then compiled. When it
is compiled, the software checks that
the script is valid. If there is anything
wrong with it, the Compile button
turns red, one or more error entries
appear in the log window and compilation is aborted.
If errors are reported, the first invalid line in the script code is highlighted. The location of the error is
also shown in the log sub-window,
as a line and column reference. Once
the problem has been fixed, you can
attempt to compile the script again.
The compiler can also generate
“warnings”. As with errors, these are
noted in the log sub-window but they
do not prevent successful compilation.
If present, these warnings indicate
possible errors in the script but they
can sometimes appear when the script
is correct.
If the script is correct (ie, there are
no errors), the Compile button turns
green and the script is added to the
list of available local scripts.
Rather than pressing the “Compile”
button you can also press the F10
key on your keyboard. The compiled
script can be transferred to the USB
Data Logger by right-clicking on it in
the green “Host Scripts” window and
selecting “Send PC Script”. For con-
venience, you can press F11 instead
which compiles the script and then
automatically sends it to the Data
Logger, assuming the compilation was
successful. You can also send all local scripts to the USB Data Logger by
pressing Shift+F11.
There is a handy help window at the
right of the user interface (with a grey
background) which lists all defined
constants, global functions and global
variables in the script. Each global
function is listed with a number in
parentheses indicating the number
of arguments that the global function
takes. Global define constants are
shown with their values, while global
variables are shown with their size.
The “Optimize Code” option, above
the log window, is enabled by default.
This allows the compiler to remove
any redundant portions of the script
or simplify it where possible. This
reduces the memory and processing
required to run a script on the USB
Data Logger.
Simulating scripts
Once a script is compiled, it can be
simulated in the console sub-window
(lower right of Fig.11) using the Run,
Stop, Reset and Step buttons. Pressing
Run begins the simulation and the
script output is shown in the console
siliconchip.com.au
window (this would normally be
stored in the log file on the memory
card). If you click Stop, the script
pauses and the next line about to be
executed is highlighted in the editor
window.
You can then use the Step button to
proceed through the script, one line at
a time. This is good for debugging since
you can observe the program flow and
see the log output from each individual
line in the script. The Reset button can
be used to start the script from scratch
and the Clear Console button blanks
the console sub-window.
During simulation, the Scale Time
option can be adjusted (upper right) to
change the speed at which the simulation runs. For example, if Scale Time
is enabled and set to 10, a scripted
delay of 25 seconds actually takes
2.5 seconds. This makes debugging
scripts with long logging periods far
less tedious.
You can also use the console subwindow to observe data being logged
to the memory card in the Data Logger
as it occurs. This is useful for the final
test of a script, with the actual sensors
attached.
Status bar
The status bar, at the bottom of the
window, indicates what the host software is doing at any given time. This
shows USB data transfers, the time
from the Data Logger and so on. At the
right of the status bar are two flexible
displays which can show various statistics, which are selected by clicking
on that portion of the status bar.
The first (left-most) flexible display
shows information about time synchronisation while the second shows
various voltages from the Data Logger, including the supply and battery
voltages.
Updating the firmware
The Data Logger’s firmware (the software running on the microcontroller)
can be updated from the host computer
over USB. To do this, first you must
activate the bootloader by holding
down S2 on the USB Data Logger while
applying power (normally from USB).
To do this, the battery must be removed
as there is no way to switch it off.
With the bootloader activated and
the Data Logger plugged into the
host PC via the USB port, launching
the host software will display the
bootloader interface instead of the
siliconchip.com.au
Tips For Installing The USB Driver
Here’s a tip for installing the USB driver. The USB Data Logger will go into
standby (and detach from the host PC’s USB interface) when there are no
custom scripts loaded. This is done to save power and since initially there
are no scripts loaded, this will be the state of the USB Data Logger after it
is first switched on.
As this can affect the installation of the driver (since the USB connection
may be lost during the driver installation), it is advisable to install the driver
with no memory card inserted in the socket. When switched on, if no memory
card is present, the USB Data Logger does not enter standby as quickly as
it does when a card is present.
This gives you around two minutes to plug it in and install the driver, which
should be long enough in most cases. If not, you can always press S2 to
keep it out of standby for another five seconds. This feature is provided as a
fail-safe feature in case the USB Data Logger is used with a very old system.
usual development environment (see
Fig.12).
In bootloader mode, the blue LED
(LED3) flashes at around 1Hz. Once
the USB interface has been recognised,
the flash rate increases slightly and is
faster again when the firmware is being
read or written.
Typically, firmware updates are supplied as a hex file (.hex file extension).
You can then use the “Write HEX”
option to transfer this file’s contents
contents into the microcontroller’s
FLASH memory (Fig.13). It will check
that the file is valid, then ask you to
confirm that you want to overwrite the
existing firmware. After rewriting the
program memory, a verify operation
is automatically performed to ensure
that it was successful.
Note that if you subsequently use
the Data Logger and then attempt to
verify the firmware manually using the
Verify Memory button, the verification
will fail because the Data Logger also
uses the FLASH memory to store its
settings. This also means that updating
the firmware resets the Data Logger’s
settings to its defaults.
Using the logger
When operating, pushbutton S2 and
blue LED3 are used to control logging
and provide feedback. A short press of
S2 tells you the logging status: LED3
will flash once if at least one script is
running or three times if there are no
scripts running (and therefore no logging is taking place).
A longer press of S2 pauses all
scripts, in which case the logger
flashes its LED three times to confirm
that logging is paused. A second long
press results in a single flash and logging resumes.
The blue LED also flashes to indicate
USB activity when the USB interface
is in use by the host software.
Standby mode
The logger automatically goes into
standby mode under the following
circumstances:
(1) When there are no custom scripts
loaded.
(2) When all the custom scripts that
are loaded are paused or not running.
(3) When there is a time delay of at
least five seconds, during which no
custom scripts need to run.
(4) When the under-voltage protection
is enabled and the battery voltage is
below the set threshold.
In standby mode, the Data Logger’s
USB interface shuts down (the PC host
will show it as being “disconnected”)
and the LED glows dimly but does
not flash.
As mentioned in Pt.1 (December
2010), the full power savings will not
be made unless the minimum logging
period of all executing scripts is above
the threshold for going into standby
(five seconds). Below this threshold,
the microcontroller does not switch
off power to certain components,
including the memory card, because
otherwise the initialisation sequence
would take too long. You will therefore
get the best battery life if your logging
scripts execute sleep periods of greater
than or equal to this time.
In standby mode, the current drain
from the battery is around 560-850µA.
If the battery voltage is very low, the
PIC enters sleep mode which is at the
February 2011 79
Errata
Sample Excerpt From Syslog.txt
Time Unavailable: USB Data Logger Version: 9.60. Global PORs: 4. Local PORs: 1.
Time Unavailable: Memory Card Detected, Total Size: 2.0 GB Free Size: 2.0 GB.
Time Unavailable: VM(s) Running: 1 of 2.
Time Unavailable: The Following VM(s) Are Loaded: { oneScript, csvScript }
lower end of this range (560µA) and
it stays in sleep mode until the device
is power cycled.
This does not include the current
consumed by any sensors powered
from the Data Logger. Typically, sensors will not consume much power
when they are idle but for long-term
logging, even a small amount of additional power can reduce battery life.
If the Data Logger goes into standby
mode while plugged into USB, it will
disconnect from the host PC (it won’t
do this if the host program is running).
Pressing S2 or inserting a memory card
brings the Data Logger out of standby
mode.
While writing to the SD card, instantaneous power consumption from the
battery can be 25mA or more but if the
scripts have long sleep periods, this
averages out to a much lower value
in the long term.
System log
As mentioned earlier, the Data
Logger can store events in a system
log for troubleshooting purposes. A
sample excerpt from the syslog.txt
file, as created when the Data Logger
is switched on, is shown in the accompanying panel.
The first line shows the Data Logger firmware version and the number
of power cycles (Power On Resets
or PORs) that the USB Data Logger
has undergone. The Global reading
indicates full resets while the local
reading shows the number of times the
scripts have been reset by the software.
This can happen if the memory card
is removed.
The second line shows information
on the memory card while the third
shows how many virtual machines
(VMs) are actively running scripts
(there are up to eight). The fourth line
shows the names of the scripts that
are loaded.
Here are some more example system
log entries:
Thu 23 Dec 2010 05:42:01: Destroy 2 VM(s).
Thu 23 Dec 2010 05:42:11: Holding.
The first line indicates that two
scripts were reset, resulting in their
virtual machines being “Destroyed”.
The second indicates that script execution has been paused by a long press
on pushbutton S2.
Digital sensor requirements
When using an input for frequency
or event counting, you must make sure
the signal is within 0-5V (for D0-D3)
or 0-3.6V (for D4 & D5).
For I2C sensors, their SCL (clock)
line must be connected to D0 and the
SDA (data) line to D1. While the pin
connections for the I2C bus are fixed,
multiple scripts can access sensors on
the one bus.
One Wire sensors can connect to
any of the six digital pins D0-D5. You
must configure the correct pin number
in the script. The same applies to the
serial port; you specify the Transmit
and Receive pin numbers, the baud
rate and the mode. The serial port
supports baud rates up to 0.5Mbps.
Multiplexed peripherals
While the PIC18F27J53 microcontroller has just two serial peripherals,
each of the eight possible scripts can
configure its own serial port with
whatever configuration it requires (pin
connections, baud rate, etc). The PIC’s
To improve filtering of the +3.3V
supply rail, the 22µF tantalum
capacitor on the output of REG1
should be changed to a 220µF
10V low-ESR electrolytic (Jaycar
RE-6300). This change applies
to both the circuit diagram in Pt.1
(December 2010, page 38) and to
the overlay diagram in Pt.2 (January
2011, page 35).
Note that there are two 22µF tantalum capacitors shown adjacent to
REG1 on the overlay. The capacitor
on the left is the one to change.
The parts list in Pt.1 should be
amended accordingly.
peripheral pin select (PPS) feature allows the software to re-map the UARTs
as appropriate for each script as it runs.
This is the same feature which allows
One Wire sensors to be connected to
any of the I/O pins.
For example, you can have one
custom script sending data to a serial port on pin D0 at 9600bps, while
having another script sending data to
an independent serial port on pin D1
at 115,200bps. The hardware state is
saved and changed as required by the
firmware for the currently executing
custom script.
As well as selecting the pin connections and baud rate for the serial
port, scripts can choose to invert the
receive or transmit logic or to have an
open drain output.
Writing scripts
Finally, for those who build the
USB Data Logger, we have prepared
some detailed information on writing
logging scripts, including a complete
description of the language’s syntax
and global functions and variables.
This information is available as
a PDF file from the February 2010
section of the SILICON CHIP website.
It is named “USB Data Logger User
SC
Manual.pdf”.
Issues Getting Dog-Eared?
Keep your copies safe with these handy binders.
REAL
VALUE
AT
$14.95
PLUS P
&
P
Available Aust, only. Price: $A14.95 plus $10.00 p&p per order (includes GST). Just
fill in and mail the handy order form in this issue; or fax (02) 9939 2648; or call (02)
9939 3295 and quote your credit card number.
80 Silicon Chip
siliconchip.com.au
|