PHOTO 3. EVEN WITH THE POOR STARTING SIGNAL,
THE FILTER MAKES THE SIGNAL LOOK REASONABLE.
AGAIN, NOTE THE LACK OF DIGITAL NOISE.
PHOTO 4. INCREASING THE FILTER CAPACITOR MAKES THE
SINE WAVE BETTER AT THE EXPENSE OF AMPLITUDE.
You will note that there are different lengths of time
between some of the step pulses. I was trying to make a
1,000 Hz sine wave out of 40 steps. As you can see, it’s not
very good. The problem is the varying step size, but we’ll
come back to that later. Right now, let’s examine the last
two components of the circuit: C2
and R2. These two parts make a low-pass filter to remove the step pulses
and smooth the waveform. Photo 3
shows what the output looks like after
it’s been filtered. Considering the
input, it’s not too bad. There are 2.5
volts of a 1 KHz sine wave that has
5.6% distortion. By changing C2 to
1,000 pF, the distortion drops to
1.25% with 1.0 volts of amplitude
(see Photo 4). This looks much better. Photo 5 shows the spectrum of
the signal. You can see that the third
harmonic is larger than the second
harmonic. This is because of the poor
Unfortunately, the control registers for the I/O control
of the pin are on a different page from the drive control
registers. This means there is a lot of time/cycles lost in
switching back and forth between pages. There are other
low-cost uC manufacturers that have all the I/O registers
The more steps there are in the
waveform, the easier it is to filter
them out. I chose 40 steps because
that created a very clean signal after
the filter. The PIC was running at 4
MHz and was almost completely
occupied with creating the waveform.
The maximum speed for some PIC
uCs is 40 MHz, which means that the
highest frequency waveform that can
be created with 40 steps is 10,000 Hz.
Circle #102 on the Reader Service Card.