Presentation based on Whats a Microcontroller by Andy
Presentation based on: “What’s a Microcontroller? " by Andy Lindsay Presented by Andy Lindsay Applications Engineer, Parallax Inc. Education Dept. www. parallax. com 599 Menlo Drive Suite 100 Rocklin, CA 95765 Slide 1
Copyrights and Trademarks This documentation is copyright 2007 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: Parallax 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 document, 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. BASIC Stamp, Stamps in Class, and Board of Education are registered trademarks of Parallax, Inc. If you decide to use the names BASIC Stamp, Stamps in Class, and/or Board of Education on your web page or in printed material, you must state that "BASIC Stamp is a registered trademark of Parallax, Inc. , " "Stamps in Class is a registered trademark of Parallax, Inc. , " and/or "Board of Education is a registered trademark of Parallax, Inc. , " respectively, upon the first appearance of the trademark name. Other brand product names are trademarks or registered trademarks of their respective holders. Slide 2
Introduction How many microcontrollers did you use today? What’s a BASIC Stamp? For the Classroom BASIC Stamp and Board of Education BASIC Stamp Home. Work Board Excerpts from pages 1, 2, and 13, 14 Slide 3
Chapter #1: Getting Started Parallax CD: • BASIC Stamp Editor • Software BASIC Stamps Windows… • What’s a Microcontroller • Documentation Educational Curriculum • BASIC Stamp Manual • Documentation BASIC Stamp Parallax Website: www. parallax. com • BASIC Stamp Editor • Downloads BASIC Stamp Software • What’s a Microcontroller • Downloads Stamps in Class Tutorials • BASIC Stamp Manual • Documentation BASIC Stamp Documentation Excerpts from pages 9 and 6…(Activity #1 – Getting the Software) Slide 4
Introduction Amazing inventions with the BASIC Stamp Excerpts from pages 3 - 4 Slide 5
Chapter #1: Getting Started Connect serial cable and battery to Home. Work Board Affix rubber feet to the underside of your board. Write a PBASIC program then download it to the BASIC Stamp Connect serial cable to computer COM port. Excerpts from pages 14 -16, 18, 20…(Activity #3: Setting up the Hardware & Testing the System) Slide 6
Chapter #1: Getting Started Run the BASIC Stamp Editor Software ' What's a Microcontroller - First. Program. bs 2 ' BASIC Stamp sends message to Debug Terminal. ' {$STAMP BS 2} ' {$PBASIC 2. 5} DEBUG "Hello, it's me, your BASIC Stamp!" END Enter this program Click the BASIC Stamp 2 Button Click the PBASIC 2. 5 button Click the ‘Run’ button Excerpts from pages 18 -22…(Activity #4: First Program) Slide 7
Chapter #1: Getting Started Click the ‘Run’ button The command: DEBUG "Hello, it's me…" Causes the BASIC Stamp to send a message to the Computer The Debug Terminal appears with a message sent by the BASIC Stamp Excerpts from pages 20, 23 Slide 8
Chapter #1: Getting Started comment Stamp 2 directive PBASIC 2. 5 directive DEBUG command END command ' What's a Microcontroller - First. Program. bs 2 ' BASIC Stamp sends message to Debug Terminal. ' {$STAMP BS 2} ' {$PBASIC 2. 5} DEBUG "Hello, it's me, your BASIC Stamp!" END Excerpts from pages 20 -21, 27 -28…(Activity #5: Lookup up Answers) Slide 9
Chapter #2 -5, 8: Digital and Analog Inputs and Outputs White Red Black Excerpt from pages 77 - 78 Slide 10
Chapter #2 -5, 8: Digital and Analog Inputs and Outputs Excerpt from pages 84, 106, 150, 182, 220 Slide 11
Chapter #2: Lights on – Lights off LED Test Circuit Parts (1) LED – Green (1) Manual Circuit – LED On Resistor – 470 (yellow-violet-brown) Manual Circuit – LED Off See What’s a Microcontroller Page 39 for resistor color code information Excerpts from pages 39, 40, 43, 46…(Activity #1: Building and Testing the LED Circuit) Slide 12
Chapter #2: Lights on – Lights off BASIC Stamp – LED Circuit Led. On. Off. bs 2 ' {$STAMP BS 2} ' {$PBASIC 2. 5} DO Next Step Write a PBASIC Program to make the BASIC Stamp Switch the LED circuit input between Vdd (5 V) and Vss (0 V). HIGH 14 PAUSE 250 LOW 14 PAUSE 250 LOOP Excerpts from pages 47 -50…(Activity #2: On/Off Control with the BASIC Stamp) Slide 13
Chapter #2: Lights on – Lights off Changing the program to make the LED flash on/off 10 times Before making any changes, save the original program, then save a copy (to be modified) under a new name: √ Use the same circuit √ Replace DO and LOOP with the segments of code shown here. √ Run your modified program. √ Remember to save your modified program. Led. On. Off. Ten. Times. bs 2 ' {$STAMP BS 2} ' {$PBASIC 2. 5} counter VAR Byte FOR counter = 1 TO 10 DEBUG ? counter HIGH 14 PAUSE 500 LOW 14 PAUSE 500 NEXT DEBUG "All done!" END Excerpts from page 54…(Activity #3: Counting and Repeating) Slide 14
Chapter #2: Lights on – Lights off LED Test Circuit Parts Next Step - Make both LEDs flash on/off (1) LED – Green (1) LED - Yellow (2) Resistor – 470 (yellow-violet-brown) √ Open Flash. Led. bs 2 √ Add two lines of code √ Run your modified program. √ Remember to save your modified program under a different name! Use Flash. Both. Leds. bs 2 BASIC Stamp – LED Circuit (Modified) Flash. Both. Leds. bs 2 ' {$STAMP BS 2} ' {$PBASIC 2. 5} Important: Leave this circuit on your board! This circuit is re-used in the next set of activities. Do not take it apart before building the next circuit. DO HIGH 14 HIGH 15 PAUSE 250 LOW 14 LOW 15 PAUSE 250 LOOP Excerpts from pages 58 -59…(Activity #4: Building and Testing a Second Circuit) Slide 15
Chapter #3: Digital Input - Pushbuttons LED Test Circuit Parts How the Pushbutton Works (1) Resistor – 220 Ω (red-brown) (1) Resistor – 10 kΩ (brown-black-orange) (1) Pushbutton - normally open Pushbutton Circuit (2) Jumper wires Excerpts from pages 72, 76…(Activity #2: Reading a Pushbutton with the BASIC Stamp) Slide 16
Chapter #3: Digital Input - Pushbuttons Read. Pushbutton. State. bs 2 ' {$STAMP BS 2} ' {$PBASIC 2. 5} DO √ Follow instructions with checkmarks on page 78 How the Circuit and Program Work DEBUG ? IN 3 PAUSE 250 LOOP Excerpt from page 77 - 78 Slide 17
Chapter #3: Digital Input - Pushbuttons Pushbutton/LED Circuit Parts (1) Pushbutton – normally open (1) Resistor - 10 k Ω (brown-black-orange) (1) LED – any color (1) Resistor – 220 Ω (red-brown) (1) Resistor – 470 Ω (yellow-violet-brown) (2) Jumper wires Pushbutton/LED Circuit Pushbutton. Controlled. Led. bs 2 ' {$STAMP BS 2} ' {$PBASIC 2. 5} DO DEBUG ? IN 3 IF (IN 3 = 1) THEN HIGH 14 PAUSE 50 LOW 14 PAUSE 50 ELSE PAUSE 100 ENDIF LOOP Excerpts from pages 80 -83…(Activity #3: Pushbutton Control of an LED Circuit) Slide 18
Chapter #3: Digital Input - Pushbuttons Pushbutton. Control. Of. Two. Leds. bs 2 Pushbutton/LED Circuit Parts (2) (2) (2) Pushbuttons – normally open Resistors - 10 kΩ (brown-black-orange) Resistors – 470 Ω (yellow-violet-brown) Resistors – 220 Ω (red-brown) LEDs – any color ' {$STAMP BS 2} ' {$PBASIC 2. 5} DO DEBUG HOME DEBUG ? IN 4 DEBUG ? IN 3 IF (IN 3 = 1) THEN HIGH 14 PAUSE 50 ELSEIF (IN 4 = 1) THEN HIGH 15 PAUSE 50 ELSE PAUSE 50 ENDIF LOW 14 LOW 15 Excerpts from pages 83 -87 Activity #4: Two Pushbuttons Controlling Two LEDs PAUSE 50 LOOP Slide 19
Stamps In Class Books and Kits Cited in Further Investigation Sections Slide 20
Stamps in Class Flowchart www. parallax. com Education Stamps in Class Flowchart Slide 21
Chapter #4: Controlling Motion Servo Circuit Parts Servo Circuit (1) Standard Servo (1) LED (red) (1) Resistor (470 Ω yellow-violet-brown) Excerpts from page 105 -108…(Activity #1: Connecting and Testing the Servo) Slide 22
Chapter #4: Controlling Motion 10 o’clock 2 o’clock 12 o’clock PULSOUT pin, duration Use 0 to 15 to select BASIC Stamp I/O pin P 0 through P 15 1. 0 ms 2. 0 ms Example: duration × 2 s = pulse duration 1. 5 ms PULSOUT 14, 1000 Excerpts from pages 113 -114 Slide 23
Chapter #4: Controlling Motion Excerpts from Example Program: Servo. Test. bs 2 FOR counter = 1 TO 150 PULSOUT 14, 1000 PAUSE 20 NEXT ≈ 3 seconds FOR COUNTER = 1 TO 150 PULSOUT 14, 500 PAUSE 20 NEXT ≈ 3 seconds FOR counter = 1 TO 150 PULSOUT 14, 750 PAUSE 20 NEXT ≈ 3 seconds Excerpts from pages 115 -118 Slide 24
Chapter #4: Controlling Motion √ Follow instructions from Activity #2, pg. 119 -124 Excerpt from Example Program: Servo. Control. With. Debug. bs 2 DEBUG CLS, "Enter number of pulses: ", CR DEBUGIN DEC pulses DEBUG "Enter PULSOUT duration: ", CR DEBUGIN DEC duration Transmit windowpane Receive windowpane Excerpts from pages 119 – 124 (Activity #2: Controlling Position with Your Computer) Slide 25
Chapter #4: Controlling Motion √ Follow instructions from Activity #3 pg. 125 – 128 Excerpts from Example Program: Servo. Velocities. bs 2 counter VAR Word Counter increments with FOR…NEXT loop. STEP value controls the rate at which counter increases FOR counter = 500 TO 1000 STEP 4 PULSOUT 14, counter PAUSE 20 DEBUG DEC 5 counter, CRSRUP NEXT FOR counter = 1000 TO 500 STEP 10 PULSOUT 14, counter PAUSE 20 DEBUG DEC 5 counter, CRSRUP NEXT As counter changes, so does the pulse width. As the pulse width changes, the servo’s position updates. Position changing over time gives an apparent velocity. Count down instead of up at a faster step rate. Excerpts from pages 125 -128 Activity #3: Converting Position to Motion Slide 26
Chapter #4: Controlling Motion Extra Pushbutton Parts (2) Pushbuttons normally open (2) Resistors – 10 k (brown-black-orange) (2) Resistors – 220 (red-brown) (3) Jumper wires The pushbutton circuit should still be on your board. √ If not, build it now. Excerpts from pages 129 – 130 Activity #4: Pushbutton Controlled Servo Slide 27
Chapter #4: Controlling Motion Excerpt from: Servo. Control. With. Pushbuttons. bs 2 DO IF IN 3 = 1 THEN IF duration > 500 THEN duration = duration - 25 ENDIF IF IN 4 = 1 THEN IF duration < 1000 THEN duration = duration + 25 ENDIF √ Follow instructions with checkmarks on page 132. PULSOUT 14, duration PAUSE 10 DEBUG HOME, DEC 4 duration, " = duration" LOOP Excerpts from pages 131 -133 Slide 28
Chapter #5: Measuring Rotation Important – more info: √ Replace your pushbutton circuits with this dial circuit. √ Remember to leave the P 14 LED and servo circuits connected. √ NOTE: The pot must be firmly seated in its breadboard sockets. √ Run Read. Pot. With. Rc. Time. bs 2 Activity #3 p. 149 √ Run Control. Servo. With. Pot. bs 2 Activity #4 p. 152 √ Have fun controlling the servo with the pot. Dial Circuit Parts (1) Resistor – 220 Ω (red-brown) (1) Capacitor – 0. 1 F Dial Circuit (2) Jumper wires (1) Potentiometer – 10 kΩ Excerpts from pages 149 -152, 190…(Activity #3: Reading the Dial with a BASIC Stamp Slide 29
Chapter #5: Measuring Rotation √ Run Read. Pot. With. Rc. Time. bs 2 √ Twist the potentiometer’s input shaft, and make notes of the time values displayed by the Debug Terminal. Excerpt from: Read. Pot. With. Rc. Time. bs 2 √ Your course guide will explain how to adjust the example program so that it works best with the pulsout command gives your servo a range of motion that uses the potentiometer’s entire range of motion. Read. Pot. With. Rc. Time. bs 2 HIGH 7 PAUSE 100 RCTIME 7, 1, time Excerpt from page 151 -152 Slide 30
Chapter #5: Measuring Rotation Control. Servo. With. Pot. bs 2 Excerpt from page 151 & 156 Activity #4: Controlling a Servo with a Potentiometer Slide 31
Educational Support ü Parallax has a strong support system through the use of forums. ü Educational support is present with two forums: • Stamps in Class (Public) • Parallax Educators (Private) Slide 32
Forum Registration 1 - Go to Parallax forums: http: //forums. parallax. com 2 - Register as new forum member. 3 - Open the confirmation email and follow the link to confirm that you have joined. 4 - Send your username to stampsinclass@parallax. com, and request access to the Parallax Educators Forum. We recommend that you send the request using your EDU email address, and include a link to your faculty page or entry in the school’s online staff directory. Slide 33
Chapter #8: Frequency and Sound Test. Piezo. With. Freqout. bs 2 √ Build the piezospeaker circuit. √ Run Test. Piezo. With. Freqout. bs 2 '{$STAMP BS 2} '{$PBASIC 2. 5} Piezospeaker Circuit Parts (2) Jumper wires (1) Piezoelectric speaker DEBUG "Tone sending. . . ", CR FREQOUT 9, 1500, 2000 DEBUG "Tone done. " I/O pin = P 9 duration = 1500 ms = 1. 5 s Piezospeaker Circuit f = 2000 Hz T = 1÷ 2000 s T Excerpt from page 219 -221 Slide 34
Chapter #8: Frequency and Sound Excerpts from: Action. Tones. bs 2 duration frequency VAR Word DEBUG "Alarm. . . ", CR PAUSE 100 FREQOUT 9, 500, 1500 PAUSE 500 FREQOUT 9, 500, 1500 PAUSE 500 √ Run Action. Tones. bs 2 DEBUG "Robot reply. . . ", CR PAUSE 100 FREQOUT 9, 100, 2800 FREQOUT 9, 200, 2400 FREQOUT 9, 140, 4200 FREQOUT 9, 30, 2000 PAUSE 500 DEBUG "Hyperspace. . . ", CR PAUSE 100 FOR duration = 15 TO 1 STEP 1 FOR frequency = 2000 TO 2500 STEP 20 FREQOUT 9, duration, frequency NEXT Excerpts from pages 222 -223 Slide 35
Chapter #8: Frequency and Sound Mixing. Tones. bs 2 '{$STAMP BS 2} '{$PBASIC 2. 5} DEBUG "Frequency = 2000", CR FREQOUT 9, 4000, 2000 + DEBUG "Frequency = 3000", CR FREQOUT 9, 4000, 3000 = DEBUG "Frequency = 2000 + 3000", CR FREQOUT 9, 4000, 2000, 3000 DEBUG "Frequency = 2000 + 2001", CR FREQOUT 9, 4000, 2001 DEBUG "Frequency = 2000 + 2002", CR FREQOUT 9, 4000, 2002 DEBUG "Frequency = 2000 + 2003", CR FREQOUT 9, 4000, 2003 DEBUG "Frequency = 2000 + 2005", CR FREQOUT 9, 4000, 2005 √ Run Mixing. Tones. bs 2 DEBUG "Frequency = 2000 + 2010", CR FREQOUT 9, 4000, 2010 DEBUG "Done", CR END Excerpt from page 225 - 226 Slide 36
Chapter #8: Frequency and Sound Excerpt from Do. Re. Mi. Fa. Sol. La. Ti. Do. bs 2 DEBUG "Mi. . . ", CR: FREQOUT 9, 500, 1319 ' E 6 DEBUG "Fa. . . ", CR: FREQOUT 9, 500, 1396 ' F 6 DEBUG "Sol. . ", CR: FREQOUT 9, 500, 1568 ' G 6 √ Run Do. Re. Mi. Fa. Sol. La. Ti. Do. bs 2 Frequencies in Music Excerpts from pages 227 - 229 Slide 37
Chapter #8: Frequency and Sound Excerpts from pages 250 - 256 Slide 38
- Slides: 38