1 A Modification of Chapters 5 & 7 Slides Presentation based on: "What's a Microcontroller ?" By...

24
1 A Modification of Chapters 5 & 7 A Modification of Chapters 5 & 7 Slides Slides Presentation based on: "What's a Microcontroller ? By Andy Lindsay Parallax, Inc Presentation developed by: Presentation developed by: Martin A. Hebel Martin A. Hebel Southern Illinois University Carbondale Southern Illinois University Carbondale College of Applied Sciences and Arts College of Applied Sciences and Arts Electronic Systems Technologies Electronic Systems Technologies 9/10/03

Transcript of 1 A Modification of Chapters 5 & 7 Slides Presentation based on: "What's a Microcontroller ?" By...

                      

1

A Modification of Chapters 5 & 7 A Modification of Chapters 5 & 7 SlidesSlides

Presentation based on:

"What's a Microcontroller ?"By Andy LindsayParallax, Inc

Presentation developed by:Presentation developed by:

Martin A. HebelMartin A. HebelSouthern Illinois University CarbondaleSouthern Illinois University CarbondaleCollege of Applied Sciences and ArtsCollege of Applied Sciences and ArtsElectronic Systems TechnologiesElectronic Systems Technologies9/10/03

                      

2

Use and CopyrightUse and Copyright

This presentation supplements "What's a Microcontroller" by Andy Lindsay. (Link to text at Parallax)

This presentation is not a replacement for the text. Important concepts of the text are highlighted. In some cases, additional material has been added

to augment the text. Denoted by titles colored goldgold.

Full program listings are generally not provided in the presentation.

Distribution:This presentation may be freely distributed without

modifications. Modifications are permitted by schools and organizations for internal use only. Credits, use and copyright slides must remain.

                      

3

COPYRIGHTS AND TRADEMARKSThis documentation is Copyright 2003 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. Check with Parallax for approval prior to duplicating any of our documentation in part or whole for any use.

BASIC Stamp is a registered trademark of Parallax, Inc. If you decide to use the name BASIC Stamp on your web page or in printed material, you must state that "BASIC Stamp is a registered trademark of Parallax, Inc." Other brand and product names are trademarks or registered trademarks of their respective holders.

DISCLAIMER OF LIABILITYParallax, Inc. and Southern Illinois University are not responsible for special,

incidental, or consequential damages resulting from any breach of warranty, or under any legal theory, including lost profits, downtime, goodwill, damage to or replacement of equipment or property, or any costs of recovering, reprogramming, or reproducing any data stored in or used with Parallax products. Parallax 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.

                      

4

Devices that Contain Light SensorsDevices that Contain Light Sensors

The boebot uses sensors to interact with its environment.

There are a variety of sensors used for a variety of purposes: Pressure, rotation, temperature, smoke, tilt, vibration, light and so on.

Light sensors are also used in a variety of applications:

Automatic street lightsTV remotes using Infrared (non-visible

light).Camera flash and exposure controlsSecurity alarms

                      

5

Introducing the PhotoresistorIntroducing the Photoresistor

While there are a variety of light sensors, a very popular one is the photoresistor in that it is easy to use and inexpensive.

As the name implies, it is a resistor that reacts to light. The active ingredient Cadmium Sulfide (CdS) allows electrons to flow more easily when light energy hits it, thus lowering it resistance (opposition to current flow).

The brighter the light the lower the resistance.

                      

6

Why?Why?

A photoresistor is made of a high resistance semiconductor.

The photons of high frequency light are absorbed by the semiconductor giving bound electrons enough energy to jump into the conduction band. The resulting free electrons (and their hole partners) conduct electricity thereby lowering resistance.

                      

7

Basic CircuitBasic Circuit

As the photoresistor’s resistance changes with light exposure, so does the voltage at Vo. As R gets larger, Vo gets smaller, and as R gets smaller, Vo gets larger.

Vo is what the BASIC Stamp I/O pin is detecting when it is functioning as an input.

If this circuit is connected to IN6, when the voltage at Vo is above 1.4 V, IN6 will store a 1. If Vo falls below 1.4 V, IN6 will store a 0.

