28129 Parallax Inc, 28129 Datasheet

TEXT BASIC ANALOG & DIGITAL

28129

Manufacturer Part Number
28129
Description
TEXT BASIC ANALOG & DIGITAL
Manufacturer
Parallax Inc
Type
Programmingr
Datasheet

Specifications of 28129

Style
Book
Title
Basic Analog and Digital
Contents
Basic Analog and Digital Text
Product
Microcontroller Accessories
Lead Free Status / RoHS Status
Not applicable / Not applicable
Basic Analog and Digital
Student Guide
VERSION 1.3

Related parts for 28129

28129 Summary of contents

Page 1

Basic Analog and Digital Student Guide VERSION 1.3 ...

Page 2

WARRANTY Parallax, Inc. warrants its products against defects in materials and workmanship for a period of 90 days. If you discover a defect, Parallax will, at its option, repair, replace, or refund the purchase price. Simply call for a Return ...

Page 3

WEB SITE AND DISCUSSION LISTS The Parallax web site (www.parallax.com) has many application 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 ...

Page 4

...

Page 5

Preface.........................................................................................................................v Audience and Teacher’s Guide ...................................................................................... v Conditions of Duplication ............................................................................................... vi Foreign Translations ...................................................................................................... vi Special Contributors ...................................................................................................... vi Chapter #1: Analog Voltage and Binary States .......................................................1 Introduction to Analog and Digital...................................................................................1 Parts Required ...........................................................................................................2 Building the Analog and ...

Page 6

What have I learned?............................................................................................... 63 Questions ................................................................................................................. 64 Challenge! ................................................................................................................ 64 Why did I learn it? .................................................................................................... 65 How can I apply this? ............................................................................................... 65 Chapter #4: Basic Digital to Analog Conversion .................................................. 67 Build a Resistive Ladder Network................................................................................. 67 ...

Page 7

Build It ....................................................................................................................127 Program It ..............................................................................................................129 What have I learned? .............................................................................................137 Questions ...............................................................................................................138 Challenge! ..............................................................................................................138 Why did I learn it? ..................................................................................................139 How can I apply this? .............................................................................................139 Chapter #8: Light Meter Gizmo with R/C Time Constants..................................141 Parts Required .......................................................................................................144 Build ...

Page 8

...

Page 9

Preface The personal computer brought in a whole new era of electronic sophistication. With it, we have immense amounts of digital computing power located right at our desk. Computers work well when they are connected to each other, and digital ...

Page 10

The answers to these experiments present no impossible or very difficult technical hurdles, and could be solved with a bit of patience. Instructors could participate in an Educator’s Forum to obtain support or Teacher’s Guides if they are available. CONDITIONS ...

Page 11

Chapter #1: Analog Voltage and Binary States This series of experiments introduces analog and digital electronics. What does that mean? In What’s a Microcontroller? we learned that analog is a “continuously variable value”. Another way to think about it is ...

Page 12

Volt/Voltage: The volt is a fundamental unit of electrical measurement named after 18th century physicist Allesandro Volta, and a measurement in volts is referred to as voltage. Most of us encounter this unit of measurement when buying batteries such as ...

Page 13

Analog and Digital Parts Kit to the Board of Education based on its circuit symbol in a schematic. Circuit Schematic: Often referred schematic, a circuit schematic is a map that uses symbols to show the components in ...

Page 14

Current/Amp: Current happens when electrons travel from point A to point B. Direct current is what happens when you give the surplus electrons in the negative terminal of a battery a pathway to get to the positive terminal. The amp ...

Page 15

Figure 1-4 shows what happens inside the pot adjusted. The jagged line represents a resistive element, typically made of carbon. One end of the resistive element is wired to Vdd on the Board of Education, and the ...

Page 16

A LM358 LM358 IMPORTANT: Disconnect the Board of Education's power source while you build the circuit. The Board of Education Figure 1-6 shows the remaining circuit symbols used in the first experiment and where ...

Page 17

X3 X4 P15 P14 P13 P12 P11 P10 Figure 1-6 also shows some samples of 5 socket wide rows that are electrically connected underneath the breadboard. There are 34 of ...

Page 18

Pot with analog Op-Amp voltage output from wiper follower circuit terminal Vdd Vdd P12 P7 A LM358 100k Ω Pot Vss Vss The potentiometer is what makes the analog output. The op-amp is wired to function as a voltage follower. ...

Page 19

