                               FSK modem

                                                          Rildo Pragana

    Modems are used for digital communication when the transmission media
is designed for human voice or otherwise band-limited signals.  Voice-graded
circuits is considered to have a usable bandwidth of 300 to 3000 Hz.  Thus
we will have to convert our digital signals into sound capable of being
sent without too much distortion in these channels to have them decoded at
the other side of the link.
There are several modulating schemes used for achieving those
requisites, such as FSK (frequency shift keying), PSK (phase shift keying),
PAM (pulse amplitude modulation) or combinations of this.  We will be
analysing mostly FSK signals, because of their relative simplicity and
ease of implementation.

        This application note describes how to use the PIC microcontrollers to
implement a FSK modem suitable for use in a phone link, by modulating the
digital signal as tones of 1200 Hz or 2400 Hz, similar to a once well known
"Kansas City standard" used for cassete storage of digital data.  This pair
of tones is well chosen because of integer number of cycles for each bit
window, what makes clock recovery a snap.

ITU (CCITT) standards could be used instead, but at the expense of more complex
timing and recovery, because of their uneven tone frequencies.
Their V.23 standard, for example, calls for 1300 Hz and 2100 Hz signals.

Higher data rates (2400 bps for instance) are possible,
by making a software correlator, but this is too complex for our purposes.

        For the signal generation, we may have to output a signal comprising of
sinusoidal waves, with minimum harmonic contents.  For doing this, we choose to
make a PWM (pulse width modulated) signal, generated by a stored function
table, that will be low-pass filtered to produce an almost sinuisodal waveform.
  The software will consider processors not equipped with PWM outputs, but
when using a PIC 17C42, this could be easily done with one of the register
controlled PWM output, simplifying considerably the transmitter part.
The filtered signal is then buffered and coupled to the phone line with
a 600 Ohms 1:1 transformer, as required by the phone company.

        For the receiving section, we begin by amplifying the signal with
some hysteresis, to not let the noise interfere with our recovered signal.
The same comparator squares the signal so it can be viewed by the PIC input
as a digitally approximated periodic "wave".  To recover the digital stream
the software will measure the duration between successive transitions at
the digital input.

        There must be some kind of "bit synchronization" {see for instance, 
LAM, S.S. - "Data Link Control Procedures", Comp. Communications, 
Vol 1: Principles, W. Chou (editor), pp. 81-113 (1983) Prentice Hall}.

as well as "frame and content synchronization", so the digital contents
may be fully restored at the receiving side.  For doing bit synchronization
we can use the same protocol as asynchronous RS-232 signals use, that means
to begin our transmission with a start bit, several data bits (8 in our case),
followed by 1 or more stop bits.  Frame synchronization is achieved by
using some form of data-link protocol, using several special characters
with special meaning.  We can use, in this case, ENQ to ask for a connection,
STX to start a data block, and so on.
Check sum or BCC (binary check character) completes the frame to get a
rudimentary form of error control. ACK or NAK may be returned in case of
a retransmission required because of a bad BCC (a bad block of data!) received.
  If all this is done, we can have a nearly secure channel for information
exchange between PICs.

The tone decoding section updates RBIT signal to reflect the received level
of the "tone signal".  Another part of the receiving software looks at this
RBIT and when it downs (descending edge), starts 1 1/2 bit time bypassing
the start bit and beginning to sample RBIT at the middle of the first
bit window. When the 8th (last) bit is sampled, another 1 bit time is
waited for to get in the middle of the stop bit, then it will be waiting
again for the start bit of the next character.

As we have a limited buffer for messages, we will limit our transmissions to
two kinds: (1) single character, and (2) full buffer.  Transmiter and receiver
must agree on buffer size prior to any transfer.

For (pulse) dialing, we can use a simple relay SPST, such as some dip-relays
easily found {in our case a GORDOS F81-1390, 5V dip-relay}.
The same relay gets the "phone off-hook", if inserted in the coupling
transformer circuit, dials numbers by pulsing on and off with the
suitable ratio, and disconnects by being opened.  For detecting the ringer,
an optical coupler may be used, by letting it (already digital,
althout pulsed) output going directly to a PIC input port. The sound wave
generated for the ringer will be sensed as an periodic 50 percent on-off signal.

