0
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
会员中心
创作中心
发布
  • 发文章

  • 发资料

  • 发帖

  • 提问

  • 发视频

创作活动
130-32000

130-32000

  • 厂商:

    PARALLAXINC.

  • 封装:

    -

  • 描述:

    KIT PROPELLER EDU PROJECT PARTS

  • 数据手册
  • 价格&库存
130-32000 数据手册
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 Preface About Version 1.2 This revision replaces the cadmium sulfide based photoresistor with a cadmium-free phototransistor that meets the European Union’s Restriction of Hazardous Substances guidelines. The Setup and Testing instructions include additions for enhanced Propeller supply voltage stability. In addition, the Parallax Serial Terminal object replaces the FullDuplexSerial Plus object. Acknowledgements Parallaxians:  Author: Andy Lindsay, Applications Engineer  Cover art: Jennifer Jacobs, Art Director  Editing: Stephanie Lindsay, Technical Editor  Illustrations: Andy Lindsay, with help from Rich Allred, Manufacturing Lead  Photography: Rich Allred  Review: Jessica Uelmen, Education Associate Parallax Community – thanks to:  Aaron Klapheck for commented code illustrating cog variable bookkeeping in the Advanced Topic: Inside Start and Stop methods section of the Objects Lab.  Engineering students at University of California Davis and California State University Sacramento who used the PE Kit in their projects and submitted great questions and bug reports.  Steve Nicholson for his incisive and thorough review of earlier drafts of the PE Kit Labs. Page 6 · Propeller Education Kit Labs: Fundamentals 1: Propeller Microcontroller & Labs Overview 1: Propeller Microcontroller & Labs Overview This chapter provides an abbreviated overview of the Propeller Microcontroller and some introductory information about the Propeller Education Kit and Labs. More detailed information about the Propeller microcontroller, its architecture, and programming languages can be found in the Propeller Manual and Propeller Datasheet. Both are available from the Downloads link at www.parallax.com/Propeller. The Propeller Microcontroller The Propeller Microcontroller in Figure 1-1 (a) is a single chip with eight built-in 32-bit processors, called cogs. Cogs can be programmed to function simultaneously, both independently and cooperatively with other cogs. In other words, cogs can all function simultaneously, but whether they function independently or cooperatively is defined by the program. Groups of cogs can be programmed to work together, while others work on independent tasks. A configurable system clock supplies all the cogs with the same clock signal (up to 80 MHz). Figure 1-1 (b) shows how each cog takes turns at the option for exclusive read/write access of the Propeller chip’s main memory via the Hub. Exclusive read/write access is important because it means that two cogs cannot try to modify the same item in memory at the same instance. It also prevents one cog from reading a particular address in memory at the same time another cog is writing to it. So, exclusive access ensures that there are never any memory access conflicts that could corrupt data. Figure 1-1: Propeller Microcontroller Packages and Hub and Cog Interaction (a) Propeller microcontrollers in 40-pin DIP, TSOP and QFN packages (b) Excerpt from Propeller Block Diagram describing Hub and Cog interaction. See Appendix D: Propeller P8X32A Block Diagram 32 KB of the Propeller chip’s main memory is RAM used for program and data storage, and another 32 KB is ROM, and stores useful tables such as log, antilog, sine, and graphic character tables. The ROM also stores boot loader code that cog 0 uses at startup and interpreter code that any cog can use to fetch and execute application code from main memory. Each cog also has the ability to read the states of any or all of the Propeller chip’s 32 I/O pins at any time, as well as set their directions and output states at any time. Propeller Education Kit Labs: Fundamentals · Page 7 Propeller Microcontroller & Labs Overview The Propeller chip’s unique multiprocessing design makes a variety of otherwise difficult microcontroller applications relatively simple. For example, processors can be assigned to audio inputs, audio outputs, mouse, keyboard, and maybe a TV or LCD display to create a microcontroller based computer system, with processors left over to work on more conventional tasks such as monitoring inputs and sensors and controlling outputs and actuators. Figure 1-2 (a) shows a Propeller chip-generated video image that could be used in that this kind of application. The Propeller also excels as a robotic controller, with the ability to assign processors to tasks such as PWM DC motor control, video processing, sensor array monitoring, and high speed communication with nearby robots and/or PCs. Figure 1-2 (b) shows an example of a Propeller controlled balancing robot with video sensor. The initial prototype was developed with a Propeller Education Kit. Although the Propeller chip is very powerful, that doesn’t mean it is difficult to use. The Propeller chip also comes in handy for simple projects involving indicator lights, buttons, sensors, speakers, actuators, and smaller displays found in common product designs. You will see examples of such simple circuits in the following Propeller Education Kit Labs. Figure 1-2: Application Examples (a) Propeller microcontroller generated graphic TV display. This application also uses a standard PS/2 mouse to control the graphics (not shown). (b) Hanno Sander’s balancing robot, initial prototype developed with the Propeller Education Kit and ViewPort software. Photo courtesy of mydancebot.com. Applications with the Propeller Chip Programs for the Propeller chip are written with PC software and then loaded into the Propeller chip, typically via a USB connection. The languages supported by Parallax’ free Propeller Tool software include a high-level language called Spin, and a low-level assembly language. Applications developed in Spin language can optionally contain assembly language code. These applications are stored on your PC as .spin files.  Other programming languages have been developed for programming the Propeller chip. Some are free and available through resources like the Parallax forums and Source Forge; others are available for purchase or free in a limited version through the Parallax web site and other companies that sell compilers. Before a cog can start executing a Spin application, it has to first load an Interpreter from the Propeller chip’s ROM (Figure 1-3 a). Spin applications get stored in main memory’s RAM as tokens, which the interpreter code makes the cog repeatedly fetch and execute (Figure 1-3 b & c). A few Page 8 · Propeller Education Kit Labs: Fundamentals 1: Propeller Microcontroller & Labs Overview examples of actions the cog might take based on the token values are shown in Figure 1-3 (c). They include read/writes to configuration registers, variables, and I/O pins as well as reads from ROM. Cogs can also execute the machine codes generated by assembly language. As shown in Figure 1-4, these machine codes get loaded into the cog’s 2 KB (512 longs) of RAM and executed at a very high speed, up to 20 million instructions per second (MIPS). Cog RAM not used by machine instructions can also provide high speed memory for the cog with four clock cycles (50 ns at 80 MHz) per read/write. Figure 1-3: Cog Interpreting Spin Language Main (Hub) Memory Main (Hub) Memory Configuration Configuration 32 KB R A M 32 KB Application R A M Stack + VAR Character Set COG Fetch/Execute Configuration Application R A M Stack + VAR Character Set COG R O Log, Antilog, & Sine Tables M R Log, Antilog, & Sine Tables O M Boot Loader Interpreter Application Stack + VAR Character Set COG R O Log, Antilog, & Sine Tables M Boot Loader Interpreter (a) Interpreter loaded into cog from Main Memory’s ROM through Hub Main (Hub) Memory Boot Loader Interpreter (b) Cog fetches token from Main Memory’s RAM I/O (c) Cog executes token. Examples include RAM, I/O or config read/write, or ROM read A cog executing assembly language can also access the Propeller chip’s main memory through the Hub. The Hub grants main memory access to each cog every 16 clock cycles. Depending on when the cog decides to check with main memory, the access time could take anywhere from 7 to 22 clock cycles, which equates to a worst case memory access time of 275 ns at 80 MHz. After the first access, assembly code can synchronize with the cog’s round-robin access window to main memory, keeping the subsequent access times fixed at 16 clock cycles (200 ns). Main (Hub) Memory Configuration R A M Application 4 clock cycles Stack + VAR Character Set R O Log, Antilog, & Sine Tables M 7 to 22 clock cycles, 16 cycles when synchronized ASM Cog RAM 2 KB (512 long) Figure 1-4: Cog Executing Assembly Language COG Boot Loader Interpreter Propeller Education Kit Labs: Fundamentals · Page 9 Propeller Microcontroller & Labs Overview Since each cog has access to the Propeller chip’s RAM in main memory, they can work cooperatively by exchanging information. The Spin language has built-in features to pass the addresses of one or more variables used in code to other objects and cogs. This makes cog cooperation very simple. Code in one cog can launch code into another cog and pass it one or more variable addresses (see Figure 1-5). These variable addresses can then be used for the two cogs to exchange information. Main (Hub) Memory Configuration R A M Application COG Stack + VAR Figure 1-5: Two (or more) Cog’s Working Cooperatively through Shared Memory Character Set COG R O Log, Antilog, & Sine Tables M Boot Loader Interpreter The Propeller chip’s cogs are numbered cog 0 through cog 7. After the application is loaded into the Propeller chip, it loads an interpreter into cog 0, and this interpreter starts executing Spin code tokens stored in main memory. Commands in the Spin code can then launch blocks of code (which might be Spin or assembly language) into other cogs as shown in Figure 1-6. Code executed by the other cogs can launch still other cogs regardless of whether they are Spin or assembly, and both languages can also stop other cogs for the sake of ending unnecessary processes or even replacing them with different ones. 2 1 0 COG COG 3 COG COG 4 Figure 1-6: Cog Launching Code in one cog launching other cogs, which can in turn launch others… Cogs can also stop other cogs to free them up for other tasks. COG Writing Application Code Spin is an object-based programming language. Objects are designed to be the building blocks of an application, and each .spin file can be considered an object. While an application can be developed as a single object (one program), applications are more commonly a collection of objects. These objects can provide a variety of services. Examples include solutions for otherwise difficult coding problems, communication with peripheral devices, controlling actuators and monitoring sensors. These building block objects are distributed through the Propeller Object Exchange (obex.parallax.com) and also in the Propeller Tool software’s Propeller Library folder. Incorporating these pre-written objects into an application can significantly reduce its complexity and development time. Page 10 · Propeller Education Kit Labs: Fundamentals 1: Propeller Microcontroller & Labs Overview Figure 1-7 shows how objects can be used as application building blocks, in this case, for a robot that maintains a distance between itself and a nearby object it senses. The application code in the Following Robot.spin object makes use of pre-written objects for infrared detection (IR Detector.spin), control system calculations (PID.spin), and motor drive (Servo Control.spin). Note that these pre-written objects can in turn use other objects to do their jobs. Instead of harvesting objects that do jobs for your application, you can also write them from scratch, and if they turn out to be useful, by all means, submit them for posting to the Propeller Object Exchange at obex.parallax.com. Top Object File Launches a cog Spin code only Figure 1-7: Object Building Blocks for Applications Launches a cog Spin + ASM In Figure 1-7, the Following Robot.spin object is called the top object file. This file has the first executable line of code where the Propeller chip starts when the application runs. In every case, cog 0 is launched and begins executing code from the top object. Our top object example, Following Robot.spin, contains code to initialize the three objects below it, making it the “parent object” of the three. Two of these three building blocks in turn initialize “child object” building blocks of their own. Two of the building block objects launch additional cogs to do their jobs, so a total of three cogs are used by this application. Regardless of whether a parent object launches a cog to execute Spin code or assembly code, the child objects have built-in Spin code and documentation that provide a simple interface for code in their parent objects to control/monitor them. Though it is not shown in our example, recall from Figure 1-6 that an object can launch more than one cog. Also, an object can launch a process into a cog and then shut it down again to make it available to other objects. Although any object can actually start and stop any cog, it's a good practice to make stopping a cog the responsibility of the object that started it. How the Propeller Chip Executes Code The Parallax Propeller Tool software can be used to develop applications and load them into the Propeller chip. When an application is loaded into the Propeller chip, the Spin code is compiled into tokens and the optional assembly code is compiled into machine codes. The Propeller Tool then Propeller Education Kit Labs: Fundamentals · Page 11 Propeller Microcontroller & Labs Overview transfers the application to the Propeller chip, typically with a serial-over-USB connection. The programmer can choose to load it directly into the Propeller chip’s main RAM, or into an EEPROM (electrically erasable programmable read-only memory). As shown in Figure 1-8, if the program is loaded directly into RAM, the Propeller chip starts executing it immediately. If the program is loaded into an EEPROM, the Propeller chip copies this information to RAM before it starts executing. Figure 1-8: Loading a Program into RAM or EEPROM Propeller Code Propeller Code Serial over USB (a) Load program directly into Propeller RAM Copy to EEPROM Load from EEPROM after Reset Serial over USB (b) Load program into EEPROM Loading programs from a PC into RAM takes around 1 second, whereas loading programs into EEPROM takes a few seconds (under 10 seconds for most). While loading programs into RAM can be a lot quicker for testing the results of changes during code development, programs should be loaded into EEPROM when the application is deployed, or if it is expected to restart after a power cycle or reset. Programs loaded into RAM are volatile, meaning they can be erased by a power interruption or by resetting the Propeller chip. In contrast, programs loaded into EEPROM are nonvolatile. After a power cycle or reset, the Propeller chip copies the program from EEPROM into RAM and then starts executing it again. The Propeller Education Kit Hardware The Propeller Education (PE) Kit is a complete Propeller microcontroller development system that can be used for projects and product prototypes. This kit also includes parts for projects that are documented by the PE Kit Labs. These labs will help you learn how to develop applications with the Propeller Microcontroller. Figure 1-9: Propeller Education Kit (40-Pin DIP Version) Page 12 · Propeller Education Kit Labs: Fundamentals 1: Propeller Microcontroller & Labs Overview The PE Kit comes in two different versions: 40-pin DIP and PropStick USB. Both feature an arrangement of interlocking breadboards with the following parts mounted on them:         Propeller microcontroller 5.0 V and 3.3 V voltage regulators EEPROM for non-volatile program storage 5.00 MHz external crystal oscillator for precise clock signal Reset button for manual program restarts LED power indicator 9 V battery-to-breadboard connector Serial to USB connection for downloads and bidirectional communication with the PC. Collectively, the interlocking breadboards with Propeller microcontroller system mounted on it are referred to in this document as the PE Platform. The PE Platform with the 40-pin DIP kit is also shown in Figure 1-10 (a). With this platform, each part and circuit in the list above is plugged directly into the breadboard. Although this version of the PE Platform takes a little while to build and test, the advantage is that any given part can be replaced at a very low cost. The PE Platform with the PropStick USB is shown in Figure 1-10 (a). The PropStick USB module is a small printed circuit board (PCB) with surface-mount versions of all the parts and circuits listed above (except the external 5 V regulator circuit). The PCB itself has pins so that it can be plugged into the breadboard. While this arrangement makes it quick wire up the PE Platform and get started, it can be relatively expensive to replace the PropStick USB rather than individual components if something gets damaged. Figure 1-10: PE Kit Platforms (a) 40-pin DIP Version (b) PropStick USB Version Propeller Education Kit Labs: Fundamentals · Page 13 Propeller Microcontroller & Labs Overview The Propeller Education Kit Labs The Propeller Education Kit Labs include the ones printed in this text as well as additional labs and applications available for download from www.parallax.com/go/PEKit. The labs in this text demonstrate how to connect circuits to the Propeller microcontroller and write programs that make the Propeller chip interact with the circuits. The programs also utilize the Spin programming language’s features as well as the Propeller microcontroller’s multiprocessing capabilities. Prerequisites These labs assume prior microcontroller experience. Although the Setup and Testing labs provide wiring diagrams, the rest do not. At a minimum, you should have experience building circuits from schematics as well as experience with some form of computer or microcontroller programming language.  Resources for Beginners: For introductions to building circuits, microcontroller programming, and much more “prior microcontroller experience”, try either the BASIC Stamp Activity Kit or BASIC Stamp Discovery kit. Both kits have everything you’ll need to get started, including a BASIC Stamp 2 microcontroller, project board, the introductory level What’s a Microcontroller? text and parts for every activity. The What’s a Microcontroller? text is also available for free PDF download from www.parallax.com/go/WAM, and both kits are available for purchase from the web site as well as from a variety of electronics retailers and distributors. To find a retailer or distributor near you, check the Distributors list under the Company category at the Parallax web site. PE Kit Labs in This Text       Software, Documentation & Resources – Download Propeller software and documentation, and install the software. Setup and Testing Lab for 40-Pin DIP PE Platform – Hardware preparation. If you have the PropStick USB Version of the PE Kit, use its alternative Setup and Testing Lab. It is a free download from www.parallax.com/go/PEKit. I/O and Timing Basics Lab – How to configure the Propeller chip’s I/O pins, monitor input signals, transmit output signals, and coordinate when events happen based on the system clock. Methods and Cogs – How to write methods in Spin and optionally launch methods into one or more of the Propeller chip’s cogs (processors). Objects – How use pre-written objects to simplify coding tasks, and how to write objects. Counter Modules and Circuit Applications – How to employ the counter modules built into each cog to perform measurements and control processes that require precise timing. (Each cog has two counter modules that can function in parallel with the cog’s program thread.) The last four labs (I/O and Timing through Counter Modules and Circuit Applications) have questions, exercises, and projects at the end of the chapter with answers in Appendix B: Study Solutions, starting on page 201. For best results, hand-enter the code examples as you go through the labs. It’ll give your mind time to consider each line of code along with the concepts and techniques introduced in the various sections of each lab. Page 14 · Propeller Education Kit Labs: Fundamentals 1: Propeller Microcontroller & Labs Overview More PE Kit Labs & Applications Online To find additional labs and applications that build on the concepts introduced in this book, go to www.parallax.com/go/PEKit. You will find links to PDFs and discussions for each of the labs in this text along with additional material, like the ViewPort lab excerpt shown in Figure 1-11. Some of these labs will utilize the parts on the PE Kit, and others require additional parts, most of which are available from Parallax or other electronics suppliers. Figure 1-11: ViewPort Lab Excerpt Oscilloscope and spectrum analyzer display signals generated by a microphone as someone whistles into it. The Propeller chip samples these signals and forwards them to the ViewPort PC Software. This is one of the activities featured in the ViewPort Lab. Propeller Education Kit Labs: Fundamentals · Page 15 Propeller Microcontroller & Labs Overview Page 16 · Propeller Education Kit Labs: Fundamentals 2: Software, Documentation & Resources 2: Software, Documentation & Resources The labs in this book require the free software shown in Figure 2-1. You’ll use the Propeller Tool to write programs for the Propeller chip, and the Parallax Serial Terminal will provide bidirectional text communication between the PC and Propeller chip. Both are included in the Propeller Tool Software Installer (please use v1.3 or newer). The installer also includes PDF versions of this book, the Propeller Manual, and Propeller Datasheet, along with the example code. Figure 2-1: Propeller Tool (left) and Parallax Serial Terminal (right) Download Software and Documentation  Go to www.parallax.com/Propeller → Downloads & Articles,  Download the Propeller Tool Software v1.3 or newer (requires Win2K/XP/Vista/7)  Install the Propeller Tool software by running the setup program and following the prompts. When you get to the Install Optional Driver Step shown below, make sure to leave the Automatically install/update driver box checked. (You can also check for the latest drivers at www.parallax.com/usbdrivers.) Leave this checkbox checked! !  If you are using the PropStick USB version of the PE Kit, be sure to locate its separate Setup and Testing Lab PDF file from www.parallax.com/go/PEKit. Propeller Education Kit Labs: Fundamentals · Page 17 Software, Documentation & Resources Accessing the Software and Documentation The installer should make program shortcuts to both the Propeller Tool and Parallax Serial Terminal. They are also accessible from the Start menu → All Programs → Parallax Inc → Propeller Tool. The same Start menu path will also lead you to a Reference folder with many documentation resources, as shown in Figure 2-2. These PDF files can also be opened through the Propeller Tool’s Help menu. Figure 2-2: PDF Resources included with the Propeller Tool software Accessing the Example Code The Propeller Tool includes several sets of example code, available from the File → Open From menu as shown in Figure 2-3. The example code for this book is included. Figure 2-3: Example code sets in the File → Open From menu Useful Web Sites In addition to www.parallax.com/Propeller, there are a couple of other web sites where you can get answers to questions as well as objects to reduce your development time on Propeller projects.    Additional labs and resources for your Propeller Education Kit: www.parallax.com/go/PEKit Object exchange: http://obex.parallax.com Propeller Chip forum: http://forums.parallax.com → Propeller Tech Support Resources Parallax Inc. offers several avenues for free technical support services:  Email: support@parallax.com  Fax: (916) 624-8003  Telephone: Toll free in the U.S: (888) 99-STAMP; or (916) 624-8333. Please call between the hours of 7:00 am and 5:00 pm Pacific time, or leave us a message.  Propeller Chip Forum: Propeller Chip forum: http://forums.parallax.com → Propeller. Here you will find an active, moderated forum dedicated to the Propeller chip, frequented by both Parallax customers and employees. Page 18 · Propeller Education Kit Labs: Fundamentals 3: Setup and Testing Lab 3: Setup and Testing Lab for 40-Pin DIP PE Platform This is the Setup and Testing lab for the 40-pin DIP version of the PE Kit.  If you have the 40-Pin DIP version of the PE Kit (#32305), continue here.  If you have the PropStick USB version of the PE Kit (#32306), check for a separate printed Setup and Testing Lab - PropStick USB Version document included with your kit. It is also a free download from www.parallax.com/go/PEKit. The PE Platform The Propeller Education (PE) Kit Platform shown in Figure 3-1 makes a great reusable prototyping tool for electronics and robotics projects. It’s also a great starting point for learning the basics of programming the Propeller microcontroller to be the embedded computer brain in your next invention. This lab introduces the 40-Pin DIP PE Platform and its components and features, and then guides you through assembling and testing your PE Platform. Figure 3-1: PE Kit Platform (40-Pin DIP version) The PE Platform in Figure 3-1 is an array of breadboards connected side-by-side with the Propeller chip and support circuits mounted in the center. Each project circuit you build on the left or right breadboards will be adjacent to Propeller chip I/O pins for easy access. Each breadboard also has vertical power connectors on both sides so that ground and regulated 3.3 V are next to any given breadboard row. This arrangement makes most circuits very simple to wire and visually track. It also minimizes the wiring spaghetti and troubleshooting problems that can occur with tall individual breadboards. Propeller Education Kit Labs: Fundamentals · Page 19 Setup and Testing Lab PE Platform Components and Features Figure 3-2 shows the 40-Pin DIP PE Platform’s major components, including:         Propeller microcontroller with pin map sticker affixed 9 V battery-to-breadboard connector 5.0 V and 3.3 V voltage regulators LED power indicator Reset button for manual program restarts 5.00 MHz external crystal oscillator for precise clock signal 32 KB EEPROM for non-volatile program storage Propeller Plug programming and communication tool for program downloads and bidirectional communication with the PC. Figure 3-2: PE Kit Platform Components 9 V batterytobreadboard connector 3.3 V voltage regulator USB Cable 5.0 V voltage regulator LED Power Indicator Propeller Plug programming & communication tool Reset Button Propeller Microcontroller + Pin Map Sticker 32 KB EEPROM 5 MHz Crystal Oscillator Propeller Microcontroller A Propeller Microcontroller in a 40-pin DIP package provides a breadboard friendly brain for the PE Platform. This amazing microcontroller has eight processors, called cogs. Its system clock can run at up to 80 MHz, and each cog can execute up to 20 million instructions per second (MIPS). Each cog takes turns at accessing the Propeller chip’s main memory. This memory access combined with the Spin (high level) and Assembly (low level) languages created especially for the Propeller makes writing code for multiple processors very simple and straightforward. If you’ve ever written a BASIC subroutine and subroutine call (or a C function and function call, or a Java method and method call), making a different processor execute that subroutine/function/method takes just two more steps. You’ll see lots of examples of this as you go through the PE Kit Labs. Propeller Datasheet and Propeller Manual  The Propeller Datasheet provides a complete technical description of the Propeller microcontroller, and the Propeller Manual explains the chip’s programming software and languages in detail. Both the Propeller Datasheet and Propeller Manual are included in PDF form in the Propeller Tool software. The printed version of the Propeller Manual is also available for purchase at www.parallax.com (#122-32000). Page 20 · Propeller Education Kit Labs: Fundamentals 3: Setup and Testing Lab Reset Button The reset button can be pressed and released to restart program execution. It can also be pressed and held to halt program execution. When released, the Propeller chip will load the program stored in PE Platform’s EEPROM program and restart from the beginning. 9 V Battery-to-Breadboard Connector This little gadget provides a simple, breadboard-friendly power supply connection. The recommended DC supply voltage across VIN–VSS is 6 to 9.5 VDC, and recommended power sources for VIN−VSS include:   9 V alkaline batteries Rechargeable 9 V batteries (common voltage ratings include 9 V, 8.4 V, and 7.2 V) Always disconnect the battery from the connector and store separately. 9 V batteries should never be stored in the same box as the PE Kit platform or components because loose parts could short across the terminals. The 9 V battery should always be disconnected from the battery-to-breadboard connector and stored where its terminals cannot short across any metal objects or other conductive materials.  “Wall Warts”: The term “wall wart” commonly describes the DC supplies that draw power from AC wall outlets, and they often supply a much higher DC voltage than they are rated for. If you are going to use a wall wart, it’s usually best to choose one that’s rated for 6 V regulated DC output with a current capacity of 500 mA or more. The PE DIP Plus kit includes a 47 µF capacitor that can be placed across the battery inputs on the breadboard to provide the input capacitance required by the PE Platform’s voltage regulator due to the wall wart’s longer supply line. 5.0 V Regulator The National Semiconductor LM2940CT-5.0 regulator is included in the PE Platform to make it convenient to supply 5 V components, such as the infrared detector introduced in the Counter Modules and Circuit Applications lab. A series resistor (typically 10 kΩ) should always be connected between a 5 V output and a Propeller I/O pin, which is 3.3 V. The 5 V regulator also serves as an intermediate stage between the battery input voltage and the 3.3 V regulator that supplies the Propeller chip. The LM2940 voltage regulator circuit is designed to provide a 400 mA output current budget with a 9 V battery supply in the classroom or lab (at room temperature). This current budget can vary with supply voltage and temperature. For example, if the supply voltage reduced from 9 V to 7.5 V, the current budget increases to nearly 700 mA at room temperature. Another example, if the supply voltage is 9 V, but the ambient temperature is 100 F (40 C), the current budget drops to around 350 mA. More Info:    Appendix E: LM2940CT-5.0 Current Limit Calculations beginning on page 227 includes equations you can use to predict the PE Kit’s 5 V regulator circuit’s current budgets under various supply voltage and temperature conditions. The LM2940CT datasheet, available from www.national.com, has lots more information, including pointers for attaching a heatsink to the LM2940 to increases its current/temperature budget by improving its ability to dissipate heat 3.3 V Regulator This National Semiconductor LM2937ET-3.3 regulator can draw up to 400 mA from the PE Platform’s LM2940 (5 V regulator) at room temperature and supply the 3.3 V system with up to 360 mA of current. The 3.3 V system includes the Propeller chip, EEPROM, power LED, and the variety of 3.3 V circuits you will build in the PE Kit Labs. Propeller Education Kit Labs: Fundamentals · Page 21 Setup and Testing Lab Keep in mind that if you have a power-hungry 5 V circuit, it subtracts current from the 5 V regulator’s 400 mA output current budget, which in turn leaves the 3.3 V regulator with a smaller current budget to supply the rest of the system. LED Power Indicator This light turns on to indicate that power is connected to the board. It can also provide indications of dead batteries, short circuits, and even tell you if the Propeller Plug programming and communication tool is connected. As wired in this lab, it draws about 12 mA. After completing this lab, you can use a larger resistor for a less-bright indicator light that draws less current. 5.00 MHz Crystal Oscillator and Socket The 5.00 MHz crystal oscillator provides the Propeller chip with a precise clock signal that can be used for time-sensitive applications such as serial communication, RC decay measurements and servo control. The Propeller chip has built-in phase locked loop circuitry that can use the 5.00 MHz oscillator signal to generate system clock frequencies of 5, 10, 40 or even 80 MHz. The 5.00 MHz oscillator can also be replaced with a variety of other oscillators. A few examples include a programmable oscillator and a 60 MHz crystal. The Propeller chip also has a built-in RC oscillator that can be used in fast or slow modes (approximately 12 MHz and 20 kHz respectively). The internal oscillators are not nearly as precise as the 5.00 MHz oscillator, so if your project involves time-sensitive tasks such as serial communication, pulse width modulation for servo control, or TV signal generation, make sure to use the external 5.00 MHz oscillator. 32 KB EEPROM The PE Platform’s 32 KB EEPROM program and data storage memory is non-volatile, meaning it can’t be erased by pressing and releasing the reset button or disconnecting and reconnecting power. This EEPROM memory should not be treated like RAM because each of its memory cells is only good for 1 million erase/write cycles. After that, the cell can actually wear out and no longer reliably store values. So, a program that modifies an EEPROM cell once every second would wear it out in only 11.6 days. On the other hand, if a cell gets modified every ten minutes, it’ll be good for over 19 years.  EEPROM: Electrically Erasable Programmable Read-Only Memory RAM: Random Access Memory. Keep in mind that your application can use the Propeller chip’s main memory (32 KB of which is RAM) for indefinite writes and rewrites at any frequency. It can then use the EEPROM to back up data that the application may need later, especially if that data has to live through disconnecting and reconnecting power. The EEPROM Datalogging Application (available at www.parallax.com → Propeller → Downloads & Articles) introduces an object that can be used to periodically back up values stored in RAM to EEPROM. Propeller Plug Programming and Communication Tool The Propeller Plug provides a serial-over-USB connection between the Propeller chip and PC for programming, communication, and debugging. This tool’s blue LED indicates messages received from the PC, while the red one indicates messages transmitted to the PC. The FTDI chip labeled FT232 on the module converts USB signals from the PC to 3.3 V serial signals for the Propeller chip and vice versa. Page 22 · Propeller Education Kit Labs: Fundamentals 3: Setup and Testing Lab On the PC side, a virtual COM port driver provided by FTDI is bundled with the Propeller Tool software you installed in the previous chapter. Aside from being necessary for the Propeller Tool software to load programs into the Propeller chip, the virtual COM port makes it convenient for the Propeller chip to communicate with serial software such as Parallax Serial Terminal. More Virtual COM Port Info  After the FTDI virtual COM Port driver is installed by the Propeller Tool Installer, a Propeller Plug that gets connected to one of the PC’s USB ports appears as a “USB Serial Port (COMXX)” in the Windows Device Manager’s Ports (COM & LPT) list. The FTDI driver converts data placed in the COM port’s serial transmit buffer to USB and sends it to the Propeller Plug’s FT232 chip, and USB messages from the FT232 are converted to serial data and stored in the COM port’s receive buffer. Serial communication software like the Propeller Tool and Parallax Serial Terminal use these COM port buffers to exchange information with peripheral serial devices. Prerequisites Please follow the directions in Software, Documentation & Resources, starting on page 17, before continuing here. Procedure Overview In this lab, you will assemble the PE Platform (40-Pin DIP version), following the steps listed below. It’s important to follow the instructions for each step carefully, especially since you will be wiring up your own development platform (on the breadboard) instead of just plugging the Propeller microcontroller into a socket on a carrier PCB.           Inventory Equipment and Parts Assemble the Breadboards Set up PE Platform Wiring and Voltage Regulators Test the PE Platform Wiring Socket the Propeller Chip and EEPROM Connect the Propeller Plug to the PC and PE Platform Connect Battery Power Supply Test Communication Load a Test Program and Test the I/O Pins Troubleshooting for the 40-pin DIP PE Platform Setup (if necessary) Since the PE Platform will be the microcontroller system at the heart of the PE Kit Labs, all its electrical connections should be tested before proceeding to the next lab. By following all the steps in this lab, it will help rule out potential wiring errors, which can easily slip by unnoticed as you build the PE Platform circuits, and then cause unexpected problems in later labs. Propeller Education Kit Labs: Fundamentals · Page 23 Setup and Testing Lab Inventory Equipment and Parts Required:  Computer with Microsoft Windows 2000, XP, or Vista and an available USB port  9 V alkaline battery (For this Setup and Testing lab, use a new 9 V, alkaline battery.)  PE Kit’s Breadboard Set (#700-32305), Propeller Plug (#32201), and Propeller DIP Plus Kit (130-32305) listed in the tables below Optional, but useful:  Small needle-nose pliers and wire cutter/stripper  Multimeter (DC + AC Voltmeter and Ohmmeter)  Digital storage oscilloscope, such as the Parallax USB Oscilloscope (#28014)  Antistatic mat and bracelet ESD Precautions: Electrostatic discharge (ESD) can damage the integrated circuits (ICs) in this kit. If you have an antistatic bracelet and mat, use them. If you don’t, the metal chassis of a PC plugged into a grounded outlet can also provide a safe and convenient way of losing static charge periodically before and while handling ICs. The part of the chassis that’s typically exposed on a PC is the frame on the back. The monitor and peripheral ports are connected to it with metal screws. Touch that frame (not the ports) before opening the antistatic bags and then frequently while handling the parts. ! Here are some more tips for reducing the likelihood of a static zap to PE Kit parts: Avoid touching the metal pins on the ICs. Handle ICs by their black plastic cases. Also, if you know your work area conditions cause you to build up static charge and then zap nearby objects, find another work area that is less static prone. Likewise, if you know a particular sweater causes you to build up charge in a certain chair, don’t wear that sweater while working with the PE Platform.  Gather the components listed in Table 3-1, Table 3-2, and Table 3-3.  Open up the PE Project Parts bag and check its contents against the PE Project Parts list in Table C-2 in Appendix C: PE Kit Components Listing. Table 3-1: Breadboard Set (#700-32305) 700-00077 3 Breadboard, 12x30 sockets, 3.19" x 1.65" 700-00081 4 Breadboard, 2x24 sockets, 3.19" x 0.5" Table 3-2: Propeller Plug (#32201) 805-00010 1 Propeller Plug 1 USB A to Mini B Retractable Cable Page 24 · Propeller Education Kit Labs: Fundamentals 3: Setup and Testing Lab Table 3-3: Propeller DIP Plus Kit (130-32305) Part Number Quantity Description 571-32305 1 9 V battery clip 201-01085 2 Capacitor, Electrolytic, 6.3 V, 1000 µF 201-04740 1 Capacitor, Electrolytic, 25 V, 0.47 µF 150-01011 1 Resistor, CF, 5%, 1/4 watt, 100 Ω 150-01030 1 Resistor, CF, 5%, 1/4 watt, 10 kΩ 251-05000 1 Crystal 5.00 MHz, 20 pF, HC-49/µs 350-00001 1 LED Green T1 ¾ 400-00002 1 Pushbutton - normally open 451-03601 1 2-pin m/m header 451-00406 1 Extended right angle m/m 4 pin header with 0.1 spacing 601-00513 1 3.3 V regulator, TO92 package 601-00506 1 5.0 V regulator, TO92 package 602-00032 1 32 kB EEPROM, DIP-8 800-00016 6 Bags of 10 Jumper Wires Propeller Chip P8X32A - 40 pin DIP Propeller DIP pin map sticker P8X32A-D40 1 120-00003 1 Parts and quantities subject to change without notice. Assemble the Breadboards The three 12-column × 30-row prototyping breadboards in Figure 3-3 have sockets whose locations can be described by (column letter, row number). Each column has a letter along the top and bottom of the breadboard and each row has a number along the sides. Two examples of breadboard coordinates in the figure are (K, 3) on the center breadboard, and (C, 7) on the right breadboard. Each breadboard is organized in rows of six sockets; all the sockets in each row of six are connected by a metal bracket underneath. So, to connect two or more wires together, just plug them into the same row of six sockets. Propeller Education Kit Labs: Fundamentals · Page 25 Setup and Testing Lab  Connect the interlocking breadboards together as shown in Figure 3-3. Figure 3-3: Breadboards Each group of six sockets is electrically connected. Example coordinate: (K, 3) on center breadboard Example coordinate: (C, 7) on right breadboard Two groups of 12 sockets by each red line are electrically connected. All 24 sockets next to each black line are electrically connected. Example coordinate: (BLACK, 22) on middleright power connector Example coordinate: (RED, 28) on right power connector See it in color and zoom in: This file is available in color as a free PDF download from www.parallax.com/go/PEKit. You can also use Adobe Acrobat Reader to zoom in on regions of the various wiring diagrams, which can be useful for verifying where certain leads get plugged in.  Adhesive Backing - don’t expose it. The breadboards have an adhesive backing covered with wax paper. Do not peel off the wax paper unless you are ready to permanently affix the breadboards to something permanent, such as a metal back plane cut to size or a project box. VSS and GND; VDD and 3.3V: The Propeller chip’s GND pin is referred to as VSS in the Propeller Manual, and VDD is +3.3 V. Each breadboard in Figure 3-3 is flanked on both sides by a 2-column × 24-row power connector. The columns on these power connectors are indicated by black and red lines, and the rows are indicated by the breadboard row numbers. Example coordinates include (BLACK, 22) on the middleright power connector and (RED, 28) on the right one. On each power connector in Figure 3-3, all 24 sockets by the vertical black line are electrically connected. These sockets typically serve as a common ground, and each of these black columns gets connected to the battery’s negative terminal on the PE Platform. Each power connector also has two groups of twelve sockets denoted by two vertical red lines. The upper twelve sockets next to the red line are grouped together, but are not connected to the lower twelve next to the other red line. The break in the red line by these socket groups indicates the break in continuity. The breadboard is designed this way to accommodate two separate voltage supplies on the same power connector. This Page 26 · Propeller Education Kit Labs: Fundamentals 3: Setup and Testing Lab feature is not used now, so all the positive power connectors are shorted together with jumper wires, and then connected to the 3.3 V regulator’s output to provide a supply for the PE Platform. Set up PE Platform Wiring and Voltage Regulators The PE Platform schematic shown in Figure 3-4 will be assembled in steps. In this section, you will first set up and test the wiring without the battery, Propeller Plug, Propeller chip or 24LC256 EEPROM. After some electrical tests to verify the wiring, you will connect and test each component. By following this procedure, you will minimize the likelihood of damaging one of the components due to a wiring error. Figure 3-4: Schematic – Propeller DIP Plus Kit Figure 3-5 shows the wiring diagram we will use for the schematic in Figure 3-4. Note that the Propeller chip, 24LC256 EEPROM, Propeller plug and battery are not yet connected. Note also that the board in the wiring diagram is tight-wired, with all the wires cut to length to be flush with the breadboard surface. This will make it easier to identify and remove loose-wired project circuits without having to worry about potentially disconnecting a part or wire that’s integral to the PE Platform.  Make sure your breadboard is oriented so that the numbers and letters that indicate the breadboard socket coordinates are the same as in Figure 3-5. Propeller Education Kit Labs: Fundamentals · Page 27 Setup and Testing Lab  Connect the wires and components exactly as shown in Figure 3-5. Make sure that the all of the wires are securely plugged into their sockets. If you accidentally cut a wire too short and it has a tenuous connection in the socket, discard it and replace it with one you have cut to the correct length.  The LED’s anode should be connected to (RED, 10) and its cathode to (L, 10). The cathode pin is the one closer to the flat spot on the otherwise round rim at the base of the LED.  The resistor across (K, 9) and (K, 10) is 100 Ω (brown-black-brown) and provides series resistance for the power LED.  The resistor across (D, 5) and (D, 9) is 10 kΩ (brown-black-orange), and will pull up one of the EEPROM pins. Figure 3-5: Wiring Diagram – Propeller DIP Plus Kit before ICs are Connected Verify Wiring Connections It’s important to eliminate any wiring mistakes before connecting power to the PE Platform. By double-checking your wiring and running a few simple tests, you can in many cases catch a mistake that might otherwise cause your system not to work or even damage some of its components. Although the PE Platform’s parts are not expensive to replace, unless you have extras on hand, waiting while the new parts get shipped could turn out to be an unwelcome delay.  Make a printout of Figure 3-5, and verify each connection by drawing over it with a highlighter pen after you have checked your wiring against the diagram, matching the coordinates of each socket that a part or wire is plugged into against the coordinates shown in the figure. Page 28 · Propeller Education Kit Labs: Fundamentals 3: Setup and Testing Lab  The 9 V battery’s red positive terminal wire should be plugged into the center breadboard’s (L, 1) socket, and its black negative terminal plugs into (L, 2).  The LM2940-5.0 voltage regulator in sockets (J, 1-3) should be plugged in so that the labeling on the black case faces left, and the heat conducting metal tab and backing faces right.  The LM2937-3.3 voltage regulator in sockets (H, 3-5) should also be plugged in so that the labeling on the black case faces left, and the heat conducting metal tab and backing faces right.  Verify that the LM2940 5 V regulator’s output capacitor’s negative terminal (find the stripe with the minus “–” signs on its metal case) is connected to (BLACK, 1) and that the LM2937 3 V regulator’s output capacitor’s negative terminal is plugged into either (J, 6) or (J, 7). ! WARNING: Reverse voltage across an electrolytic capacitor can cause it to rupture or in some cases explode. The electrolytic capacitor’s negative terminals (denoted by a stripe with negative signs) should always be connected to a lower voltage than its positive terminal.  Verify that the Power LED’s anode terminal is connected to (RED, 10) and that its cathode terminal (indicated by the shorter lead and flat spot on the otherwise cylindrical plastic case) is connected to (L, 10). Test the PE Platform Wiring This section has a list of test points that you can probe with a multimeter to verify that:    The voltage regulators are correctly wired and working properly The supply voltages are correctly distributed to all the power rails The supply voltages are routed to the correct sockets to supply the Propeller and EEPROM chips.  If you have a multimeter at your disposal, the test points are listed below. Tests Points with Battery Disconnected Continuity Most multimeters have a continuity setting that allows you to probe for low resistances. The symbol for continuity test is typically a diode with a dot emitting sound waves, indicating that if the meter detects low resistance, it will play a tone. If your meter does not have a continuity test mode, consider measurements under 1 Ω as an indication of continuity. Resistance measurements tend to vary with length of wire. For example, the resistance between (RED, 30) on the far left power connector and (RED, 30) on the far right power connector might measure in the 0.5 Ω range, while if you measure two points on the same power connector, it might measure almost nothing. The measurement will depend on your meter’s calibration and probe resistance. You can find out what zero ohms should be by shorting your probes together. If a pair of test points below fail the continuity test, look for missing jumper wires and loose connections on the center board and rails. Propeller Education Kit Labs: Fundamentals · Page 29 Setup and Testing Lab  Battery clip’s negative terminal sockets to the BLACK columns in all four power connectors. (The negative terminal on the battery clip is the smaller diameter terminal that’s closer to the wires.)  Battery clip’s positive terminal to the center board’s (G, 1)  Battery clip’s negative terminal to the following sockets: (G, 19), (G, 20), (F, 22), (D, 4), (F, 7), (G, 6, 7, 8, 9), (G, 2), and (K, 4).  (I, 5) to (RED, 13) and (RED, 18) on all four power connectors.  (RED, 18) to: (F, 19), (G, 22), (B, 5,), and (B, 6). Tests with Battery Connected If your voltmeter is pretty accurate, measured voltages will typically fall in the ± 0.1 VDC range. Some inexpensive voltmeters out there have much lower accuracy. If you are using a very inexpensive voltmeter, or one with an unknown history, you may notice somewhat larger measurement variations.  The 0.47 µF capacitor should be placed across the 9 V power input if you are using a 6-9 VDC supply that plugs into the wall, or any supply wire that’s longer than 9 V battery-to-breadboard adapter that comes in the kit.  Connect a new alkaline or freshly charged rechargeable 9 V battery to the PE Platform’s battery clip. The power LED should glow brightly. If it does not, or if the green LED takes glows orange instead of green, disconnect the battery immediately and go to Troubleshooting entry (2) on page 41. DC Voltage  Test the voltage across the four red/black vertical power rails. The voltage across (RED, 13) and (BLACK, 13) should measure 3.3 VDC on each of the four power connectors. If the voltage is instead in the 4 V neighborhood or higher, disconnect power immediately and go to Troubleshooting entry (11) on page 44. If the voltage is otherwise incorrect, go to Troubleshooting entry (3) on page 42.  Repeat the 3.3 VDC test for (RED, 18) and (BLACK, 13).  (I, 1) on center breadboard to (BLACK, any): same as voltage across battery terminals.  (G, 3) on center breadboard to (BLACK, any): 5 VDC. . If the voltage is instead in the 6 V neighborhood or higher, disconnect power immediately and see Troubleshooting entry (11) on page 44. Socket the Propeller Chip and EEPROM Figure 3-6 shows the PE Platform Schematic after the Propeller chip and EEPROM have been socketed.  Disconnect the battery from the clip for the next steps.  Identify the reference notch on the Propeller chip and pin map sticker, and compare their orientation to the reference notch on the pin map sticker in Figure 3-6. (The reference notch is the semicircle between the P0 and P31 labels on the pin map sticker, and it should correspond to an actual notch in the Propeller chip at the same location.)  Affix the pin map sticker to the Propeller chip, making sure that the reference notch on the sticker is oriented the same way as the reference notch on the chip.  Make sure that each pin is aligned with the correct breadboard socket it’s going to get pressed into. Page 30 · Propeller Education Kit Labs: Fundamentals 3: Setup and Testing Lab  Plug the Propeller chip into the breadboard, verifying its orientation against Figure 3-6. Press firmly with two thumbs.  Find the reference notch on the 24LC256 EEPROM chip, then orient it as shown in Figure 3-6 and plug it in. The reference notch should be between the pins that are in the (F, 6) and (G, 6) sockets. Figure 3-6: Wiring Diagram – Propeller DIP Plus Kit Connect the Propeller Plug to the PC and PE Platform The Propeller Tool software should be loaded on your PC before starting here.  If you have not already done so, complete the Software, Documentation & Resources lab, starting on page 17 before continuing here. The first time you connect your Propeller Plug to your PC with a USB cable, two things should happen: 1) The Propeller Plug’s serial transmit and receive LEDs should flicker briefly. 2) The Windows operating system should display the message “Found New Hardware – USB Serial Port” followed by “Found New Hardware – Your new hardware is installed and ready to use.” Each time you reconnect your Propeller Plug to the PC, the communication LEDs should flicker, but Windows typically does not display the serial port installation messages again after the first time.  The battery should still be disconnected. Propeller Education Kit Labs: Fundamentals · Page 31 Setup and Testing Lab  Connect the Propeller Plug to your computer with the USB cable, and verify that both of the Propeller Plug’s communication LEDs (red and blue) flicker briefly immediately after you make the connection.  Now, connect the Propeller Plug to the 4-pin header in your PE Platform parts side up as shown in Figure 3-6.  Verify that the power indicator LED that’s plugged into the (RED, 10) and (L, 10) sockets glows faintly. You may have to look straight down on its dome top to see the glow. If the power LED does not glow faintly, do not proceed to the next step. Instead, go to Troubleshooting entry (5) on page 42. Connect Battery Power Supply When you connect the battery supply, the power LED that glowed faintly when you connected the Propeller Plug should glow brightly. This indicates that the PE Platform’s 3.3 V regulator is supplying 3.3 V power to the PE Platform’s Propeller chip, EEPROM, and sockets next to the red stripes on the power connectors.  Connect the battery to the battery clip as shown in Figure 3-6. The PE Platform’s power LED should glow brightly. If it does not, unplug the battery immediately and go to Troubleshooting entry (4) on page 42. The same applies if the green power LED takes on an orange hue.  If you have a voltmeter, test the voltage at the red and black power connectors. Each should now measure 3.3 VDC. If the voltage is incorrect, disconnect the battery and go to Troubleshooting entry (3) on page 42.  Check the AC voltage across the red and black power connectors. There should only be about 50 mV of AC voltage. For AC voltages greater than 300 mV, go to Troubleshooting entry (11) on page 44. Test Communication The Propeller Tool software’s Identify Hardware feature can be used to verify communication between the PC and the Propeller chip.      Make sure that the battery is connected. Verity that the USB cable connects the PC to the Propeller Plug. Verify that the Propeller Plug is connected to the 4-pin header parts side up (label side down). Open the Propeller Tool software, click the Run menu select Identify Hardware…(or F7). If the Propeller Tool reports, “Propeller Chip version 1 found on COM…”, continue to the next section (Load a Test Program and Test the I/O Pins). Otherwise, go to Troubleshooting entry (6) on page 42 and Troubleshooting entry (1) on page 39. Load a Test Program and Test the I/O Pins These tests are important before proceeding with the PE Kit labs. One example of a problem these tests can intercept is a bent I/O pin on the Propeller chip. Occasionally, one of the pins gets bent underneath the Propeller chip instead of sinking into its breadboard socket. It can be difficult to catch by visual inspection, but if an I/O pin does not sense inputs or control outputs, these tests will lead to finding the problem quickly. It might otherwise take a lot of time looking for an error in an application circuit or the accompanying code before discovering a bent pin is the culprit. So follow along and perform these tests. It won’t take long, and it could end up saving you a lot of time later. Page 32 · Propeller Education Kit Labs: Fundamentals 3: Setup and Testing Lab I/O Pin Test Circuit Parts  Open up the PE Project Parts bag and check its contents against the PE Project Parts list in Table C-2 in Appendix C: PE Kit Components Listing.  For the next test circuits, gather the following parts from the PE Project Parts bag: (1) LED - Red, green or yellow (2) Resistors – 100 Ω (brown-black-brown) (1) Resistor – 10 kΩ (brown-black-orange) (1) Pushbutton (4) Jumper wires Build the Test Circuit The circuit shown in Figure 3-7 and Figure 3-8 will provide a means of testing the Propeller chip’s I/O pins as both inputs and outputs. If any of the checklist instructions do not work, go to Troubleshooting entry (9) on page 43. Start by verifying that the LED circuit is correct and that all the power connector sockets by the red vertical lines supply 3.3 V as follows:  Disconnect the battery from the battery clip.  Build the circuit shown in Figure 3-7 and Figure 3-8.  Reconnect the battery to the battery clip. The LED circuit can be tested by connecting it to one of the power connector rails’ RED sockets, which should supply it with 3.3 VDC.  Disconnect the LED wire from (L, 14) in Figure 3-8, and plug it into (RED, 13) on the power connector between the center and left prototyping breadboards. The LED should light. If it doesn’t, double-check your wiring. First, make sure the LED is not plugged in backwards. Its shorter (cathode) leg should be plugged into a socket next to the black line on the left power connector. Figure 3-7: Test Circuit Schematic Propeller Education Kit Labs: Fundamentals · Page 33 Setup and Testing Lab Figure 3-8: Test Circuit Wiring Diagram The LED circuit can also be used to test and make sure all the RED power rails are connected to the 3.3 V supply. If you already did that with a voltmeter, skip this checklist instruction.  Unplug the wire from (RED, 13), and plug it into (RED, 12) on the leftmost power connector. The LED should glow again. Repeat for (RED, 18) on the leftmost power connector as well as (RED, 18) on the middle-left power connector. The LED should glow at each test point. If not, check your board against the wiring diagram in Figure 3-8 for missing jumper wires between RED power connector sockets. After testing the LED circuit and power connectors, the LED should be reconnected to the Propeller I/O pin so that it can be used in conjunction with a test program to indicate that I/O pins are functioning properly as outputs.  Reconnect the LED circuit to the Propeller chip’s P3 I/O pin (L, 14) in Figure 3-8. Test Program – PushbuttonLedTest.spin As written, PushbuttonLedTest.spin flashes an LED connected to any I/O pin on the Propeller chip’s left side (P0 to P15). The rate the LED flashes depends on whether or not the pushbutton connected to P18 is pressed (10 Hz) or not pressed (2 Hz). The wire connecting P3 to the LED circuit can be used to probe each I/O pin. For example, if that wire is instead connected to (L, 11), it confirms that P0 is functioning as an output if it makes the LED blink. Connect the wire to (L, 12), and it confirms, P1 is functioning, and so on, up through P15 (L, 30). You can use the pin map sticker on your Propeller chip to quickly and easily locate I/O pins.  I/O pin is an abbreviation for input/output pin. The direction and state of each I/O pin is controlled by the program. Programs can set and modify the directions and states of individual I/O pins as well as groups of I/O pins at any time. Page 34 · Propeller Education Kit Labs: Fundamentals 3: Setup and Testing Lab If the LED blinks at 2 Hz while the pushbutton is pressed and held, and blinks at 10 Hz after it is released, it confirms that P18 is functioning as an input. The program can then be modified and the wire connecting P18 to the pushbutton can be moved to each I/O pin on the right side of the Propeller chip to test those I/O pins as inputs. After all the outputs on the Propeller chip’s left side and all the inputs on its right side have been tested, the pushbutton can then be moved to the left side and the LED to the right. Then, the test can be repeated to verify that all I/O pins on the left function as inputs and the pins on the right function as outputs. Load PushButtonLedTest.spin into EEPROM You can load this program into the PE Platform’s EEPROM memory by clicking the Run menu, selecting Compile Current, and then Load EEPROM (F11). After the program is loaded into EEPROM, the Propeller chip copies it from EEPROM into its main memory RAM and one of the Propeller chip’s processors starts executing it. (If you disconnect and reconnect power or press and release the PE Platform’s reset button, the Propeller chip will reload the program from EEPROM into main memory and start running it from the beginning.)  Open PushbuttonLedTest.spin into the Propeller Tool, or type it in. If you type it, be careful to indent each line exactly as shown.  Click the Propeller Tool’s Run menu and select Compile Current → Load EEPROM (F11). The Propeller Communication window will appear briefly and display progress as the program loads. If it closes after the “Verifying EEPROM” message, then the download was successful. Propeller Education Kit Labs: Fundamentals · Page 35 Setup and Testing Lab  If instead an error window opens that reads “EEPROM programming error...” refer to Troubleshooting entry (8) on page 43.  Verify that the LED connected to P3 flashes on/off rapidly, at 10 Hz.  Press and hold the pushbutton down, and verify that the LED flashes slower, at only 2 Hz.  If everything worked as anticipated, go on to I/O Pin Tests below. If it did not work, go to Troubleshooting entry (9) on page 43. I/O Pin Tests Use the pin map sticker on the Propeller chip to locate Propeller I/O pins. If any of these tests indicate that an I/O pin is faulty, refer to Troubleshooting entry (10) on page 43. The first step is to use the LED circuit to verify that each I/O pin on the left side of the Propeller chip functions as an output.  Unplug the end of the wire that’s in (L, 14) and use it probe P0 through P15. (L, 11) through (L, 18) and (L, 23) through (L, 30). Each I/O pin should cause the LED circuit to blink. Next, use the Pushbutton circuit to verify that each I/O pin on the right side of the Propeller chip functions as an input.  Press and hold the pushbutton on the right breadboard. The LED circuit on the left breadboard should flash at 2 Hz instead of 10 Hz.  Disconnect the battery from the battery clip.  Unplug the pushbutton wire at P18, (A, 28) on the center breadboard, and plug it into P16 (A, 30).  Modify the program to monitor P16 instead of P18 by changing the PUSHBUTTON CON directive in the PushButtonLedTest.spin object from 18 to 16.  Reconnect the battery to the battery clip.  Load the modified program into RAM by clicking the Run menu and selecting Compile Current → Load RAM (F10).  Verify that the pushbutton, which is now connected to P16, controls the LED frequency.  Repeat this procedure for P17, P19, P20, and so on, up through P27.  Load RAM (F10) vs. Load EEPROM (F11): The Propeller Tool software’s Load RAM feature is fast, but the program gets erased whenever power gets disconnected/reconnected or the PE Platform’s reset button gets pressed. After a reset, the Propeller chip will load the program most recently loaded into EEPROM and start executing it. While programs loaded into EEPROM do not get erased, they take longer to load. Since testing the pushbutton involves iteratively changing and reloading the program into the Propeller chip, it saves time to use Load RAM. What about testing P28..P31? These Propeller I/O pins are hardwired to the FTDI USB → serial chip and EEPROM program memory. If you were able to use the Load EEPROM feature it confirms that these I/O pins are fully functional. While it’s true that these pins can be used with some application circuits, you would need to make sure that the application circuits will not damage and cannot be damaged by the other circuits connected to P28..P31. See Figure 3-4 on page 27 for details. For the most part, the PE Kit labs will not use these I/O pins for application circuits. At this point, half of the Propeller chip’s I/O pins have been tested as outputs, and the other half have been tested as inputs. Before moving the test circuits to opposite sides of the board, it’s a good idea to load an empty program into the PE Platform’s EEPROM so that the Propeller chip won’t send signals to the wrong I/O pins. The power should be disconnected when the circuit is changed. To make sure the empty program runs automatically when the power gets reconnected, it should be loaded into EEPROM using F11.  Load this program (DoNothing.spin) into EEPROM (F11): Page 36 · Propeller Education Kit Labs: Fundamentals 3: Setup and Testing Lab '' File: DoNothing.spin PUB main ' Empty main method Now, power can be disconnected, the pushbutton can be moved to the left breadboard, and the LED circuit can be moved to the right breadboard.         Disconnect the battery and USB cable. Move the LED circuit to the right breadboard and connect it to P16. Move the pushbutton to the left breadboard and connect it to P15. Modify the object PushbuttonLedTest.spin as follows: o Change the LEDs_START CON directive from 0 to 16. o Change the LEDs_END CON directive from 15 to 27. o Change the PUSHBUTTON CON directive to 15. Reconnect the USB cable and battery. Load the modified PushbuttonLedTest.spin object into EEPROM using F11. Repeat the output LED tests for P16 to P27. Repeat the input pushbutton tests starting at P15, then P14, and so on through P0. Remember to modify the code, and then load RAM using F10 between each test. Before Changing or Adjusting Circuits The program DoNothing.spin causes all the I/O pins to be set to input, ensuring that it cannot inadvertently send a high (3.3 V) signal to a circuit that’s sending a low (0 V) signal, or vice versa. When you are finished testing, it’s a good idea to load the DoNothing.spin object back into EEPROM so that your Propeller chip cannot damage the next circuit that gets connected to it. In fact, make it a habit. Always load DoNothing.spin into EEPROM using F11 before disconnecting power and building a new circuit or making changes to an existing one.  Load DoNothing.spin into EEPROM (F11) now. When you reconnect power, DoNothing.spin will automatically load from EEPROM to Propeller main memory, and the Propeller chip will execute it. It will set all I/O pins to input by default. Then, the program ends, and the Propeller chip goes into low power mode. This protects the Propeller chip and your new circuit from the time you turn power back on until the time you load the program for your new circuit into the Propeller chip. Propeller Supply Voltage Regulation – It’s Important! A stable voltage supply is important because many different application circuits and subsystems depend on it. Any voltage supply fluctuations will translate directly into fluctuations in 3.3 V high signals sent by Propeller I/O pins. They also translate into fluctuations in Propeller I/O pin threshold voltage, which in the Propeller is approximately ½ of the 3.3 V supply voltage. When voltage is applied to a Propeller I/O pin set to input, the Propeller interprets it as binary-1 if that voltage is above the threshold or binary-0 if it’s below. I/O pin high and low signal levels and input threshold voltage are also used in a variety of analog to digital (voltage measurement) and digital to analog (voltage synthesis) applications. So any supply voltage fluctuations that affect output-high and input threshold voltage levels also reduce the accuracy of both voltage measurement and synthesis. Products and prototyping printed circuit boards designed with Propeller chips typically have several features to improve supply voltage stability. The voltage regulator output is usually very close to the Propeller chip’s supply inputs—the 3.3V and GND pins. Depending on the diagram, you might also Propeller Education Kit Labs: Fundamentals · Page 37 Setup and Testing Lab see them labeled Vdd and Vss. The metal traces on the board that connect the voltage regulator to the Propeller’s supply inputs are also typically wider than other traces that transmit signals. Since even metal conductors have a small amount of resistance, these measures minimize the resistance between the voltage regulator’s output and the Propeller chip’s supply inputs. This in turn improves supply voltage stability by minimizing voltage fluctuations that can occur if Propeller current consumption fluctuates, which can in turn occur when processors (cogs) launch and when I/O pins that drive loads switch on and off. Capacitors can also be connected across the Propeller chip’s supply inputs to provide additional protection from voltage fluctuations and further improve supply voltage stability. Improve PE Kit Supply Voltage Stability Compared to products and prototyping boards, the distances between the PE Platform’s voltage regulator outputs and Propeller chip supply inputs are quite large, and this can reduce voltage stability. That’s bad. The remedy is simple, and only requires two capacitors and two wires. That’s good. The wires connect the supply inputs on opposite sides of the chip to each other to ensure that the supply voltage levels are identical at both input terminals. The capacitors are placed across the 3.3 V and GND supply input terminals on both sides of the Propeller chip to filter out any voltage fluctuations caused by the long supply lines. Parts List: (2) Jumper Wires (2) Capacitors – 0.1 μF (from the PE Kit Project Parts bag) Procedure: Figure 3-9 shows the jumper wire and capacitor connections. The Propeller chip’s 3.3 V supply pins are connected to each other with one jumper wire, and the GND pins are connected with a second jumper wire. 0.1 μF capacitors are then connected across the Propeller chip’s 3.3 V and GND pins on both sides.  Disconnect power and programming port  Trim the two jumper wires to reduce any excess wire length when connected as shown in Figure 3-9.  Use a red jumper wire to connect (J, 22) to (D, 19).  Use a black jumper wire to connect (J, 20) to (D, 22).  Plug the leads of one 0.1 μF capacitor into (K, 22) and (J, 19).  Plug the leads of the other 0.1 μF capacitor into (B, 19) and (B, 22).  Double-check your wiring.  Reconnect power and programming port. Figure 3-9: Close-up View of Supply Input Strap and Filter Capacitor Connections Page 38 · Propeller Education Kit Labs: Fundamentals 3: Setup and Testing Lab Troubleshooting for the 40-Pin DIP PE Platform Setup (1) Programming Connection and Serial Port a. When you connect the Propeller plug to the USB port, the red and blue LEDs next to the Propeller Plug’s mini B connector should flicker briefly. If not, try a different port. If none of the ports result in this response, contact Parallax technical support. (See Tech Support Resources on page 18.) b. Run the Propeller Tool, click the Run menu and select Identify Hardware (F7). If you get the message shown in Figure 3-10: i. Make sure the USB cable is connected to both the Propeller Plug and your computer’s USB port. ii. Check the following jumper wires on your PE Platform: (D, 3) to (D, 10), (F, 10) to (F, 21), (B, 1) to (B, 12), and (C, 2) to (C, 11) iii. Also, make sure the battery is connected and that the PE Platform’s green power LED is glowing brightly. Then, try F7 again. iv. If that does not correct the problem, try connecting the cable to a different USB port on your computer. Figure 3-10: Communication Error Message c. If you still get the Figure 3-10 message after ensuring that the USB cable is connected: i. Click the Communication Error message box’s Edit Ports button. The Serial Port Search List window in should appear. You can also access this utility by clicking the Edit menu and selecting Preferences (F5). Click the Operation tab and then click the Edit Ports button. ii. Leave the USB cable plugged into the Propeller Plug and unplug and re-plug the USB cable into the PC’s USB port. Wait about 20 seconds between disconnecting and reconnecting the USB cable. The list should update and show a new “USB Serial Port” entry like the COM46 line in Figure 3-11. iii. If it appears in light gray print, right-click the entry and select Include Port (COMX), or in some cases Re-Include Port. Propeller Education Kit Labs: Fundamentals · Page 39 Setup and Testing Lab Figure 3-11: Serial Port Search List d. If the serial port search list already does scan for and recognize that port, go to www.parallax.com and click on the USB Driver Installer link at the bottom of the page, and then follow the Troubleshooting link at the bottom of that web page. e. If the Propeller Tool software still displays the “No Propeller chip found…” message, use your Device Manager to locate the USB Serial Port. i. To access the Ports List in the Windows Device Manager, right-click My Computer and select Properties. Click the Hardware tab, and then click the Device Manager Button. In the Device Manager, click the + next to Ports (COM & LPT). ii. Each time you plug in the USB cable, a reference to USB Serial Port (COMXX) should appear, as shown in Figure 3-12. Each time you unplug the cable that connects the Propeller Plug to the PC, the reference should disappear. For example, the Device Manager below shows USB Serial Port (COM 46), which indicates that a Propeller Plug might be connected to COM46. Figure 3-12: Device Manager Ports List Page 40 · Propeller Education Kit Labs: Fundamentals 3: Setup and Testing Lab f. iii. If the USB Serial Port entry does not appear in the Ports (COM &LPT) list but the Device Manger display appears to refresh every time you plug and unplug the USB cable: 1. It may indicate that the Propeller Plug was plugged into the PC and an attempt to manually install the driver was made before the Propeller Tool software and driver were installed. Browse the list to find the driver that gets added each time you plug in the Propeller Plug. When you find it, uninstall it. You can typically do this by right-clicking the driver and selecting Uninstall. 2. Then, unplug the Propeller Plug. Before plugging it back in, make sure the FTDI USB Driver is installed. The easiest way to do this is to uninstall and reinstall the Propeller Tool. 3. When you reinstall the Propeller Tool software: a. Make sure the checkbox for installing the USB drivers is checked! See the Download Software and Documentation section on page 17 for more information. b. After you have reinstalled the software, the correct driver should automatically get installed when you connect the Propeller Plug to the PC. Make sure to leave the battery disconnected when you connect the Propeller Plug to the PC with the USB cable for the first time. Contact Parallax Tech Support. (See page 18.) (2) If the PE Platform’s power LED did not light, or if it glowed orange, when the battery was connected: a. If the power LED glowed orange: i. Check for a short between the LED’s cathode and ground. The LED should have a 100 Ω series resistor between its cathode (L, 10) and ground (BLACK, 9). The resistor should bridge (K, 9) to (K, 10). ii. Check to make sure the voltage at the LED’s anode (RED, 10) is 3.3 V. b. If the LED did not light, it may be plugged in backwards. Check to make sure the cathode is connected to the resistor and the anode is connected to the 3.3 V supply. In terms of Figure 3-5 on page 28, the pin coming out by the flat spot on the otherwise cylindrical base of the LED’s round plastic housing should be plugged into (L, 10). The other (anode lead) should be connected to (RED, 10). See Verify Wiring Connections on page 28 for details. c. Make sure the battery’s (+) terminal is connected to (L, 1) and its (–) terminal is connected to (L, 2). d. There could be a wiring mistake causing a short circuit from one of the supply voltages to ground. If you don’t have a multimeter, start visually checking your wiring again. With a multimeter, you can check the resistance between the battery’s negative terminal, and the three positive supplies. Make sure to disconnect the USB cable and battery before testing resistance. iii. Start by measuring the resistance between the 3.3 V connection and the battery’s negative terminal. For example, test at probe points: (RED, 13) and (J, 4) in the center breadboard. iv. Repeat resistance measurements between the battery’s negative terminal (J, 4) and the 5 V regulated output (G, 3) as well as (J, 4) and the battery input (G, 1). If any of these resistance measurements shows less than 10 Ω, that supply voltage may have been shorted to ground. v. Contact Parallax Tech Support. (See page 18.) Propeller Education Kit Labs: Fundamentals · Page 41 Setup and Testing Lab (3) If the voltage across the power connectors (RED−BLACK) is not 3.3 V: a. If your meter is a lesser-quality model or has been subject to heavy use by other students, check it against a known voltage before trusting its measurements. b. Repeat Verify Wiring Connections section starting on page 28. Carefully continue through Connect Battery Power Supply on page 32, paying close attention to detail, and hopefully you’ll catch the error this time around. These tests can rule out a variety of problems, including shorts with the 5 and/or 9 V supplies. (4) If the Power LED does not light when you plug the battery in after socketing the Propeller chip, but it checked out during previous testing: a. Check for wiring errors to its pins: If a wire terminates at a row that is shared with a Propeller chip or 24LC256 EEPROM pin, it’s a prime suspect. Make sure the socket coordinates are identical to Figure 3-5 on page 28, and Figure 3-6 on page 31. b. Remove the Propeller chip and 24LC256 EEPROM from the breadboard and repeat Verify Wiring Connections on page 28. Continue through Connect Battery Power Supply on page 32 with attention to detail, and hopefully you’ll catch the error this time around. c. Contact Parallax Tech Support. (See page 18.) (5) If the Power LED does not glow faintly after you connect the Propeller Plug to the PE Platforms 4-pin header and to the PC with a USB cable: d. Verify that the resistor in the LED circuit is 100 Ω (brown, black, brown). e. Verify that the power LED’s anode is plugged into (RED, 10), and the cathode is plugged into (L, 10). The cathode is the pin by the flat spot at the base of the otherwise cylindrical plastic case. f. Try the other USB Ports on your PC. g. Try one of the green LEDs from the PE Project Parts kit. The long (anode) pin should plug into (RED, 10), and the shorter (cathode) pin into (L, 10). h. Check all wiring details against Figure 3-5 on page 28, and Figure 3-6 on page 31. i. Remove the Propeller chip and EEPROM from the breadboard and repeat Test the PE Platform Wiring on page 29. Continue through Connect Battery Power Supply on page 32, and hopefully you’ll catch the error this time around. j. Contact Parallax Tech Support. (See page 18.) (6) Common causes of the “No Propeller Chip found…” message are: a. Battery disconnected. Connect the battery. b. Dead battery, battery that needs to get recharged. c. USB cable not connecting Propeller Plug to PC. Make sure both ends are plugged in. d. Propeller Plug not plugged into the 4-pin header, or plugged in upside-down. It should be parts side up (label side down). e. Damaged or worn USB port. Most computers have more than one USB port. Try another port. f. Propeller chip or 24LC256 EEPROM not fully plugged in. The underside of the Propeller chip and 24LC256 EEPROM should both be flush with the top of the breadboard. If not, make sure all the pins are lined up with the breadboard holes, then press down firmly on each chip. g. FTDI USB drivers not installed. See entry (1)in this section. h. Supply voltages – if you didn’t check the voltages with a voltmeter, it’s time to get one and do that. (See Test the PE Platform Wiring on page 29.) If the supply voltages are incorrect, see entry (3). i. Propeller chip plugged in upside down. The semicircle Pin-1 indicator on the Propeller chip sticker shown in Figure 3-6 on page 31 should be adjacent to row 11, not row 30. Page 42 · Propeller Education Kit Labs: Fundamentals 3: Setup and Testing Lab j. Also, verify that the semicircle notch in the Propeller chip is under the printed semicircle on the sticker, also adjacent to row 11. Defective USB Cable. If you have a spare USB A to mini B cable, try it. (7) If the test LED circuit does not light when you plug the jumper wire into (RED, 13): a. The polarity on the LED may be backward. Check to make sure the LED’s cathode is connected to a socket on the power connector next to the black line. b. If the LED did not light when probing the power connector on the left, check to make sure the jumper that that connects the red column in the middle-left power connector to the red column on the far left power connector. (8) If you get an “EEPROM programming error…” message when you use the Propeller Tool’s Load EEPROM feature: a. Check for loose USB and battery connections. b. If the problem persists, try a different USB port. c. If you have a spare USB A to mini B cable, try it. d. The Propeller chip may not be firmly socketed. See Socket the Propeller Chip and EEPROM on page 30. e. Check the following connections: (A, 8) to (A, 14), (A, 9) to (A, 13), (BLACK, 9) to (L, 9), (H, 6) to (H, 7), (I, 7) to (I, 8), (H, 8) to (H, 9), (E, 4) to (E, 7), (RED, 6) to (A, 6), and the 10 kΩ resistor across (D, 5) and (D, 9). See Figure 3-6 on page 31. f. Make sure the 24LC256 is not socketed upside-down. The reference notch on the topcenter of the chip should be between (F, 6) and (G, 6). g. If the problem still persists, contact Parallax Tech Support. (See page 18.) (9) If the program downloads, but the test LED circuit does not flash: a. If you hand-entered the program, download it from the Propeller Education Kit page instead. Open it with the Propeller Tool software, and use F11 to download it to EEPROM. This will eliminate the possibility of a typing error during program entry. b. If the LED does not start flashing, check to make sure the oscillator is plugged in to the socket. (See the 5.00 MHz Crystal in Figure 3-2 on page 20 and check Figure 3-5 on page 28 for the correct sockets for connecting the 5.00 MHz oscillator.) c. Remove the oscillator and plug it back in, then re-test. d. Try changing the line in the PushButtonLedTestv1.0.spin that reads _clkmode = xtal1 + pll16x to _clkmode = xtal1 + pll8x. If this change causes the light to start flashing, change it back to pll16x, load this original program back into the Propeller chip and verify that the light won’t flash. If that’s the case, please contact Parallax Tech Support. (See page 18.) (10) Propeller chip I/O pins are factory tested before shipment. If the LED or pushbutton tests indicate a bad I/O pin: a. Take a close look at the pin and verify that it did not miss the socket and bend under the chip’s case. b. Try touching the LED probe lead to the I/O pin. If the light blinks with this electrical contact, but not when it is plugged into an adjacent socket: i. Again, take a look to make sure the pin is not bent under the module. ii. Try unsocketing the Propeller chip, and verify that the pin is not bent. iii. If you have a multimeter, test continuity between the socket the I/O pin was in and the socket the wire was plugged into. If there is no continuity, please contact Parallax Tech Support. (See page 18.) c. If the continuity in the breadboard row is good, and the pin is not bent, plug the Propeller chip back into the breadboard, and test all I/O pins, and take notes on which ones work Propeller Education Kit Labs: Fundamentals · Page 43 Setup and Testing Lab and which ones don’t. Also, make notes of any events you observed during testing, and then contact Parallax Tech Support. (See Tech Support Resources on page 18.) d. Please see the Warranty Policy at www.parallax.com for more information on replacing a module with damaged I/O pins. (11) 4 VDC or more across (RED, any) and (BLACK, any), or 6 VDC or more across (G, 3) to (BLACK, any). a. a. One of the 1000 µF capacitors may not be not properly connected. This is indicated by a DC voltage measurement that is 1 to 2.5 V above what it should be. i. Check to make sure the capacitor leads are inserted into the correct sockets. ii. Check to make sure the capacitor leads are long enough and making sufficient contact with the socket. b. If the voltage across (G, 3) to (BLACK, any) turns out to be 9 V, a wiring mistake may be shorting the battery's positive terminal (G..L, 1) to (G..L, 3). c. If the voltage across (RED, any) and (BLACK, any) measures 9 V, a wiring mistake may be shorting the battery's positive terminal (G..L, 1) to either (G..L, 6) or to one of the red power connectors. d. If the problem still persists, contact Parallax Tech Support. (See page 18.) Page 44 · Propeller Education Kit Labs: Fundamentals 4: I/O and Timing Basics Lab 4: I/O and Timing Basics Lab Introduction Most microcontroller applications involve reading inputs, making decisions, and controlling outputs. They also tend to be timing-sensitive, with the microcontroller determining when inputs are monitored and outputs are updated. The pushbutton circuits in this lab will provide simple outputs that the example applications can monitor with Propeller I/O pins set to input. Likewise, LED circuits will provide a simple and effective means of monitoring Propeller I/O pin outputs and event timing. While this lab’s pushbutton and LED example applications might seem rather simple, they make it possible to clearly present a number of important coding techniques that will be used and reused in later labs. Here is a list of this lab’s example applications and the coding techniques they introduce:            Turn an LED on – assigning I/O pin direction and output state Turn groups of LEDs on – group I/O assignments Signal a pushbutton state with an LED – monitoring an input, and setting an output accordingly Signal a group of pushbutton states with LEDs – parallel I/O, monitoring a group of inputs and writing to a group of outputs Synchronized LED on/off signals – event timing based on a register that counts clock ticks Configure the Propeller chip’s system clock – choosing a clock source and configuring the Propeller chip’s Phase-Locked Loop (PLL) frequency multiplier Display on/off patterns – Introduction to more Spin operators commonly used on I/O registers Display binary counts – introductions to several types of operators and conditional looping code block execution Shift a light display – conditional code block execution and shift operations Shift a light display with pushbutton-controlled refresh rate – global and local variables and more conditional code block execution Timekeeping application with binary LED display of seconds – Introduction to synchronized event timing that can function independently of other tasks in a given cog. Prerequisite Labs  Setup and Testing Parts List and Schematic This lab will use six LED circuits and three pushbutton circuits. (6) LEDs – 2-each: red, green, yellow (9) Resistors – 100 Ω (3) Resistor – 10 kΩ (3) Pushbutton – normally open (misc) jumper wires  Build the schematic shown in Figure 4-1. Propeller Education Kit Labs: Fundamentals · Page 45 I/O and Timing Basics Lab Figure 4-1: LED Pushbutton Schematic Propeller Nomenclature The Propeller microcontroller’s documentation makes frequent references to cogs, Spin, objects, methods, and global and local variables. Here are brief explanations of each term:       Cog – a processor inside the Propeller chip. The Propeller chip has eight cogs, making it possible to perform lots of tasks in parallel. The Propeller is like a super-microcontroller with eight high speed 32-bit processors inside. Each internal processor (cog) has access to the Propeller chip’s I/O pins and 32 KB of global RAM. Each cog also has its own 2 KB of RAM that can either run a Spin code interpreter or an assembly language program. Spin language – The Spin language is the high-level programming language created by Parallax for the Propeller chip. Cogs executing Spin code do so by loading a Spin interpreter from the Propeller chip’s ROM. This interpreter fetches and executes Spin command codes that get stored in the Propeller chip’s Global RAM. Propeller cogs can also be programmed in low-level assembly language. Whereas highlevel Spin tells a cog what to do, low-level assembly language tells a cog how to do it. Assembly language generates machine codes that reside in a cog’s RAM and get executed directly by the cog. Assembly language programs make it possible to write code that optimizes a cog’s performance; however, it requires a more in-depth understanding of the Propeller chip’s architecture. The PE Kit Fundamentals labs focus on Spin programming. Method – a block of executable Spin commands that has a name, access rule, and can optionally create local (temporary) variables, receive parameters, and return a value. Global and local variables – Global variables are available to all the methods in a given object, and they reserve variable space as long as an application is running. Local variables are defined in a method, can only be used within that method, and only exist while that method executes commands. When it’s done, the memory these local variables used becomes available to other methods and their local variables. Local and global variables are defined with different syntax. Object – an application building block comprised of all the code in a given .spin file. Some Propeller applications use just one object but most use several. Objects have a variety of uses, depending partially on how they are written and partially on how they get configured and used by other objects. Some objects serve as top objects, which provide the starting point where the first command in a given application gets executed. Other objects are written to provide a library of useful methods for top objects or other objects to use. Page 46 · Propeller Education Kit Labs: Fundamentals 4: I/O and Timing Basics Lab Objects can be written to use just one cog, or can include code that gets launched into one or more additional cogs. Some objects have methods that provide a means to exchange information with processes running in other cogs. One object can even make multiple copies of another object, and set each one to a different task. Objects can use other objects, which in turn can use still other objects. In more complex applications, a set of objects will form functional relationships that can be viewed as a file structure with the Propeller Tool’s Object Info window. The examples in this lab only involve single, top-level objects with just one method. Upcoming labs will introduce various building-block techniques for using multiple objects and methods in an application, as well as parallel multiprocessing applications using multiple cogs. Though the objects in this lab are simple, many of them will be modified later to serve as building blocks for other objects and/or future projects. Lights on with Direction and Output Register Bits The LedOnP4 object shown below has a method named LedOn, with commands that instruct a cog in the Propeller chip to set its P4 I/O pin to output-high. This in turn causes the LED in the circuit connected to P4 to emit light.  Load LedOnP4 into RAM by clicking Run → Compile Current → Load RAM (or press F10). '' File: LedOnP4.spin PUB LedOn ' Method declaration dira[4] := 1 outa[4] := 1 ' Set P4 to output ' Set P4 high repeat ' Endless loop prevents program from ending How LedOnP4.spin Works The first line in the program is a documentation comment. Single-line documentation comments are denoted by two apostrophes (not a quotation mark) to the left of the documentation text.  Click the Documentation radio button above the code in the Propeller Editor. While commands like dira :=… and repeat don’t show in documentation mode, notice that the text to the right of the double apostrophe documentation comments does appear. Notice also that the nondocumentation comments in the code, preceded by single apostrophes, do not appear in Documentation mode.  Try the other radio buttons and note what elements of the object they do and do not show.  Block Comments: There are also documentation block comments that can span multiple lines. They have to begin and end with double-braces like this: {{ block of documentation comments }}. Non-documentation comments can also span multiple lines, beginning and ending with single-braces like this: { block of nondocumentation comments }. All Spin language commands that the Propeller chip executes have to be contained within a method block. Every method block has to be declared with at least an access rule and a name. Access rules and method names will be explored in depth in upcoming labs; for now, just keep in mind that PUB LedOn is a method block declaration with a public (PUB) access rule and the name LedOn. Propeller Education Kit Labs: Fundamentals · Page 47 I/O and Timing Basics Lab  Bold or not bold? In the discussion paragraphs, the Parallax font used in the Propeller Tool is also used for all text that is part of a program. The portions that are reserved words or operators will be in bold. The portions that are defined by the user, such as method, variable, and constant names and values, will not be in bold text. This mimics the Propeller Tool software’s syntax highlighting Spin scheme. Code listings and snippets are not given the extra bolding. To see the full syntax-highlighted version, view it in the Propeller Tool with the Spin scheme. Go to Edit→ Preferences→ Appearance to find the Syntax Highlighting Scheme menu. The dira register is one of several special purpose registers in cog RAM; you can read and write to the dira register, which stores I/O pin directions for each I/O pin. A 1 in a given dira register bit sets that I/O pin to output; a 0 sets it to input. The symbol “:=” is the Assignment operator; the command dira[4] := 1 assigns the value 1 to the dira register’s Bit 4, which makes P4 an output. When an I/O pin is set to output, the value of its bit in the outa register either sets the I/O pin high (3.3 V) with a 1, or low (0 V) with a 0. The command outa[4] := 1 sets I/O pin P4 high. Since the P4 LED circuit terminates at ground, the result is that the LED emits light.  I/O Sharing among Cogs? Each cog has its own I/O Output (outa) and I/O Direction (dira) registers. Since our applications use only one cog, we do not have to worry about two cogs trying to use the same I/O pin for different purposes at the same time. When multiple cogs are used in one application, each I/O pin 's direction and output state is the "wired--OR" of the entire cogs collective. How this works logically is described in the I/O Pin section in Chapter 1 of the Propeller Manual. The repeat command is one of the Spin language’s conditional commands. It can cause a block of commands to execute repeatedly based on various conditions. For repeat to affect a certain block of commands, they have to be below it and indented further by at least one space. The next command that is not indented further than repeat is not part of the block, and will be the next command executed after the repeat loop is done. Since there’s nothing below the repeat command in the LedOnP4 object, it just repeats itself over and over again. This command is necessary to prevent the Propeller chip from automatically going into low power mode after it runs out of commands to execute. If the repeat command weren’t there, the LED would turn on too briefly to see, and then the chip would go into low power mode. To our eyes it would appear that nothing happened. Modifying LedOnP4 More than one assignment can be made on one line.  Replace this: dira[4] := 1 outa[4] := 1 ...with this: dira[4] := outa[4] := 1 Of course, you can also expand the LedOn method so that it turns on more than one LED.  Modify the LedOn method as shown here to turn on both the P4 and P5 LEDs: PUB LedOn dira[4] := outa[4] := 1 dira[5] := outa[5] := 1 repeat Page 48 · Propeller Education Kit Labs: Fundamentals 4: I/O and Timing Basics Lab If the repeat command was not the last command in the method, the LEDs would turn back off again so quickly that it could not be visually discerned as on for any amount of time. Only an oscilloscope or certain external circuits would be able to catch the brief “on” state.  Try running the program with the repeat command commented with an apostrophe to its left.  If you have an oscilloscope, set it to capture a single edge, and see if you can detect the signal. I/O Pin Group Operations The Spin language has provisions for assigning values to groups of bits in the dira and outa registers. Instead of using a single digit between the brackets next to the outa command, two values separated by two dots can be used to denote a contiguous group of bits. The binary number indicator % provides a convenient way of defining the bit patterns that get assigned to the group of bits in the outa or dira registers. For example, dira[4..9] := %111111 will set bits 4 through 9 in the dira register (to output.) Another example, outa[4..9] := %101010 sets P4, clears P5, sets P6, and so on. The result should be that the LEDs connected to P4, P6, and P8 turn on while the others stay off.  Load GroupIoSet.spin into RAM (F10).  Verify that the P4, P6, and P8 LEDs turn on. '' File: GroupIoSet.spin PUB LedsOn dira[4..9] := %111111 outa[4..9] := %101010 repeat Modifying GroupIoSet.spin Notice that outa[4..9] := %101010 causes the state of the outa register’s bit 4 to be set (to 1), bit 5 cleared (to 0), and so on. If the pin group’s start and end values are swapped, the same bit pattern will cause bit 9 to be set, bit 8 to be cleared, and so on…  Replace outa[4..9] := %101010 …with this outa[9..4] := %101010  Load the modified program into the Propeller chip’s RAM and verify that the LEDs display a reversed bit pattern. It doesn’t matter what value is in an outa register bit if its dira register bit is zero. That’s because the I/O pin functions as an input instead of an output when its dira register bit is cleared. An I/O pin functioning as an input detects high and low signals instead of sending them. While a pin configured to function as an output either transmits 3.3 or 0 V, a pin configured to input doesn’t transmit at all because it is instead monitoring the voltage applied to the pin. An I/O pin set to output-high connected to an LED circuit turns the light on when it applies 3.3 V to the LED circuit. Since the other end of the LED circuit is connected to ground (0 V), the electrical Propeller Education Kit Labs: Fundamentals · Page 49 I/O and Timing Basics Lab pressure across the LED circuit causes current to flow through the circuit, which turns the light on. An I/O pin set to output-low turns the light off because it applies 0 V to the LED circuit. With 0 V at both ends of the circuit, there is no electrical pressure across the circuit, so no current flows through it, and the light stays off. The light also stays off when the I/O pin is set to input, but for a different reason. An I/O pin set to input doesn’t apply any voltage at all because it is instead sensing voltage applied to it by the circuit. The result is the same, the LED stays off. Since an I/O pin set to input doesn’t apply any voltage to a circuit, it doesn’t matter what value is in the corresponding outa register bit. The LED circuit connected to that pin will remain off. Here is an example that sets all the bits in outa[4..9] but not all the bits in dira[4..9]. The LEDs connected to P6 and P7 will not turn on because their I/O pins have been set to input with zeros in the dira register.  Set all the outa[4..9] bits. outa[4..9] := %111111  Clear bits 6 and 7 in dira[4..9]. dira[4..9] := %110011  Load the modified program into the Propeller chip’s RAM and verify that the 1’s in the outa[6] and outa[7] bits cannot turn on the P6 and P7 LEDs because their I/O pins have been set to inputs with zeros in dira[6] and dira[7]. Reading an Input, Controlling an Output The ina register is a read-only register in Cog RAM whose bits store the voltage state of each I/O pin. When an I/O pin is set to output, its ina register bit will report the same value as the outa register bit since ina bits indicate high/low I/O pin voltages with 1 and 0. If the I/O pin is instead an input, its ina register bit updates based on the voltage applied to it. If a voltage above the I/O pin’s 1.65 V logic threshold is applied, the ina register bit stores a 1; otherwise, it stores a 0. The ina register is updated with the voltage states of the I/O pins each time an ina command is issued to read this register. The pushbutton connected to P21 will apply 3.3 V to P21 when pressed, or 0 V when not pressed. In the ButtonToLed object below, dira[21] is set to 0, making I/O pin P21 function as an input. So, it will store 1 if the P21 pushbutton is pressed, or 0 if it is not pressed. By repeatedly assigning the value stored in ina[21] to outa[6], the ButtonLed method makes the P6 LED light whenever the P21 pushbutton is pressed. Notice also that the command outa[6] := ina[21] is indented below the repeat command, which causes this line to get executed over and over again indefinitely.  Load ButtonToLed.spin into RAM.  Press and hold the pushbutton connected to P21 and verify that the LED connected to P6 lights while the pushbutton is held down. '' File: ButtonToLed.spin '' Led mirrors pushbutton state. PUB ButtonLed ' Pushbutton/Led Method dira[6] := 1 dira[21] := 0 ' P6 → output ' P21 → input (this command is redundant) repeat outa[6] := ina[21] ' Endless loop ' Copy P21 input to P6 output Page 50 · Propeller Education Kit Labs: Fundamentals 4: I/O and Timing Basics Lab Read Multiple Inputs, Control Multiple Outputs A group of bits can be copied from the ina to outa registers with a command like outa[6..4] := ina[21..23]. The dira[6] := 1 command will also have to be changed to dira[6..4] := %111 before the pushbuttons will make the LEDs light up.  Save a copy of ButtonToLed, and modify it so that it makes the P23, P22, and P21 pushbuttons light up the P4, P5 and P6 LEDs respectively. Hint: you need only one outa command.  Try reversing the order of the pins in outa[6..4]. How does this affect the way the pushbutton inputs map to the LED outputs? What happens if you reverse the order of bits in ina[21..23]? Timing Delays with the System Clock Certain I/O operations are much easier to study with code that controls the timing of certain events, such as when an LED lights or how long a pushbutton is pressed. The three basic Spin building blocks for event timing are:   cnt – a register in the Propeller chip that counts system clock ticks. clkfreq – a command that returns the Propeller chip’s system clock frequency in Hz.  Another useful way to think of it is as a value that stores the number of Propeller system clock ticks in one second. waitcnt – a command that waits for the cnt register to get to a certain value. The waitcnt command waits for the cnt register to reach the value between its parentheses. To control the amount of time waitcnt waits, it’s best to add the number of clock ticks you want to wait to cnt, the current number of clock ticks that have elapsed. The example below adds clkfreq, the number of clock ticks in 1 second, to the current value of cnt. The result of the calculation between the parentheses is the value the cnt register will reach 1 s later. When the cnt register reaches that value, waitcnt lets the program move on to the next command. waitcnt(clkfreq + cnt) ' wait for 1 s. To calculate delays that last for fractions of a second, simply divide clkfreq by a value before adding it to the cnt register. For example, here is a waitcnt command that delays for a third of a second, and another that delays for 1 ms. waitcnt(clkfreq/3 + cnt) waitcnt(clkfreq/1000 + cnt) ' wait for 1/3 s ' wait for 1 ms The LedOnOffP4.spin object uses the waitcnt command to set P4 on, wait for ¼ s, turn P4 off, and wait for ¾ s. The LED will flash on/off at 1 Hz, and it will stay on for 25 % of the time. '' File: LedOnOffP4.spin PUB LedOnOff dira[4] := 1 repeat outa[4] := 1 waitcnt(clkfreq/4 + cnt) outa[4] := 0 waitcnt(clkfreq/4*3 + cnt) Propeller Education Kit Labs: Fundamentals · Page 51 I/O and Timing Basics Lab  Load LedOnOffP4 object into the Propeller chip’s RAM and verify that the light flashes roughly every second, on ¼ of the time and off ¾ of the time. Remember that indentation is important! Figure 4-2 shows a common mistake that can cause unexpected results. On the left, all four lines below the repeat command are indented further than repeat. This means they are nested in the repeat command, and all four commands will be repeated. On the right, the lines below repeat are not indented. They are at the same level as the repeat command. In that case, the program never gets to them because the repeat loop does nothing over and over again instead! Notice the faint lines that connect the “r” in repeat to the commands below it. These lines indicate the commands in the block that repeat operates on. To enable this feature in the Propeller Tool software, click Edit and select Preferences. Under the Appearance tab, click the checkmark box next to Show Block Group Indicators. Or, use the shortcut key Ctrl+I. ! Figure 4-2: Repeat Code Block This repeat loop repeats four commands The commands below repeat are not indented further, so they are not part of the repeat loop. Inside waitcnt(clkfreq + cnt) When Run → Compile Current → Load… is used to download an object, the Propeller Tool software examines it for certain constant declarations that configure the Propeller chip’s system clock. If the object does not have any such clock configuration constants, the Propeller Tool software stores default values in the Propeller chip’s CLK register which set it to use the internal RC oscillator to fast mode (approximately 12 MHz) for the system clock. With the default 12 MHz system clock, the instruction waitcnt(clkfreq + cnt) is equivalent to the instruction waitcnt(12_000_000 + cnt). Figure 4-3 shows how waitcnt(12_000_000 + cnt) waits for the cnt register to accumulate 12 million more clock ticks than when the waitcnt command started. Keep in mind that the cnt register has been incrementing with every clock tick since the Propeller chip was either reset or booted. In this example, cnt reached the 50,000,008th clock tick at the point when the waitcnt command was executed. Then, the cnt value that waitcnt waits for is 12,000,000 + 50,000,008 = 62,000,008. So, the cog executing waitcnt(12_000_000 + cnt) is not allowed to move on to the next command until the cnt register reaches the 62,000,008th clock tick. Page 52 · Propeller Education Kit Labs: Fundamentals 4: I/O and Timing Basics Lab Figure 4-3: The waitcnt Command and the cnt Register System Clock Configuration and Event Timing Up to this point, our programs have been using the Propeller chip's default internal 12 MHz clock. Next, let's modify them to use the external 5.00 MHz oscillator in our PE Platform circuit. Both Spin and Propeller Assembly have provisions for declaring constants that configure the system clock and making sure that all the objects know its current operating frequency. The CON block designator defines a section of code for declaring Propeller configuration settings, as well as global constant symbols for program use. Declarations similar to ones in the CON block below can be added to a top object to configure the Propeller chip’s system clock. This particular set of declarations will make the Propeller chip’s system clock run at top speed, 80 MHz. CON _xinfreq = 5_000_000 _clkmode = xtal1 + pll16x The line _xinfreq = 5_000_000 defines the expected frequency from the external oscillator, which in the PE Platform’s case is 5.00 MHz. The line _clkmode = xtal1 + pll16x causes the Propeller Tool software’s Spin compiler to set certain bits in the chip’s CLK register when it downloads the program. (See the Propeller Manual for more information.) The xtal1 clock mode setting configures certain XO and XI pin circuit characteristics to work with external crystals in the 4 to 16 MHz range. The frequency of the external crystal provides the input clock signal which the Propeller chip’s phase-locked loop (PLL) circuit multiplies for the system clock. pll16x is a predefined clock mode setting constant which makes the PLL circuit multiply the 5 MHz frequency by 16 to supply the system with an 80 MHz clock signal. The constant pll8x can be used with the same oscillator to run the Propeller chip’s system clock at 40 MHz. pll4x will make the Propeller chip’s system clock run at 20 MHz, and so on. The full listing of valid _clkmode constant declarations can be found in the Propeller Manual's Spin Language Reference _CLKMODE section. Propeller Education Kit Labs: Fundamentals · Page 53 I/O and Timing Basics Lab Crystal Precision The Propeller chip's internal RC clock serves for non-timing-sensitive applications, such as controlling outputs based on inputs and blinking lights. For applications that are timing-sensitive like serial communication, tone generation, servo control, and timekeeping, the Propeller chip can be connected to crystal oscillators and other higher-precision external clock signals via its XI and XO pins. The Propeller chip’s internal oscillator in its default RCFAST mode is what the Propeller chip uses if the program does not specify the clock source or mode. This oscillator’s nominal frequency is 12 MHz, but its actual frequency could fall anywhere in the 8 to 20 MHz range. That’s an error of +66 to – 33%. Again, for applications that do not require precise timing, it suffices. On the other hand, an application like asynchronous serial communication can only tolerate a total of 5 % error, and that’s the sum of both the transmitter’s and receiver’s timing errors. In practical designs, it would be best to shoot for an error of less than 1%. By using an external crystal for the Propeller chip’s clock source, the clock frequency can be brought well within this tolerance, or even within timekeeping device tolerances.  The PE Platform has an ESC Inc. HC-49US quartz crystal connected to the Propeller chip’s XI and XO pins that can be used in most timing-sensitive applications. The datasheet for this part rates its room temperature frequency tolerance at +/- 30 PPM, meaning +/- 30 clock ticks for every million. That’s a percent error of only +/- 0.003%. Obviously, this is more than enough precision for asynchronous serial communication, and it’s also great for servo control and tone generation. It’s not necessarily ideal for watches or clocks though; this crystal’s error could cause an alarm clock or watch to gain or lose up to 2.808 s per day. This might suffice for datalogging or clocks that periodically check in with an atomic clock for updates. Keep in mind that to make the Propeller chip function with digital wristwatch precision, all it takes is a more precise oscillator. The HC-49US datasheet also has provisions for temperature (+/- 50 PPM) and aging (+/- 5 PPM per year). Even after 5 years, and at its rated -10 to + 70  C, the maximum error would be 105 PPM, which is still only +/- 0.0105% error. That’s still great for asynchronous serial communication, tone generation, and servo control, but again, an alarm clock might gain or lose up to 9 s per day. Since clkfreq stores the system clock frequency, object code can rely on it for correct timing, regardless of the system clock settings. The clkfreq command returns the number of ticks per second based on the Propeller chip’s system clock settings. For example, this CON block uses _xinfreq = 5_000_000 and _clkmode = xtal1 + pll16x, so clkfreq will return the value of 5,000,000 × 16, which equals 80,000,000. ConstantBlinkRate.spin can be configured to a variety of system clock rates to demonstrate how clkfreq keeps the timing constant regardless of the clock frequency.  Load ConstantBlinkRate.spin into the Propeller chip’s RAM (F10). The system clock will be running at 80 MHz.  Verify that the blink rate is 1 Hz.  Modify the _clkmode constant declaration to read _clkmode = xtal1 + pll8x to make the system clock run at 40 MHz, and load the program into RAM (F10). '' File: ConstantBlinkRate.spin CON _xinfreq = 5_000_000 _clkmode = xtal1 + pll16x PUB LedOnOff dira[4] := 1 repeat outa[4] := 1 waitcnt(clkfreq/2 + cnt) outa[4] := 0 waitcnt(clkfreq/2 + cnt) Page 54 · Propeller Education Kit Labs: Fundamentals 4: I/O and Timing Basics Lab The Propeller chip’s system clock is now running at 40 MHz. Is the LED still blinking on/off at 1 Hz?  Repeat for pll4x, pll2x, and pll1x. There should be no change in the blink rate at any of these system clock frequencies. Timing with clkfreq vs. Timing with Constants Let’s say that a constant value is used in place of clkfreq to make the program work a certain way at one particular system clock frequency. What happens when the Propeller system clock frequency changes?  Save a copy of the ConstantBlinkRate object as BlinkRatesWithConstants.spin.  Make sure the PLL multiplier is set to pll1x so that the system clock runs at 5 MHz.  For a 1 Hz on/off signal, replace both instances of clkfreq/2 with 2_500_000. (The Propeller Tool accepts underscores, but not commas, in long numbers to make them more legible.)  Load the object into the Propeller chip’s RAM and verify that the LED blinks at 1 Hz.  Next, change the PLL multiplier to pll2x. Load the modified object into the Propeller chip’s RAM. Does the light blink twice as fast? Try pll4x, pll8x, and pll16x. When a constant value was used instead of clkfreq, a change in the system clock caused a change in event timing. This is why objects should use clkfreq when predictable delays are needed, especially for objects that are designed to be used by other objects. That way, the programmer can choose the best clock frequency for the application without having to worry about whether or not any of application’s objects will behave differently. More Output Register Operations In the I/O Pin Group Operations section, binary values were assigned to groups of bits in the dira and outa registers. There are lots of shortcuts and tricks for manipulating groups of I/O pin values that you will see used in published code examples. The Post-Set “~~” and Post-Clear “~” Operators Below are two example objects that do the same thing. While the object on the left uses techniques covered earlier to set and clear all the bits in dira[4..9] and outa[4..9], the one on the right does it differently, with the Post-Set “~~”and Post-Clear “~”operators. These operators come in handy when all the bits in a certain range have to be set or cleared. ''File: LedsOnOff.spin ''All LEDS on for 1/4 s and off ''for 3/4 s. ''File: LedsOnOffAgain.spin ''All LEDS on for 1/4 s and off ''for 3/4 s with post set/clear. PUB BlinkLeds PUB BlinkLeds dira[4..9] := %111111 dira[4..9]~~ repeat repeat outa[4..9] := %111111 waitcnt(clkfreq/4 + cnt) outa[4..9] := %000000 waitcnt(clkfreq/4*3 + cnt) outa[4..9]~~ waitcnt(clkfreq/4 + cnt) outa[4..9]~ waitcnt(clkfreq/4*3 + cnt)  Load each program into the Propeller chip’s RAM and verify that they function identically. Propeller Education Kit Labs: Fundamentals · Page 55 I/O and Timing Basics Lab  Examine how the Post-Set operator replaces := %111111 and the Post-Clear operator replaces := %000000.  Try modifying both programs so that they only affect P4..P7. Notice that the Post-Set and Post-Clear operators require less maintenance since they automatically set or clear all the bits in the specified range. The Bitwise Not “!” Operator Here are two more example programs that do the same thing. This time, they both light alternate patterns of LEDs. The one on the left has familiar assignment operators in the repeat loop. The one on the right initializes the value of outa[4..9] before the repeat loop. Then in the repeat loop, it uses the Bitwise NOT “!” operator on outa[4..9]. If outa[4..9] stores %100001, the command !outa[4..9] inverts all the bits (1s become 0s, 0s become 1s). So, the result of !outa[4..9] will be %011110.  Load each object into the Propeller chip’s RAM and verify that they function identically.  Try doubling the frequency of each object. ''File: LedsOnOff50Percent.spin ''Leds alternate on/off 50% of ''the time. ''File: LedsOnOff50PercentAgain.spin ''Leds alternate on/off 50% of ''the time with the ! operator. PUB BlinkLeds PUB BlinkLeds dira[4..9]~~ outa[4..9] := %100001 dira[4..9]~~ repeat repeat outa[4..9] := %100001 waitcnt(clkfreq/4 + cnt) outa[4..9] := %011110 waitcnt(clkfreq/4 + cnt) !outa[4..9] waitcnt(clkfreq/4 + cnt) Register Bit Patterns as Binary Values A range of bits in a register can be regarded as digits in a binary number. For example, in the instruction outa[9..4] := %000000,recall that % is the binary number indicator; %000000 is a 6-bit binary number with the value of zero. Operations can be performed on this value, and the result placed back in the register. The IncrementOuta object below adds 1 to outa[9..4] each time through a repeat loop. The result will be the following sequence of binary values, displayed on the LEDs: Binary Value %000000 %000001 %000010 %000011 %000100 %000101 etc… %111101 %111110 %111111 Decimal Equivalent 0 1 2 3 4 5 61 62 63 Page 56 · Propeller Education Kit Labs: Fundamentals 4: I/O and Timing Basics Lab  Load IncrementOuta.spin it into RAM. '' File: IncrementOuta.spin PUB BlinkLeds dira[9..4]~~ outa[9..4]~ repeat waitcnt(clkfreq/2 + cnt) outa[9..4] := outa[9..4] + 1 'change to (clkfreq + cnt) to slow down the loop The loop starts by setting LED I/O pins to output with dira[9..4]~~. Next, outa[9..4]~ clears all the bits in the outa register range 9..4 to %000000, binary zero. The first time through the repeat loop, 1 is added to it, the equivalent of outa[9..4] := %000001, which causes the P4 LED to light up. As the loop repeats indefinitely, the LED pattern cycles through every possible permutation. The Increment “++” operator The Increment “++”operator can be used instead of + 1 to increment a value. outa[9..4]++ is equivalent to outa[9..4] := outa[9..4] + 1. The command  Modify the outa command in the repeat loop to use only outa[9..4]++.  Load the modified object into RAM. Do the LEDs behave the same way? Conditional Repeat Commands Syntax options for repeat make it possible to specify the number of times a block of commands is repeated. They can also be repeated until or while one or more conditions exist, or even to sweep a variable value from a Start value to a Finish value with an optional step Delta.  Read the syntax explanation in the REPEAT section of the Propeller Manual's Spin Language Reference, if you have it handy. Let's modify IncrementOuta.spin further to stop after the last value (%111111 = 63) has been displayed. To limit the loop to 63 cycles just add an optional Count expression to the repeat command, like this: repeat 63  Save IncrementOuta.spin as BinaryCount.spin.  Add the Count value 63 after the repeat command.  To keep the LEDs lit after the repeat block terminates, add a second repeat command below the block. Make sure it is not indented further than the first repeat.  Load the BinaryCount object into the Propeller chip’s RAM and verify that the LEDs light up according to the Binary Value sequence. There are a lot of different ways to modify the repeat loop to count to a certain value and then stop. Here are a few repeat loop variations that count to decimal 20 (binary %010100); the second example uses the Is Equal “==” operator, the third uses the Is Less Than “ 18 repeat until ++outa[9..4] > 19 repeat until ++outa[9..4] => 20 repeat until outa[9..4]++ => 19 ' ' ' ' ' ' ' ' Repeat until outa[9..4] greater than 18. Repeat until outa[9..4] greater than 19. Repeat until outa[9..4] or greater than 20. Repeat until outa[9..4] or greater than 19. post-incremented is pre-incremented is pre-incremented is equal post-incremented is equal  Examine each of the repeat commands and try each one in the IncrementUntilCondition object. If there are any question marks in your brain about this, don’t worry right now. The point of this section is to demonstrate that there is a variety of ways to make comparisons and to increment values. Upcoming labs will include better ways to display each loop repetition so that you can test each approach. More Repeat Variations with From...To... (Or, Another 3 Ways to Count to 20) Here is one more condition for repeat, repeating outa[9..4] from one value to another value. With each repetition of the loop, this form of repeat automatically adds 1 to the count each time through. Take a look at the code snippet below. The first time through the loop, outa[9..4] starts at 0. The second time through, 1 is automatically added, and the condition is checked to make sure outa[9..4] is greater than or equal to 0 or less than or equal to 19. 1 is added each time through the loop. After the repetition where outa[9..4] is equal to 19, it adds 1 to outa[9..4], making 20. Since 20 is not in the "from 0 to 19" range, the code in the loop does not execute. repeat outa[9..4] from 0 to 19 ' Add 1 to outa[9..4] with each repetition ' start at 0 and count through 19. Repeats Code ' block when outa[9..4] gets to 20. Propeller Education Kit Labs: Fundamentals · Page 59 I/O and Timing Basics Lab Here is a repeat command that serves a similar function using and. It tests for two conditions, both of which must be true in order for the loop to repeat. Here we need to increment outa[9..4] within the loop block: repeat while (outa[9..4] => 0) and (outa[9..4] =< 19) outa[9..4]++ Another nice thing about the repeat…from…to… form is you can use an optional step argument. For example, if you want to repeat what’s in a loop with outa[9..4] at all even values, and exit the loop leaving outa[9..4] at 20, here’s a way to do it: Repeat outa[9..4] from 0 to 18 step 2  Try the various repeat command variations in this section in the IncrementUntilCondition object. Some Operator Vocabulary Unary operators have one operand. For example, the Negate operator “-” in the expression -1 is a unary operator, and 1 is the operand. Binary operators have two operands; for example, the Subtract operator “-” in the expression x - y is a binary operator, and both x and y are operands. Normal operators, such as Add “+”, operate on their operands and provide a result for use by the rest of the expression without affecting the operand(s). Some operators we have used such as :=, ~~, ~, and ! are assignment operators. Unary assignment operators, such as ~ , ~~, and ++ write the result of the operation back to the operand whereas binary assignment operators, such as :=, assign the result to the operand to the immediate left. In both cases the result is available for use by the rest of the expression. The shift operators Shift Right “>>”and Shift Left“= or = 1 Each time through the repeat loop, the command if [9..4] == 0 uses the == operator to compare outa[9..4] against the value 0. If the expression is true, the result of the comparison is -1. If it’s false, the result is 0. Remember that by default outa[9..4] is initialized to zero, so the first time through the repeat loop outa[9..4] == 0 evaluates to true. This makes the if statement execute the command outa[9..4] := %100000, which turns on the P9 LED. After a 1/10 s delay, >>= (the Shift Right assignment operator) takes the bit pattern in outa[9..4] and shifts it right one bit with this instruction: outa[9..4] >>= 1. The rightmost bit that was in outa[4] is discarded, and the vacancy created in outa[9] gets filled with a 0. For example, if outa[9..4] stores %011000 before outa[9..4] >>= 1, it will store %001100 afterwards. If the command was outa[9..4] >>= 3, the resulting pattern would instead be %000011. Each time through the loop, the outa[9..4] >>= 1 command shifts the pattern to the right, cycling through %100000, %010000, %001000,…, %000001, %000000. When outa[9..4] gets to %000000, the if command sees that outa[9..4], stores a 0, so stores %100000 in outa[9..4], and the shifting LED light repeats.  Try changing the second operand in the shift right operation from 1 to 2, to make the pattern in outa[9..4] shift two bits at a time. You should now see every other LED blink from left to right. Propeller Education Kit Labs: Fundamentals · Page 61 I/O and Timing Basics Lab Variable Example The ButtonShiftSpeed object below is an expanded version of ShiftRightP9toP4 that allows you to use pushbuttons to control the speed at which the lit LED shifts right. If you hold the P21 pushbutton down the shift rate slows down; hold the P22 pushbutton down and the shift rate speeds up. The speed control is made possible by storing a value in a variable. The pattern that gets shifted from left to right is also stored in a variable, making a number of patterns possible that cannot be achieved by performing shift operations on the bits in outa[9..4].  Load ButtonShiftSpeed.spin into RAM.  Try holding down the P22 pushbutton and observe the change in the LED behavior, then try holding down the P21 pushbutton. '' File: ButtonShiftSpeed.spin '' LED pattern is shifted left to right at variable speeds controlled by pushbuttons. VAR Byte pattern, divide PUB ShiftLedsLeft dira[9..4] ~~ divide := 5 repeat if pattern == 0 pattern := %11000000 if ina[22] == 1 divide ++ divide = 1 waitcnt(clkfreq/divide + cnt) outa[9..4] := pattern pattern >>= 1 ButtonShiftSpeed has a variable (VAR) block that declares two byte-size variables, pattern and divide. The pattern variable stores the bit pattern that gets manipulated and copied to outa[9..4], and divide stores a value that gets divided into clkfreq for a variable-length delay. Byte is one of three options for variable declarations, and it can store a value from 0 to 255. Other options are word (0 to 65535) and long (-2,147,483,648 to 2,147,483,647). Variable arrays can be declared by specifying the number of array elements in brackets to the right of the variable name. For example, byte myBytes[20] would result in a 20-element array named myBytes. This would make available the variables myBytes[0], myBytes[1], myBytes[2],…, myBytes[18], and myBytes[19]. The first if block in the repeat loop behaves similarly to the one in the ShiftRightP9toP4 object. Instead of outa[9..4], the if statement examines the contents of the pattern variable, and if it’s zero, the next line reassigns pattern the value %11000000. Page 62 · Propeller Education Kit Labs: Fundamentals 4: I/O and Timing Basics Lab The Limit Minimum “#>”and Limit Maximum “” and Limit Maximum “ 0 Where did 624 come from?  The number of clock ticks between phsa~ and dira[17]~ was determined by replacing the 0.01 µF capacitor with a 100 pF capacitor and finding the lowest value before zero was returned. In the test program, time := phsa replaces time := (phsa – 624) #> 0, and the lowest measurable value was 625. Page 130 · Propeller Education Kit Labs: Fundamentals 7: Counter Modules and Circuit Applications Lab Example Object Measures RC Decay Time The TestRcDecay object applies the techniques just discussed to measure RC decay in a circuit with variable resistance controlled by the position of a potentiometer’s adjusting knob. As shown in Figure 7-5, the program displays a “working on other tasks” message after starting the RC decay measurement to demonstrate that the counter module automatically increments the phsa register until the voltage applied to P17 decays below the Propeller chip’s 1.65 V I/O pin threshold. The program can then check back at a later time to find out the value stored in phsa. Figure 7-5: RC Decay Times  Please note that the majority of the code examples in this lab are top objects that demonstrate various details and inner workings of counter modules. If you plan on incorporating these concepts into library objects that are designed to be used by other applications, make sure to pay close attention to the section entitled: Probe and Display PWM – Add an Object, Cog and Pair of Counters that begins on page 165.  Open the TestRcDecay.spin object. It will call methods in Parallax Serial Terminal.spin, so make sure they are both saved in the same folder.  Open Parallax Serial Terminal and set its Com Port field to the same port the Propeller Tool software uses to load programs into the Propeller chip.  Use the Propeller Tool to load TestRcDecay.spin into the Propeller chip.  Immediately click the Parallax Serial Terminal’s Enable button. (Don’t wait for the program to finish loading. In fact, you can click the Parallax Serial Terminal’s Enable button immediately after you have pressed F10 or F11 in the Propeller Tool software.)  Try adjusting the potentiometer knob to various positions and note the time values. They should vary in proportion to the potentiometer knob’s position. '' TestRcDecay.spin '' Test RC circuit decay measurements. CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 ' System clock → 80 MHz OBJ pst : "Parallax Serial Terminal" ' Use with Parallax Serial Terminal to ' display values Propeller Education Kit Labs: Fundamentals · Page 131 Counter Modules and Circuit Applications Lab PUB Init 'Start Parallax Serial Terminal; waits 1 s for you to click Enable button pst.Start(115_200) ' Configure counter module. ctra[30..26] := %01000 ctra[5..0] := 17 frqa := 1 ' Set mode to "POS detector" ' Set APIN to 17 (P17) ' Increment phsa by 1 for each clock tick main ' Call the Main method PUB Main | time '' Repeatedly takes and displays P17 RC decay measurements. repeat ' Charge RC circuit. dira[17] := outa[17] := 1 waitcnt(clkfreq/100_000 + cnt) ' Set pin to output-high ' Wait for circuit to charge ' Start RC decay measurement. It's automatic after this... phsa~ dira[17]~ ' Clear the phsa register ' Pin to input stops charging circuit ' Optional - do other things during the measurement. pst.Str(String(pst#NL, pst#NL, "Working on other tasks", pst#NL)) repeat 22 pst.Char(".") waitcnt(clkfreq/60 + cnt) ' Measurement has been ready for a while. Adjust ticks between phsa~ & dira[17]~. time := (phsa - 624) #> 0 ' Display Result pst.Str(String(pst#NL, "time = ")) pst.Dec(time) waitcnt(clkfreq/2 + cnt) Two Concurrent RC Decay Measurements Since a counter module keeps track of high time after the decay starts, and since each cog has two counter modules, it is possible to take two concurrent RC decay measurements on different pins with a single cog. Figure 7-6 shows an example of a second circuit connected to P25 to test concurrent decay measurements. Instead of a potentiometer for measuring knob position, this circuit has a phototransistor for measuring ambient indoor light levels. The amount of current the phototransistor allows to pass into its collector (C) terminal and then back out of its emitter (E) terminal is controlled by the brightness of light shining on its base (B) terminal. If the light is brighter, the phototransistor allows more current to pass, which results in faster capacitor decay times. If the light is dimmer, the phototransistor allows less current, resulting in longer decay times.  Locate the phototransistor in your PE Project Parts. There are three parts with clear plastic cases that resemble the infrared phototransistor on the right side of Figure 7-6. The two identical parts are infrared light emitting diodes. The third part will have a slightly shorter plastic case, and that’s the infrared phototransistor. Page 132 · Propeller Education Kit Labs: Fundamentals 7: Counter Modules and Circuit Applications Lab  Build the circuit shown in Figure 7-6. Figure 7-6: Second RC Decay Parts and Circuit Parts List Schematic ─────────────────────── ────────────────────────────────── 100 ω (1) Resistor - 100 ω P25 ─────┳───────────┐ (1) Phototransistor │ │ (1) Capacitor - 0.1 μF Photo-  0.1 μF (misc) Jumper wires transistor   GND GND ─────────────────────── ──────────────────────────────────  B C E The 100 Ω series resistor in the Figure 7-6 phototransistor circuit prevents current surges into the capacitor when the I/O pin first switches from input to output-high. The phototransistor conducts more current when the light is brighter. So under bright lighting conditions, the series resistor also reduces the load the phototransistor might otherwise place on the I/O pin as it charges the capacitor. With a phototransistor in the circuit, the 100 Ω resistor does not prevent the capacitor from charging to 3.3 V before the decay measurement. If the phototransistor were instead replaced with a resistive light sensor, lower light sensor resistances would result in lower initial voltages before decay measurements, just like it would if it were added to the Figure 7-1 potentiometer circuit. TestRcDecay.spin can be modified so that it uses Counter B to measure light levels during a time period that overlaps with the Counter A potentiometer knob position decay measurement. Since a single cog manages both measurements, it initiates them sequentially—one after the other. However, since both counter modules can track the decay times independently, the cog’s code does not have to wait for the first measurement to finish before starting the second one. It can start them both, one immediately after the other and then move on to other tasks and check the results in the phase registers later. One approach to modifying TestRcDecay.spin for the two measurements would be to start by converting the time variable to a two-element array so that each measurement can be stored in a different element: PUB Main | time[2] Each counter module can then be set to positive detector mode, with one monitoring P17 and the other monitoring P25, like this: ' Configure counter modules. ctra[30..26] := %01000 ctra[5..0] := 17 frqa := 1 ' Set CTRA mode to "POS detector" ' Set APIN to 17 (P17) ' Increment phsa by 1 for each clock tick ctrb[30..26] := %01000 ctrb[5..0] := 25 frqb := 1 ' Set CTRB mode to "POS detector" ' Set APIN to 25 (P25) ' Increment phsb by 1 for each clock tick Both I/O pins can be set to output-high to charge both capacitors before starting the decay measurements. The capacitor in the phototransistor circuit is 10 times larger than the one in the potentiometer circuit, and there is also a resistor limiting the current charging the capacitor, so it might take longer to charge. With this in mind, the delay before the measurements starts should be increased from 10 μs to at least 100 μs by changing clkfeq/100_000 to clkfreq/10_000. ' Charge RC circuits. dira[17] := outa[17] := 1 dira[25] := outa[25] := 1 waitcnt(clkfreq/10_000 + cnt) ' Set P17 to output-high ' Set P25 to output-high ' Wait for circuit to charge Propeller Education Kit Labs: Fundamentals · Page 133 Counter Modules and Circuit Applications Lab Since the counter modules are measuring the decay times, the cog can start each measurement in rapid succession without waiting for the first one to finish before starting the second. The potentiometer measurement is started by clearing phsa and dira[17]. When phsa is cleared, the counter module resumes counting clock ticks from zero. Since the counter is operating in POS detector mode, frqa gets added to phsa when P17 has a high signal applied to it. When dira[17] is cleared, the I/O pin becomes an input. As an input, it no longer delivers charge to the capacitor, so the capacitor’s voltage starts to decay. This process is repeated for the phototransistor circuit connected to P25 by clearing phsb and dira[25]: ' Start RC decay measurements... phsa~ dira[17]~ phsb~ dira[25]~ ' ' ' ' Clear the phsa register Pin to input stops charging circuit Clear the phsb register Pin to input stops charging circuit After enough time has passed, the contents of one phase register can be copied into the time[0] variable and the other into time[1]: ' Measurement has been ready for a while. Adjust ticks between phsa~ ' and dira[17]~. Repeat for phsb~ and dira[25]~. time[0] := (phsa - 624) #> 0 time[1] := (phsb - 624) #> 0 Last, but certainly not least, display both results: ' Display Results pst.Str(String(pst#NL, "time[0] = ")) pst.Dec(time[0]) pst.Str(String(pst#NL,"time[1] = ")) pst.Dec(time[1]) waitcnt(clkfreq/2 + cnt)  Make a copy of TestRcDecay.spin.  Use the approach just discussed to modify the copy so that it measures the circuits from Figure 7-1 and Figure 7-6 concurrently. The code does not have to wait for a fixed period of time before checking the phase registers. It can instead find out if a given measurement is done by polling (repeatedly checking) the state of the I/O pin. After the decay measurement has started, if ina[17] stores a 1, it means the decay is still in progress, so don’t check phsa yet. If it stores 0 instead, the measurement is done. Likewise, if ina[25] stores a 1, the light measurement is still in progress, so don’t check phsb yet. Here is a simple modification that makes the cog wait for both measurements to finish before copying the contents of the phase registers to the time variables: ' Poll until both measurements are done. Then, adjust ticks between phsa~ ' and dira[17]~ as well as phsb~ and dira[25]~. repeat until ina[17] == 0 and ina[25] == 0 time[0] := (phsa - 624) #> 0 time[1] := (phsb - 624) #> 0 With all the delays in the code, there isn’t an appreciable difference in the display rate. It becomes more evident when you comment the code that causes the delays (except the waitcnt that gives the Page 134 · Propeller Education Kit Labs: Fundamentals 7: Counter Modules and Circuit Applications Lab capacitors time to charge). It also helps to declare a variable for counting the repeat loop repetitions and to increment and display its value between each measurement. With this arrangement, you’ll be able to see that many measurements per second are taken.  Try it. Objects for RC Measurements You have just finished examining certain techniques that go into creating an RC decay measurement object that utilizes counter modules.  If your application measures one or more RC decay circuits, there’s no need to use the example code here. It’s much easier to instead use an RC decay measurement object. There’s a nice one posted on the PE Kit Resources page at www.parallax.com/go/pekit. Look for the Measure Resistance and Capacitance link. It features a variety of circuit examples and sensor measurement techniques you can try with your PE Kit. D/A Conversion – Controlling LED Brightness with DUTY Modes There are two DUTY mode options, single-ended and differential. A counter module in single-ended DUTY mode allows you to control a signal that can be used for digital to analog conversion with the FRQ register. Although the signal switches rapidly between high and low, the average time it is high (the duty) is determined by the ratio of the FRQ register to 232. pin high time FRQ duty = ───────────── = ───────────── time 4_294_967_296 Eq. 1 For D/A conversion, let’s say the program has to send a 0.825 V signal. That’s 25% of 3.3 V, so a 25% duty signal is required. Figuring out the value to store in the FRQ register is simple. Just set duty = 0.25 and solve for FRQ. FRQ 0.25 = ───────────── 4_294_967_296 → FRQ = 1_073_741_824 You can also use Eq. 1 to figure out what duty signal an object is sending. Let’s say the value 536,870,912 is stored in a counter module’s FRQ register, and its CTR register has it configured to single-ended DUTY mode. 536_870_912 duty = ───────────── = 0.125 4_294_967_296 On a 3.3 V scale, that would resolve to 0.4125 V. Again, the great thing about counters is that they can do their jobs without tying up a cog. So, the cog will still be free to continue executing commands while the counter takes care of maintaining the D/A conversion duty signal. How Single-ended DUTY Mode Works Each time FRQ gets added to PHS, the counter module’s phase adder (that adds FRQ to PHS with every clock tick) either sets or clears a carry flag. This carry operation is similar to a carry operation Propeller Education Kit Labs: Fundamentals · Page 135 Counter Modules and Circuit Applications Lab in decimal addition. Let’s say you are allowed 3 decimal places, and you try to add two values that add up to more than 999. Some value would normally be carried from the hundreds to the thousands slot. The binary version of addition-with-carry applies when the FRQ register gets added to the PHS register when the result is larger than 232 − 1. If the result exceeds this value, the PHS adder’s carry flag (think of it as the PHS registers “bit 32”) gets set. The interesting thing about this carry flag is that the amount of time it is 1 is proportional to the value stored in the FRQ register divided by 232. In single-ended DUTY mode, the counter module’s phase adder’s carry bit controls an I/O pin’s output state. Since the time in which the phase adder’s carry bit is 1 is proportional to FRQ/232, so is the I/O pin’s output state. The I/O pin may rapidly switch between high and low, but the average pin high time is determined by the FRQ-to-232 ratio shown in Eq. 1 above. Parts and Circuit Yes, it’s back to LEDs for just a little while, and then we’ll move on to other circuits. Previous labs used LEDs to indicate I/O pin states and timing. This portion of this lab will use single-ended DUTY mode for D/A conversion to control LED brightness. Figure 7-7: LED Circuit for Brightness Control with Duty Signals Parts List ─────────────────── (4) Resistors 100 ω (2) LEDs - green (2) LEDs - yellow (misc) Jumper wires ─────────────────── Schematic ────────────────────── green 100 ω LED P4 ────────────┐ green │ 100 ω LED │ P5 ────────────┫ yellow │ 100 ω LED │ P6 ────────────┫ yellow │ 100 ω LED │ P7 ────────────┫  GND ──────────────────────  Add the circuit shown in Figure 7-7 to your PE Platform, leaving the RC decay circuit in place. Configuring a Counter for DUTY Mode Figure 7-8 shows more entries from the CTR object’s and Propeller Manual’s Counter Mode Table. As mentioned previously, the two types of DUTY modes are single-ended and differential. With single-ended DUTY mode, the APIN mirrors the state of the phase adder’s carry bit. So, if FRQ is set to the 1,073,741,824 value calculated earlier, the APIN will be high ¼ of the time. An LED circuit receiving this signal will appear to glow at ¼ of its full brightness. In differential DUTY mode, the APIN signal still matches the phase adder’s carry bit, while the BPIN is the opposite value. So whenever the phase adder’s carry bit (and APIN) are 1, BPIN is 0, and viceversa. If FRQ is set to 1,073,741,824, APIN would still cause an LED to glow at ¼ brightness while BPIN will glow at ¾ brightness. Page 136 · Propeller Education Kit Labs: Fundamentals 7: Counter Modules and Circuit Applications Lab Figure 7-8: More Excerpts from the CTR.spin’s Counter Mode Table Accumulate APIN BPIN CTRMODE Description FRQ to PHS output* output* ┌────────┬─────────────────────────────┬────────────┬────────────┬────────────┐ │ %00000 │ Counter disabled (off) │ 0 (never) │ 0 (none) │ 0 (none) │ ├────────┼─────────────────────────────┼────────────┼────────────┼────────────┤ . . . ├────────┼─────────────────────────────┼────────────┼────────────┼────────────┤ │ %00110 │ DUTY single-ended │ 1 │ PHS-Carry │ 0 │ │ %00111 │ DUTY differential │ 1 │ PHS-Carry │ !PHS-Carry │ ├────────┼─────────────────────────────┼────────────┼────────────┼────────────┤ . . . │ %11111 │ LOGIC always │ 1 │ 0 │ 0 │ └────────┴─────────────────────────────┴────────────┴────────────┴────────────┘ * must set corresponding DIR bit to affect pin A¹ = APIN input delayed by 1 clock A² = APIN input delayed by 2 clocks B¹ = BPIN input delayed by 1 clock Figure 7-9 is a repeat of Figure 7-4. From Figure 7-8, we know that the value stored in the CTR register’s CTRMODE bit field has to be either %00110 (DUTY single-ended) or %00111 (DUTY differential). Then, the APIN (and optionally BPIN) bit fields have to be set to the I/O pins that will transmit the duty signals. Figure 7-9: CTRA/B Register Map from CTR.spin ┌────┬─────────┬────────┬────────┬───────┬──────┬──────┐ bits │ 31 │ 30..26 │ 25..23 │ 22..15 │ 14..9 │ 8..6 │ 5..0 │ ├────┼─────────┼────────┼────────┼───────┼──────┼──────┤ Name │ ── │ CTRMODE │ PLLDIV │ ────── │ BPIN │ ──── │ APIN │ └────┴─────────┴────────┴────────┴───────┴──────┴──────┘ The RC decay application set the FRQ register to 1, and the result was that 1 got added to PHS for every clock tick in which the pin being monitored was high. In this application, the FRQ register gets set to values that control the high time of the duty signal applied to an I/O pin. There is no condition for adding with duty mode; FRQ gets added to PHS every clock tick. Setting up a Duty Signal Here are the steps for setting a duty signal either with a counter: (1) (2) (3) (4) (5) Set the CTR register’s CTRMODE bit field to choose duty mode. Set the CTR register’s APIN bit field to choose the pin. If you are using differential DUTY mode, set the CTR register’s BPIN field. Set the I/O pin(s) to output. Set the FRQ register to a value that gives you the percent duty signal you want. Propeller Education Kit Labs: Fundamentals · Page 137 Counter Modules and Circuit Applications Lab Example – Send a 25% single-ended duty signal to P4 Using Counter A. (1) Set the CTR register’s CTRMODE bit field to choose a DUTY mode. Remember that bits 30..26 of the CTR register (shown in Figure 7-9) have to be set to the bit pattern selected from the CTRMODE list in Figure 7-8. For example, here’s a command that configures the counter module to operate in single-ended DUTY mode: ctra[30..26] := %00110 (2) Set the CTR register’s APIN bit field to choose the pin. Figure 7-9 indicates that APIN is bits 5..0 in the CTR register. Here’s an example that sets the ctra register’s APIN bits to 4, which will control the green LED connected to P4. ctra[5..0] := 4 We’ll skip step (3) since the counter module is getting configured to single-ended DUTY mode and move on to: (4) Set the I/O pin(s) to output. dira[4]~~ (5) Set the FRQ register to a value that gives you the duty signal you want. For ¼ brightness, use 25% duty. So, set the frqa register to 1_073_741_824 (calculated earlier). frqa := 1_073_741_824 Tips for Setting Duty with the FRQ Register Since the special purpose registers initialize to zero, frqa is 0, so 0 is repeatedly added to the PHS register, resulting on no LED state changes. As soon as the program sets the FRQ register to some fraction of 232, the I/O pin, and the LED, will start sending the duty signal. Having 232 different LED brightness levels isn’t really practical, but 256 different levels will work nicely. One simple way to accomplish that is by declaring a constant that’s 232 ÷ 256. CON scale = 16_777_216 ' 232 ÷ 256 Now, the program can multiply the scale constant by a value from 0 to 255 to get 256 different LED brightness levels. Now, if you want ¼ brightness, multiply scale by ¼ of 256: frqa := 64 * scale  Time Varying D/A and Filtering: When modulating the value of frqa to send time varying signals, an RC circuit typically filters the duty signal. It’s better to use a smaller fraction of the useable duty signal range, say 25% to 75% or 12.5% to 87.5%. By keeping the duty in this middle range, the D/A will be less noisy and smaller resistor R and capacitor C values can be used for faster responses. This is especially important for signals that vary quickly, like audio signals, which will be introduced in a different lab. R duty signal ────────┳─── voltage C  GND Page 138 · Propeller Education Kit Labs: Fundamentals 7: Counter Modules and Circuit Applications Lab Single-Ended DUTY Mode Code Example The LedDutySweep.spin object demonstrates the steps for configuring a counter single-ended DUTY mode and transmitting a duty signal with an I/O pin. It also sweeps a duty variable from 0 to 255 repeatedly, causing the P4 LED to gradually increase in brightness and then turn off.  Load the LedDutySweep object into the Propeller chip and observe the effect. ''LedDutySweep.spin ''Cycle P4 LED from off, gradually brighter, full brightness. CON scale = 16_777_216 ' 2³²÷ 256 PUB TestDuty | pin, duty, mode 'Configure counter module. ctra[30..26] := %00110 ctra[5..0] := 4 frqa := duty * scale ' Set ctra to DUTY mode ' Set ctra's APIN ' Set frqa register 'Use counter to take LED from off to gradually brighter, repeating at 2 Hz. dira[4]~~ ' Set P5 to output repeat repeat duty from 0 to 255 frqa := duty * scale waitcnt(clkfreq/128 + cnt) ' ' ' ' Repeat indefinitely Sweep duty from 0 to 255 Update frqa register Delay for 1/128th s Duty – Single Ended vs. Differential Modes Differential is the second option for DUTY mode, as well as several other counter modes. Differential signals are useful for getting signals across longer transmission lines, and are used in wired Ethernet, RS485, and certain audio signals. When a counter module functions in differential mode, it uses one I/O pin to transmit the same signal that single-ended transmits, along with a second I/O pin that transmits the opposite polarity signal. For example, a counter module set to duty differential mode can send the opposite signal that P4 transmits on P5 or any other I/O pin. Whenever the signal on P4 is high, the signal on P5 is low, and vice versa. Try modifying a copy of LedDutySweep.spin so that it sends the differential signal on P5. Then, as the P4 LED gets brighter, the P5 LED will get dimmer. Here are the steps:  Save a copy of the LedDutySweep object that you will modify.  To set the counter module for differential DUTY mode, change ctra[30..26] := %00110 to ctra[30..26] := %00111.  Set the ctra module’s BPIN bit field by adding the command ctra[14..9] := 5  Set P5 to output so that the signal gets transmitted by the I/O pin with the command dira[5]~~. Using Both A and B Counter Modules Using both counter modules to display different LED brightness levels is also a worthwhile exercise. To get two counter modules sending duty signals on separate pins, try these steps: Propeller Education Kit Labs: Fundamentals · Page 139 Counter Modules and Circuit Applications Lab      Save another copy of the original, unmodified (single-ended) LedDutySweep object. Add ctrb[30..26] := %00110. Assuming ctrb will control P6, add ctrb[5..0] := 6. Also assuming ctrb will control P6, add dira[6]~~. In the repeat duty from 0 to 255 loop, make frqb twice the value of frqa with the command frqb := 2 * frqa. This will cause the P6 LED to get bright twice as fast as the P4 LED. Inside DUTY Mode Let’s take a closer look at how this works by examining the 3-bit version. Since the denominator of the fraction is 2 raised to the number of bits in the register, a 3-bit version of FRQ would be divided by 23 = 8: pin high time frq duty = ───────────── = ───── time 8 (3-bit example) Let’s say the carry bit needs to be high 3/8 of the time. The 3-bit version of the FRQ register would have to store 3. The example below performs eight additions of 3-bit-FRQ to 3-bit-PHS using longhand addition. The carry bit (that would get carried into bit-4) is highlighted with the ↓ symbol whenever it’s 1. Notice that out of eight PHS = PHS + FRQ additions, three result in set carry bits. So, the carry bit is in fact set 3/8 of the time. carry flag set 3-bit frq 011 3-bit phs(previous) +000 ──── 3-bit phs(result) 011 ¹¹ 011 +011 ──── 110 ↓ ¹¹ 011 +110 ──── 001 ¹¹ 011 +001 ──── 100 011 +100 ──── 111 ↓ ¹¹¹ 011 +111 ──── 010 ¹ 011 +010 ──── 101 ↓ ¹¹¹ 011 +101 ──── 000 Binary Addition works just like decimal addition when it’s done “long hand”. Instead of carrying a digit from 1 to 9 when digits in a particular column add up to a value greater than 9, binary addition carries a 1 if the result in a column exceeds 1. Binary Result  0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 10 (0, carry the 1) 1+1+1 = 11 (1, carry the 1) Special Purpose Registers Each cog has a special purpose register (SPR) array whose elements can be accessed with spr[index]. The index value lets you pick a given special purpose register. For example, you can set the value of ctra by assigning a value to spr[8], or ctrb by assigning a value to spr[9]. Likewise, you can assign values to frqa and frqb by assigning values to spr[10] and spr[11], or phsa and phsb by assigning values to spr[12] and spr[13]. A full list of the SPR array elements can be found in the Propeller Manual.  Look up SPR in the Spin Language reference section of the Propeller Manual, and review the SPR explanation and table of SPR array elements. Page 140 · Propeller Education Kit Labs: Fundamentals 7: Counter Modules and Circuit Applications Lab The advantage to using SPR array elements is that they are accessible by index values. Also, ctrb, frqb, and phsb are all one array element above ctra, frqa, and phsa. This makes it possible to choose between A and B counter registers by simply adding 1 to (or subtracting 1 from) the index value used to access a given SPR register. This in turn makes it possible to eliminate condition statements for deciding which counter module to use and it also makes it possible to initialize and update counter modules within looping structures. One drawback to special purpose registers is that they are not bit-addressable. For example, the commands ctra[30..26] := %00110 and ctra[5..0] := 4 have to be coded differently for spr[8], which is the ctra special purpose array element. The most convenient way to accomplish these two commands in Spin language with the SPR array is like this: spr[8] := (%00110
130-32000 价格&库存

很抱歉,暂时无法提供与“130-32000”相匹配的价格&库存,您可以联系我们找货

免费人工找货