Path: Home => AVR overview => Applications => DCF77 receivers => 32kHz Superhet => Xtal oscillator   Diese Seite in Deutsch: Flag DE
DCF77 receiver logo Applications of
AVR single chip controllers AT90S, ATtiny, ATmega and ATxmega
Crystal oscillator for the DCF77 superhet receiver

4 DCF77 superhet receiver with xtal filter

4.2 The superhet schematic

4.2.2 TCA440 with an external oscillator

Note that previous versions had errors, the oscillator works fine now. Concept using a crystal oscillator as basis

LC resonance circuits are slightly temperature sensitive, so that its frequency has to be adjusted from time to time. Under long term operation and with some aging of parts, this has some disadvantages. An alternative to the LC would be to generate the oscillator frequency from a xtal-controlled base frequency, by dividing that with a fixed rate.

Of course, there are no 110.268 or 44.732 kHz on the market. This solution here uses a xtal clocked AVR as a rectangle generator.

An AVR, here an ATtiny25, is clocked by an external xtal oscillator. Its timer/counter 0 works as a divider (in CTC mode), divides the clock frequency by a fixed rate and toggles the compare outputs A and B on compare match. By starting outputs A and B with different start conditions, it produces counter-phased rectangles. The rectangles are filtered with an RC network, that yields sine waves that can drive the TCA440's oscillator inputs with a symmetric sine wave signal. Selecting´the crystal frequency

Digital dividers can only divide by integer values. Therefore the xtal frequency, divided by the divider, has to fit nearest to the desired TCA440 oscillator frequency. To find the nearest fit I have listed all available xtals in a spreadsheet and did some calculations with those.

