PE Kit Tools: Measure Resistance and Capacitance
Propeller microcontroller applications that need to measure resistors or capacitors can use the RC Time object and a resistor capacitor (RC) circuit.и Since there’s a myriad of resistive and capacitive sensors that respond to physical properties such as light, rotation, humidity and force (to name a few), the simple, inexpensive circuits and the easy-to-use RC Time object featured in this PE Kit Tools article open up a world of measurement possibilities.
Full PDF & source code: PE Kit Tools - Measure Resistance and Capacitance.zip и
More info: PE Kit Labs, Tools, and Applications
Platform: Propeller Education Kit
In this Tool Chapter:
иииииииии RC Time Parts and Circuit
иииииииии How RC Time Measurements Work
иииииииии Simple Test Code
иииииииии RC Time object features
oииии Timeout Setting
oииии Charge Time Setting
oииии Sequential vs. parallel measurements
oииии Establishing Sampling Rates
иииииииии More PE Kit Sensor Examples
oииии Ambient and Infrared Phototransistors
oииии Direct Sunlight with LEDs
oииии Proximate Flame with an Infrared LED
иииииииии Application Example: RC Resistance Meter
иииииииии Application Example: 200 kHz Sampling Rate
RC Time Parts and Circuit
One of the most common variable resistance sensors is the potentiometer, a.k.a “pot”.и As the knob on the pot is turned, its resistance varies.и The Propeller microcontroller can use the RC Time object to measure the variable resistors (labeled POT) in Figure 1, which can in turn give the application accurate information about how far each potentiometer knob has been turned.и The potentiometer can also be replaced by any number of other resistive sensors.и For example, if the pot is replaced with a photoresistor, the circuit can instead be used to measure light intensity.и If the pot is replaced with a fixed resistor, variable capacitor sensors that measure pressure or humidity can be measured.и The examples in this chapter will use a couple of potentiometers to explore the RC Time object’s features, and then demonstrate how other PE Kit parts like phototransistors and LEDs can be used with RC Time to measure a variety of physical properties.и
Pииииии Build the circuits shown in Figure 1.
How RC Time Measurements Work
The RC Time object can be used to determine a variable resistor value by treating the capacitor in the circuit like a small battery.и It charges up this capacitor (left side of Figure 2) by sending an output-high signal to the I/O pin.и Then, it changes the pin to input and measures the time it takes the capacitor’s voltage to decay as it looses its charge through the variable resistor (right side of Figure 2).и The decay measurement time (Dt) starts at 3.3 V, and stops when the voltage to decays below the Propeller I/O pin’s 1.65 V logic threshold.и For larger resistances, it takes more time for the capacitor to lose its charge.и For smaller the resistances, it takes less time for the capacitor to lose its charge.
The equation that describes the time it takes for the voltage to decay from 3.3 to 1.65 V is:
Δt = 0.693 О C О R
With a little algebra, the terms can be rearranged to solve for the value of R.и This is great if the project is to make a simple resistance meter.и On the other hand, if the application needs a sensor measurement, it may just scale the time measurement and compare it to some benchmark values.и Other sensor applications need to compare the sensor measurement to complex equations, and others still use points from a graph in the sensors datasheet.и The application can then check to find out which value in the list is closest to the measured value and so determine the value of the property the sensor measures.
Simple Test Code
The RC Time object has lots of tools for measuring RC voltage growth and decay in circuits.и In its simplest form, code that measures the circuits in Figure 1 resembles PBASIC RCTIME commands for the Parallax BASIC Stamp microcontroller.и After declaring the RC Time object, the code passes the pin, voltage state of the circuit at the start of the measurement, and the address of the variable where the Time method should store the result.и The RC Time object uses these parameters to charge the circuit, measure the growth/decay, and store the results in the appointed variables: tGrowth in the first method call, and tDecay in the second.
и 'Test Simple RCTIME.spin
иии rc : "RC Time"
и PUB Go | tGrowth, tDecay
иии rc.time(27, 0, @tGrowth)
иии rc.time(17, 1, @tDecay)
The “PE Kit Tools – Measure Resistance and Capacitance.zip” file has both Spin and ASM versions of the RC Time object along with several test code examples.и The first code example to try is “Test Simple RCTIME.spin”.и This object use the PST Debug LITE object to display the measurements in the Parallax Serial Terminal.и For a primer on how to use this object to display variable names and their values, see Debug LITE for the Parallax Serial Terminal topic.
Pииииии Download and unzip “PE Kit Tools – Measure Resistance or Capacitance.zip”.
Pииииии Open “Test Simple RCTIME.spin” with the Propeller Tool software.
Pииииии Open the Parallax Serial Terminal, and set the COM Port to the Propeller chip’s programming port.и (You can use F7 in the Propeller Tool to find out which port that is.)
Pииииии Set the Parallax Serial Terminal’s Baud Rate to 115200.
Pииииии In the Propeller Tool, load the Test Simple RCTIME object into the Propeller chip with F11
Pииииии Wait just long enough for the Propeller Tool software’s Communication window to report “Loading…” before clicking the Parallax Serial Terminal’s Enable button.и The Parallax Serial Terminal will wait for the Propeller Tool software to finish loading code into the Propeller chip before it connects to the COM port.
Figure 3 shows an example of how “Test Simple RCTIME.spin” displays decay and growth time measurements in the Parallax Serial Terminal.и These growth and decay times are in terms of 12.5 ns units.и That’s because this program has the Propeller chip’s system clock set to 80 MHz, and if the clock is ticking at 80 million times per second, the time between each tick is 12.5 ns.и
The range of decay times should be about ten times the range of growth times since the decay circuit has a capacitor that’s ten times as large as the one in the growth circuit.и Since the decay circuit’s capacitor can store ten times the charge, the voltage will take ten times as long to decay through the same size resistor.и This can be verified by setting the potentiometers to roughly the same position.и The tDecay value should be about ten times the tGrowth value.и There will be some variation, especially since the threshold voltage is not likely to be exactly 1.65 V.и For example, if the threshold voltage instead 1.63 V, the decay time will be longer and the growth time will be shorter.и Reason being, the decay will have to drop from 3.3 V down to 1.63 V, which is a 1.67 V decay.и Meanwhile, measuring the growth will only be a 1.63 V voltage rise, and a different growth time measurement.
Post Edited (Andy Lindsay (Parallax)) : 8/24/2010 6:08:42 PM GMT