Distinctive Ring Switch Using PIC

by Analog Services, Inc.


    Distinctive ringing lets phone service customers have two phone numbers with only one twisted-pair line.  The standard ring cadence tells the customer that someone is calling on number X, while the distinctive ring cadence tells him (her) that someone is calling on number Y.  People can easily tell which ring is which.  But equipment like answering machines can't.  Here is the complete design of a smart switch, based on a PIC (Microchip Technology, Inc., 2355 West Chandler Blvd., Chandler, AZ) microcontroller, that will detect the ring and route the call appropriately.  The schematic is shown in figure 1.  The assembly code (contact us if you would like a text file of the code)  follows the figure.   The Data Access Arrangement shown is intended for registration in the United States and Canada.

    A normal ring is 2 seconds ON and 4 seconds OFF.   Distinctive ringing has 1 second ON, 0.75 second OFF, 1 second ON, and 4 seconds OFF.  Therefore, if a ring is ON for more than 1 second, it is normal.

   The switch works by measuring time intervals.   For reliable operation, the switch ignores the first ring and begins its measurements on the second one.  The incoming line is always connected to one or the other of the output lines.   Once a decision is made and the relay is opened or closed, it is simply left in this state until the next ring cadence.  On power up the relay is open.  Because the switch requires at least two rings before it can make a decision, connected devices such as answering machines should be programmed to require 4 rings.

wpe19.gif (12042 bytes)

Figure 1 -- Ring Detector Schematic

 

;ringdet1.asm
;Stephen D. Anderson --- November 29, 1997
;Program used by distinctive ring detector.
;Uses PIC macros.
;The ring detector has one phone line input and two outputs.  It
;switches the input to one of the two outputs based on which type
;of ringing is present.  When ringing stops it leaves the relay in
;the last position used.
;Normal ringing consists of 2 second of ring followed by 4 second
;silence.  Distinctive ring is 1 sec. ring, 3/4 second gap, 1 second
;ring, and 4 second silence.
;The algorithm is as follows:
;   start
;       wait for ring
;       check if valid
;       if not, go to start
;       wait for end of ring.
;       measure next ring.
;       if longer than 1.5 sec goto line1
;       else goto line2
;   line1
;       switch relay to line 1 (normal ring)
;       goto start
;   line2
;       switch relay to line 2 (distinctive ring)
;       wait for ring to stop
;       goto start
;   Revision Log:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            list    p=16c54, r=HEX
            radix   dec
#include "macro.h"
;option register values.
rts         equ     0x20            ;set for external clock.
rte         equ     0               ;increm on low-to-high.
psa         equ     0               ;prescale rtcc.
ps2         equ     0               ;prescale value = 16.  This gives a
ps1         equ     2               ;clock period of 21.8 msec. to rtcc.
ps0         equ     1
option_val  equ     rts | rte | psa | ps2 | ps1 | ps0
status      equ     3               ;status register.
;status register bits.
s_zero      equ     2               ;zero flag.
rtcc        equ     1               ;timer register.
;port names.
outport     equ     5               ;port A address.
inport      equ     6               ;port B address.
;port A (output) bit positions.
relay       equ     0               ;relay control.
                                    ;low selects line 1.
test        equ     3               ;test output.
;port B (input) bit positions.
ring        equ     0               ;high level indicates ring present.
same        equ     1
w           equ     0
sec_by_10   equ     256-4           ;1/10 second (4 ticks).
onesec      equ     256-46          ;1 second.
half_sec    equ     256-23          ;one half second.
one_p_4     equ     256-64          ;1.4 second.
            org     8               ;start of variables.
count       res     1               ;register holds counter.
o_start     res     1               ;register used for outport at startup.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            org     0x1ff           ;jump to start on reset.
            goto    start
            org     0x000
start
            movlw   option_val      ;set up options.
            option
;set up the output port.
            bcf     o_start,test    ;it is done in this way to avoid
            bcf     o_start,relay   ;problems associated with
                                    ;port being an input port until
                                    ;execution of the "tris"
            movfw   o_start         ;instruction.
            movwf   outport
            clrw
            tris    outport
rw0         ;power up causes a false ring signal.
            ;wait for initial ring signal to go away.
            jump_if_set rw0,inport,ring
rw1         ;wait for ring.
            call    good_ring
rw3         ;if we got here, then a good ring has been detected.
            ;wait for it to stop.
            clrwdt
            jump_if_set rw3,inport,ring
rw4         ;wait for next ring.
            call        good_ring
;            set_bit     outport,test
rw5         ;now in good ring with half second elapsed.
            ;set up timer for one more second so that total is 1.5 sec.
            load_reg    rtcc,onesec
rw6         ;if gone before time out, then short ring.  So go to
            ;line 2.
            jump_if_clr line2,inport,ring
            call    time_check      ;timed out?
            jnz     rw6             ;continue if not.
                                    ;else goto line1 (long ring).
line1       ;set relay for line 1.
            clear_bit   outport,relay
            goto    end_wait
line2       ;set relay for line 2.
            set_bit     outport,relay
end_wait    set_bit     outport,test
            ;if no ringing for 5 second, then start over.
            load_reg    count,5
ew0         load_reg    rtcc,onesec
ew1         jump_if_set end_wait,inport,ring
ew2         call    time_check
            jnz     ew1
            decf    count,same
            jnz     ew0
            clear_bit   outport,test
            goto    rw1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
good_ring   ;subroutine waits for a valid ring.  if ring lasts for
            ;half a second, this is considered valid.
            clrwdt
            jump_if_clr good_ring,inport,ring
            load_reg    rtcc,half_sec
gr1         clrwdt
            jump_if_clr good_ring,inport,ring
            call    time_check
            jnz     gr1
            retlw   0
;end subroutine good_ring.
time_check  ;subroutine checks whether rtcc is 0.  use zero flag
            ;to check.
            clrwdt                  ;kick dog.
            movf    rtcc,w
            andlw   0xff            ;test for zero.  if rtcc was
                                    ;zero, zero flag is set.
            retlw   0               ;return.
;end subroutine time_check.
            end

 

;set of macros for PIC assembly language.
;Stephen D. Anderson --- November 11, 1995
set_bit     macro   reg, bit
            bsf     reg, bit
            endm
clear_bit   macro   reg, bit
            bcf     reg, bit
            endm
load_reg    macro reg, value
            ;macro to load a byte value.
            if value != 0
                movlw   value
                movwf   reg
            else
                clrf    reg
            endif
            endm
jump_if_set macro   where, reg, bit
            ;macro to branch if bit is 1.
            btfsc   reg,bit
            goto    where
            endm
jump_if_clr macro   where, reg, bit
            ;macro to branch if bit is 0.
            btfss   reg,bit
            goto    where
            endm
jz          macro   where
            ;macro to branch if zero flag set.
            jump_if_set where,status,s_zero
            endm
jnz         macro   where
            ;macro to branch if zero flag clear.
            jump_if_clr where,status,s_zero
            endm

For more information on how Analog Services, Inc. can help solve your circuit/system problems, call or e-mail us today.

Contacting Analog Services, Inc.:

VOICE 612-927-7112        FAX 612-929-7503        E-Mail: stevea@analogservices.com


home