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.

Refrain from attempting multiple options unless time permits; your priority should be to complete the labs in accordance with the ticking criteria.

Any files provided should be downloaded to your project directory as before. To add downloaded files to your project, go Project | Add/Remove Files in Project. Either click Add All, or use ... to browse and Add one or more files.



Hex dice

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

A button on the board is held down to "roll" the dice during which time a 7 segment LED can display anything. Upon release 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 result 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