V0

R

                      

8

A Better Idea: Measuring Using A Better Idea: Measuring Using TimeTimeThe photoresistor can also be used

with the BASIC Stamp in an RC circuit (Resistor-Capacitor circuit) to obtain a value in relation to the amount of resistance, or, in this case, the amount of light hitting the sensor.

In a RC-network, the capacitor is charged and discharged at different rates determined by the resistor and the capacitor sizes.

                      

9

Introducing the CapacitorIntroducing the Capacitor

The capacitor is a device which can store an electron charge. Its size is expressed typically in microfarads (F) or millionths of Farads.

Certain types of capacitors are polarity sensitive, that is, they can only be connected in one direction.

Connecting a polarity sensitive capacitor backwards can cause the device to explode.•Wear safety glasses.•Ensure proper polarity when connecting.

                      

10

                      

11

Polled RC TimePolled RC Time

In the Polled RC Time circuit the following occurs: Button is pressed charging the capacitor.

5V

The button is released, the BASIC Stamp

begins timing and the capacitor begins todischarge.

                      

12

3. The BASIC Stamp continues timing until input P7 changes to a low (drops below 1.4V).LOOP UNTIL IN7=0

4. Time is displayed in tenths of seconds.

V => 1.4VLogic 1

V < 1.4VLogic 0

                      

13

The time to discharge the capacitor is in proportion to the size of the resistor and capacitor network (RC).

The larger the capacitance (C), the greater the charge it can hold, increasing time.

The larger the resistance (R), the slower the capacitor will discharge, increasing time.

                      

14

Activity #3: Reading with BASIC Activity #3: Reading with BASIC StampStampThe BASIC Stamp has an instruction to

perform much of the timing operation automatically:

RCTIME Pin, State, VariableWhere: Pin is the pin the RC network is connected.State is the initial state when timing

begins.Variable is the memory location to store

the results. Just like PULSOUT the time is the number of 2uS increments.

                      

15

Activity #1: Build & Test Light Activity #1: Build & Test Light MeterMeterThe RC Time circuits is

configured so that the capacitor is charged by the output (P2 in this case) and the time to discharge though the resistor is measured.

In this case, as light level changes, discharge time will change.

                      

16

What happens to the value of time as the light level changes? When is it lowest? Highest?

                      

17

Using Stamp Plot LiteUsing Stamp Plot Lite

This image shows a plot of the light level. Note how the value increases from left to right then drops again suddenly?

                      

18

FLASHLIGHT BEAM FOLLOWING BOE-BOT

Activity:Test and calibrate your Boe-Bot’s

light sensors to recognize the difference between ambient light and a directed flashlight beam.

Program the Boe-Bot to follow the flashlight beam that is pointed at the surface in front of the Boe-Bot.

                      

19

Adjust Sensors to Search for Flashlight BeamPosition the photoresistors’ light-

collecting surfaces are pointing ahead at separate points on the ground about 2 in (5.1 cm) in front of the Boe-Bot.

                      

20

Difference in lightDifference in light

Know the difference between light readings with and without the flashlight beam shining in the Boe-Bot’s path.

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

timeLeft VAR WordtimeRight VAR WordDEBUG "PHOTORESISTOR VALUES", CR,

"timeLeft timeRight", CR,"-------- ---------"

DOHIGH 6 ' Left RC time measurement.PAUSE 3RCTIME 6, 1, timeLeftHIGH 3 ' Right RC time measurement.PAUSE 3RCTIME 3, 1, timeRightDEBUG CRSRXY, 0, 3, DEC5 timeLeft, " ", DEC5 timeRightPAUSE 100

LOOP

                      

21

Use ConstantsUse Constants

Use constants (from your table):LeftAmbient CON 108RightAmbient CON 114LeftBright CON 20RightBright CON 22

Calculate other constants' Average Scale

factorLeftThreshold CON LeftBright + LeftAmbient /2 * 5 /

8RightThreshold CON RightBright + RightAmbient /2

* 5 / 8

                      

22

The ProgramThe Program

                      

23

The ProgramThe Program

                      

24

The ProgramThe Program