+ Reply to Thread
Results 1 to 14 of 14

Thread: PE Kit Tools: Measure Resistance and Capacitance

  1. #1

    Default PE Kit Tools: Measure Resistance and Capacitance

    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
    и '...
    и 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.
    и



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

    Education Department
    Parallax, Inc.

    Post Edited (Andy Lindsay (Parallax)) : 8/24/2010 6:08:42 PM GMT
    Attached Thumbnails Attached Thumbnails Click image for larger version

Name:	Figure01.jpg‎
Views:	2171
Size:	49.2 KB
ID:	67365   Click image for larger version

Name:	Figure02.jpg‎
Views:	2170
Size:	47.3 KB
ID:	67366   Click image for larger version

Name:	Figure03.jpg‎
Views:	2099
Size:	27.3 KB
ID:	67367   Click image for larger version

Name:	p791692-1.gif‎
Views:	1487
Size:	35.6 KB
ID:	73441   Click image for larger version

Name:	p791692-2.gif‎
Views:	1459
Size:	7.4 KB
ID:	73442  

    Attached Files Attached Files
    Last edited by ForumTools; 09-30-2010 at 07:18 PM. Reason: Forum Migration

  2. #2

    Default

    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.и



    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.и




    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.и



    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[2] : "RC Time"ииииииии
    и
    PUB Go | tGrowth, tdecay, iииииииии
    и repeat i from 0 to 1иииииииииии
    иии rc[i].SetMode(rc#PARALLEL)
    и '...
    и rc[1].Time(27, 0, @tGrowth)
    ииrc[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.



    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.и



    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[0] is configured with a 0.1 ms charge time, a 1.0 ms timeout, and a 2 ms sample interval (clkfreq/500).и rc[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[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[1].start(27, 0, clkfreq/1_0000, clkfreq/2000, clkfreq/1000, @tGrowth)
    и rc[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[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[1] takes and stores in tGrowth at a sample interval of 1 ms and a sampling frequency (or sampling rate) of 1 kHz.



    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
    Attached Thumbnails Attached Thumbnails Click image for larger version

Name:	Figure04.jpg‎
Views:	2057
Size:	49.2 KB
ID:	67368   Click image for larger version

Name:	Figure05.jpg‎
Views:	2085
Size:	59.9 KB
ID:	67369   Click image for larger version

Name:	Figure06.jpg‎
Views:	2060
Size:	67.9 KB
ID:	67370   Click image for larger version

Name:	Figure07.jpg‎
Views:	2082
Size:	62.1 KB
ID:	67371   Click image for larger version

Name:	p791694-1.gif‎
Views:	1432
Size:	4.7 KB
ID:	73443  

    Click image for larger version

Name:	p791694-2.gif‎
Views:	1426
Size:	8.1 KB
ID:	73444  
    Last edited by ForumTools; 09-30-2010 at 07:18 PM. Reason: Forum Migration

  3. #3

    Default

    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.



    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.


    и
    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.



    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.





    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
    Attached Thumbnails Attached Thumbnails Click image for larger version

Name:	Figure08.jpg‎
Views:	2160
Size:	11.8 KB
ID:	67378   Click image for larger version

Name:	Figure09.jpg‎
Views:	2134
Size:	33.0 KB
ID:	67379   Click image for larger version

Name:	Figure10.jpg‎
Views:	2057
Size:	12.8 KB
ID:	67380   Click image for larger version

Name:	p791695-1.gif‎
Views:	1448
Size:	29.4 KB
ID:	73445   Click image for larger version

Name:	p791695-2.gif‎
Views:	1419
Size:	7.4 KB
ID:	73446  

    Last edited by ForumTools; 09-30-2010 at 07:18 PM. Reason: Forum Migration

  4. #4

    Default

    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.



    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.



    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.



    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 иииииииии
    иииииииииииииииииииииииииииииииии



    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Ω) 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
    Attached Thumbnails Attached Thumbnails Click image for larger version

Name:	Figure11.jpg‎
Views:	2035
Size:	41.4 KB
ID:	67375   Click image for larger version

Name:	Table01.jpg‎
Views:	2071
Size:	42.9 KB
ID:	67376   Click image for larger version

Name:	Figure12.jpg‎
Views:	2071
Size:	37.0 KB
ID:	67377   Click image for larger version

Name:	p791696-1.gif‎
Views:	1420
Size:	6.4 KB
ID:	73447  
    Last edited by ForumTools; 09-30-2010 at 07:18 PM. Reason: Forum Migration

  5. #5

    Default

    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.



    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.



    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.



    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
    Attached Thumbnails Attached Thumbnails Click image for larger version

Name:	Figure13.jpg‎
Views:	2056
Size:	39.3 KB
ID:	67372   Click image for larger version

Name:	Figure14.jpg‎
Views:	2010
Size:	26.0 KB
ID:	67373   Click image for larger version

Name:	Figure15.jpg‎
Views:	2033
Size:	45.5 KB
ID:	67374  
    Last edited by ForumTools; 09-30-2010 at 07:18 PM. Reason: Forum Migration

  6. #6

    Default

    Reserved for attachments...

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

    Education Department
    Parallax, Inc.
    Last edited by ForumTools; 09-30-2010 at 07:18 PM. Reason: Forum Migration

  7. #7

    Default

    Reserved for attachments...

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

    Education Department
    Parallax, Inc.
    Last edited by ForumTools; 09-30-2010 at 07:18 PM. Reason: Forum Migration

  8. #8

    Default

    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
    Last edited by ForumTools; 09-30-2010 at 07:18 PM. Reason: Forum Migration

  9. #9

    Default

    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
    Last edited by ForumTools; 09-30-2010 at 07:18 PM. Reason: Forum Migration

  10. #10

    Default

    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.
    Last edited by ForumTools; 09-30-2010 at 07:18 PM. Reason: Forum Migration

  11. #11

    Default

    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
    Last edited by ForumTools; 09-30-2010 at 07:18 PM. Reason: Forum Migration

  12. #12

    Default

    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
    Last edited by ForumTools; 09-30-2010 at 07:18 PM. Reason: Forum Migration

  13. #13

    Default

    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).



    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.
    ии
    Code:
    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
    Attached Thumbnails Attached Thumbnails Click image for larger version

Name:	ViewPort Displays 40 kHz Photoresistor Sampling.jpg‎
Views:	3042
Size:	171.9 KB
ID:	59524  
    Attached Files Attached Files
    Last edited by ForumTools; 09-30-2010 at 07:18 PM. Reason: Forum Migration

  14. #14

    Default

    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
    Last edited by ForumTools; 09-30-2010 at 07:18 PM. Reason: Forum Migration

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts