Stable and fast measurement of variable capacitor - Page 1
Forum section: electronics / projects

author: kalj
author_rank: Contributor
timestamp: October 17, 2020, 10:30:11 am
content: I am working on rebuilding an old radio (Sony CF-420L) with completely new modern digital electronics inside. The plan for this abomination is to use an Arduino with an TEA5767 and a Bluetooth module, combined with reusing the existing switches and knobs as controls.The frequency dial of the radio is connected to a variable air capacitor (14-680pF) as well as a frequency indicator. I now want the Arduino to read the setting of the capacitor to then set the frequency of the radio module accordingly. The exact capacitance is not relevant, and it does not necessarily have to be linear, but it needs to be stable with relatively low noise. I want to map the measurement to the regular 87.5—108.0 MHz range accurately to the first decimal place. So roughly <0.1% noise is needed, unless I screwed up the estimate. Additionally, for reasonable responsiveness, the measurement needs to be performed at least with say 10Hz rate.I have breadboarded two circuits to measure the capacitance, neither of which has worked satisfactory:A. A cd40106 oscillator feeding a Cd4046 PLL, out of which I tap the CV to the PLL VCO. The CV is then low passed and then read with analogRead. With the components I chose, I get frequencies in the range 1.6kHz - 8 kHz. However, the frequency of the cd40106 oscillator seems to have a variation of at least 1% which makes the rest of the circuit kind of hopeless.B. A 555 timer set up as a linear ramp using a constant current source:With this, I can send in trigger pulses at the "trigger" pin, and then measure the length of the pulse coming out at "output". With the component values in the schematic, I get pulse lengths of 80us - 1100us. However, using my oscilloscope to check the pulse lengths at a given capacitance shows that the variation is a bit too high. At maximum capacitance I get 1.100ms-1.112ms, and at minimum capacitance 79.2us-80.2us, i.e. roughly 1%.Does anyone have a clue what I can do to improve on the accuracy on either solution, or perhaps you have an idea of another solution?

author: MosherIV
author_rank: Super Contributor
timestamp: October 17, 2020, 10:39:11 am
content: It sounds/looks like you are trying to measure rise time to measure capacitance.Inherently unstable.Try measuring the impeadance.You using Arduino which has timers on board which can be set up to create 1MHz (or even 10MHz) freq.This can then be fed ito the cap. You can then use the same technique the $25 component tester uses to measure the impeadance and capacitance.

author: Twoflower
author_rank: Frequent Contributor
timestamp: October 17, 2020, 10:40:37 am
content: Since you remove the guts of that radio, why not replace the variable cap by a potentiometer? Or mechanically add a potentiometer in parallel? Just thinking.

author: coromonadalix
author_rank: Super Contributor
timestamp: October 17, 2020, 11:12:07 am
content: the problem, in a radio you have more circuitry like a pll "phase lock loop" and other stabilisation circuitryyour small ne555 circuit will never be stable, i doesnt have any frequency or pulse feedback ... use a dds as a generator insrtead ?And you have many arduinos AM-FM applications out there to suit your needs why complicate things ?BUTDo i understand :you want to read the capacitance to have a frequency readout of somekind of selection ?? to keep the look and feel of the radio ?you want to match the dial cord tunning assembly and give it a digital tunning version ?Like thishttps://vintageautoradio.com/index.php?option=com_content&view=article&id=54&Itemid=64https://www.tech-retro.com/aurora-design/home.htmlBut its done at an huge pricing ...

author: T3sl4co1l
author_rank: Super Contributor
timestamp: October 17, 2020, 11:29:38 am
content: CMOS 555 is better (LMC555, 7555..). Your CCS is so weak, the pin leakage (input bias current) is probably dominant. Propagation delay (at the smallest C values) will also dominate, so that you end up measuring a combination of delay plus capacitance, not capacitance by itself, nice and proportional.You can do the same thing with an MCU pin: set the pin output-low, then input-high (passive pullup). Start timer at the same instant, and stop timer when pin crosses threshold (use an input capture pin, or pin-change interrupt to sample CNT, or get the analog comparator involved (if available), etc.).Probably won't be very sensitive to small changes in capacitance, but you can repeat measurements to average out noise, and you can get arbitrarily long periods with an external pullup resistor rather than the internal pullup (which will also be more stable vs. temperature).Better still than measuring single periods: measure frequency. Small changes in timing are imperceptible from cycle to cycle, but accumulate over time. Measuring frequency using the timer is more complicated, but there are numerous sketches showing how to do it.To get frequency, you need an astable oscillator, which the 555 can still do, or the MCU can do to a certain extent, depending on available hardware. (MEGA might not be able to do this with low latency, but XMEGA I think can pull it off, using events and analog comparator? STM can probably do it as well.)And yeah, consider replacing the varicap with a potentiometer. What could be easier than using an ADC to measure a static voltage?Speaking of ADC, and impedance as mentioned above -- you can set up a crude impedance divider, using GPIO pins, series resistors or capacitors, and the varicap. By sampling the voltage on the varicap, at a reliable time delay, you'll sample some point along the RC (or other) discharge curve that the capacitance will go through when pulsed by those GPIOs. I say GPIOs plural, because you may want to use several in parallel, with a range of series impedances (R or C), to cover that wide of a range.Tim

author: Zero999
author_rank: Super Contributor
timestamp: October 17, 2020, 11:40:28 am
content: How about using an LC oscillator, rather than an RC? It's much more stable at higher frequencies and lower capacitance values. The 74HC4060 could be used if you want a lower frequency the MCU can handle.

author: David Hess
author_rank: Super Contributor
timestamp: October 17, 2020, 05:48:13 pm
content: Why not keep the original local oscillator and measure the output frequency?

author: CatalinaWOW
author_rank: Super Contributor
timestamp: October 17, 2020, 06:38:04 pm
content: Or put the capacitor as feedback on op-amp and then give it charge packets (pulses from the arduino through a resistor). Voltage out is then proportional to number of charge packets and inversely proportional to capacitance value. You can either use a comparator to detect a known voltage or use a fixed number of packets and measure the voltage. There are details like a discharge circuit to reset capacitor to known voltage, dealing with input offsets (voltage and current) on the op-amp but there is lots of material out on how to do this. Search integrating A to D circuits.

author: kalj
author_rank: Contributor
timestamp: October 17, 2020, 09:52:17 pm
content: Quote from: Twoflower on October 17, 2020, 10:40:37 amI would really like to avoid that since the frequency since it is a quite complicated mechanical mechanism with strings, wheels, and springs. Also, I really prefer solving electronics problems rather than mechanical ones.

author: kalj
author_rank: Contributor
timestamp: October 17, 2020, 09:56:23 pm
content: Quote from: MosherIV on October 17, 2020, 10:39:11 amInteresting. How come rise time is "inherently unstable"?Could you elaborate a little on how to go about measuring the capacitance/impedance using the 1MHz square wave?

