Path:
Home =>
AVR-EN =>
Applications =>
AVR-D/A-Converter =>
DAC-Filter => RC filter
Diese Seite in Deutsch:
 |
Tutorial for learning the AVR assembly language of
AVR single chip controllers AT90S, ATtiny, ATmega and ATxmega
of ATMEL usind practical examples.
A simple 8-bit-Digital-to-Analog-Converter with a R/2R network
Flexible RC filter for the R/2R network |
Flexible RC filter with 4051
If you generate sine waves with very different frequencies, you'll have the problem
that the RC-filter network has to be adjusted to fit to those frequencies and the
harmonics produced. This here helps: it switches eight different capacitors to the
RC network. The capacitors can be selected digitally. This can be used e.g. for the
sine generator with an ATmega324
here.
In this device, the port pins PA5 to PA7 are unused and can be used to switch the
capacitor with the 4051-input pins A, B and C.
The hardware
This is the hardware. It consists of two analog multiplexer ICs of the type 4051.
Switched are eight different capacitors C1 to C8, the resistor is fixed. The input
pins A, B and C select the capacitor.
In this scheme the negative operating voltage VEE is tied to zero Volts (no negative
voltages possible). The input signal therefore has to stay at zero Volt or above.
Therefore the DC separation capacitor must follow the RC network, its input goes to
the output pin of the oerational amplifier behind the R/2R network.
Selection of R and C1 to C8
As selecting R and C is not trivial, I have written a program in Lazarus that calculates
the attenuations of RC networks by frequency. I fixed R at 2,2 kΩ, which
provides enough output impedancies. The C's range from 220 pF to 680 nF. As
can be seen, the factor 3 of the capacitor values covers the frequency range between
10 Hz and 100 kHz. If you want to reduce the frequency range a little bit,
a factor of 2 or 1.5 can be used for the values of the capacitors.
The capacitors are suitable for frequencies, where the attenuation remains below a
factor of 2. The diagram therefore displays the 0.5 line.
This cutoff frequency can be calculated from the capatitor value with this equation:
f0.5 = e-ln(C)-10
The other way round: to calculate the capacitor from the cutoff frequency use this
equation:
C = e-ln(f0.5)-10
In both formulas f is in Hz and C is in Farad.
The cutoff frequencies of the eight capacitors with R=2k2 are listed in the table.
Additionally the table lists
- the resolution of the R/2R network Res in this frequency range,
- the lower frequency of the range fl and the upper
fu cutoff frequency, and
- the attenuation factors Al and Au.
Cn | C | f0.5 (Hz) | Res | fl(Hz) |
fu(Hz) | Al | Au |
C1 | 680 nF | 66.5 | 256 | 10 | 66.5 | 643 | 17,143 |
C2 | 220 nF | 205.7 | 256 | 66.5 | 205.7 | 2,828 | 17,143 |
C3 | 68 nF | 665.4 | 256 | 205.7 | 665.4 | 2,773 | 18,079 |
C4 | 22 nF | 2,056.8 | 128 | 665.4 | 2,056.8 | 748 | 6,005 |
C5 | 6.8 nF | 6,654.4 | 64 | 2,056.8 | 6,654.4 | 165 | 1,781 |
C6 | 2.2 nF | 20,568.1 | 8 | 6,654.4 | 20,568.1 | 4.7 | 27.9 |
C7 | 680 pF | 66,544.0 | 8 | 20,568.1 | 66,544.0 | 5.0 | 28.7 |
C8 | 220 pF | 205,681.4 | 8 | 66,544.0 | 205,681.4 | 1.8 | - |
The attenuations at very high frequencies are not sufficient to suppress harmonics. The
frequencies up to 20kHz are correct.
Calculating A, B and C with an AVR
If a frequency f, that is given in mHz, the correct capacitor (A, B and C) can be
calculated from the below table that holds the cutoff frequencies in mHz (as 32 bit
numbers).
FTable:
.dw 0x03F0,0x0001 ; C =680 nF, f 1/2= 66.544 Hz
.dw 0x2371,0x0003 ; C =220 nF, f 1/2= 205.681 Hz
.dw 0x2760,0x000A ; C =68 nF, f 1/2= 665.440 Hz
.dw 0x626E,0x001F ; C =22 nF, f 1/2= 2.057 kHz
.dw 0x89BD,0x0065 ; C =6.8 nF, f 1/2= 6.654 kHz
.dw 0xD847,0x0139 ; C =2.2 nF, f 1/2= 20.568 kHz
.dw 0x6163,0x03F7 ; C =680 pF, f 1/2= 66.544 kHz
.dw 0x72CA,0x0C42 ; C =220 pF, f 1/2= 205.681 kHz
With a counter that starts at zero, we pass through the values of the table
and compare the 32 bit frequency in mHz with those. If comparison yields the
carry flag set, we skip the passes. If not, we either add 1 (to yield values
between 0 and 7) with SUBI rCounter,-1 or we add 1<<5 (to yield
values between 0b0000,0000 and 0b1110,0000 in the upper three bits) with
SUBI rCount,-(1<<5).
To the top of this page
©2020 by http://www.avr-asm-tutorial.net