Download UNIT 3 : ANALOG INPUT

Document related concepts

Computer wikipedia , lookup

Phase-locked loop wikipedia , lookup

Coupon-eligible converter box wikipedia , lookup

Tektronix analog oscilloscopes wikipedia , lookup

Flip-flop (electronics) wikipedia , lookup

Amplifier wikipedia , lookup

Immunity-aware programming wikipedia , lookup

CMOS wikipedia , lookup

Oscilloscope wikipedia , lookup

MOS Technology SID wikipedia , lookup

Multimeter wikipedia , lookup

Wilson current mirror wikipedia , lookup

Power electronics wikipedia , lookup

Resistive opto-isolator wikipedia , lookup

Oscilloscope types wikipedia , lookup

Voltage regulator wikipedia , lookup

Valve RF amplifier wikipedia , lookup

Current mirror wikipedia , lookup

Oscilloscope history wikipedia , lookup

Integrating ADC wikipedia , lookup

Transistor–transistor logic wikipedia , lookup

Operational amplifier wikipedia , lookup

Switched-mode power supply wikipedia , lookup

Schmitt trigger wikipedia , lookup

Analog-to-digital converter wikipedia , lookup

Rectiverter wikipedia , lookup

Opto-isolator wikipedia , lookup

Transcript
UNIT 3 : ANALOG INPUT
Analog input involves sensing an electrical signal from some source external to the computer. This
generated as a result of some changing physical phenomenon such as air pressure, temperature, pH
vibration, etc. This signal is usually not the well defined on/off voltage you have studied in the dig
section, but a voltage that changes continuously with time. As you know, the computer can only de
digital signals, therefore, a process called Analog to Digital Conversion is used. This process is
divided into a number of steps including: generation of the signal by a device we will refer to as a
transducer or sensor, amplification or conditioning of the signal if needed, changing the analog si
to a digital signal that the computer can read and, repeating if necessary. The digital signal is com
discrete voltages which are represented by the binary numbers 0 and 1. These digits are usually org
into groups called bytes or words In unit 1 we used a magnetic microphone generating an electric
signal as an example of an analog signal. The next illustration is an expanded view of this concept
ANALOG TO DIGITAL CONVERTER
The analog to digital converter (ADC) is the heart of the sensing system. The modern ADC is usua
twenty pin integrated circuit (chip). This chip, along with supporting circuitry, is on an interface c
Page 47
UNIT 3 - ANALOG INPUT
plugs into the expansion slot of a computer or in a stand alone system that connects to the serial port.
Analog to digital converters exist in a variety of configurations which determines their use. The most import
characteristics that differentiate one ADC from another are resolution and speed. Other parameters such as
voltage range and type (serial or parallel) are also factors that have to be considered.
RESOLUTION
You have probably seen metre sticks in a science lab that have a different scale on each side. One scale may
be divided into centimetres and the other millimetres. If you are measuring the length of a room for some
purpose, the centimetre side is adequate. If you wish to measure the diameter of a pencil, clearly this scale is
useless. The millimetre side has a higher resolution and will give a more accurate measurement.
The resolution of the ADC chip defines the smallest change in the input signal that can be measured
accurately. Resolution is usually stated in bits. The number of bits (remember binary digit) is the number
of consecutive 0's and 1's that the chip can manipulate at one time. Generally speaking, the greater the
number of bits the ADC is rated at, the finer the resolution of the input signal.
We can look at this concept more closely by comparing two of the more common ADC chips, one rated at 8
bits and the other at 12 bits. The 8 bit chip can resolve the input signal range into 28 or 256 parts. Most
ADC chips operate over a voltage range of 0 to 5 volts. Therefore the finest resolution of this chip would be
5 V ÷ 256 = 0.020 V or 20 millivolts per division. By comparison, the 12 bit chip can resolve the
input into 212 = 4096 parts. Again, 5 V ÷ 4096 = .0012 V or
1.2 mV per division.
This may seem a bit confusing, therefore we will use a practical example. Consider that the voltage from a
temperature sensor changes as the temperature goes up and down. This electronic thermometer is
being used to measure a temperature range from 1 to 256 degrees Celsius. The 8 bit ADC can resolve the
temperature range into 1 degree divisions. To prove this, consider the following calculation. Remember,
the 8 bit can have 256 divisions. In terms of percent, 1 out of 256 works out to be .39%. Therefore. if we
calculate .39% of 256 we will get 1 degree, which is the finest division of our thermometer. However if we
used a 12 bit ADC we can get a resolution of 1 part in 4096 which works out to be 0.024% of the full scale.
If we calculate 0.024% of 256 degrees, we get about .06 degrees as the finest division on our thermometer.
What would be the finest division on our thermometer if we used a 16 bit ADC?
Many of the interface cards used in high school science labs are 12 bit. The finer the resolution of the chips,
the higher the cost. An 8 bit chip can be purchased for as little as $5.00, while a 12 bit may cost $20.00 or
more..
SPEED
Page 48
UNIT 3 - ANALOG INPUT
The second important characteristic of the Analog to Digital converter is the speed at which the chi
samples of the input signal. This is called the sample rate and is measured in Hertz (samples per s
A sample is taken when the ADC determines the value of a given voltage (waveform) at a particula
in time (this process is also called digitizing). An ADC with a speed of 25 kilohertz can sample an
signal 25 thousand times per second. The sample rate is determined by a characteristic called conv
time. This is the time it takes the ADC to convert the input voltage into the equivalent digital byte
when commanded by the computer. The quicker the conversion time, the more samples that can be
a changing voltage. This is not important if you are sampling the atmospheric pressure every half h
becomes crucial when analyzing a fast changing signal such as a sound wave. An ADC that has a
conversion time of 50 :s (microseconds) has a sample rate ( frequency) of 20,000 hertz. This is ca
by using the following equation:
If you have taken a Physics course this equation will be familiar as the relation between frequency
period. Again we will look at an example to illustrate this characteristic. The following is the actu
of a 12 bit ADC which was used to sense the signal coming from a small magnetic microphone. Th
electrical signal from this microphone varied with the intensity of the sound. The first graph on the
page shows a plot of sound intensity versus the times at which the samples were taken. Only the p
are shown. To draw this graph, 700 samples or ordered pairs (sound intensity and time) were conv
stored. In the second graph the character showing the position of the points is erased and lines join
points are drawn. From the x-axis it can be seen that the total time is 0.03 s. Therefore, to take 700
in 0.03 seconds means that the sample rate must have been at least
Page 49
UNIT 3 - ANALOG INPUT
Some of the commercially available interface board for school use have ADC's rated at 40 kilohertz and
above.
Graph of sound intensity versus time. 700 points are shown. Note that the y-axis is unca
and shows the 'raw' ADC output. (voltages converted to numbers between 0 and 4095)
Page 50
UNIT 3 - ANALOG INPUT
Graph showing sound wave (male voice) with point symbols erased and points
Page 51
UNIT 3 - ANALOG INPUT
A good understanding of the sample rate is critical when using the ADC to capture and display a waveform.
A waveform is the graph of a changing voltage versus time. The ADC will sample the value of the changing
waveform of a signal at various points in time. The computer will store these points and a software
application will graph them to reproduce the original waveform. The software essentially joins the points
with straight lines to display the graph. If the sample rate is too low, not enough points will be taken to
reproduce the waveform accurately. To illustrate this problem we will look at a number of graphs that are
the result of samples taken with a 12 bit ADC. The original waveform is a sine wave produced by an
electronic signal generator. The first diagram shows the original wave, the next diagrams are a sequence
where the number of samples taken are displayed on each graph.
Page 52
UNIT 3 - ANALOG INPUT
It is clear that in the
second graph, where 5
samples are taken, the reproduced waveform looks nothing like the first. As the sample rate increa
resulting wave becomes closer and closer to the original. The last graph shows 50 samples and her
shape of the sine wave is clearly visible. (The first graph of the original wave was reproduced usin
samples!) The problem of having too slow a sample rate which results in an inaccurate representa
original signal is called aliasing.
OTHER FACTORS:
VOLTAGE RANGE
As already stated, most ADC chips have an input voltage range between 0 and 5 volts. If the electr
output of the transducer (sensor) in use varies widely between these values, the signal does not hav
modified. However if the output fluctuates over a tiny range it has to be amplified to be useful. F
example, a typical magnetic microphone has a full scale output of about 0.005 volts (5 millivolts).
calculated previously, an 8 bit ADC can resolve a 5 volt range to about 20 millivolts. If you conne
microphone and yelled and shouted, the ADC would not respond. This is somewhat analogous to a
mass scales that has one digit in its display, 0 - 9 kilograms. If you place a feather on this scale, the
would still read 0. Only when at least 1 kilogram was placed on the scale would the display change
12 bit ADC with a resolution of just over
1 millivolt per division would only change by 4 or
possible range of 4096. The amplifiers used are OP AMPS or operational amplifiers. These are si
cheap, and work well. For the most part they are hidden from the user. The gain (amplification) o
amp is usually set from the software that is used to control the ADC, however some ADC boards u
switches. Sometimes the output of a sensor is above the ADC specification. In this case the OP A
used to 'deamplify' the output to a usable level. The schematic diagram of a typical op amp is show
Page 53
UNIT 3 - ANALOG INPUT
Typical op amp circuit. The amplification factor is determined by the
ratio R2/R1. By changing the value of resistor R2 the degree of
amplification of the input can be controlled.
INPUT
CHANNELS
Many commercially available ADC's have more than one input channel. This means that the ADC board can
be connected to more than one source of signals. The active channel is usually selected by the software.
This process is called multiplexing. The ADC board you will use when you begin the activities provides
3 input channels, although the ADC chip itself has 8.
Page 54
UNIT 3 - ANALOG INPUT
TRANSDUCERS
This is the front end of the apparatus. Any device that generates an electrical signal or modifies on
response to some external stimulus can be used as a transducer or sensor. Generally sensors fall int
categories. Those that produce their own electrical signal and those that modify a supplied voltage
by a changing resistance. Examples of the former are silicon photovoltaic cells, magnetic microph
coils and magnets, voltaic cells, thermocouples, and piezo crystals. Examples of the latter are cadm
sulphide photocells, thermistors, potentiometers, strain gauges, and silicon pressure cells.
The most import characteristic of any sensor is its linearity. That is, how it produces or changes a
in response to the parameter it is measuring. To illustrate this property we can look at an example.
output of a thermistor (temperature dependent resistor) is 0.5 v at 0° C, 0.8 v at 50° C and 0.9v at 1
then the relation between voltage and temperature is clearly not linear. (A graph of these two variab
be curved). Special circuits must be used to modify the electrical output of the transducer so that it
in a linear fashion with respect to the physical phenomenon that causes the change. Most software
assumes this to be the case when sensors are calibrated. If you are fabricating your own sensors,
information on their characteristics is usually given by the manufacturer. For example, if you are b
position sensor using a potentiometer (volume control) be sure to check the specifications as to whe
a log or linear taper. Log taper potentiometers are used in audio equipment and, as the name impli
an exponential relation between resistance and position. You will be using a position sensor in one
activities. To further illustrate the concept of linearity in sensors consider the next graph. The data
produce the plot was taken from a fact sheet supplied with a thermistor from Radio Shack. It is cl
the relation between temperature and resistance is not linear.
Page 55
UNIT 3 - ANALOG INPUT
Refere
nce
has
been made to the word calibrated in the previous section. We need to explore the calibration of sensors
and transducers. Remember a sensor produces or modifies an electrical signal. Let's look at an example. As
mentioned, a thermistor is a device that changes its electrical resistance in response to a temperature
change. If the thermistor is connected to a source of electrical potential (voltage), its output will be a voltage
that changes with temperature. We might place the device in a bath of ice water and have the ADC measure
the voltage as say 0.5 volts. We might then place it in a beaker of boiling water and have the ADC again
measure the voltage as
1.5 volts. This is all well and fine until we tell someone that its a nice day outside
and the temperature is 0.7 volts! Most existing software provides a method to equate the voltage
output of the sensor to the actual physical parameter it is sensing, in this case temperature. This procedure is
called calibration.
In our example the temperature changed from 0 to 100 degrees. The voltage changed from 0.5 to 1.5 volts.
We will plot these points on a graph and join them with a straight line. We do this only if we can be assured
that the output of the sensor is linear. That is, all ordered pairs of temperature and voltage will occur along
the line.
To make use of this information, the software, either programmed by you or "off the shelf", must formulate a
relation between the two variables, temperature and voltage. Because we are dealing with a straight line
relationship, we can use the equations of linear graphs such as.
Page 56
UNIT 3 - ANALOG INPUT
Page 57
UNIT 3 - ANALOG INPUT
The slope of the graph can be calculated:
Taking
an ordered pair and substituting in the slope intercept form of the linear equation, we can calculate the
intercept.
We now
have the final relation between the voltage that the ADC senses and the temperature. It is important to note
that this relation is only valid for our imaginary thermistor. Another sensor would have a different
relationship.
This equation is usually saved as a calibration file by most commercial software and used when the
actual temperature has to be reported. Now we can say that it is a fine day and the temperature is 20 degrees
Celsius.
We have looked into some of the theory of Analog to Digital conversion. You will now proceed to do a
number of activities to further your understanding.
Page 58
UNIT 3 - ANALOG INPUT
You will be using two methods to investigate Analog to Digital conversion. The first uses Quick B
the breadboard. The second uses a commercial package of software and hardware called the Multi
Lab Interface (MPLI) from Vernier Software. This system provides access to the ADC and is trans
the user. This is fine from the perspective of using the ADC as a tool for data acquisition, but does
accessing and controlling the ADC chip directly. Therefore the first two activities in this section w
programming in Quick Basic while the rest will use the commercial software.
The Analog to Digital converter chip can be found on the interface board and is marked AD7870.
Sunset Laboratories manual contains more information on this chip.) This is an 8 input chip, which
that it can accept voltages from 8 different sources. The chip can convert a physical voltage to a nu
:s (microseconds) which means that sample rates over 100,000 per second are possible. The AIB
also set up to take a number of input voltage ranges eg. 0 to 0.5 volts, 0 to 3 volts, 0 to 10 volts etc
Before you begin the activities, you need to understand the steps needed to actually convert an anal
electrical voltage to a number the computer can store, analize and display. These include
•
•
•
•
•
•
Initalizing the chip
Setting the input port
Setting the input voltage range
Starting the conversion
Waiting for the conversion to finish
Reading the stored number
Program comments for the next activity will explain how each of these steps is done.
Page 59
UNIT 3 - ANALOG INPUT
ACTIVITY 11
In this activity we will be using the AIB interface board and Quick Basic to do an Analog to Digital
conversion. Make sure the ribbon cable is plugged into Jumper Port #1 of the AIB board.
Materials:
Advanced Interface Board (installed)
Microcomputer
Ribbon Cable
Bread board
Battery holder and two D cells
Jumper wires
Make sure the computer is turned off before you make any connections. Have
someone double check before you power up the computer.
Connect the circuit as shown in the next diagram.
Turn on the computer, load Quick Basic and type in the following basic program.
OUT 819, 152
OUT 818, 1
Activity 11: Bread board setup
Page 60
UNIT 3 - ANALOG INPUT
OUT 821, 0
OUT 820, 1
N% = (INP(820) + 256 * (INP(821) XOR 8))
PRINT "THE CORRESPONDING DECIMAL NUMBER IS ";N%
END
Make sure the battery holder is connected to the breadboard and then run the program. If everythin
hooked up right, a number around 1200 should be displayed. Write it down. (Actually 1228 would
correspond to an input of 3 volts.)
PROGRAM COMMENTS
OUT 819, 152
From your previous work, you may remember that 819 is the address
the Control Register (or data direction register). This line simply sets
or initializes the ADC chip.
OUT 818, 1
818 is the address of I/O Port C. This port is used to control the
input voltage range. The 1 sets the range at 0 to 10 volts. (See the A
manual for the other ranges.)
OUT 821, 0
821 is the address that controls which of the 8 inputs to the ADC chip
selected. The 0 selects ADC input #1. (The range is 0 to 7 which sel
ADC inputs #1 to #8.)
OUT 820, 1
820 is the address that starts the ADC chip to do a conversion. It doesn't ma
what number you output to 820. any number starts the process.
N% = (INP(820) +
256*(INP(821) XOR 8))
Wow! What is this all about? When used in the output mode, adress
821 and 820 are used to select the ADC input and start the conversion
However, when used in the input mode, they are used to store the
number coming from the ADC chip.
Why are two addresses needed to store the number? Each of these
addresses can store an 8 bit number (1 byte). Therefore the largest
number that can be stored is 255 (11111111 binary = 255 decimal). T
ADC chip is a 12 bit device. The largest number that it can output is
4095 and this cannot be stored in one 8 bit address.
The number is therefore broken into two parts. A low byte and a hig
byte. The low byte is stored in address 820 and the high byte in 821.
To read the number or assign it to a variable ( eg. N%) you have to lo
at both addresses. Don't worry about the rest of the line. If you are
really interested refer to pages 18 and 19 of the AIB manual. Just
remember that whenever you need to program the ADC chip you wil
have to use this line.
Page 61
UNIT 3 - ANALOG INPUT
Now let's find out about the number (N%) that was displayed when you ran the last program. Obviously this
number represents the voltage of the battery that you connected to the breadboard. To calculate that voltage
follow the next example. We will then modify the program and let the computer do the calculation.
Example: Suppose the monitor displayed 1200 as the stored number from the Analog to Digital converter.
Since we have set the input range as 0 - 10 volts and because we are using a 12 bit converter chip, that 10
volt range is divided into 4096 parts. We can use a simple proportion to determine what voltage the number
1200 corresponds to.
Add this modification to the
program just before the last line (END)
V = N%*10 / 4096
PRINT "THIS CORRESPONDS TO A VOLTAGE OF ";V
If you have learned how to round numbers to a certain number of decimal places you could modify these
lines to do so.
Page 62
UNIT 3 - ANALOG INPUT
ACTIVITY 12
In this activity we again will be using the AIB interface board and Quick Basic to do an Analog to
conversion. Make sure the ribbon cable is plugged into Jumper Port #1 of the AIB board.
Materials:
Advanced Interface Board (installed)
Microcomputer
Ribbon Cable
Bread board
R1 - 1 kS resistor
10 turn linear potentiometer, 5kS
Jumper wires
Make sure the computer is turned off before you make any connections. Have
someone double check before you power up the computer.
Connect the circuit as shown in the next diagram.
Turn on the computer, load Quick Basic and type in the following basic program.
OUT 819, 152
OUT 818, 1
OUT 821, 0
Activity 12: Bread board setup
Page 63
UNIT 3 - ANALOG INPUT
DO WHILE INKEY$ <> CHR$(13)
OUT 820, 1
N% = (INP(820) + 256 * (INP(821) XOR 8))
CLS
PRINT "ADC OUTPUT NUMBER = ";N%;
LOOP
END
Run the program. The screen should display a the number returned by the Analog to Digital converter chip
along with the corresponding voltage. Turn the potentiometer shaft. The number and voltage should
change.
-
Rotate the shaft completely clockwise and make a note of the number.
-
Rotate the shaft completely counterclockwise and again note the number.
QUESTIONS:
1.
What was the largest number that was displayed?
2.
The 12 bit ADC has a range from 0 to 4095. Where does the answer to question #1 fit in this
range? Can you expain why? (HINT: The input voltage range was set for 0 - 10 volts. The
potentiometer is connected to #10 of the dip plug which supplies 5 volts)
YOUR TURN
Modify the program to print out the corresponding voltage. Round the output to 1 decimal place.
Page 64
UNIT 3 - ANALOG INPUT
ACTIVITY 13
In this activity we will be using the Vernier MPLI interface box and the MPLI software to control
Analog to Digital converter on the AIB interface board. Make sure the MPLI box is plugged into J
Port #1 of the AIB board.
Materials:
Advanced Interface Board (installed)
MPLI box and software
Microcomputer
Ribbon Cable
Bread board
Voltage cables
R1 - 1 kS resistor
Cadmium sulphide photocell and thermistor
Jumper wires
Make sure the computer is turned off before you make any connections. Have
someone double check before you power up the computer.
Connect one of the ribbon cables to Jumper Port #2 of the AIB interface board. (We will be using
to supply +5 volts to our breadboard.) Connect a set of voltage leads to Input A of the MPLI box
Connect the circuit on the bread board as shown in the next illustration. Make sure the red and
black probes from the MPLI voltage cable are securely clipped to the resistor leads
as shown.
Activity 13: Bread board setup
Page 65
UNIT 3 - ANALOG INPUT
Activity11: Schematic Diagram
Check the
circuit and
boot the computer. The next series of instructions are for the MPLI software. They will be presented in
recipe style. As you become familiar with this software you can probably do most of the future activities
without following the software instructions too closely. For now however, it might be a good idea to check
off each step as you proceed. NOTE: The word select usually means to move to a menu item using the
cursor keys and press enter.
-
Load the MPLI software.
-
When the main menu appears, select O - OTHER OPTIONS.
-
Select I - SELECT INPUTS.
-
Place the cursor on B - INPUT B and press the spacebar turn off input B.
-
Do the same for input C. When finished press enter.
-
Select X - RETURN TO MAIN MENU.
-
Select M - MONITOR INPUT.
-
Press enter to move past he options screen. You will see a screen with a table of time vs
potential. The table should be filling with values under input A
What you are viewing is the voltage across the resistor R1 which changes as the resistance of the photocell
changes. The photocell changes resistance in response to changing light levels. Move your hand over the
photocell. What does the input voltage do?
-
When you have verified that your set-up is working, press enter twice to return to the main menu.
Recall that one of the characteristics of an ADC is the sample rate. The MPLI software has an option to
change the rate.
-
Select O - OTHER OPTIONS.
Page 66
UNIT 3 - ANALOG INPUT
-
Select T - CHANGE SAMPLE RATE.
-
Read the instructions and when you are finished type in 60 as the new sample rate and press
enter.
This will cause the ADC to take 60 samples at 1/120 second each (0.5 s) and average the readings.
averge that is reported to the screen.
-
Select M - MONITOR INPUT.
-
Press enter to bypass the options. Does the table seem to be filling faster?
-
Press enter twice to return to the main menu.
The MPLI software has a real time graphing function that can display the data as it is converted.
-
Select R - GRAPH IN REAL TIME.
-
A graph style option screen will appear. Turn on L - LINE CONNECTING POINTS by
moving to it with the cursor and pressing the spacebar. The option, P - POINT
PROTECTORS should already be on.
-
When finished setting the options press enter.
-
Accept the MINIMUM ANTICIPATED INPUT 0 by pressing enter.
-
Change the MAXIMUM ANTICIPATED INPUT to 5 and press enter.
-
Select NO for STORE DATA IN MEMORY.
-
Move the cursor to the third digit from the right and change it to a 1 (1 minute).
-
Press enter to begin measurements.
Again move your hand over the photocell. Try turning off the room lights.
NOTE: You can interupt data taking at any time by pressing enter.
Repeat this activity by substituting the thermistor for the photocell. You may change the maximu
anticipated input to a lower value (say 2) to use more of the screen. Try holding your finger on the
thermistor. If you have a soldering iron, bring it near the thermistor while collecting a real time gr
(Careful not to burn the circuit wires or yourself.)
QUESTIONS:
1.
You learned about two types of transducers (sensors) in the introductory section of Unit 3.
kind of sensors are the photo cell and the thermistor? Explain.
2.
The resistance of the photocell and the thermistor changes in a non-linear fashion with resp
Page 67
UNIT 3 - ANALOG INPUT
light. Could these sensors be used to make an accurate light meter or electronic thermometer as
connected in this circuit? Explain.
3.
Try using a different source of light on the photo cell such as an incandescent lamp. a flashlight
and/or natural sunlight. Was there any difference in the real time graph? Can you explain why?
Page 68
UNIT 3 - ANALOG INPUT
ACTIVITY 14
In this activity we will be using the Vernier MPLI interface box and the MPLI software. Make su
MPLI box is plugged into Jumper Port #1 of the AIB board.
Materials:
Advanced Interface Board (installed)
MPLI box and software
Microcomputer
Bread board
Voltage cables
R1 - 1 kS resistor
Piezo crystal
Jumper wires
Make sure the computer is turned off before you make any connections. Have
someone double check before you power up the computer.
Connect the circuit as shown in the next illustration. Note: You will not be using the ribbon cable
plug as the circuit does not need any power. Make sure the MPLI voltage cable is plugged into inp
the MPLI box.
Activity 14: Breadboard Setup
Page 69
UNIT 3 - ANALOG INPUT
Activity 12: Schematic diagram
-
Load the
MPLI
software.
-
When the main menu appears, select O - OTHER OPTIONS.
-
Select I - SELECT INPUTS.
-
Place the cursor on B - INPUT B and press the spacebar turn off input B.
-
Do the same for input C. When finished press enter.
-
Select X - RETURN TO MAIN MENU.
-
Select M - MONITOR INPUT.
-
Press enter to move past he options screen. You will see a screen with a table of time vs
potential. The table should be filling with values under input A.
-
Blow or whistle into the piezo crystal. What happens to the values of the voltage?
-
Press enter twice to return to the main menu.
-
Select R - GRAPH IN REAL TIME.
-
A graph style option screen will appear. Turn on L - LINE CONNECTING POINTS by
moving to it with the cursor and pressing the spacebar. The option, P - POINT
PROTECTORS should already be on.
-
When finished setting the options, press enter.
-
Change the MINIMUM ANTICIPATED INPUT to -0.3 and press enter.
-
Change the MAXIMUM ANTICIPATED INPUT to 0.3 and press enter.
-
Select NO for STORE DATA IN MEMORY.
Page 70
UNIT 3 - ANALOG INPUT
-
Move the cursor to the third digit from the right and change it to a 1 (1 minute).
-
Press enter to begin measurements.
-
Again blow or whistle into the piezo crystal. Try tapping it on the desk top. (not too hard!!
-
When you are finished, return to the main menu.
So far you have been taking samples of the output from the crystal at a fairly slow rate compared to
that the ADC is capable of. This software has an oscilloscope function that allows data conversion
high speed. (You may want to find out exactly what an oscilloscope is, if you don't already know.)
-
Select L - OSCILLOSCOPE.
-
If the letters B and/or C are in boxes at the bottom of the screen, press the corresponding ke
those inputs off.
-
Press the up/down cursor key until the value in the A box reads 0.100 (volts/division).
-
Blow or whistle into the piezo crystal. Describe what you see on the screen.
-
Try changing the time base by pressing the left/right cursor keys.
-
When you have finished exploring the oscilloscope, press enter.
-
When the pull down menu appears, select X - EXIT - NOT STORING.
-
Exit the program.
Page 71
UNIT 3 - ANALOG INPUT
QUESTIONS:
1.
Review the two catagories of sensor. What type of sensor is the piezo crystal? Explain.
2.
Remember, transducers (sensors) change a real world phenomenon into a changing voltage that we
can sense. Without doing any research think up two uses for this sensor. That is, at least two
physical parameters that this sensor could be used to detect and measure.
3.
Do some research and find out just where these crystals are used. Hint: the crystal we are refering
to is a quartz crystal.
Page 72
UNIT 3 - ANALOG INPUT
ACTIVITY 15
In this activity we will be using the Vernier MPLI interface box and the MPLI software. Make su
MPLI box is plugged into Jumper Port #1 of the AIB board. Plug the ribbon cable into Jumper por
Materials:
Advanced Interface Board (installed)
MPLI box and software
Microcomputer
Bread board
Ribbon cable
Voltage cables
R1 - 1 kS resistor
10 turn linear potentiometer, 5kS
Jumper wires
Make sure the computer is turned off before you make any connections. Have
someone double check before you power up the computer.
Connect the circuit as shown in the next illustration. Make sure the MPLI voltage cable is plugged
input A on the MPLI box.
Activity 15: Bread board setup
Page 73
UNIT 3 - ANALOG INPUT
Activity 15: Schematic diagram
-
Load
the
MPLI software.
-
When the main menu appears, select O - OTHER OPTIONS.
-
Select I - SELECT INPUTS.
-
Place the cursor on B - INPUT B and press the spacebar turn off input B.
-
Do the same for input C. When finished press enter.
-
Select X - RETURN TO MAIN MENU.
-
Select M - MONITOR INPUT.
-
Press enter to move past he options screen. You will see a screen with a table of time vs
potential. The table should be filling with values under input A.
-
Rotate the shaft of the potentiometer (pot) clockwise. The voltage under A should increase. What
is the minimum and maximum voltage when the pot has been rotated fully both ways?
-
When you are finished, return to the main menu.
In our discussion of sensors, we indicated that sensors can be calibrated to report the information they
display in units other than volts. The MPLI software includes a routine that creates a calibration file. This
file can be saved for later use.
-
Select Z - CALIBRATION.
-
Select A - INPUT A.
-
Select YES when the red warning window appears.
-
Type ROTATION as the new input label. Press enter.
-
Type DEGREES as the new input unit. Press enter.
Page 74
UNIT 3 - ANALOG INPUT
You will now see a Calibrate Input screen. Make sure the shaft of the pot is turned fully counter
clockwise, ie. minimum voltage. The numbers you see flashing under input A is the value being re
ADC. You are going to equate this number with the amount of rotation of the pot.
-
Press enter
-
When the Input Rotation prompt appears, type in 0 and press enter.
-
Rotate the shaft of the pot exactly one full turn clockwise. You can put a pencil mark on
the shaft or use a marked knob to be more accurate.
-
Press enter.
-
When the Input Rotation prompt appears, type in 360 and press enter.
-
When the prompt, Calibration by, appears, type in your initials.
-
Select YES when asked to save the calibration.
-
Type in the letters POT and your initials as the filename. eg. POTJD. Press enter.
-
Select X - RETURN TO MAIN MENU.
Look at the top left corner of the main menu. You should see A: ROTATION.
-
Select M - MONITOR INPUT.
-
Move the cursor to L - LARGE DIGIT DISPLAY and press the spacebar to turn this
option on. Press enter.
-
Turn the shaft. The display should indicate the degree of rotation of the shaft.
You might also want to graph the rotation in real time. Don't forget to set the minimum and maxim
in terms of degrees. (eg. 0 and 3600). See a previous activity if you can't remember how to use the
graphing feature.
QUESTIONS:
1.
Why are we able to calibrate the potentiometer and feel confident that the angle of rotation
is fairly accurate? Hint: Look again at the list of materials for this activity and review the s
on transducers.
2.
Name at least two practical uses for our rotation sensor.
3.
This is a ten turn pot. Would our calibration have been more or less accurate if we had rota
shaft 10 times and typed in 3600 degrees as the rotation for the second calibration point. D
4.
This sensor can be used to measure another physical parameter. What would it be? Discus
procedure for calibrating the sensor for this task and then do the calibration and save the file
Page 75
UNIT 3 - ANALOG INPUT
your calibration.
Page 76
UNIT 3 - ANALOG INPUT
ACTIVITY 16
In this activity we will be using the Vernier MPLI interface box and the MPLI software. Make su
MPLI box is plugged into Jumper Port #1 of the AIB board. Plug the ribbon cable into Jumper por
Materials:
Advanced Interface Board (installed)
MPLI box and software
Microcomputer
Bread board
Ribbon cable
Voltage cables
R1 - 10 kS resistor
R2 - 100 S resistor
Photo transistor
Operational Amplifier (OP AMP) LF351
Jumper wires
Make sure the computer is turned off before you make any connections. Have
someone double check before you power up the computer.
Connect the circuit as shown in the next illustration. Make sure the MPLI voltage cable is plugged
input A on the MPLI box. The ribbon cable will be used to supply ± 12 volts to the op amp.
Activity 16: Bread board setup
Page 77
UNIT 3 - ANALOG INPUT
Activity 16: Schematic diagram
This
circuit is
a little more involved than the previous activities. Make sure the op amp is inserted correctly. The dot
indicates pin#1. Usually this pin is on the bottom left when you can read the lettering on the top of the chip.
When you turn on the computer place your finger on the op amp. If it immediately gets very hot, turn off the
computer, you have something incorrectly wired. Also make sure the tab on the photo transistor is pointed in
the right direction as in the bread board drawing.
Review why the output of sensors needs to be amplified. The photo transistor is being used to measure light
levels. The cadmium sulphide photocell was used for this in activity 13. The photo transistor can change its
output much more rapidly with changes in light intensity.
-
Load the MPLI software.
-
When the main menu appears, select O - OTHER OPTIONS.
-
Select I - SELECT INPUTS.
-
Place the cursor on B - INPUT B and press the spacebar turn off input B.
-
Do the same for input C. When finished, press enter.
-
Select X - RETURN TO MAIN MENU.
-
Select M - MONITOR INPUT.
-
Press enter to move past the options screen. You will see a screen with a table of time vs
potential. The table should be filling with values under input A
Move your hand over the photo transistor. What does the input voltage do?
Page 78
UNIT 3 - ANALOG INPUT
-
Return to the main menu.
-
Select L - OSCILLOSCOPE.
-
If the letters B and/or C are in boxes at the bottom of the screen, press the corresponding ke
those inputs off.
-
If you are in a room with fluorscent lights, make sure they are on. If the room lights are
incandescent, (ie. light bulbs) borrow a fluorescent desk lamp and place it close to the photo
transistor.
-
Press the up/down cursor key until you get a wave like graph on the screen. You may also
change the time base by pressing the left/right cursor keys.
What you are seeing is a graph of light intensity versus time as the fluorescent lights blink on and o
might try to determine how fast they are flashing.
-
When you have finished exploring the oscilloscope, press enter.
-
When the pull down menu appears, select X - EXIT - NOT STORING.
This simple sensor has many uses. You will explore them further by doing a project with the MPL
might want to solder two wires onto the photo transistor so that you can place it further away from
board for sensing. Make sure you insulate each leg of the photo transistor from the other. A photo
is heat sensitive. Place a small pair of pliers or an aligator clip on the lead between the transistor an
soldering iron. This will act as a heat sink and carry dangerous heat away from the transistor. If y
used to soldering, get some help, but do it yourself.
Page 79
UNIT 3 - ANALOG INPUT
QUESTIONS:
1.
Explain why the op amp is needed.
2.
What advantage does the photo transistor offer over the photo cell.
PROJECTS
These two projects can be done using the set up from activity 16 and the oscilloscope function of the MPLI
software. You will need to do some reading as to how to set up the oscilloscope for automatic
triggering . You can read about this in the MPLI manual.
1.
Use the photo transistor sensor and a light bulb to check how long the shutter of a camera stays
open for a particular shutter speed setting. Place the sensor on one side of the camera, open the
back and place the bulb on the other side. Set the oscilloscope to trigger and press the shutter
release. You can read the open time from the x-axis of the oscilloscope display.
2.
Does a light bulb turn on faster than it turns off. Do larger bulbs take longer to turn on and off.
Use the sensor in a dark room to prove your hypothesis.
Page 80
UNIT 4: ANALOG OUTPUT
In the previous section you investigated the theory and practice of Analog to Digital Conversion.
The complementary process is of course called Digital to Analog Conversion. This involves the
conversion of computer stored or generated data into a continuously changing output voltage throu
appropriate interface device. (In actual fact, the computer's output is not continuously changing, bu
in small increments. The smaller the increment, the closer the approximation to a continuous volta
of the most common illustrations of this technology is the compact disk for music or CD. In this d
pits, which have been etched into an aluminum disk, are illuminated by a small diode laser. Depen
the presence or absence of these holes, a 0 or 1 is read by the circuitry. These binary digits or bits
converted by a DAC (Digital to Analog Converter) to a varying voltage which is then amplified an
presented to our ears as music. Other examples include speech synthesis and speed control of elect
motors,
The most important characteristics of the DAC are resolution, conversion speed and output
voltage range.
RESOLUTION
Like its opposite, the ADC (Analog to Digital Converter), resolution is measured in bits. The most
DAC's currently in use are 12 bit chips. You have studied what this means in Section 3, but let's re
here.
212 = 4096
That means that the Digital to Analog converter can resolve the output voltage into 4096 parts, whi
corresponds to a resolution of 0.024%.
CONVERSION SPEED
This is how fast the DAC chip can accept a number (binary word) from the computer and output a
corresponding voltage. Speeds of several hundred thousand conversions per second would be requ
music CDs.
OUTPUT VOLTAGE RANGE
This is the range of voltages that can be generated by the DAC. Typical ranges include 0 to 5 volts
+5 volts. The larger the voltage range, the coarser the resolution for a given ADC chip.
The Sunset AIB board which comes as part of the Vernier interface has two Digital to Analog conv
named DAC1 and DAC2. These are 12 bit chips and as configured, have an output voltage range o
volts. The output is also linear with respect to the input. Therefore we can predict the following:
M
M
M
An input of 0 (decimal) by the computer will cause the output of the DAC to be -5 volts.
An input of 2048 will result in an output voltage of 0 volts.
An input of 4095 will result in an output of +5 volts.
Remember, a 12 bit converter can divide the voltage range into 4096 parts (0 - 4095).
The DACs on the AIB board can be controlled by using the OUT command from Quick Basic. Th
addresses that are accessed are 822 and 823 for DAC1 and 828 and 829 for DAC 2. The DACs ar
Page 81
UNIT 4 - ANALOG OUTPUT
controlled by registers. A register is a temporary memory storage area. The registers on the AIB board are 8
bit registers. In reviewing our binary numbers, 8 bits means 28 = 256. Therefore the largest number an 8 bit
register can store is 255 (0 to 255 is 256 numbers). Because the DACs themselves are 12 bit (4096) devices,
two 8 bit registers must be used to control them. When you send a decimal number to the DAC to cause it to
output a voltage, you must first break the number down into two parts called the Low Byte and the High
Byte. The method for doing this is shown next in an example.
Example:
If you want to input the decimal number 4000 to the DAC to cause it to output a voltage,
you would divide 4000 by 256.
The remainder,
160, is the low byte and the quotient, 15, is the high byte. These bytes are sent to the
DAC using the OUT command. The DAC then outputs the corresponding voltage. You
will use two Quick Basic operators to divide a number into the Low and High Bytes.
These are:
Page 82
MOD which returns the remainder from a division and
\ (Backslash) which is an integer division. (It returns the whole number
quotient without decimals or remainders.)
UNIT 4 - ANALOG OUTPUT
To program the example in Quick Basic, you would use the following.
N = 4000
Lo% = N MOD 256
Hi% = N \ 256
OUT 822, Lo%
OUT 823, Hi%
(Lo% and Hi% are the High and Low Bytes)
This small program would cause DAC 1 to output approximately +4.76 volts.
Page 83
UNIT 4 - ANALOG OUTPUT
In this activity we will be using the AIB interface board. Make sure the ribbon cable is plugged into Jumper
Port #1 of the AIB board. You will also need to borrow a voltmeter from the physics lab. A digital meter
with auto polarity would be best, but, if you don't have access to one, a traditional meter that has a range of at
least 0 to 5 volts DC will do.
Materials:
Advanced Interface Board (installed)
Microcomputer
Bread board
Ribbon cable
Voltmeter
Jumper wires
Make sure the computer is turned off before you make any connections. Have
someone double check before you power up the computer.
Connect the circuit as shown in the next illustration.
Turn on the computer, load Quick Basic and type in the following basic program.
FOR N = 2050 TO 4050 STEP 200
Page 84
UNIT 4 - ANALOG OUTPUT
LO% = N MOD 256
HI% = N \ 256
OUT 822, LO%
OUT 823, HI%
CLS
PRINT "The DAC input number is ";N
PRINT
PRINT "Please copy down the voltmeter reading "
PRINT
PRINT "(Press ENTER to input the next DAC number"
DO WHILE INKEY$ <> CHR$(13)
LOOP
NEXT N
This program will cause the DAC to output 11 voltages. Copy each DAC input number and the
corresponding output voltage in a table similar to the following.
DAC Input (Number) DAC Output (Volts)
2050
2250
2450
2650
2850
3050
3250
3450
3650
3850
4050
When you have finished taking the data, plot a graph of DAC Output (Volts) versus DAC Input
(Number). Make sure the DAC Input is on the horizontal x-axis. Plot a "line of best fit" for the da
-
Calculate the slope for this best fit line.
Using the slope and the ordered pair for a data point on the best fit line, calculate the y inter
Copy to the area below.
NOTE:If you have the Vernier program "Graphical Analysis", you can use it to input your ordere
Page 85
UNIT 4 - ANALOG OUTPUT
pairs and draw a graph. Turn on Point protectors, Regression line and Statistics. The
resulting plot will automatically calculate the slope (m) and y intercept (b). Copy to the area below.
_________ Slope (m)
_________ y intercept (b)
ANALYSIS: The 12 bit DAC has a resolution of:
1.
Compare this with the slope of your graph.
2.
The DAC has a 10 volt output range, -5 volts to 5 volts. What is the significance
of the y intercept that you found for your graph.
3.
What is the shape of your graph. What characteristic of the DAC does this
illustrate.
ACTIVITY 18
NOTE:This activity can only be done if you have at least two two computers with AIB interface boards and
the MPLI box. It will also mean a doubling up of students, however it is a worthwhile exercise.
This is the same activity as #17, however the MPLI is used instead of the voltmeter.
In this activity we will be using the AIB interface board. Make sure the ribbon cable is plugged into Jumper
Port #1 of the AIB board. You will also need to set up a second computer with an AIB board and MPLI.
The MPLI software should be on the second computer.
Materials:
2 Advanced Interface Boards (installed)
MPLI and software
Voltage leads for MPLI
2 Microcomputers
Bread board
Ribbon cable
Jumper wires
Make sure the computer is turned off before you make any connections. Have
someone double check before you power up the computer.
Connect the circuit as shown in the next illustration. Make sure the voltage leads are plugged into Input A of
the MPLI box.
Page 86
UNIT 4 - ANALOG OUTPUT
Activity 18: Bread board setup
Page 87
UNIT 4 - ANALOG OUTPUT
Turn on the first computer, the one connected to the breadboard, load Quick Basic and type in the following
basic program. This is the same program as Activity 17. If you saved it, retreive it and make the small
change to the third print statement.
FOR N = 2050 TO 4050 STEP 200
LO% = N MOD 256
HI% = N \ 256
OUT 822, LO%
OUT 823, HI%
CLS
PRINT "The DAC input number is ";N
PRINT
PRINT "Type this number into the MPLI program"
PRINT
PRINT "(Press ENTER to input the next DAC number"
DO WHILE INKEY$ <> CHR$(13)
LOOP
-
NEXT N
Load the MPLI software into the second computer.
-
When the main menu appears, select O - OTHER OPTIONS.
-
Select I - SELECT INPUTS.
-
Place the cursor on B - INPUT B and press the spacebar turn off input B.
-
Do the same for input C. When finished, press enter.
-
Select X - RETURN TO MAIN MENU.
-
Select K - Monitor input vs keyboard entry.
-
Enter DAC INPUT as new label for horizontal axis.
-
Enter NUMBER as new units.
-
Press enter to select 0 offset.
-
Run the Quick Basic program in the first computer. (This will cause the DAC to output a voltage
close to 0 volts.)
-
Let the MPLI run for a few seconds to let the voltage stabilize then press the spacebar.
-
Type in the number that appears on the screen of the first computer and press enter. (It should be
Page 88
UNIT 4 - ANALOG OUTPUT
2050.)
-
Press the ENTER key on the first computer to input a second number to the DAC. You wi
the number change on the second computer.
-
Again let the MPLI run for a few seconds to let the voltage stabilize then press the spaceba
-
Again type in the number that appears on the screen of the first computer and press enter. (
should read 2250.)
-
Repeat this procedure until you arrive at 4050 on the first computer. When you have finish
entering the last number, press enter, not the space bar. This will stop the input of data and
you to the main menu.
-
Select Plot graph.
-
When the Graph Style Options screen appears, turn ON the following by pressing the
spacebar: P - Point Protectors, R - Regression Line and S - Statistics.
-
Press enter when finished selecting options.
-
When the Graph Scaling Menu appears, select A - Automatic Scaling, Axis Starts
at 0 (horizontal axis). Press enter.
-
For the vertical axis, select C - Manual Scaling
-
For the minimum value to be plotted, enter -5
-
For the maximum value to be plotted, enter 5
A graph should now be displayed. It should be similar to the one shown next. If it is not, repeat th
procedure.
Page 89
UNIT 4 - ANALOG OUTPUT
A
N
A
L
Y
SI
S:
1.
Lo
ok
ne
ar
the
top
of
the
gra
ph
for
the
sta
tist
ics.
The software has calculated the slope (m) and y intercept (b). Copy to the area below.
_________ Slope (m) _________ y intercept (b)
2.
Using the results, answer the three questions in the analysis section of activity 17.
ACTIVITY 19
NOTE:This activity can only be done if you have at least two computers with AIB interface boards and the
MPLI box. It will also mean a doubling up of students, however, again, it is a worthwhile exercise.
In this activity we will be using the AIB interface board. Make sure the ribbon cable is plugged into Jumper
Port #1 of the AIB board. You will also need to set up a second computer with an AIB board and MPLI.
Materials:
2 Advanced Interface Board (installed)
MPLI and software
Voltage leads for MPLI
2 Microcomputers
Bread board
Ribbon cable
Jumper wires
Make sure the computer is turned off before you make any connections. Have
Page 90
UNIT 4 - ANALOG OUTPUT
someone double check before you power up the computer.
NOTE: This activity uses the same setup as in the previous activity. See the
diagram for Activity 16.
Turn on the first computer, the one connected to the breadboard, load Quick Basic and type in the f
basic program.
CLS
PRINT "Press the enter key to quit"
DO WHILE INKEY$ <> CHR$(13)
FOR N = 0 TO 6.28 STEP .01
A = SIN(N) * 2048 + 2048
LO% = A MOD 256
HI% = A \ 256
OUT 822, LO%
OUT 823, HI%
NEXT N
LOOP
END
PROGRAM COMMENTS
A = SIN(N) * 2048 + The
2048
sine function in Quick Basic uses RADIANS. You may have
learned from a math course that 2B radians = 360 degrees. Since 2B
roughly equals 6.28, the FOR...NEXT loop steps N from 0 to 6.28
which gives the full 360 degrees for the sine wave.
The limits of the sine function are +1, 0, and -1. If we input
these numbers into the DAC we will not get a usable output.
Therefore, we will modify the line to get an output that can be
easily graphed. For example:
When N = 0, SIN(N) = 0 and A = 2048. The output of the
DAC will be 0 volts.
When N = 1.57 (roughly B/2), SIN(N) = 1 and A = 4096. Th
output of the DAC will be +5volts.
When N = 3.14 (roughly B), SIN(N) = -1 and A = 0. The
output of the DAC will be -5 volts.
-
Load the MPLI software into the second computer.
Page 91
UNIT 4 - ANALOG OUTPUT
-
Select Oscilloscope (from the main menu).
-
Press B to turn off channel B. If channel C is on, turn it off by pressing C. (If the letters B and C
are below the oscilloscope screen in a box, those inputs are on.)
-
Adjust the horizontal axis (sweep time) to 100 ms/div. Use the left and right arrows (cursor keys).
-
Adjust the vertical axis (sensitivity) to 2.00 volts/div. Use the up/down cursor keys.
-
Run the program in the first computer.
-
You may have to adjust the left/right cursor keys to get a number of waves displayed on the screen.
-
Try replacing the step value (eg. FOR N = 0 TO 6.28 STEP .01) in the basic program with other
values such as .05, 0.1, 0.5, and 1.0.
Page 92
UNIT 4 - ANALOG OUTPUT
ANALYSIS: 1.
What effect did changing the step value have on (i) the shape of the wave an
the numbers of waves produced in a given time. (If that time is one second t
number of waves in that time is called the frequency.) If you would like to
calculate the frequency of the wave see the optional section, extras, after thi
activity.
YOUR TURN
1.
Replace the line A = SIN(N) * 2048 +2047 with the new line
A = ABS(SIN(N)
2048 + 2047 and run the program again with a step value of 0.01. What effect does the AB
(absolute value) function have on the wave form.
2.
Create basic programs so that the waveforms shown in the next three illustrations are produ
a)
Page 93
UNIT 4 - ANALOG OUTPUT
b)
c)
Page 94
UNIT 4 - ANALOG OUTPUT
EXTRA (OPTIONAL)
-
When you have a good trace, press S (single sweep) to freeze the wave. If you don't get a g
waveform, press the spacebar to unfreeze the wave and try again.
-
Type O (for other menu).
-
Select S (Exit - store data).
-
Select Plot graph.
-
The only option to be on is line connecting points (read the instructions at the bottom of th
screen).
-
Press enter when finished.
-
Press enter twice more to see the graph.
-
When finished viewing the graph, press enter.
-
Select E - Examine Data.
-
Your graph will reappear complete with a cross-hair that can be moved with the right/left
cursor keys. Move the cross-hair to the crest of one of the waves on the left.
-
Read and record the time (in the Analysis section) shown in the lower left corner of the grap
should read X = *** ms. (where *** is the time in milliseconds).
-
Move the cross hair to the crest of the next wave on the right. Again read and record the tim
When you have the two times, you can calculate the frequency of the wave. (For a step value of 0.
frequency of 2.4 hertz was obtained on a 12 Mhz 286 computer.)
Subtract the first time from the second to obtain the period of the wave form.
Use the formula f = 1/T to calculate the frequency of the sine wave.
It has been mentioned previously that the DAC is at the heart of the CD music player. Unfortunate
won't be able to duplicate this process, however, we will be able to program the DAC to make som
noises.
ACTIVITY 20
In this activity we will be using the AIB interface board. Make sure the ribbon cable is plugged int
Port #1 of the AIB board.
Microcomputer
Bread board
1000 S resistor
Page 95
UNIT 4 - ANALOG OUTPUT
TIP 29A transistor
Small speaker
Battery holder and 2 D cells
Ribbon cable
Jumper wires
Make sure the computer is turned off before you make any connections. Have
someone double check before you power up the computer.
In this activity you will be using the DAC's output to control the TIP29A transistor. This is the same device
used in activity 7 to control a motor. The transistor, in turn, will control the current flowing to the small
speaker. This setup can be used for a variety of experimental programs. The speaker is connected to the
breadboard's terminals by using alligator clip jumper wires or by soldering wires to the speakers terminals.
Make sure the speaker is in good condition with no holes in the paper cone. Small speakers can be recovered
from a scraped radios or cassette recorders.
Set up the circuit as shown in the next illustration.
Page 96
UNIT 4 - ANALOG OUTPUT
Activity 20: Bread board setup
Page 97
UNIT 4 - ANALOG OUTPUT
Activity 20: Schematic diagram
Page 98
UNIT 4 - ANALOG OUTPUT
Load Quick Basic and type in the following program. This is the modified program from Your Tu
activity 19. If you have a saved copy, load that instead.
CLS
PRINT "Press the enter key to quit"
DO WHILE INKEY$ <> CHR$(13)
FOR N = 0 TO 6.28 STEP .01
A = ABS(SIN(N)) * 2048 + 2047
LO% = A MOD 256
HI% = A \ 256
OUT 822, LO%
OUT 823, HI%
NEXT N
LOOP
END
Run the program. You should hear some output from the speaker.
Now change the step value (eg. FOR N = 0 TO 6.28 STEP .01) in the basic program with the valu
.05, 0.1, 0.5, and 1.0. Run the program each time and note the difference in the sound coming from
speaker.
Question:
What happens to the pitch of the sound (frequency) coming from the speaker as you make t
value larger. Explain why this happens.
Now try the following programs to create some sound effects. These programs essentially turn the
and therefore the speaker, on and off. This corresponds to a "square wave" and causes the speaker
continuous frequency. Each program will have a small difference from the previous one.
There is no need to type the full program, just change the lines indicated.
Page 99
UNIT 4 - ANALOG OUTPUT
1.
CLS
PRINT "Press the enter key to quit"
LO% = 4000 MOD 256
HI% = 4000 \ 256
LOO% = 2048 MOD 256
HII% = 2048 \ 256
DO WHILE INKEY$ <> CHR$(13)
OUT 822, LO%
OUT 823, HI%
OUT 822, LOO%
OUT 823, HII%
LOOP
END
2.
CLS
PRINT "Press the enter key to quit"
LO% = 4000 MOD 256
HI% = 4000 \ 256
LOO% = 2048 MOD 256
HII% = 2048 \ 256
DO WHILE INKEY$ <> CHR$(13)
OUT 822, LO%
OUT 823, HI%
OUT 822, LOO%
OUT 823, HII%
FOR T = 1 TO 50: NEXT T
LOOP
END
Page 100
UNIT 4 - ANALOG OUTPUT
3.
CLS
PRINT "Press the enter key to quit"
LO% = 4000 MOD 256
HI% = 4000 \ 256
LOO% = 2048 MOD 256
HII% = 2048 \ 256
DO WHILE INKEY$ <> CHR$(13)
FOR X = 1 TO 200
OUT 822, LO%
OUT 823, HI%
OUT 822, LOO%
OUT 823, HII%
FOR T = 1 TO X: NEXT T
NEXT X
LOOP
END
4.
CLS
PRINT "Press the enter key to quit"
LO% = 4000 MOD 256
HI% = 4000 \ 256
LOO% = 2048 MOD 256
HII% = 2048 \ 256
DO WHILE INKEY$ <> CHR$(13)
FOR X = 1 TO 50
FOR Y = 1 TO 5
OUT 822, LO%
OUT 823, HI%
OUT 822, LOO%
OUT 823, HII%
FOR T = 1 TO X: NEXT T
NEXT Y
NEXT X
LOOP
END
5.
CLS
PRINT "Press the enter key to quit"
LO% = 4000 MOD 256 : HI% = 4000 \ 256
LOO% = 2048 MOD 256 : HII% = 2048 \ 256
DO WHILE INKEY$ <> CHR$(13)
Page 101
UNIT 4 - ANALOG OUTPUT
FOR X = 50 TO 1 STEP -1
FOR Y = 1 TO 5
OUT 822, LO%
OUT 823, HI%
OUT 822, LOO%
OUT 823, HII%
FOR T = 1 TO X: NEXT T
NEXT Y
NEXT X
LOOP
END
CLS
PRINT "Press the enter key to quit"
6.
LO% = 4000 MOD 256 : HI% = 4000 \ 256
LOO% = 2048 MOD 256 : HII% = 2048 \ 256
DO WHILE INKEY$ <> CHR$(13)
FOR Z = 60 TO 20 STEP -10
FOR Y = Z TO 1 STEP -1
FOR X = 1 TO 5
OUT 822, LO%
OUT 823, HI%
OUT 822, LOO%
OUT 823, HII%
FOR T = 1 TO Y: NEXT T
NEXT X
NEXT Y
NEXT Z
LOOP
END
YOUR TURN
1.
Modify program #4 & #5 to replace the upper limits in the FOR...NEXT loops (50 and 5) with
RANDOM NUMBER generators which generate numbers between 1 and 5 and 1 and 50.
2.
Create a program to emulate a police siren or a fire siren or the "RED ALERT" siren on the USS
Enterprise.
Page 102
UNIT 4 - ANALOG OUTPUT
It has been mentioned previously in this section that the DAC's output can be used to control the sp
motors and the intensity of lights. The last two activities in this module will demonstrate this funct
ACTIVITY 21
In this activity we will be using the AIB interface board. Make sure the ribbon cable is plugged int
Port #1 of the AIB board.
Microcomputer
Bread board
1000 S resistor
TIP 29A transistor
Small Lamp
Battery holder and 2 D cells
Ribbon cable
Jumper wires
Make sure the computer is turned off before you make any connections. Have
someone double check before you power up the computer.
You will use the DAC to output a current through the 1000S resistor. This resistor is connected to
terminal of the transistor. The small current from the DAC causes the transistor to conduct a larger
from the battery through the lamp. If the current from the DAC increases the current to the lamp w
increase and it will become brighter. (The DAC can provide only 5 milliamperes of current.
The lamp will draw about 300 milliamperes, therefore the battery and transistor are required to sup
control this current.)
Connect the circuit as shown in the next illustration.
Page 103
UNIT 4 - ANALOG OUTPUT
Activity 21: Bread board setup
Activity 21: Schematic diagram
Page 104
UNIT 4 - ANALOG OUTPUT
Load Quick Basic and type in the following program.
CLS
PRINT "Press the enter key to quit"
DO WHILE INKEY$ <> CHR$(13)
FOR N = 3000 TO 4000 STEP 100
LO% = N MOD 256
HI% = N \ 256
OUT 822, LO%
OUT 823, HI%
FOR T = 1 TO 5000: NEXT T
NEXT N
LOOP
END
Before you run the program, try to predict what you will see.
YOUR TURN
1.
Modify the program so that the lamp goes from bright to dim in 10 brightness levels.
2.
Create a program to vary the brightness of the lamp by five steps by pressing the space bar.
Page 105
UNIT 4 - ANALOG OUTPUT
ACTIVITY 22
In this activity we will be using the AIB interface board. Make sure the ribbon cable is plugged into Jumper
Port #1 of the AIB board.
Microcomputer
Bread board
1000 S resistor
TIP 29A transistor
Small DC motor
Battery holder and 2 D cells
Ribbon cable
Jumper wires
Make sure the computer is turned off before you make any connections. Have
someone double check before you power up the computer.
This is the same circuit as in activity 21. Simply substitute a the small motor for the lamp.
Load Quick Basic. To make sure your circuit is working you can use the program from activity 19. Now,
try the following for a change of pace!!
Activity 22: Bread board setup
CLS
Page 106
UNIT 4 - ANALOG OUTPUT
SCREEN 12
VIEW SCREEN (95, 320)-(539, 330), 0
LOCATE 4, 1
S = 30
PRINT SPC(S); " F1 - IMPULSE"
PRINT
PRINT SPC(S); " F2 - WARP 1"
PRINT
PRINT SPC(S); " F3 - WARP 3"
PRINT
PRINT SPC(S); " F4 - WARP 5"
PRINT
PRINT SPC(S); " F5 - STOP ENGINES"
PRINT
PRINT SPC(S); "Press enter to stop program"
LOCATE 20, 1
PRINT SPC(12); "IMPULSE"; SPC(10); "WARP1"; SPC(10); "WA
PC(10); "WARP5"
DO WHILE INKEY$ <> CHR$(13)
ON KEY(1) GOSUB IMPULSE
ON KEY(2) GOSUB WARP1
ON KEY(3) GOSUB WARP3
ON KEY(4) GOSUB WARP5
ON KEY(5) GOSUB ALLSTOP
KEY(1) ON
KEY(2) ON
KEY(3) ON
KEY(4) ON
KEY(5) ON
LO% = N MOD 256
HI% = N \ 256
OUT 822, LO%
OUT 823, HI%
LOOP
END
IMPULSE:
N = 3300
CLS 1
LINE (100, 320)-(150, 330), 2, BF
RETURN
WARP1:
N = 3600
CLS 1
LINE (100, 320)-(270, 330), 14, BF
Page 107
UNIT 4 - ANALOG OUTPUT
RETURN
WARP3:
N = 3800
CLS 1
LINE (100, 320)-(390, 330), 14, BF
RETURN
WARP5:
N = 4095
CLS 1
LINE (100, 320)-(510, 330), 4, BF
RETURN
ALLSTOP:
N = 2048
CLS 1
RETURN
Page 108