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
Logo

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.

4.2.2.1 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.

4.2.2.2 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).

Xtal
(MHz)
77.5 + 32.768 = 110.268 kHz77.5 – 32.768 = 44.732 kHz
Dividerf is
(kHz)
Delta
%
Delta
(Hz)
Dividerf is
(kHz)
Delta
%
Delta
(Hz)
1.8432008115.2004.474932.02143.8861.89-846.3
2.0000009111.1110.76843.12245.4551.62722.5
2.09715210104.8584.91-5410.42345.5901.92858.3
2.45760011111.7091.311441.12745.5111.74779.1
2.50000011113.6363.053368.42844.6430.20-89.1
3.00000014107.1432.83-3125.13444.1181.37-614.4
3.07200014109.7140.50-553.73445.1760.99444.5
3.27680015109.2270.94-1041.33744.2811.01-450.9
3.57954516111.8611.441592.84044.7440.0312.3
3.68640017108.4241.67-1844.54144.9560.50224.1
3.68641117108.4241.67-1844.14144.9560.50224.2
3.93216018109.2270.94-1041.34444.6840.11-48.4
4.00000018111.1110.76843.14544.4440.64-287.6
4.09600019107.7892.25-2478.54644.5220.47-210.3
4.19430419110.3760.10108.44744.6200.25-111.7
4.43361920110.8400.52572.55044.3360.88-395.8
4.91520022111.7091.311441.15544.6840.11-48.4
5.00000023108.6961.43-1572.35644.6430.20-89.1
5.06880023110.1910.07-76.75744.4630.60-268.8
5.12000023111.3040.941036.35744.9120.40180.3
5.20000024108.3331.75-1934.75844.8280.2195.6
6.00000027111.1110.76843.16744.7760.1044.1
6.00000027111.1110.76843.16744.7760.1044.1
6.14400028109.7140.50-553.76944.5220.47-210.3
6.40000029110.3450.0776.87244.4440.64-287.6
6.55360030109.2270.94-1041.37344.8880.35155.7
7.37280033111.7091.311441.18244.9560.50224.1
8.00000036111.1110.76843.18944.9440.47211.8
8.00000036111.1110.76843.18944.9440.47211.8
8.86723840110.8400.52572.59944.7840.1252.0
9.21600042109.7140.50-553.710344.7380.015.9
9.83040045109.2270.94-1041.311044.6840.11-48.4
10.00000045111.1110.76843.111244.6430.20-89.1
10.00000045111.1110.76843.111244.6430.20-89.1
10.24000046111.3040.941036.311444.9120.40180.3
10.70000049109.1840.98-1084.312044.5830.33-148.7
11.00000050110.0000.24-268.012344.7150.04-16.6
11.05920050110.5920.29324.012444.5940.31-138.5
12.00000054111.1110.76843.113444.7760.1044.1
12.00000054111.1110.76843.113444.7760.1044.1
12.28800056109.7140.50-553.713744.8470.26114.7
12.75000058109.9140.32-354.214344.5800.34-151.6
14.00000063111.1110.76843.115644.8720.31139.8
14.31800065110.1380.12-129.516044.7440.0311.7
14.74560067110.0420.21-226.216544.6840.11-48.4
15.00000068110.2940.0226.116844.6430.20-89.1
16.00000073109.5890.62-679.017944.6930.09-39.3
18.00000082109.7560.46-511.920144.7760.1044.1
18.43200084109.7140.50-553.720644.7380.015.9
20.00000091109.8900.34-377.922444.6430.20-89.1


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.

4.2.2.3 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.

4.2.2.4 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.

4.2.2.5 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.

4.2.2.6 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             *
; *********************************
;
.nolist
.include "tn25def.inc" ; Define device ATtiny25
.list
;
; **********************************
;     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
; **********************************
;
.cseg
.org 000000
;
Main:
  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
Loop:
  sleep ; Go to sleep
  rjmp loop
;
; End of source code

4.2.2.7 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.

4.2.2.8 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 http://www.avr-asm-tutorial.net