X3 P15 P14 P13 P12 P11 P10 IMPORTANT: Pay careful attention to placing the LM358 so that the index mark is to the top, as shown on this breadboard ...

Page 20

Basic Analog and Digital - State_of_P7.bs2 ' Check the state of P7 and show it on the Debug Terminal. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG CLS INPUT 7 OUTPUT 12 DO OUT12 = IN7 DEBUG HOME, "The state ...

Page 21

INPUT 7 Likewise, I/O pin P12 functions as output with this command: OUTPUT 12 The rest of the program should be done over and over again, so this is a good place to put a loop. So, at the point ...

Page 22

To send the program back to the command: LOOP Troubleshooting Here are a few tips on things to check if your program doesn't work as expected. • It often takes a few tries to catch all the wiring mistakes and ...

Page 23

The Output As you adjust the potentiometer, note how the LED at the voltage follower's analog output can vary in brightness. Meanwhile the LED circuit driven by P12 either turns on or off. This characterizes the difference between analog voltage ...

Page 24

About the Comparator Using PBASIC, we programmed the BASIC Stamp to function as a comparator. A comparator is so named because it's a circuit that compares its input voltage to a particular voltage, also called the threshold voltage. If the ...

Page 25

What have I learned? On the lines below, insert the appropriate words from the list on the left. A __________ shows circuit symbols connected to each other by lines. Each circuit symbol corresponds to a component and the lines connecting ...

Page 26

Questions 1. Circle the word that makes the sentence true: The input for a voltage follower is at the ( inverting / non-inverting ) terminal of the op-amp in this experiment. 2. How do you tell the difference between the ...

Page 27

Why did I learn it? In this experiment, we compared a binary LED output to an analog LED output. Aside from knowing that the voltage at the wiper terminal had just crossed the threshold voltage, there was no way of ...

Page 28

...

Page 29

Chapter #2: Introduction to Bit Crunching An important step in learning how to make the BASIC Stamp process analog data is learning how to make it send and receive binary numbers. It's also important to understand how binary numbers work, ...

Page 30

Jumper wires The Pushbutton There's just one new part and circuit symbol to introduce for this experiment, the pushbutton in Figure 2-1. Note how each terminal on the circuit symbol corresponds to two pins on the part. If you ...

Page 31

Vdd P1 P0 Ω 220 10 k Vss P5 P4 470 Ω LED Vss Before making a PBASIC program telling the BASIC Stamp how to interface with this circuit, it's essential to understand how the circuit works. The LEDs are ...

Page 32

Program Listing 2.1 makes the left LED in Figure 2-3 light up when the left pushbutton is pressed. ...

Page 33

Basic Analog and Digital - PL2_1R0.bs2 ' Program Listing 2.1 Revision 0. ' {$STAMP BS2} ' {$PBASIC 2.5} a VAR Bit b VAR Bit d VAR Nib INPUT 0 INPUT 1 OUTPUT 4 OUTPUT 5 DEBUG CLS DO a ...

Page 34

So how do you count from decimal-0 to decimal-3 using the binary pushbuttons? The two-bit binary equivalent of decimal-0 is 00. When you don’t press either of the pushbuttons, the decimal output the Debug Terminal. When you ...

Page 35

Next, three variables are defined. Variables can be used to store values while the program is running. The letters a the variable a can store a single binary digit, likewise with the variable defined variable that stores ...

Page 36

Next, we need to set the output at pin P4 equal to the input taken at pin P1. The left LED which is connected to P4 will light up when the left button, which is connected to P1, is pressed. ...

Page 37

Six commands are used to display all the measured states and the calculated DEBUG binary values in the Debug Terminal. The first different items. Remember, each item in a single comma. The command sends the cursor to the top-left "home" ...

Page 38

Here's something new. The modifier variable Because this is the last instruction we want to repeat, it’s followed by the d. command. LOOP DEBUG "Decimal equivalent: ", DEC1 d, CR LOOP Counting in Binary Table 2-1 shows how to count ...

Page 39

Converting from binary to decimal takes two steps. The first step is to multiply each bit by its power of two. Table 2-2 shows the powers of two for up to 8-bits. When you multiply each bit by its value ...

Page 40

Parallel and Serial Transmission Program Listing 2.1 repeats the entire check and report on the pushbutton states routine over and over again. Because the BASIC Stamp checks for input over and over again without waiting for some kind of signal ...

Page 41

