28123 Parallax Inc, 28123 Datasheet

TEXT WHAT'S A MICROCONTROLLER

28123

Manufacturer Part Number
28123
Description
TEXT WHAT'S A MICROCONTROLLER
Manufacturer
Parallax Inc
Type
Programmingr
Datasheet

Specifications of 28123

Style
Book
Title
What's a Microcontroller?
Contents
Whats a Microcontroller? Text
Product
Microcontroller Accessories
Core Processor
PIC16C57c
Flash
128 Bytes
Operating Supply Voltage
9 V
Board Size
31 mm x 16 mm
Lead Free Status / RoHS Status
Not applicable / Not applicable
What’s a Microcontroller?
Student Guide
VERSION 2.2

Related parts for 28123

28123 Summary of contents

Page 1

What’s a Microcontroller? Student Guide VERSION 2.2 ...

Page 2

... 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 ...

Page 3

... 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 BASIC Stamp application, no matter how life-threatening it may be. WEB SITE AND DISCUSSION LISTS The Parallax Inc. web site (www.parallax.com) has many downloads, products, customer applications and on-line ordering for the components used in this text. We also maintain several e-mail discussion lists for people interested in using Parallax products. These lists are accessible from www.parallax.com via the Support → ...

Page 4

Preface.........................................................................................................................v Audience.........................................................................................................................v Support and Discussion Groups .....................................................................................v Teacher’s Guide ............................................................................................................vi The Stamps in Class Curriculum ...................................................................................vi Foreign Translations .....................................................................................................viii Special Contributors .....................................................................................................viii Chapter #1: Getting Started.......................................................................................1 How Many Microcontrollers Did You Use Today? ..........................................................1 The BASIC Stamp 2 - Your ...

Page 5

Chapter #4: Controlling Motion ............................................................................ 103 Microcontrolled Motion ............................................................................................... 103 On/Off Signals and Motor Motion ............................................................................... 103 Activity #1: Connecting and Testing the Servo........................................................... 103 Activity #2: Controlling Position with Your Computer ................................................. 119 Activity #3: Converting Position to Motion ...

Page 6

Summary ....................................................................................................................258 Chapter #9: Electronic Building Blocks ...............................................................263 Those Little Black Chips .............................................................................................263 Expand Your Projects with Peripheral Integrated Circuits ..........................................264 Activity #1: Control Current Flow with a Transistor.....................................................265 Activity #2: Introducing the Digital Potentiometer .......................................................267 Summary ....................................................................................................................278 Chapter #10: ...

Page 7

Preface This text answers the question “What’s a microcontroller?” by showing students how they can design their own customized, intelligent inventions with Parallax, Inc.’s BASIC Stamp microcontroller module. The activities in this text incorporate a variety of fun ® and ...

Page 8

Educational Support: stampsinclass@parallax.com Contact the Parallax Stamps in Class Team directly if you are having difficulty subscribing to either of these Yahoo! Groups, or have questions about the material in this text, our Stamps in Class Curriculum, our Educator’s Courses, ...

Page 9

... Energy focus more closely on topics in electronics, while StampWorks provides a variety of projects that are useful to hobbyists, inventors and product designers interested in trying a variety of projects. “Elements of Digital Logic”, Student Guide, Version 1.0, Parallax Inc., 2003 “Experiments with Renewable Energy”, Student Guide, Version 1.0, Parallax Inc., 2004 “ ...

Page 10

FOREIGN TRANSLATIONS Parallax educational texts may be translated to other languages with our permission (e- mail stampsinclass@parallax.com). If you plan on doing any translations please contact can provide the correctly-formatted MS Word documents, images, etc. We also ...

Page 11

Chapter #1: Getting Started HOW MANY MICROCONTROLLERS DID YOU USE TODAY? A microcontroller is a kind of miniature computer that you can find in all kinds of gizmos. Some examples of common, every-day products that have microcontrollers built-in are shown ...

Page 12

... In this text, “BASIC Stamp” refers to Parallax Inc.’s BASIC Stamp module. There are other BASIC Stamp modules, some of which are shown in Figure 1-3. Each BASIC Stamp module is color coded. The BASIC Stamp 2 is green. The BASIC Stamp 2e is red. The BASIC Stamp 2SX is blue, and the BASIC Stamp 2p is gold. Each variation on the BASIC Stamp 2 is slightly different, featuring higher speed, more memory, additional functionality, or some combination of these extra features ...

Page 13

... Parallax Inc.’s Boe-Bot can be tackled using the Boe-Bot after you’ve worked through the activities in this one. The robot on the right was built by a group of students and entered into a First Robotics competition. The goal of the contest is different each year. In the example shown, the goal was to see which group’ ...

Page 14

With the help of microcontrollers, robots will also take on day-to-day tasks, such as mowing the lawn. The BASIC Stamp module inside the robotic lawn mower shown in Figure 1-6 helps it stay inside the boundaries of the lawn, and ...

Page 15

You will build circuits for displays, sensors, and motion controllers. You will learn how to connect these circuits to the BASIC ...

Page 16

Computer System Requirements You will need either laptop computer to run the BASIC Stamp Editor software. Getting started with BASIC Stamp programming is easiest if your PC or laptop has the following features: Microsoft Windows 95 or ...

Page 17

When you get to the BASIC Stamp Software page, find the most recent version of the BASIC Stamp Windows Editor download, with a version number of 2.0 or higher. √ Click the Download icon. In Figure 1-9, the download ...

Page 18

Wait while the BASIC Stamp Editor installation program downloads (shown in Figure 1-12). This may take a while if you are using a modem connection. √ When the download is complete, leave the window shown in Figure 1-13 open ...

Page 19

If the Welcome application does not automatically run, double-click My Computer, then double-click your CD drive, then double-click Welcome. √ Click the Software link shown in Figure 1-14. √ Click the + next to the BASIC Stamps folder shown ...

Page 20

