-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstep_1.html
More file actions
506 lines (485 loc) · 20.3 KB
/
step_1.html
File metadata and controls
506 lines (485 loc) · 20.3 KB
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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>PIC Circuits</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="generator" content="Org-mode" />
<style type="text/css">
<!--/*--><![CDATA[/*><!--*/
.title { text-align: center; }
.todo { font-family: monospace; color: red; }
.done { color: green; }
.tag { background-color: #eee; font-family: monospace;
padding: 2px; font-size: 80%; font-weight: normal; }
.timestamp { color: #bebebe; }
.timestamp-kwd { color: #5f9ea0; }
.right { margin-left: auto; margin-right: 0px; text-align: right; }
.left { margin-left: 0px; margin-right: auto; text-align: left; }
.center { margin-left: auto; margin-right: auto; text-align: center; }
.underline { text-decoration: underline; }
#postamble p, #preamble p { font-size: 90%; margin: .2em; }
p.verse { margin-left: 3%; }
pre {
border: 1px solid #ccc;
box-shadow: 3px 3px 3px #eee;
padding: 8pt;
font-family: monospace;
overflow: auto;
margin: 1.2em;
}
pre.src {
position: relative;
overflow: visible;
padding-top: 1.2em;
}
pre.src:before {
display: none;
position: absolute;
background-color: white;
top: -10px;
right: 10px;
padding: 3px;
border: 1px solid black;
}
pre.src:hover:before { display: inline;}
pre.src-sh:before { content: 'sh'; }
pre.src-bash:before { content: 'sh'; }
pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
pre.src-R:before { content: 'R'; }
pre.src-perl:before { content: 'Perl'; }
pre.src-java:before { content: 'Java'; }
pre.src-sql:before { content: 'SQL'; }
table { border-collapse:collapse; }
caption.t-above { caption-side: top; }
caption.t-bottom { caption-side: bottom; }
td, th { vertical-align:top; }
th.right { text-align: center; }
th.left { text-align: center; }
th.center { text-align: center; }
td.right { text-align: right; }
td.left { text-align: left; }
td.center { text-align: center; }
dt { font-weight: bold; }
.footpara:nth-child(2) { display: inline; }
.footpara { display: block; }
.footdef { margin-bottom: 1em; }
.figure { padding: 1em; }
.figure p { text-align: center; }
.inlinetask {
padding: 10px;
border: 2px solid gray;
margin: 10px;
background: #ffffcc;
}
#org-div-home-and-up
{ text-align: right; font-size: 70%; white-space: nowrap; }
textarea { overflow-x: auto; }
.linenr { font-size: smaller }
.code-highlighted { background-color: #ffff00; }
.org-info-js_info-navigation { border-style: none; }
#org-info-js_console-label
{ font-size: 10px; font-weight: bold; white-space: nowrap; }
.org-info-js_search-highlight
{ background-color: #ffff00; color: #000000; font-weight: bold; }
/*]]>*/-->
</style>
<link rel="stylesheet" type="text/css" href="css/styles.css"/>
<link href='http://fonts.googleapis.com/css?family=Ubuntu+Mono|Ubuntu' rel='stylesheet' type='text/css'>
<script type="text/javascript">
/*
@licstart The following is the entire license notice for the
JavaScript code in this tag.
Copyright (C) 2012-2013 Free Software Foundation, Inc.
The JavaScript code in this tag is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
@licend The above is the entire license notice
for the JavaScript code in this tag.
*/
<!--/*--><![CDATA[/*><!--*/
function CodeHighlightOn(elem, id)
{
var target = document.getElementById(id);
if(null != target) {
elem.cacheClassElem = elem.className;
elem.cacheClassTarget = target.className;
target.className = "code-highlighted";
elem.className = "code-highlighted";
}
}
function CodeHighlightOff(elem, id)
{
var target = document.getElementById(id);
if(elem.cacheClassElem)
elem.className = elem.cacheClassElem;
if(elem.cacheClassTarget)
target.className = elem.cacheClassTarget;
}
/*]]>*///-->
</script>
<script type="text/javascript" src="http://orgmode.org/mathjax/MathJax.js"></script>
<script type="text/javascript">
<!--/*--><![CDATA[/*><!--*/
MathJax.Hub.Config({
// Only one of the two following lines, depending on user settings
// First allows browser-native MathML display, second forces HTML/CSS
// config: ["MMLorHTML.js"], jax: ["input/TeX"],
jax: ["input/TeX", "output/HTML-CSS"],
extensions: ["tex2jax.js","TeX/AMSmath.js","TeX/AMSsymbols.js",
"TeX/noUndefined.js"],
tex2jax: {
inlineMath: [ ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"], ["\\begin{displaymath}","\\end{displaymath}"] ],
skipTags: ["script","noscript","style","textarea","pre","code"],
ignoreClass: "tex2jax_ignore",
processEscapes: false,
processEnvironments: true,
preview: "TeX"
},
showProcessingMessages: true,
displayAlign: "center",
displayIndent: "2em",
"HTML-CSS": {
scale: 100,
availableFonts: ["STIX","TeX"],
preferredFont: "TeX",
webFont: "TeX",
imageFont: "TeX",
showMathMenu: true,
},
MMLorHTML: {
prefer: {
MSIE: "MML",
Firefox: "MML",
Opera: "HTML",
other: "HTML"
}
}
});
/*]]>*///-->
</script>
</head>
<body>
<div id="content">
<h1 class="title">PIC Circuits</h1>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#sec-1">1. Getting started with PIC circuit design.</a>
<ul>
<li><a href="#sec-1-1">Design time</a></li>
<li><a href="#sec-1-2">Coding time</a></li>
</ul>
</li>
<li><a href="#sec-2">2. Adding Inputs</a>
<ul>
<li><a href="#sec-2-1">Design time</a></li>
<li><a href="#sec-2-2">Coding time</a></li>
</ul>
</li>
<li><a href="#sec-3">3. Digital Vs. Analogue</a>
<ul>
<li><a href="#sec-3-1">Design time</a></li>
<li><a href="#sec-3-2">Save It</a></li>
<li><a href="#sec-3-3">Code It</a></li>
<li><a href="#sec-3-4">Try It</a></li>
</ul>
</li>
<li><a href="#sec-4">4. Badge It</a>
<ul>
<li><a href="#sec-4-1">Assessment Task</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class=ribbon>
<a href="https://github.com/stsb11/pic_programmer">Fork me on GitHub</a>
</div>
<center>
<img src='img/pic4.jpg' width=33%>
</center>
<div id="outline-container-sec-1" class="outline-2 activity">
<h2 id="sec-1"><span class="section-number-2">1</span> Getting started with PIC circuit design.</h2>
<div class="outline-text-2" id="text-1">
</div>
<div id="outline-container-sec-1-1" class="outline-3 design">
<h3 id="sec-1-1">Design time</h3>
<div class="outline-text-3" id="text-1-1">
<ul class="org-ul">
<li>Open up Circuit Wizard, and create the following circuit layout. The Genie C08 chip can be found in the "Microcontrollers" drop-down menu item.
</li>
</ul>
<div class="figure">
<p><img src="img/step_1.png" alt="step_1.png" />
</p>
</div>
<ul class="org-ul">
<li>Whether its an LED or a PIC chips, the first thing that electronic components need is power, and a connection to ground. Circuit Wizard simplifies this for us by showing each of the 8 legs of the PIC (known as pins) in a different order to how they really are. This makes drawing the initial circuit easier. In this case, Power has been drawn by itself at the top of the chip, and the ground pin (the negative end of a battery) is at the bottom.
</li>
<li>When designing PIC circuits, Inputs are placed to the left of the PIC chip. We're not going to worry about these for now.
</li>
<li>Outputs are placed to the right of the PIC chip. In the project you're making, you'll actually use 3 LEDs, connected to the other output pins. For now, we can just leave outputs 2 and 4 empty.
</li>
<li>One of great things about the Genie C08 PIC is that you can change the configuration of the pins; with this particular project, we'll be using pins 0, 1 and 2 for outputs, and pin 4 for our input. This is because when the PCB was designed, using this arrangement allowed us to make the PCB smaller with this setup.
</li>
</ul>
<div class="figure">
<p><img src="./img/rclick.png" alt="rclick.png" />
</p>
</div>
<ul class="org-ul">
<li>To change the configuration, start by <b>right-clicking</b> on the Genie chip in Circuit Wizard. From the menu that appears, then choose <b>Program</b> and then <b>Program settings</b>.
</li>
</ul>
<div class="figure">
<p><img src="./img/changepins.png" alt="changepins.png" />
</p>
</div>
<ul class="org-ul">
<li>At the bottom of the window that appears, click the drop-down list, and choose the option that says, "<b>2 inputs, 3 outputs (G0-G2)</b>". Now click "Ok".
</li>
<li>Try and run the circuit. You'll see an error message, and the screen will change to show you a green flowchart symbol with the word, "Start" in it. This is because the PIC chip needs you to give it instructions as to what you'd like it to do. Using shapes located on the right-hand side of the screen and experimenting with clicking near the shapes you've drawn, create the following flowchart. We're going to make the LED blink on and off.
</li>
</ul>
<div class="figure">
<p><img src="img/step_2.png" alt="step_2.png" />
</p>
</div>
<ul class="org-ul">
<li>If you had to guess, you could probably figure out that instructions are followed starting from "Start", and following the arrows to the bottom, before being started all over again endlessly. If you've tried to run the program, you'll see that its still not sure what you'd like it to do.
</li>
<li>Before it can run, the PIC chip needs a little more information. Which output(s) are we turning on? How long are we to wait for?
</li>
</ul>
<div class="figure">
<p><img src="img/step_3.png" alt="step_3.png" />
</p>
</div>
<ul class="org-ul">
<li>Double click on the top parallelogram (the top output shape), and slowly click twice on the faint letter 'x' that is just underneath output 0 until it turns green, then click "Ok".
</li>
<li>Repeat for the other output shape, but this time click only once to turn it to "0".
</li>
<li>Finally, double-click on each of the "Wait" shapes, and type "2" in the time boxes.
</li>
<li>Time to test your first PIC circuit. Click the, "Circuit Diagram" tab in the bottom-left-hand corner of the Circuit Wizard window, then click the play icon to start the simulation. Your program is now working as follows:
</li>
</ul>
<div class="org-src-container">
<pre class="src src-html">1. Turn on output 0 (the LED),
2. Wait 2 seconds,
3. Turn off output 0 (the LED),
4. Wait 2 seconds,
5. Go to line 1.
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-2" class="outline-3 run">
<h3 id="sec-1-2">Coding time</h3>
<div class="outline-text-3" id="text-1-2">
<ul class="org-ul">
<li>Try and modify your program and answer the questions below on a Word document. You'll be saving this circuit in your home drive later.
</li>
<li>Make the LED blink on and off twice as quickly.
</li>
<li>Why are there two wait shapes, and not just one?
</li>
<li>Modify your program, so that it comes on for 2s, off for 1s, on for 1s and off for 2s before repeating.
</li>
<li>Modify your program so that the LED comes on for 3s ONCE, then blinks steadily on and off once a second until the program is stopped.
</li>
<li>Save your file as FirstPIC.cwz in your Systems and Control\pic\ folder, then save it again straight away as SecondPic.cwz, so that you can make the next set of changes and still have a backup.
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-sec-2" class="outline-2 activity">
<h2 id="sec-2"><span class="section-number-2">2</span> Adding Inputs</h2>
<div class="outline-text-2" id="text-2">
</div>
<div id="outline-container-sec-2-1" class="outline-3 design">
<h3 id="sec-2-1">Design time</h3>
<div class="outline-text-3" id="text-2-1">
<ul class="org-ul">
<li>Our PIC so far is quite limited. While its great that it can flash in patterns (it could signal SOS in <a href="http://en.wikipedia.org/wiki/Morse_code">Morse</a> code), but PICs become more powerful when they can interact with the World around them.
</li>
<li>Modify your circuit diagram to add a PTM (Push to Make) switch and 10k resistor, as shown in the screenshot below. Make sure you connect the bottom of the switch to input 3 on the PIC.
</li>
</ul>
<div class="figure">
<p><img src="img/step_4.png" alt="step_4.png" />
</p>
</div>
<ul class="org-ul">
<li>If you run your circuit now, you'll see that clicking the button doesn't change the way the program behaves. This is because we've not told the PIC what we'd like to do yet.
</li>
<li>Go back to your Flowchart, and add a "Digital" diamond to the top of the program, as shown in the picture below. Double-click the diamond, and set it to check if input 1 is turned on.
</li>
</ul>
<div class="figure">
<p><img src="img/step_5.png" alt="step_5.png" />
</p>
</div>
<ul class="org-ul">
<li>Connect the flow lines as shown in the picture above, then go back to your circuit and run it. Click on the switch to see what happens.
</li>
<li>Now go back to the flowchart and click play. While the simulation is running, you can click once on the diamond, and simulate pushing button 3 from there.
</li>
</ul>
</div>
</div>
<div id="outline-container-sec-2-2" class="outline-3 run">
<h3 id="sec-2-2">Coding time</h3>
<div class="outline-text-3" id="text-2-2">
<ul class="org-ul">
<li>Modify the program so that pushing the button and holding it down turns on the LED, and releasing it turns it off. Save this as "PIC Torch.cwz"
</li>
<li>Change it again, so that when you push and hold the button, it flashes on and off slowly. When the button is released, make it flash quickly.
</li>
<li>Add two more LEDs to your circuit diagram, and make a note of which output pin they're connected to. You can change their colour by double-clicking them. Make output 0 red, output 1 amber and output 2 green.
</li>
<li>Write a program that makes each of the LEDs come on for 2s at a time while the button is held down. When released, they should all turn off.
</li>
<li>You can turn on multiple LEDs at once. Modify the code so that when the button is pushed, they simulate a set of <a href="http://www.drivingtesttips.biz/traffic-lights-sequence.html">traffic lights</a> (make then change once every 2s). Save this as "PIC-traffic.cwz".
</li>
<li>Congratulations! This program (or any of the others you've made) could be put straight onto the circuit you're going to make in your practical sessions.
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-sec-3" class="outline-2 activity">
<h2 id="sec-3"><span class="section-number-2">3</span> Digital Vs. Analogue</h2>
<div class="outline-text-2" id="text-3">
</div>
<div id="outline-container-sec-3-1" class="outline-3 design">
<h3 id="sec-3-1">Design time</h3>
<div class="outline-text-3" id="text-3-1">
<ul class="org-ul">
<li>We've nearly covered all the theory we'll need for this project. The last stage is to add the type of intput your project will use.
</li>
<li>Some input components are digital. This means that they can only be either 'on' or 'off', like switches or buttons.
</li>
<li>Some input components are analogue. This means they can have a range of different values, like a <a href="http://en.wikipedia.org/wiki/Photoresistor">LDR</a> or <a href="http://en.wikipedia.org/wiki/Thermistor">thermistor</a>.
</li>
<li>LDRs work because their resistance increases as it gets darker, and when connected to an analogue input on a PIC chip, this can be read as a number between 0 (very dark) and 255 (extremely bright).
</li>
<li>Modify your circuit diagram, by swapping the PTM switch for an LDR (found in the Sensors section of Input Components in Circuit Wizard).
</li>
<li><span class="underline"><b>NOTE:</b></span> The LDR is connected to input 4. This is because an LDR is an analogue component, so needs to be connected to an input that can accept it (notice the /A after G4 in the picture below).
</li>
</ul>
<div class="figure">
<p><img src="img/step_6.png" alt="step_6.png" />
</p>
</div>
<ul class="org-ul">
<li>Your circuit should now look something like the picture above.
</li>
<li>Lets look at the results of this work. Click the 'play' button to run the circuit, then click the text saying, 'View the analogue sensor readings' which can be seen on the far right-hand side of the circuit wizard window, about half-way down the screen.
</li>
</ul>
<div class="figure">
<p><img src="img/step_7.png" alt="step_7.png" />
</p>
</div>
<ul class="org-ul">
<li>Your screen should look the same as shown above. If you now click once on the LDR symbol on the circuit diagram, you can simulate a change in light level by dragging
</li>
<li>We can now be a little more flexible about how our programs work. With a digital switch, we're no longer limited to "is it on?". We could program our chip to work as a light meter, for instance.
</li>
</ul>
</div>
</div>
<div id="outline-container-sec-3-2" class="outline-3 save">
<h3 id="sec-3-2">Save It</h3>
<div class="outline-text-3" id="text-3-2">
<p>
Save your work as "Analogue PIC.cwz".
</p>
</div>
</div>
<div id="outline-container-sec-3-3" class="outline-3 run">
<h3 id="sec-3-3">Code It</h3>
<div class="outline-text-3" id="text-3-3">
<ul class="org-ul">
<li>Using the analogue diamond shape in Circuit Wizard, create the following program…
</li>
</ul>
<div class="figure">
<p><img src="img/step_12.png" alt="step_12.png" />
</p>
</div>
<ul class="org-ul">
<li>Note the values I used on the decision diamonds.
</li>
<li>Make sure with your output parallelograms that you turn off any outputs that aren't being turned on. For instance, in the bottom-left shape, I turned output 0 on, and also turned off outputs 1 and 2.
</li>
<li>Test your program when finished, and see how changing the light level affects how many LEDs are turned on.
</li>
</ul>
</div>
</div>
<div id="outline-container-sec-3-4" class="outline-3 try">
<h3 id="sec-3-4">Try It</h3>
<div class="outline-text-3" id="text-3-4">
<ul class="org-ul">
<li>Try adding another decision box to turn all 3 LEDs on when the light level is even higher.
</li>
<li>Try adding another decision box (and adjusting the others), so that all the LEDs are off when its dark, then one, two or 3 come up as it gets brighter.
</li>
<li>Then change it again so that when its really bright, all 3 LEDS flash on and off repeatedly.
</li>
<li>Save your best program as, "my analogue program.cwz".
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-sec-4" class="outline-2 activity">
<h2 id="sec-4"><span class="section-number-2">4</span> Badge It</h2>
<div class="outline-text-2" id="text-4">
</div>
<div id="outline-container-sec-4-1" class="outline-3 design">
<h3 id="sec-4-1">Assessment Task</h3>
<div class="outline-text-3" id="text-4-1">
<p>
Create a text document and answer the following questions:
</p>
<ul class="org-ul">
<li>What are the advantages of using PIC chips over traditional circuit design?
</li>
<li>Giving examples, explain the difference between analogue and digital input components.
</li>
<li>In programming, what is meant by the term, "loop"? Why is is often advantageous to have programs use these, rather than running through their code from top to bottom?
</li>
<li>Write down the purpose of each pin on a Genie C08. E.g. Pin 1 - Power, Pin 2 -… etc. You can find out most of these by hovering the mouse over the pins in Circuit Wizard, but for some, you'll need to explore the Circuit Wizard help files.
</li>
</ul>
<p>
<a href="index.html">Return to homepage</a>
</p>
</div>
</div>
</div>
</div>
<div id="postamble" class="status">
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
</body>
</html>