-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab4.html
426 lines (396 loc) · 33.1 KB
/
lab4.html
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Lab 4</title>
<link rel="shortcut icon" href="favicon-paper-plane.ico" />
<!-- Bootstrap Core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,700,300italic,400italic,700italic" rel="stylesheet" type="text/css">
<link href="vendor/simple-line-icons/css/simple-line-icons.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/stylish-portfolio.min.css" rel="stylesheet">
</head>
<body id="page-top">
<!-- Navigation -->
<a class="menu-toggle rounded" href="#">
<i class="fas fa-bars"></i>
</a>
<nav id="sidebar-wrapper">
<ul class="sidebar-nav">
<li class="sidebar-nav-item">
<a class="js-scroll-trigger" href="index.html#page-top">Home</a>
</li>
<li class="sidebar-nav-item">
<a class="js-scroll-trigger" href="index.html#about">About</a>
</li>
<li class="sidebar-nav-item">
<a class="js-scroll-trigger" href="index.html#milestones">Milestones</a>
</li>
<li class="sidebar-nav-item">
<a class="js-scroll-trigger" href="index.html#labs">Labs</a>
</li>
</ul>
</nav>
<!-- Header -->
<header class="masthead d-flex">
<div class="container text-center my-auto">
<h1 class="mb-1">Lab 4</h1>
<h3 class="mb-5">
<em>We can see clearly now, the rain is gone (kinda)</em>
</h3>
<a class="btn btn-primary btn-xl js-scroll-trigger" href="#about">Wanna know more?</a>
</div>
<div class="overlay"></div>
</header>
<section id="about" class="content-section">
<div class="container">
<h1>Objective</h1>
<p>For this lab, we used an FPGA ( a DE0-Nano board), an Arduino, and an OV7670 camera, to create a system that distinguishes red and blue color. The FPGA is used to clock the camera and read from the camera’s byte output, and transform said output into data that can be stored in memory and displayed on a screen. The Arduino is used to write register data to the camera and receive color detection information from the FPGA.</p>
<h1>Procedure</h1>
<p>The main goal in Lab 4 was to get the camera up and running and have our system distinguish between red and blue color, as well as communicate whether a treasure even exists. Although our live camera feed is still quite imperfect (this will likely cause problems for shape-detection further down the road), our system does indeed successfully meet this overarching goal of distinguishing color. The steps we took to complete this task are outlined below:</p>
<ul>
<li>Create a Phase-Locked-Loop to ensure that the several clocks we require (the OV7670 requires a 24-MHz clock, the VGA module requires a 25-MHz clock, etc.) are treated in the FPGA as actual clock lines and that they are not skewed</li>
<li>
<p>On the Arduino:</p>
<ul>
<li>Determine the register values needed to be written to their specific register addresses (using the OV7670 datasheet)</li>
<li>Write these register values to the camera via the Arduino (and a sketch file)</li>
<li>Successfully reading color data sent from the FPGA</li>
</ul>
</li>
<li>
<p>On the FPGA:</p>
<ul>
<li>Correctly display memory contents of an FPGA onto a screen</li>
<li>Correctly parse camera information (in our case, RGB-565-formatted data), and display it to the screen</li>
<li>Accurately determine if most pixels from the camera feed are red/blue (distinguishing color), and correctly sending such data</li>
</ul>
</li>
<li>
<p>Integration:</p>
<ul>
<li>Wiring the Arduino, Camera, and FPGA all together correctly such that the FPGA can successfully communicate color distinguishment to the Arduino</li>
</ul>
</li>
</ul>
</div>
</section>
<!-- Milestones -->
<section class="content-section bg-primary text-white text-center" id="milestones">
<div class="container">
<div class="content-section-heading">
<h2 class="mb-5">Let's Break it Down</h2>
</div>
<div class="row">
<div class="col-lg-3 col-md-6 mb-5 mb-lg-0">
<a href="#pll" class="text-white text-center js-scroll-trigger">
<span class="service-icon rounded-circle mx-auto mb-3">
<i class="far fa-lightbulb"></i>
</span>
<h4>
<strong>Phase-Locked Loop (PLL)</strong>
</h4>
<p class="text-faded mb-0"></p>
</a>
</div>
<div class="col-lg-3 col-md-6 mb-5 mb-lg-0">
<a href="#arduino" class="text-white text-center js-scroll-trigger">
<span class="service-icon rounded-circle mx-auto mb-3">
<i class="fas fa-screwdriver"></i>
</span>
<h4>
<strong>Arduino Side</strong>
</h4>
<p class="text-faded mb-0"></p>
</a>
</div>
<div class="col-lg-3 col-md-6 mb-5 mb-md-0">
<a href="#fpga" class="text-white text-center js-scroll-trigger">
<span class="service-icon rounded-circle mx-auto mb-3">
<i class="fas fa-toolbox"></i>
</span>
<h4>
<strong>FPGA Side</strong>
</h4>
<p class="text-faded mb-0"></p>
</a>
</div>
<div class="col-lg-3 col-md-6">
<a href="#problems" class="text-white text-center js-scroll-trigger">
<span class="service-icon rounded-circle mx-auto mb-3">
<i class="fas fa-car-crash"></i>
</span>
<h4>
<strong>Summary and Conclusions</strong>
</h4>
<p class="text-faded mb-0"></p>
</a>
</div>
</div>
</div>
</section>
<section class="content-section" id="pll">
<div class="container">
<h1>Phase Locked Loop (PLL)</h1>
<p>There are multiple clocks of different frequencies needed in our system; in order to lock them all together we initialized a phased- locked- loop (this ensures that there is minimal clock skew in our system). We created another file with an overall clock at 50 MHz. We then initialized each of our output clocks at 24, 25, and 50 MHz with 50% duty cycles. We then assigned an output pin for the 24 MHz clock (to be wired to the camera).</p>
</div>
</section>
<section id="analyzing_potentiometers" class="content-section bg-primary text-white">
<div class="container">
<h1>Arduino Side</h1>
<h3>Registers</h3>
<p>The registers we write to are described in the following table:</p>
<table style="width:100%">
<tr>
<th>Register</th>
<th>Address</th>
<th>Value</th>
<th>Purpose</th>
</tr>
<tr>
<td>COM7</td>
<td>0x12</td>
<td>0x80</td>
<td>Resets all registers to default values</td>
</tr>
<tr>
<td>COM3</td>
<td>0x0C</td>
<td>0x08</td>
<td>Enables scaling</td>
</tr>
<tr>
<td>CLKRC</td>
<td>0x11</td>
<td>0xC0</td>
<td>Enables ‘double-clocking’ and tells camera to use external clock</td>
</tr>
<tr>
<td>COM15</td>
<td>0x40</td>
<td>0xD0</td>
<td>Set output resolution to RGB-565</td>
</tr>
<tr>
<td>COM7</td>
<td>0x12</td>
<td>0x0E, 0x0C</td>
<td>QCIF format, and Color bar test enable, QCIF format, and Color bar test disable</td>
</tr>
<tr>
<td>COM17</td>
<td>0x42</td>
<td>0x08, 0x00</td>
<td>Enable color bar test, Disable color bar test</td>
</tr>
<tr>
<td>MVFP</td>
<td>0x1E</td>
<td>0x30</td>
<td>Flip and mirror the image</td>
</tr>
</table>
<p>Again, these values were determined by looking through the OV7670 data sheet.</p>
<h3>Writing Register Values from Arduino</h3>
<p>The wiring for the camera-Arduino is shown in the following picture:</p>
<div class="container">
<div class="row no-gutters">
<div class="col-lg-6">
<a class="portfolio-item">
<img class="img-fluid" src="img/lab4/arduino_diagram.png" alt="">
</a>
</div>
</div>
</div>
<p>Note: On the camera, the pins SIOC and SIOD correspond to SCL and SDA respectively.</p>
<h3>Receiving FPGA data</h3>
<p>We initialized 2 output pins in our Verilog code that would carry either 00 (neither), 01 (blue), or 10 (red). We then analyzed the output of the image processor (the RESULT variable) by linking each bit with an LED on the FPGA and examining which LEDs were lit. We used the LEDs to test whether our image processor worked, before hooking these pins from the FPGA up to the Arduino. The two pins were then directly connected into digital input pins on the Arduino with their variables initialized in the code. In order to show the code worked, we held a color test image up to the camera and then had the code print out whether it was red or blue. This function is relatively simple (just reading certain digital pins and outputting to serial monitor accordingly), and will be left off for brevity.</p>
<p>See a video of the FPGA sending color data to the Arduino:</p>
<iframe width="560" height="315" src="https://www.youtube.com/embed/sju5XPj3VnM" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
</section>
<section id="fpga" class="content-section">
<div class="container">
<h1>FPGA Side</h1>
<h3>Displaying M9K memory contents</h3>
<p>One of our initial tasks was to write a pattern directly into the FPGA memory and display it on the screen. We created an always block that updated on the positive edge of the 25MHz clock, that would enable memory writing if the X and Y addresses were inside the picture frame. We then wrote in colors directly into the pixel_data_RGB332 variable which would then be stored in the current address in memory, depending on whether they were in the range for the shape we wanted to create. The X and Y write addresses were subsequently changed as long as they were still within the screen width and height.</p>
<p>We successfully outputted our test pattern (a simple/arbitrary cross) as you can see below:</p>
<div class="container">
<div class="row no-gutters">
<div class="col-lg-6">
<a class="portfolio-item">
<img class="img-fluid" src="img/lab4/cross.jpg" alt="">
</a>
</div>
</div>
</div>
<h3>Down-sampler: color bar and camera feed</h3>
<p>The downsampler takes the RGB 565 format image from the camera and then turns it into 8 bits that can be stored in our memory. RGB 565 format for pixels means one pixel equates to two bytes of information (first 5 pixels red, next 3 green, then next 3 green last 5 blue). We essentially parse the 565 data into 332 data by selecting the most significant digits for each color and enter them into the 8 bit 332 format.</p>
<p>When the camera V_Sync signal is high, this signals the end of an entire frame, so we reset the X and Y addresses. When V_Sync is low, and HREF was high, pixel data is transmitted row by row. Since the RGB 565 pixel data comes in bytes, and each pixel is two bytes of 565 data, we have to read across two clock cycles (of PCLK, outputted from the camera) to get the full info of one pixel. We use an auxiliary variable to keep track of which pixel (first or second) we are receiving, and store the camera input data in a register. When HREF is low again, the row is over and the Y address updates (we move down a row).</p>
<p>Here is our down-sampler code:</p>
<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #888888">//Down-sampler</span>
<span style="color: #008800; font-weight: bold">always</span> @ ( <span style="color: #008800; font-weight: bold">posedge</span> <span style="color: #003366; font-weight: bold">P_CLOCK</span> ) <span style="color: #008800; font-weight: bold">begin</span>
<span style="color: #008800; font-weight: bold">if</span> ( old_vsync <span style="color: #333333">==</span> <span style="color: #005588; font-weight: bold">0</span> <span style="color: #333333">&&</span> <span style="color: #003366; font-weight: bold">V_SYNC</span><span style="color: #333333">==</span><span style="color: #005588; font-weight: bold">1</span> )<span style="color: #008800; font-weight: bold">begin</span> <span style="color: #888888">// V_SYNC marks the end of</span>
<span style="color: #888888">// a frame: reset X and Y.</span>
<span style="color: #003366; font-weight: bold">W_EN</span> <span style="color: #333333"><=</span> <span style="color: #005588; font-weight: bold">0</span>; <span style="color: #888888">// Don't write to memory!</span>
<span style="color: #003366; font-weight: bold">X_ADDR</span> <span style="color: #333333"><=</span> <span style="color: #005588; font-weight: bold">15</span><span style="color: #0000DD; font-weight: bold">'d0</span>;
<span style="color: #003366; font-weight: bold">Y_ADDR</span> <span style="color: #333333"><=</span> <span style="color: #005588; font-weight: bold">15</span><span style="color: #0000DD; font-weight: bold">'d0</span>;
i <span style="color: #333333"><=</span> <span style="color: #005588; font-weight: bold">0</span>;
<span style="color: #008800; font-weight: bold">end</span>
<span style="color: #008800; font-weight: bold">else</span> <span style="color: #008800; font-weight: bold">if</span> ((<span style="color: #003366; font-weight: bold">HREF</span> <span style="color: #333333">==</span> <span style="color: #005588; font-weight: bold">0</span>) <span style="color: #333333">&&</span> (old_href <span style="color: #333333">==</span> <span style="color: #005588; font-weight: bold">1</span>)) <span style="color: #008800; font-weight: bold">begin</span> <span style="color: #888888">// End of Row.</span>
<span style="color: #003366; font-weight: bold">W_EN</span> <span style="color: #333333"><=</span> <span style="color: #005588; font-weight: bold">0</span>; <span style="color: #888888">// Don't write anything here!!</span>
<span style="color: #003366; font-weight: bold">X_ADDR</span> <span style="color: #333333"><=</span> <span style="color: #005588; font-weight: bold">15</span><span style="color: #0000DD; font-weight: bold">'d0</span>; <span style="color: #888888">// Beginning of next row</span>
<span style="color: #003366; font-weight: bold">Y_ADDR</span> <span style="color: #333333"><=</span> <span style="color: #003366; font-weight: bold">Y_ADDR</span> <span style="color: #333333">+</span> <span style="color: #005588; font-weight: bold">15</span><span style="color: #0000DD; font-weight: bold">'d1</span>; <span style="color: #888888">// Move down to next row</span>
i <span style="color: #333333"><=</span> <span style="color: #005588; font-weight: bold">0</span>;
<span style="color: #008800; font-weight: bold">end</span>
<span style="color: #008800; font-weight: bold">else</span> <span style="color: #008800; font-weight: bold">begin</span>
<span style="color: #003366; font-weight: bold">Y_ADDR</span> <span style="color: #333333"><=</span> <span style="color: #003366; font-weight: bold">Y_ADDR</span>;
<span style="color: #008800; font-weight: bold">if</span> (<span style="color: #003366; font-weight: bold">HREF</span> <span style="color: #333333">==</span> <span style="color: #005588; font-weight: bold">1</span>) <span style="color: #008800; font-weight: bold">begin</span>
<span style="color: #008800; font-weight: bold">if</span> (i <span style="color: #333333">==</span> <span style="color: #005588; font-weight: bold">0</span>)<span style="color: #008800; font-weight: bold">begin</span> <span style="color: #888888">// First byte received of two.</span>
<span style="color: #888888">//(Blue info)</span>
<span style="color: #003366; font-weight: bold">W_EN</span> <span style="color: #333333"><=</span> <span style="color: #005588; font-weight: bold">0</span>; <span style="color: #888888">// DON'T WRITE TO</span>
<span style="color: #888888">// MEMORY YET!</span>
temp[<span style="color: #005588; font-weight: bold">7</span><span style="color: #333333">:</span><span style="color: #005588; font-weight: bold">0</span>] <span style="color: #333333"><=</span> CameraInput[<span style="color: #005588; font-weight: bold">7</span><span style="color: #333333">:</span><span style="color: #005588; font-weight: bold">0</span>];
<span style="color: #888888">// Save blue info!</span>
i <span style="color: #333333"><=</span> <span style="color: #005588; font-weight: bold">1</span>;
<span style="color: #003366; font-weight: bold">X_ADDR</span> <span style="color: #333333"><=</span> <span style="color: #003366; font-weight: bold">X_ADDR</span>;
<span style="color: #008800; font-weight: bold">end</span>
<span style="color: #008800; font-weight: bold">else</span> <span style="color: #888888">// i = 1 : second byte!</span>
<span style="color: #888888">// (Red & Green info)</span>
<span style="color: #008800; font-weight: bold">begin</span>
pixel_data_RGB332[<span style="color: #005588; font-weight: bold">7</span><span style="color: #333333">:</span><span style="color: #005588; font-weight: bold">5</span>] <span style="color: #333333"><=</span> CameraInput[<span style="color: #005588; font-weight: bold">7</span><span style="color: #333333">:</span><span style="color: #005588; font-weight: bold">5</span>];
<span style="color: #888888">// Red</span>
pixel_data_RGB332[<span style="color: #005588; font-weight: bold">4</span><span style="color: #333333">:</span><span style="color: #005588; font-weight: bold">2</span>] <span style="color: #333333"><=</span> CameraInput[<span style="color: #005588; font-weight: bold">2</span><span style="color: #333333">:</span><span style="color: #005588; font-weight: bold">0</span>];
<span style="color: #888888">// Green </span>
pixel_data_RGB332[<span style="color: #005588; font-weight: bold">1</span><span style="color: #333333">:</span><span style="color: #005588; font-weight: bold">0</span>] <span style="color: #333333"><=</span> temp[<span style="color: #005588; font-weight: bold">4</span><span style="color: #333333">:</span><span style="color: #005588; font-weight: bold">3</span>];
<span style="color: #888888">// Blue</span>
<span style="color: #888888">// Now the pixel is finished! Update</span>
<span style="color: #888888">// WRITE_ADDRESS and enable memory writing</span>
<span style="color: #003366; font-weight: bold">W_EN</span> <span style="color: #333333"><=</span> <span style="color: #005588; font-weight: bold">1</span>; <span style="color: #888888">// Memory is written.</span>
<span style="color: #003366; font-weight: bold">X_ADDR</span> <span style="color: #333333"><=</span> <span style="color: #003366; font-weight: bold">X_ADDR</span> <span style="color: #333333">+</span> <span style="color: #005588; font-weight: bold">15</span><span style="color: #0000DD; font-weight: bold">'d1</span>; <span style="color: #888888">// Update X</span>
i <span style="color: #333333"><=</span> <span style="color: #005588; font-weight: bold">0</span>;
<span style="color: #008800; font-weight: bold">end</span>
<span style="color: #008800; font-weight: bold">end</span>
<span style="color: #008800; font-weight: bold">else</span> <span style="color: #008800; font-weight: bold">begin</span>
<span style="color: #003366; font-weight: bold">X_ADDR</span> <span style="color: #333333"><=</span> <span style="color: #005588; font-weight: bold">0</span>;
i <span style="color: #333333"><=</span> <span style="color: #005588; font-weight: bold">0</span>;
<span style="color: #008800; font-weight: bold">end</span>
<span style="color: #008800; font-weight: bold">end</span>
old_vsync <span style="color: #333333">=</span> <span style="color: #003366; font-weight: bold">V_SYNC</span>;
old_href <span style="color: #333333">=</span> <span style="color: #003366; font-weight: bold">HREF</span>;
<span style="color: #008800; font-weight: bold">end</span>
</pre></div>
<p>In order to test that the correct colors were being constructed after the downsampling, we updated the registers in the Arduino code to show a color bar and then checked to see that the correct colors were shown. Below is a picture of the color bar test:</p>
<div class="container">
<div class="row no-gutters">
<div class="col-lg-6">
<a class="portfolio-item">
<img class="img-fluid" src="img/lab4/color_bar.JPG" alt="">
</a>
</div>
</div>
</div>
<p>We had trouble getting a consistent camera feed. While we managed to get reasonable colors and defined shapes, our video seemed to update in bars, which was best described as “flickering”. Despite looking through our code many times, analyzing the clocks, replacing all the hardware, and rewiring at least once, we were unable to get a clean image unless the gain was turned very low, at which point the feed was very dark.</p>
<p>Here is a video of this raw, imperfect camera feed:</p>
<iframe width="560" height="315" src="https://www.youtube.com/embed/Ob7xX0_PDgk" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<p>However, after playing around with some more camera registers, we were able to obtain a relatively clean output. This is the register that alters the gain ceiling, which makes the image very dark, but smoothes out the camera feed. We added the following register to our list of registers to write in the Arduino file:</p>
<ul>
<li>Register: COM9</li>
<li>Address: 0x14</li>
<li>Value: 0x0A</li>
<li>Purpose: After the gain ceiling</li>
</ul>
<p>And here is a video of the clean feed:</p>
<iframe width="560" height="315" src="https://www.youtube.com/embed/1ZIq0y7bGI8" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<h3>Color Distinguishment</h3>
<p>We wrote the image processor module to identify what was the dominant color of the camera's current frame. We created registers which update each time the RGB pixels from the downsampler with the color that is the largest in those bits. At the end of a frame, the totals are compared and the output RESULT is assigned to either 9’b01 if blue or 9’b10 if red, before all the variables are reset.</p>
<p>To test the image processor we assigned LEDs on the FPGA to light up according to which color was observed by the camera (as described in Arduino-Side, 3. Receiving FPGA data).</p>
<p>Here is our image-processor (color-detection) code:</p>
<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #008800; font-weight: bold">always</span> @ ( <span style="color: #008800; font-weight: bold">posedge</span> <span style="color: #003366; font-weight: bold">CLK</span> ) <span style="color: #008800; font-weight: bold">begin</span>
<span style="color: #888888">// If we've reached the end of a frame, compare red and blue, and</span>
<span style="color: #888888">// output accordingly.</span>
<span style="color: #888888">// red = RESULT[1] high, and blue = RESULT[0] high</span>
<span style="color: #008800; font-weight: bold">if</span> (<span style="color: #003366; font-weight: bold">VGA_VSYNC_NEG</span>) <span style="color: #008800; font-weight: bold">begin</span>
<span style="color: #888888">// RED</span>
<span style="color: #008800; font-weight: bold">if</span> ( redcounter <span style="color: #333333">></span> bluecounter ) <span style="color: #008800; font-weight: bold">begin</span>
res <span style="color: #333333">=</span> <span style="color: #005588; font-weight: bold">9'b10</span>;
<span style="color: #008800; font-weight: bold">end</span>
<span style="color: #888888">// BLUE</span>
<span style="color: #008800; font-weight: bold">else</span> <span style="color: #008800; font-weight: bold">if</span> ( redcounter <span style="color: #333333"><</span> bluecounter ) <span style="color: #008800; font-weight: bold">begin</span>
res <span style="color: #333333">=</span> <span style="color: #005588; font-weight: bold">9'b01</span>;
<span style="color: #008800; font-weight: bold">end</span>
<span style="color: #888888">// NEITHER</span>
<span style="color: #008800; font-weight: bold">else</span> <span style="color: #008800; font-weight: bold">begin</span>
res <span style="color: #333333">=</span> <span style="color: #005588; font-weight: bold">9'b00</span>;
<span style="color: #008800; font-weight: bold">end</span>
red <span style="color: #333333">=</span> <span style="color: #005588; font-weight: bold">0</span>;
blue <span style="color: #333333">=</span> <span style="color: #005588; font-weight: bold">0</span>;
<span style="color: #008800; font-weight: bold">end</span>
<span style="color: #888888">// Mid-frame, increment red and blue</span>
<span style="color: #008800; font-weight: bold">else</span> <span style="color: #008800; font-weight: bold">begin</span>
<span style="color: #888888">// Increment Red</span>
<span style="color: #008800; font-weight: bold">if</span> ( ( <span style="color: #003366; font-weight: bold">PIXEL_IN</span>[<span style="color: #005588; font-weight: bold">7</span><span style="color: #333333">:</span><span style="color: #005588; font-weight: bold">6</span>] <span style="color: #333333">></span> <span style="color: #003366; font-weight: bold">PIXEL_IN</span>[<span style="color: #005588; font-weight: bold">1</span><span style="color: #333333">:</span><span style="color: #005588; font-weight: bold">0</span>] ) <span style="color: #333333">&&</span> ( <span style="color: #003366; font-weight: bold">PIXEL_IN</span>[<span style="color: #005588; font-weight: bold">7</span><span style="color: #333333">:</span><span style="color: #005588; font-weight: bold">6</span>] <span style="color: #333333">></span> <span style="color: #005588; font-weight: bold">2'b10</span> ) ) <span style="color: #008800; font-weight: bold">begin</span>
red <span style="color: #333333">=</span> red <span style="color: #333333">+</span> <span style="color: #005588; font-weight: bold">1</span>;
<span style="color: #008800; font-weight: bold">end</span>
<span style="color: #888888">// Increment Blue</span>
<span style="color: #008800; font-weight: bold">if</span> ( ( <span style="color: #003366; font-weight: bold">PIXEL_IN</span>[<span style="color: #005588; font-weight: bold">1</span><span style="color: #333333">:</span><span style="color: #005588; font-weight: bold">0</span>] <span style="color: #333333">></span> <span style="color: #003366; font-weight: bold">PIXEL_IN</span>[<span style="color: #005588; font-weight: bold">7</span><span style="color: #333333">:</span><span style="color: #005588; font-weight: bold">6</span>] ) <span style="color: #888888">/*&& ( PIXEL_IN[1:0] > PIXEL_IN[4:3] ) */</span>) <span style="color: #008800; font-weight: bold">begin</span>
blue <span style="color: #333333">=</span> blue <span style="color: #333333">+</span> <span style="color: #005588; font-weight: bold">1</span>;
<span style="color: #008800; font-weight: bold">end</span>
redcounter <span style="color: #333333">=</span> red;
bluecounter <span style="color: #333333">=</span> blue;
<span style="color: #008800; font-weight: bold">end</span>
<span style="color: #008800; font-weight: bold">end</span>
</pre></div>
<p>And here is a video of the full color detection system (referred in section Arduino-Side, 3. Receiving FPGA Data):</p>
<iframe width="560" height="315" src="https://www.youtube.com/embed/sju5XPj3VnM" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<p>Note that our FPGA’s 2-bit treasure signal implicitly signifies whether or not there is a treasure (i.e. 00 = no treasure, 01 = blue treasure, 10 = red treasure). So, this system effectively communicates whether or not there is a treasure, and what color it is.</p>
</div>
</section>
<section id="problems" class="content-section bg-primary text-white">
<div class="container">
<h1>Summary and Conclusions</h1>
<p>As demonstrated in our video above, our color-detection system, by and large, works! We found that it worked best when we did left the gain-ceiling register on the camera to its default value. I.e., while the camera feed may look, er….. unpleasant, our color-detection seems to work regardless.</p>
<p>This lab was a huge learning experience for our team; none of us ever had extensive experience with coding and debugging an FPGA with verilog until this lab. We definitely gained some valuable debugging and problem-solving skills.</p>
</div>
</section>
<!-- Map -->
<!-- POINT TO PHILLIPS -->
<section id="contact" class="map">
<iframe width="100%" height="100%" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.com/maps?q=phillips%20hall%2C%20ithaca&t=&z=13&ie=UTF8&iwloc=&output=embed"></iframe>
<br/>
<small>
<a href="https://www.google.com/maps/place/Phillips+Hall/@42.4445807,-76.4842416,17z/data=!4m7!3m6!1s0x89d0818c816cffe3:0xfd9ee07ff22c5aa4!8m2!3d42.4445768!4d-76.4820529!9m1!1b1"></a>
</small>
</section>
<!-- Footer -->
<footer class="footer text-center">
<div class="container">
<ul class="list-inline mb-5">
<li class="list-inline-item">
<a class="social-link rounded-circle text-white" href="https://github.com/ece3400-team16">
<i class="icon-social-github"></i>
</a>
</li>
</ul>
<p class="text-muted small mb-0">Copyright © ECE 3400 2018</p>
</div>
</footer>
<!-- Scroll to Top Button-->
<a class="scroll-to-top rounded js-scroll-trigger" href="#page-top">
<i class="fas fa-angle-up"></i>
</a>
<!-- Bootstrap core JavaScript -->
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Plugin JavaScript -->
<script src="vendor/jquery-easing/jquery.easing.min.js"></script>
<!-- Custom scripts for this template -->
<script src="js/stylish-portfolio.min.js"></script>
</body>
</html>