Free downloads at the Parallax web site are included in the Parallax CD, but only up to the date the CD was created. The date on the front of the CD indicates when it was created. If the CD is ...

Page 21

If you located the software on the Parallax CD, click the Install button shown in Figure 1-17. √ When the BASIC Stamp Editor InstallShield Wizard window opens, click the Next button shown in Figure 1-18. √ Select Typical for ...

Page 22

Click the Next button. √ When the InstallShield Wizard tells you it is “Ready to Install the Program”, click the Install button shown in Figure 1-20. √ When the InstallShield Wizard window tells you “InstallShield Wizard Completed”, as shown ...

Page 23

... BASIC Stamp Editor to test the system. This activity will show you how. ® Introducing the BASIC Stamp Parallax Inc.’s Board of Education Stamp module. As mentioned earlier, the BASIC Stamp is a type of very small computer. This very small computer plugs into the Board of Education carrier board. As you will soon see, the Board of Education makes it easy to connect a power supply and serial cable to the BASIC Stamp module ...

Page 24

Parallax, Inc.’s BASIC Stamp HomeWork Board is like a Board of Education with the BASIC Stamp 2 module built-in. Its surface- mounted components are visible to the left of the white breadboard area. You can use either the Board of ...

Page 25

CAUTION! Before using an AC adapter, “battery replacer” supply: √ Consult Appendix D: Batteries and Power Supplies on page 311 to make sure the supply you use is appropriate for the activities in this text. Connecting the Hardware ...

Page 26

USB Port Adapter If you are using a USB to Serial Adapter: √ Connect the USB end to your PC’s USB port. √ Connect the COM port adapter either directly to your Board of Education or HomeWork Board, or connect ...

Page 27

Plug a DC power supply into the 6-9 VDC jack as shown in step-3, or plug a 9-V battery into the 9 VDC battery jack as shown in step-4. √ Move the 3-position switch from position-0 to position-1. The ...

Page 28

Power Reset ® BASIC Stamp HomeWork Board Testing for Communication The BASIC Stamp Editor has a feature for testing to make sure your PC or laptop can communicate with your BASIC Stamp module. √ Double-click the BASIC Stamp Editor ...

Page 29

The Windows Start Menu can also be used to run the BASIC Stamp Editor. Click your Windows Start button, then select Programs → Parallax, Inc. → BASIC Stamp Editor 2…, then click the BASIC Stamp Editor icon. Your BASIC Stamp ...

Page 30

ACTIVITY #4: FIRST PROGRAM The first program you will write and test will tell the BASIC Stamp to send a message to your PC or laptop. Figure 1-33 shows how it sends a stream of ones and zeros to communicate ...

Page 31

You will enter this program into the BASIC Stamp Editor. Some lines of the program are made automatically by clicking buttons on the toolbar. Other lines are made by typing them in from the keyboard. √ Begin by clicking the ...

Page 32

Save your work by clicking File and selecting Save as shown in Figure 1-37. √ Enter the name FirstProgram into the File name field near the bottom of the Save As window as shown in Figure 1-38. √ Click ...

Page 33

A Download Progress window will appear briefly as the program is transmitted from the PC or laptop to your BASIC Stamp module. Figure 1-40 shows the Debug Terminal that should appear when the download is complete. You can prove to ...

Page 34

The BASIC Stamp Editor has shortcuts for most common tasks. For example, to run a program, you can press the ‘Ctrl’ and ‘R’ keys at the same time. You can also click the Run button. It’s the blue triangle shown ...

Page 35

A command is a word you can use to tell the BASIC Stamp do a certain job. The first of the two commands in this program is called the DEBUG "Hello, it's me, your BASIC Stamp!" This is the command ...

Page 36

Save the changes you made by clicking File and selecting Save. Your program should now look like the one shown in Figure 1-42. √ Run your modified program. You will have to either select Run from the Run menu ...

Page 37

ACTIVITY #5: LOOKING UP ANSWERS The two activities you just finished introduced two PBASIC commands: You can find out more about these commands and how they are used by looking them up, either in the BASIC Stamp Editor’s Help or ...

Page 38

Your Turn √ Use the scrollbar to review the lots of explanations and example programs you can try. √ Click the Contents tab, and find DEBUG there. √ Click the Search tab, and run a search for the word DEBUG. ...

Page 39

Viewing the BASIC Stamp Manual on the Parallax CD √ Click the Documentation link. √ Click the + next to the BASIC Stamps folder. √ Click the BASIC Stamp Manual book icon. √ Click the View button. √ Figure 1-47 ...

Page 40

Your Turn √ Use the BASIC Stamp Manual’s Index to look up the √ Look up the command in the BASIC Stamp Manual. END ACTIVITY #6: INTRODUCING ASCII CODE In Activity #4, you used the formatter with the DEC number ...

Page 41

How ASCIIName.bs2 Works Each letter in the command corresponds to one ASCII code symbol that appeared DEBUG in the Debug Terminal. DEBUG 66,65,83,73,67,32,83,116,97,109,112,32, the ASCII code for capital “B” the code for capital “A” and so ...

Page 42

Disconnecting Power With the Board of Education Rev C, disconnecting power is easy. If you are using the Board of Education Rev C, power is disconnected by moving the 3-position switch to position-0 by pushing it to the left as ...

Page 43

SUMMARY This chapter guided you through the following: An introduction to some devices that contain microcontrollers • An introduction to the BASIC Stamp module • A tour of some interesting inventions made with BASIC Stamp modules. • Where to get ...

Page 44

Guess what the Debug Terminal would display if you ran this command: DEBUG DEC There is a problem with these two commands. When you run the code, the numbers they display are stuck together so ...

Page 45

... Parallax web site or the Parallax CD to get a free copy of this text and of the BASIC Stamp Manual. Printed copies can also be purchased from Parallax. “BASIC Stamp Manual”, Users Manual, Version 2.0c, Parallax Inc., 2000 You can learn much more about the up in the BASIC Stamp Manual ...

