Path: Home => AVR-EN => Applications => AVR-D/A-Converter => DAC-Filter => RC filter   Diese Seite in Deutsch: Flag DE
DAC8 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

Schematic of the 4051-RC-Network 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.

Sine generator with a 4051 RC filter 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

Filter network attenuation vs. frequency 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.

Attenuation curves 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

CnCf0.5 (Hz)Resfl(Hz) fu(Hz)AlAu
C1680 nF66.52561066.564317,143
C2220 nF205.725666.5205.72,82817,143
C368 nF665.4256205.7665.42,77318,079
C422 nF2,056.8128665.42,056.87486,005
C56.8 nF6,654.4642,056.86,654.41651,781
C62.2 nF20,568.186,654.420,568.14.727.9
C7680 pF66,544.0820,568.166,544.05.028.7
C8220 pF205,681.4866,544.0205,681.41.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