Start
Intelligent
Architechture
Putting
the Pieces Together
Programming
Brains
Building
and Interface
Education
Possible
Sources
& PDF
PUTTING THE PIECES
TOGETHER
Everything sounds good
in theory. But what about putting this smart device
in place?
In addition to about
$20 worth of garden-variety sprinkler components,
I used an AT89C2051 microcontroller. This 20-pin 8051
derivative from Atmel includes 2 KB of program space.
I installed an RS-232
transceiver to provide external communications. The
software handles a real-time clock/calendar and an
alarm clock that sequences throughout the program
and manages the watering start times.
The emMicro module provides
a remote interface for manually programming the system
and customizing watering schedules. One of the beauties
of the remote interface is that it can be easier to
use than the physical interface on the device itself.
Some sprinkler controls seem to require a college
course just to get your lawn watered at the right
time.
A serial EEPROM device
stores interface documents and program times in a
nonvolatile array to ensure that the device retains
essential information if it loses power. A 9-V battery
serves as a power backup to keep the clock running
during a power failure.
All you need onboard
is the microcontroller and the hardware it needs to
turn on 24-V AC devices. I used a 74HC138 decoder
so eight valves could be controlled using three lines
from the microcontroller. The schematic provides for
an additional decoder that gives control for up to
16 valves (see Figure
2).
Figure 3 shows the programming
logic. As I mentioned, the real-time clock/calendar
was implemented completely in software, and it uses
the microcontrollers 18,432-MHz crystal as its
time base.
|

Figure 3The programming logic
centers around the main calling loop, which
receives information from and transmits
information to other controlling elements
of the device.
|
The clock has two main
software componentsan interrupt-service routine
(ISR) and the clock routine. The 8051s hardware
timer 0 executes the ISR once every 10 ms. The ISR
must reset the hardware timer for the next interrupt
and account for interrupt latency, which would cause
the clock to drift off.
Unfortunately, the 8051
architecture doesnt support a 16-bit auto-reload
mode, which would make it unnecessary to correct for
interrupt latency. This situation isnt hard
to correct.
Because T0LOW (an 8051
special function) is small (zero), theres no
real possibility of a rollover when the addition is
done and, therefore, no reason to account for a carry
into the upper portion of the counter. The most important
thing the ISR does is set the bit variable called
temMSbit, which tells the real-time clock routine
that a time tick occurred.
The clock routine is
responsible for counting the ticks created by the
ISR. Basically, it just counts hours, minutes, seconds,
and days, and it sets a few bits here and there to
tell other routines when to operate.
For instance, once every
minute, the bit variable CheckWater is set. This way,
the alarm-clock routine knows to check all the scheduled
watering times to see if any are supposed to begin.
There are two day counters.
One is used for watering schedules based on the day
of the week (Monday through Friday) and the other
handles periodic watering (every other day, every
third day, etc.).
The counting routine
is called by the main calling loop in a round-robin
multitasking methodology. It is called much more frequently
than the 10-ms rate of the timer ISR, so it is sure
not to miss a tick.
Whenever the ISR sets
temMSbit, the clock routine increments its clock registers
as necessary. It then clears temMSbit so it wont
respond more than once to each tick.