Reprogramming to Receive Serial Data Enter Program Listing 2.2 into the BASIC Stamp Editor, and save it under the name PL2_2R0.bs2. ' Basic Analog and Digital - PL2_2R0.bs2 ' Program Listing 2.2 Revision 0. ' {$STAMP BS2} ' {$PBASIC 2.5} ...

Page 42

Next, release the right button, and press and release the left button again. The output should change so that it looks like Figure 2-6. Figure 2-5 Debug Terminal Output for Program Listing 2.2. Figure 2-6 Debug Terminal Output for Program ...

Page 43

Press and hold the right button, then press and release the left button twice. Then the output should look like Figure 2-7. If your program worked as shown, you just synchronously shifted 4 serial bits into the BASIC Stamp's RAM. ...

Page 44

Read Input Clock signal from left pushbutton to P1 Data signal from right pushbutton to P0 Figure 2-8: Timing Diagram. About the Code Like Program Listing 2.1, we use a comment to include some information about the program at the ...

Page 45

This loop executes the PBASIC command between the FOR…NEXT command four times. The first time through the loop the value the second NEXT time through the value of n increments to 2, and so on until ...

Page 46

DEBUG HOME, "Shifting in bits: ", BIN4 d NEXT Once the loop is finished and all the bits are shifted into the FOR…NEXT messages are printed. The second of the two This modifier is used to make the Debug Terminal ...

Page 47

What have I learned? On the lines below, insert the appropriate words from the list on the left. The _____________ can be used to process information about analog measurements using _____________ . Before working with analog to largest digital interfaces, ...

Page 48

Questions 1. Determine the decimal equivalents of these binary numbers: 1010, 1111, 0010, and 0100. 2. The command d = d<<1 1. What command do you think would be used to shift the bits to the right? What command would ...

Page 49

Why did I learn it? The goal in this series of experiments is to demonstrate how a device such as the BASIC Stamp, which processes binary data, can be used to interface with the analog world. Binary numbers and states ...

Page 50

...

Page 51

Chapter #3: Basic Analog to Digital Conversion BUILD YOUR OWN DIGITAL DC VOLTMETER A digital DC voltmeter (DC DVM handy tool for measuring voltage between two contact points. In this experiment, we will build a DVM for measuring ...

Page 52

ADC0831 (1) 100 k potentiometer (10) Jumper wires, give or take a few The Potentiometer, a Source of Variable Voltage There is a reason why the voltage at the wiper terminal of a pot changes when you turn the ...

Page 53

Resistors in Series: A chain of resistors connected end to end. Three resistors in series are shown below. The three resistors can be viewed as a single resistance whose value is: The ADC0831 Integrated Circuit - An 8-bit Analog to ...

Page 54

DVM output). The BASIC Stamp must also be programmed to send binary control signals to make the ADC0831 do its job. Figure 3-2 shows a pin map of the ADC0831. Each pin has a ...

Page 55

Electronics designers use data sheets to find the kind of information just discussed. Each IC manufacturer publishes data sheets for the integrated circuits they make. The information just covered on the pin map and control signals was condensed from a ...

Page 56

We'll modify the code so that it also displays the decimal conversion of the 8-bit binary number. Next we'll add some more code to adjust the number volt scale. Make sure your circuit is constructed correctly and ...

Page 57

The Output If the pot is adjusted somewhere in the middle of its range, the output displayed in the Debug Terminal should look similar to Figure 3-4. As you adjust the pot, the zeros and ones should change rapidly. Each ...

Page 58

The next section is called the variable declarations section, and it begins with a comment explaining that this is the declarations section. This program uses just the variable at present. We'll add code that will make use of the other ...

Page 59

DO GOSUB ADCDATA GOSUB CALC_VOLTS GOSUB DISPLAY LOOP ADCDATA: HIGH CS LOW CS LOW CLK PULSOUT CLK, 210 SHIFTIN dataOutput,CLK,MSBPOST,[adcbits\8] RETURN The subroutine sends control signals to and collects output data from the ADC_Data ADC0831. This subroutine is where the ...

Page 60

LOW CLK The command sends a clock pulse to the ADC0831's CLK input. PULSOUT CLK, 210 This is the first clock pulse, and all it does is tell the ADC0831 to start converting on the next clock pulse. Because of ...

Page 61

The subroutine is empty right now, but we will develop the code for this Calc_Volts subroutine shortly. The subroutine will calculate the measured voltage to the hundredth’s decimal place. Calc_Volts: RETURN At present, the subroutine just displays the binary output ...

Page 62

