Slide 1 599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a...

38
Slide 1 www.parallax.com 599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller? by Andy Lindsay Presented by Andy Presented by Andy Lindsay Lindsay Applications Engineer, Applications Engineer, Parallax Inc. Parallax Inc. Education Dept. Education Dept.

Transcript of Slide 1 599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a...

Page 1: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 1

www.parallax.com599 Menlo Drive

Suite 100Rocklin, CA 95765

Presentation based on:

“What’s a Microcontroller?" by Andy Lindsay

Presented by Andy Presented by Andy LindsayLindsay

Applications Engineer,Applications Engineer,

Parallax Inc. Education Parallax Inc. Education Dept.Dept.

Page 2: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 2

Copyrights and TrademarksCopyrights and TrademarksThis 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 and product names are trademarks or registered trademarks of their respective holders.

Page 3: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 3

IntroductionIntroduction

How many How many microcontrollers did microcontrollers did you use today?you use today?

What’s a BASIC What’s a BASIC Stamp?Stamp?

Excerpts from pages 1, 2, and 13, 14

For the ClassroomFor the Classroom

BASIC Stamp and BASIC Stamp and Board of EducationBoard of Education

BASIC Stamp BASIC Stamp HomeWork BoardHomeWork Board

Page 4: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 4

Chapter #1: Getting StartedChapter #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

