For our CPE 133 class at Cal Poly we were told to create a VHDL/Basys 3 project that would help the environment and was simple enough that we could implement it with our new knowledge of digital design. The idea behind our project that, in general, people don't think about where they throw their trash. We decided to create a machine that would force people to put thought into where they put their trash. Our trash sorter takes user input through three switches, each representing either trash, recycling or compost. Once the user has selected they type of waste(s) they would like to dispose of they press a button. This button will cause the corresponding container lids to open. The machine also used the display on the Basys 3 to indicate if any of the lids are currently open. When the button is released the lids will then close again so that the machine will be ready for the next user.
Step 1: Materials
The materials required for this project are:
Basys 3 board
Computer with Vivado installed
3 feet copper wire
Soldering iron and solder
*because servos are expensive and we are college students we substituted a 68 ohm resistor and LED for each servo as a prototype (code functions the same way)
Step 2: Beginning Coding
There is a lot of code to be written for this project. We will be using VHDL code written in Vivado. To start we will want to create a new project. First you will name the project and specify the project type. Be sure to select the same settings as pictured. When you have gotten to the sources screen you will want to add six sources named "top", "flip_flop", "segments", "servo_top", "servo_sig" and "clk_div". Be sure to select VHDL for the language of each file, not Verilog. On the constraints screen you should create one file for the pin assignment. The name of this file is not important. You will then be prompted to select the board you will be using. Make sure that you select the correct one. Reference photos for correct selection. The last step will ask you to specify the inputs and outputs of each source file. This step can be coded later so click next.
Step 3: Constraints File
In this step we will write the constraints file. This tells Vivado which pins will send/receive which signals from the circuitry. We will need the clock, three switches, the seven segment display (seven cathodes and four anodes), a button and the three output PMOD pins that the servo/LED will use. Reference photos for how the code should look.
Step 4: Flip Flop File
The next file we will be writing is the flip_flip source file. This will be a VHDL implementation of a D flip flop. In other words it will only pass it's input to the output on the rising edge of the clock signal and when the button is pressed. It will take clock, D and the button as an input and will output Q. reference the photos for code. The purpose of this file is to allow the bins to open only when the button is pressed rather than directly opening each time the switch is flipped and only closing when the switch is flipped back.
Step 5: Segments File
The next file to be written is the segments file. This will take the button as in input and output values for the seven cathodes and four anodes of the Basys 3's seven segment display. This file causes the seven segment display to show a "C" when the bins are closed and a "O" when the bins are open. For code see attached photo.
Step 6: Clock Divider File
Servos function by taking a PWM signal with a frequency of 64k Hz while the clock built into the Basys 3 functions at 50M Hz. The clock divider file will convert the default clock to a friendly frequency for the servo. The file will take the clock and a reset signal as an input and will output a new clock signal. See the photo attached for code.
Step 7: Servo Signal File
The servo signal file will take a clock input, a reset input and a desired position input. It will output a PWM signal that will drive the servo to the desired position. This file uses the clock signal created in the last file to create a PWM signal for the servo with different duty cycles depending on the position desired. This allows us to turn the servos that control the lids of the garbage bins. See the attached photo for code.
Step 8: Servo Top File
The purpose of this file is to compile the last two files into a functional servo driver. It will take a clock, a reset and a position as an input an will output the servo PWM signal. It will use both the clock divider and the servo signal file as components and will include an internal clock signal to pass the modified clock from the clock divider to the servo signal file. See photos at
Step 9: Top File
This is the most important file of the project as it wraps everything we've created together. It will take the button, the three switches and the clock as inputs. It will give the seven cathodes, the four anodes and the three servo/LED signals as outputs. It will use the flip flop, segments and servo_top files as components and will have an internal switch and internal servo signal.
Step 10: Testing in Vivado
Run Synthesis, implementation and write bitsream in Vivado. If you encounter any error messages find the error location and then compare to the given code. Work through any errors until all of these runs finish successfully.
Step 11: Building Hardware Intro
In this step you will create the LED hardware we used in our prototype. If using servos the project should be ready to go as long as the correct pins are used. If using LEDs follow the steps below.
Step 12: Prep
Cut the wire into six even pieces. Strip the ends of each piece of wire enough so soldering can occur. Separate LEDs, resistors and wires into three groups. Heat up soldering iron.
Step 13: Soldering
Solder each of the 68 ohm resistors to the negative side of their corresponding LED. Solder a wire onto the positive side of the LED and another wire onto the side of the resistor not soldered to the led. You should have three of the LED contraptions pictured above.
Step 14: Finale
Insert each positive wire into the corresponding PMOD pin and each negative into a ground PMOD pin. Optionally add cardboard bins to represent trash bins and hide your soldering mess. Once the wires are correctly plugged in and the code is properly uploaded to the board without errors the machine should function as intended. If anything is going wrong return to previous steps to troubleshoot. Have fun with your new "trash sorter".