Page 46

Chapter #2: Lights On – Lights Off INDICATOR LIGHTS Indicator lights are so common that most people tend not to give them much thought. Figure 2-1 shows three indicator lights on a laser printer. Depending on which light is on, ...

Page 47

An LED circuit can be connected to the BASIC Stamp, and the BASIC Stamp can be programmed to connect and disconnect the LED circuit’s power. This is much easier than manually changing the circuit’s wiring or connecting and disconnecting the ...

Page 48

Yellow Resistors like the ones we are using in this activity have colored stripes that tell you what their resistance values are. There is a different color combination for each resistance value. For example, the color code for ...

Page 49

The first stripe is yellow, which means the leftmost digit • The second stripe is violet, which means the next digit • The third stripe is brown. Since brown means add ...

Page 50

When you start building your circuit, make sure to check it against the schematic symbol and part drawing. For the part drawing, note that the LED’s leads are different lengths. The longer lead is connected to the LED’s anode, and ...

Page 51

Vdd Vin X3 P15 P14 P13 P12 P11 P10 Input/output pins are usually called I/O pins, and after connecting your circuit to one or more of these I/O pins, ...

Page 52

Plug the resistor’s other lead into one of the sockets labeled Vdd. Direction does matter for the LED, but not for the resistor. If you plug the LED in backward, the LED will not emit light when you connect ...

Page 53

Double check to make sure you built your circuit exactly as shown in Figure 2- 6. √ If you are using a What’s a Microcontroller kit that somebody used before you, the LED may be damaged, so try a ...

Page 54

Chemical reactions inside the battery supply the circuit with current. The battery’s negative terminal contains a compound that has molecules with extra electrons (shown in Figure 2-7 by minus-signs). The battery’s positive terminal has a chemical compound with molecules that ...

Page 55

Your Turn – Modifying the LED Test Circuit In the next activity, you will program the BASIC Stamp to turn the LED on, then off, then on again. The BASIC Stamp will do this by switching the LED circuit between ...

Page 56