Interpreting the Output The ADC0831 measures an analog voltage at its input. Then it sends the BASIC Stamp a binary number describing the value it measured. For now, we’ll focus on a voltage scale that starts with 0 volts and ...

Page 63

First, multiply each bit by its power of two from Table 3-1: 128 128 ...

Page 64

Calculate Voltage Now that we know the decimal equivalent of the ADC0831’s binary output, we can do a few calculations to get the measured voltage. To find out what voltage the decimal number corresponds to, we need to calculate where ...

Page 65

So, now we know to multiply by 5 and divide by 255 for a 5 volt scale with 256 levels. We can calculate the voltage from Figure 3-6 where the ADC0831’s output is 10100101 = 165. The measured voltage is: ...

Page 66

The PBASIC command set for the BASIC Stamp does arithmetic using integer values. Integers are the counting numbers: …-2, - etc. The largest integer the BASIC Stamp can process is 65535. When using integer arithmetic, the ...

Page 67

A/D Voltage = 255 In long division, calculating the part of the answer to the right of the decimal point is repetitive. We multiply the remainder by 10, then divide by 255 again, then take another remainder, ...

Page 68

This gives us our three PBASIC commands for calculating the values to the left and right of the decimal point. To reconstruct the fractional value on the display, we’ll print a period "." in-between the two values. The first of ...

Page 69

All that remains to be done is to correct the rounding error in the hundredth’s place. This rounding problem can be corrected by adding the segment of code shown below to the subroutine. Calc_Volts Calc_Volts adcBits ...

Page 70

The Output The output sample from Figure 3-9 indicates that the DVM is now calculating to the hundredth’s decimal place correctly. As soon as you're sure your program works right, save it as P3_1R4.bs2. We will add to both the ...

Page 71

This process could be repeated over and over again to get the digit in the ten-thousandth’s place, the hundred-thousandth’s place, and so on. Once the digit in the thousandth’s place is known, the rules for rounding apply as follows: • ...

Page 72

Since the first value is zero, there are 255 voltage steps. The step size is given by: 5 Volts = = Step Size 0.0196 255 steps With this ...

Page 73

What have I learned? On the lines below, insert the appropriate words from the list on the left. Using the A/D converter makes it possible to process __________ information with the BASIC Stamp, a digital ( __________ ) device. The ...

Page 74

Questions 1. In your own words, explain the function of an A/D converter. 2. What would be the resolution if you were to use a 16-bit A/D converter in this experiment? 3. How does the voltage divider equation relate to ...

Page 75

Why did I learn it? There is a wide variety of electronic applications where analog signals are measured and digital devices are used to process the analog signal data. In this experiment, we used a BASIC Stamp and A/D converter ...

Page 76

...

Page 77

Chapter #4: Basic Digital to Analog Conversion BUILD A RESISTIVE LADDER NETWORK Digital to analog conversion (D/A conversion) is, for the most part, the reverse of A/D conversion. With A/D conversion, we started with a continuous voltage range at the ...

Page 78

Stamp to send the resistive ladder network sets of binary voltage levels. These sets of binary voltages are converted by the resistive ladder network to discrete output voltages. The DVM from Chapter #3 will be used to measure the converter's ...

Page 79

DAC Output P7 2 kΩ 1 kΩ 2 kΩ kΩ 1 kΩ kΩ 1 kΩ kΩ 2 kΩ Vss Vss This being the case, why doesn't everybody use resistive ladder networks for A/D and ...

Page 80

Voltmeter Input Lead Vdd 8 5 Vdd Vref 1 P0 /CS 2 Vin(+) GND CLK Vin(-) ADC0831 Vss Program It Not only can we use the DVM to measure the output voltage from ...

Page 81

Editor and make sure to save it for future use. When the circuit is built and the code is entered and saved, run Program Listing 4.1, and let's see how it works. ' -----[ Title ]----------------------------------------------------------- ' Basic Analog and ...

Page 82

LOW CLK PULSOUT CLK, 210 SHIFTIN DataOutput,CLK,MSBPOST,[adcBits\8] RETURN Calc_Volts adcBits / 255 adcBits // 255 v2 = 100 * R / 255 v3 = 100 * R // 255 ...

Page 83

About the Code The comments are updated to indicate that this is Program Listing 4.1. In the third comment is included a reference to indicate that a function was added to the DVM that does D/A conversion. ' -----[ Title ...

Page 84

This is the start of the digital to analog conversion (DAC) subroutine, so it's descriptively labeled . The value of is set to 11. This means that the output should be n steps DAC n above output ...

