Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Need help with oscillator with parasitic capacitance

Status
Not open for further replies.

Mjolnir

New Member
I am trying to build a capacitance meter using a simple relaxation oscillator with a fixed resistor R in series with a capacitor to be measured C0. I am applying the formula where Freq=frequency and K is a constant.:

C0= K / ( R * Freq )

I have however noticed parasitic capacitance in the circuit that affects the measured capacitance and frequency. I am therefore looking for a correct formula that takes into consideration of 2 extra parasitic phantom capacitors, C1 which is in parallel with R and C2 which is in parallel with C (see picture).

Oscillator-Relaxation.jpg


The resulting formula should be in the form of:

C0 = f( R, C1, C2, K, Freq)

Looking forward to any assistance with this problem.
 
Hi,

Here is a quick formula:
C0=(1-2*ln(2)*f*C2*R-2*ln(2)*f*C1*R)/(2*ln(2)*f*R)

This is based on the other three resistors all being the same value, and the output impedance of the op amp being much lower than R, and the op amp output is rail to rail.
Check this over carefully as i didnt get a chance to check it good yet.
 
Thanks Al. By rewriting your formula it became: C0 = 1 / (2*ln(2)*f*R) - C1 - C2, meaning that any value of C1 would have an identical effect on C as C2 with the same value. I did simulate the circuit in LTSPICE ( using 0 pf and 100 pf for C1 and C2) and the results are somewhat confusing:

1. A change in C1 has the opposite effect on the frequency as the same change in C2. Reversed sign in the formula?
2. A change in C1 has a larger impact on frequency than the same change in C2!!

Oscillator-Relaxation-1.jpg


What can the explanation possibly be?
 
Hello again,

Yes i thought that was strange too. It's because i used the a wrong assumption about the basic behavior of the wave across the lower caps.

Here is an updated formula, although it's not as neat as the other:
f=1/(2*(C2+C1+C0)*(-log(C2+C1+C0)+log(C2+C0)+log(2))*R)

The problem now is that f is not linear in the variable C0 so it may not be possible to solve without resorting to a numerical calculation.
The formula does show the correct response now though for the various capacitor values as f goes up with C1 nd down with C2, and everywhere we see C2 we see C0 added so it's the same for C0.

I am trying to come up with the simplest formula without being overly complex, but there are problems that come up. Another problem is that when we assume that the output is a voltage source that means that the voltage across C2 could jump up instantaneously when the output goes high, and that's not going to he the case because there is always some output impedance . The bet is that the output impedance is low enough to prevent too much of a deviation. If that's not the case, and even more complicated formula is necessary. The other bet is that the output jumps perfectly up to V+ and perfectly down to 0v. That is not going to be the case either but we hope it is close enough again to prevent too much of a deviation. If this doesnt work out, then the formula has to be made more complex again to include these effects.

There may be an analytical solution for C0 for the above equation but you'll have to try maybe Wolfram or something like that. Otherwise it has to be done using a numerical solver. Numerical solvers are not that bad really they just are not as neat and compact as an analytical solution is.
 
Thanks again Al,

I did plug values into your last formula and compared the results with Spice simulation results and a modification of your formula. I did only get discrepancies when C1 was larger than 0 so I played around with the formula and when I removed C1 from the first bracket in the denominator I got results that very closely matched the simulation.

Modded formula: f=1/(2*(C2+C0)*(-log(C2+C1+C0)+log(C2+C0)+log(2))*R)

C1 / C2 (pF)______Al's formula_______Spice________Modified Al's formula

0 / 0____________72.1347 kHz______72.621 kHz________72.1347 kHz

0 / 100__________65.6770 kHz______65.577 kHz_______65.6770 kHz

100 / 0__________57.6499 kHz______83.565 kHz________83.6318 kHz

100 / 100_________68.7414 kHz______74.896 kHz_______74.9906 kHz


Is my assumption to remove C1 correct? If so I now have a new problem and that is to find and squeeze a solver algorithm into a PIC 16F628.
 
Last edited:
Hello again,

What are the other values you are using here? Such as R and C0, and the power supply voltage.

I should have also mentioned that there will be limitations on C1 because C1 and Cx=C0+C2 form an instantaneous voltage divider that can only work as long as the divider effect can not increase the voltage by 1/3 of Vcc or even close to that probably.

