Introduction: Water Tracker Device
Background
According to the United Nations, the world population is expected to increase from 6.1 billion to 9.3 billion from the year 2000 to 2050. This means that in order for the global water footprint to not increase over the coming decades, the average water footprint per capita will have to decrease from ~365,878 gallons in 2000 to ~240,396 gallons in 2050.
In this project, the Basys3 board is used as a tool for individuals to track their daily water usage relative to the United Nations’ 2050 per capita goals. Our system will allow a user to select from the most common home activities that use the most water and track the amount of water they are using throughout their day. These activities include, toilet flushing, bath and shower, laundry, dish washing, and the bathroom sink. For activities that use a finite amount of water the user will confirm the use and the amount will be subtracted from their daily amount. For activities that are dependent on time, the user will be asked to enter a time they wish to perform the activity, confirm the amount of water usage, and start a timer for that activity, and the amount will be subtracted from their daily amount.
Using this device, we hope that the user will become more conscientious of their responsibility over their water consumption and will have an effective tool to track and reduce their use in line with the United Nation’s goals.
Below we’ve listed step by step instructions of how to create this device on a Basys3 board; we hope your find our instructions helpful and that you enjoy the creation of this project.
By: Jonathan, Kyle, Sabrina, Marco
California Polytechnic State University San Luis Obispo
Step 1: Materials
Hardware
1. Basys 3 FPGA Board
2. Arduino Uno
3. Breadboard
4. Jumper Cables
5. Display
6. Speaker
Software
1. Vivado Design Suite from Xilinx
Step 2: Understanding the Design
The Black Box diagram and the Finite State Machine are shown above.
Black Box Diagram
This is our black box diagram which is made up of the main module called water_tracker and is useful in seeing how the overall circuit works. There are various components and, therefore, it is important to get a good idea of the design of our circuit. The BTN and switches are the inputs that sends the voltage signal in the Basys 3 board to the to the Display component as well as the seven segment display.
Finite State Machine
We integrate programmable memory for storing settings to time a user’s activities, to select a time for the timer, and to track the amount of water a user is using relative to the total daily allotted amount. We integrate combinational logic when subtracting the used amount from the user’s current total, selective signals when choosing a user’s activity, and sequential logic for determining whether a user needs a timer or has a estimated water usage.
Step 3: Overview
Using the switches, the user will be able to toggle through various activities that use the most water at home, including toilet flushing, bath and shower, laundry, dish washing, and bathroom sink. For activities that have consistent water usage (i.e. toilet flushing), the user can press a button to see the amount of gallons they would use and its percentage from the daily amount. A selection of the center button will subtract this value from their allotted daily total. For activities in which the water usage is dependent on the time of use (i.e. showering), the user can use the buttons to enter the amount of minutes they wish to run for, be displayed the amount and percentage of their activity, and confirm the use. If selected, the timer will begin and a buzzer will ring at the end of their period.
In order to track one’s daily water use, we use the LEDs as a visual representation of the percentage of water a user can still use within the day. When all LEDs are on, the user has used no water. The LEDs are divided into 16 equal percentages and turn off as the user uses more water. When all lights have been used, the display will tell the user to stop all activities and the alarm will ring. The user will always have a button to restart the day and a button to display their current percentage.
With this intention, an 8-bit switch input and 5-bit button input provided on the Basys3 board are used. Our on-board outputs will include the 15-bit LED displays. Our off-board outputs will include a display, alarm, and all associated connection components between the outputs and the Basys3 board. The following are the components used in our black box diagram which were then implemented into Vivado as separate VHDL files.
- Water_tracker
- Calc
- Task 5
- Sub
Step 4: Water_tracker
Inputs
Restart - This is the button that will restart the counter.
SW - This is a three bit bus that will control the activities based on the switches on the Basys 3 board.
FLUSH - This button is pressed whenever the toilet activity is chosen which, when pressed, calculates the
amount of water used every flush.
CLK - This is the clock that controls when the system changes state.
up_btn - This is the button that enables the clock to count up incrementally.
show_btn - This is the button that allows the user to display their current amount of water.
Outputs
calc_sig_out - This output passes the calculated value coming from the inputs and passes it to the pins of the
Arduino board.
segments - This output of Task 5 passes the counter values onto the seven segment display on the Basys 3
board.
an - This output controls the anodes of the seven-segment display, controlling which segments are on.
The water_tracker is the main driver file and essentially controls which activity you want to choose on the Basys 3 board by using the switches as an input, which then displays the activity name on the display board connected to the Arduino. The buttons are also used physically on the Basys 3 board in order to control the counter. The inputs Restart, SW, and FLUSH all are connected to the Calc module, which provide the information that is calculated and passed on to the display and Task 5 module. The inputs up_btn and shw_btn are both connected to Task 5 as inputs, which are then passed on to the seven-segment display and anode output.
Step 5: Calcs
The Calcs module controls all calculations with the user’s daily amount of water. To understand the code, it is important to note that the board needs to track a current amount of water throughout the day, subtract relative to the activity, hold that value, and be able to restart the current amount when the day is finished or when the user deems fit.
Calcs contains the module Sub, which takes in two inputs (first and second), subtracts the values from each other and outputs the result to calc_out. In order to track the current amount of water, the output of Sub is wired back to a mux that connects back to the first input. A mux is used so that when restart_btn is activated, the mux will pass the original daily amount to first and pass 0 to second, ultimately, restarting the current value.
During normal use, the user is able to choose between time-dependent and time-independent activities. Thus, Calcs uses a series of muxes so that the user can specify their activity and confirm its use. For example, for a time-dependent activity, when its switch is activated and the counter is activated, the activity’s water usage value gets passed to be subtracted from the current amount every second the activity is performed. Alternatively, for a time-independent activity, when its switch is activated and the activation button has been pressed, the activity’s water usage value gets subtracted once.
By default, the current value continues to cycle through, thus being held, and gets subtracted by 0 so that its value ceases to change until the next activity has been performed.
Step 6: Task 5
The Task 5 module is composed up of a counter, seven segment display driver, and a clock divider. The function of this module is to act as a counter for all time-dependent activities. Besides acting as the clock for our project the Task 5 module handled a large portion of the encoding needed for the displays. The seven segment driver, sseg_dec, has all the logic needed to encode the 14 bit binary number onto the seven segment display on the Basys board. The conversion logic required to be implemented for correct output values of time. Essentially the counter is made of 14 d flip flops and combinational logic in a cascaded configuration. This way, the enabled the output is able to count up. Contained inside the counter file are flip flops and combinational logic. These flip flops are are looped a certain way so that it is able to count up. Contained in the Task 5 module is the clk_div2, or the clock divider module. The clk_div2 module is used to slow down the clock speed. This is necessary since the Basys 3 board operates at 100MHz and since our counter circuit is dependent of the rising clock edge, the speed we wanted to have the counter count at the closest possible speed to real time possible.
The inputs contained in Task 5 are Clock, calc_in,EN_BTN, and UP_BTN. UP_BTN is connected to the counter module, which controls the counter. The EN_BTN controls what is shown and displayed on the seven-segments themselves. The CLK is connected to the sseg_dec module and to the clk_div2 file as well and sent back to the counter file.
The outputs contained in Task 5 are count_info, segments, and DIS_EN. Both segments and DIS_EN are displayed directly through the seven segment display and the display connected to the Arduino board respectively.
Step 7: Sub
Sub subtracts the two 14-bit binary inputs (first and second) from each other. In order to subtract, we must use the concept of radix complement to perform the appropriate operation using a 14-bit full-adder.
To use a full-adder to subtract, the first input gets passed directly to the adder. The second input gets passed to twos_comp. Here the input is inverted and added to one using its own 14-bit full adder. Now, the number has successfully been converted to its complement and can then be passed to the second input of the 14-bit full-adder of Sub. Since we will get a carry-out, we must ignore its value to maintain the uses of 14-bits in our system and pass the rest of the sum to sub_out where it will be used by the rest of the system.
Step 8: Arduino Code
The Arduino code was set up to first read 14 bits sent from the basys to pins 26-40. From there each bit was stored in ‘val_array’. Using the array in a For loop the program converted the number from binary to decimal and then displayed it on the LCD board to indicate the gallons of water left for the day. As different values were sent to the Arduino they were continuously subtracting from the ‘CurrentGal’ variable, which started at 609 gallons. To get the buzzer to sound we used an If statement along with a For loop. The buzzer was set to go off once the ‘CurrentGal’ variable reached zero. To restart the process the basys would send a bit, either High or Low, to pin 41 on the board. Using an If statement, if the signal was High, the ‘CurrentGal’ would reset back to 609 gallons and the LCD would read “RESET” for a short period of time.
Attachments
Step 9: Assembly
For the assembly of the arduino we used the analog inputs 26-41. These pins were connected to the JB and JC ports on the basys board. The LCD display was connected to six Arduino pins, which were set to be outputs, as well as 5V and GND connection to power it. For the speaker we connected one end to one of the digital pins on the Arduino, and the other to ground.
Step 10: Programming the Board
To try this for yourself!
Included are all of the VHD files you will be needing to re-create this project on Vivado.
Have fun and we hope you enjoy the creation of this project as much as we did.