Propeller Education Kit Labs
Fundamentals
Version 1.2
(web release 2)
By Andy Lindsay
WARRANTY
Parallax Inc. warrants its products against defects in materials and workmanship for a period of 90 days from receipt of product. If you
discover a defect, Parallax Inc. will, at its option, repair or replace the merchandise, or refund the purchase price. Before returning the
product to Parallax, call for a Return Merchandise Authorization (RMA) number. Write the RMA number on the outside of the box used to
return the merchandise to Parallax. Please enclose the following along with the returned merchandise: your name, telephone number,
shipping address, and a description of the problem. Parallax will return your product or its replacement using the same shipping method
used to ship the product to Parallax.
14-DAY MONEY BACK GUARANTEE
If, within 14 days of having received your product, you find that it does not suit your needs, you may return it for a full refund. Parallax
Inc. will refund the purchase price of the product, excluding shipping/handling costs. This guarantee is void if the product has been altered
or damaged. See the Warranty section above for instructions on returning a product to Parallax.
COPYRIGHTS AND TRADEMARKS
This documentation is copyright © 2006-2010 by Parallax Inc. By downloading or obtaining a printed copy of this documentation or
software you agree that it is to be used exclusively with Parallax products. Any other uses are not permitted and may represent a violation of
Parallax copyrights, legally punishable according to Federal copyright or intellectual property laws. Any duplication of this documentation
for commercial uses is expressly prohibited by Parallax Inc. Duplication for educational use is permitted, subject to the following
Conditions of Duplication: Parallax Inc. grants the user a conditional right to download, duplicate, and distribute this text without Parallax's
permission. This right is based on the following conditions: the text, or any portion thereof, may not be duplicated for commercial use; it
may be duplicated only for educational purposes when used solely in conjunction with Parallax products, and the user may recover from the
student only the cost of duplication.
This text is available in printed format from Parallax Inc. Because we print the text in volume, the consumer price is often less than typical
retail duplication charges.
Propeller, Penguin, and Spin are trademarks of Parallax Inc. BASIC Stamp, Stamps in Class, Boe-Bot, SumoBot, Scribbler, Toddler, and
SX-Key are registered trademarks of Parallax, Inc. If you decide to use any trademarks of Parallax Inc. on your web page or in printed
material, you must state that (trademark) is a (registered) trademark of Parallax Inc.” upon the first appearance of the trademark name in
each printed document or web page. Other brand and product names herein are trademarks or registered trademarks of their respective
holders.
ISBN 9781928982555
1.2.0-10.07.12-HKTP —
(WEB RELEASE 2)
DISCLAIMER OF LIABILITY
Parallax Inc. is not responsible for special, incidental, or consequential damages resulting from any breach of warranty, or under any legal
theory, including lost profits, downtime, goodwill, damage to or replacement of equipment or property, or any costs of recovering,
reprogramming, or reproducing any data stored in or used with Parallax products. Parallax Inc. is also not responsible for any personal
damage, including that to life and health, resulting from use of any of our products. You take full responsibility for your Propeller
microcontroller application, no matter how life-threatening it may be.
INTERNET DISCUSSION LISTS
We maintain active web-based discussion forums for people interested in Parallax products. These lists are accessible from
www.parallax.com via the Support
→
Discussion Forums menu. These are the forums that we operate from our web site:
Propeller Chip – This list is specifically for our customers using Propeller chips and products.
BASIC Stamp – This list is widely utilized by engineers, hobbyists and students who share their BASIC Stamp projects
and ask questions.
Stamps in Class
®
– Created for educators and students, subscribers discuss the use of the Stamps in Class series of tutorials
in their courses. The list provides an opportunity for both students and educators to ask questions and get answers.
Parallax Educators – A private forum exclusively for educators and those who contribute to the development of Stamps in
Class and Propeller Education materials. Parallax created this group to obtain feedback on our educational materials and to
provide a place for educators to develop and share classroom resources.
Robotics – Designed for Parallax robots, this forum is intended to be an open dialogue for robotics enthusiasts using the
Boe-Bot
®
, SumoBot
®
, Scribbler
®
or their own custom robots built with Parallax microcontrollers and sensors..
Sensors – A place to discuss interfacing Parallax sensors to microcontrollers.
PropScope – Discussion and technical assistance for using this PC-based digital storage oscilloscope and logic analyzer,
designed with a Propeller P8X32A on board.
HYDRA Game Development – For creating and sharing games on this Propeller P8X32A-based system.
ERRATA
While great effort is made to assure the accuracy of our texts, errors may still exist. If you find an error, please let us know by sending an
email to editor@parallax.com. We continually strive to improve all of our educational materials and documentation, and frequently revise
our texts. Occasionally, an errata sheet with a list of known errors and corrections for a given text will be posted to our web site,
www.parallax.com. Please check the individual product page’s free downloads for an errata file.
Table of Contents
Table of Contents
PREFACE............................................................................................................................................... 5
1: PROPELLER MICROCONTROLLER & LABS OVERVIEW .............................................................. 7
The Propeller Microcontroller ............................................................................................................. 7
The Propeller Education Kit Hardware............................................................................................. 12
The Propeller Education Kit Labs..................................................................................................... 14
2: SOFTWARE, DOCUMENTATION & RESOURCES ........................................................................ 17
Download Software and Documentation.......................................................................................... 17
Useful Web Sites.............................................................................................................................. 18
Tech Support Resources ................................................................................................................. 18
3: SETUP AND TESTING LAB FOR 40-PIN DIP PE PLATFORM ...................................................... 19
The PE Platform ............................................................................................................................... 19
Procedure Overview......................................................................................................................... 23
Inventory Equipment and Parts........................................................................................................ 24
Assemble the Breadboards.............................................................................................................. 25
Set up PE Platform Wiring and Voltage Regulators......................................................................... 27
Test the PE Platform Wiring............................................................................................................. 29
Socket the Propeller Chip and EEPROM......................................................................................... 30
Load a Test Program and Test the I/O Pins .................................................................................... 32
Before Changing or Adjusting Circuits ............................................................................................. 37
Propeller Supply Voltage Regulation – It’s Important! ..................................................................... 37
Troubleshooting for the 40-Pin DIP PE Platform Setup ................................................................... 39
4: I/O AND TIMING BASICS LAB......................................................................................................... 45
Introduction....................................................................................................................................... 45
Propeller Nomenclature.................................................................................................................... 46
Lights on with Direction and Output Register Bits............................................................................ 47
I/O Pin Group Operations................................................................................................................. 49
Reading an Input, Controlling an Output.......................................................................................... 50
Timing Delays with the System Clock .............................................................................................. 51
System Clock Configuration and Event Timing................................................................................ 53
More Output Register Operations .................................................................................................... 55
Conditional Repeat Commands ....................................................................................................... 57
Operations in Conditions and Pre and Post Operator Positions...................................................... 58
Some Operator Vocabulary.............................................................................................................. 60
Shifting LED Display......................................................................................................................... 61
Variable Example ............................................................................................................................. 62
Timekeeping Applications ................................................................................................................ 64
Study Time ....................................................................................................................................... 66
5: METHODS AND COGS LAB............................................................................................................ 69
Introduction....................................................................................................................................... 69
Defining a Method’s Behavior with Local Variables ......................................................................... 70
Calling a Method .............................................................................................................................. 70
Launching Methods into Cogs.......................................................................................................... 73
How Much Stack Space for a Method Launched into a Cog? ......................................................... 75
Method Calls and the Result Variable.............................................................................................. 77
Cog ID Indexing................................................................................................................................ 78
Study Time ....................................................................................................................................... 80
Propeller Education Kit Labs: Fundamentals
·
Page 3
Table of Contents
6: OBJECTS LAB................................................................................................................................. 83
Introduction ...................................................................................................................................... 83
Method Call Review......................................................................................................................... 85
Calling Methods in Other Objects with Dot Notation ....................................................................... 85
Objects that Launch Processes into Cogs....................................................................................... 88
Conventions for Start and Stop Methods in Library Objects ........................................................... 92
Documentation Comments .............................................................................................................. 92
Public vs. Private methods .............................................................................................................. 95
Multiple Object Instances................................................................................................................. 96
Propeller Chip – PC Terminal Communication................................................................................ 97
Parallax Serial Terminal.spin and Other Library Objects .............................................................. 102
Sending Values from Parallax Serial Terminal to the Propeller Chip ............................................ 106
Terminal I/O Pin Input State Display ............................................................................................. 109
Terminal LED Output Control ........................................................................................................ 111
The DAT Block and Address Passing ........................................................................................... 112
The Float and FloatString Objects ................................................................................................. 114
Objects that Use Variable Addresses............................................................................................ 115
Passing Starting Addresses to Objects that Work with Variable Lists........................................... 117
Study Time..................................................................................................................................... 120
7: COUNTER MODULES AND CIRCUIT APPLICATIONS LAB ....................................................... 125
Introduction .................................................................................................................................... 125
How Counter Modules Work.......................................................................................................... 126
Measuring RC Decay with a Positive Detector Mode.................................................................... 126
D/A Conversion – Controlling LED Brightness with DUTY Modes ................................................ 135
Special Purpose Registers ............................................................................................................ 140
Generating Piezospeaker Tones with NCO Mode......................................................................... 143
Applications - IR Object and Distance Detection with NCO and DUTY Modes ............................ 153
Counting Transitions with POSEDGE and NEGEDGE Modes ..................................................... 158
PWM with the NCO Modes............................................................................................................ 162
Probe and Display PWM – Add an Object, Cog and Pair of Counters.......................................... 165
PLL Modes for High-Frequency Applications ................................................................................ 171
Metal Detection with an LC Circuit Using PLL and POS Detector Modes..................................... 176
Study Time..................................................................................................................................... 185
APPENDIX A: OBJECT CODE LISTINGS ........................................................................................ 191
Parallax Serial Terminal.spin ......................................................................................................... 191
SquareWave.spin .......................................................................................................................... 200
APPENDIX B: STUDY SOLUTIONS ................................................................................................. 201
I/O and Timing Basics Lab Study Solutions .................................................................................. 201
Methods and Cogs Lab Study Solutions ....................................................................................... 207
Objects Lab Study Solutions.......................................................................................................... 209
Counter Modules and Circuit Applications Lab Study Solutions ................................................... 214
APPENDIX C: PE KIT COMPONENTS LISTING .............................................................................. 224
APPENDIX D: PROPELLER P8X32A BLOCK DIAGRAM ................................................................ 226
APPENDIX E: LM2940CT-5.0 CURRENT LIMIT CALCULATIONS.................................................. 227
INDEX ................................................................................................................................................ 229
Page 4
·
Propeller Education Kit Labs: Fundamentals
Preface
Preface
Since the Propeller chip comes in a 40-Pin DIP package, a pluggable breadboard kit for the Propeller
chip made a lot of sense. The support circuits for the Propeller chip, including EEPROM program
memory, voltage regulators, crystal oscillator, and Propeller Plug programming tool are all also
available in versions that can be plugged into a breadboard, so why not? It also makes a great deal of
sense from the college and university lab standpoint. Provide a simple kit that students can afford,
that is reusable, with a microcontroller that excels in a multitude of electronics, robotics, and
embedded systems projects. With that in mind, the PE DIP Plus Kit was put together, as a bag that
includes the Propeller microcontroller, “plus” all the other parts you might need to make it work.
The PE DIP Plus Kit made sense for folks who have already have breadboards and some experience,
but what about a student who maybe just completed the Stamps in Class
What’s a Microcontroller
tutorial, and is interested in approaching the Propeller chip as a kit and tutorial as well? With this
student in mind, another bag of parts was assembled, along with a series of activities that put the parts
in the bag to work with the Propeller microcontroller. The bag of parts ended up with the name PE
Project Parts, and the activities became the PE Kit Labs.
The PE Kit Labs in this text are written primarily for college and university students with some
previous programming and electronics experience, preferably with microcontrollers. Subjects
introduced include:
Microcontroller basics such as I/O control and timing with the system clock
Programming topics such as operators, method calls, and objects, and variable addresses
Programmed multiprocessor control
Microcontroller-circuit interactions with indicator lights, pushbuttons, circuits that sense the
environment and can be measured with RC decay, frequency circuits (speakers), and
frequency selective circuits
Advanced topics include utilizing counter modules to perform tasks in the background
This collection of PE Kit Labs is intended give the reader a good start with programming the
Propeller chip and using it in projects. However, this book is just a start. Introducing all aspects of
the Propeller microcontroller with PE Kit Labs would take several such books, so additional labs are
available online. More labs and applications will be posted periodically.
This text also includes pointers to the wealth of information available for the Propeller chip in the
Propeller Manual, Propeller Datasheet, Propeller Forum, and Propeller Object Exchange, as well as
examples of using these resources. The reader is especially encouraged to utilize the Propeller
Manual as a reference while going through these labs. The Propeller Manual’s contents and index
will provide references to more information about any topic introduced in these labs.
The Propeller Chip Forum at forums.parallax.com has a Propeller Education Kit Labs sticky-thread
with links to discussions about each lab. The reader is encouraged to utilize this resource for posting
questions about topics in the PE Kit Labs as well as comments and suggestions. Parallax collects this
feedback and incorporates it into future revisions of each lab. Also, if you (or your students)
prototyped something cool with the PE Kit, by all means, post your documented project to the forums
so that others can see what you did and how you did it.
Propeller Education Kit Labs: Fundamentals
·
Page 5