Shop OBEX P1 Docs P2 Docs Learn Events
PE Kit Tools: Measure Resistance and Capacitance — Parallax Forums

PE Kit Tools: Measure Resistance and Capacitance

edited 2009-03-21 04:13 in Propeller 1
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.

attachment.php?attachmentid=67365

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.

attachment.php?attachmentid=67366


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.
·
attachment.php?attachmentid=73441

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.·
·
attachment.php?attachmentid=67367
·
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.
·
attachment.php?attachmentid=73442


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Andy Lindsay

Education Department
Parallax, Inc.

Post Edited (Andy Lindsay (Parallax)) : 8/24/2010 6:08:42 PM GMT

Comments

  • edited 2009-03-13 04:49
    RC Time Object Features

    The RC Time object has a number of built-in features to make measurements simple and easy.· For example, it has a built-in timeout that stops waiting for the decay (or growth) to cross the Propeller I/O pin’s logic threshold after 0.01 seconds.· It also has a charge time of 0.1 ms before it starts the measurement.· The RC Time object has methods that allow you to adjust these values.

    The RC Time object also defaults to taking measurements sequentially.· In this mode, the cog that calls the object’s Time method has to wait for the measurement to complete.· There is also a method for configuring the RC Time object to take its measurements in parallel, without halting execution in the cog that called its Time method.· Additionially, the RC Time object has Start and Stop methods for taking repeated measurements and storing the latest measurements in certain variables and specified intervals.

    Timeout Setting

    Let’s say a circuit will decay under most circumstances, but not always.· What happens then?· Some objects that measure RC decay will wait indefinitely.· In contrast, the RC Time object has a configurable timeout that defaults to 10 ms to prevent this problem.· This configurable timeout also prevents the application from having to wait an unnecessarily long time for circuits that are responding slowly due to a large resistance or capacitance value.· In many cases, a slow RC response indicates a throw-away measurement anyhow.· A photoresistor in complete darkness is an example.· It can really slow down an RC measurement due to large resistance values, but maybe the application only cares that it’s beyond a certain level of darkness.· At that point, the application might chose to hibernate until morning, or maybe turn on the lights!

    Both the RC Time and RC Time.ASM objects have default timeout values of 10 ms.· For RC Time.ASM, the timeout value is just as accurate as the decay measurement itself, good to the nearest clock tick.· This is possible because RC Time.ASM uses assembly language to take the growth and decay measurements; whereas, RC Time takes its decay measurements in Spin.· Since Spin is an interpreted language, it does not provide the same degree of control over timing that assembly language does.· Keep in mind that both objects’ growth and decay measurements are good to the nearest clock tick.· The difference between the two objects is that the Spin language RC Time object’s timeout value is approximate; whereas, assembly language RC Time.ASM’s timeout value is exact.

    Changing either object’s timeout value involves a simple method call to its TimeOut method.· The examples below impose a 0.5 ms timeout on RC measurements for the Figure 1 circuits by passing clkfreq/2000 to the RC Time object’s TimeOut method.· This value is the number of clock ticks in half a millisecond, because clkfreq is the number of clock ticks in one second, and dividing 2000 into this value gives us the number of clock ticks in half a millisecond.· It’s equivalent to (clkfrreq/1000)/2.·

    attachment.php?attachmentid=73443

    Figure 4 shows how the Spin RC Time object’s tDecay timeout is approximate while the assembly language version is accurate to the clock tick.· The code above configures both versions of the object to time out at 40_000 clock ticks (0.5 ms at 80 MHz).· Keep in mind that for most applications, the actual decay measurement is the important part, and that both objects will return the exact same value, provided when the measurement is below the timeout.·

    attachment.php?attachmentid=67368


    P······ Try both “Test RCTIME Timeout.spin” and “Test RCTIME Timeout.ASM.spin”objects, and verify that they take the same measurements when the timeout values are below the 0.5 ms threshold.·
    P······ Set the potentiometer connected to P17 so that it causes each object to time out and verify that the assembly language version of the object can enforce the timeout more precisely.·

    Charge Time Setting

    The RC Time object’s default charge time is 0.1 ms, which works fine for the small RC values we are using in this chapter.· However, larger capacitors may take longer to charge.· To adjust the charge time, simply pass the object’s ChargeTime method the number of clock ticks to wait and charge.· For example, if you want to change the charge time from the default 0.1 ms to 5 ms, use this method call:
    ·
    · Rc.ChargeTime(clkfreq/200)

    Sequential vs. Parallel RC Measurements

    The RC Time objects default to sequential measurements.· In sequential mode, the RC Time object does not return from the Time method call until either the measurement is complete or timeout is reached.·· Figure 5 shows what happens when the RC Time object’s Time method gets called twice in immediate succession like it does in “Test Simple RCTIME.spin”.· On the left, the first measurement takes just over 1 ms to complete, and the second measurement does not start until the first measurement finishes.· On the right, the first measurement takes less than 250 µs to complete, so the application moves on to the second measurement more quickly.·

    attachment.php?attachmentid=67369

    The RC Time object can be configured to launch multiple measurements in parallel.· For parallel measurements, a copy of the RC Time object has to be created for each simultaneous measurement, and then each copy of the object has to be configured to return immediately after starting its RC measurement.·

    Here is an excerpt from “Test Parallel RCTIME.spin”.· It declares two copies of the RC Time object and then configures each copy for taking parallel measurements by passing rc#PARALLEL to its SetMode method.·

    OBJ······························
    · rc[noparse][[/noparse]2] : "RC Time"········
    ·
    PUB Go | tGrowth, tdecay, i········
    · repeat i from 0 to 1···········
    ··· rc[noparse][[/noparse]i].SetMode(rc#PARALLEL)
    · '...
    · rc[noparse][[/noparse]1].Time(27, 0, @tGrowth)
    ··rc[noparse][[/noparse]0].Time(17, 1, @tdecay)···
    · 'Code here can work on other tasks while
    · 'waiting for the measurements complete...·······························

    With two copies of the RC Time object configured to take parallel measurements, Figure 6 shows how the second measurement starts immediately after the first one does, so the duration of the first measurement no longer affects when the second measurement starts.· This approach can be useful for making sure measurements start at approximately the same time, and it can also be useful for saving time by taking multiple measurements in parallel.· The drawback is that each measurement launches a separate cog for the duration of the measurement.· This drawback is not severe because the RC Time object also shuts down a given cog immediately after the measurement is complete.· Keep in mind that if your application launches four simultaneous RC decay measurements, there will four cogs occupied with simultaneous measurements for a brief period of time.

    attachment.php?attachmentid=67370

    If you have an oscilloscope:

    P······ Examine how the duration of the first measurement can delay the start of the second measurement in “Test Simple RCTIME.spin” while the second measurement in “Test Parallel RCTIME.Spin” starts a brief, fixed time after the first measurement starts.·

    attachment.php?attachmentid=73444

    Establishing Sampling Rates

    The RC Time object also has Start and Stop methods.· The Start method makes it possible to make one or more copies of the RC Time object take growth/decay measurements at one or more different rates.· When the application doesn’t need any more measurements, the Stop method can be used to shut down the code and make it available for other tasks.

    The RC Time object’s Start method requires three additional parameters, charge time, timeout, and sample interval.· The sample interval is the time between measurements, and it establishes the sampling rate.· In the example code below, rc[noparse][[/noparse]0] is configured with a 0.1 ms charge time, a 1.0 ms timeout, and a 2 ms sample interval (clkfreq/500).· rc[noparse][[/noparse]1] also has a 0.1 ms charge time, but its timeout is 0.5 ms and its sample interval is 1 ms (clkfreq/1000).
    ·
    · ...
    ·
    OBJ
    ·
    · rc[noparse][[/noparse]2]····· : "RC Time"···················· ' RC Time.ASM is also an option
    · debug····· : "PST Debug LITE"············· ' Variable & I/O display tool
    · ...
    ··············· ·····························
    PUB Go | tGrowth, tdecay
    ·
    · debug.Start(115_200, debug#LIST)·········· ' 115.2 kbps, list display
    · debug.Title(String("Time Measurements", debug#NL, "(units = 12.5 ns)"))
    · debug.TitleAppend(String(debug#NL, "
    ", debug#NL))
    ·
    · ' Set up cogs to repeatedly take measurements and update tDecay & tGrowth.
    · rc[noparse][[/noparse]1].start(27, 0, clkfreq/1_0000, clkfreq/2000, clkfreq/1000, @tGrowth)
    · rc[noparse][[/noparse]0].start(17, 1, clkfreq/1_0000, clkfreq/1000, clkfreq/500, @tDecay)
    ·
    · repeat
    ··· debug.VarsHome(@tDecay, String("| tDecay, tGrowth"))
    ··· waitcnt(clkfreq/10 + cnt)···············

    After the Start method for each RC Time instance gets called, the repeat loop can just send the latest measurement stored in each variable (tDecay and tGrowth) to PST Debug LITE for viewing in the Parallax Serial Terminal.· One of the parameters in the start method is the address of the variable that the RC Time object should store its result in.· Since both instances are taking repeated measurements, the tDecay and tGrowth measurements both store the latest value.· tDecay gets updated at 500 Hz, and tGrowth gets updated at 1 kHz.·

    Figure 7 shows how the two instances of the RC Time object, configured to independent sampling rates, and both repeatedly take RC measurements.· The upper trace shows rc[noparse][[/noparse]0], which repeats its measurements at a T = 2 ms sampling interval.· Since sampling frequency is the inverse of sampling interval, (f = 1/T), f = 1/(2 ms) = 500 Hz.· The lower trace shows the measurements rc[noparse][[/noparse]1] takes and stores in tGrowth at a sample interval of 1 ms and a sampling frequency (or sampling rate) of 1 kHz.

    attachment.php?attachmentid=67371

    P······ Open “Test Repeated RCTIME.spin” with the Propeller Tool software.
    P······ Open the RC Time object and examine the minimum times allowed for the start method’s chargeTimeTicks, timeOutTicks, and sampleTicks parameters.
    P······ Try a variety of sampling rates, and if you have an oscilloscope, use it to examine the repeated RC measurements.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 8/24/2010 6:11:40 PM GMT
    582 x 264 - 49K
    641 x 336 - 60K
    641 x 355 - 68K
    579 x 333 - 62K
    612 x 175 - 5K
    636 x 88 - 8K
  • edited 2009-03-13 04:52
    More PE Kit Sensor Examples

    The RC decay technique can be used with a variety of sensors.· Examples of parts in the PE Kit that can be used as RC Time compatible sensors include:

    ········· Rotational position with a potentiometer
    ········· Ambient light with a phototransistor or photoresistor*
    ········· Infrared light with an infrared phototransistor
    ········· Lightly filtered ambient light with LEDs
    ········· Infrared light and flame with an infrared LED

    * Whether your PE kit has a photoresistor or a phototransistor depends on its vintage.· Older PE Kits have photoresistors.· The newer RoHS compliant kits use phototransistors for light detection instead.

    As we’ve already seen, the potentiometer’s resistance varies with rotational position, i.e. where the knob is turned.· Next, phototransistors regulate current passing through based on light intensity, which can also be measured with RC Time.· LEDs that are reverse biased in a modified RC decay circuit behave like tiny solar cells that discharge their own junction capacitance and can also be measured with RC Time.

    attachment.php?attachmentid=73445

    Ambient and Infrared Phototransistors

    Newer PE kits have two phototransistors, shown in Figure 8 on the left and right.· The ambient phototransistor has a clear plastic case and is sensitive to wavelengths from green to infrared, and is sometimes used in products to replace photoresistors for ambient light detection.· The cadmium sulfide photoresistor in the center of Figure 8 is no longer included in the PE Kit due to recent RoHS (Restrictions on certain Hazardous Substances) rules.· Its use in commercial products is also dropping off for the same reason.· The infrared phototransistor looks like a smaller LED with a black coating.· That coating filters for infrared.· Strong sources of infrared include the sun, and the clear infrared LEDs included in the Propeller Education Kit.

    attachment.php?attachmentid=67378
    ·
    Phototransistors allow more current to pass with more light.· Similarly, a photoresistor’s resistance drops with more light.· The result with either device is the same –more light leads to smaller decay times.· The quickest way to test these parts is to remove the potentiometer and replace it with either the phototransistor or the photoresistor.· Figure 9 shows RC Time circuit schematics for the phototransistors and also for the photoresistor.· If you are using the ambient phototransistor, connect the longer pin to the I/O pin.· If you are using the infrared phototransistor, the longer pin connects to ground.· With the photoresistor, direction doesn’t matter.

    attachment.php?attachmentid=67379

    The photoresistor and ambient light phototransistor both work well with Test Simple RCTIME.spin.· The infrared phototransistor needs a timeout that’s longer than the default, so if you test that part, make sure to use Test RCTIME Timeout.spin, and set the timeout to something generous, like a fifth of a second (clkfreq/5).

    P······ Substitute your light sensor of choice in place of the potentiometer.
    P······ Run Test Simple RCTIME.spin (or a modified Test RCTIME Timeout.spin for the infrared phototransistor.)
    P······ Examine tDecay under a variety of lighting conditions.

    Measure Light with LEDs

    LEDs as light sensors can sometimes serve as an inexpensive substitution for photodiodes, and have the advantage over phototransistors of an output that’s linearly proportional to light level.· They also respond well to direct sunlight, which tends to saturate phototransistors.· Each color of LED also has some inherent filtering, and responds most the color of light it emits when it’s forward biased.· LEDs also have inherent capacitance across the junction of the two silicon materials with different impurities that electrons have to cross to emit photons.· The capacitance across this junction is not surprisingly called junction capacitance.· The LED’s junction capacitance, along with the capacitance inherent to the metal clips in your breadboard make it possible to use the Figure 10 circuit for LED light measurements, with no external capacitor.

    attachment.php?attachmentid=73446

    attachment.php?attachmentid=67380

    P······ Build the circuit shown in Figure 10.· Make sure that the LED’s longer anode pin connects to ground.
    P······ Save Test RCTIME Timeout.spin as Test LED Light Sensor.spin
    P······ Change the Timeout method call’s parameter to half a second (clkfreq/2).
    P······ Change rc.time(17, 1, @tDecay) to rc.time(4, 1, @tDecay).
    P······ Load the program into the Propeller chip.
    P······ Examine tDecay under a variety of lighting conditions.

    Proximate Flame Detection with Infrared LEDs

    You can replace one of the colored LEDs in Figure 10 with the clear infrared LED to detect nearby flames.· For best results, point the dome on the top of the infrared led directly at the flame.· Provided the detector is kept out of direct sunlight, a range of half a meter or more is feasible.
    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 8/24/2010 6:12:38 PM GMT
    498 x 230 - 12K
    606 x 215 - 33K
    277 x 174 - 13K
    646 x 318 - 29K
    550 x 96 - 7K
  • edited 2009-03-13 04:54
    Application Example: Resistance Meter

    The “RC Resistance Meter.spin” application circuit and Parallax Serial Terminal display are shown in Figure 11.· The RC circuit is simply the P17 connection we have been using.· The approach to taking measurements is somewhat different from a simple RC decay measurement.· First, the RC Resistance object that the RC Resistance Meter application uses for measurements takes an average of 200 decay measurements to eliminate the effect of electrical noise.· Second, the application needs to be calibrated.· The calibration procedure is very simple, and corrects the cumulative effects of the various sources of error in the circuit, which include: actual capacitance value different from nominal (named) value, I/O pin threshold not exactly 1.65 V, stray resistances and capacitances in the circuit and prototyping board, and any deviation from nominal in the 100 Ω series resistor value.· Since each of these errors contributes to one of the terms in ∆t = 0.693 × C × R, they can all be corrected with the scalar and offset from our old algebraic friend y = mx + b.

    attachment.php?attachmentid=67375

    Table 1 shows errors before and after calibration.· Note that calibration can reduce 50% errors down to below 1%.· A minimal calibration can be accomplished by comparing two measurements against known resistor values.· This will give you two (x, y) data points, where x is the measured value, and y is the known value.· By solving for m and b in y = mx + b, you will get the scale factor and offset values that can be declared as constants in the example program.

    attachment.php?attachmentid=67376

    A better calibration procedure is to take more (x, y) data points and then use a spreadsheet to calculate the average of m and b.· For example, the seven x and y measurements in Table 1 are graphed with a Microsoft Excel as shown in Figure 12.· Spreadsheets also have tools that can display a trend line and an equation that yields the average values of m and b for all the points in the graph.· For the measurements in table 1, Figure 12 shows that m = 0.894 and b = –60.944 for the test circuit.· Keep in mind that your test circuit will almost certainly have different m and b values.

    attachment.php?attachmentid=67377

    The application relies on the RC Resistance Meter.spin object for both calibration and testing.· Before calibration, this object has its scalar constant set to 1.0 and its offset constant set to 0.0.· The RC Resistance Meter.spin object passes these values, along with CAP = 0.1e-6 to the RC Resistance object.· The RC Resistance object in turn uses this equation to calculate the resistance based on the time measurement along with the scalar, offset, and CAP values it received:
    ·
    ·································
    ········· ··Δt × Scalar···········
    · rVar =· ─────────────── - Offset
    ········· ··0.693 × CAP ·········
    ·································

    attachment.php?attachmentid=73447

    Before calibration, the measured resistance values will be linearly related to the actual values.· You can then use the spreadsheet included with the example programs to calculate the new values for scalar (m) and offset (b).· Or, for a quick and lower precision calibration, simply use a couple of data points,· (like resistance measurements for1 kΩ and 10 k&#937[noparse];)[/noparse] and y = mx + b for a rough calibration.· Here is the procedure for more precise calibration with the spreadsheet:

    P······ Open “RC Resistance Meter Calibration Example.xls”.· It’s included in the “PE Kit Lab Tools – Measure Resistance or Capacitance.zip” file.
    P······ Use a known good ohmmeter to measure the PE Kit resistors listed in Table 1’s Nominal Values column.· Record your measurements in the y-axis values column.
    P······ Open “RC Resistance Meter.spin” with the Propeller Tool software.
    P······ In the CON block, make sure that the scalar = 1.0 and offset = 0.0.
    P······ Remove the Pot from the P17 RC decay circuit you built from Figure 1.· Each test resistor should be plugged in where the pot’s wiper and B terminal were in the RC Decay circuit in Figure 1.
    P······ Run the program, and measure each resistor in the RC circuit, and record each measurement in the x-axis values column.
    P······ Copy the updated trend line values for m and b that appear in the graph above the trend line into the scalar and offset CON block declarations.·
    P······ Load the modified program into the Propeller chip, and measure the resistors in the RC circuit again, this time, using the results to populate the Measured After Calibration column.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 8/24/2010 6:13:20 PM GMT
    578 x 245 - 41K
    551 x 240 - 43K
    540 x 393 - 37K
    646 x 72 - 6K
  • edited 2009-03-13 04:56
    Application Example: 200 kHz Sampling Rate

    If you need a sampling rate that’s faster than what RC Time.spin can provide, use RC Time.ASM.spin.· It can support sampling intervals as short as a few hundred clock ticks, as opposed to the several thousand minimum in the RC Time.spin object’s documentation.· Let’s say that your application requires a 200 kHz sampling rate.· The sampling interval is T = 1/f = 1/200 kHz = 5 µs.· Assuming the Propeller chip’s system clock is running at 80 MHz, the number of clock ticks in the sampling interval would be:
    ·
    sample interval clock ticks = ticks in 1 second ´ sample interval
    ··························· = 80 MHz ´ 5 µs
    ··························· = 400 clock ticks
    ·
    Figure 13 shows an RC growth circuit that responds 100 times more quickly than the circuit in Figure 1.· That’s because the capacitor is 1/100 the size of the one in Figure 1.· Instead of growth times in the 0 to 5000 clock tick range, the measurements will be in the 0 to 50 clock tick neighborhood.

    P······ Modify the RC growth circuit connected to P27 according to Figure 13.

    attachment.php?attachmentid=67372

    These excerpts from “200 kHz Sampling rate.spin” configure the RC Time.ASM object to charge the circuit’s capacitor for 50 clock ticks, and allow 125 clock ticks for the decay before timeout, repeating every 400 clock ticks.·

    ·
    · ...
    ·
    OBJ
    · rc······· : "RC Time.ASM"················· ' RC Time.spin is also an option
    · debug···· : "PST Debug LITE"·············· ' Variable & I/O display tool·
    · ...
    ············································
    PUB Go | tGrowth, repsAddr
    ·
    · debug.Start(115_200, debug#LIST)
    · ...
    ·
    · repsAddr := rc.start(27, 0, 50, 125, 400, @tgrowth)
    ·
    · repeat
    ··· debug.VarsHome(@tgrowth, String("| tgrowth"))
    ··· debug.Vars(repsAddr, String("| @repsAddr"))
    ··· waitcnt(clkfreq/10 + cnt)···············
    ·
    According to the RC Time.ASM object’s documentation, its Start method returns the address of the object’s repsAddr variable, which stores the number of samples the object has taken.· (Unless all cogs were busy, in which case the Start method returns zero.)· Example code in the “200 kHz Sampling Rate.spin” object uses this variable address along with a modified versions of the Display object to list the number of measurements (reps) that RC Time.ASM has taken.· Every second, the repetitions display increments by 200,000.· Figure 14 shows the display at about the 10 second mark.

    attachment.php?attachmentid=67373

    Figure 15 shows the RC measurements on a 100 MHz oscilloscope set to 1 µs/division.· Note that the I/O pin switches to output-low to recharge the circuit every 5 µs demonstrating the 200 kHz sampling rate.

    attachment.php?attachmentid=67374

    P······ Open “200 kHz Sampling Rate.spin” with the Propeller Tool software.
    P······ Open the RC Time ASM.spin object, and view it in Documentation mode.· Read the Start method’s documentation, and pay special attention to how many more clock ticks than the timeout the sample interval has to have.·
    P······ Try a variety of sampling rates, and if you have an oscilloscope, use it to examine the repeated RC measurements.
    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 8/24/2010 6:14:05 PM GMT
    555 x 231 - 39K
    465 x 242 - 26K
    419 x 335 - 46K
  • edited 2009-03-13 04:56
    Reserved for attachments...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.
  • edited 2009-03-13 05:03
    Reserved for attachments...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.
  • rjo_rjo_ Posts: 1,825
    edited 2009-03-13 21:02
    Andy,

    The PE kits are all fabulous... this one is looking great.

    It is worth buying a Prop just to be able to do the kits.

    A Propeller "Etch a Sketch" would be a cool learning tool... a couple of pots and video out.

    Rich
  • edited 2009-03-13 22:07
    Ha! Rich, that's a fantastic idea.

    Graham Stabler's Good thread index (new and improved) has a link to a nice etch_n_sketch.spin app by El Paisa.· Looks like it uses a PS/2 mouse. Adjusting it for a couple of pots looks pretty doable.

    Andy

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 8/24/2010 6:15:17 PM GMT
  • edited 2009-03-17 02:23
    This thread has been updated as follows:

    - First post - PE Kit Tools: Measure Resistance and Capacitance
    ···· o Typo corrections
    ···· o Link to zipped full PDF + source code
    - Four place holder posts have been populated with the following topics:
    ···· o Setting Timeout Values for RC Measurements
    ···· o Sequential vs. Parallel RC Measurements
    ···· o Establishing Sampling Rates
    ···· o 200 kHz Sampling Rate Example

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.
  • Jim ColemanJim Coleman Posts: 52
    edited 2009-03-20 02:20
    Hi Andy,

    The prop and your Labs have hooked me again and now all my spare time time is now consumed. I have just finished your Propeller + PC Applications with ViewPort and I enjoyed it so much that I want to do all of your Labs over again using ViewPort. Unfortunately, ViewPort is like a drug: the more I use it, the more I can't live without it. Which brings me to my question: I am going to start your Measure Resistance and Capacitance Lab and I would like to use ViewPort. Unfortunately, I will not have the luxury of all your precise instructions to direct me. Can the Measure Resistance and Capacitance Lab be done with ViewPort and develop all the graphical displays.

    Jim
  • edited 2009-03-20 23:50
    Hi Jim,

    The instrumentation I used to measure the signals is the Parallax USB Oscilloscope, and I learned how to use it with the Understanding Signals book. The oscilloscope screen captures were only used to verify the functionality of the MeasureTime object.

    I would recommend trying this ViewPort tutorial: 12_Measure Capacitance. It's on the ViewPort welcome screen.· It demonstrates resistance/capacitance measurements with VeiwPort.

    Also, I'll add an example that uses·the MeasureTime object featured in this article and post an app here, hopefully in a few minutes.

    Andy

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 3/21/2009 1:39:59 AM GMT
  • edited 2009-03-21 01:04
    Hi again Jim,

    This·article showcases·a building block object (MeasureTime.spin) for RC growth/decay measurements and the various ways it can be used.· Here is an example of how to·display·measurement results from the MeasureTime object with ViewPort.· This is just one of many possible sensor examples that can be displayed (and then analyzed)·with ViewPort's instrumentation.· Of course, you can also use the ViewPort Debugger to develop applications with these objects and sensors.

    One of the features this article introduces is the MeasureTime object's ability to launch a new cog that samples RC·growth/decay at a rate·the application code passes to·the MeasureTime object's start method.·· Once you have a cog updating a measured value at a specific rate, it's ready to forward to ViewPort.· So, here is an example of the MeasureTime object sampling a photoresistor at 40 kHz and forwarding the information to ViewPort across a 1 Mbit connection.· (Remove the pot connected to P27 in Figure 1 and replace it with a photoresistor from the Propeller Education Kit.)· What you see here in the DSO view below is a trace of·me rapidly passing my index finger back and forth over the face of the·photoresistor in a fairly well lit room (fluorescent lights).

    attachment.php?attachmentid=59524

    Here is the top file code, and·40 kHz RC Sampling Rate for ViewPort.zip is attached.· It is similar to the 200 kHz code, just a little slower sampling rate to accommodate the circuit's decay time range (2000 clock ticks per cycle -> 40 kHz).· Note that the Parallax Serial Terminal is replaced by the Conduit object, and the·tGrowth variable was shared with the conduit object.
    ··
    CON
       
      _clkmode = xtal1 + pll16x                  ' System clock → 80 MHz
      _xinfreq = 5_000_000
     
    OBJ
     
      time      : "MeasureTime.ASM"              ' MeasureTime.ASM is also an option
      vp        : "Conduit"                      'transfers data to/from PC
      schematic : "Schematic for 40 kHz"         ' Schematic
                                                   
    PUB Go | tdecay, tgrowth, repsAddr
     
      repsAddr := time.start(27, 0, 200, 1500, 2000, @tgrowth)
    
      vp.config(string("var:tGrowth"))
      vp.config(string("start:dso"))
      vp.config(string("dso:view=tGrowth(offset=500,scale=200),timescale=0.1s,ymode=manual"))
      vp.share(@tgrowth,@tgrowth) 
     
      'repeat
     
    


    Notice also that after everything gets configured and launched, cog 0 comes to an end.··The program does not end because other cogs managed by the MeasureTime and Conduit are still active.

    Andy

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 8/24/2010 6:17:27 PM GMT
  • Jim ColemanJim Coleman Posts: 52
    edited 2009-03-21 04:13
    Hi Andy,

    Thank you so much for this new materiel, it should keep me busy for a good while. If you don't mind my repeating myself, I have always been a fan of your work, you are truly a fine educator.

    Jim
Sign In or Register to comment.