author: kalj
author_rank: Contributor
timestamp: October 17, 2020, 09:57:48 pm
content: Quote from: David Hess on October 17, 2020, 05:48:13 pmThat would probably have been easiest, but it is a little too late for that now. Unfortunately, I don't have much more of the original components than this variable capacitor.

author: kalj
author_rank: Contributor
timestamp: October 17, 2020, 10:00:36 pm
content: Quote from: Zero999 on October 17, 2020, 11:40:28 amInteresting, could you describe how such a circuit would function? Perhaps you have a link? I really don't know what to search for...

author: Zero999
author_rank: Super Contributor
timestamp: October 17, 2020, 10:32:53 pm
content: Quote from: kalj on October 17, 2020, 10:00:36 pmhttps://wiki.analog.com/university/courses/electronics/electronics-lab-21

author: mag_therm
author_rank: Frequent Contributor
timestamp: October 17, 2020, 10:42:56 pm
content: I like David's suggestion.Sony CF-420L has a separate Hartley one transistor ( Q3) FM oscillator I suppose running from 97.8 to 118.7 MHz.Re-use the Hartley coil to make an oscillator closely based on the existing one, nelecting AFC ( 6pF coupling)Assuming station separation is in 200 kHz steps ( as in USA) starting at 87.5 MHz ( Sweden ?) , you will need a frequency counter of sufficient accuracy to create 100 entries in LUT.Assuming the frequency counter is >> more accurate than the free running Hartley, the Hartley will need to have a drift < 100 kHz approx after warmup.Well, I have an old tube FM receiver here that has 6DT8 FM osc, stays close to the quadrature detector centre for long periods even with the AFC off,so would expect a transistor oscillator to be at least as stable as that.

author: kalj
author_rank: Contributor
timestamp: October 18, 2020, 12:03:25 pm
content: Quote from: mag_therm on October 17, 2020, 10:42:56 pmI do in fact have most of the components left, so perhaps I can go this path. The problem is however that I have no experience at all with analog radio circuits like this, so I need all help I can get with understanding how to go about this. I have found this schematic of the radio:Can you explain what part of the circuit I need to recreate, and how I could I go about measuring the frequency of the oscillator?

author: kalj
author_rank: Contributor
timestamp: October 18, 2020, 12:18:45 pm
content: If we are talking about L2 and/or L4, I believe I might have lost them unfortunately. As I said previously, I was completely set on replacing the whole analog circuit with stuff that I understand. Do you think there is a way of replacing those coils?

author: kalj
author_rank: Contributor
timestamp: October 18, 2020, 12:50:15 pm
content: As and aside, I've had some suggestions that I should try the simplest and most obvious solution: Charging the capacitor from an Arduino pin, and using the internal comparator to trigger the timing. I did try such a circuit now, with mixed results. It does seem to produce decent accuracy in the time measurement. However, the charge time measured seems quite sensitive to external disturbances. By just touching some of the jumper wires, I was able to get the measured time to vary by around 10%.Anyways, I still feel a bit lost, this circuit should be very similar to the 555-based one, so perhaps any difference in results are just from random differences in the wiring of my bread board design. I feel that I really need to solder something up on perf board to really evaluate how good a method really is.

author: Zero999
author_rank: Super Contributor
timestamp: October 18, 2020, 02:09:35 pm
content: Quote from: kalj on October 18, 2020, 12:50:15 pmDid you try the LC oscillator I suggested? It's much more stable than an RC time constant, irrespective of whether it's an oscillator, or charging the capacitor from an MCU output.

author: kalj
author_rank: Contributor
timestamp: October 18, 2020, 02:49:54 pm
content: Quote from: CatalinaWOW on October 17, 2020, 06:38:04 pmWow that is a cool idea. I tried breadboarding up something, and I see how it could work in theory, but I am too inexperienced with this to have a clue of how to design a half decent circuit. If you have time to make a draft of something I could try I would be super grateful, but I perfectly understand if you don't have the time.

author: mag_therm
author_rank: Frequent Contributor
timestamp: October 18, 2020, 02:51:10 pm
content: You would have to recreate the circuit around Q3 out to and including L4The temperature grades of C14 and C13 would have been selected to offset ( tend to null) thermal drift in Q3 and L4.So they are not necessarily NPO.But if L4 has been discarded, it might be a job to do another stable oscillator."Synthetic Rock" comes to mind but you can search it for VHF versions, or otherwise look for 2 metre VFO circuits.Perhaps someone on here versed in the statistics of it, can explain why a high Q oscillator is perhaps the best way to accurately measure L & C.I like your original idea for restoration. I have some old vacuum tube receivers I restored, in good condition.A very early 1940's Philco FM, here woodwork looks good, but is too far gone to receive FM properly, maybe a candidate for your idea.

author: CatalinaWOW
author_rank: Super Contributor
timestamp: October 18, 2020, 05:22:13 pm
content: Quote from: kalj on October 18, 2020, 02:49:54 pmI've got other things going on so won't try to detail a design for you, but google will be your friend here. I will also mention that you can eliminate several sources of error by adding a known reference capacitor (presumably about mid range in your variable cap) and switching between them. Then the unknown capacitance is just the ratio of the pulses in to charge the reference capacitor to a known voltage (or the delta voltage achieved with a fixed number of pulses).

