ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 12.06.2025
Просмотров: 1673
Скачиваний: 0
Page 148 · Basic Analog and Digital
Figure 8-7 shows the output under low light conditions.
Figure 8-7
Sample Debug
Terminal
Output for Low
Light
Figure 8-8 shows a sample of the output with the lights out. Overflow occurred. The discharge time was more than 65,536 microseconds. As a result, the variable reset to zero because the light variable also overflowed. Since both dischargeTime and light reset to zero, the variable sound reached its maximum. This is because sound was programmed as: sound = (65535 – light)/40. Light was reset to zero due to overflow, so sound became (65535 -–0)/40 = 1638.
Chapter 8: Light Meter Gizmo with R/C Time Constants Page 149
Figure 8-8
Sample Debug
Terminal Output
in After
Somebody
Turned Out the
Lights
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. If you are dealing with low light conditions, use a 0.1 µF capacitor instead.
The reason for using different capacitors is because the range of resistances for the photoresistor varies for different ranges of light levels. Under lower lighting, the photoresistor has a much higher range of resistance values than it does in a well-lit or full sun area.
As discussed earlier, the discharge time depends on the RC time constant, R x C. If R tends toward a relatively high range of resistances, using a smaller value of C will bring the value of R multiplied by C back down. Likewise, if R is low, using a larger value of C helps bring the value of RC back up.
Page 150 · Basic Analog and Digital
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
VP15 = Vdd × e R×C
Since we'll use PBASIC to make the BASIC Stamp tell us the measured amount of time, t, we have the following information shown in Table 8-1
Table 8-1: Known Values at the Instant VP15 Crosses the
Threshold Voltage
Values |
Comments |
||
Vdd = 5.0 volts |
The initial condition of the voltage at P15. |
||
VP15 = 1.4 volts |
The final condition of the voltage at P15. |
||
e § 2.718 |
The value of e is a constant found in many |
||
algebra books, physics texts, etc. |
|||
C = Can solve for |
If the value of resistance (R) is known, then the |
||
capacitance (C) can be determined. |
|||
t = Known |
The BASIC Stamp counts the time for us in 2 |
||
microsecond increments. |
|||
R = Can solve for |
If the value of capacitance (C) is known, then |
||
resistance (R) can be determined. |
|||
Algebra can be applied to the exponential decay equation to solve for R or C. First, take the natural log of both sides of the equation. It eliminates the e term.
− t |
t |
||||||||
ln(V )= ln V |
× e |
R×C |
ln(V |
)= ln(V )− |
|||||
R × C |
|||||||||
P15 |
dd |
P15 |
dd |
||||||
Rearranging terms yields:
t |
= ln(Vdd )− ln(VP15 ) |
|
R × C |
||
Chapter 8: Light Meter Gizmo with R/C Time Constants Page 151
Using properties of logarithms, this simplifies to:
t |
V |
||
= ln |
dd |
||
R C |
|||
V |
|||
P15 |
|||
Rearranging again gives us an equality in terms of R and C and t:
R C = |
t |
|||
V |
||||
ln |
dd |
|||
V |
||||
P15 |
If R is the unknown value, divide both sides by C. If C is the unknown value, divide both sides by R. The resulting two equations are useful for determining an unknown R if C is known, or visa versa.
R = |
t |
or |
C = |
t |
|||||
V |
V |
||||||||
C ln |
dd |
R ln |
dd |
||||||
V |
V |
||||||||
P15 |
P15 |
Try a few different resistor and capacitor combinations from the Analog and Digital Parts Kit. Remember that capacitor values can vary as much as 20% from their nominal (named) value. This will in turn cause error in your measured values. However, if a resistor with a very low tolerance, such as 1% is available, the measurements of capacitance can be pretty accurate. Once the capacitor has been calibrated, then it's possible to take accurate resistance measurements with the RC circuit as well
Page 152 · Basic Analog and Digital
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 |
||
threshold |
variety of physical quantities. An ______________ circuit can be used in |
|
conjunction with a BASIC Stamp binary input pint to measure resistance |
||
capacitance |
or capacitance. |
|
The ______________ is charged to 5-volts, then it is allowed to discharge, |
||
capacitor |
||
and the time it takes to get from 5-volts to the ______________ voltage of |
||
RC |
a BASIC Stamp input pin is measured. The equation for ______________ |
|
decay can then be used to determine a value of resistance or capacitance if |
||
exponential |
the other quantity is known. |
|
An RC circuit where the resistance varies can be calibrated to a certain |
||
discharge |
||
range of ______________ times by changing the value of the capacitor. |
||
This method can be used because the resistance multiplied by the |
||
______________ is logarithmically related to the rate of decay. |
Chapter 8: Light Meter Gizmo with R/C Time Constants Page 153
Questions
1.Given the circuit in Figure 8.3, how long will it take to discharge if the value of the photoresistor is 47 k ?
2.For the discharge time in Question 1, would you expect any of the variables in Program Listing 8.1 to overflow? If so, which ones? Explain your answer.
3.If the light conditions are so low that none of the capacitors in the kit work any more, a store bought capacitor might be the answer. What values of capacitor might you try to find? Explain your answer.
4.For better resolution in the higher end of the light level scale, you can also reduce the value of a in Program 8.1. How would that affect your Debug Terminal readout and the sound of the piezoelectric speaker?
Challenge!
1.Design a circuit which has two photoresistors that are monitored. Assume that you will be displaying the light intensity information on the Debug Terminal, and that you won't be using a piezoelectric speaker.
2.Program the BASIC Stamp to monitor the light level at both of the photoresistors and display the information using the Debug Terminal.
3.Try holding different colored papers in front of the photoresistors; black and white will work best. Write a program to distinguish which photoresistor senses white and which sees black.
4.Make sure your program from Challenge #3 is not affected by the ambient light level in the room. Hint: You will need to compare the RELATIVE intensities of the light measured by both photoresistors instead of comparing them to some fixed number that was experimentally determined using a fixed value of ambient light.
Page 154 · Basic Analog and Digital
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 in this series of experiments can be mixed and matched to actually design an electronic device. It also demonstrates that capacitors are not the exact value they are stated to be due to tolerances. You now know how to calculate the capacitor value.
How can I apply this?
While learning all this, we've covered a number of circuit designs and a wide variety of programming techniques. We've also gained some first hand experience with analog phenomenon. We've also covered how to electronically interface, process, and in general, do things with a digital device, the BASIC Stamp microcontroller. Below is a list of key concepts that we've worked with in these experiments.
Chapter #1: Serial and parallel data, and synchronous and asynchronous communication. Chapter #2: The comparator, the buffer, and threshold voltage.
Chapter #3: Analog to digital conversion, voltage dividers, and normalized voltage measurements.
Chapter #4: Digital to analog conversion, the resistive ladder network, and sound frequency and volume.
Chapter #5: The oscilloscope and time varying signals.
Chapter #6: The 555 timer, frequency and measuring frequency signals.
Chapter #7: The optical couple and pulse width management for D/A conversion. Chapter #8: Building an electronic gizmo - a light meter, and A/D conversion using RC time constants.
These eight experiments provide a first exposure to analyzing a variety of analog phenomenon, the basics of electric circuits, and the essentials of digitally processing information about analog measurements using a digital electronic device.
If you are an electronics hobbyist, hopefully there were a few items to add to your bag of electronic design tricks. If you are a high school or college student continuing on to an electrical technical or engineering field, you will undoubtedly revisit many of the concepts covered here in much grater detail.
Chapter 8: Light Meter Gizmo with R/C Time Constants Page 155
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 examples of these are digital keypads, liquid crystal displays and servo motors.
If you have completed this series of experiments as well as the What’s a Microcontroller? series, connecting the parts from each will be a relatively simple matter. In addition, imagine what you can design and build using a digital keypad, a liquid crystal display, and the analog interface concepts learned. A few examples: build an interface for a factory automation process, a temperature and altitude sensor for your rocket system, or a weather monitoring station. Good luck!
Appendix A: Parts Listing and Sources Page 157
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 through Parallax. To use this curriculum you need three items: (1) a BASIC Stamp 2 module (available alone, or in the Board of Education - Full Kit); (2) a Board of Education (available alone or in a Board of Education Full Kit); and 3) the Analog and Digital Parts Kit. The typical setup consists of the Board of Education Full Kit and the Analog and Digital Parts Kit.
Board of Education Kits
The BASIC Stamp 2 (BS2-IC) is available separately or in the Board of Education Full Kit. If you already have a BS2-IC module, then purchase the Board of Education Kit. Individual pieces may also be ordered using the Parallax stock codes shown below.
Board of Education Full Kit (#28102)
Parallax Code# |
Description |
Quantity |
28150 |
Board of Education |
1 |
800-00016 |
Jumper wires |
10 |
BS2-IC |
BASIC Stamp 2 module |
1 |
800-00003 |
Serial cable |
1 |