Computer Laboratory

ECAD and Architecture Practical Classes

Exercise 2

Open toplevel.sv. Using your synchronisation module from Exercise 1, complete one of the following options. The options are (roughly) in ascending order of difficulty.

You may complete additional options if you wish, but will not receive any extra credit. It is preferable to move on to the next lab as soon as possible.

Any files provided should be downloaded to your project directory as before. To add downloaded files to your project, select Project | Add/Remove Files in Project. Click ... to browse and select one or more files. If you select a single file you will need to click Add. Click OK.

Note that you will need to modify the body of toplevel.sv, including removing some or all of the logic that flashes the LEDs and 7-segment displays. The module header that declares the ports that are connected to the FPGA pins should not be modified, even if you are not using some of the ports.



Hex dice

Files Provided

hex_to_7seg.sv
Converts numbers in the range 0-15 to appropriate signals for display on a 7 segment display.

Behaviour

A push button on the board is held down to "roll" the dice during which time a 7 segment display can show anything. When the button is released, the display should show a "random" hexadecimal digit between 0 and F.

Implementation advice

When a push button (KEY[3]) is held down a 4 bit counter can be incremented every clock cycle. The 50MHz clock input (CLOCK_50) can be used. The value of the 4 bit counter should be output continuously via the translation logic in hex_to_7seg.sv to one of the 7 segment displays (HEX0).

Note that the push buttons are active low e.g. KEY[3] is 1 normally and 0 when it's being pressed.




Knight rider

Behaviour

When a button (KEY[3]) is held down the red LEDs (LEDR) scan the back and forth displaying the Knight Rider pattern (shown in action in this gif) at a reasonable speed. Releasing the button freezes the pattern.

Implementation advice

This pattern can be generated by breaking it into two phases. A 28 bit register is used; in both phases the LEDs output the central 18 bits. The register should be initialised to 28'b1111 and shifted left every cycle during the first phase and right every cycle in the second.

Doing a shift every clock cycle will result in a pattern too fast to be seen (or indeed for the LEDs to display). All the LEDs will merely appear to be dimly lit. There are two approaches to solve this: increment a counter every cycle and only do a shift when it takes on a particular value; or use a slower clock. To generate a slower clock you can use a PLL (Phase Locked Loop) megafunction but you'll still need a counter to slow things down sufficiently.




Simple Calculator

Files Provided

hex_to_7seg.sv
Converts numbers in the range 0-15 to the appropriate signals for display on a 7 segment LED.

Behaviour

Pressing, respectively, KEY[3] and KEY[2] will increment once a 4-bit number displayed on HEX[3] and HEX[2]. Pressing KEY[1] will display their 5-bit summation using HEX[1:0]. Pressing KEY[0] will reset the system.

Implementation Advice

Use a 4-bit register to store the value of each summand. Work out how to detect a rising edge incurred by pressing a button, and increment the corresponding value each time you detect one.

Note that the push buttons are active low e.g. KEY[3] is 1 normally and 0 when it's being pressed.




Annihilation!

Behaviour

Consider a bit vector and define a pulse to be a contiguous sequence of active bits in this vector. The pulse is generated at a specified end of the vector by appending a bit to its (shifted) tail, and travels to the opposite end. Using the red LEDs, pressing KEY[3] will generate a pulse from the left; pressing KEY[2] will generate a pulse from the right. Where (the heads of) the two pulses overlap, the overlapping bits are deactivated (annihilate).

Implementation Advice

Represent pulses from the left and right using separate 18-bit registers. A third 18-bit register can be used to track annihilations and display the net effect.

Making a pulse travel requires shifting the vector in the appropriate direction. Doing a shift every clock cycle will result in a pattern too fast to be seen (or indeed for the LEDs to display) - all the LEDs will merely appear to be dimly lit. There are two approaches to solve this: increment a counter every clock cycle and only do a shift when it takes on a particular value; or a use a slower clock. To generate a slower clock you can use a PLL (Phase Locked Loop) megafunction.

Note that the push buttons are active low e.g. KEY[3] is 1 normally and 0 when it's being pressed.

Previous  |  Contents  |  Next - Lablet 1.2