Continued from Part 1 -- Introduction and Concepts.
| Part 1 | Oscillator Section |
| Part 2 | Wave shaper and AGC |
| Part 3 | Microcontroller Section |
Q2 is mirrored by Q4, and the emitter current of Q2 (which also contains the oscillatory component) is equally found at the emitter of Q4. The resulting voltage drop across R2 is stripped of its DC component with C4. Q4 is primarily a means to draw the oscillation from Q1/Q2 with a high impedance presented to the oscillator core. C4 couples the oscillation into a conventional common-emitter one-transistor amplifier stage around Q5. R3 and R4 determine the DC operating point of Q5, and R6 stabilizes the operating point through negative DC feedback. C5 ensures that the emitter of Q5 is AC-coupled to ground. The AC signal, amplified approximately 20x, is drawn from the collector of Q5.
In extension to the principle schematic, the full schematic includes power supply bypass capacitors (C6...C9). A selector switch was provided to select different capacitors for the resonant LC tank. The selector switch also provides logic levels for the microcontroller to read the switch position. Larger inductors may cause significant transients when the switch is actuated while the circuit is powered, and these transients ar absorbed by the Zener diodes Z1 and Z2.
Along the second path (C13), the signal is again stripped of its DC component (with R12) and rectified (D1). D1 together with R13 and C22 form a peak detector that is buffered with op-amp U1a. The output of U1a therefore carries the amplitude of the oscillator sine wave reduced by the forward voltage of D1 (not very relevant, because the forward voltage threshold acts on small amplitudes where the amplitude gain is maxed out anyway). From the output of U1a the amplitude can be read by the microcontroller. In addition, the amplitude is subtracted from a 2.8V reference point and amplified 10x (U1b). By using the output of the inverting amplifier U1b as the input to the oscillator current source Q3, negative feedback is established that allows to attenuate large-amplitude oscillations.
This section also contains the power supply. The circuit is insensitive to supply voltage variations from about 9V to 12V, and three, 18650 Li-ion cells (or a 12V wall adapter) are suitable to provide the supply power. The circuit draws less than 40mA. For the digital part, a 7805 linear regulator (U3) is used, and its input further decoupled from the analog section with R7 and D3. The decoupled almost-12V supply (designated 12VA) is also used for U1, which prevents unwanted feedback along the power supply loop.
One input to the MCU's built-in analog-to-digital converter is used to measure the amplitude of the oscillation (from U1a via R21 and C27). Two of the three selector signals from the LC tank capacitor selector switch are evaluated, and a pushbutton is also provided. The pushbutton, as well as the LED D4 have been provided "just because" with initially no dedicated purpose. A LCD is provided, and the CPU can be programmed in-circuit at the programming header CN3.
We can now return to the LC tank frequency equation,
\[f = \frac{1}{2 \pi \sqrt{L C} } \]
and solve it for the unknown inductor L:
\[L = \frac{1}{(2 \pi f)^2 C } = \frac{a}{f^2}\]
The constants can be combined into a lump coefficient \( a \). This is important, because I based the computation on a 32-bit integer math library that I developed for high-speed applications. Of course, the use of floating-point math with, for example Arduino C, is entirely possible as an alternative approach, especially since there is no time-critical element in the software apart from the 200ms gate. With a 32-bit integer division available, the frequency scaling factor of 160 can be moved into the coefficient \( a\). Furthermore, \( a \) can be scaled to yield the inductance in units of 100nH. We now have
\[L = \left( \frac{1}{(2 \pi)^2 C } \cdot \frac{10^7}{160^2 \cdot 16^2} \right) \cdot \frac{1}{\hat{f}^2} \]
where C is given in pF and \( \hat{f} \) is the value read directly from TMR1, i.e., the frequency scaled down by 160, which is in turn divided by 16 (i.e., actual frequency in Hz, divided by 2560) to prevent numerical overflows. For the three capacitor values, we found \( a \) as
In in Part 3 of this article, we'll now cover the prototype and the final device.