You will also experiment with programs that make the BASIC Stamp do this at different speeds. SOUT VIN 1 24 SIN VSS 2 23 BS2 ATN RES 3 22 VSS VDD (+5V Vdd P15 ...

Page 57

P14 Ω 470 LED Vss Resistors are essential. Always remember to use a resistor. Without it, too much current will flow through the circuit, and it could damage any number of parts in your circuit, BASIC Stamp, or Board of ...

Page 58

DO HIGH 14 PAUSE 500 LOW 14 PAUSE 500 LOOP How LedOnOff.bs2 Works The command DEBUG "The LED connected to Pin 14 is blinking!" statement appear in the Debug Terminal. The command Stamp to internally connect I/O pin P14 to ...

Page 59

DO HIGH 14 PAUSE 250 LOW 14 PAUSE 250 LOOP A Diagnostic Test for your Computer A very few computers, such as some laptops, will halt the PBASIC program after the first time through a loop. These computers have a ...

Page 60

So, you should be able to run all of the remaining DEBUG programs in this book even if your computer failed the diagnostic test. Your Turn – Timing and Repetitions By changing the command’s PAUSE time ...

Page 61

Here is how to test to see what your persistence of vision threshold is: √ Try modifying both of your they are 100. √ Re-run your program and check for flicker. √ Reduce both Duration √ Keep ...

Page 62

In this activity, you will program the BASIC Stamp to stop flashing the LED on and off after ten repetitions. Counting Parts and Test Circuit Use the example circuit shown in Figure 2-11 ...

Page 63

Run the program a second time, and verify that the value of the Debug Terminal accurately tracks how many times the LED blinked. Hint: instead of clicking Run a second time, you can press and release the Reset button ...

Page 64

What’s a Byte? A byte is enough memory to store a number between 0 and 255. The BASIC Stamp has four different types of variables, and each can store a different range of numbers: Table 2-2: Variable Types and Values ...

Page 65

DEBUG "All done!" This command is included just to show what the program does after ten times through the loop. It moves on to the command that comes after the FOR…NEXT Your Turn – Other Ways to Count √ Replace ...

Page 66

Building and Testing the Second LED Circuit In Activity #1, you manually tested the first LED circuit to make sure it worked before connecting it to the BASIC Stamp. Before connecting the second LED circuit to the BASIC Stamp, it’s ...

Page 67

P15 Ω 470 P14 Ω 470 LED Vss Using a Program to Test the Second LED Circuit In Activity #2, you used an example program and the the LED circuit connected to P14. These commands will have to be modified ...

Page 68

DO HIGH 15 PAUSE 500 LOW 15 PAUSE 500 LOOP Controlling Both LEDs Yes, you can flash both LEDs at once. One way you can do this is to use two commands before the first PAUSE next command sets P15 ...

Page 69

Your Turn – Alternate LEDs You can cause the LEDs to alternate by swapping the control one of the I/O pins. This means that while one LED is on, the other will be off. √ Modify FlashBothLeds.bs2 so that the ...

Page 70

Introducing the Bi-Color LED The bi-color LED’s schematic symbol and part drawing are shown in Figure 2-16. 1 LED- bicolor Red Green 2 The bi-color LED is really just two LEDs in one package. Figure 2-17 shows how you can ...

Page 71

Vdd Vdd 470 Ω 470 Ω LED- LED Red Green Vss Vss Bi-Color LED Circuit Parts (1) LED – bi-color (1) Resistor 470 Ω (yellow-violet-brown) (1) Jumper wire Building and Testing the Bi-Color LED Circuit Figure ...

Page 72

Vdd Vin Vss X3 P15 P14 P13 P12 P11 P10 Controlling a bi-color LED with the BASIC Stamp requires two I/O pins. After you have manually verified ...

Page 73

BASIC Stamp Bi-Color LED Control Figure 2-20 shows how you can use P15 and P14 to control the current flow in the bi- color LED circuit. The upper schematic shows how current flows through the red LED when P15 is ...

Page 74

The bi-color LED will also turn off if you send high signals to both P14 and P15. Why? Because the electrical pressure is the same at P14 and P15 regardless of whether you set both I/O pins high or low. ...

Page 75

VAR BYTE √ Nest the loop below within the FOR…NEXT FOR counter = HIGH 15 LOW 14 PAUSE counter LOW 15 HIGH 14 PAUSE counter NEXT When you are done, your code should look like this: ...

Page 76

SUMMARY The BASIC Stamp can be programmed to switch a circuit with a light emitting diode (LED) indicator light on and off. LED indicators are useful in a variety of places including many computer monitors, disk drives, and other devices. ...

Page 77

What do you always have to do before modifying a circuit that you built on a breadboard? 5. How long would PAUSE 10000 6. How would you cause the BASIC Stamp to do nothing for an entire minute? 7. ...

Page 78

Q8. No. The largest value a byte can hold is 255. The value 500 is out of range for a byte. Q9. will cause the BASIC Stamp to internally connect I/O pin P7 to Vdd. HIGH 7 E1. The must ...

Page 79

... Basic Analog and Digital uses LEDs to describe counting in binary, describes analog conditions, and it introduces new ways to adjust an LED’s brightness. “BASIC Stamp Editor Help File”, PBASIC 2.5 Version 2.0 Parallax Inc., 2003 The PBASIC 2.5 Help File has information on PBASIC 2.5 and not included in the BASIC Stamp Manual. You can find this information by clicking the book icon on your BASIC Stamp Editor task bar, then selecting PBASIC Reference from the menu in the left sidebar window ...

Page 80

Chapter #3: Digital Input - Pushbuttons FOUND ON CALCULATORS, HAND HELD GAMES, AND APPLIANCES How many devices with pushbuttons do you use on a daily basis? Here are a few examples that might appear in your list: computer, mouse, calculator, ...

Page 81

If the pushbutton only had two pins, those pins would eventually bend and break from all the pressure that the pushbutton receives when people press it The left ...

Page 82

Always disconnect power from your Board of Education or BASIC Stamp HomeWork Board before making any changes to your test circuit. From here onward, the instructions will no longer say “Disconnect power…” between each circuit modification ...

Page 83

Press and hold the pushbutton, and verify that the LED emits light while you are holding the pushbutton down. How the Pushbutton Circuit Works The left side of Figure 3-4 shows what happens when the pushbutton is not pressed. ...

Page 84

Vdd P15 1, 4 P14 P13 P12 P11 LED P10 Ω 470 Vss Can you really do that with the LED? Up until now, the LED’s cathode has ...

Page 85

Vdd P3 Ω 220 10 kΩ Vss Figure 3-7 shows what the BASIC Stamp sees when the button is pressed, and when it’s not pressed. When the pushbutton is pressed, the BASIC Stamp senses that Vdd is connected to P3. ...

Page 86

Vdd 220 Ω 10 kΩ Vss Vdd Ω 220 10 kΩ Vss Binary and Circuits: The base-2 number system uses only the digits 1 and 0 to make numbers, and these binary values can be transmitted from one device to ...

Page 87

Debug Terminal displays the number 0. √ Enter the ReadPushbuttonState.bs2 program into the BASIC Stamp Editor. √ Run the program. √ Verify that the Debug Terminal displays the value ...

Page 88

Your Turn – A Pushbutton with a Pull-up Resistor The circuit you just finished working with has a resistor connected to Vss. This resistor is called a pull-down resistor because it pulls the voltage at P3 down to Vss (0 ...

Page 89

ACTIVITY #3: PUSHBUTTON CONTROL OF AN LED CIRCUIT Figure 3-10 shows a zoomed in view of a pushbutton and LED used to adjust the settings on a computer monitor. This is just one of many devices that have a pushbutton ...

Page 90

Build the circuit shown in Figure 3-11. P14 470 Ω LED Vss Vdd P3 Ω 220 10 kΩ Vss Programming Pushbutton Control The BASIC Stamp can be programmed to make decisions using an statement. The example program you are ...

Page 91

DEBUG ? IN3 IF (IN3 = 1) THEN HIGH 14 PAUSE 50 LOW 14 PAUSE 50 ELSE PAUSE 100 ENDIF LOOP How PushbuttonControlledLed.bs2 Works This program is a modified version of ReadPushbuttonState.bs2 from the previous activity. The and DO…LOOP DEBUG ...

Page 92

Your Turn – Faster/Slower √ Save the example program under a different name. √ Modify the program so that the LED flashes twice as fast when you press and hold the pushbutton. √ Modify the program so that the LED ...

Page 93

P15 470 Ω P14 470 Ω LED Vss Vss P4 Ω 220 P3 Ω 220 10 kΩ 10 Vss Vss Connecting wires with dots: There are three places where wires intersect in Figure 3-12, but only two dots. Wires only ...

Page 94

Vdd X3 P15 P14 P13 P12 P11 P10 Programming Pushbutton Control In the previous activity, you experimented with making decisions using an statement. There is also such a thing ...

Page 95

DEBUG HOME DEBUG ? IN4 DEBUG ? IN3 IF (IN3 = 1) THEN HIGH 14 PAUSE 50 ELSEIF (IN4 = 1) THEN HIGH 15 PAUSE 50 ELSE PAUSE 50 ENDIF LOW 14 LOW 15 PAUSE 50 LOOP How PushbuttonControlOfTwoLeds.bs2 Works ...

Page 96

PAUSE 50 This is where the keyword helps. If ELSEIF the LED connected to P15 on instead of the one connected to P14. ELSEIF (IN4 = 1) THEN HIGH 15 PAUSE 50 If neither statement is true, we still want ...

Page 97

HIGH 14 PAUSE 50 with this statement: IF...ELSEIF IF (IN3 = 1) AND (IN4 = 1) THEN HIGH 14 HIGH 15 PAUSE 50 ELSEIF (IN3 = 1) THEN HIGH 14 PAUSE 50 A code block is a group of commands. ...

Page 98

Your next task is to develop a proof of concept for the reaction timer test. The solution you will build and test in this activity is an example of how to solve this problem, but ...

Page 99

P15 1 2 P14 470 Ω Vdd P3 220 Ω 10 kΩ Vss Programming the Reaction Timer This next example program will leave the bi-color LED off until the game player presses and holds the pushbutton. When the pushbutton is ...

Page 100

What's a Microcontroller - ReactionTimer.bs2 ' Test reaction time with a pushbutton and a bi-color LED. ' {$STAMP BS2} ' {$PBASIC 2.5} timeCounter VAR Word DEBUG "Press and hold pushbutton.", CR, "to make light turn red.", CR, CR, "When ...

Page 101

DO PAUSE 1 timeCounter = timeCounter + 1 LOOP UNTIL IN3 = 0 LOW 14 DEBUG "Your time was ", DEC timeCounter, " ms.", CR, CR, "To play again, hold the ", CR, "button down again.", CR, CR LOOP How ...

Page 102

The inner deserves a closer look. A DO…LOOP whether or not to break out of the loop and move on to more commands that come afterwards. This will repeat itself as long as the button is not pressed ( DO…LOOP ...

Page 103

CR, CR The last statement in the program is statement. DO Your Turn – Revising the Design The marketing department gave your prototype to some game testers. When the game testers were done, the marketing department came ...

Page 104

For precision, you can use the */ operator to multiply by a value with a fraction to make your answer more precise. The */ operator is not hard to use; here’s how: 1) Place the value or variable you want ...

Page 105

Modify the command so that the random value is added to 1000 (for PAUSE one second) in the PAUSE PAUSE 1000 + value What’s an algorithm? An algorithm is a sequence of mathematical operations. What’s pseudo random? Pseudo random ...

Page 106

SUMMARY This chapter introduced the pushbutton and common pushbutton circuits. This chapter also introduced how to build and test a pushbutton circuit and how to use the BASIC Stamp to read the state of one or more pushbuttons. The BASIC ...

Page 107

Project 1. Modify ReactionTimer.bs2 so that two player game. Add a second button wired to P4 for the second player. Solutions Q1. Sending uses the BASIC Stamp I/O pin as an output, whereas receiving uses the I/O ...

Page 108

P15 P14 470 Ω Snippets from the solution program are included below, but keep in mind solutions may be coded a variety of different ways. However, most solutions will include the following modifications: Use two variables to ...

Page 109

DEBUG "Player A is the winner!", CR ELSEIF (timeCounterB < timeCounterA) THEN DEBUG "Player B is the winner!", CR ELSE DEBUG "It's a tie!", CR ENDIF The complete solution is shown below. ' What's a Microcontroller - Ch03Prj03_TwoPlayerReactionTimer.bs2 ' Test ...

Page 110

ENDIF IF (IN4 = 1) THEN timeCounterB = timeCounterB + 1 ENDIF LOOP UNTIL (IN3 = 0) AND (IN4 = 0) LOW 14 DEBUG "Player A Time: ", DEC timeCounterA, " ms. ", CR DEBUG ...

Page 111

... Basic Analog and Digital explains binary counting using pushbuttons. It also uses pushbuttons to introduce a technique for transmitting numbers from one system to another called synchronous serial communication. “BASIC Stamp Editor Help File”, PBASIC 2.5 Version 2.0 Parallax Inc., 2003 The PBASIC 2.5 Help File has information on the used with , and information on nesting and DO… ...

Page 112

Chapter #4: Controlling Motion MICROCONTROLLED MOTION Microcontrollers make sure things move to the right place all around you every day. If you have an inkjet printer, the print head that goes back and forth across the page as it prints ...

Page 113

DC motor, and gears. These parts work together to take high/low signals from the BASIC Stamp and convert them into positions held by the servo horn CAUTION: use only a Parallax Standard ...

Page 114

Resistor – 470 Ω (yellow-violet-brown) (1) LED – any color Building the Servo and LED Circuits It’s really important to be careful when connecting a servo to your BASIC Stamp. How you connect your servo depends on whether you ...

Page 115

P14 470 Ω Vdd White P14 Red Black Vss √ Turn off the power as shown in Figure 4-4. Figure 4-5 shows the servo header on the Board of Education Rev C. This is where you will plug in your ...

Page 116

X4 The jumper allows you to choose the power supply (Vin or Vdd) for the Parallax Standard Servo. If you are using battery best to set it to Vdd. Either setting will work ...

Page 117

Up until now, you have been using the 3-position switch in the 1 position. Now, you will move it to the 2 position to turn on the power to the servo header. √ Supply power to the servo header by ...

Page 118

P14 Ω 470 LED Vss Vin White P14 Red Black Vss √ Disconnect your 9 V battery from your HomeWork Board. √ Build the LED indicator and servo header circuit shown in Figure 4-10. Figure 4-9 Schematic for Servo and ...

Page 119

Vdd Vin Vss X3 + P15 P14 P13 P12 P11 P10 √ Connect the servo to the servo header as shown in Figure 4-11. √ Make sure that the ...

Page 120

Vdd Vin Vss X3 + P15 P14 P13 P12 P11 P10 √ Move on to Programming Servo Control on page 113. Board of Education Rev B Figure 4-12 shows ...

Page 121

P14 470 Ω Vss Vin White P14 Red Black Vss √ Disconnect your battery or any other power supply from your board. √ Build the LED circuit shown in Figure 4-12. √ Connect the servo to the servo header as ...

Page 122

White Red Red Black Black X4 X5 Vdd Vin Vss X3 + P15 P14 P13 P12 P11 P10 √ Make sure that the colors on ...

Page 123

A millionth of a second is called a microsecond. The Greek letter µ is used in place of the word micro and the letter s is used in place of second. This is handy for writing and taking notes, because ...

Page 124

Observe the servo turns at each of the three steps in the program, and record where the horn is really pointing. √ Re-run the program and verify that the LED flickers dimly. It should be brightest when the BASIC ...

Page 125

PULSOUT 14, 1000 PAUSE 20 NEXT sends a pulse that lasts 1000 × 2 µs. That’s 2000 µ ms. PULSOUT 14, 1000 Figure 4-15 is called a timing diagram. It shows a picture of the high and low ...

Page 126

Vdd (5 V) Vss ( The last loop delivers 150 pulses, each of which lasts 1.5 ms. This instructs FOR…NEXT the servo its center position (12 o’clock) for about 3.23 seconds. FOR ...

Page 127

For example, if you didn’t already know that the here is how you could calculate it. = × Duration 500 = 750 You can also figure out the Duration equation. Duration = number of ms 500 For ...

Page 128

PULSOUT 14,850 √ Modify the command in the second loop so that it reads: PULSOUT PULSOUT 14,650 √ Run the modified program, and explain the differences in the positions the servo turns to and holds. ACTIVITY #2: CONTROLLING POSITION WITH ...

Page 129

You will also program the BASIC Stamp to use these values to control the servo. Parts and Circuit Same as Activity #1 Programming the BASIC Stamp to Receive Messages from Debug Programming the BASIC Stamp to send messages to the ...

Page 130

Echo is when you send a message, and a copy of that message appears in your Receive Windowpane. You can click the Echo Off checkbox (shown below) to make a checkmark appear in it. This will make the Debug Terminal ...

Page 131

Experiment with entering other values between 500 and 1000 for the and values between 1 and 65534 for the number of pulses. Duration It takes between 40 and 45 pulses to make the servo hold a position for 1 ...

Page 132

The variable is declared for use by a counter #3 for details. The and pulses duration They are both used to receive and store values sent from the Debug Terminal. The variable is also used to set the number of ...

Page 133

As in previous examples, the counter loop. Up until this example, all the 150 for . In this EndValue FOR…NEXT control the of the EndValue FOR…NEXT delivered to the servo. The end result is that the servo holds a given ...

Page 134

DO DEBUG "Enter pulsout duration:", CR DEBUGIN DEC duration IF duration < 500 THEN DEBUG "Value of duration must be above 499", CR PAUSE 1000 ENDIF IF duration > 1000 THEN DEBUG "Value of duration must ...

Page 135

FOR counter = 500 TO 1000 STEP 8 You can also make the servo turn the opposite direction by counting down instead of counting up. In PBASIC, ...

Page 136

DEBUG CR, "Pulse width decrement by 20", CR FOR counter = 1000 TO 500 STEP 20 PULSOUT 14, counter PAUSE 7 DEBUG DEC5 counter, CR, CRSRUP NEXT DEBUG CR, "Repeat", CR LOOP How ServoVelocities.bs2 Works The first loop counts upwards ...

Page 137

PAUSE 7 DEBUG DEC5 counter, CR, CRSRUP NEXT Your Turn – Adjusting the Velocities √ Try different values to make the servo turn at different rates. STEP √ Re-run the program after each modification. √ Observe the effect of each ...

Page 138

Adding the Pushbutton Control Circuit Figure 4-20 shows the pushbutton circuits that you will use to control the servo. P4 Ω 220 P3 Ω 220 Vss √ Add this circuit to the servo+LED circuit that you have been using up ...

Page 139

Vdd White Red Red Black Black X4 X5 Vdd Vin Vss X3 + P15 P14 P13 P12 P11 P10 Vdd Vin Vss X3 + P15 ...

Page 140

White Red Red Black Black X4 X5 Vdd Vin Vss X3 + P15 P14 P13 P12 P11 P10 √ Test the pushbutton connected to P3 ...

Page 141

Example Program: ServoControlWithPushbuttons.bs2 This example program makes the servo’s horn rotate counterclockwise when the pushbutton connected pressed. The servo’s horn will keep rotating so long as the pushbutton is held down and the value of pushbutton connected ...

Page 142

IF IN4 = 1 THEN IF duration < 1000 THEN duration = duration + 25 ENDIF ENDIF PULSOUT 14, duration PAUSE 10 DEBUG HOME, DEC4 duration, " = duration" LOOP Your Turn – Software Stoppers Servos have a built in ...

Page 143

SUMMARY This chapter introduced microcontrolled motion using a servo. A servo is a device that moves to and holds a particular position based on electronic signals it receives. These signals take the form of pulses that last anywhere between 1 ...

Page 144

Exercises 1. Write a code block that sweeps the value of of 700 to 800, then back to 700, in increments of (a) 1, (b) 4. Duration 2. Add a nested loop to your answer to exercise 1b so that ...

Page 145

E2. FOR counter = 700 TO 800 STEP 4 FOR pulses = PULSOUT 14, counter PAUSE 20 NEXT NEXT FOR counter = 800 TO 700 STEP 4 FOR pulses = PULSOUT 14, counter PAUSE ...

Page 146

... Further Investigation The servo, and using sensors to control servos, can be investigated in detail in a variety of Stamps in Class texts. “Advanced Robotics: with the Toddler”, Student Guide, Version 1.2, Parallax Inc., 2003 Advanced Robotics: with the Toddler uses servos to control the motions of the Parallax Toddler robot’ ...

Page 147

Chapter #5: Measuring Rotation ADJUSTING DIALS AND MONITORING MACHINES Many households have dials to control the lighting in a room. Twist the dial one direction, and the light gets brighter; twist the dial in the other direction, and the light ...

Page 148

Figure 5-3 shows the schematic symbol and part drawing of the potentiometer you will use in this chapter. Terminals A and B are connected kΩ resistive element. Terminal W is called the wiper terminal, and it is ...

Page 149

ACTIVITY #1: BUILDING AND TESTING THE POTENTIOMETER CIRCUIT Placing different size resistors in series with an LED causes different amounts of current to flow through the circuit. Large resistance in the LED circuit causes small amounts of current to flow ...

Page 150

Vdd 220 Ω Pot 10 kΩ LED nc Vss Testing the Potentiometer Circuit √ Turn the potentiometer clockwise until it reaches its mechanical limit shown in Figure 5-6. Handle with care: If your potentiometer will not turn this far, do ...

Page 151

A and W terminals changes. This in turn changes the current flow through the LED circuit. ACTIVITY #2: MEASURING RESISTANCE BY MEASURING TIME This activity introduces a new part called a ...

Page 152

Resistance and Time Parts (1) Capacitor – 3300 µF (1) Capacitor – 1000 µF (1) Resistors – 220 Ω (red-red-brown) (1) Resistor – 470 Ω (yellow-violet-brown) (1) Resistor – 1 kΩ (brown-black-red) (1) Resistor – 2 kΩ (red-black-red) (1) Resistor ...

Page 153

P7 Ω 220 3300 µF Vss Vdd Vin Vss X3 P15 P14 P13 P12 P11 P10 Polling the RC-Time Circuit with ...

Page 154

Record the measured time (the capacitor’s discharge time) in the 470 Ω row of Table 5-1. √ Disconnect power from your Board of Education or BASIC Stamp HomeWork Board. √ Remove the 470 Ω resistor labeled R 145, and ...

Page 155

DEBUG ? IN7 DEBUG DEC5 timeCounter, CR, CRSRUP, CRSRUP LOOP UNTIL IN7 = 0 DEBUG CR, CR, CR, "The RC decay time was ", DEC timeCounter, CR, "tenths of a second.", CR, CR END How PolledRcTimer.bs2 Works Two variables are ...

Page 156

As the capacitor discharges, the voltage across its terminals gets lower and lower (decays). INPUT 7 Back in the pushbutton chapter, you used the BASIC Stamp to detect a high or low ...

Page 157

Repeat the steps in the Example Program: PolledRcTimer.bs2 section, and record your time measurements in Table 5-2. √ Compare your time measurements to the ones you took earlier in Table 5-1. How close are they to 1/3 the value ...

Page 158

Building an RC Time Circuit for the BASIC Stamp Figure 5-11 shows a schematic for the fast RC-time circuit, and Figure 5-12 shows the wiring diagram. This is the circuit that you will use to monitor ...

Page 159

X3 P15 P14 P13 P12 P11 P10 Programming RC-Time Measurements The BASIC Stamp program to measure the potentiometer’s resistance will do essentially the same thing that you did by ...

Page 160

How ReadPotWithRcTime.bs2 Works Here are the pseudo-code steps the program goes through to take the RC-time measurement. Declare the variable • time Code block within • DO…LOOP Set I/O pin Wait for 100 ms ( ...

Page 161

An example of a model airplane and its radio controller are shown in Figure 5-13. The model airplane has servos to control all its flaps and the gas engine’s throttle settings. These servos are controlled using the radio control (RC) ...

Page 162

Jumper wires CAUTION: use only a Parallax Standard Servo for the activities in this text! Do not substitute a Parallax Continuous Rotation Servo may be quickly damaged by the circuits shown below. Likewise not recommend ...

Page 163

So how can these input values be adjusted so that they map to the values of 500 and 1000 that are needed to control the servo with the multiplication and addition. First, multiply the input values by something to make ...

Page 164

That takes care of the scaling, now all we need add the offset of 500. This can be done with a second command that adds 500 to time = time */ 185 ...

Page 165

Substitute your and scale √ Add this line of code between the can view your results. DEBUG HOME, DEC5 time √ Run the modified program and check your work. Because the values were rounded off, the limits may not ...

Page 166

Likewise, if you have to recalibrate your scale factor or offset, you can also just change the directives at the beginning of the program. CON Assigning an alias is what you do when you give a variable, constant or I/O ...

Page 167

Save the example program under a new name. √ Change the and scaleFactor circuit that you determined in the previous Your Turn section. √ Run the modified program and verify that it works correctly. √ Modify your circuit by ...

Page 168

SUMMARY This chapter introduced the potentiometer, a part often found under various knobs and dials. The potentiometer has a resistive element that typically connects its outer two terminals and a wiper terminal that contacts a variable point on the resistive ...

Page 169

The used at the beginning of a program to substitute a name for a number. As with naming variables, naming constants is also called creating an alias. After an alias is ...

Page 170

Q2. No, it’s fixed. The variable resistance is between either outer terminal and the wiper (middle) terminal. Q3. A capacitor is like a rechargeable battery in that it can be charged up to hold voltage. The difference is that it ...

Page 171

HIGH 7 PAUSE 10 RCTIME 7, 1, time time = time + 330 IF ( time > prevTime + 2) THEN HIGH 13 LOW 12 ELSEIF ( time < prevTime - 2) THEN LOW 13 HIGH 12 ...

Page 172

... Robotics: with the Toddler”, Student Workbook, Version 1.2, Parallax Inc., 2003 “Robotics with the Boe-Bot”, Student Workbook, Version 2.0, Parallax Inc., 2003 “SumoBot”, Student Workbook, Version 1.1, Parallax Inc., 2002 Every Stamps in Class robotics text uses detect a variety of conditions ...

Page 173

Chapter #6: Digital Display THE EVERY-DAY DIGITAL DISPLAY Figure 6-1 shows a display on the front of an oven door. When the oven is not in use, it displays the time. When the oven is in use, it displays the ...

Page 174

Common Cathode Common Cathode Pin Map: Figure 6 example of a pin map. A pin map contains useful information that helps you connect a part to other circuits. ...

Page 175

ACTIVITY #1: BUILDING AND TESTING THE 7-SEGMENT LED DISPLAY In this activity, you will manually build circuits to test each segment in the display. 7-Segment LED Display Test Parts (1) 7-segment LED display ...

Page 176

Vdd Vss √ Disconnect power, and modify the circuit by connecting the resistor to the B LED input as shown in Figure 6-6 and Figure ...

Page 177

Vdd 1 kΩ Vss √ Reconnect power and verify that the B segment emits light. √ Using the pin map from Figure 6 guide, repeat these steps for ...

Page 178

Vdd Vdd Vdd Vdd Vss √ Build and test the circuit shown in Figure 6-8 and Figure 6-9, and verify that it displays the number three. √ Draw ...

Page 179

ACTIVITY #2: CONTROLLING THE 7-SEGMENT LED DISPLAY In this activity, you will connect the 7-segment LED display to the BASIC Stamp, and then run a simple program to test and make sure each LED is properly connected. 7-Segment LED Display ...

Page 180

P15 P14 P13 P12 P11 P10 LED’s Be careful with the resistors connected to P13 and P14. Look carefully at the resistors connected to P13 and P14 in Figure 6-11. There is gap ...

Page 181

E Parallel Device: The 7-segment LED display is called a parallel device because you have to use more than one I/O line at a time to send data (high and low information) to the device. In the case of this ...

Page 182

BS2} '{$PBASIC 2.5} pinCounter VAR Nib DEBUG "I/O Pin", CR, "-------", CR FOR pinCounter = DEBUG DEC2 pinCounter, CR HIGH pinCounter PAUSE 1000 LOW pinCounter NEXT Your Turn – A Different Pattern Removing the command LOW ...

Page 183

A binary number that has 8 digits is said to have 8 bits. Each bit is a slot where you can store either byte is a variable that contains 8 bits. There ...

Page 184

PAUSE 1000 OUTH = %11010011 PAUSE 1000 OUTH = %11010110 PAUSE 1000 OUTH = %10110100 PAUSE 1000 OUTH = %01110110 PAUSE 1000 OUTH = %01110111 PAUSE 1000 OUTH = %11000100 PAUSE 1000 OUTH = %11110111 PAUSE 1000 OUTH = %11110110 ...

Page 185

The first command: OUTH = %00000000 gets all the I/O pins (P8 through P15) ready to send the low signals. If they all send low signals, it will turn all the LEDs in the 7-segment LED display off. If you ...

Page 186

BAFG.CDE OUTH = %11010110 The display is turned so that the three on the display is upside-down because it more clearly shows how the values in OUTH uses binary zeros to set I/O pins P8, P11, and P13 low, ...

Page 187

Decimal vs. Hexadecimal The basic digits in the decimal (base-10) number system are and 9. In the hexadecimal (base-16) number system the basic digits are ...

Page 188

DEBUG ? value, CR DEBUG "Change the index variable to a ", CR, "different number(between 0 and 4).", CR, CR, "Run the modified program and ", CR, "check to see what number the", CR, "LOOKUP command places in the", CR, ...

Page 189

OUTH DEBUG " ", DEC2 index, " PAUSE 1000 NEXT DIRH = %00000000 END Your Turn – Displaying 0 through F Again √ Modify DisplayDigitsWithLookup.bs2 so that it counts from 0 through F in hexadecimal. ...

Page 190

P5 220 Ω Pot 10 kΩ Programming the Dial and Display There is a useful command called the command. While the command gives you a number based on an index, the LOOKUP command gives you an index based on a ...

Page 191

Re-run the program after each change to the value from the list gets placed in the Unless you tell it to make a different kind of comparison, the to see if a value is equal to an entry in ...

Page 192

CR, "index variable." END Example Program: DialDisplay.bs2 This example program mirrors the position of the potentiometer’s knob by lighting segments around the outside of the 7-segment LED display as shown in Figure 6-16. √ ...

Page 193

LOOKUP index, [ %11100101, %11100001, %01100001, %00100001, %00000001, %00000000 ], OUTH LOOP How DialDisplay.bs2 Works This example program takes an RCTIME a variable named . time HIGH 5 PAUSE 100 RCTIME 5, 1, time The variable is then used in ...

Page 194

SUMMARY This chapter introduced the 7-segment LED display, and how to read a pin map. This chapter also introduced some techniques for devices and circuits that have parallel inputs. The and variables were introduced as a means of controlling the ...

Page 195

E1. The first step for configuring . So bits 8, 10, and 12 get set to "1". Then put a "0" for each HIGH and 13 get a "0", as shown. To configure and 13 must be set as outputs ...

Page 196

... As with all texts cited in this section, this one is available for free download from www.parallax.com. “StampWorks”, Workbook, Version 1.2, Parallax Inc., 2001 StampWorks is written by Nuts & Volts author Jon Williams, and features a wide variety of experiments. This text is a collection of 32 experiments including several that use 7-segment LED displays and other types of displays ...

Page 197

Chapter #7: Measuring Light DEVICES THAT CONTAIN LIGHT SENSORS You have already worked with two different kinds of sensors. The pushbutton can be thought simple pressure sensor, and the potentiometer is a position/rotation sensor. There are many ...

Page 198

As with a potentiometer, you can use a photoresistor in an RC-time circuit. The program to read the photoresistor is also about the same as the one used to read the potentiometer. Even though the programming is the same, light ...

Page 199

Second, the variable resistor is now a photoresistor instead of a potentiometer. √ Build the circuit shown in Figure 7-2 and Figure 7-3. P2 220 Ω Vss Vdd X3 P15 P14 P13 P12 P11 P10 ...

Page 200

Example Program: TestPhotoresistor.bs2 Instead of twisting the potentiometer’s knob, the circuit is tested by exposing the light collecting surface of the photoresistor to different light levels. When the example program is running, the Debug Terminal should display small values for ...

Related keywords