Goal: Design a sequential circuit (FSM) and implement using the Nexys 4 FPGA board. (The Nexys 4 uses the Vivado Design Suite. )
Using labkit_lab4.v, display_8hex.v and Nexys4DDR_Master_lab4.xdc, synthesize, implement, generate and load a bit file to the Nexys 4 board. The switches should turn on the LEDs. The value of the right most 4 switches should be displayed on the LSB of the display. Three pushbuttons should display a red, green and blue LED. Here's a Vivado quick start guide.
Using the Integrated Logic Analyzer is very useful in debugging your design- here's how Integrated Logic Analyzer ILA
Please have the following available during checkoff:
Be able to respond to any of the following questions (and possibly others).
[Checkoff: 7 points with 440/880hz siren, 8 points with selected sound effects. -- see the end]
Porsche Anti-Theft System
A recent MIT grad just completed a very successful IPO of her Cambridge startup and celebrated by purchasing a new Porsche. Though the car has a built in anti-theft system, she is concerned since this is a standard factory unit and many people know how to disable it. So she's looking for someone to design and build a system with some hidden security features only you two will know about! Your job is to create a working prototype.
In this lab you will implement an anti-theft system that uses several interacting FSMs to process sensor inputs and generate the appropriate actuator control signals. This lab provides you with a design methodology that will be useful in future labs and your final project.
Description of Anti-Theft System
Since your client is completely focused on her start-up, she wants an anti-theft system that's highly automated. The system is armed automatically after she turns off the ignition, exits the car (i.e., the driver's door has opened and closed) and T_ARM_DELAY has passed. If there is a passenger and both the driver's door and passenger's doors are open, the system arms itself after all the doors have been closed and T_ARM_DELAY has passed; that delay is restarted if a door is opened and reclosed before the alarm has been armed.
Once the system has been armed, opening the driver's door the system begins a countdown. If the ignition is not turned on within the countdown interval (T_DRIVER_DELAY), the siren sounds. The siren remains on as long as the door is open and for some additional interval (T_ALARM_ON) after the door closes, at which time the system resets to the armed but silent state. If the ignition is turned on within the countdown interval, the system is disarmed.
Always a paragon of politeness, your client opens the passenger door first if she's transporting a guest. When the passenger door is opened first, a separate, presumably longer, delay (T_PASSENGER_DELAY) is used for the countdown interval, giving her extra time to walk around to the driver's door and insert the key in the ignition to disarm the system.
There is a status indicator LED on the dash. It blinks with a two-second period when the system is armed. It is constantly illuminated either the system is in the countdown waiting for the ignition to turn on or if the siren is on. The LED is off is the system is disarmed.
So far this all is ordinary alarm functionality. But you're worried that a knowledgable thief might disable the siren and then just drive off with the car. So you've added an additional secret deterrent -- control of power to the fuel pump. When the ignition is off power to fuel pump is cut off. Power is only restored when first the ignition is turned on and then the driver presses both a hidden switch and the brake pedal simultaneously. Power is then latched on until the ignition is again turned off.
The diagram below lists all the sensors (inputs) and actuators (outputs) connected to the system.
The system timings are based on four parameters (in seconds): the delay between exiting the car and the arming of the alarm (T_ARM_DELAY), the length of the countdown before the alarm sounds after opening the driver's door (T_DRIVER_DELAY) or passenger door (T_PASSENGER_DELAY), and the length of time the siren sounds (T_ALARM_ON). The default value for each parameter is listed in the table below, but each may be set to other values using the Time_Parameter_Selector, Time_Value, and Reprogram signals. Time_Parameter_Selector switches specify the parameter number of the parameter to be changed. Time_Value switches are a 4-bit value representing the value to be programmed -- a value in seconds between 0 and 15. Pushing the Reprogram button tells the system to set the currently selected parameter to Time_Value. Note that your system should behave correctly even if one or more of the parameters is set to 0.
|Interval Name||Symbol||Parameter Number||Default Time (sec)||Time Value|
|Countdown, driver's door||T_DRIVER_DELAY||01||8||1000|
|Countdown, passenger door||T_PASSENGER_DELAY||10||15||1111|
|Siren ON time||T_ALARM_ON||11||10||1010|
The following diagram illustrates a possible organization of your design into modules.
You should implement this lab by programming each module individually and then instantiating and connecting the modules together in the toplevel labkit_lab4.v module. Then compile your implementation using the Xilinx tools, download it to your kit's FPGA, and demonstrate its operation. Please use the following labkit devices for the various sensors and actuators:
|Sensor/Actuator||Nexys 4 device|
|Hidden switch||BTNU up button|
|Brake depressed switch||BTND down button|
|Driver door switch||BTNL left button|
|Passenger door switch||BTNR right button|
|Reprogram||BTNC center button|
|Fuel pump power||LED|
Here's a more detailed description of each module:
A second problem arises from the mechanical "bounce" inherent in switches: as a metal contact opens and closes it may bounce a couple of times, creating a sequence of on/off transitions in rapid succession. So you need to use debouncing circuitry to filter out these unwanted transitions. debounce.v (available on the Handouts page of the course website) is a Verilog implementation of a digital retriggerable one-shot that requires that an input transition be stable for 0.01sec before reporting a transition on its output. This module happens to produce a synchronous output, so a separate synchronizer is not required. You should use an instance of the debounce module to debounce any switch inputs you use in your design.
On power on, the parameters should be set to the default values specified above. However the user may modify any of the values by manipulating Time_Parameter_Selector (2 bits), Time_Value (4 bits), and Reprogram. Whenever a parameter is reprogrammed, the FSM should be reset to its ARMED state (after which it may transition immediately to another state depending on the sensor inputs).
Note that more than one FSM state may be needed to implement the required functionality of each mode, i.e, your state transition diagram will have many more than 4 states.
The IO pins cannot drive the speaker directly. We will use a 74HC08 as a driver. See staff for a speaker, cables, headers and protoboard. Using a cable, connect the output of the siren generator to the JA output of the FPGA, which appears on a connector on the right side of the board. Wire up a protoboard and connect JA to pins 9 and 10 of the 74HC08 AND gate. Note the orientation of the three dots on the connector.
Check and make sure pin 14 is attached to 3.3V and pin 7 is attached to gound. Attach the speaker to pin 8 of the AND gate and ground. In this application, the AND gate is used to drive the speaker. The 74HC08 is operated way out of spec (and abused) - not recommended as an engineering design - but okay for lab use. After the lab is checked off you leave the speaker assembly for other students to use.
You're anxious to make a good impression on your client in the hopes of getting the design commisions (and earning an extra point on the lab). So once you've implemented the basic functionality described above, create a different sound effect with your Siren Generator. Some ideas:
The labkit_lab4.v template top-level file and display_8hex.v can be downloaded by right-clicking on the link and choosing "Save As". The two Verilog files allow a user to utilize some of the Nexys 4 features including buttons, switches, leds, user input/output pins, VGA output, etc.
You will need to instantiate all submodules in this top level file as well as create wires to connect the submodules. For example, to connect and instantiate your divider and timer blocks you could add something like the following lines in the labkit_lab4.v file:
//declare wires as shown in Figure 2 to connect the submodules: wire reset_sync; wire one_hz_enable; wire [3:0] value; wire expired, start_timer; //instantiate the submodules and wire their inputs and outputs //(use the labkit's clock_25mhz as the clock to all blocks) divider divider1 (.clock_25mhz(clock_25mhz), .reset_sync(reset_sync), .one_hz_enable(one_hz_enable)); timer timer1(.clock_25mhz(clock_25mhz), .reset_sync(reset_sync), .value(value), .expired(expired), .start_timer(start_timer));
In addition, you will need to connect the input buttons and switches that you use to the appropriate submodules. There are verilog statements in labkit_lab4.v that set default values for all outputs, e.g., the leds/switches and JA[7:0]. You'll need to replace those statements with your own logic that generates the appropriate driving values.
Inevitably your design won't be 100% correct the first time. Debugging by just observing the outputs talked about above may not work -- you'll need more info to figure out what's happening. Start by building a test-jig for each module of your design and then the overall test-jig to verify the expected behavior of the system on several sequences of inputs that you expect to test on a real labkit. Once the system passes these tests you can proceed to the implementation on the labkit.
For debug on the labkit you have several options. Use the display_8hex.v module to show 6 hex digits of info (32 bits) on the kits 8-character LCD display. You will need the display to show that your timer is working correctly. Use one digit to show the current state of the FSM, another digit to indicate currently selected time parameter, yet another digit to show the current value of the timer's module internal counter, etc. You'll want to use this handy module for displaying debugging info for all your designs!