Path:
Home =>
AVR overview =>
Applications =>
DCF77 receivers =>
32kHz Superhet => Xtal oscillator
Diese Seite in Deutsch:
 |
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
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 kHz | 77.5 – 32.768 = 44.732 kHz |
Divider | f is (kHz) | Delta % | Delta (Hz) | Divider | f is (kHz) | Delta % | Delta (Hz) |
1.843200 | 8 | 115.200 | 4.47 | 4932.0 | 21 | 43.886 | 1.89 | -846.3 |
2.000000 | 9 | 111.111 | 0.76 | 843.1 | 22 | 45.455 | 1.62 | 722.5 |
2.097152 | 10 | 104.858 | 4.91 | -5410.4 | 23 | 45.590 | 1.92 | 858.3 |
2.457600 | 11 | 111.709 | 1.31 | 1441.1 | 27 | 45.511 | 1.74 | 779.1 |
2.500000 | 11 | 113.636 | 3.05 | 3368.4 | 28 | 44.643 | 0.20 | -89.1 |
3.000000 | 14 | 107.143 | 2.83 | -3125.1 | 34 | 44.118 | 1.37 | -614.4 |
3.072000 | 14 | 109.714 | 0.50 | -553.7 | 34 | 45.176 | 0.99 | 444.5 |
3.276800 | 15 | 109.227 | 0.94 | -1041.3 | 37 | 44.281 | 1.01 | -450.9 |
3.579545 | 16 | 111.861 | 1.44 | 1592.8 | 40 | 44.744 | 0.03 | 12.3 |
3.686400 | 17 | 108.424 | 1.67 | -1844.5 | 41 | 44.956 | 0.50 | 224.1 |
3.686411 | 17 | 108.424 | 1.67 | -1844.1 | 41 | 44.956 | 0.50 | 224.2 |
3.932160 | 18 | 109.227 | 0.94 | -1041.3 | 44 | 44.684 | 0.11 | -48.4 |
4.000000 | 18 | 111.111 | 0.76 | 843.1 | 45 | 44.444 | 0.64 | -287.6 |
4.096000 | 19 | 107.789 | 2.25 | -2478.5 | 46 | 44.522 | 0.47 | -210.3 |
4.194304 | 19 | 110.376 | 0.10 | 108.4 | 47 | 44.620 | 0.25 | -111.7 |
4.433619 | 20 | 110.840 | 0.52 | 572.5 | 50 | 44.336 | 0.88 | -395.8 |
4.915200 | 22 | 111.709 | 1.31 | 1441.1 | 55 | 44.684 | 0.11 | -48.4 |
5.000000 | 23 | 108.696 | 1.43 | -1572.3 | 56 | 44.643 | 0.20 | -89.1 |
5.068800 | 23 | 110.191 | 0.07 | -76.7 | 57 | 44.463 | 0.60 | -268.8 |
5.120000 | 23 | 111.304 | 0.94 | 1036.3 | 57 | 44.912 | 0.40 | 180.3 |
5.200000 | 24 | 108.333 | 1.75 | -1934.7 | 58 | 44.828 | 0.21 | 95.6 |
6.000000 | 27 | 111.111 | 0.76 | 843.1 | 67 | 44.776 | 0.10 | 44.1 |
6.000000 | 27 | 111.111 | 0.76 | 843.1 | 67 | 44.776 | 0.10 | 44.1 |
6.144000 | 28 | 109.714 | 0.50 | -553.7 | 69 | 44.522 | 0.47 | -210.3 |
6.400000 | 29 | 110.345 | 0.07 | 76.8 | 72 | 44.444 | 0.64 | -287.6 |
6.553600 | 30 | 109.227 | 0.94 | -1041.3 | 73 | 44.888 | 0.35 | 155.7 |
7.372800 | 33 | 111.709 | 1.31 | 1441.1 | 82 | 44.956 | 0.50 | 224.1 |
8.000000 | 36 | 111.111 | 0.76 | 843.1 | 89 | 44.944 | 0.47 | 211.8 |
8.000000 | 36 | 111.111 | 0.76 | 843.1 | 89 | 44.944 | 0.47 | 211.8 |
8.867238 | 40 | 110.840 | 0.52 | 572.5 | 99 | 44.784 | 0.12 | 52.0 |
9.216000 | 42 | 109.714 | 0.50 | -553.7 | 103 | 44.738 | 0.01 | 5.9 |
9.830400 | 45 | 109.227 | 0.94 | -1041.3 | 110 | 44.684 | 0.11 | -48.4 |
10.000000 | 45 | 111.111 | 0.76 | 843.1 | 112 | 44.643 | 0.20 | -89.1 |
10.000000 | 45 | 111.111 | 0.76 | 843.1 | 112 | 44.643 | 0.20 | -89.1 |
10.240000 | 46 | 111.304 | 0.94 | 1036.3 | 114 | 44.912 | 0.40 | 180.3 |
10.700000 | 49 | 109.184 | 0.98 | -1084.3 | 120 | 44.583 | 0.33 | -148.7 |
11.000000 | 50 | 110.000 | 0.24 | -268.0 | 123 | 44.715 | 0.04 | -16.6 |
11.059200 | 50 | 110.592 | 0.29 | 324.0 | 124 | 44.594 | 0.31 | -138.5 |
12.000000 | 54 | 111.111 | 0.76 | 843.1 | 134 | 44.776 | 0.10 | 44.1 |
12.000000 | 54 | 111.111 | 0.76 | 843.1 | 134 | 44.776 | 0.10 | 44.1 |
12.288000 | 56 | 109.714 | 0.50 | -553.7 | 137 | 44.847 | 0.26 | 114.7 |
12.750000 | 58 | 109.914 | 0.32 | -354.2 | 143 | 44.580 | 0.34 | -151.6 |
14.000000 | 63 | 111.111 | 0.76 | 843.1 | 156 | 44.872 | 0.31 | 139.8 |
14.318000 | 65 | 110.138 | 0.12 | -129.5 | 160 | 44.744 | 0.03 | 11.7 |
14.745600 | 67 | 110.042 | 0.21 | -226.2 | 165 | 44.684 | 0.11 | -48.4 |
15.000000 | 68 | 110.294 | 0.02 | 26.1 | 168 | 44.643 | 0.20 | -89.1 |
16.000000 | 73 | 109.589 | 0.62 | -679.0 | 179 | 44.693 | 0.09 | -39.3 |
18.000000 | 82 | 109.756 | 0.46 | -511.9 | 201 | 44.776 | 0.10 | 44.1 |
18.432000 | 84 | 109.714 | 0.50 | -553.7 | 206 | 44.738 | 0.01 | 5.9 |
20.000000 | 91 | 109.890 | 0.34 | -377.9 | 224 | 44.643 | 0.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.
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.
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
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
- a variation of the two capacitors, or
- dividing the XTAL2/CLKO output pin's voltage with resistors, or
- adding a 1MΩ resistor parallel to the xtal to increase
back-coupling of the CLKI/CLKO inverter
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
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.
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:
- The two output pins OC0A and OC0B are configured as outputs.
- The port register of OC0A is cleared, the one for OC0B is set
to one (reversed signal)./li>
- Both compare values are set to the divider factor (divider
minus 1).
- In the control port TCCR0A of timer TC0 the CTC mode is set
and both output pins are defined to toggle on compare match.
- In control port TCCR0B the timer is started with a prescaler
value of 1.
- 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:
- CLKDIV8 has to be disabled.
- 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
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.
This is the version with the integrated xtal oscillator.
©2019-2020 by http://www.avr-asm-tutorial.net