Model of a Universal Off Switch

Introduction: Model of a Universal Off Switch

Are you tired of checking that all the lights in your house are off before you go to sleep? Do you wish you could turn off every light at once without any fuss? In order to save power and time, we decided to create a system that could theoretically shut an entire house down all at once.

We modeled a proof of this concept using a couple of LED's and a basys 3 circuit board, and created a design that would deactivate all of the LED's with the push of a button. This model could be applied towards an actual home lighting system as well, although it would require more complicated wiring and modifications to the given VHDL files.

Step 1: Import the Given VHDL Files

In order for our model to work correctly you will need to download the software that gives the Basys 3 board its instructions.

First you will need to download a synthesis tool for implementing vhdl files to hardware. If you want to be certain that all of the code will fully replicate our design without the need for any modifications, we recommend that you use Vivado 2016.2. After you have installed Vivado you can create a project and download our source files. Add them as sources to your project, don't forget to add the constraints file as well!

Next we'll explain what each of the source files does. Skip steps 2 through 6 if you just want to get to the physical construction of the device.

Step 2: Breakdown of VHDL Top Module

The top module of the project is what connects all the individual component modules to the used hardware. As you can see we have the killSwitch and buzzerControl modules defined as components on the top.

The lower section specifies how these modules are connected together. We have connected four LED's to the board and associated them with the killSwitch modules dev0 through dev3. We have four killSwitch modules defined because we need one to manage the state of each connected LED. Each of these modules utilizes the clock and button signal that we created in the top module definition as well as their respective input switch and output device signals.

The buzzer control module on the bottom activates the buzzer when the universal off button is pressed. As you can see the buzzer control module is passed the clock and button signal as inputs. It is also passed the physical buzzer output pin to control it accordingly.

Step 3: Breakdown of VHDL Kill Switch Module

The Kill Switch is the universal off button, and the module is concerned primarily with connecting it to other circuit elements so that when it is pressed all of the lights will turn off.

While the top module handles connecting physical hardware to software, the killSwitch module handles the main logic of each device. The module takes in inputs for the clock signal, universal off button, and the device toggle switch. In return it controls the state of the device pin it is connected to.

In the architecture section of the code we see that it has a dependency on the dFlipFlop module to store memory. You can also see that we have declared four signals that will be used to connect the flip flop as well as implement our logic statements. Within the behavioral section of the code we have created an instance of the dFlipFlop module and assigned our I/O signals to the ports.

From here the main part of our logic lies in the signal values for invertState and isDevOn. Our logical basis for the device is as follows: "Any time the switch is thrown the light will invert it's on/off state. Any time the button is pressed, and the LED is currently on, the LED will invert its state to off." From these two statements we can extrapolate that the LED's state should be the XOR of the switch and our memory element.That way a change in either inverts the LED. This can be seen implemented in the isDevOn signal. The LED on condition for the memory element is handled by our invertState signal. If the LED is on and the button is pressed, our memory element will update and invert its state. This then inverts the LED's state as well.

Step 4: Breakdown of VHDL Flip Flop Module

One problem with our design was the fact that after using the off switch, lights that were previously on might need to be flipped twice to return to the on position. This would be quite the inconvenience for people over time. We managed to circumvent this inconvenience by including a "Flip Flop," a circuit element capable of storing information, into our design. Now, the system remembers whether a light switch was previously on so that if it is flipped again it will turn on regardless of its initial position.

The VHDL code uses if and else statements in order to create the Flip Flop as a component within our circuit design. It ensures that when the clock signal transitions from a low to a high state, when the lightbulb is on, and when the off switch is pushed, the flip flops output overwrites its input. When the input is overwritten the flip flop is inverted.

Step 5: Breakdown of VHDL Piezo Buzzer Module

This file is a bit superfluous as far as the hardware design is concerned, but it is essential in order to make the top module and constraints files run smoothly. If you choose not to use the Piezo buzzer, download this file, but don't attach the buzzer to the Basys 3 board.

The Piezo buzzer will, upon pressing the disable button, play a two note tone that will provide the user with auditory feedback that the button has been pushed. We implemented this behaviorally in VHDL through a series of if statements in a process structure. We started by creating an integer value to keep track of how many clock changes have occurred. Once the process begins the program spends the first half a second (0 to 50 million clock ticks) outputting an A note at 440 hertz. This is accomplished by inverting the piezo buzzer signal every even multiple of 227272 clock ticks with a modulo function. This number is the result of dividing the board's clock signal (100 MHz) by the desired frequency (400 Hz). During the second half a second (50 to 100 million clock ticks) the board outputs an F note at 349.2 hertz via the same method as before. After one second the program doesn't increment the clock variable any further and stops outputting anything from the piezo buzzer. Pressing the universal off button again resets this number to 0, restarting the noise cycle.

Step 6: Breakdown of VHDL Constraints File

The constraints file tells Vivado what devices on the Basys 3 board we are using. It also provides Vivado with the names that we gave to the devices in our code. Vivado needs this information so it knows how to connect our logic elements to the physical hardware. The constraints file includes a large amount of commented-out (unused) code. These lines of code reference the devices on the board that we aren't using.

The devices we are using include four input switches labeled V17, V16, W16, and W1 on the board. We are also using the universal off button, labeled U18. The output pins for our four connected LEDs are JB4, JB10, JC4, and JC10. For our piezzo buzzer we are using output pin JA9.

As we stated in the top module breakdown, if you want to add additional LEDs or other devices to the board you need to increase the scope of the sw and dev signals, add more killSwitch modules, and connect them together. You then need to link those variable names to the device hardware via the constraints file. This can be done by uncommenting (re-enabling) the lines of code associated with the pins you want to use then adding the name of it's associated variable in the top module. The proper syntax for this can be copied from the devices we are using. To find out the names of the pins you want to use on the board refer to the Baasys 3 reference guide here.

Step 7: Constructing the Basys 3

You will need to plug your LED's into the correct I/O ports of the Basys 3. Follow the provided pictures to determine what the correct ports are, because if you plug an LED into the wrong port it will not light up. If you have chosen to attach the piezo buzzer, you will also need to connect that to the correct I/O ports.

When the board is ready, plug it into your computer via USB cable.

Step 8: Implementing VHDL Files to Basys 3

Now that your board is ready and your code is finished, you can finally put the model together.

Once you have your project in Vivado set up, you must click the "Generate Bitstream" button in order to compile the code before it gets uploaded to the board. If you receive an error message at this time, you have to double check that your code matches ours exactly. When I say exactly, I mean down to even the semicolons or the types of parentheses that are being used. Once your bitstream has been written successfully, go to the hardware manager within Vivado and click on the "Open Target" button, then click on "Program Device" immediately afterwards. Your Basys 3 board should now be fully functional.

Step 9: Using the Basys 3 Board

Now that the Basys 3 Board is operational and has been programmed to represent our model, you have to know how to use it.

Each of the four switches furthest to the right controls one of the LED's, flicking them will cause the LED to turn on or off. If the LED does not activate, check to see that you are plugged into the correct I/O port, and that your LED is functional in the first place.

When you want to disable all of the LED's at once, you must push the center button in the set of five buttons displayed above.

Step 10: Show Off!

The model serves as a neat little novelty that you can demonstrate in front of your friends and family. It can theoretically also be used to implement the universal off switch into your home electrical system, if you replace the LED's with wires leading to your lights. While it is possible, we would still have to advise against it. There's potential to do serious harm to yourself or your home if you attempt to rewire without the help of an electrician.

Be the First to Share


    • Make It Bridge

      Make It Bridge
    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge
    • For the Home Contest

      For the Home Contest