-
Notifications
You must be signed in to change notification settings - Fork 7
/
DE10_LITE_Golden_Top.v
231 lines (207 loc) · 5.21 KB
/
DE10_LITE_Golden_Top.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
// ============================================================================
// Ver :| Author :| Mod. Date :| Changes Made:
// V1.1 :| Alexandra Du :| 06/01/2016:| Added Verilog file
// ============================================================================
//=======================================================
// This code is generated by Terasic System Builder
//=======================================================
`define ENABLE_ADC_CLOCK
`define ENABLE_CLOCK1
`define ENABLE_CLOCK2
`define ENABLE_SDRAM
`define ENABLE_HEX0
`define ENABLE_HEX1
`define ENABLE_HEX2
`define ENABLE_HEX3
`define ENABLE_HEX4
`define ENABLE_HEX5
`define ENABLE_KEY
`define ENABLE_LED
`define ENABLE_SW
`define ENABLE_VGA
`define ENABLE_ACCELEROMETER
`define ENABLE_ARDUINO
`define ENABLE_GPIO
module DE10_LITE_Golden_Top(
//////////// ADC CLOCK: 3.3-V LVTTL //////////
`ifdef ENABLE_ADC_CLOCK
input ADC_CLK_10,
`endif
//////////// CLOCK 1: 3.3-V LVTTL //////////
`ifdef ENABLE_CLOCK1
input MAX10_CLK1_50,
`endif
//////////// CLOCK 2: 3.3-V LVTTL //////////
`ifdef ENABLE_CLOCK2
input MAX10_CLK2_50,
`endif
//////////// SDRAM: 3.3-V LVTTL //////////
`ifdef ENABLE_SDRAM
output [12:0] DRAM_ADDR,
output [1:0] DRAM_BA,
output DRAM_CAS_N,
output DRAM_CKE,
output DRAM_CLK,
output DRAM_CS_N,
inout [15:0] DRAM_DQ,
output DRAM_LDQM,
output DRAM_RAS_N,
output DRAM_UDQM,
output DRAM_WE_N,
`endif
//////////// SEG7: 3.3-V LVTTL //////////
`ifdef ENABLE_HEX0
output [7:0] HEX0,
`endif
`ifdef ENABLE_HEX1
output [7:0] HEX1,
`endif
`ifdef ENABLE_HEX2
output [7:0] HEX2,
`endif
`ifdef ENABLE_HEX3
output [7:0] HEX3,
`endif
`ifdef ENABLE_HEX4
output [7:0] HEX4,
`endif
`ifdef ENABLE_HEX5
output [7:0] HEX5,
`endif
//////////// KEY: 3.3 V SCHMITT TRIGGER //////////
`ifdef ENABLE_KEY
input [1:0] KEY,
`endif
//////////// LED: 3.3-V LVTTL //////////
`ifdef ENABLE_LED
output [9:0] LEDR,
`endif
//////////// SW: 3.3-V LVTTL //////////
`ifdef ENABLE_SW
input [9:0] SW,
`endif
//////////// VGA: 3.3-V LVTTL //////////
`ifdef ENABLE_VGA
output [3:0] VGA_B,
output [3:0] VGA_G,
output VGA_HS,
output [3:0] VGA_R,
output VGA_VS,
`endif
//////////// Accelerometer: 3.3-V LVTTL //////////
`ifdef ENABLE_ACCELEROMETER
output GSENSOR_CS_N,
input [2:1] GSENSOR_INT,
output GSENSOR_SCLK,
inout GSENSOR_SDI,
inout GSENSOR_SDO,
`endif
//////////// Arduino: 3.3-V LVTTL //////////
`ifdef ENABLE_ARDUINO
inout [15:0] ARDUINO_IO,
inout ARDUINO_RESET_N,
`endif
//////////// GPIO, GPIO connect to GPIO Default: 3.3-V LVTTL //////////
`ifdef ENABLE_GPIO
inout [35:0] GPIO
`endif
);
reg [7:0] txData;
reg txLoad = 1'b0;
wire [7:0] rxData;
reg flag = 1'b1;
wire txReset = 1'b1;
wire rxReset = 1'b1;
reg [3:0] hex_info [5:0];
wire txIdle;
wire txReady;
wire rxIdle;
wire rxReady;
parameter ClkFrequency = 50000000;
parameter Baud = 9600;
wire RxD_data_ready;
wire [7:0] RxD_data;
async_receiver GPS( .clk(MAX10_CLK1_50),
.rst(1'b0),
.RxD(GPIO[35]),
.RxD_data_ready(rxReady),
.RxD_data(rxData));
defparam GPS.ClkFrequency=ClkFrequency;
defparam GPS.Baud=Baud;
hex7seg h0(LAT[3:0], HEX0);
hex7seg h1(LAT[11:8], HEX1);
hex7seg h2(LAT[19:16], HEX2);
hex7seg h3(LON[3:0], HEX3);
hex7seg h4(LON[11:8], HEX4);
hex7seg h5(LON[19:16], HEX5);
integer precision = 3;
reg [2:0] STATE=0;
reg [23:0] NMEA=0;
reg [23:0] LAT=0;
reg [23:0] LON=0;
integer prec_cnt = 0;
always @(posedge MAX10_CLK1_50) begin
case(STATE)
0: begin //Search for '$'
if(rxReady && rxData=="$")begin// '$': Start of frame
STATE<=STATE+1;
end
end
1: begin //Check Tag, if not the proper tag go back
if(rxReady) begin
if(rxData==",")begin
if(NMEA=="GLL")begin
STATE<=STATE+1;
end
else begin
STATE<=0;
end
end
else begin //Grab the NMEA Message Type
NMEA[23:8]<=NMEA[15:0];
NMEA[7:0]<=rxData; //Grab the tag info
end
end
end
2: begin //Parse the latitude
if(rxReady) begin
if(rxData==",")begin
STATE<=STATE+1;
prec_cnt = 0;
end
else if (prec_cnt < precision) begin //grab only 3 first LAT values, because we have only 3 HEX available
prec_cnt = prec_cnt + 1;
LAT[23:8]<=LAT[15:0];
LAT[7:0]<=rxData;
end
end
end
3: begin //Parse letter
if(rxReady) begin
if(rxData==",")begin
STATE<=STATE+1;
end
end
end
4: begin //Parse the longitude
if(rxReady) begin
if(rxData==10)begin //LF: Line Feed, end of message, go to idle state
STATE<=0;
prec_cnt = 0;
end
else if (prec_cnt < precision)begin //grab only 3 first LON values, because we have only 3 HEX available
prec_cnt = prec_cnt + 1;
LON[23:8]<=LON[15:0];
LON[7:0]<=rxData;
end
end
end
default: begin
STATE<=0;
end
endcase
end
//just for debug
assign LEDR[0] = STATE[0];
assign LEDR[1] = STATE[1];
endmodule