EE 552
The Electronic Gardener
Final Report
November 23, 1998
Mark Kudryk (301594)
Kim Ellis (336098)
The Electronic Gardener is a device which is programmed by the human gardener to maintain a set moisture level or to set a one time watering per day. The user interface consists of an LCD screen and four user push buttons. The user buttons are used to navigate through a few menus displayed on the LCD screen to set the features as desired.
The Altera Max+Plus II CAD tool was utilized to design the VHDL code to program into the Altera EPF10K20 FPGA. The complete design was simulated according to design specifications in the CAD tools prior to programming the FPGA device. The university program demonstration board was put to use in the prototype for the Electronic Gardener.
The external hardware was built on a separate board and connected to the demonstration board using a 60 pin connector cable. The complete hardware comprised of an LCD screen, an EPROM, two LEDs, four push buttons, four resistors, and four capacitors. All hardware was powered off of the Altera board using the positive five volt and ground connections.
User Features:
FPGA (Software) Components/Description
Table of Contents
Project Description
The Electronic Gardener is a control device that can be programmed to care for a plant according to the specifications of the human gardener. The user will be able to specify a single watering period length each day and the soil moisture level to be maintained.
The Electronic Gardener was implemented through six functional modules: system clock divider, device controller, menu state machine, 24 hour clock, message decoder and an LCD driver. The internal relationship between these modules is illustrated in figure 1. The reset signal is not shown, but is connected to each module.
Figure 1 - Functional Diagram
The device controller is responsible for controlling the signal that would be used with external watering hardware such as a watering valve. Decisions are made based on the user specified setting. If the timed watering is active, the device controller compares the user entered watering start and end times from the menu state machine with the 24 hour clock, and uses the results to decide whether to turn the watering control on or not. If the maintain moisture is a value other than zero, the off state, then the user set maintain moisture level is compared with the actual reading would be an external moisture meter, in this case a set of 8 dip switches. The maintain moisture feature operates on a cycle by turning the control signal on for thirty seconds, then off for thirty seconds before re-comparing the values. This method was adopted to prevent the soil from becoming over-saturated since an accurate measurement can not be obtained immediately. Both options can operate either individually or simultaneously. When operating simultaneously, the maintain moisture feature has priority in order to keep the soil moisture level from exceeding the user defined maximum level. Control from the timed watering is disabled when the set moisture level has been surpassed. An indicator light is used to notify the human gardener than the soil is being watered. The light is continuously active when the timed watering feature is watering the soil. The indicator is also continuously active when the maintain moisture feature is watering. It does not cycle like the maintain moisture control, instead it remains active while the watering is cycling and becomes inactive when soil moisture level reaches or exceeds the user set level.
The 24 hour clock provides a second pulse, minute and hour count to the system. The minute and hour can be set by the user so as to reflect the actual current time.
The LCD Driver is responsible for initializing and writing the Electronic Gardener's UI Screens to the Emerging Display EC16220 16x2 character LCD display. After initialization, it notify the Message Decoder that it is ready to accept a new UI screen to be displayed. When the Message Decoder replies that it too is ready with a new message, the LCD Driver will request byte-by-byte 32 ASCII bytes from the Message Decoder which will get displayed on the LCD screen.
The structure of the driver is very simple. The data path from the Message Decoder input to the LCD screen output is broken only by a multiplexor, which allows the LCD driver's state machine to insert initialization instructions into the data path to get written to the LCD screen.
The Menu State Machine is the central module of the Electronic Gardener. It accepts from the user, via four push-buttons, data which will set the operating parameters of the Electronic Gardener. It will communicate to the user through an LCD screen and two LED which will indicate when external components are functioning or certain options have been activated; it will also communicate the user inputted data to the device controller which will control the external devices according to the user inputted operating parameters.
The Electronic Gardener consists of five separate UI screens. The Menu State Machine has been constructed around these five screens. One screen corresponds to one state; when some screens require static and variable messages to be combined, the state has been split into two: one to handle the writing of the message to the LCD screen, the other to receive data from the user.
The Message Decoder is responsible for assembling static and variable UI data into single UI screen that will be sent onto the LCD Driver. When the Menu State Machine requests that a screen be displayed, it will provide to the Message Decoder the base address where the static message resides in memory. The Message Decoder will then query the EPROM for the static UI message byte-by-byte, after each byte request from the LCD driver.
Most characters of all five UI screens are static. Some screens require variables to be inserted into them. The Message Decoder will know that the next character or two to be displayed is a variable when the ASCII code for '?' is encountered. When '?' is encountered, the Message Decoder will request the Menu State Machine for the variable. The variable provided will be a single byte in binary form. The Message Decoder will convert this binary byte into two ASCII byte, corresponding to a high and low byte. When a '?' is detected, no byte will be provided to the LCD driver.
When the next byte or two read from the EPROM will either be a '%' or '!' character. When the '%' is encountered, the high ASCII byte will be inserted onto the data path and written to the LCD driver, and when the '!' is encountered, the low ASCII byte will be inserted.
The physical layout of the Message Decoder is shown in the figure below.
Figure 2 : Message Decoder Layout
The hardware consists of one 16 character by 2 line LCD screen used for the user interface and four user buttons used to navigate through the menus. One LED is used to display the watering status to the user. The moisture probe and water valve was an optional external hardware component. For the prototype, the input from the probe was replaced by eight dip switches and the water valve by an LED to indicate if it would be on or not.
An EPROM was used in the Electronic Gardener as a static memory element. It was preprogrammed with the Electronic Gardener's user interface messages. The message decoder used the static messages along with the dynamic system variables to code the user messages displayed on the LCD screen.
The user buttons are connected using a simple decaying RC circuit to maintain the signal for a brief time beyond the length of the user input. A 300ns delay was produced using a 10kW resistor and a 30nF capacitor. The layout is the following.
Figure 3 : User Push Button Circuit
The external hardware interface is illustrated below.
Figure 4 - Hardware Interface
An over view of the design hierarchy is given below. Included is all six functional components interconnecting within the "chip" (enchilada) scope. Four of the six modules are comprised of a number of sub-modules.
Figure 5 - Design Hierarchy
The following is the separate resource requirements of the internal part of the Electronic Gardener, which will be based in the FPGA. As well as a comparison with the integrated system. The requirements are measured in turns of the number of logic cells needed by each functional unit. A listing of the minimum clock period and maximum clock frequency is also included in table 1.
Functional Unit |
Final Usage |
Clock Period |
Clock Freq. |
Device Controller |
121 |
27.5ns |
36.36 MHz |
24 Hour Clock |
72 |
33.9ns |
29.49 MHz |
Menu State Machine |
488 |
37.1ns |
26.59 MHz |
Message Decoder |
140 |
18.0ns |
55.55 MHz |
LCD Driver |
170 |
40.4ns |
24.75 MHz |
Internal Clock |
21 |
19.0ns |
52.63 MHz |
TOTAL |
1012 |
40.4ns min. |
24.75 MHz max. |
Enchilada |
988 |
64.6ns min. |
15.47 MHz max. |
Table 1.
A system wide clock frequency of 10 kHz has been chosen to allow the LCD to process each instruction within one clock cycle. This eliminates the need for the LCD driver to read back from the LCD to check if the LCD is ready for another operation, thus reducing the complexity of the driver.
During the development of the Electronic Gardener, several problems were encountered. The more interesting problems are described below along with there solutions.
1. Unavailability of Tri-state buses: As the Altera FPGA Flex10K20 does not permit tri-state buses, it was not possible to read and write from the LCD screen. In most cases a driver would only write to the LCD, but would read from it to check if it was available for use. To solve this problem, the system-wide clock frequency was reduced to 10 kHz from a maximum possible frequency of approximately 26.6 MHz. This frequency was chosen as all writes to the LCD are guaranteed by the manufacturer to complete execution within a certain period of time. The most common time period was 37 m s. Selection of a 10 kHz clock results in a period of 100 m s, which is more than enough time for a write to finish. Therefore, it is assumed that at the start of each clock cycle that LCD driver is ready for a new instruction/write.
2. Combining Static and Variable Messages: The UI combines static and variable messages. The static messages are retrieved from the external EPROM, the variable data from the Menu State Machine, and combined by the Message Decoder. The Message decoder knows when a variable data is required when the character '?' is retrieved from the EPROM. This character is blocked from being written to the LCD, and instead a request is made for the variable data to be sent from the Menu State Machine. This variable will be in a single binary byte format, and will be transformed into two ASCII bytes. The next characters will either be a '&' or a '!'. When the former is encounter, the Message Decoder will write the high ASCII byte to the LCD, and the low ASCII byte when the later is encounter.
3. Complex UI - Originally, the Electronic Gardener was designed with a four-line, 15 menu UI, and offered watering and heating features. Due to the limitation of a single FLEX10K20 chip, after implementing only a single menu, the Menu State Machine uses up nearly 50% of its allocated logic cell resources. This resulted in a reduction in size of the screen from 4 lines to 2, the number of separate menu screens from 15 to 5, and the elimination of the heating feature completely.
4. Hour and Minute Comparisons - The device controller is comprised of multiple sub-modules. One module compares the current time with the set watering feature start and end time. A simple hour and minute comparison routine would not handle the hour wrapping around nor the minute wrapping around. A multiple comparison routine had to be implemented to handle this phenomenon depending on the relation of the end time to the start time. Three separate states exist: when both the end time hour and minutes wrap around, or just the end time minutes wrap around or neither. Each of these conditions were tested for, and then handed in the appropriate manner.
5. Debugging - When implementing the Electronic Gardener on a FLEX10K20 chip, there was a lack of tools to aid us in debugging the hardware/software inter-operations. The method employed was to run on the Altera UP1 development board sub-sets of the system-circuit and debug at this more management level.
The test cases used to verify the correct operation of the Electronic Gardener were based on the test cases used to verify the individual modules. These system-wide tests are listed below, followed by the test cases used to simulate the individual modules. The output waveforms for selected system-wide tests are included in Appendix B.
The Device Controller is responsible for controlling the operation of the watering device. Three possible operating states may occur within the Device Controller during operation: maintain moisture may be active, set watering time may be active, or both. Priority is given to the maintain moisture level control when both features are active. Each feature is responsible for comparing set values to the current values and performing certain functions depending on the result. Performance to the following tests will verify the correct operation of the Device Controller.
Maintain Moisture Level:
Session Watering:
Combined Operation of Maintaining Set Level and Timed Watering: (Maintain Moisture Level has precedence over the Timed Watering)
The 24 Hour Clock provides the system with a second pulse, minute and hour count. The time is in 24 hour format. It is also possible for the user to set the time to whatever they wish (hours 0-23, minutes 0-59). The successful completion of the following tests by the 24 Hour Clock will verify is correct operation.
The Menu State Machine is responsible for accepting inputs from the user via four buttons, displaying output to the user via an LCD screen, and passing operating parameters set by the user to the device controller. The number of states approximately corresponds to the number of different screens in the UI (some have two states due to their complexity). Each state is responsible for: initiating the display of the correct UI screen, including any variables that screen may require; accepting inputs from the user corresponding to one of four possible "softkeys"; and successfully accepting system operating parameters from the user and sending them to the appropriate modules for their use. The successful completion of the following tests by the Menu State Machine will verify is correct operation.
The Message Decoder is responsible for accepting a base address from the Menu State Machine which corresponds to a preset UI Screen, which will be stored in an EEPROM. Each byte of the message will be retrieved and passed onto the LCD driver when requested by the LCD driver. It will also be responsible for detecting special characters in the UI Screen which indicate that those characters need to be replaced by variables obtained from the Menu State Machine. The variables received from the Menu State Machine will be in an eight-bit binary format, and will be converted into two ASCII bytes. The successful completion of the following tests by the Message Decoder will verify is correct operation.
The LCD Driver is responsible for displaying a UI Screen onto the 16 characters by two line screen. Each Screen therefore is 32 characters long, the first 16 being displayed on the first line, the later 16 on the second. The LCD Driver is responsible for correctly initializing the LCD screen, and requesting from the Message Decoder for the UI screen contents. The successful completion of the following tests by the LCD Driver will verify is correct operation.
The following pages include the VHDL code for all of the Electronic Gardener's high level modules, plus all supporting modules.
High Level Modules
Supporting Modules
Simulations for the system wide tests as explained in the Test Cases and Simulation section were attached to the Formal Written Report.