In the table the higher (110.268 - 77.5 = 32.768 kHz as well as the lower (77.5 - 44.732 = 32.768 kHz are considered. The divider is calculated, the divider determined and the factually generated frequency f is as well as its absolute deviation in percent and in +/- Hz is listed. The table is available here as OpenOffice file.

The table holds a second sheet, listing xtal oscillators only. There are fewer, but also some frequencies that are not available as discrete xtal. The output of the crystal oscillator is connected to the ATtiny25's XTAL1 pin. The CLKOUT fuse can, but must not be activated. The calculation sheet "xtal_oscillator" lists that.

Please note that the divider toggles the OC0 pins, so that two toggles are necessary for one wave. The frequency therefore is half of the compare value (+1).

77.5 + 32.768 = 110.268 kHz77.5 – 32.768 = 44.732 kHz
Dividerf is
Dividerf is

When mixing the 77.5 kHz input signal with the higher frequency (+32.768  = 110.268 kHz) the 15 MHz xtal has the smallest deviation (0.02%, +26.1 Hz). The crystals 5.0688 and 6.4 MHz deviate by 0.07% or 77 Hz and the xtal 4.194304 MHz by 0.1% or 108 Hz. When mixing with the lower frequency (77.5 - 32.768 = 44.732 kHz) the 9.216 MHz- crystal fits best, with 0.01% or 5.9 Hz deviation.

When mixing with 44.732 kHz the first harmonic (89.46 Hz) is in the wider range of the input frequency. Therefore interferences cannot be excluded, therefore the 15 MHz xtal was chosen. This deviates by 26.1 Hz upwards. Rectangles to sine waves

Any ATtiny has an 8-bit counter/timer with OC0A and OC0B output. The two pins can generate a symmetric output signal: OC0B generates the opposite signal by starting with a high instead of a low port-bit. So, the oscillator signal can be fed symmetrically to the oscillator input of the TCA440.

On both outputs, OC0A and OC0B, rectangular signals are made. Using those rectangles for mixing would have adverse consequences, as rectangles consist of all uneven harmonics of the base frequency. It is better if those harmonics are filtered off by use of a three stage RC network.

The calculation spreadsheet OpenOffice file here has a sheet named "Rectangle2Sine", where I played with different RC combinations. To have a large-enough signal the filter should not damp the base frequency too much, but only the third (and beyond) harmonic.

To limit the number of components three RC filter stages have been combined. Finally I selected a combination of 1kΩ and 1nF. The loss of amplitude is limited and the harmonics are well suppressed with that.

Rectangle-to-Sine wave conversion This displays the filter effect of the three stages, as calculated with the spreadsheet.

The first stage (V(C1), blue curve) still is nearly fully reaching the operating voltage limits. In the second stage (V(C2), the red curve) the amplitude swing is smaller and the form is nearer to a sine wave. In the third stage (V(C3), green curve) the amplitude loss is lower and the wave is a nearly perfect sine.

Reverse phase and supply currents Displayed above is only one signal, the second is reversed, as can be seen in this picture. This includes, in green and on the right side scale, the operating supply currents through the PWM output pins during these phases. These are roughly 3.2 mA by average, but reach slightly above 8 mA in the peaks.

With that signal mixing can be made. The schematic with a discrete crystal

Schematic of a 110kHz oscillator with a discrete crystal The schematic is rather simple: the timer outputs OC0A and OC0B generate the reversely clocked rectangle of 110.294 kHz, to be filtered in three RC stages. The oscillator inputs on pin 4 and 5 of the TCA440 receive that signal.

The reset input of the ATtiny25 are, via a resistor of 10 kΩ, tied to the operating voltage of 3.3 V. The xtal of 15 MHz is connected to the XTAL inputs, each with a capacitor of 18 pF to GND.

In practice, the xtal didn't swing above an operating voltage of 4 V. Even did not resolve that problem. The operating voltage was therefore reduced with a resistor, a Zener diode and an electrolytic capacitor to suppress Zener random noise. In addition I realized that removing the standard CMOS ceramic capacitor on the supply pin increased swinging of the xtal. Mounting of this capacitor directly to VCC completely shut down swinging. Starting swinging was increased by delaying reset with a small electrolytic capacitor. With all that measures the oscillation is reliable, but small signals on the supply line can still stop oscillation.

I call this unbelievable behavior "reverse BOD level effect". Reversed because applying more than 4V stops oscillation. The schematic with an integrated xtal oscillator

Schematic of an integrated xtal oscillator for the 110kHz oscillator This is the schematic using an integrated crystal oscillator. That works at 5 V operating voltage and does not have any other limitations like above described. Even though this type of xtal oscillators produce a horrible rectangular signal (anything else than a steap up and down), it works perfect with an ATtiny25.

Oscillogram of the generated sine waves These are the two sine waves of the two generated signals. Looks clean. Software for the ATtiny25

The software for the ATtiny25 consists of a few lines assembler:
  1. The two output pins OC0A and OC0B are configured as outputs.
  2. The port register of OC0A is cleared, the one for OC0B is set to one (reversed signal)./li>
  3. Both compare values are set to the divider factor (divider minus 1).
  4. In the control port TCCR0A of timer TC0 the CTC mode is set and both output pins are defined to toggle on compare match.
  5. In control port TCCR0B the timer is started with a prescaler value of 1.
  6. The sleep mode of the controller is set to idle mode, the SLEEP instruction is executed and the controller is not needed any further.
The source code is listed here and can be downloaded in assembler format here.

; *********************************
; * Xtal oscillator for TCA440    *
; * 15 MHz ==> (77.5+32.768 kHz)  *
; * (C)2019 by DG4FAC             *
; *********************************
.include "" ; Define device ATtiny25
; **********************************
;     H A R D W A R E
; **********************************
; Device: ATtiny25, Package: 8-pin-PDIP_SOIC
;            _________
;         1 /         |8
; RESET o--|RESET  VCC|--o +5 V
; XTAL1 o--|PB3    PB2|--o
; XTAL2 o--|PB4    PB1|--o Osc out -
;   0 V o--|GND    PB0|--o Osc out +
;         4|__________|5
; **********************************
;   F I X E D   C O N S T A N T S
; **********************************
.equ clock = 15000000 ; 15 MHz
.equ fosc = 77500+32768 ; Added
.equ divider = (clock+fosc)/(fosc*2)
.equ cCtc = divider - 1 ; CTC value
; **********************************
;        R E G I S T E R S
; **********************************
.def rmp = R16 ; Multipurpose register
; **********************************
;  M A I N   P R O G R A M   I N I T
; **********************************
.org 000000
  sbi DDRB,DDB0 ; PB0 direction output
  cbi PORTB,PORTB0 ; Clear OC0A output
  sbi DDRB,DDB1 ; PB1 direction output
  sbi PORTB,PORTB1 ; Set OC0B output 
  ldi rmp,cCtc ; Write CTC value
  out OCR0A,rmp ; to compare register A
  out OCR0B,rmp ; and B
  ldi rmp,(1<<WGM01)|(1<<COM0A0)|(1<<COM0B0) ; CTC mode, toggle OC0A
  out TCCR0A,rmp ; in TC0 control port A
  ldi rmp,(1<<CS00) ; Prescaler = 1
  out TCCR0B,rmp ; in TC0 control port B
  ldi rmp,1<<SE ; Sleep enable, idle mode
  out MCUCR,rmp
  sleep ; Go to sleep
  rjmp loop
; End of source code Fuses of the ATtiny25

Prior to or after programming the flash the fuses of the ATtiny25 have to be set to work with the external xtal or xtal oscillator. The following fuses have to be set with a discrete crystal:
  1. CLKDIV8 has to be disabled.
  2. The clock frequency has to be set to an external oscillator of more than 8 MHz. Mounting the xtal sine wave generator

Oscillator on the breadboard This is the sine wave generator on a breadboard, here with a discrete crystal. The six capacitors right to the ATtiny25 form the three RC networks for sine wave filtering.

Oscillator with integrated xtal oscillator on a breadboard This is the version with the integrated xtal oscillator.

©2019-2020 by