Dec 23rd 2005
Adjustable capacitors are usually limited to the 1-50pF
range, are
very sensitive to changes in temperature, and when you use a
screwdriver to adjust them the screwdriver's pressure screws everything
up. Variable inductors with moving ferrite slugs aren't much better.
I've hated every adjustable passive component I've ever used. Digital
potentiometers are nice and useful, but they aren't cheap and there are
only so many places that you can use them.
Comatose and Afroman present:
Digital capacitors
(and sometimes digital inductors too)
Overview
By manipulating the input/output states on a
microcontroller,
you can effectively switch capacitors in and out of circuit, as long as
the circuit requires one end of the capacitor to be connected to ground
when it is in use. When you set a PIC's tristate buffer bit to be 1, it
makes the pin an input and makes it high impedance as if it is an
open circuit. When you set a PIC's tristate buffer bit to be 0 and set
the data bit to 0, it makes the pin an effective ground. With this
system you can adjust capacitance to whatever you want, with range
being dictated by your choice of capacitors and the resolution
being dictated by the number of microcontroller pins you have
available. This system is suitable for a large number of low
power
circuits. Here are some crappy pictures explaining it:


Using CCS PCWH, setting the tristate buffer's value is as easy as
set_tris_c(capacitancevalue);
Applications
Radio transmission
An extremely cheap and simple FSK data transmitter can be made using
a PIC12F675 and a 555 timer. If you were to output the carrier
frequency directly from the PIC, you would have to use a lot
of resources (timers etc) to generate the carrier, and even
then
you would be limited to a frequency of a few dozen kHz since a PIC
doesn't have much processing power. If you use a digital capacitor
system to modulate the frequency of a wave generated by a 555, you
could have an FSK transmitter operating in the legal ~1Mhz AM band
easily. The code would require minimal resources since all you are
doing is changing the state of 1 microcontroller pin. This leaves you
with plenty of processing power free to do other important things like
preparing the packet data and calculating CRCs.
In this example circuit the 555 is set to oscillate at (theoretically)
1069kHz using R1, R2 and C3. The capacitor C4 connected to the PIC's
pin is just floating around doing nothing for now. When the PIC's pin
changes from high Z input to a digital 0V output, the 33pF capacitor
becomes part of the 555 oscillator, and the frequency changes to
952kHz. To change the frequency back, change the pin's tristate value
to be an input.

Use this
page
to help you calculate the components you need, and remember that all
555 chips are different and many are so shitty that they can't reach
above 100kHz. Also most 555 guides fail to mention how important caps
C1 and C2 are for stable operation, so always use them.
Radio reception
The typical
front end of any radio receiver is an LC circuit approximately
tuned to
the band you are trying to listen into. To tune the radio to a
different band, most hobbyists use mechanical rotary switches that
physically switch components in/out of the circuit, which creates the
problem of finding a switch with multiple positions, and makes
frequency scanning a pain in the ass.
For example here is the front of a classic crystal AM radio receiver, tuned to
530Khz. If you want to tune
it to 1.5Mhz, you either need to mess around with adjustable passive
components or build a heterodyne receiver (not easy for
beginners). If you wanted to
tune into 40Mhz, you would have to physically switch out the
components entirely.
Doing this with a PIC can be done in microseconds, and
requires only basic knowledge of radio receiver and microcontroller
design.




Here is an 8 bit PIC controlled AM radio receiver front end circuit
using a digital capacitor system

I haven't actually made this, but in theory you should be able
to digitally control entire LC filters, and not just
capacitors.

Using
a digitally controlled capacitor and/or LC filter selector, you could
design a radio scanner with
a very wide input range, and never have to mess around with heterodyne
receiver design. The front end LC filters can have very high Q and good
rejection of unwanted frequencies. Since the whole thing is controlled
by a microcontroller, you could make a wide range radio scanner
controlled by your PC's serial port very easily.
Digital
equalizers and
effects sans DSP
To change the bass/midrange/treble in audio
circuits, you
either have to do it with potentiometers in a purely analog solution,
or use a high powered DSP to do all sorts of crazy shit to the audio
data before it even hits the DAC. With a digital capacitor there is
some middle ground, and you can have better control over how
your
music sounds without knowing anything about DSP. What you would do is
create a digital notch filter to attenuate the frequencies of your
choice, then just amplify everything. In most cases a
potentiometer will work great, but if you want to control things
electrically instead of by hand, then a digital pot or digital cap
might be helpful. The audio will sound pretty weird, but that may be
exactly what you want.

Music synthesis &
VFOs
Similar to the FSK idea, you can use a PIC plus a 555 to
make a
ghetto synth (variable frequency oscillator). A PIC16F627A with 8
capacitors on port B would give you an 8 bit synth: 256 possible
oscillation frequencies. You could make a stereo synth with
a PIC16F72, 16 capacitors, and two 555s - use Port B for the
left
channel and Port C for the right channel. Here is a simple 4 bit mono
example using a PIC16F627A. Here
is the video

The source code is as simple as it gets:
void main()
{
int i;
output_b(0);
while(TRUE)
{
for(i=0;i<255;i++)
{
set_tris_b(i);
delay_ms(50);
}
}
}
I have no idea if this stuff is patented or not or if it is being used
in any commercial designs, but I haven't found any webpage mentioning
it despite a lot of searching. In any case I am writing this article
because it is a seriously useful trick for hobbyists to use in their
projects and more people should try it.
Meg