1300 Henley Court Pullman, WA 99163 509.334.6306 www.digilentinc.com PmodJSTK2TM Reference Manual Revised July 19, 2016 This manual applies to the PmodJSTK2 rev. C Overview The Digilent PmodJSTK2 (Revision C) is a versatile user input device that can be easily incorporated into a wide variety of projects. With a two-axis joystick on a center button, a trigger button, and a programmable RGB LED capable of 24-bit color. Features include: Factory Calibrated Two Axis Resistive Joystick Center Joystick Button Trigger Style Push Button 24-bit RGB LED 6-pin Pmod connector with SPI interface Library and example code available in resource center The PmodJSTK2. 1 Functional Descriptions The PmodJSTK2 utilizes two potentiometers oriented orthogonally to one another and are manipulated by moving the joystick in the X and Y directions. As the joystick moves, the voltage output at the sweep pin of each potentiometer changes and is measured by the 10-bit ADC present on the embedded PIC16F1618 microcontroller. The raw measured data is stored at a rate of 100 Hz as a 16-bit right-justified variable in RAM with the upper 6 bits masked with zeros. Additionally, each successive measurement also produces two 8-bit values representative of the joysticks physical location with respect to each axis. Note that if inversion of either of the 8-bit position axis are set, the values will not change until the data has been re-collected by the PIC16 at the 100 Hz rate. DOC#: 502-330 Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners. Page 1 of 9 PmodJSTK2TM Reference Manual 2 Specifications Parameter Min Typical1 Max Recommended Operating Voltage 3.1 3.3 3.5 Maximum Supply Voltage 5.5 Power Supply Current2 4.85 3 Power Supply Current 17.6 Parameter Value Maximum Joystick Angle 25 Communication Protocol SPI Note: Data in the Typical Column uses VCC at 3.3V unless otherwise noted Note: Normal operation with the RGB LED Off and no buttons pressed Note: Normal operation with the RGB LED set to white and both buttons pressed 3 Units V V mA mA Units Degrees Interfacing with the Pmod The PmodJSTK2 communicates with the host board via the SPI protocol. With the PmodJSTK2, there are two types of data packet protocols: the standard data packet of 5 bytes and an extended data packet with 6 or 7 bytes in total. With the standard 5 byte protocol, users may use the old code from the PmodJSTK without any syntax errors. The 5 byte packet structure is provided in the image below: As noted in the standard data packet structure, users may either send a zero and a series of 4 dummy bytes to receive the standard 5 bytes of data or they may send a single command byte with up to 4 parameters in the four following bytes to set the internal values such as the joystick calibration or on-board RGB LED. The extended data protocol allows for additional data to be obtained from the device during a communication session after the standard 5 bytes of information such as normalized 8-bit positional data for each axis. Users may also obtain the current calibration values and the status of the module through this method. Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners. Page 2 of 9 PmodJSTK2TM Reference Manual 3.1 SPI Timing Requirements The embedded PIC16F1618 requires certain SPI timing requirements in order for successful communication to occur. When the Chip Select line is brought low, users must wait at least 15 S before sending the first byte of data. An interbyte delay of at least 10 S is required when transferring multiple bytes. When the Chip Select line is brought high after the last byte has been transferred, at least 25 S is required before users may bring the Chip Select line low again to initiate another communication session. 3.2 Calibrating the Module The PmodJSTK2 has a set of factory loaded calibration values that are used to calculate the 8-bit position values for each axis. Users may enter calibration mode to recalculate all of those values by rotating the joystick around so the embedded PIC16 can record all of the maximum and minimum samples for the two axes. The on-board blue LED will be flashing to indicate that the calibration sequence is taking place. When the embedded microcontroller detects that the joystick has not changed for an entire second, allowing the microcontroller to presume that the most recent set of measurements correspond to the joystick's center position, the blue LED will stop flashing and the green LED will flash twice to indicate that the calibration procedure was successful. However, if 10 seconds pass without the PIC16 detecting the center position, the blue LED will stop flashing and the red LED will flash twice indicating that the calibration procedure was not successful. Once the Chip Select pin goes high after the calibration command has been processed, the PmodJSTK2 will not accept any new commands during the calibration procedure. Users may still poll the status register to determine the current status of the device during this time. Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners. Page 3 of 9 PmodJSTK2TM Reference Manual 3.3 Using the High-endurance Flash The PmodJSTK2 has a set of factory loaded calibration values that are used to calculate the 8-bit position values for each axis. Users may enter calibration mode to recalculate all of those values by rotating the joystick around so the embedded PIC16 can record all of the maximum and minimum samples for the two axes. The on-board blue LED will be flashing to indicate that the calibration sequence is taking place. When the embedded microcontroller detects that the joystick has not changed for an entire second, allowing the microcontroller to presume that the most recent set of measurements correspond to the joystick's center position, the blue LED will stop flashing and the green LED will flash twice to indicate that the calibration procedure was successful. However, if 10 seconds pass without the PIC16 detecting the center position, the blue LED will stop flashing and the red LED will flash twice indicating that the calibration procedure was not successful. Once the Chip Select pin goes high after the calibration command has been processed, the PmodJSTK2 will not accept any new commands during the calibration procedure. Users may still poll the status register to determine the current status of the device during this time. Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners. Page 4 of 9 PmodJSTK2TM Reference Manual 3.4 Command Summary 3.4.1 Get Commands Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners. Page 5 of 9 PmodJSTK2TM Reference Manual 3.4.2 Set Commands Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners. Page 6 of 9 PmodJSTK2TM Reference Manual Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners. Page 7 of 9 PmodJSTK2TM Reference Manual 3.4.3 Other Commands Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners. Page 8 of 9 PmodJSTK2TM Reference Manual 4 Pinout Description Table A pinout table of the PmodJSTK2 is provided below. Pin 1 2 3 4 5 6 Signal CS MOSI MISO SCK GND VCC Description Chip Select Master-Out-Slave-In Master-In-Slave-Out Serial Clock Power Supply Ground Power Supply (3.3V/5V) Although users are welcome to create their own interface code for the PmodJSTK2 if they so desire, preconstructed libraries that provide functions for initializing the module, reading in values, and adjusting calibration values exist. They are available on the PmodJSTK2 example code page. Any external power applied to the PmodJSTK2 must be within 2.95V and 5.5V; however, it is recommended that Pmod is operated at 3.3V. 5 Physical Dimensions The pins on the pin header are spaced 100 mil apart. The PCB is 1.875 inches long on the sides parallel to the pins on the pin header, 0.9375-inch-long on the sides perpendicular to the pin header, and 1.75 inches tall. With the 3D printed housing the module is 1.875 inches long on the sides parallel to the pins on the pin header, 1.125 inches long on the sides perpendicular to the pin header, and 1.75 inches tall. Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners. Page 9 of 9