# Computer Laboratory

Course pages 2015–16

# ECAD and Architecture Practical Classes

## Exercise 4: 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.

If you attempted optional Exercise 1b you should have written a shiftregctl to read the display buttons. If not you can download a working example: shiftregdriver.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 a 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 enocders. 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.

Exercise 1b 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.

• © 2015 Computer Laboratory, University of Cambridge
Information provided by Prof Simon Moore