Tell me what your other values are and i'll try to duplicate this with an ideal op amp and see what i can find out.

I did not realize you needed an algorithm for a micro controller either. We can look at ways to do that too.
 
All values are in the schematic in my post earlier today. Supply voltage is 5V and the comparator I'm using is LT1720. I'm really about to use the PIC's internal comparator but since I don't have a Spice model of the PIC I'm using a LT comparator for this simulation instead.
 
Hi again,

Ok i'll check that out.

Normally we dont just pull components out of a formula without a good physical reason for doing so, but the results are so close it makes it interesting to think about that. Maybe you could try testing with some more values and see if this modification holds over several ranges of values.
When i did it with my own simulation using an idea op amp (or comparator with rail to rail output) i got very good results with the first formula, so this tells me that there is something different about the LT device that is non ideal. If we find out what that is it will help improve the formula.
Also, the value of R should probably be 1k or greater.
Maybe try slightly larger values for the 1.5k resistors too, like 5k each. Maybe they are stealing too much of the available current from the output of the op amp.

I developed another formula that is much much more complex so im not sure if it is worth mentioning. I am going to use it to test other assumptions.

Here's another quick formula you can try:
f=1/(2*(C2+C0+C1)*ln((2*(C2+C0)-C1)/(C2+C0+C1))*R1)

This one is based on the initial voltage in C1 being close to Vcc minus the initial voltage in C2+C0, and the charge time is identical to the discharge time (50 percent duty cycle output).

Have you ever done a numerical solver routine before in any language?
 
Last edited:
Hello again,

Here is the best formula yet, matching the simulation very closely. This is based on the charge time being different than the discharge time which is really the case, even though it may be a small difference:
t=R1*(C1+Cx)*(ln((2*Cx-C1)/(C1+Cx))+ln((2*Cx)/(C1+Cx)))

where
f=1/t, and
Cx=C0+C2

This last formula should match closely unless we have a big problem with the op amp.

For numerical solving we might break it into:
t=ln(A)*R1(C1+Cx)
where
A=(2*Cx*(2*Cx-C1))/(C1+Cx)^2

which means we only have to calculate ln(A) once per pass.
 
Last edited:
Hello again,

Here's one more formula. This one is accurate to about 1 part in 1000 as measured with ideal components. It could be better than that (with ideal components) but that was at the limit of my simulation measurements. The simulation had shown a period of 1.202ms while the calculation had shown a period of 1.203ms. You can try with your model and see how it compares. Also you should do some real world testing with the actual device that will be used.

Tp=2*ln(A)*(C1+Cx)*R1

where
Tp is the total period of one cycle, and
A=(2*Cx-C1)/(C1+Cx)

and of course f=1/Tp and Cx=C0+C2.

I think that's about as simple as we can ever get unless someone can find an analytical solution for Tp.
 
Thanks Al,

I will check this out. Your last formula from yesterday deviated quite a bit from my simulation results for C1 > 0. My posts under forum Micro Controllers / Pic Based High Resolution Cap Meter deals with measurement inaccuracies consistent with the existence of C1>0. When calibrated the meter measures an assumed C2 which actually is a composite of C1 and C2. Since the software calibration simply subtracts the measured assumed C2 from C the meter becomes non-linear. My readings are consistent with this effect so this is the theory I'm trying to verify and hopefully introduce a solution in order to improve the accuracy.
 
Hello again,

Thanks, your recent formula works very well. All simulation results are very close to the calculated values. My next step is the real world testing.
 
Hi again,

I am happy we finally at least got the theory right, or should i say "I" finally got the theory right as i was making a mistake about the initial cap voltage for C1 and i think that is what caused the main problem. Funny though that the previous simulation i did still came out pretty close, but not as close as this last one. That's probably because i tested it with only one set of values and the right thing to do is what you did and test it with lots of different values, within reason of course.

This last one is based on the cap charging and discharging between 1/3 of Vcc to 2/3 of Vcc as that is governed by the three equal resistors connected to the non inverting terminal. That also makes the frequency independent of the supply voltage, insofar as the capacitors are considered linear even with DC voltage. What i overlooked at first was that the initial capacitor voltage of C1 actually reverses during some part of the operation (when the output of the op amp goes low) because at that time there is still a fairly stiff positive voltage across C2 and C0.