author: pwlps
author_rank: Frequent Contributor
timestamp: October 19, 2020, 12:03:46 am
content: Quote from: kalj on October 18, 2020, 12:50:15 pmQuote from: CatalinaWOW on October 17, 2020, 06:38:04 pmI think you can improve a lot the accuracy using the LTC1043 precision switched-capacitor block : use it to charge a much bigger capacitor and count the number of cycles it needs to reach a reference voltage being a fixed fraction of the charging voltage. This should be much easier to be made very accurate as it won't depend on the exact voltage value. The LTC1043 leakage currents are in the pA range therefore it shouldn't have problems even with very small capacitance values. The Arduino comparator will only see the big capacitor, and you can set the switching frequency high enough to make any errors due to the comparator input bias current negligible (the maximum usable frequency will be limited by the RC time constant but should still be high enough, it's getting too late here to try any calculations). To minimize external disturbances the switch and the big capacitor should be placed close to the variable capacitor being measured.

author: MosherIV
author_rank: Super Contributor
timestamp: October 19, 2020, 08:05:50 am
content: QuoteThis is why it is unstable!Regarding using square wave to measure capacitance it actually measures AC impeadance.I am not 100% certain how that us then converted into capacitance.Need to go look up how the $20 component tester works or look up how lcr bridge works.

author: pwlps
author_rank: Frequent Contributor
timestamp: October 19, 2020, 09:48:19 am
content: Here is the idea of my previous post.SW1 is a switch (any reasonably fast high isolation SPST switch, didn't have time to look what is available in my LTSpice library) to reset the measurement (discharging C2) just before starting counting. R1,R2,R4 set the ratio charging voltage/comparator voltage, C3 is to filter power voltage fluctuations during a measurement cycle.There is of course a tradeoff between the resolution and the measureement time (depending on the values of C2 and R4) but you can easily get a 4-digit resolution. Anyway I bet this will be orders of magnitude more accurate than any 555 crap (I hate 555s)NB. The simulation won't work with a generic SW1, should be removed or replaced by a real one.Edit: One question not to overlook is how the resolution of each measurement technique varies across the capacitance range. Since the radio frequency varies like 1/sqrt(C) the resolution on C should vary like 1/C^3/2 to get a constant resolution over the radio frequency range. In my circuit the resolution varies like 1/C but in time-constant measurements it would vary the wrong way (roughly proportional to C) making it difficult for small capacitances. With a 555 we should measure the frequency rather than the time constant (roughly equivalent to averaging many measurements).Update : Today I did some simulations, see below (simulations are done with the last version capmeter2.asc, just removing the switch). The charging time even in the upper range of capacitance (I took 700pF) is below 2us so the max frequency is of order of 500kHz.The topology of the first version wasn't optimal because the Vcomp+ reference voltage was taken from the supply of the charging pin (S1A) and was subject to spikes from the current pulses. In the new version I just added a separate voltage divider for Vcomp+. Even then the charging input S1A-S3A will have to be heavily decoupled to keep Vcomp+ clean (here C5; some spikes are also present on Vss which should be decoupled too).

author: IDEngineer
author_rank: Super Contributor
timestamp: October 19, 2020, 03:20:28 pm
content: At first I thought the OP wanted to do this primarily with the hardware on an Arduino, but since the OP included fresh hardware involving 4000 family parts and the 555 I presume it's OK to suggest other new hardware.Take a good look at the Charge Time Measurement Unit (CTMU) included in a bunch of Microchip PIC MCU's. I've used that in several designs and it's literally tailor made to do exactly what you want to do here: Measure capacitance. Everything you need in both the analog and digital domains is already on the chip, and this approach will give you the flexibility of firmware control over the entire process. It will also unburden the Arduino from requiring time-specific operations to measure C... just let the MCU handle it like it was specifically designed to do.Once you're measuring C with the CTMU, having the MCU gives you lots of options to communicate the results to your Arduino. SPI, UART, roll your own, whatever you like.I have successfully measured capacitance down into the low double digit picofarad range, and on the other end you can scale (dynamically in your firmware if necessary) to almost any upper value. Obviously you'll need to pay attention to layout but that's true of any method when measuring C down to ~14pF as mentioned in the first post.In addition to the spec sheets for the MCU's that include the CTMU, there are at least two Microchip appnotes that focus specifically on it. Do a Google search. Lots of reading material and example applications to get you started. This is a one-chip answer to your question with nearly infinite flexibility.

author: Zero999
author_rank: Super Contributor
timestamp: October 20, 2020, 08:26:45 pm
content: The circuit on the left is a Colpitts oscillator and the one on the right Hartley. U1 is an unbuffered CMOS inverter IC, i.e. pins 9 & 10 on the '4060.https://assets.nexperia.com/documents/data-sheet/74HC_HCT4060.pdfIn the Hartley oscillator, vary C1 and make C2 much greater, than the minimum value of C1.In the Colpitts oscillator either C1 or C2 can variable.

author: kalj
author_rank: Contributor
timestamp: October 20, 2020, 08:31:26 pm
content: Quote from: Zero999 on October 17, 2020, 10:32:53 pmQuote from: Zero999 on October 18, 2020, 02:09:35 pmI did start playing around with a simple LC resonance circuit, and it does look like the resonance frequency is very stable, so this method looks promising. I have ordered the CD4069UB part that is used in the page you linked.Quote from: mag_therm on October 18, 2020, 02:51:10 pmLooked around for some of the oscillator circuits you mention, but felt that those old pieces of analog art are a bit above my understanding. Hand-winding coils and stuff seem like a very daunting task!Yeah it feels good to give old devices new life. In this case, the radio belonged to my father in law who bought it as his first radio in his youth. Now the plan is to fix it and give it back as a Christmas present.

author: kalj
author_rank: Contributor
timestamp: October 20, 2020, 08:44:31 pm
content: Quote from: pwlps on October 19, 2020, 09:48:19 amThat looks very interesting. Let me see if I understand this: The LTC1043 charges the varcap, then switches over so that the varcap charges the 1µF capacitor, then switches back, etc. This process repeats until the reset switch is flipped and the 1µF cap is discharged. I can sense Vcomp- and Vcomp+ and measure the number of cycles needed to charge the big cap. Correct?I am curious why this would be more stable than the other charge-time methods I have tried. Any idea?Anyways, I have ordered the LTC1043 and will have a shot at your suggested circuit when it arrives.

author: kalj
author_rank: Contributor
timestamp: October 20, 2020, 08:49:45 pm
content: Quote from: IDEngineer on October 19, 2020, 03:20:28 pmThanks for the tip! It is amazing how many approaches there are to solving such a seemingly simple problem.I am quite inexperienced with PIC MCUs though. Have always found them more complicated to work with than say the Arduino. Do you have a suggestion for a suitable - preferably cheap - PIC if I want to try out the CTMU for this simple task?

author: kalj
author_rank: Contributor
timestamp: October 20, 2020, 09:12:34 pm
content: Quote from: Zero999 on October 20, 2020, 08:26:45 pmThanks! That looks similar to the oscillator based on CD4069 linked by Zero999 (https://wiki.analog.com/university/courses/electronics/electronics-lab-21). I have ordered the CD74HCT4060 now so I will try your circuit out once it arrives.Anyways, what inductor type and value do you suggest for combining with my 14-680pF varcap? And are regular old ceramic caps okay, or are any other type preferable?

author: IDEngineer
author_rank: Super Contributor
timestamp: October 20, 2020, 09:55:58 pm
content: Quote from: kalj on October 20, 2020, 08:49:45 pmFirst, be prepared for naysayers who will speak poorly of the PIC family. But they're like every other MCU out there - you select the one that is best suited for the specific application. In this case, what you're buying is the CTMU and it happens to come wrapped in a PIC. We're not focused on the purity of some CPU architecture, we're trying to get a job done!There are quite a few PIC's with the CTMU. You can pick one using Microchip's website selectors, but take a look at the PIC18F23K22. You don't need much code space nor memory, it's available in a 28 pin PDIP package which will make breadboarding easy, etc. To get started debugging you can use their cheap PICkit3 debugger which costs like $50. That, their free compiler, and a laptop and you're ready to go. You could be testing this in a couple of hours.EDIT: The PIC's aren't any more complex than anything else. You'll program in C, just like the Arduino, and you control the on-chip peripherals via hardware registers that have handy mnemonic names. Not hard at all.EDIT2: Here's the link to the spec sheet:http://ww1.microchip.com/downloads/en/DeviceDoc/40001412G.pdf. The CTMU starts on page 311.

author: pwlps
author_rank: Frequent Contributor
timestamp: October 20, 2020, 11:53:39 pm
content: Quote from: kalj on October 20, 2020, 08:44:31 pmYes, the process repeats until you detect that the comparator tripped, then you save the counter value and programatically close the switch to discharge the 1µF capacitor. To start a new measurement you reset the counter and reopen the switch at the same time.I don't know the electrical and timing characteristics of arduino pins but in a first approximation you might possibly simulate the switch action (if you don't have a switch already) toggling a pin between the input (high impedance-switch open) and output (low state-switch closed) configurations.Note that you can also provide your own clock from an arduino pin (overriding the LTC1043 internal clock, see datasheet), this gives more flexibility (e.g. the exact timing and speed of the switch will be irrelevant if you drive the clock programatically). From my estimations you can use a clock frequency up to at least 200-300kHz (taking roughly 5 RC time constants for charging/discharging the varcap, with R being the on-state resistance of LTC1043, but double-check my estimations).QuoteI would say the most relevant difference is that the total amount of charge involved is thousands times bigger, the process is effectively averaging the measurement of charge on the varcap. However note that this is not exactly the same as averaging many charge-time measurements because there is no averaging of errors due to jitter (mathematically speaking and leaving aside the clock speed, the jitter error here scales like 1/N whereas for averaged charge-time measurements it would scale like 1/sqrt(N) (*); this "1/sqrt" behavior of jitter contribution is also found in RC-discharge based frequency generators, cf. 555 style generators). Maybe there are other subtle points, I'm open to a discussion on this interesting question.(*) for the math seehttps://en.wikipedia.org/wiki/Random_walk#Gaussian_random_walk;the total excursion varies like sqrt(N) therefore the average over N samples varies like 1/sqrt(N)

author: David Hess
author_rank: Super Contributor
timestamp: October 21, 2020, 08:52:54 am
content: An easier and more accurate way to use the LTC1043 is to configure it as a voltage-to-frequency converter, which is very simple, but with a fixed voltage so the frequency varies with the capacitance instead of voltage.

author: pwlps
author_rank: Frequent Contributor
timestamp: October 21, 2020, 09:17:47 am
content: Quote from: David Hess on October 21, 2020, 08:52:54 amI saw this application in the datasheet and thought of it too but it's not necessarily more accurate because it is directly related to the voltage stability, you would need to add a precision voltage regulation stage. I actually preferred a circuit where the measurement result is determined by the values of passive components only and does not depend on any voltage, at least in first order.Edit: and I don't find it easier at all, at least the circuit proposed in the datasheet is more complicated. But it certainly depends on our personal experience with various approaches.

author: David Hess
author_rank: Super Contributor
timestamp: October 22, 2020, 09:20:30 am
content: That is right; the frequency is proportional to the capacitance *and* the voltage so a voltage reference is required and that voltage reference limits accuracy. In practice however the variable film capacitor has a larger temperature coefficient than even an inexpensive voltage reference so the voltage reference does not limit accuracy. Indeed, accuracy could be improved considerably by including a thermister or diode to deliberately vary the voltage slightly with temperature.The advantage of this circuit is extreme linearity without any additional effort. For instance there are no effects from having to periodically reset including dielectric absorption. An LC oscillator would have the same advantage.

author: pwlps
author_rank: Frequent Contributor
timestamp: October 22, 2020, 01:24:47 pm
content: Quote from: David Hess on October 22, 2020, 09:20:30 amI must agree with your point on the temperature drift and possibly on the effects of dielectric absorption (although I have no idea at which level of accuracy the dielectric absorption and related memory effects may become a concern, I'm curious to know if you have experience with such problems).I also agree that an LC oscillator might be the simplest solution. Still I'm curious what the performance of my circuit would be compared to others, and apparently the OP ordered an LTC1043 already...PS. Just an additional info not related to this discussion: I updated the schematic and added some simulations in my post of oct 19.

author: mag_therm
author_rank: Frequent Contributor
timestamp: October 22, 2020, 01:49:33 pm
content: Thanks for adding the sim traces.As I see it, the Cvariable carries back its residual charge to S1a, so next charge is to the difference Q_c5 - Q_c2 and the staircase has smaller steps toward the end.So accuracy might be better if V_C2 is not charged too close to V_C5.Why did you move reference Vcomp+ away from R3? I thought it was in a good place for overall error cancellation in your first revision.

author: David Hess
author_rank: Super Contributor
timestamp: October 22, 2020, 04:41:27 pm
content: Quote from: pwlps on October 22, 2020, 01:24:47 pmDesigns which continuously integrate their input have at least an order of magnitude more accuracy, but that probably does not matter here because of the limited accuracy of the variable capacitor unless its temperature coefficient is compensated. 1 part in 100,000 is possible while reset based designs have trouble even below 1 part in 10,000.Multi-slope integrating analog-to-digital converters get around this by using "run-up" and "run-down" designs which make the integrating capacitor effectively much much larger so that its error contribution from dielectric absorption is smaller.QuoteThe only disadvantage of the LC oscillator is the temperature coefficient of the inductor. Extra accuracy is available by selecting an inductor which has the opposite temperature coefficient of the variable capacitor but this can be difficult.

author: pwlps
author_rank: Frequent Contributor
timestamp: October 22, 2020, 05:43:01 pm
content: Quote from: mag_therm on October 22, 2020, 01:49:33 pmAs I explain in the update notes this is to easier and better decouple the reference comparator voltage from spikes at S1A. (I had overlooked this little potential problem and changed the circuit after I saw spikes on Vcomp+ in my simulations of the first version). There shouldn't be any difference in the error cancellation (at least as long as all resistances have the same temperature coefficient), in fact the only difference is that the current through the R1/R4 divider does not flow through R2.

author: mag_therm
author_rank: Frequent Contributor
timestamp: October 22, 2020, 05:52:58 pm
content: Old type shortwave receiver with a variable capacitor VFO ( warmed up) might typically drift by +/- 100 Hz over 24 hours when tuned to WWV @ 10 MHz.That is "accuracy, free run /day " of +/- 1e-5A TCXO might be spec'ed at +/- 1e-7Usually the old coils were air cored litz wound solenoids with a diameter of 25 to 50 mm. Larger diameter has higher Q factor.Look at photos and circuits ( Colpitts) of the Geloso 104 VFO which was well respected 70 years ago.

author: pwlps
author_rank: Frequent Contributor
timestamp: October 22, 2020, 06:27:02 pm
content: Quote from: David Hess on October 22, 2020, 04:41:27 pmSo it would take two more SPDT (reference and charging voltages) to implement multi-slope here. If the OP has enough courage...

author: kalj
author_rank: Contributor
timestamp: October 22, 2020, 07:49:03 pm
content: Interesting discussions on the LTC1043-based approach! I will try out some of your suggestions once I get a hold of the the chip.Meanwhile, I have started to play around with the LC oscillator using CD4069 / 74HCT4060. I tried both the Hartley and the Colpitts types and managed to get something that seems to oscillate very solidly. I used some random 100µH coils and a 470pF ceramic capacitor, and got oscillations in the 380kHz - 1.6MHz range. However, I notice that at higher frequencies, the waveforms look less and less sine shaped, if that is a problem. Also, there seems to be an amplitude dependence on the frequency (higher frequency -> smaller amplitude). With the 74HCT4060, the damping was strong enough to not yield oscillations for the smallest capacitances.I really feel lost concerning the ideal choice of coils and capacitors for the oscillator. If anyone has any insight and suggestions that would be very appreciated!To determine the frequency using the Arduino, I guess I can either measure pulse lengths (accuracy decreases with frequency), or pulse counts per time unit (accuracy increases with frequency). It is an interesting question what combination of frequency range of the oscillator and measurement method produces the overall smallest noise. What do you guys think?

author: kalj
author_rank: Contributor
timestamp: October 22, 2020, 07:55:09 pm
content: Quote from: kalj on October 22, 2020, 07:49:03 pmI just realized that if I can get the oscillator working using the 74HCT4060, I will essentially get a pulse counter for free. I.e., arduino resets 4060 counter, waits say a millisecond, then reads of the value of the counter, and then F=count/1ms. Perhaps I need to add a register to latch the counter to not get race conditions in the readings.How about that solution?

author: pwlps
author_rank: Frequent Contributor
timestamp: October 22, 2020, 08:17:33 pm
content: Quote from: kalj on October 22, 2020, 07:49:03 pmThe standard high-resolution frequency measurement technique working at either low or high frequencies combines both counting and period measurements and is known as "reciprocal frequency counting", see eg.https://www.instructables.com/High-Resolution-Frequency-Counter/

author: mag_therm
author_rank: Frequent Contributor
timestamp: October 22, 2020, 08:41:29 pm
content: There are not many hits for cmos gate LC oscillators!In 74HC4060 data sheet ( Nexperia) Fig 13, the crystal oscillator feedback is via a 2k2 limiting resistor, which might be OK for a crystal,but I think will reduce the Q factor (and hence accuracy) of an LC, unless C2 can be increased to be >> C_variable.I would add a jfet and make a standard colpitts of which there are lots of examples.The aim is to get it oscillating in the linear range without too much over-drive,across the C_Variable's range, with a pure fundamentalby adjusting the feedback side capacitor C2 (maybe the cause of the distortion you mention)Looks '4060 need to be safely below 20MHZ.

author: Zero999
author_rank: Super Contributor
timestamp: October 22, 2020, 08:52:20 pm
content: Quote from: mag_therm on October 22, 2020, 08:41:29 pmThe 74HC4060 should work as an LC oscillator. The link I posted above shows the crusty old CD4007/4069 working fine as an LC oscillator. It's not on the data sheet because it isn't something one would normally do, because an inductor is no cheaper than a crystal, or ceramic resonator, which will have far superior stability and accuracy.https://wiki.analog.com/university/courses/electronics/electronics-lab-21Overdrive is only an issue for a fragile crystal, which can easily be damaged by too much power. The 74HC4060 can whack an LC circuit as hard as it can without any damage. In this case a squarewave is the desired outcome so it's no problem if it goes into clipping, which is good and to be expected. The only potential issue I can see is high current draw. If the 74HC4060 draws more than 10mA or so, add a resistor between the output and LC circuit, try 100R to 1k first, to dial down the drive a little.Try a discrete JFET if you like, but I don't see anything wrong with the MOSFETs inside the 74HC4060.Quote from: kalj on October 20, 2020, 09:12:34 pmThe inductance depends on what output frequency you desire and will be divided by the counter inside the 74HC4060 (you've got the choice of 2n, where n can be from 4 to 10, or 12 to 14) which is only guaranteed to work up to 25MHz at 5V, over the full temperature range. The inductor can't be too higher value because the resistance will be too high and its parasitic capacitance will dominate too much. You could try a common more choke, in which case the inductors will be coupled, so can be smaller, but it might be too lossy over a few MHz.The formula to calculate the frequency for the Colpitts and Hartley oscillators can be found on Wikipedia:https://en.wikipedia.org/wiki/Colpitts_oscillatorhttps://en.wikipedia.org/wiki/Hartley_oscillatorFor the Colpitts oscillator, the variable capacitor can be either C1 or C2, with the fixed capacitor being around 330pF, around the middle value of the variable capacitor.As I said, for the Hartley oscillator, C1 is the variable capacitor and C2 much greater, than the maximum value of C1, so 10nF will do, as it's much higher than 10nF.I think the Hartley oscillator might be the better option, for this application, but try both.

author: mag_therm
author_rank: Frequent Contributor
timestamp: October 22, 2020, 10:58:45 pm
content: Hi Zero, Agreed, mostly.But for anaccurateLCR oscillator, the limiting condition for maintenance of oscillation, is R = 0The active device effectively puts a negative R.If R < 0 as you "wack a circuit as hard as it can" the LCR oscillator will drive up to a rail and will become non-linear and clip, reducing accuracy.If R > 0 damped, the oscillation will die out , moreover before that the frequency will skew, as the DE solutions show.There is a "oscillator maintenance equation" that allows gain selection, and allows best accuracy.If you put a probe on a well designed oscillator, you will see the ouput level within the linear range of the active device.

author: CatalinaWOW
author_rank: Super Contributor
timestamp: October 22, 2020, 11:33:03 pm
content: Quote from: mag_therm on October 22, 2020, 10:58:45 pmR identically equal to zero is impossible to maintain in a real linear circuit (and causes an interesting startup problem if you think about it). The gain will change slightly with temperature, aging, supply voltages and a myriad of other things. Real and well design oscillators either have a feedback loop controlling gain, or are slightly non-linear so that effective gain is reduced as amplitude increases.

author: vk6zgo
author_rank: Super Contributor
timestamp: October 23, 2020, 01:48:01 am
content: Quote from: kalj on October 18, 2020, 12:18:45 pmSo when in doubt, instead of spending a bit of time learning about analog circuitry, replace a perfectly good design with one which probably won't work as well?------Bravo!OK, I've had my rant, here's a possible solution:-Make or modify a rotary encoder, mount it on the capacitor shaft, read the angle it has moved through, program the Arduino to display that in frequency & all is well.OK it entails a bit of mechanical work, but it gives you nice, clean, repeatable pulses to look at.

author: Zero999
author_rank: Super Contributor
timestamp: October 23, 2020, 09:28:13 pm
content: Quote from: mag_therm on October 22, 2020, 10:58:45 pmI don't think I've every seen a nice sine wave from an oscillator made with a CMOS inverter, irrespective of the topology.Quote from: CatalinaWOW on October 22, 2020, 11:33:03 pmLike a CMOS inverter, which has a lower gain, when the output voltage approaches either supply rail.I plugged it into LTSpice using the HEF4007 model for the inverter with a 12V power supply and works over the 14pF to 680pF range. The Colpitts oscillator seems to require a lower ESR, than the Hartley, but it produces a better waveform, over the entire frequency range, not that it really matters.

author: kalj
author_rank: Contributor
timestamp: October 23, 2020, 09:39:49 pm
content: Quote from: vk6zgo on October 23, 2020, 01:48:01 amYou can rant away all you want. I'm the first one to admit it was a great mistake to strip the original circuit. But it was many months ago and it really did look impossibly complicated to figure out what was wrong in the original circuit to me as a simple software guy. However, with all I've learned since, I would definitely have proceeded differently today.I might look into a mechanical solution if the other approaches fail. At this point I see it as a fun project to see if I can solve it using the varcap. Besides, the stringed varcap - knob - indication display mechanism is quite complex and does definitely not seem like something which lends itself well for customization.

author: vk6zgo
author_rank: Super Contributor
timestamp: October 24, 2020, 02:48:25 am
content: Quote from: kalj on October 23, 2020, 09:39:49 pmIf you just need the dial reading to control the completely new radio tuning, you could still use a rotary encoder & only need to retain the shaft & bearings in the capacitor, so the dial will work.It would, perhaps be possble to remove some of the plates of the cap, somehow fit the rotary encoder to the shaft in their place & be good to go.This sounds fiddly, but it may, be possible, depending upon the capacitor's construction, to partially dismantle it without detaching it from the dial cord, so you can fit the encoder directly on the shaft.(If it is one of the sealed "polyvaricons", you may be able to do something similar, but they are quite flimsy.)It seems to me that all the really effective ways to do what you want would end up with a substantial component of mechanical work.One semi-electronic way, if it is possible to remove plates from the cap, would be to reduce its capacitance range, use it to "pull" a crystal oscillator, then measure the resultant frequency.This may be more stable than a self excited oscillator, or just trying to read the capacitance.

author: IDEngineer
author_rank: Super Contributor
timestamp: October 24, 2020, 03:19:09 am
content: This is a very interesting and educational thread. But if the OP's actual goal is to measure the capacitance, why not just do so the most straightforward way: Charge with a constant current source for a known amount of time and measure the resulting voltage.Wouldn't it be nice if there were a single chip, fully configurable solution that implemented that? Oh yeah, I already recommended it: The CTMU. And if you need more accuracy than your voltage regulator provides, add a dedicated voltage reference - another inexpensive single chip solution.I seriously love all of the various schemes discussed herein, but it feels like we're getting rather esoteric and far afield from what the OP originally wanted to do. If his goal has changed, my apologies.

author: David Hess
author_rank: Super Contributor
timestamp: October 24, 2020, 06:43:59 am
content: Quote from: IDEngineer on October 24, 2020, 03:19:09 amThe low capacitance involved makes that more difficult than some of the alternatives. For instance a frequency output is more easily measured than a voltage output.Even using a current and time is not required. Charge up a reference capacitor, which is how the charge balancing designs we have discussed work, and then redistribute charge between the reference capacitor and variable capacitor and measure the resulting voltage. This also allows temperature compensation if the temperature coefficients of the two capacitors are matched which could be relatively easy to do.

author: pwlps
author_rank: Frequent Contributor
timestamp: October 24, 2020, 01:54:18 pm
content: I'm posting below the third version of my LTC1043-based capacitance meter.This iteration follows recent discussions with David Hess, let me first shortly recall the background.NB. I started working on this yesterday evening and I see now there have been new posts since, I apologize for not taking them into account yet.As David Hess pointed out there is an issue regarding the stability of the reference capacitor (C2). I looked into this and it is not easy indeed to find relatively big (1uf) capacitors having low temperature coefficients. With 500 ppm/°C or more it would be difficult to keep the required 0.1% stability over a reasonable temperature range.The temperature drift could in principle be compensated using a PTC /NTC combination as suggested e.g. here :https://www.tdk-electronics.tdk.com/download/530754/480aeb04c789e45ef5bb9681513474ba/pdf-generaltechnicalinformation.pdfbut there is also a huge humidity dependence so I'm not sure it would be reliable.On the other hand David Hess recalled that 1) voltage references are much more stable than capacitors and are cheap today, 2) integrating designs can achieve high stability. I have built on that for my new design.There was also a suggestion of adapting a V/F converter. Now I found some time to look more closely at the V/F converter example in the LTC1043 datasheet, this circuit is analyzed in the AD application notehttps://www.analog.com/media/en/technical-documentation/application-notes/an03f.pdfHowever I'm not sure it would still be good for capacitances as low as 15pF.If I understand it correctly, it is basically a 555-like RC-discharge design albeit using precision components. But like with all RC designs the weak point is in the comparator (here the comparator is hidden in the LTC1043 clock circuitry). A comparator is a high-gain device and as such it highly amplifies noise and produces jitter (I already mentioned the jitter problem of RC based oscillators in my post of Oct 20). And we can reasonably guess that the smaller the available charge to drive the comparator inputs the bigger jitter will be (*). Finally the least frequently we have to compare anything the better the performance hence the idea of accumulating charge packets in a bigger capacitor.(*) Here the charge is amplified by the LF356 opamp but I don't think it changes the problem fundamentally, I'm open to discussion though.With a 10pF range capacitor even a high performance V/F converter like the one suggested in the appnotes will suffer, we either need a very high switching frequency or very large resistances and ridicously small currents. I strongly suspect that for 10pF range the performance would drop dramatically.For these reasons I stick to the idea of accumulating charge packets in a bigger capacitor.Now the problem is the big capacitor is varying - no problem, just measure it!In fact it is simpler to think in terms of charge measurement. Charge can be measured using a stable voltage reference like in integrating ADCs: set a constant current using a voltage reference and a stable resistance and measure the time to charge it to a given voltage, the integral of the current will give the charge. (Of course we still need a stable resistance but here it seems much easier than for stable capacitors).There are two phases in the measurement. In fact three if I count the cold startup : before the first measurement the software would discharge C2 by connecting Vcomp+ to ground and then setting S1 in the right direction depending on the sign of Vcomp- until zero-crossing on the comparator input is detected.The first phase is the same as in the previous version: connect the opamp input to S2A and Vcomp+ to Vref+ , then wait until comparator trips counting the number of charge packets.In the second phase Vcomp+ is connected to ground and the opamp input to Vref- through R2, the software then measures the time to discharge C2 at a constant current Vref-/R2.Then S1, S2 are immediately set as in the first phase and the process repeats for the next measurement.I think using two SPDTs with a single comparator should also bring the benefit of compensating for the comparator offset, although I did not attempt to study it more deeply.If N is the number of packets and T the time to discharge the capacitor then we have :Q(C2)=N * Q(Cvariable)Q(C2)=|Vref-| * T / R2Q(Cvariable)=Cvariable * Vref+givingCvariable=|Vref-| * T / (N * Vref+ * R2)(NB. If Arduino has differential analog inputs the formula can be made more precise measuring the residual voltage Vcomp- - Vref+, this would improve resolution for the highest capacitance values when N is relatively small)I'm certainly reinventing the wheel here, there are apparently dozens of patents on capacitance measurement techniques, unfortunately reading patent texts is beyond my skillsI'm eager to know your opinions about this new design.

author: CatalinaWOW
author_rank: Super Contributor
timestamp: October 24, 2020, 02:13:44 pm
content: You might want to think about how much accuracy you need. In the era of this radio frequency markings were a general indication where to tune, and you searched around that area until you got the station you wanted. Easy in areas with lots of stations, sometimes a problem in large urban areas. Today's method of entering a three or four digit number and getting the station you want was not conceivable.

author: IDEngineer
author_rank: Super Contributor
timestamp: October 24, 2020, 02:35:51 pm
content: Quote from: David Hess on October 24, 2020, 06:43:59 amChanges in value in the single digit picofarads can be discerned with the CTMU. Even one of its appnotes openly discusses measuring changes of 10pF. The smaller the absolute value, the higher the current you select from the constant current source to yield a larger measurable charge. And you can lengthen the charge time period, too.One of the products where I use the CTMU involves a capacitance range of ~100-300pF. That has been in continuous production for several years with many thousands of units in the field. While I don't have memorized values from my own work, one of the appnote examples describes a 500mV change from a ~10pF shift. Presuming a 10+ bit A/D, 500mV should be easily discerned.'Nuff said. The option is available if anyone is interested.

author: mag_therm
author_rank: Frequent Contributor
timestamp: October 24, 2020, 02:43:25 pm
content: In post 13 I made a note about the accuracy required assuming 100 stations on Sweden.Fortunately the frequencies are invariant.I assume kalj will make a look up table containing the exact frequency, usually at every odd first decimal place across the band.The capacitor read-out only has to give a pointer to select the record in the LUT.And after this thread, I have the old radio with a free running oscillator ( AFC switched off) tuned to WKUF low power for 5 days . The frequency stay on the discriminator within a few hundred Hz all week, ( compared to the 100 kHz needed accuracy) with the radio switched off and on every day.So accuracy with a free running analog oscillator is not a problem.I expect pwlps instrument will also be more than adequate.Frequency goes by the sqrt(C), what does that do the the required error in C?

author: pwlps
author_rank: Frequent Contributor
timestamp: October 24, 2020, 04:05:46 pm
content: Quote from: mag_therm on October 24, 2020, 02:43:25 pmI have mentioned it in one of my previous posts, as frequency goes by 1/sqrt(C) the absolute error on C goes by 1/C^3/2 (it's just a derivative of 1/sqrt) and accordingly the relative error by sqrt(C) to have a constant error on frequency (NB. for a radio it is the absolute frequency error and not its relative error which is relevant).The smaller is C the better therelativeresolution in C is needed to keep a constant resolution in f. This is the main problem here.QuoteI don't expect it to be that muchmoreadequate for the lowest capacitance range. My estimations remain qualitative, I prefer to wait until experimental results are available

author: mag_therm
author_rank: Frequent Contributor
timestamp: October 24, 2020, 06:00:16 pm
content: I am re-using an old variable capacitor from FM radio ,on an active antenna tuner with high Q ferrites for shortwave listening ( 3 ~20 MHz.)I noticed quite a change in minimum capacitance between prototyping on a wood breadboard, and then into the metal case.I had to pull turns off the medium and high freq range inductors which is not ideal.Next time I take it apart I will try varicap diodes.There is a capacitance between the moving blades and nearby metal.This increases as the blades un-mesh toward minimum capacitance.Here, the resonant frequency actually reduces after about 80 degrees rotation, meaning there are 2 settings that give the same resonant frequency.I think in the real FM radios that would have been compensated by customising the dial graduations, and by not using the last 20 degrees or so.Anyway, I was thinking about spin -offs of kalj's smart idea, to old radio restoration, on the bike ride this morning.That is, for those who still like the smooth tuning dials on the old boat anchors.I suppose there are not many left, as the serious amateurs were going to digital frequency "appliances", more than 30 years ago.The first digitally tuned radio I saw was the USA Navy (and NATO?) an/urt-23 which was also used by the Australian Navy from about 1969 on.

author: kalj
author_rank: Contributor
timestamp: October 25, 2020, 08:32:02 pm
content: Quote from: Zero999 on October 23, 2020, 09:28:13 pmThanks for those simulation setups. I hadn't really played around with LT Spice until now, but boy was that a great tool. I tried simulating your circuit and it seems to be working great for the whole range 14pF-680pF, producing oscillations in the range 2-13Mhz which I suppose should be okay for the 74HC4060. However, as you say, it seems the Hartley one is sensitive to Rser in the inductors. In fact, using the 5V supply that I am targeting, the Hartley one needs around 9ms to get started, unless I lower the Rser of the inductors.Speaking of the inductors, I am looking through the available ones at Mouser, and get a bit overwhelmed by all the types. I know now that DC resistance is crucial in this case. However, what else should I consider? I have heard that the Q factor (Q minimum) is of importance in oscillation circuits. For instance, how aboutthis onewith Qmin=140 and Rser=15mOhm?

author: T3sl4co1l
author_rank: Super Contributor
timestamp: October 25, 2020, 08:45:47 pm
content: That's quite a nice Q, and it's measured at a nearby frequency (2.52MHz) so should be nice. Is rather big though.Shouldn't the inductors be coupled, for Hartley?Tim

author: Zero999
author_rank: Super Contributor
timestamp: October 25, 2020, 09:21:34 pm
content: Quote from: kalj on October 25, 2020, 08:32:02 pmDon't take the simulation too seriously. The 74HC4060 has a much wider bandwidth than the HEF4007, so should work with a higher ESR inductor. The one you've found on Mouser appears to be suitable.Quote from: T3sl4co1l on October 25, 2020, 08:45:47 pmIt will work with non-coupled inductors.https://en.wikipedia.org/wiki/Hartley_oscillator

author: T3sl4co1l
author_rank: Super Contributor
timestamp: October 25, 2020, 11:54:17 pm
content: Quote from: Zero999 on October 25, 2020, 09:21:34 pmI know it works without. It might work over a wider range with.Tim

author: David Hess
author_rank: Super Contributor
timestamp: October 25, 2020, 11:56:52 pm
content: Quote from: IDEngineer on October 24, 2020, 02:35:51 pmLTC1043 charge balancing voltage-to-frequency converters can easily achieve a resolution (not accuracy) of 18 bits and higher. The best voltage-to-frequency designs perform comparably with 20 to 24 bit delta-sigma converters but the later are much less expensive now. With a 1000 picofarad pumping capacitor, that yields a resolution of better than 0.003 picofarads and I have seen that kind of performance when tracking down linearity errors. Accuracy is limited by temperature compensation of the capacitor which is where -120ppm/C resistors for compensating polystyrene capacitors come from.The advantage of the CTMU is low cost and fast measurement speed. It would be excellent in this application but not because of improved accuracy or resolution.The LC oscillator method is also very suitable simply because that is what the radio originally used.

author: mag_therm
author_rank: Frequent Contributor
timestamp: October 26, 2020, 12:55:21 pm
content: Quote from: T3sl4co1l on October 25, 2020, 11:54:17 pmSolutions for the reactive components of the Hartley loops in the Class A case:M is mutual inductance between the two inductorsequations below are approximationsneeded_volt_Gain_mu = [(L_o + M)/L_fb + M)] + F_resonant = [ 2*pi*sqrt(L_fb_ + L_o + 2*M) *C ]^-1f_actual = F_resonant * ( 1 + resistive_components_inclusion)Kalj will most likely use one of two choices:Store bought separate inductors where M = 0 :needed_volt_Gain_mu = [L_o /L_fb ] + A wound ferrite toroid with a feedback tap where M = sqrt(L_fb * L_o)needed_volt_Gain_mu = [(L_o + M)/L_fb + M)]} + Simulator should show the above cases, and a hand calculation using the above can show that the oscillator is mostly in Class A.That is because the tank circuit acts as a filter so the time varying output will appear sinusoidal even in Class C.If the oscillator runs toward Class C (meaning over-drive) , the efficiency improves, but accuracy reduces as non-linearity may be temperature dependant,and rail voltage can have ripple etc.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: October 26, 2020, 01:13:52 pm
content: A bit of TL:DR.The combination of a current source and a 555 is not very good for stability.The constant current source wil be somewhat stable regardless of power supply voltage, while the 555 thresholds change with the power supply voltage.The CC circuit will also change current with the temperature of the transistor (Vbe changes about 2-mV/degree Celcius)Replacing the CC circuit with a simple resistor will give more stable results, as then both charge rate and threshold voltage changes cancel each other out.Some 15+ years ago there was a popular LC meter based on a LC oscillator made from some passives and and opamp or comparator, and a microcontroller to to measure the frequency, but it seems previous posts already suggested similar directions.Also: Probing around with your scope probe is not the best way to get accurate results. First, simply by attaching your scope probe you change capacitances, and just the proximity of your hands, and changing position of them may change the behavior of the circuit.

