December
2004, Issue 173
H8/38024F-Based
Programmable Timer
HARDWARE
Photo
2 shows the modified demo board. Note the battery holder
located where the power supply components used to be
and the piezo speaker just below it. An array of push
buttons is located in the prototyping area at the bottom.
The schematic is shown in Figure 2 (page 16).
|

(Click
here to enlarge)
|
Photo
2—The hardware started out as a demo board. I snipped off everything that wasn’t needed
and then made a few additions. The battery is at
the top, with the piezo speaker just below it. The
buttons fit comfortably in the prototyping area
at the bottom. |
|

(Click
here to enlarge)
|
Figure
2—The H8/38024F contains almost everything needed
for the timer. I was able to take advantage of the
pull-up resistors on ports 1 and 3. There were just
enough pins for all the switches without having
to multiplex them. The optional serial port circuitry
doesn’t use any power unless it’s enabled with the
Boot switch. |
The
H8/38024F is a good fit for this application. It has
a built-in LCD controller/driver with just enough segment
pins to drive a four-digit display in Static mode, which
allows it to work over a wider voltage range than with
multiplexed drive. The H8 is set to output the same
signal on all four LCD common outputs. Two of these
drive the display, which uses a pair of pins connected
to a single backplane. The H8’s low-frequency oscillator
allows it to keep time and drive the display while using
a miniscule amount of power. There are plenty of I/O
pins allowing the push buttons to be connected without
multiplexing them. This saves time and power during
button scanning.
The
10-bit A/D converter is used to sense battery voltage
in an unconventional way. Because its reference voltage
is internally connected to the supply, and the supply
is connected directly to the battery without any regulation,
the ADC’s reference will rise and fall with the battery
voltage. I used a 1.235-V reference diode to feed one
of the analog inputs, so the converted value will be
the ratio between the diode voltage and the battery
voltage. Thus, as the battery drops, the converted value
will increase. An output port controls power to the
reference diode. Even though it consumes only 10 µA,
I didn’t want this extra drain to run continuously.
Each
of the switches connects to a port with an internal
pull-up resistor—there are just enough of them. The
switches’ common terminals are controlled by an output
port, which I enable only when they’re being read. The
exception is the On button, which has to be active when
the MCU is in Standby mode. When the H8 enters Standby
mode, all of its port drivers are disabled, even though
the pull-up resistors are still active. I took advantage
of the IRQ0 input to wake up the MCU. The datasheet
states that either it or IRQ1 should work, but I was
unable to get any response from IRQ1 in Standby mode.
It worked fine in Sub-Sleep mode, so I used it for the
Start/Stop button instead.
One
of the PWM outputs drives a piezo speaker element. By
setting the PWM to a 50% duty cycle, I got a square
wave output at the conversion rate. This allows the
piezo to generate a single frequency beep, which is
all that’s needed. I originally wanted to use both PWM
outputs to drive the piezo differentially and effectively
double the drive voltage, but I couldn’t find a way
to synchronize the two channels. It turned out to be
unnecessary, because the beep ended up loud enough even
with a single-ended drive.
I
wanted the timer to operate on a single lithium coin
cell, which is typically rated for discharge down to
2 V at room temperature. The MCU won’t run that low,
but it will work down to 2.7 V, which takes advantage
of about 90% of the cell’s capacity. The maximum cell
voltage is around 3.3 V, so no voltage regulator is
needed. I used a 2.7-V reset supervisor (U2) to keep
the MCU honest, and set the low battery threshold to
2.8 V for plenty of warning.
As
I selected U2, I discovered the interesting fact that
some parts have power consumption specs that vary with
the package type. For example, the Fairchild FM809R
uses only 2 µA in the SOT-23 package, but needs 6 µA
in an SC-70 for an otherwise identical part. The Microchip
TCM809R uses 17 µA in an SOT-23, but the SC-70 needs
only 9 µA. I avoided the issue by using a Seiko S-80927CL,
which is rated at 1.2 µA in any package. It doesn’t
have the built-in time delay that the others do, but
the MCU has its own 131,072-cycle (approximately 26
ms) reset timer that does the job.
When
the timer is awake, it’s almost always in Sub-Sleep
or Sub-Active modes, measured at 10 and 22 µA, respectively.
When asleep, it’s in Standby mode drawing only 5 µA.
Occasional short bursts of Active mode (each time a
button is pressed or released) use little enough power
to be ignored. I chose a CR2032 cell because it’s commonly
available and has a rated capacity of 220 mAh. This
allows for more than a full year of continuous operation.
It can operate for several years if it’s used infrequently.
The
demo board includes a flash memory MCU, which allows
for instant reprogramming and easy debugging using a
serial port. I used what was once the demo board’s power
switch to control power to a 3-V RS-232 converter so
it would only draw power when needed. The switch also
puts the MCU in Boot mode, thereby allowing the flash
memory programming routine to be downloaded into RAM
and executed. I ended up using a power supply when downloading,
because the battery couldn’t run the serial port for
very long.