Department of Computer Science and Technology

Course pages 2017–18

ECAD and Architecture Practical Classes

Exercise 2a: Rotary encoders and shift register on FPGA



Exercise

Implement and test your debouncer and rotary controller on the FPGA. Also implement the shift register controller to read in the display board buttons. Display the state on the LEDs.

Procedure

You should already have rotary.sv and debounce.sv from Exercise 1.

A pair of 74HC165 shift registers are used to read the display buttons, as described in our buttons documentation. You should download the shiftregctl.sv. You should also download hex_to_7seg.sv, a combinational module that converts binary into hexadecimal digits to display on the 7-segment LEDs.

Copy these into your ecad_fpga_1 folder and add them to the project (use Project | Add/Remove files in Project and choose files - note that you have to click the Add... button to actually perform the add).

Now instantiate each in toplevel.sv and connect up their pins. Wire DIALL as the input to the left rotary encoder, and DIALR to the right. Display your 8 bits of counter for the left on HEX5 and HEX4, and the right on HEX3 and HEX2. The outputs from your counter come out as binary codes, so pass each digit through an instance of hex_to_7seg to make them into readable digits.

The shiftreg_ ports on shiftregctl match up with the external I/O pins that go to the display board. Use CLOCK_50 for clocking both shiftregctl and your rotary encoders. For reset you can use the KEY[0] button, but note this will cause an active low reset: if your modules are active high you need to invert it.

The shift register documentation gives some code to break out the buttons into meaningful names - add this to your toplevel. Route the buttons to the red LEDs called LEDR[9:0]. There are not enough LEDs for buttons and there are some non-button bits in the 16-bit shift register word, so decide how you want to display them.

Synthesise your FPGA, download it to the board and test that you are able to correctly read the encoders and buttons.