circuitcellar.com
Magazine Support   Digital Library   Products & Services   Suppliers Directory 
 
 





 

Issue 156 July 2003
Stealth Telephone Screener
Mad Dash for Flash Cash Grand Prize Winner


FRAME UPDATE

The frame update routine runs every 25 ms. Rather than calling it directly from the interrupt routine, it’s called regularly by the main routine by checking the frame update flag (FRMFLG) whenever there’s a loop waiting for an event. FRMFLG is set by the interrupt routine every 200 samples.

This routine reads and debounces the inputs, and checks for an abort condition (see Listing 1). The two switches, ring detector, VOX, and the line-voltage detector are debounced using two separate on and off times for each input. Thus, multiple functions can be based on a single input. For instance, when the phone rings, the short debounce-time ringing bit would follow the ring cadence, and the longer one would indicate the overall ringing period.

Listing 1—The debounce routine checks each of the input conditions (IFLAGS) and sets the status bits (SFLAG1 and SFLAG2) after applying the debounce times from ONTBL1/2 or OFFTBL1/2. This provides two different debounce times for each bit.

INTERRUPTS

The highest priority is the sample interrupt, which runs at 8 kHz; it handles the A/D and PWM samples along with reading and writing to the external EEPROM. The mode flag determines which action will be taken depending on the current operating mode.

The VOX is the most time-intensive function, because each sample must be squared and summed as it’s acquired. The routine was carefully optimized so that the interrupt routine loading is only 64%, leaving plenty of CPU cycles for the main routine.

Audio recording and playback, including ADPCM coding, is handled entirely at the interrupt level, using a 64-byte circular buffer feeding the I2C EEPROM. Because the I2C bus takes time to transfer data, only one bus transaction is performed per interrupt. A state machine steps through each I/O operation to execute a read or write of the buffer.

Audible ring-back and beep tones are generated with a pair of phase accumulators and a sine wave look-up table. Dividing down the frame counter and toggling the speaker output pin generate the two-tone ringing sound.

If the phone line is picked up, the line voltage is sampled once per frame. The A/D conversion is interleaved between a pair of audio conversions by setting Timer0 to generate an interrupt roughly halfway between audio samples. Thus, the timing of the audio samples isn’t affected. 

THE MICROCONTROLLER

The PIC16F872 uses a 16.384-MHz ceramic resonator, which is a convenient multiple of the 8-kHz sample rate (see Figure 4). It controls an EEPROM via the I2C port and drives a speaker to generate an alternating tone ringing sound. In addition, it controls the phone line hook switch and power to the analog section via a DPDT relay.

(Click here to enlarge)

Figure 4—An ultralow-power linear regulator and switchable pull-down for S1 result in miniscule power consumption when the MCU is sleeping.

I used a low-power relay that requires only 10 mA and is directly driven by a port pin. The On/Off switch is driven by an output port pin, which goes high in Sleep mode to eliminate the pull-up current. The prototype has an ICSP port for easier programming. 

PHONE-LINE INTERFACE  

In order to connect directly to a telephone line, there are a number of FCC and Underwriters Laboratories (UL) safety and performance requirements. To learn more about these requirements, take a look at the resources listed at the end of this article. Although the FCC’s technical requirements are now handled by the Administrative Council on Terminal Attachments and published by the Telecommunications Industry Association, I’ll refer to them by their former name. 

Often, the most difficult requirements are the line-to-line and line-to-ground surge specifications, which are designed to protect against a lightning strike (FCC) or a direct power line short (UL). Because the Screener doesn’t have external connections, the line-to-ground requirements are relatively easy: they’re met by using a plastic box and properly isolating any exposed metal parts. UL typically allows the battery contacts not be isolated from the phone line, provided the battery compartment requires a tool for opening it (e.g., a screwdriver or coin) and the product has a suitable warning message.

The line-to-line surges are somewhat trickier because anything connected to the line could be exposed. The surges are applied both on and off the hook. Different strategies were applied here for each case. 

When the Screener is on-hook, the relay will protect anything downstream from the surge. The only two components that will be exposed to high voltage are C8 and R11, which are both rated for 1 kV—the highest surge voltage applied (see Figure 5). Most common 0.25-W resistors are rated for 500 V, so two can be used in series rather than using a more expensive part.

(Click here to enlarge)

Figure 5—The phone-line interface consists of the hook relay, ring detector, and active current sink. A pair of dual op-amps is used for the antialiasing and reconstruction filters. The receive gain is switchable, allowing either the caller’s voice or a locally connected phone (used for recording a greeting) to be the right level for the A/D converter.

In the off-hook state, a surge suppressor, D2, limits the surge to 18 V. The circuit must withstand a 1000-V, 25-A, type-B metallic surge without damage; therefore, I used a special surge-withstand fuse that was designed to meet FCC requirements (i.e., TIA-968-A section 4.2.3.1, which was formerly FCC part 68, section 302 (c)(1)). All of the wiring from the phone jack to D2 must be able to handle this surge current. Otherwise, surge testing may result in a dramatic separation of the wiring from its former connections!

An active current sink (Q3 and nearby components) controls the DC-line current with a dynamic resistance of 200 W. This is about two times the resistance of a typical telephone and was chosen so the line voltage would be noticeably higher than normal, making it easier to tell when a phone is picked up.

When the Screener first picks up the line, the current sink doesn’t start drawing current because C11 isn’t charged yet. If no other phone is picked up, the line voltage will rapidly rise until it’s limited by D2 (around 18 V). After 10 ms, if it doesn’t go high enough, the Screener immediately hangs up the line and waits for another call.

Ring detection is done using a diac, which is a breakdown device that triggers at 60 V. This powers a bidirectional optoisolator driving the PIC’s interrupt input. When the phone rings, the signal toggles at 40 Hz. The optoisolator is only used to protect the PIC from lightning surges, because it isn’t otherwise needed for electrical isolation.