AN123 Silicon_Laboratories, AN123 Datasheet - Page 3

no-image

AN123

Manufacturer Part Number
AN123
Description
Using THE DAC AS A Function Generator
Manufacturer
Silicon_Laboratories
Datasheet
value. An efficient way to implement this operation
is to XOR the 2’s complement value with 0x8000.
Table Defined Waveforms
As mentioned above, waveform generation consists
of three stages before samples are written to the
DAC. The output of the first stage, which
determines the full scale output value, can either
result from a calculation or a table lookup. A
lookup table can be used if the output is not quickly
or easily calculated. The main trade-off is sampling
speed vs. code size.
Phase Error
Figure 1 shows one period of a sine wave. A
lookup table containing 256 samples of this
waveform is used to approximate a true sine wave.
Keep in mind that the lookup table can
approximate any other periodic waveform. If the
output is set to “sine wave” at the command
prompt, the Timer 4 ISR performs a lookup to
obtain the output, using the eight most significant
bits of the phase accumulator as the table index.
The truncation to 8-bits introduces an error which
can be interpreted as an instantaneous phase error
or a slight error in the waveform amplitude. The
frequency resolution, which is determined by the
16-bit accumulator, is not affected by the truncation
because the error is not accumulated across
multiple samples.
Amplitude Error
Amplitude error can be introduced from two
sources, a low resolution amplitude or phase axis.
Since the DAC has a 12-bit output resolution, error
resulting from the amplitude axis can be eliminated
by storing 16-bit values in the lookup table. Ampli-
tude error that results from the phase axis can only
be corrected by increasing the number of entries in
the lookup table. Increasing the number of table
entries will stabilize the instantaneous frequency
by reducing the phase error, at the expense of
increased code size.
Rev. 1.1
Calculated Waveforms
Stage one of the Timer 4 ISR calculates the full
scale output value of the waveform corresponding
to the 16-bit phase accumulator. Since using the
full 16-bit precision of the phase accumulator in the
calculation does not require many clock cycles,
both the amplitude and phase error are less than in
table-defined waveforms.
Square Wave
The algorithm used to calculate the output value of
the square wave is quite simple. As shown in
Figure 2, if the phase accumulator is in the first half
of the cycle, then the output is set to the maximum
value of +32767. Otherwise, the output is set to the
minimum value (-32768). The most significant bit
of the phase accumulator contains enough informa-
tion to determine the output value of the square
wave.
Triangle Wave
The calculation of a triangle wave involves the
equation of 2 lines with opposite slope. From
Figure 3, the slope is +2 in the first half and -2 in
the second half.
Saw Tooth Wave
AN123
3

Related parts for AN123