Introduction: How to Use a Joystick With an FPGA
This instructable is yet another stop on my journey to build the claw game driven by an FPGA. Previously I wrote how to control a stepper motor with an FPGA. Now I needed to control a joystick so that I can eventually connect both to my control system.
This demo receives the data from the PmodJSTK joystick and displays it on the seven segment display. Switch 0 changes the display from X data to Y data. It also connects the buttons on the PmodJSTK to the LEDs on the Basys3, and Switch 1 and 2 to the LEDs on the PmodJSTK.
Step 1: Collect Your Materials
Here is what you will need to build this project:
- Basys 3
Step 2: Some Background Info
This demo uses the PmodJSTK and Basys 3. The PmodJSTK communicates via spi to both transfer and recieve data.
In this demo data is displayed the the seven segment display. Sw0 controls whether the data is from X or Y. Both the data from X and from Y is between 0 and 1023. The buttons on the PmodJSTK are connected to LD0, LD1, and LD2. The switch 1 and 2 on the Basys 3 are connected to the LEDs on the PmodJSTK. BTNC on the Basys 3 can reset the design.
Step 3: Download and Unzip the Demo Code
Download the zip file attached to this step.
Unzip the file and open the vivado project. You can do this either by double clicking on the file or opening vivado and selecting open project.
Note: I used Vivado 2015.4 to create this project. If you have a different version installed I would suggest creating a new project in your version, then adding each of the source files. You would need to add, PmodJSTK.v, PmodJSTK_Demo.v, spiCtrl.v, SPIDmode0.v, ClkDiiv_66_67kHz.v, ssdCtrl.v, Binary_To_BCD.v, ClkDiv_5Hz.v, and PmodJSTK_contraints.XDC.
Step 4: Generate the Bit File and Program Your Board
Once the file is open you can generate the bit file and program the board.
To generate the bit file double click generate bitstream. To program the board open the hardware manager, open target and program the board.
Step 5: Plug in the PmodJSTK to the Basys 3
The code uses the top bank of pmod header JA, that is pins 1-4.
Now you have the board programmed and the Pmod plugged in you can start viewing the data from the JSTK, and modifying to fit your specific needs.
To learn more about the PmodJSTK and its functioning visit the resource center.