This is only a preview of the November 2008 issue of Silicon Chip. You can view 29 of the 96 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 "12V Speed Controller/Lamp Dimmer":
Items relevant to "USB Clock With LCD Readout, Pt.2":
Items relevant to "Wideband Air-Fuel Mixture Display Unit":
Items relevant to "IrDA Interface Board For The DSP Musicolour":
Purchase a printed copy of this issue for $10.00. |
USB Clock
With LCD
Readout
Pt.2: By MAURO GRASSI
Last month, we detailed the circuit of the
USB Clock and showed you how to build it. This
month, we detail the software installation and describe
how it is used. We also describe how to synchronise your PC
to an internet time server and how to synchronise the USB
Clock to the PC each time the PC boots up.
H
AVING BUILT the hardware, the
next step is to install the necessary driver. The following outlines the
steps for Windows XP but other Windows versions, including Windows
Vista, should work similarly.
The first step is to download the
Microchip installer (MCHPFSUSB_
Setup_v1.3.exe) from the SILICON CHIP
website and run it (it’s in the November
2008 downloads section). Note that
you must use version 1.3, as older or
newer versions may not be compatible.
When you run the installer, this will
copy the driver to the C:\MCHPFUSB\
PC\MCHPUSB Driver\Release folder.
Subsequently, when you first connect the USB Clock to your computer,
Windows will recognise the device as
a “Microchip Custom USB device”.
siliconchip.com.au
The “Found New Hardware” dialog
will then appear (see Fig.7) and you
should select the “No, not this time”
option and click “Next”.
At the following dialog, select “Install from a list or specific location”
and click “Next” again to bring up the
dialog shown in Fig.8. Select “Search
for the best driver in these locations”
and enable the “Include this location
in the search” box.
Now click the “Browse” button. In
the “Locate File” dialog that appears,
navigate to where the MCHPUSB files
were installed (normally it will be C:\
MCHPFUSB\PC\MCHPUSB Driver\
Release folder) and select “mchpusb.
inf”. Click “Next” and Windows will
then install the driver.
If the driver is installed correctly,
you should be able to see the “Microchip Custom USB Device” entry in
Device Manager (provided the USB
Clock is connected), as shown in Fig.9
(Control Panel -> System -> Hardware
Tab -> Device Manager tab).
Installing/using usbclock.exe
Once the driver has been installed,
you can control the USB clock using
the usbclock.exe program. The first
step is to download this program from
the SILICON CHIP website (November
2008 downloads section), unzip it and
copy it to a suitable folder (eg, create
a folder called “usbclock”).
Usbclock.exe is a simple program
that’s run from the Command Prompt
dialog (formerly known as a DOS box).
It’s simply a matter of navigating to the
November 2008 35
Fig.7: this is the dialog that appears the first time the
USB clock is connected to the PC. Select the option
shown and click the “Next” button.
Fig.8: selecting “Install from a list or specific location”
brings up this dialog. Select the options shown and click
the “Next” button. Windows then installs the driver.
Fig.9: this entry will appear in Device
Manager if the driver is installed
correctly.
folder where the program resides, then
typing usbclock to synchronise the
USB Clock with the clock on the PC.
For other functions, simply enter
usbclock x at the command prompt,
substituting the appropriate switch
for the “x”.
Table 4 shows the various command
line switches and their functions.
Among other things, you can view the
current operating settings (-i), change
the PWM duty cycle (and thus the
brightness) of the backlight (-p:X), set
the backlight timeout period (-t:X), set
the auto-backlighting on or off (-a:X)
and change the display format from
36 Silicon Chip
Fig.10: the USB clock is synchronised with your PC’s time by running the
usbclock.exe program from a command window. This screen grab shows the
output after running usbclock -i to view all the clock’s operating settings.
the default 24-hour time to 12-hour
format (-y:X).
Fig.10 shows a typical example
of the screen that appears when the
usbclock program is run.
Driving the USB Clock
There’s only one control on the front
panel of the USB Clock and that’s
pushbutton switch S1. You simply
press S1 to turn on the backlight. This
will be turned on for the duration of
the timeout period (set by running
the usbclock –t:X command) at the
set PWM duty (set by running the
usbclock –p:X command).
Pressing S1 again allows you to
scroll through the different display
modes of the clock. You can then see
the date displayed on the clock as well
as other settings. The display modes
were shown in Table 2 last month.
siliconchip.com.au
Synchronising Your PC To A Network Time Server
Fig.11: this dialog is used in WinXP
to enable your PC to synchronise
with an internet time server.
T
HE NTP (network time protocol)
is used to synchronise “networkenabled” devices (such as your PC)
with remote time-servers. Basically, a
time-server is a server computer that
derives its time from a very accurate
reference clock and distributes this
time to other computers. The most
common time reference for these
servers is a GPS clock or GPS master clock.
To ensure that your PC’s local
clock (and by extension, your USB
clock) always shows the correct time,
it’s necessary to enable NTP time
synchronisation in Windows. When
this is done, your PC will synchronise
with the selected Internet time server
once a week, although you can also
perform manual updates as well.
NTP synchronisation is enabled in
Windows XP as follows:
(1) Double-click the clock in the bottom right corner of the system tray.
(2) Click the “Internet Time” tab on the
resulting “Date and Time Properties”
dialog to bring up the dialog shown
in Fig.11.
(3) Select “Automatically synchronize
with an Internet time server”.
(4) Enter a valid NTP server domain
name into the space provided. The
After the display timeout period
expires (from the last switch press)
the display mode will revert to the
default display mode (set by running
the usbclock –z:X command). The
display timeout can be changed by
running the usbclock –d:X command.
There’s one more feature we need
siliconchip.com.au
Fig.12: if you have the firwall enabled on an ADSL or cable modem/router,
then you will have to enable outgoing UDP connections on port 123. This
screen grab shows the set-up for a Motorola SBG900 cable modem.
au.pool.ntp.org server should work
for users in Australia but you can also
select one of the default overseas
servers from the drop-down list.
Alternatively, there are many other
NTP servers available and you can
easily do an internet search for them.
A good place to start is www.pool.
ntp.org
(5) Click on the “Update Now” button to test the synchronisation. The
Windows NTP service may fail if a
firewall is blocking it, although NTP
may also fail sporadically even when
set-up correctly, due to lost packets
or handshaking timing out.
Punching through the firewall
NTP uses UDP port 123, so you
must ensure that your firewall is not
blocking outgoing traffic on this port.
If it is, NTP synchronisation will fail
to explain and that’s the auto backlighting mode. If enabled (usbclock
-a:1 or usbclock-a:2 turns it on, while
usbclock -a:0 turns it off), the unit
automatically turns the backlight on
at the set PWM duty cycle, depending
on the time of day (provided that the
USB Clock is running on USB power).
consistently and you will have to
change the firewall’s settings.
The Windows XP and Vista firewalls allow all outgoing traffic and will
work by default. By contrast, other
third-party firewalls often block out
going connections on port 123 and
will have to be modified.
Do a search on the Internet to find
the appropriate settings for your particular firewall (or check the manual).
Note that you only need to enable
outgoing UDP traffic on port 123 (not
incoming).
Similarly, if you have the firewall
enabled on your ADSL (or cable)
modem/router, then you may need
to modify its settings as well.
Fig.12 shows the settings for a Motorola SBG900 cable modem. Again,
you only need to allow outbound UDP
traffic on port 123.
If in automatic backlight mode 1,
the backlight will turn on between
6pm and 6am. This means that if you
have the USB clock connected to a
powered hub, the backlight will come
on automatically at night. By contrast,
in mode 2, it will be on all day.
The auto backlighting will not work
November 2008 37
Command
Function
Example
Result
The windows time will be synchronised
with the USB clock.
You will be able to see all the operating
settings of the USB clock on your PC. An
example screen shot is shown in Fig.10.
usbclock or usbclock -s
Synchronises the USB clock with the
local clock on your Windows PC.
usbclock
usbclock -i
View all relevant operating settings of
the USB clock.
usbclock -i
usbclock -m:X where X is the
number of one of the display
modes in Table 2.
Sets the PWM duty for the backlight.
The higher the number the brighter
the backlighting will be and the greater
the power consumption. Note that for
values below about 15%, the backlight
will not be visible.
Sets the timeout period in seconds
for the backlight. When switch S1 is
pressed the USB Clock will light the
backlight. After the time-out period
expires, the backlight dims to off.
Sets the display time-out period in seconds. When this expires, the display
reverts to the default display mode.
Set the USB Clock’s display mode for
the display time-out period. The clock
then reverts to the default display
mode.
usbclock -v:X where X is in mV
Sets the USB Clock’s reference voltage.
usbclock -p:X, where X is a
number from 0 to 100.
usbclock -t:X
usbclock -d:X
usbclock -p:80
Sets the backlight PWM duty to 80%.
usbclock -t:60
Sets the time-out period to 1 minute.
usbclock -d:120
usbclock -m:0
Sets the display time-out period to 120
seconds (2 minutes).
Sets the display mode to display the time
in HH:MM (hours, minutes) format.
usbclock -v:3300
Sets the reference voltage to 3.3V.
the USB Clock’s sense resistor
usbclock -c:X where X is in mΩ Sets
value.
usbclock -z:X where X is the
Sets the USB Clock’s default display
number of one of the display
mode (and the display mode).
modes in Table 2.
usbclock -c:1650
Sets the sense resistor reference value to
1.65Ω.
usbclock -l:X where X is in mV
between 2170 and 4500mV.
Sets the USB Clock’s low-voltage trip
point.
usbclock -l:2400
usbclock -a:X where X is either
0 (disable) or 1 (enable 6pm to
6am) or 2 (all day).
usbclock -y:X where X is either
0 for 24-hour time (default) or 1
for 12-hour time.
Sets the USB Clock’s auto backlighting
on or off.
usbclock -a:1
Sets the backlight to automatically turn on
between 6pm and 6am.
Sets the USB Clock’s time display
mode (24hr or 12hr).
usbclock -y:1
Sets the USB Clock to 12-hour time.
usbclock.exe -r
Resets the USB Clock.
usbclock -z:1
usbclock.exe -r
Making Usbclock.exe Run Automatically
The USB Clock does not synchronise its time automatically with the PC
just because it is connected to the PC
via a USB cable. To do that, you have
to run the usbclock.exe program (ie,
by typing usbclock and pressing the
Enter key at the command line).
If you wish, you can automate
this procedure by having Windows
run usbclock.exe each time the
computer boots up. This is done by
placing a shortcut to the program in
the Start-up folder, as follows:
(1) Create a shortcut to the usbclock.
exe program by right-clicking it and
dragging it to the desktop.
(2) Copy or move this shortcut to
the C:\Documents and Settings\
38 Silicon Chip
YourUserName\Start Menu\Programs\Startup folder (YourUserName is your user account name).
Once the above steps have been
completed, the usbclock.exe program will automatically run each
time Windows boots up and thus
synchronise the USB Clock to the
PC’s clock.
Note that you should also set up
your PC’s local time to synchronise
automatically with an internet time
server, to make sure that your PC’s
clock (and thus your USB Clock) is
always accurate. The way to do this
is set out in a separate panel titled
“Synchronising Your PC With A Network Time Server”.
Sets the display to show the date.
Sets the low voltage trip point to 2.4V.
If it is set too high, the backlight will be
turned off too soon.
Resets the USB Clock and all settings are
restored to default values.
Table 4: the command line switches
for the usbclock.exe host program.
The USB Clock synchronises its time
with your PC’s clock when you run
this program without any switches
and the program can also be set to run
automatically when the PC boots.
when the USB clock is running from
battery power. In that case, you will
have to turn the backlight on manually
by pressing S1.
Tweaking the charging current
The charging current depends on the
reference value for the sense resistor.
If you wish, this reference value can
be changed (to give a more accurate
charging current readout) by running
the usbclock -c:X command.
The default value is 1.65Ω which
is the nominal resistance of the two
siliconchip.com.au
How The Circuit Conserves Power
One important feature of the PIC
18F4550 is its support for low-power
managed modes. Although the use of
CMOS ICs is important for minimising power consumption, much of the
power conservation is achieved in
the firmware
Basically, the microcontroller will
respond to interrupts and then go into
idle mode, resulting in very low power
consumption. In idle mode, peripherals like the screen refresh timer and
the timekeeping timer still operate but
the CPU is switched off. An interrupt
generated by the peripheral will wake
the CPU. The interrupt will then be
serviced, after which the CPU reverts
to idle mode again.
In normal operation without the
backlighting, the current consumption
is less than 1mA. This means that the
clock should be able to keep running
from battery power for at least a few
weeks before the batteries need
recharging.
By contrast, the backlight draws
around 200mA at 100% duty-cycle.
This reduces to around 100mA at
50% duty-cycle and 80mA at 30%
duty-cycle.
In battery mode, the backlight is
turned on by briefly pressing S1. It will
then stay on for the duration of the timeout period (this can be set by running
the usbclock.exe program using the -t
option, as explained below).
After the period expires, the backlight quickly dims down and turns off.
Note that the backlight duty cycle is
also set by running the usbclock.
exe program, this time using the -p
option.
In addition, as mentioned previously, the microcontroller automatically
reduces the duty cycle if it detects
that the supply voltage rail is buckling
parallel 3.3Ω resistors on the PC board.
If the resistors don’t measure 1.65Ω,
you can tweak the reference value to
match their actual value.
Normally, however, you don’t need
to worry about this unless you’re very
fussy about accurate charging current
readings.
Similarly, the supply voltage reading depends on the accuracy of the
3.3V reference voltage. In practice
siliconchip.com.au
under the load (this will only happen
when the backlight is used when running from battery power).
Basically, the microcontroller sets a
low-voltage trip point, with an interrupt
occurring if the supply voltage drops
below this point when S1 is pressed.
When that happens, the microcontroller immediately reduces the PWM
duty cycle of the backlight.
As a result, if the batteries are sufficiently discharged, the backlight will
not turn on when S1 is pressed.
Going one step further, if the microcontroller detects that the supply
voltage is below the trip point when
the backlight is not being driven (ie,
0% duty-cycle), then the firmware will
go into an extended power conservation mode (extra low power). In this
mode, the main priority is to keep
the real time clock updated, while
the display will show “Lo” to indicate
a low battery.
The firmware will subsequently
exit this mode when the USB clock
is connected to a PC and the battery
begins charging again.
If the supply voltage drops even
lower than this, the firmware assumes that power is soon to be lost
or that the battery is too discharged
to provide power. In this case, the
firmware instructs the microcontroller
to go to sleep.
In this state, the CPU and all
peripherals are turned off, markedly
reducing the power consumption to
just microamps.
This prevents the battery from
discharging even further.
Of course, at this point, the timekeeping fails. However, it is subsequently synchronised the next time
the USB clock is connected to the
PC (provided the PC is operating).
though, this may be slightly off due
to manufacturing variations of IC1. It
should be close to 3.3V and so the default value of 3.3V should be adequate
in most cases.
If necessary, you can change the
reference voltage (using the usbclock
-v:X command) to increase the accuracy of the voltage reading. It should
match the voltage at pin 19 of IC1, as
SC
measured using a voltmeter.
JOIN THE TECHNOLOGY
AGE NOW
with
PICAXE
Developed as a teaching tool,
the PICAXE is a low-cost “brain”
for almost any project
Easy to use and understand,
professionals & hobbyists can
be productive within minutes.
Free software development
system and low-cost in-circuit
programming.
Variety of hardware, project
boards and kits to suit your
application.
Digital, analog, RS232,
1-Wire™, SPI and I2C.
PC connectivity.
Applications include:
Datalogging
Robotics
Measurement & instruments
Motor & lighting control
Farming & agriculture
Internet server
Wireless links
Colour sensing
Fun games
Distributed in Australia by
Microzed Computers
Pty Limited
Phone 1300 735 420
Fax 1300 735 421
www.microzed.com.au
November 2008 39
|