DTMF Decoder
by Paul Bergsman
In the Spring 1994 issue of 2600, Xam Killroy described a circuit that decodes Touch-Tone (DTMF) signals and transmits that information to a Commodore 64 or VIC-20 computer.
This article expands on that by detailing how to interface a simple DTMF decoder circuit to an IBM-compatible computer via its parallel port. Since IBM-compatibles comprise the vast majority of existing computers, this solution is fairly universal. Information contained in this article was taken from my new book, Controlling The World With Your PC.
If you don't already own an IBM-compatible computer, older PC/XT and AT-type computers are often available for under $100 at hamfests, auctions, etc. Far from being obsolete, many uses can be found for these inexpensive and ubiquitous computers. This article describes in detail a simple circuit and software that will monitor a telephone line, decode all DTMF signals, and log the data to a computer. It will even decode the A, B, C, and D Silver Box tones used by telcos, the military, ham radio operators, and Customer-Owned Coined-Operated Telephones (COCOTs).
Theory: Dual-Tone Multi-Frequency (DTMF) tones, or Touch-Tones, are, as their name implies, comprised of a pair of audio sine waves. There are eight distinct frequencies (four rows and four columns) ranging from 697 to 1633 Hertz. The two frequencies that intersect on a 4x4 matrix make up each of the sixteen DTMF tones: 0 - 9, *, #, A, B, C, and D.
The fourth column (1633 Hz) isn't used on consumer telephones, but is used on the U.S. military's AUTOVON telephone network to designate routing priority. As just mentioned, it is also used internally by some telcos, ham radio repeater systems, and some COCOTs for maintenance purposes.
Touch-Tone signals were developed by the Bell System over 30 years ago for in-band telephone signaling. The audio frequencies were carefully chosen to avoid harmonic interference and false triggering by voice signals. The signaling format is so effective that applications for it expanded far beyond the scope they were intended for. Voicemail, audiotex, paging, and data entry/retrieval systems are some examples. You can input data collected from a remote location to your computer over a twisted pair. DTMF signals can even be transmitted over the airwaves via an inexpensive FM transmitter, received with a mating FM receiver, and decoded by your computer. Working in reverse, I have used a DTMF-encoded FM transmitter/receiver pair to control a small robotic vehicle with my computer.
Not too many years ago, one had to painstakingly construct and align a separate circuit to decode each Touch-Tone. No more. Several companies now manufacture dedicated IC chips designed to decode, filter, and convert all DTMF signals to binary numbers. Basically, you plug audio containing DTMF tones in one end, and get a binary number out the other. The IC does all the work. The circuit illustrated here is based on the popular Teltone M-8870 DTMF decoder chip.
The Circuit
Figure 1 shows a circuit for decoding DTMF signals and interfacing them to an IBM-compatible computer via its parallel printer port.
Nearly all parts can be purchased at RadioShack or from DigiKey (see parts list).
Construction layout is not critical, and the circuit can be laid out and soldered on a RadioShack project board. You may want to solder DIP sockets for the two IC chips on the board and plug the chips in later to prevent thermal damage from soldering. Because of their low cost, (about $10.00) a second parallel port card is recommended for your PC instead of repeatedly swapping your printer cable.
Rather than reinvent the wheel and design my own phone line interface from scratch, I used RadioShack's 43-236 Telephone Recording Control ($24.95). This handy device provides microphone-level audio from the phone line and an electronic switch closure in response to an "off-hook" condition. Drawing its power from the phone line, it is FCC-approved for direct connection to the dial-up network and can be attached anywhere along the phone line - from the telephone itself all the way back to the central office switch. An RJ11 coupler, RJ11-to-spade lug cable, and alligator clips make the connection a snap.
The "REMOTE" plug, (designed to activate a tape recorder via its remote control jack) can be used to signal the computer that a phone is off the hook. The "MIC" plug is wired to the M-8870's Pin-2 input. The M-8870's inactive high StD line (Pin-15) will go to active low each time a valid DTMF signal (digit) has been decoded.
The StD line is wired to the printer port's ACK line at Pin-10. The computer waits for the ACK line to rise to an active low. When it does, the DTMF conversion is read at the parallel printer port's ERROR, SELECT, PAPER-END, and BUSY lines as binary bits. Software then decodes those 4-bit codes and writes them to RAM.
Because the M-8870 is a CMOS IC chip, its outputs are rated for operating only one low-power TTL load. The 4049 inverting hex buffer is designed to allow low-power CMOS signals to sink TTL power levels. Its inclusion provides more reliable circuit operation if your interface cable is over six inches long. With the 4049, the connecting cable can be up to six feet long. If you require a longer cable (up to ten feet), you can add a pull-up resistor between each of the 4049's buffer outputs and +5 volts. This means you would connect a 4.7 kΩ resistor between +5 volts and Pins-2, -4, -6, -10, -12, and -15 on the 4049 inverting hex buffer chip.
Switch S1 is optional, but it facilitates logging intercepted cordless and cellular telephone DTMF signals from a scanner's earphone jack. Take the mini (1/8") "MIC" plug from the RadioShack recording controller and insert it into your scanner's earphone jack (a Y-adapter permits simultaneous monitoring). Disconnect the recording controller's sub-mini (3/32") "REMOTE" plug from the decoder and install a SPST toggle switch between R4 and ground.
Closing S1 generates the strobe signal required by the software. The computer thinks the phone is off-hook, and starts writing binary DTMF values to memory. When S1 is released, the DTMF digits are logged to a disk file which is time and date-stamped.
Alternatively, you could record Touch-Tones directly off a phone line with the recording control and a small tape recorder and decode them later by replaying them into your decoder/computer. Likewise, you could record Touch-Tones "off the air" from cordless or cellular telephones with your scanner by connecting an attenuating cable between the scanner's earphone jack and the recorder's microphone jack. You can monitor the recording in real time with an earphone plugged into the tape recorder.
Note that tape recorded DTMF tones may suffer some distortion due to tape speed fluctuations and tape hiss, and may not always decode accurately. Your tape recorder should have new alkaline batteries or run off an AC adapter. For optimum decoding results, you may have to adjust your scanner or tape recorder's volume control (try midway first) when playing the audio back into the decoder.
The Software
DTMF2PRN.BAS is a QBasic program that logs all DTMF tones decoded off a phone line.
The program opens a file on your A: drive named: DTMF(date).DAT
For example, if the date is 07/04/1994, the program opens a file named: A:\DTMF0704.DAT
Each time the phone is picked up (or S1 is closed), all subsequent DTMF tones are decoded and stored in RAM. When the call is completed and the phone hung up, the data is saved as a record in the disk file: A:\DTMF0704.DAT
Each new line of the file begins with a time-stamp in 24-hour format (00:00:00). A ten second pause between digits will log a single "P" to indicate a pause, and a two minute lapse of touch tones starts a single new line.
If you turn your computer off, and then back on later that day, any new DTMF records will be added to the end of the A:\DTMF0704.DAT file (assuming the TSR is loaded.) Each day, the program creates a new file and logs all of that day's DTMF traffic into it.
TSR Software (Terminate-and-Stay-Resident)
The parallel printer port's ACK line was carefully chosen to input the STROBE signal.
On all IBM-compatible parallel ports, the ACK line can be used as a hardware interrupt. Instead of dedicating your computer solely as a DTMF logger, you can have it do the job in the "background."
With TSR software, your computer can stop whatever it's doing and jump to special instructions whenever the ACK line is brought to logic high. This means your computer could be executing other tasks, then stop everything whenever the ACK pin is brought to logic high and record the time and date-stamped DTMF data to a disk file. When ACK returns low, the PC will return to the original task it was performing.
Writing a hardware interrupt-driven TSR is not a trivial matter, and is impractical in BASIC. I have written many TSRs in Pascal and C, and have devoted an entire chapter of my book to the subject. The compiled and executable TSR software with over 400 lines of source code is included on the program disk supplied with the book.
Applications
You could use this system as a "pen register" to log all phone numbers called from a particular telephone line. For example, if you share a phone line with roommates this could be very helpful in resolving billing disputes by documenting all line usage. Since all Touch-Tones are logged in the computer, account numbers could be assigned to each caller and dialed after each phone number to distinguish callers.
An attorney or other "professional" who bills clients by the minute could use this system to document billable phone time. By entering each client's account number with touch tones after the start of every telephone call involving billable time, a record could be kept for accounting purposes and printed out later.
A law enforcement officer could attach an FM phone line transmitter (such as the DECO WTT-20) to any point along a phone line to transmit the audio to a remote FM receiver hundreds of feet away. The earphone output of a portable radio or FM Walkman could be fed to the decoder's input jack through an attenuating cable, and a laptop PC employed to remotely log all DTMF traffic decoded from that phone line.
If desired, a miniature voice-activated tape recorder connected between the attenuating cable and the decoder's input (through a Y-adapter) could record voice traffic to facilitate subsequent correlation of DTMF loggings. A recording FM Walkman or portable stereo with a tape recorder could also be used. An earphone plugged into the tape recorder would allow real time audio supervision. The entire system would fit easily inside a shoulder bag or briefcase for portability.
Any such connections to or monitoring of DTMF or voice traffic on a payphone, Charge-A-Call, COCOT, law enforcement, or security-related phone line is definitely not encouraged by the author. Consult a qualified attorney to determine the legality of pen register and telephone call recorder usage in your area. Unauthorized reception of cellular (not cordless) radiotelephone transmissions is a violation of federal law.
Parts List
Components Available at RadioShack:
Telephone Recording Control 43-228 - $24.95 RJ11-to-Spade Lug Cable 279-391 - $1.99 (Optional) Attenuating Patch Cable 42-2152 - $3.49 (Optional) 16-Pin DIP Socket 276-1998 - $.99 (Optional) 18-Pin DIP Socket 276-1992 - $.49 (Optional) DB-25M Connector 276-1547 - $1.49 Alligator Clips 270-356 - $1.79 (Optional) 0.1 µF Capacitors 272-109 - $1.89 100k Resistors 271-1347 - $.49 4.7k Resistor 271-1330 - $.49 300k Resistor 271-1315 - $.49 Project Board 270-283 - $4.39 RJ11 Coupler 279-358 - $2.49* SPST Switch 275-624 - $2.29 (Optional) Y-Adapter 274-310 - $2.39 (Optional)Components Available from DigiKey:
3.579 MHz Crystal CTX049 - $1.43 4049 Inverting Hex Buffer CD4049UBE - $0.47 5 VDC Regulated Power Supply EPS129-ND - $33.75Other Components:
M-8870 DTMF Decoder Chip, from the author, $6.00 postpaid. Wireless Telephone Transmitter, WTT-20, DECO Industries 914-232-3878, $29.95 (Optional)Complete specifications and application notes for the M-8870 DTMF Decoder chip are available free from Teltone Corporation 1-800-426-3926. Ask for their Telecom Design Solutions Component Data Book.
Available From the Author
The author can supply the following items:
A.) Controlling The World With Your PC, from HighText Publishers, $29.95
B.) A fully assembled and tested DTMF decoder circuit board, complete with QBasic and compiled Pascal .EXE software for TSR operation. The board includes jacks for connecting directly to a RadioShack 43-236 telephone recording control, a male DB-25 connector for connection to an IBM parallel printer port, and a 5 VDC power supply, all for $50.00 (plus $5.00 shipping).
C.) An M-8870 DTMF Decoder chip alone, for $6.00 postpaid.
D.) A compiled and ready-to-run .EXE program that operates the circuit in Figure 1 as a TSR, for $5.00 postpaid (specify diskette format).
The author will reply to any reasonable technical questions if you enclose a stamped, self-addressed envelope. Address all correspondence to:
Paul Bergsman 521 E. Wynnewood Road Merion Station, PA 19066-13465
REM FILE: DTMF2PRN.BAS, WRITTEN IN QBASIC, by Paul Bergsman REM REM Inputs 4-bit data from an M8870, DTMF Receiver to Binary converter, REM via an IBM-compatible Parallel Printer Port. Output from the REM M8870 is read into the parallel port's (Base Address + 1). D6 REM of the (Base Address + 1), the ACKbit, is used to input M8870's REM strobe signal. When D6 goes to an active HIGH, the new byte value is REM displayed on the screen. The ACK bit can also be used as a hardware REM TSR, (Terminate and Stay Resident), input. If some additional REM software is added, this circuit can be operated as a TSR device. REM The program opens a file on Disk Drive "A:\". All files begin with REM "DTMF", followed by four digits coding today's date. For example, if REM today's date is 12/23/1994, the program opens a file titled: REM DTMF1223.DAT REM All DTMF signals decoded on 12/23, will be stored in the file REM called DTMF1223. Each record in the file will start with the time REM the phone was taken off-hook, followed by all DTMF codes, and REM ending with the time of hang-up. The file will include a "P" for a REM pause greater than 10 seconds. If the pause is longer than two REM minutes, the program closes the current record and waits for an REM off-hook signal to start a new record. REM REM Each day starts a new file. If operating at midnight the program REM closes the current file and opens a new one for the new date. REM REM To EXIT the program, press "E" REM REM The following IC chips are equivalent: REM CMD CM8870C, Crystal CS8870, Motorola MC8870, and Teltone M8870 REM OpenFile: FileName$ = DATE$ FileName$ = "DTMF" + LEFT$(FileName$, 2) + MID$(FileName$, 4,2) + ".DAT" FileName$ = "A:\" + FileName$ OPEN FileName$ FOR APPEND AS #1: REM add records to today's file INPUTBITS = 0: ActiveTone = 0: OffHook = 0: TonePresent = 0: D0 = 1: D1 = 1: D6 = 64: LptPortAddress = 0: PhoneNumber$ = "" LptPortAddress = 888: REM Base address of Graphic Card's printer port. REM Use 632 for 3ED printer port base address. REM Use 956 for Monochrome Card's printer port. CLS Today$ = DATE$ PRINT "Open file = "; FileName$ WaitForCall: OffHook = INP(LptPortAddress + 1) IF Today$ <> DATE$ THEN GOTO CloseFile: REM new day means new file Ch$ = INKEY$ IF (Ch$ = "e") OR (Ch$ = "E") THEN GOTO ExitProgram: IF (OffHook AND D0) = 0 THEN GOTO WaitForCall: REM phone off-hook? REM start new record StartTime& = TIMER PhoneNumber$ = TIME$ + " ": REM record begins with start time WaitForDTMFcode: StartTime& = TIMER OUT (LptPortAddress + 2), 4: REM set all bits HIGH with 000001100 TonePresent = INP(LptPortAddress + 2): REM is a DTMF tone present OffHook = INP(LptPortAddress + 1) IF (OffHook AND D0) = 0 THEN GOTO DigestDTMFcode: EndTime& = TIME&: ElapsedTime& = EndTime& - StartTime& IF (ElapsedTime& > 120) THEN GOTO CloseFile: IF (ElapsedTime& > 10) AND (RIGHT$(PhoneNumber$, 2) <> "P ") THEN PhoneNumber$ = PhoneNumber$ + "P " END IF DigestDTMFcode: IF (TonePresent AND DO) = 0 THEN GOTO WaitForDTMFcode: ActiveTone = INP(LptPortAddress + 1): REM input decoded Touch-Tones REM -=[ reformat raw data as low nibble, D0 - D3 J=- ActiveTone = ActiveTone XOR 128: REM invert the inverted bit, D7 IF (ActiveTone AND 128) = 128 THEN ActiveTone = ((ActiveTone - 128) * 2) + 128 GOTO Shift5Right: ELSE ActiveTone = ActiveTone * 2: END IF Shift5Right: ActiveTone = ActiveTone \ 16: AddToneToRecord: SELECT CASE ActiveTone CASE 1 TO 9 Temp$ = STR$ (ActiveTone): REM decode characters "1" TO "9" CASE 10 Tenp$ = "0" CASE 11 Temp$ = "*" CASE 12 Temp$ = "#" CASE 13 TO 15 Temp$ = STRS$ (ActiveTone + 53): REM decode characters "A" TO "C" CASE 0 Temp$ = "D" END SELECT PhoneNumber$ = PhoneNumber$ + Temp$ + " " PRINT Temp$; " "; : REM display DTMF code OUT (LptPortAddress + 2), 4: REM set all bits HIGH with 00000100 IF (INP(LptPortAddress + 2) AND D1) = 0 THEN GOTO SaveRecord: OffHook = INP(LptPortAddress + 1): REM is phone still off hook? IF (OffHook AND DO) = 0 THEN GOTO WaitForDTMFcode: PRINT SaveRecord: Temp$ = Temp$ + TIME$: REM add hang-up time to file PRINT #1, Temp$: REM save record to file PRINT Temp$: PRINT: REM display record GOTO WaitForDTMFcode: CloseFile: CLOSE GOTO OpenFile: ExitProgram: CLOSE ENDCode: DTMF2PRN.BAS