Real world worries included the fact that the op amp impedance would affect the charging of C1 in that it would slow it down much more than under ideal conditions of zero output impedance. Luckily, if R is kept high enough (like maybe 1k or higher) the time constant of C1 and any output impedance should be much faster than the time constant of R and Cx, meaning it should not have significant impact. It will have an impact eventually no doubt, but at a frequency which is probably higher than you will even be able to use with a regular microcontroller.
The other worry was that the real world op amp output will not be truly rail to rail and all the calculations are based on a perfect rail to rail performance. If that is not the case we might have to modify the formula slightly although it may scale perfectly with this defect which would make it easy to fix (multiply Cx by some factor). Otherwise it will have to be worked into the formula.

This will be very interesting to see how it goes in the real world. If you can test with the actual op amp you did the simulations with that would be good too. I seriously doubt that the on board peripheral comparator to the PIC chip is going to be as good as that LT device, which could easily bring in other problems.
Maybe you can post some results when you get them.
Also, did you mention what range of C0 you want to try to measure?


For microcontroller use, here is one algorithmic procedure...

1. Calculate Cx from Cx=1/(2*ln(2)*f*R1)
2. Using that estimate, calculate S from:
S=((C1-2*Cx)*(1/f-2*ln(A)*(C1+Cx)*R1))/(2*(ln(A)*C1-3*C1-2*Cx*ln(A))*R1)
3. Add Cx+S, that becomes the new Cx.
4. Repeat steps 2 and 3 until Cx stabilizes (probably one or two passes).

I did this with C1=0.1uf and got something like 0.87uf for Cx, then after one pass got 0.997uf which is better than 1 percent accuracy with only that one pass (actual Cx was 1uf).
The method itself is known as "Newtons Method".
Note that in the equation for S there are a few things that are calculated more than once so they can be stored and used wherever they appear in the calculation.
Another method to calculate S (less accurate and probably less stable) is to use a numerical derivative to develop the step, as this technique uses an actual derivative. This would require calculating Cx twice anyway though in the formula given in the previous post.
 
Last edited:
I did the same thing myself. Since the formula can easily be differentiated analytically I didn't have to resort to do it numerically. Using the Newton-Raphson method in Mathematica I found a stable solution with only a few steps. Hopefully this could be programmed into a PIC with sufficient resolution.
 
Hi,

The algorithm can definitely be programmed into any microcontroller with any required resolution, the real question is will it be fast enough. I am not sure how fast you need to take readings. 64 bit floating point would work, maybe even 32 bit. I also dont know what accuracy you are after here.

You could also investigate turning the formula solutions into a series where you can calculate Cx more directly, or find a power series to fit the solutions curve, or something else similar to that.
 
Last edited:
Nice thread. I been following it and wrote some equations as well, and they get pretty hairy, if not interesting, when you take into account the less than ideal rail-to-rail op amp, its limited current output, power supply dependency, matched threshold resistors, etc. For the small parasitics to matter, you have to be looking for good accuracy and precision in the measurement using small value capacitors, quite a challenge. All those little imperfections get in the way.

Not to burst the bubble, but rather to point to a novel circuit idea that can zero parasitics out and does not involve lengthy computation, yet still uses only one IC, look here: **broken link removed**

I have simulated the idea and it is amazingly accurate, especially for such a simple circuit. If using a PIC, much of the circuit can be eliminated and you have a bunch of inverters left over. The PIC can substitute for the clock. The PIC can then measure the delay directly without the need for a meter or ADC. The delay is directly and linearly proportional to the capacitor value. The main problem is the burden of range switching. A different integrator circuit that the PIC can select the constant current value would solve that.

Anyway, just thought you might be interested in that idea as I took an interest in this thread and spent some time with it. Cheers.
 
I agree with ccurtis. It's difficult to directly measure C1 and C2 with any precision. All I know is that the meter before calibration measures 334pF with no capacitor. This value represents a function of C1 and C2. By playing around with different values I figure that a C1 at about 80pF and C2 at about 450pF is not only fairly consistent with the 334pF reading but also for my readings of caps up to 50nF. Also another complication is that there is a trim pot in series with R which has to be adjusted during the calibration process. Rather than trying to measure C1 and C2 directly I will get a set of caps with different values and have them measured to <0.1% precision. I will then use the data from the readings of these caps and estimate the precise values of C1 and C2 using Al's latest function for a least square sum type curve fitting.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top