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 · '... · OBJ ··· 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