Telegesis (UK) Limited
TG-ETRXn-UG-01-103
25
User Guide
1.04
ETRX1 and ETRX2
©2008 Telegesis (UK) Ltd
ETRXn User Guide (Rev 1.04)
Bit
7
6
5
4
3
2
1
0
Name
FOC2
WGM20
COM21
COM20
WGM21
CS22
CS21
CS20
Value
0
0
0
1
1
x
x
x
Table 4. TCCR2 register
Force Output Compare FOC2: not used here
Waveform Generation Mode WGM2[1:0] = 2: Clear Timer on Compare. Resets the counter to
zero when it equals OCR2
Compare Output Mode COM2[2:0] = 1: toggle output pin when counter equals OCR2 (guarantees
a 50% output duty cycle)
The counter increments at a rate set by the clock prescaler. The rates are determined by the
values of Clock Select CS2[2:0] according to Table 5.
CS22 CS21 CS20
Description
0
0
0
Counter stopped
0
0
1
clk (no prescaling)
0
1
0
clk/8
0
1
1
clk/64
1
0
0
clk/256
1
0
1
clk/1024
1
1
0
External clock
1
1
1
External clock
Table 5. Prescaler ratios
The frequency at the module‟s output pin is given by
f
tone
= 8MHz/(2×(1+OCR2))
where f
clk
is the divided 8MHz clock rate. For example, for a 800Hz tone we need a total division
factor of 5000 which is achievable closely by these combinations:
Prescaler OCR2
1
4999
8
624
64
77
256
19
1024
4
Table 6. Settings for 1kHz tone
Prescaling by 64 gives the best resolution for audio tones, so we set OCR2 = 77 = 0x4D, and
TCCR2 = 00011011b = 0x1B. Hence we set S-register S2F = 4D1B. This is also the default
setting of register S30 causing an audible tone as soon as the special function pin is enabled.
6.1.2 ETRX2 Settings
On the ETRX2 S2F represents the top value of a 16-bit counter incrementing at 12MHz.
Whenever the top value is reached the counter restarts from zero and I/O3 is set.