====== Displaying Joystick Position ====== {{ reference:test-and-measurement:analog-discovery-2:pmod-jstk:shot_1.png?400 |}} ===== Introduction ===== This project streams positional data from the Digilent Pmod JSTK2 into a Digilent Test and Measurement device. The data is presented on an X-Y plot, showing the position of the joystick and any button clicks, similar to a joystick calibration dialog. The project demonstrates how SPI transactions can be generated, and how the results can be plotted and interpreted within WaveForms. ===== Inventory ===== * A Digilent Test and Measurement device that supports WaveForms' //Scope//, //Patterns//, and //Logic// instruments. * [[https://digilent.com/shop/analog-discovery-2-100ms-s-usb-oscilloscope-logic-analyzer-and-variable-power-supply/|Analog Discovery 2]] * [[https://digilent.com/shop/analog-discovery-studio-a-portable-circuits-laboratory-for-every-student/|Analog Discovery Studio]] * //An Analog Discovery (Legacy) can also be used.// * [[https://digilent.com/shop/pmod-jstk2-two-axis-joystick/|Pmod JSTK2]] * A Pmod JSTK (Legacy) is pin-compatible and can also be used. * WaveForms Installation * [[software:waveforms:waveforms-3:start|Resource Center]] * {{reference:test-and-measurement:analog-discovery-2:pmod-jstk:displaying-joystick-position.zip|ZIP Archive}} * //Includes a WaveForms workspace for displaying positional data captured from the Pmod JSTK2.// ===== Description ===== The script included in the workspace download is used to initialize several instruments, process captured data, and display it within an X-Y plot. This script utilizes the pattern generator to produce the clock and chip select signals required for SPI communication with the Pmod. The logic analyzer is used to take samples of the data every 5 milliseconds, which is pushed into an array that is displayed in the oscilloscope window as a reference channel. The array contains 500 points, so the X-Y plot will display a trace of the joystick position. When either of the 3 buttons on the Pmod are pressed, the display is cleared and three points in the top portion of the plot represent the left, center, and right buttons. The script performs bit-wise operations to convert the data into a usable form. As the [[pmod:pmodjstk2:reference-manual|Pmod JSTK2 Reference Manual]] states, the X- and Y-coordinates are each passed to the Test and Measurement device as 10 bits contained within 2 bytes. The first byte in the set contains the 8-least significant bits, and the last 2 bits of the second byte are the 2 most-significant bits of the coordinate. The fifth byte indicates the status of the three buttons, represented by the 3 least-significant bits. See the chart below for a visualization of the data. Thus, the data, taken as 16-bit words is processed into a 10-bit number ranging from 0 to 1023. After the number is generated it is added to an array which is displayed as the X-Y plot. For a better understanding of the what the script is doing, please read the [[pmod:pmodjstk2:reference-manual|Pmod JSTK2 Reference Manual]] and see Figure 1, below. {{ reference:test-and-measurement:analog-discovery-2:pmod-jstk:flow_diagram.png?400 |}}