author: IDEngineer
author_rank: Super Contributor
timestamp: October 26, 2020, 04:00:06 pm
content: Quote from: David Hess on October 25, 2020, 11:56:52 pmAgreed, and I wasn't suggesting it would yield vastly superior accuracy or resolution. But it would be sufficient (the definition of good Engineering), and would meet the OP's criteria:QuoteThe CTMU approach would give him what he asked for in a one-chip solution, plus give him significant flexibility in its control and behavior via firmware (on that same single chip). There are many possible solutions to this challenge (as evidenced by this thread) but so far the CTMU is the simplest, most straightforward, and most flexible given the OP's original criteria. Some of the other proposals herein are definitely more technically interesting and I'd love to pursue them for the personal enrichment, but I'm trying to keep my eyes on the OP's original plan without creeping featurism.

author: kalj
author_rank: Contributor
timestamp: November 04, 2020, 07:57:11 pm
content: I have been busy with other things, but finally now got the chance to look into this. I've built two circuits with a Hartley and a Colpitts oscillator respectively. In both cases, the component values in the simulation by Zero999 have been used, except for C1 in the Colpitts oscillator which was chosen as 1nF to increase the frequency range. I also added 100nF decoupling capacitors to both circuits. The IC is the CD74HCT4060E.In both cases I get good oscillations in the 1-5MHz range, and the counter outputs are toggling correspondingly. However, in both cases the oscillation amplitude decreases sharply with high frequency / decreasing capacitance, to the extent that for the last 20% of the varcap the oscillations are to small to correctly trigger the counter.To see if this was due to a too high frequency, I tried increasing the inductance in the Colpits oscillator, to 100µH instead of 10µH. The frequency was lowered as expected, but the amplitude attenuation seemed to behave the same, with oscillations dying out at the same capacitance.Any clue what might be causing this problem? Can it be that 14pF is too low a value compared to the ESR of the circuit?