DocumentationExcerpts from pages 9 and 6…(Activity #1 – Getting the Software)

Page 5: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 5

IntroductionIntroduction

Amazing inventions with the BASIC StampAmazing inventions with the BASIC Stamp

Excerpts from pages 3 - 4

Page 6: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 6

Chapter #1: Getting StartedChapter #1: Getting Started

Write a PBASIC program then

download it to the BASIC Stamp

Connect serial cable and battery to HomeWork Board

Connect serial cable to computer COM port.Excerpts from pages 14-16, 18, 20…(Activity #3: Setting up the Hardware &

Testing the System)

1 0 0 1 1

0 1

0 1 1 1 0 0

1 1

0 0 0 0 0

0 0 1 1 0 0 0 0 1

1 0

1 0

1 0

1 0

0 1

0

0 1 1 1 0 0 1 0 0 0 0 1 0 0 0 1 1 0 0 0 1 0 1 00

w w w .stam psinc lass.co m

Reset

B o a rd o f E d u c a tio n

P wr

9 VdcBatte ry

6-9V D C

Sou tSinATNVssP0P1P2P3P4P5P6P7

P11

P9P8

Vin

P10

P15P14P13P12

VddRstVss

B la ckR e d

X 4 X 5

15 14 13 12

1

X1

V ssP 1P 3P 5P 7P 9P 11P 13P 15V in

V ssP 0P 2P 4P 6P 8P 10P 12P 14V dd

U 1

T M

0 1 2

© 2 000 -2003

Vdd

P 15P 14P 13P 12P 11P 10P 9P 8P 7P 6P 5P 4P 3P 2P 1P 0

X2

X3

Vdd VssVin

S TA M P S C LA S Sin

9 VdcBatte ry

Alk

alin

e B

atte

ryPowercell

Com

1

Reset

(916 ) 624 -8333www.pa rallax inc.comwww.s tam psinc lass.com

R ev A

S TA M PS CL A SSin

© 2002

Power

BASIC Stam p Hom eW ork Board

P 15P 14P 13P 12P 11P 10P 9P 8P 7P 6P 5P 4P 3P 2P 1P 0

X2

X3

Vdd VssVin

2

Alkaline B

atteryPowercell

Affix rubber feet to the underside of your board.

Page 7: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 7

Chapter #1: Getting StartedChapter #1: Getting Started' What's a Microcontroller - FirstProgram.bs2 ' BASIC Stamp sends message to Debug Terminal.' {$STAMP BS2}' {$PBASIC 2.5}DEBUG "Hello, it's me, your BASIC Stamp!"ENDRun the

BASIC Stamp Editor

Software Enter this program

Click the ‘Run’

button

Click the PBASIC

2.5 button

Click the BASIC

Stamp 2 Button

Excerpts from pages 18-22…(Activity #4: First Program)

Page 8: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 8

Chapter #1: Getting StartedChapter #1: Getting StartedClick the

‘Run’ button

The Debug Terminal appears with a message sent by the BASIC Stamp

DEBUG "Hello, it's me…"

The command:

Causes the BASIC Stamp to send a message to the Computer

Excerpts from pages 20, 23

1 0 0 1 1

0 1

0 1 1 1 0 0

1 1

0 0 0 0 0

0 0 1 1 0 0 0 0 1

1 0

1 0

1 0

1 0

0 1

0

0 1 1 1 0 0 1 0 0 0 0 1 0 0 0 1 1 0 0 0 1 0 1 00

w w w .stam psinc lass.co m

Reset

B o a rd o f E d u c a tio n

P wr

9 VdcBatte ry

6-9V D C

Sou tSinATNVssP0P1P2P3P4P5P6P7

P11

P9P8

Vin

P10

P15P14P13P12

VddRstVss

B la ckR e d

X 4 X 5

15 14 13 12

1

X1

V ssP 1P 3P 5P 7P 9P 11P 13P 15V in

V ssP 0P 2P 4P 6P 8P 10P 12P 14V dd

U 1

T M

0 1 2

© 2 000 -2003

Vdd

P 15P 14P 13P 12P 11P 10P 9P 8P 7P 6P 5P 4P 3P 2P 1P 0

X2

X3

Vdd VssVin

S TA M P S C LA S Sin

9 VdcBatte ry

Alk

alin

e B

atte

ryPowercell

Page 9: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 9

Chapter #1: Getting StartedChapter #1: Getting Started

' What's a Microcontroller - FirstProgram.bs2 ' BASIC Stamp sends message to Debug Terminal.

' {$STAMP BS2}' {$PBASIC 2.5}

DEBUG "Hello, it's me, your BASIC Stamp!"END

comment

comment

Stamp 2 directivePBASIC 2.5

directive

DEBUG command

END command

Excerpts from pages 20-21, 27-28…(Activity #5: Lookup up Answers)

Page 10: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 10

Chapter #2-5, 8: Digital and Analog Inputs and Chapter #2-5, 8: Digital and Analog Inputs and OutputsOutputs

Excerpt from pages 77 - 78

WhiteRed

Black

Page 11: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 11

Chapter #2-5, 8: Digital and Analog Inputs and Chapter #2-5, 8: Digital and Analog Inputs and OutputsOutputs

Excerpt from pages 84, 106, 150, 182, 220

Page 12: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 12

LED Test Circuit Parts(1) LED – Green

(1) Resistor – 470 (yellow-violet-brown)

Chapter #2: Lights on – Lights off Chapter #2: Lights on – Lights off

470 Yellow

VioletBrown

GoldS ilverorB lank

+

LED

Manual Circuit – LED On

Manual Circuit – LED Off

See What’s a MicrocontrollerPage 39 for resistor color codeinformation

Excerpts from pages 39, 40, 43, 46…(Activity #1: Building and Testing the LED Circuit)

P15P14P13P12P11P10P9P8P7P6P5P4P3P2P1P0

X 2

X 3

V dd V ssV in

Vss

LED470

Vss

+

Vdd

Vss

LED

470

470

Vss

LED470

Vss

P15P14P13P12P11P10P9P8P7P6P5P4P3P2P1P0

X 2

X 3

V dd V ssV in

+

Page 13: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 13

Chapter #2: Lights on – Lights off Chapter #2: Lights on – Lights off

P14

Vss

LED470

P15

P13P12P11P10P9P8P7P6P5P4P3P2P1P0

P14

X 2

X 3

V dd V ssV in

+

BASIC Stamp – LED Circuit

Next StepWrite a PBASIC Program to make the BASIC Stamp Switch the LED circuit input between Vdd (5 V) and Vss (0 V).

Excerpts from pages 47-50…(Activity #2: On/Off Control with the BASIC Stamp)

' {$STAMP BS2}' {$PBASIC 2.5}

DO

HIGH 14 PAUSE 250 LOW 14 PAUSE 250

LOOP

LedOnOff.bs2P14

Vss

LED470

S O U T

S IN

ATN

V S S

P 0

P 1

P 2

P 3

P 4

P 5

P 6

P 7

V IN

V S S

R E S

V D D (+ 5 V )

P 1 5

P 1 4

P 1 3

P 1 2

P 11

P 1 0

P 9

P 8

1

2

3

4

5

6

7

8

9

10

11

12

2 4

23

2 2

2 1

2 0

1 9

1 8

17

1 6

15

1 4

13

B S 2-IC

B S 2

V dd

V ss

S O U T

S IN

ATN

V S S

P 0

P 1

P 2

P 3

P 4

P 5

P 6

P 7

V IN

V S S

R E S

V D D (+ 5 V )

P 1 5

P 1 4

P 1 3

P 1 2

P 11

P 1 0

P 9

P 8

1

2

3

4

5

6

7

8

9

10

11

12

2 4

23

2 2

2 1

2 0

1 9

1 8

17

1 6

15

1 4

13

B S 2-IC

B S 2

V dd

V ss

Page 14: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 14

Chapter #2: Lights on – Lights offChapter #2: Lights on – Lights off

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

Excerpts from page 54…(Activity #3: Counting and Repeating)

LedOnOffTenTimes.bs2

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:

' {$STAMP BS2}' {$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

' {$STAMP BS2}' {$PBASIC 2.5}

HIGH 14 PAUSE 500 LOW 14 PAUSE 500

Page 15: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 15

LED Test Circuit Parts(1) LED – Green(1) LED - Yellow(2) Resistor – 470 (yellow-violet-brown)

Chapter #2: Lights on – Lights off Chapter #2: Lights on – Lights off

BASIC Stamp – LED Circuit(Modified)

P14

P15

Vss Vss

LEDLED

470

470

P15P14P13P12P11P10P9P8P7P6P5P4P3P2P1P0

X 2

X 3

V dd V ssV in+

+

Next Step - Make both LEDs flash on/off √ Open FlashLed.bs2 √ Add two lines of code √ Run your modified program.√ Remember to save your modified program under a different name! Use FlashBothLeds.bs2

FlashBothLeds.bs2

Important: Leave this circuit on your

board!This circuit is re-used in the next set

of activities. Do not take it apart beforebuilding the next circuit.

' {$STAMP BS2}' {$PBASIC 2.5}

DO

HIGH 14 HIGH 15 PAUSE 250 LOW 14 LOW 15 PAUSE 250

LOOP

HIGH 15

LOW 15

P14

P15

Vss Vss

LEDLED

470

470

Excerpts from pages 58-59…(Activity #4: Building and Testing a Second Circuit)

Page 16: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 16

LED Test Circuit Parts(1) Resistor – 220 Ω (red-red-brown)(1) Resistor – 10 kΩ (brown-black-orange)(1) Pushbutton - normally open

(2) Jumper wires

Chapter #3: Digital Input - Chapter #3: Digital Input - PushbuttonsPushbuttons

How the Pushbutton Works

P15P14P13P12P11P10P9P8P7P6P5P4

P2P1P0

P3

X 2

X 3

V dd V ssV in

Vdd

10 k

Vss

P3

220

Pushbutton Circuit

Excerpts from pages 72, 76…(Activity #2: Reading a Pushbutton with the BASIC Stamp)

1, 4

2 , 3 2

1 4

3

1, 4

2 , 3

1 , 4

2 , 3

Vdd

10 k

Vss

P3

220

Page 17: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 17

Chapter #3: Digital Input - Chapter #3: Digital Input - PushbuttonsPushbuttons

' {$STAMP BS2}' {$PBASIC 2.5}

DO

DEBUG ? IN3 PAUSE 250

LOOP

How the Circuit andProgram Work

Excerpt from page 77 - 78

ReadPushbuttonState.bs2 √ Follow instructions with checkmarks on page 78

Vdd

Vss

10 k220

S O U T

S IN

ATN

V S S

P 0

P 1

P 2

P 3

P 4

P 5

P 6

P 7

V IN

V S S

R E S

V D D (+ 5 V )

P 1 5

P 1 4

P 1 3

P 1 2

P 11

P 1 0

P 9

P 8

1

2

3

4

5

6

7

8

9

10

11

12

2 4

23

2 2

2 1

2 0

1 9

1 8

17

1 6

15

1 4

13

B S 2-IC

B S 2

1

0

Vdd

10 k

Vss

220

S O U T

S IN

ATN

V S S

P 0

P 1

P 2

P 3

P 4

P 5

P 6

P 7

V IN

V S S

R E S

V D D (+ 5 V )

P 1 5

P 1 4

P 1 3

P 1 2

P 11

P 1 0

P 9

P 8

1

2

3

4

5

6

7

8

9

10

11

12

2 4

23

2 2

2 1

2 0

1 9

1 8

17

1 6

15

1 4

13

B S 2-IC

B S 2

1

0

Vdd

Vss

10 k220

S O U T

S IN

ATN

V S S

P 0

P 1

P 2

P 3

P 4

P 5

P 6

P 7

V IN

V S S

R E S

V D D (+ 5 V )

P 1 5

P 1 4

P 1 3

P 1 2

P 11

P 1 0

P 9

P 8

1

2

3

4

5

6

7

8

9

10

11

12

2 4

23

2 2

2 1

2 0

1 9

1 8

17

1 6

15

1 4

13

B S 2-IC

B S 2

1

0

Vdd

10 k

Vss

220

S O U T

S IN

ATN

V S S

P 0

P 1

P 2

P 3

P 4

P 5

P 6

P 7

V IN

V S S

R E S

V D D (+ 5 V )

P 1 5

P 1 4

P 1 3

P 1 2

P 11

P 1 0

P 9

P 8

1

2

3

4

5

6

7

8

9

10

11

12

2 4

23

2 2

2 1

2 0

1 9

1 8

17

1 6

15

1 4

13

B S 2-IC

B S 2

1

0

Page 18: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 18

Pushbutton/LED Circuit Parts

(1) Pushbutton – normally open(1) Resistor - 10 k Ω (brown-black-orange)(1) LED – any color(1) Resistor – 220 Ω (red-red-brown)(1) Resistor – 470 Ω (yellow-violet-brown)(2) Jumper wires

Chapter #3: Digital Input - Chapter #3: Digital Input - PushbuttonsPushbuttons

P15P14

P3

P13P12P11P10P9P8P7P6P5P4

P2P1P0

X 2

X 3

V dd V ssV in

Vdd

10 k

Vss

P3

220

P14

Vss

LED470

+

Excerpts from pages 80-83…(Activity #3: Pushbutton Control of an LED Circuit)

PushbuttonControlledLed.bs2

Pushbutton/LED Circuit

ELSE PAUSE 100

ENDIF

' {$STAMP BS2}' {$PBASIC 2.5}

DO

HIGH 14 PAUSE 50 LOW 14 PAUSE 50

LOOP

DEBUG ? IN3

IF (IN3 = 1) THEN

P14

Vss

LED470

Vdd

10 k

Vss

P3

220

Page 19: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 19

' {$STAMP BS2}' {$PBASIC 2.5}DO

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

Pushbutton/LED Circuit Parts

(2) Pushbuttons – normally open(2) Resistors - 10 kΩ (brown-black-

orange)(2) Resistors – 470 Ω (yellow-violet-

brown)(2) Resistors – 220 Ω (red-red-brown)(2) LEDs – any color

Chapter #3: Digital Input - Chapter #3: Digital Input - PushbuttonsPushbuttons

P15P14

P4P3

P13P12P11P10P9P8P7P6P5

P2P1P0

X 2

X 3

V dd V ssV in

++

PushbuttonControlOfTwoLeds.bs2

Excerpts from pages 83-87Activity #4: Two Pushbuttons Controlling Two LEDs

P14

P15

Vss Vss

LEDLED

470

470

Vdd Vdd

10 k

Vss

10 k

Vss

P4

P3

220

220

Page 20: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 20

Stamps In Class Books and KitsStamps In Class Books and Kits

Cited in Further Investigation Sections

Page 21: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 21

Stamps in Class FlowchartStamps in Class Flowchart

www.parallax.com

Education Stamps in Class Flowchart

Page 22: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 22

Servo Circuit Parts(1) Standard Servo(1) LED (red) (1) Resistor (470 Ω yellow-violet-brown)

Chapter #4: Controlling Motion Chapter #4: Controlling Motion

Excerpts from page 105-108…(Activity #1: Connecting and Testing the Servo)

Servo Circuit

Page 23: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 23

Chapter #4: Controlling MotionChapter #4: Controlling Motion

PULSOUT pin, duration

Use 0 to 15 to select BASIC

Stamp I/O pin P0 through P15

duration × 2 s = pulse duration

Example: PULSOUT 14, 1000

ms

s

sdurationpulse

0.2

2000

10002

Excerpts from pages 113-114

P14

Vss

LED470

Vss

P14 W hite

Red

Black

Vin

Servo

Vdd (5 V )

Vss (0 V)

2 .0 ms

10 o’clock 2 o’clock 12 o’clock

www.parallax.com

standard servo

www.parallax.com

standard servo

www.parallax.com

standard servo

1.0 ms 2.0 ms 1.5 ms

Page 24: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 24

Chapter #4: Controlling MotionChapter #4: Controlling Motion

FOR counter = 1 TO 150 PULSOUT 14, 1000 PAUSE 20NEXT

FOR COUNTER = 1 TO 150 PULSOUT 14, 500 PAUSE 20NEXT

FOR counter = 1 TO 150 PULSOUT 14, 750 PAUSE 20NEXT

Excerpts from Example Program: ServoTest.bs2

≈ 3 seconds

≈ 3 seconds

≈ 3 seconds

Excerpts from pages 115-118

Vdd (5 V )

Vss (0 V)

1 .0 ms 1.0 ms

Vdd (5 V )

Vss (0 V)

1 .5 ms 1.5 ms

Vdd (5 V )

Vss (0 V)

2 .0 ms 2.0 ms

20 m s

20 m s

20 m s

www.parallax.com

standard servo

www.parallax.com

standard servo

www.parallax.com

standard servo

Page 25: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 25

Chapter #4: Controlling MotionChapter #4: Controlling Motion

Excerpt from Example Program: ServoControlWithDebug.bs2

Receive windowpane

Transmit windowpane

DEBUG CLS, "Enter number of pulses:", CR DEBUGIN DEC pulses

DEBUG "Enter PULSOUT duration:", CR DEBUGIN DEC duration

Excerpts from pages 119 – 124 (Activity #2: Controlling Position with Your Computer)

√ Follow instructions from Activity #2, pg. 119-124

Page 26: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 26

Chapter #4: Controlling MotionChapter #4: Controlling Motion

Excerpts from Example Program: ServoVelocities.bs2

FOR counter = 500 TO 1000 STEP 4 PULSOUT 14, counter PAUSE 20 DEBUG DEC5 counter, CR, CRSRUPNEXT

Excerpts from pages 125-128Activity #3: Converting Position

to Motion

√ Follow instructions from Activity #3 pg. 125 – 128

counter VAR Word

STEP value controls the rate at which counter increases

Counter increments with FOR…NEXT loop.

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.

FOR counter = 1000 TO 500 STEP 10 PULSOUT 14, counter PAUSE 20 DEBUG DEC5 counter, CR, CRSRUPNEXT

Count down instead of up at a faster step rate.

Page 27: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 27

Chapter #4: Controlling Motion Chapter #4: Controlling Motion Extra Pushbutton Parts(2) Pushbuttons normally open(2) Resistors – 10 k (brown-black-orange)(2) Resistors – 220 (red-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

P14

Vss

LED470

Vdd Vdd

10 k

Vss

10 k

Vss

P4

P3

220

220

Vss

P14 W hite

Red

Black

Vin

Servo

Page 28: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 28

Chapter #4: Controlling MotionChapter #4: Controlling MotionExcerpt from: ServoControlWithPushbuttons.bs2

DO IF IN3 = 1 THEN IF duration > 500 THEN duration = duration - 25 ENDIF ENDIF

IF IN4 = 1 THEN IF duration < 1000 THEN duration = duration + 25 ENDIF ENDIF

PULSOUT 14, duration PAUSE 10

DEBUG HOME, DEC4 duration, " = duration"LOOP

Excerpts from pages131-133

√ Follow instructions with checkmarks on page 132.

Page 29: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 29

Chapter #5: Measuring RotationChapter #5: Measuring Rotation

Dial Circuit Parts(1) Resistor – 220 Ω (red-red-brown) (1) Capacitor – 0.1 F

(2) Jumper wires (1) Potentiometer – 10 kΩ

10 kPot

++

A

B

W

A

B

W

104

0.1 µF

0.01 µF103

Dial Circuit

P15P14P13P12P11P10P9P8

P6P5P4P3P2P1P0

P7

X 2

X 3

V ssV in

Excerpts from pages 149-152, 190…(Activity #3: Reading the Dial with a BASIC Stamp

Important – more info: √ Replace your pushbutton

circuits with this dial circuit. √ Remember to leave the P14 LED and servo circuits connected.√ NOTE: The pot must be firmly

seated in its breadboard sockets.

√ Run ReadPotWithRcTime.bs2 Activity #3 p. 149√ Run ControlServoWithPot.bs2 Activity #4 p. 152√ Have fun controlling the servo with the pot.

Vss

P7

Pot10 k

X

0.1 µF

220 nc

10 k

Pot

+

W

A

B

0.1 µ F

Page 30: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 30

Chapter #5: Measuring RotationChapter #5: Measuring Rotation

Excerpt from: ReadPotWithRcTime.bs2

HIGH 7

PAUSE 100

RCTIME 7, 1, timeExcerpt from page 151-152

√ Your course guide will explain how to adjust

the example program so that it works best with

the pulsout command and gives your servo a

range of motion that uses the potentiometer’s

entire range of motion.

√ Run ReadPotWithRcTime.bs2√ Twist the potentiometer’s input shaft,

and make notes of the time values displayed by the Debug Terminal.

ReadPotWithRcTime.bs2

Page 31: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 31

Chapter #5: Measuring RotationChapter #5: Measuring Rotation

ControlServoWithPot.bs2

Excerpt from page 151 & 156

Activity #4: Controlling a Servo with a Potentiometer

P15

P4P3

P14

P7

P13P12P11P10P9P8

P6P5

P2P1P0

X 2

X 3

V dd V ssV in

V dd

B lackR ed

X4 X5

15 13 1214

+

www.para llax inc .com

PARALLAXSTD BB HS

P14

Vss

LED470

Vss

P14 W hite

Red

Black

Vin

Servo

Vss

P7

Pot10 k

X

0.1 µF

220 nc

Page 32: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 32

Educational SupportEducational 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)

Page 33: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 33

Forum RegistrationForum 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 [email protected], 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.

Page 34: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 34

Chapter #8: Frequency and SoundChapter #8: Frequency and Sound

Piezospeaker Circuit Parts(2) Jumper wires(1) Piezoelectric speaker

Piezospeaker Circuit

TestPiezoWithFreqout.bs2

P15P14P13P12P11P10

P8P7P6P5P4P3P2P1P0

P9

X 2

X 3

V dd V ssV in

Vss

P9 +

'{$STAMP BS2}'{$PBASIC 2.5}

DEBUG "Tone sending...", CR

FREQOUT 9, 1500, 2000

DEBUG "Tone done."

f = 2000 Hz

T = 1÷2000 s

duration = 1500 ms

= 1.5 s

I/O pin = P9

T

Excerpt from page 219-221

√ Build the piezospeaker circuit.√ Run TestPiezoWithFreqout.bs2

Vss

P9

Vss

P9

Page 35: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 35

Chapter #8: Frequency and SoundChapter #8: Frequency and SoundExcerpts from: ActionTones.bs2

DEBUG "Alarm...", CR PAUSE 100 FREQOUT 9, 500, 1500 PAUSE 500 FREQOUT 9, 500, 1500 PAUSE 500

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 NEXT

duration VAR Wordfrequency VAR Word

Excerpts from pages 222-223

√ Run ActionTones.bs2

Page 36: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 36

Chapter #8: Frequency and SoundChapter #8: Frequency and Sound

'{$STAMP BS2}'{$PBASIC 2.5}

DEBUG "Frequency = 2000", CRFREQOUT 9, 4000, 2000

DEBUG "Frequency = 3000", CRFREQOUT 9, 4000, 3000

DEBUG "Frequency = 2000 + 3000", CRFREQOUT 9, 4000, 2000, 3000

DEBUG "Frequency = 2000 + 2001", CRFREQOUT 9, 4000, 2000, 2001

DEBUG "Frequency = 2000 + 2002", CRFREQOUT 9, 4000, 2000, 2002

DEBUG "Frequency = 2000 + 2003", CRFREQOUT 9, 4000, 2000, 2003

DEBUG "Frequency = 2000 + 2005", CRFREQOUT 9, 4000, 2000, 2005

DEBUG "Frequency = 2000 + 2010", CRFREQOUT 9, 4000, 2000, 2010

DEBUG "Done", CREND

MixingTones.bs2

+

Excerpt from page 225 - 226

=

√ Run MixingTones.bs2

Page 37: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 37

Chapter #8: Frequency and SoundChapter #8: Frequency and Sound

1046

.5

1318

.5

1174

.7

1396

.9

1568

.0

1760

.0

1975

.5

2093

.0

2349

.3

2637

.0

2793

.0

3136

.0

3520

.0

3951

.1

4186

.0

1108

.7

1244

.5

1480

.0

1864

.7

1661

.2

1217

.5

2489

.0

2960

.0

3322

.4

3729

.3

C 6 D 6 E6 F6 G 6 D 7B6A6 C 7 E7 F7 G 7 C 8A7 B7

D

E6

6#

b

or

C6#

D6b

or

F

G6

6#

b

or

A

B6

6#

b

or

G

A6

6#

b

or

C7

D7

#

b

or

D

E7

7#

b

or

F

G7

7#

b

or

G

A7

7#

b

or

A

B7

7#

b

or

DEBUG "Mi...", CR: FREQOUT 9,500,1319 ' E6

DEBUG "Fa...", CR: FREQOUT 9,500,1396 ' F6

DEBUG "Sol..", CR: FREQOUT 9,500,1568 ' G6

Frequencies inMusic

Excerpts from pages 227 - 229

Excerpt from DoReMiFaSolLaTiDo.bs2

√ Run DoReMiFaSolLaTiDo.bs2

Page 38: Slide 1  599 Menlo Drive Suite 100 Rocklin, CA 95765 Presentation based on: “What’s a Microcontroller?" by Andy Lindsay Presented by Andy.

                      

Slide 38

Chapter #8: Frequency and SoundChapter #8: Frequency and Sound

Excerpts from pages 250 - 256