Professional Documents
Culture Documents
76
Issue 171
October 2004
CIRCUIT CELLAR
www.circuitcellar.com
collector voltage rises. The rising voltage triggers the MCU to stop the
CIRCUIT CELLAR
Issue 171
697 Hz
770 Hz
852 Hz
941 Hz
1,209 Hz
1
4
7
*
1,336 Hz
2
5
8
0
1,744 Hz
3
6
9
#
1,633 Hz
A
B
C
D
October 2004
77
DTMF DETECTION
The telephone tone dialing system is
called dual-tone multi-frequency (DTMF)
signaling. Its a standard telecommunication system developed by Bell
Laboratories. In this system, a matrix is
used to compose a signal, which consists
of a lower frequency group, containing
four distinct frequencies that are below
1 kHz, and a high-frequency group, containing four distinct frequencies above
1 kHz (see Table 1). Each telephone key
is represented by a pair of simultaneous
low- and high-frequency tones.
To detect DTMF signals by software
in the digital domain, many algorithms
have been proposed. The modified
Goertzel algorithm is one of the most
efficient computing techniques for
detecting a limited number of frequencies. In the case of DTMF tone detection,
the Goertzel algorithm analyzes only
eight frequencies instead of performing
an entire transform using something like
FFT. This saves a lot on computational
resources, which are critical for lowerpower processors. Its noncomplexity is
easy to adapt into small MCUs and
78
Issue 171
October 2004
Listing 1Here you can see the Goertzel DFT filter register usages and the variable definitions.
// GoertzelDFT function Parameters:
// R0: Cosine coefficient of the frequency (premultiplied by 2^16)
//
// Return:
// R0 Magnititude^2 of the filtered frequency
//
// Note:
//
// Gozertzel algorithm:
// Sk[n] = x[n] + 2*coefficient*Sk[n-1] - Sk[n-2]
// Only last N (do once):
// Mag^2 = SK[N]^2 - 2*coefficient*SK[N]*SK[N-1] + SK[N-1]^2
//
// The operation is using fixed point data format
// Upper 18bit is integer part of the real data
// Lower 14bit is fraction port of the real data
//
// Register usage:
// ER0:
Sk[n]
// ER1:
Sk[n-1]
// ER2:
Sk[n-2]
// E3
coefficient * 4
// R3L
loop count
// ER4
input sample pointer
// ER5
for temp reg
******************************************************************
SKN1
.REG
(ER1)
SKN2
.REG
(ER2)
COE:
.REG
(E3)
LPCOUNT
.REG
(R3L)
NEGFLG
.REG
(R3H)
SAMPLEPTR
.REG
(ER4)
SKN1HIGH
.REG
(E1)
SKN1LOW
.REG
(R1)
SKN2HIGH
.REG
(E2)
SKN2LOW
.REG
(R2)
Listing 2And here you see the Goertzel DFT filter assembly codes.
// Function: GoertzelDFT
******************************************************************
GoertzelDFT:
PUSH.L ER2
//ER0 and ER1 don't to save
PUSH.L ER3
PUSH.L ER4
PUSH.L ER5
MOV.W
R0, COE
//save coefficient on R3
SUB.L
SKN1, SKN1
//initial SKN1
SUB.L
SKN2, SKN2
//and SKN2
MOV.L
@_DTMFBUFFPTR,SAMPLEPTR //pointer to first sample
MOV.B
#DTMFCOUNT, LPCOUNT //set loop counts
GozertzelLoop:
MOV.L
SKN1, ER0
//use ER0 for temp reg
BPL
?0010
//if Sk[n-1] is positive, go ahead
NEG.L
ER0
//else change it to positive number
?0010: SHAL.L ER0
//Sk[n-1] * 2
;Multiply lower portion of Sk[n-1] with cosine coefficient
MOV.L
ER0, ER5
//ER5 for fraction(Sk[n-1])
MULXU.W COE, ER5
//fraction(Sk[n-1])*2*Coefficient
MOV.W
E5, R5
//move upper word to lower
EXTU.L ER5
//clear upper word
;Multiply upper portino of Sk[n-1] with cosine coefficient
MOV.W
E0, R0
MULXU.W COE, ER0
//temp=integer(Sk[n-1])*4*Coeff
ADD.L
ER0, ER5
//result is in ER5
MOV.L
SKN1, ER0
//test Sk[n-1]
BPL
?0020
//if postive, do nothing
NEG.L
ER5
//else change result to positive
?0020 SUB.L
ER0,ER0
//clear ER0
(Continued)
CIRCUIT CELLAR
www.circuitcellar.com
Listing 2Continued.
MOV.W
SHLR.L
ADD.L
SUB.L
MOV.L
MOV.L
DEC.B
BNE
SUB.B
MOV.W
BPL
NEG.W
INC.B
?0030: MOV.W
BPL
NEG.W
INC.B
?0040: MOV.L
SHAL.L
MULXU.W
MOV.W
MULXU.W
MULXU.W
MULXU.W
ADD.L
BTST
BEQ
ADD.L
BRA
?0050: SUB.L
?0060: MOV.L
POP.L
POP.L
POP.L
POP.L
RTS
DSP. Therefore, we selected the modified Goertzel DFT for our design.
Like an infinite impulse response (IIR)
filter, a Goertzel algorithm contains a
recursive feedback path. For a DTMF
tone filter, the following calculation
step is performed on incoming data:
2k
Sk [ n ] = x [ n ] + 2 cos
N
Sk [ n 1] Sk [ n 2 ]
2k
= Sk2 [ n ] 2 cos
Sk [ N ]
N
Sk [ N 1] + Sk2 [ N 1]
DTMF GENERATION
The DTMF tone generator is implemented using a D/A converter and
sine wave look-up table, which is a
50-entry byte array representing a complete precalculated sine wave. Two
16-bit timer units drive D/A converters with accurate clock rates. When a
DTMF tone is requested, the two
basic frequencies are selected. The
clock rate for each DAC is determined
with the following equation:
D / A clock rate =
basic DTMF frequency 50
MCU OPERATION
We mixed H8S/2600 assembly and C
languages. Figure 3 is the program flow
chart. When the device is powered on,
the MCU starts a reset process and sets
up the on-chip peripheral I/O modules,
including 16-bit timer units, an ADC, a
DMA controller, D/A converters, and I/O
Issue 171
October 2004
79
Photo 1The bottom is the telephone interface board, which connects to the top evaluation board by a 14-conductor ribbon cable.
80
Issue 171
October 2004
CIRCUIT CELLAR
www.circuitcellar.com
Figure 4JP1 and JP2 are the connectors of the starter kit board. The power supply block is connected to the evaluation board power supply switch 5-V regulated source and
9-V unregulated source. Note the point in-between T1 and R2 is a connection point to the optional audio monitor circuit.
www.circuitcellar.com
CIRCUIT CELLAR
Issue 171
October 2004
83
Mode
Selection
Setting
0+*
1+*
numbers + #
numbers + #
84
Issue 171
October 2004
CIRCUIT CELLAR
PROJECT FILES
To download the code, go to ftp.circuit
cellar.com/pub/Circuit_Cellar/2004/171.
RESOURCES
FCC, Part 68 of the FCC rules,
www.fcc.gov/wcb/iatd/part_68.html.
SOURCES
MC34119 Low-power audio amplifier
Freescale Semiconductor, Inc.
www.freescale.com
H8S/2398 Microcontroller
Renesas Technology Corp.
www.renesas.com
OPA2340 Op-amp
Texas Instruments, Inc.
(972) 644-5580
www.ti.com
www.circuitcellar.com