Page 85

Modify the Code If the D/A converter works as we expect, each time the value of the D/A output should increment by 0.2 volts. Try starting with n=0 by modifying the value of in the subroutine. n DAC n = ...

Page 86

Addressing Until now, we’ve been addressing each of the I/O lines one at a time. This works well whenever you need to have control over the status of a particular control line. For example, a single LED, is easily addressed ...

Page 87

There are two registers that we need to set to control output on a specific group of I/O ...

Page 88

Here is how to count from using a nibble 0000 4 = 0100 1 = 0001 5 = 0101 2 = 0010 6 = 0110 3 = 0011 7 = 0111 When nibble b is ...

Page 89

This would result in I/O pin P6 being set as an output, and all the other pins (P0, P1, P3) set as inputs. Hence the command “1”) sets up each of the I/O lines as outputs. Sweeping the value of ...

Page 90

Figure 4-6 shows the output. Try that with a hand held voltmeter and you’ll begin to see the usefulness of combining the BASIC Stamp with analog interfaces. Imagine trying to test all 4096 levels of a 12-bit DAC one at ...

Page 91

Third, the largest error is 0.1 volts. This kind of data can be exceedingly useful in electronics design, and the automated testing process is a huge time saver. The Voltage Follower Let's use the voltage sweep to analyze what ...

Page 92

Table 4-1:D/A Converter Output Without Buffer Decimal Binary Figure 4-7 shows the D/A converter with an LED circuit added. The LED circuit is the ...

Page 93

Vdd 8 5 Vdd Vref 1 P0 /CS 2 Vin(+) GND CLK Vin(-) ADC0831 Vss Figure 4-8 D/A Circuit With a Buffer Comparing the two tables, it should be fairly clear that the ...

Page 94

Table 4-2:D/A Converter Output with Buffer Decimal Binary The reason for this goes back to Ohm's Law (voltage equals ...

Page 95

What have I learned? On the lines below, insert the appropriate words from the list on the left. A set of ___________ voltage values sent to the inputs of a resistive ladder network results in a ___________ voltage level at ...

Page 96

Questions 1. “1101” is what value in the decimal number system? What voltage would you expect from the D/A converter output if you sent it this binary number? 2. What function is provided by a D/A converter? 3. What are ...

Page 97

Why did I learn it? There are many different “real world” circuits that require some sort of analog voltage. For example, when you listen to a compact disc, you’re listening to sounds that started as analog signals from a microphone. ...

Page 98

...

Page 99

Chapter #5: Time Varying Signals In this chapter we'll view signals with the Stamp-O-Scope this we'll use the BASIC Stamp along with the A/D and D/A circuits built in Chapters #3 and #4 to emulate the function of ...

Page 100

Oscilloscope A device that measures and displays time-varying voltage signals. oscilloscope is a common tool used by many electronics technicians and engineers to display these signals. The signals of interest often repeat themselves many times each second. The oscilloscope can ...

Page 101

The piezoelectric speaker shown in Figure 5-2 has positive and negative terminals shown on both the circuit symbol and the component. The speaker from the Analog and Digital Parts Kit has a plus (+) on its topside above the appropriate ...

Page 102

Main: GOSUB DAC GOSUB ADC_Data 'GOSUB Calc_Volts GOSUB Display RETURN Modify the subroutine so it looks like this: DAC DAC: DIRB = 15 OUTB = n PAUSE 50 RETURN Also modify the subroutine from Program Listing 4 looks ...

Page 103

If you were to rotate the Stamp-O-Scope display a quarter turn counter-clockwise, it would resemble the display of a normal oscilloscope. Figure 5-4 shows the Stamp-O- Scope rotated this way. It also shows three of the most basic measurements taken ...

Page 104

Voltage Figure 5-4: Horizontal Output Sample of Time-Varying Waveform A more conventional way of viewing time-varying waveforms is shown in Figure 5-4. This is the way they are typically displayed using an oscilloscope. The amplitude, period and DC offset are ...

Page 105

The D/A converter's output is programmed for a maximum of 3 volts and a minimum of 1.6 volts. Therefore the peak-to-peak amplitude is 3 – 1.6 volts = 1.4 volts. The DC offset is the difference between 0 ...

Page 106

GOSUB Display RETURN This is the simplest form of DAC subroutine covered in Chapter #4. DAC: DIRB = 15 OUTB = n PAUSE 50 RETURN The command in the DEBUG Display location in the Debug Terminal corresponding to the magnitude ...

Page 107