author: Doctorandus_P
author_rank: Super Contributor
timestamp: November 06, 2020, 04:27:08 pm
content: Why not simply build an oscillator with a 555?

author: kalj
author_rank: Contributor
timestamp: November 06, 2020, 05:50:41 pm
content: Quote from: Doctorandus_P on November 06, 2020, 04:27:08 pmYou didn't read the first post did you?

author: pwlps
author_rank: Frequent Contributor
timestamp: November 06, 2020, 05:55:25 pm
content: Quote from: Doctorandus_P on November 06, 2020, 04:27:08 pmIt has apparently been built already, see post #1.QuoteWhich CC circuit ?

author: Zero999
author_rank: Super Contributor
timestamp: November 07, 2020, 12:43:24 pm
content: Quote from: T3sl4co1l on October 25, 2020, 11:54:17 pmYes, coupled inductors would be better. A common mode choke could be used.

author: andrewstuart
author_rank: Newbie
timestamp: January 10, 2022, 08:09:51 pm
content: I solved this using an esp8266 with the ADC and no extra components.For reasons I have not been able to work out, I could not implement the same solution using any other microcontroller - the readings are too unstable to use. i tried an esp32 and an RP2040.Here is the working Arduino code:Code:const int OUT_PIN = 16; //D0 // esp8266const int IN_PIN = A0; // esp8266int iteration = 0;const int numReadings = 50; // the number of times we sample the tuning capacitor to smooth out jittersconst int capacitorValueRange = 130; // the range of numbers that can be obtained from the tuning capacitorconst int capacitorValueOffset = 760; // the range of numbers that can be obtained from the tuning capacitorfloat frequencyTable; // a table of the count of the number of times each capacitor value occurs// NOTE: the term "frequency" here has nothing to do with radio frequency, it is the count of times a reading is obtainedvoid setup() {Serial.begin(115200);pinMode(OUT_PIN, OUTPUT);pinMode(IN_PIN, INPUT);}void loop() {// zero out the frequencyTablefor (int i = 0; i < capacitorValueRange; i++) {frequencyTable = 0;}iteration = 0;while (iteration < numReadings) {// write some voltage to the tuning capacitor to charge itdigitalWrite(OUT_PIN, HIGH);// read the value of the tuning capacitorint ADCValue = analogRead(IN_PIN);// count how many times we see each capacitor readingfrequencyTable[ADCValue - capacitorValueOffset]++;// discharge the tuning capacitordigitalWrite(OUT_PIN, LOW);// a 10 millisecond delay seems to stabilize the value read from the ADC/variable capacitor/tunerdelay(10);iteration++;};// the "mode" is a mathematical term refering to the most common number in a sequence of numbers// we use the mode to smooth out the little bit of jitter that comes when reading the tuning capacitorint mode = 0;int previousMaxFound = 0;for (int i = 0; i < capacitorValueRange; i++) {if (frequencyTable > previousMaxFound) {mode = i;previousMaxFound = frequencyTable;}}Serial.print("mode: ");Serial.println(mode + capacitorValueOffset);delay(200);}