-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPmodJSTK_Demo.v
executable file
·148 lines (126 loc) · 5.03 KB
/
PmodJSTK_Demo.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: Digilent Inc.
// Engineer: Josh Sackos
//
// Create Date: 07/11/2012
// Module Name: PmodJSTK_Demo
// Project Name: PmodJSTK_Demo
// Target Devices: Nexys3
// Tool versions: ISE 14.1
// Description: This is a demo for the Digilent PmodJSTK. Data is sent and received
// to and from the PmodJSTK at a frequency of 5Hz, and positional
// data is displayed on the seven segment display (SSD). The positional
// data of the joystick ranges from 0 to 1023 in both the X and Y
// directions. Only one coordinate can be displayed on the SSD at a
// time, therefore switch SW0 is used to select which coordinate's data
// to display. The status of the buttons on the PmodJSTK are
// displayed on LD2, LD1, and LD0 on the Nexys3. The LEDs will
// illuminate when a button is pressed. Switches SW2 and SW1 on the
// Nexys3 will turn on LD1 and LD2 on the PmodJSTK respectively. Button
// BTND on the Nexys3 is used for resetting the demo. The PmodJSTK
// connects to pins [4:1] on port JA on the Nexys3. SPI mode 0 is used
// for communication between the PmodJSTK and the Nexys3.
//
// NOTE: The digits on the SSD may at times appear to flicker, this
// is due to small pertebations in the positional data being read
// by the PmodJSTK's ADC. To reduce the flicker simply reduce
// the rate at which the data being displayed is updated.
//
// Revision History:
// Revision 0.01 - File Created (Josh Sackos)
//////////////////////////////////////////////////////////////////////////////////
// ==============================================================================
// Define Module
// ==============================================================================
module PmodJSTK_Demo(
CLK,
RST,
MISO,
SW,
SS,
MOSI,
SCLK,
LED,
AN,
SEG
);
// ===========================================================================
// Port Declarations
// ===========================================================================
input CLK; // 100Mhz onboard clock
input RST; // Button D
input MISO; // Master In Slave Out, Pin 3, Port JA
input [2:0] SW; // Switches 2, 1, and 0
output SS; // Slave Select, Pin 1, Port JA
output MOSI; // Master Out Slave In, Pin 2, Port JA
output SCLK; // Serial Clock, Pin 4, Port JA
output [2:0] LED; // LEDs 2, 1, and 0
output [3:0] AN; // Anodes for Seven Segment Display
output [6:0] SEG; // Cathodes for Seven Segment Display
// ===========================================================================
// Parameters, Regsiters, and Wires
// ===========================================================================
wire SS; // Active low
wire MOSI; // Data transfer from master to slave
wire SCLK; // Serial clock that controls communication
reg [2:0] LED; // Status of PmodJSTK buttons displayed on LEDs
wire [3:0] AN; // Anodes for Seven Segment Display
wire [6:0] SEG; // Cathodes for Seven Segment Display
// Holds data to be sent to PmodJSTK
wire [7:0] sndData;
// Signal to send/receive data to/from PmodJSTK
wire sndRec;
// Data read from PmodJSTK
wire [39:0] jstkData;
// Signal carrying output data that user selected
wire [9:0] posData;
// ===========================================================================
// Implementation
// ===========================================================================
//-----------------------------------------------
// PmodJSTK Interface
//-----------------------------------------------
PmodJSTK PmodJSTK_Int(
.CLK(CLK),
.RST(RST),
.sndRec(sndRec),
.DIN(sndData),
.MISO(MISO),
.SS(SS),
.SCLK(SCLK),
.MOSI(MOSI),
.DOUT(jstkData)
);
//-----------------------------------------------
// Seven Segment Display Controller
//-----------------------------------------------
ssdCtrl DispCtrl(
.CLK(CLK),
.RST(RST),
.DIN(posData),
.AN(AN),
.SEG(SEG)
);
//-----------------------------------------------
// Send Receive Generator
//-----------------------------------------------
ClkDiv_5Hz genSndRec(
.CLK(CLK),
.RST(RST),
.CLKOUT(sndRec)
);
// Use state of switch 0 to select output of X position or Y position data to SSD
assign posData = (SW[0] == 1'b1) ? {jstkData[9:8], jstkData[23:16]} : {jstkData[25:24], jstkData[39:32]};
// Data to be sent to PmodJSTK, lower two bits will turn on leds on PmodJSTK
assign sndData = {8'b100000, {SW[1], SW[2]}};
// Assign PmodJSTK button status to LED[2:0]
always @(sndRec or RST or jstkData) begin
if(RST == 1'b1) begin
LED <= 3'b000;
end
else begin
LED <= {jstkData[1], {jstkData[2], jstkData[0]}};
end
end
endmodule