DO FOR GOSUB Main NEXT FOR GOSUB Main NEXT LOOP Note that both the amplitude and period of the waveform increased. This is because the BASIC Stamp is programmed to ...

Page 108

FOR…NEXT values of in the second n FOR…NEXT has to be between 0 and 15. Changing the limits of the first FOR…NEXT stays high. In other words, you can change the pulse width buy ...

Page 109

LM358 P7 Ω Ω Ω Ω Ω Ω Ω Ω Ω Vss Enter this program into the BASIC Stamp ...

Page 110

First, run the program as shown. The piezoelectric speaker should tick about every half- second indicating the transitions between the high and low signal. Next, change the value of from 500 to 100, and note that the ticking is much ...

Page 111

Figure 5-6. These three circuit elements are all that's necessary to connect to the BASIC Stamp to play tunes and tones. P10 Vss The piezoelectric speaker shown in Figure 5-6 works like a rechargeable battery that charges and ...

Page 112

A list of these musical notes is then played using Reprogram the Circuit for Musical Notes ' Basic Analog and Digital - PL5_3R0.bs2 ' Charge!!! ' {$STAMP BS2} ' {$PBASIC ...

Page 113

About the Code The only new command introduced is follows: FREQOUT Pin, Duration, Freq1, Freq2 We already know that is a number between 1 and 15 that refers to your choice of Pin BASIC Stamp I/O pin, P1 through P15. ...

Page 114

What have I learned? On the lines below, insert the appropriate words from the list on the left. voltage An oscilloscope is a tool used by many electronics technicians and engineers, and it measures and displays ________________ signals. period Amplitude, ...

Page 115

Questions 1. What's the main difference between the Stamp-O-Scope display and a regular oscilloscope display the frequency of a signal is 1000 Hz, what's the period? 3. How can you adjust the scale to display finer variations in ...

Page 116

Why did I learn it? The oscilloscope is an essential tool in the electronics industry, and many hobbyists use them as well. This is a good first exposure to using the oscilloscope and to viewing time- varying waveforms. If you ...

Page 117

Chapter #6: Recording Frequency Data In the previous chapter we used the BASIC Stamp to control a D/A converter to produce audible tones. In this chapter, we'll use a 555 timer to generate frequencies in the audible sound range, then ...

Page 118

The electrolytic capacitor has a positive (+) and a negative (-) terminal. The negative terminal is the lead that comes out of the metal canister closest to the stripe with a negative (–) sign. Always make sure to connect these ...

Page 119

Timer Build It The circuit in Figure 6-4 is called "astable multivibrator" and is used to generate a steady stream of pulses. The 555 timer's output drives a piezoelectric speaker circuit and ...

Page 120

After you've built the circuit, adjust the potentiometers until the piezoelectric speaker makes a steady, slow tic-toc sound. A frequency desirable. You can make the tic-toc stop any time you want by connecting pin-5 of the ...

Page 121

The Output Figure 6-5 shows the Stamp-O-Scope 2 display. You can adjust the potentiometers and change the frequency characteristics of the waveform. For example, pot B directly affects the amount of time the signal is low. It also indirectly affects ...

Page 122

Now, try adjusting pot B and make the low signal two asterisks wide. What happened to the pulse width? It should also have gotten narrower too. Next, try adjusting pot B as far as it will go to increase the ...

Page 123

The pulse train is now repeating itself several times as fast as the sampling rate. So the Stamp-O-Scope 2 display is no longer valid. Now back way off on pot B so that all you get is a periodic clicking ...

Page 124

Program It Let's make a program that counts how many times the pulse train repeats itself. In effect, we will make a program that determines the frequency of the pulse train. The BASIC Stamp has a built in feature for ...

Page 125

Remember that you can turn the sound (noise, racket, whatever you want to call it by now) off by shorting pin 5 on the 555 timer to Vss. When you want the sound back on, just disconnect the wire from ...

Page 126

Vdd Ω Ω 7 555 Timer 6 100 k Ω POT 0.1 µF Vss Adjusting pot B, you should now be able to measure sound on a frequency range from about ...

Page 127

During the time this program records the frequency, the Debug Terminal display is similar to the previous revision of the program. When the program is done recording, it displays ten frequency samples. The Debug Terminal data shown in Figure 6-10 ...

Page 128

As the value of is incremented in the n first time through the array, a value is loaded into word f(0), the second time through the array, a value is loaded into word f(1), and so on through word f(9). ...

Page 129

What have I learned? On the lines below, insert the appropriate words from the list on the left. Sounds can be characterized by _____________ waveforms. sampling frequency range for audible sound is between 20 and 20,000 Hz. When a rate ...

Page 130

Questions 1. Given four different frequencies of sound, 3.5 Hz, 350 Hz, 3,500 Hz, 35,000 Hz, which ones can you hear and which ones can't you hear? Explain your answers. Also, compare the pitch of the sounds you can hear. ...

Page 131

Hint: Review Chapter #1 for circuit and program techniques for implementing the pushbuttons. Why did I learn it? Digital processing of audio signals is still expanding ...

Page 132

...

Page 133

Chapter #7: Digital to Analog the Easy Way using PWM A resistor, capacitor, BASIC Stamp, and a single line of PBASIC code. That's all it takes to build a D/A converter with 8-bit resolution. Sound too good to be true? ...

Page 134

You could also disconnect the battery from the capacitor, and it would maintain its voltage. Typically, there is a small amount of current that does make it through the dielectric material that separates the plates. It's called leakage ...

Page 135

V     Output − = × ⇒     V   Input   All that's left is to plug in the ...

Page 136

Output 5 Voltage 4 (Volts -0.02 -0.01 0 Input 5 Voltage 4 (Volts -0.02 -0.01 0 Applying many narrow pulses as opposed to the single very wide pulse applied in Figure 7-3 ...

Page 137

The photoresistor senses light level. Under a bright light, the resistance can drop to as low as a few ohms. In darkness, the resistance can climb as high Figure 7-4 shows the circuit symbol for a ...

Page 138

The format of the command is: PWM PWM Pin, Duty, Cycles The term refers to a BASIC Stamp I/O pin, and you can specify a pin number Pin between 0 and 15 to select a pin. Since the converter input ...

Page 139

Usually, we know what voltage we want can rearrange the equation to tell us what duty we need: duty = 255 × (D/A Output ÷ 5) Since we want our D/A output to be 3.25 volts: duty = ...

Page 140

CLK PIN DataOutput PIN Modify the subroutine from Program Listing 4.1 as follows: DAC DAC 166 PWM RETURN Also modify the subroutine so that it only displays the voltage, as shown below. Display Display: DEBUG ...

Page 141

High input impedance: BASIC Stamp I/O pins set to input mode, op-amp input terminals, and the ADC0831's Vin terminals all have an important aspect in common that makes them invisible to other circuits. It's high input impedance. The term impedance ...

Page 142

As you can see, a buffer is essential to keep the voltage steady. You can use the same voltage follower that we used in Chapters #2, #4 and #5 to buffer the output. Place a voltage follower in between the ...

Page 143

Vdd A P8 LM358 Ω µF Vss Vss Figure 7-8: PWM DAC with Op-amp Buffer and a Load Figure 7-9 indicates that the buffer is doing its job. Vdd 8 5 Vdd Vref 2 Vin(+) 1 /CS ...

Page 144

Next, add a photoresistor in series with positive lead of your BASIC Stamp DVM should be connected to the node where the photoresistor connects to the 10 kW resistor. This is a voltage divider output, and as ...

Page 145

VAR Byte r VAR Byte v2 VAR Byte v3 VAR Byte n VAR Word ' -----[ Initialization ]-------------------------------------------------- CS PIN 0 CLK PIN 1 DataOutput PIN 2 DEBUG CLS ' -----[ Main Routine ]---------------------------------------------------- DO FOR ...

Page 146

Display: DEBUG HOME, "Decimal value to DAC: DEBUG CR, CR, "DVM Reading: DEBUG ".", DEC2 v2, "-Volts", CR, CR RETURN The Debug Terminal output should indicate that the output of the voltage divider varies as the LED gets brighter and ...

Page 147

What have I learned? On the lines below, insert the appropriate words from the list on the left. The BASIC Stamp has a built in feature for D/A conversion that uses pulse width modulation. The technique uses a series of ...

Page 148

Questions 1. Can changing the capacitor or resistor values improve the resolution of the PWM D/A converter? Explain your answer. 2. Given the command: PWM 14,51,50 does the command take to execute? How many milliseconds is the pulse train high? ...

Page 149

Why did I learn it? Using a simple RC circuit with a buffer is an inexpensive and easy way to get 8-bit DAC. It's also really easy to program, and the accuracy is much closer to that of a D/A ...

Page 150

...

Page 151

Chapter #8: Light Meter Gizmo with R/C Time Constants In this chapter, we'll be using concepts we learned in previous activities to develop a light meter gizmo. Here is the list of gizmo specifications: • The gizmo should beep every ...

Page 152

In Chapter #7, the amount of time it takes a capacitor to charge circuit with a step input was introduced. The same principle applies here. A step will be applied to the circuit, and the amount of ...

Page 153

Output 5 Voltage 4 (Volts -0.02 -0.01 0 Input 5 Voltage 4 (Volts -0.02 -0.01 0 The difference in time it takes the three different circuit outputs to decay can be used ...

Page 154

Parts Required This experiment requires the following parts: (1) 0.1 µF poly capacitor (1) 1 µF electrolytic capacitors (1) 10 µF electrolytic capacitor (1) Piezoelectric speaker (1) 220 resistor (1) Photoresistor Build It Build the circuit shown in Figure 8-3 ...

Page 155

Vdd Vin X3 P15 P14 P13 P12 P11 P10 The PBASIC instruction set has a command called of time it takes a capacitor to discharge under the conditions just ...

Page 156

Then takes care of the time measurement and data storage. RCTIME RCTIME 15, 1, light Program It Enter Program 8.1 in your BASIC Stamp Editor, and download to the BASIC Stamp. ' Basic Analog and Digital - PL8_1R0.bs2 ' Program ...

Page 157

Figure 8-6 shows a sample output with a book casting a shadow over the light meter. The tone emitted by the speaker is audibly lower Figure 8-5 Sample Debug Terminal Output in a Well-lit Area with no Direct Sun Figure ...

Page 158

Figure 8-7 shows the output under low light conditions. Figure 8-8 shows a sample of the output with the lights out. Overflow occurred. The discharge time was more than 65,536 microseconds result, the variable reset to zero because ...

Page 159

Under brighter light conditions, the resolution is poor. You can replace the 1 µF capacitor with a 10 µF capacitor to increase the resolution at higher light levels. For full sun, some kind of shade for the photoresistor would help. ...

Page 160

Do the Math The RC time measurements along with the exponential decay equation can be a powerful tool for determining an unknown resistance or capacitance. − t × = × Since we'll ...

Page 161

Using properties of logarithms, this simplifies to:       ×   Rearranging again gives us an equality in terms of R and C and t: ...

Page 162

What have I learned? On the lines below, insert the appropriate words from the list on the left. Analog sensors that vary in resistance or capacitance are used to measure a variety of physical quantities. An ______________ circuit can be ...

Page 163

Questions 1. Given the circuit in Figure 8.3, how long will it take to discharge if the value of the photoresistor For the discharge time in Question 1, would you expect any of the variables ...

Page 164

Why did I learn it? Pretty neat, huh? We used light for our input and sound was our output. We measured light intensity and generated a particular tone based on that measured intensity. This chapter illustrates how the concepts introduced ...

Page 165

Many of the parts used in this series of experiment are very basic and inexpensive. Applications kits and a myriad of components are available that can be used to add a new level of functionality to the BASIC Stamp. Some ...

Page 166

...

Page 167

Appendix A: Parts Listing and Sources Parts Listing All components (next page) used in the Basic Analog and Digital experiments are readily available from common electronic suppliers. Customers who would like to purchase a complete kit may also do so ...

Page 168

... Analog and Digital Parts And Text Kit (#28155) Analog and Digital Parts Only (#28128) Text only (#28129) Parallax Code# Description ...

Page 169

Appendix B: Resistor Color Code Resistor Color Code Most common types of resistors have colored bands that indicate their value. The resistors that we’re using in this series of experiments are typically “1/4 watt, carbon film, with a 5% tolerance”. ...

Page 170

A resistor has the following color bands: Band #1. = Red Band #2. = Violet Band #3. = Yellow Band #4. = Gold Looking at our chart above, we see that Red has a value write: ...

Page 171

Index - 5 - 555 timer, 107 - A - ADC0831, 41, 43 addressing, 76 aliasing, 113 analog, 1 analog to digital converter, 43 astable multivibrator, 109 asynchronous BASIC Stamp Memory, 26 EEPROM, 26 RAM, 26 ...

Page 172

Pulse width, 98 pulse width modulated, 123 pulse with modulation, 100 pushbutton, 20 PWM, 128 - time constant, 141 RCTIME, 143, 145 Resistance/Ohm, 4 resistive ladder, 67 resistor, 3 ...

Page 173

...

Page 174

...

Page 175

...

Page 176

...

Related keywords