





                    When  designing products for  the consumer market, cost
          is  one of the most critical design criteria.  Usually one of the
          best ways to reduce product cost is to move as much functionality
          as   possible into the product's firmware, reducing the unit cost
          of the hardware.
                     
                    In  a telephone  design,  generating Dual Tone Multiple
          Frequency  (DTMF)  signalling  is  usually  done  by  specialized
          hardware  dialler chips.   However,  these devices  typically add
          more  than a  dollar to the  manufacturing cost of  the phone; it
          would  be  desirable to  be  able to  do  this in  software, with
          minimal hardware support.
                     
                    Another  benefit  of a  software implementation  is the
          added  flexibility of  generating tones  other than  the standard
          DTMF  tone pairs.   This might  be useful  for special signalling
          with  propietary  equipment,  or  other  tones  such  as  audible
          feedback    when  the  user  presses   keys,  etc.    Also, there
          applications  other  than  telephony  which  could  benefit  from
          software sinewave generation.
                     
                    This    report examines    the requirements    for DTMF
          dialling, and shows how these requirements may be met at very low
          cost  with  a software  implementation  for both  the  68HC05 and
          68HC11 family of microcontrollers.
                     
                                       DTMF Requirements
                     
                    DTMF    signalling  represents  16  binary  digit codes
          through  the use of  sine wave tone pairs,  organized into a high
          group  (1200-1700 Hz)  and a low  group (600-1000  Hz). There are
          four tones in each group.
                     
                    As  shown  below,  the  tones  are  associated  with  a
          particular  row or column on the telephone keypad, which is shown
          below with the associated frequencies. Column four is defined but
          is  not  usually  implemented  on  a  telephone.    Signalling is
          accomplished  by  transmitting one  tone  from each  group  for a
          minimum of 50 ms, followed by a silent period of at least 50 ms.
                     
                              Column 1  Column 2  Column 3  Column 4
                              1209 Hz   1336 Hz   1477 Hz   1633 Hz
                     
                    Row 1          "1"       "2"       "3"       "A"
                    697 Hz
                     
                    Row 1          "4"       "5"       "6"       "B"
                    770 Hz
                     
                    Row 1          "7"       "8"       "9"       "C"
                    852 Hz
                     
                    Row 1          "*"       "0"       "#"       "D"
                    941 Hz












                     
                    Generating  network-quality DTMF is not a trivial task.
          Industry  specifications generally require frequency errors to be
          less than 1%, and total harmonic distortion (THD) to be less than
          10%.   Additionally, the frequency response of the telephone line
          will  generally roll off at  high frequencies, requiring the high
          group  of tones to be transmitted  at a higher amplitude than the
          low  group.   The telephony  buzzword for  this characteristic is
          twist.
                     
                                       Software Approach
                     
                    The basic technique to generate these tones in software
          involves  a table lookup of two sine waves, adding them together,
          and  outputting them through a D/A  converter. In order to reduce
          harmonic  content to  a minimum, they  must be sampled  at a high
          enough  rate  so  that  the  noise  introduced  at  the  sampling
          frequency  can  be easily  filtered from  the  output.   A sample
          period  of 128  us was  chosen for  this example;   this produces
          sampling noise at 7.8 Khz.
                     
                    In  order to save memory, a single 256 sample sine wave
          table  is used. If we  just picked out one  sample per period and
          output that data to the D/A, the output frequency would be
                     
                                        1/(256*128 us)
                     
                    or  30.5  Hz.    However, we  need  the  flexibility to
          generate  many different frequencies, none  of which are 30.5 Hz.
          To  do this,  we can  skip several  samples after  one is output,
          wrapping  around to the start  of the table when  we skip off the
          end.   This has the effect of multiplying the output frequency by
          the  number of samples  skipped. For example,  if we skipped past
          two  samples to arrive at the next  one to be output, we would be
          outputting  only every third sample.   The output frequency would
          be three times the base frequency or
                     
                                 3/(256 * 128 us) = 91.55 Hz.
                     
                    So the lowest frequency we can generate is 30.5 Hz, and
          the highest is
                     
                                 128/(256 * 128 us) = 3.9 Khz,
                     
                    Since  we cannot go above  1/2 the sample frequency due
          to  Nyquist's sampling theory.   Our frequency resolution is 30.5
          Hz.
                     
                    So  in order to generate DTMF, we must use two pointers
          stepping  through this 256  byte table in  memory; at each sample
          period,  two  values are  retrieved from  the table,  summed, and
          output  to a DAC. The pointers are then updated by adding a value
          to  each to  step through  the table.   This value  is called the













          pointer  interval, and  is different  for each  frequency that we
          must generate.
                     
                               Calculating the Pointer Intervals
                     
                     
                    The general form of our equation is
                     
                    Fout      = Interval/(Table Size * Sample Period)
                     
                     
                    So  the  interval  is calculated  by  flipping  that to
          become
                     
                    Interval  = Table Size * Sample Period * Fout
                     
                     
                    Let's  run through an example.  The frequency for row 1
          on  the DTMF keypad is 697 Hz. If we use a sine wave table of 256
          entries,
                     
                    Interval  = 256 * 128 us * 697 Hz
                              = 22.83
                     
                    We    can't  step   through  the   table  by fractional
          intervals,  so we  round the  interval to  23.   If we  plug that
          number back into the frequency equation, our actual Fout is:
                     
                     
                    Fout      = 23/(256 * 128 us)
                              = 701.9 Hz.
                     
                    This  gives  us a  frequency  error of  0.70%  which is
          acceptable.
                     
                    Below  is  a  table  of  DTMF  frequencies  which  were
          calculated  using the above equations. The actual frequencies are
          also  shown with the percentage error  calculated.  A Lotus 1-2-3
          compatible   spreadsheet  file,  DTMF.WKS,   is  available  which
          calculates  these intervals  based on  the sine  wave table size,
          sample   period,  and  desired  frequency,   as  well  as  actual
          frequencies and error.
                     
                     
                                     Software DTMF Dialler
                                    Using Fixed Sample Rate
                     
                    Sample Period (uS)  128
                    Sample Table Size   256
                     
                    Frequency ->   697       770       852       941
                    Interval       23        25        28        31
                    Actual         701.90    762.94    854.49    946.04
                    Error (%)      0.70      -0.92          0.29      0.54












                     
                    Frequency ->   1209      1336      1477      1633
                    Interval       40        44        48        54
                    Actual         1220.70   1342.77   1464.84   1647.95
                    Error (%)      0.97      0.51      -0.82          0.92
                     
                    Implementing High Tone Pre Emphasis
                     
                    In  order to compensate  for the rolloff characteristic
          of  most telephone lines, the high group of tones must be about 1
          to  3 db  higher power  than the  low group.   This  equates to a
          voltage multiplication of about 1.12 to 1.41.  A convenient value
          might  be 1.25  (1 and 1/4th),  since 1/4th is  a binary fraction
          which can be achieved by shifting instead of a full multiply.
                     
                    To  implement this, the sine  table contains values for
          the  low frequency row tones.  When the high group sample is read
          from  the sine table, it  is shifted right 2  bits (divide by 4),
          and then the same sine value is added again into the accumulator,
          producing the 1.25 multiplication.  The pre emphasis is therefore
                     
                    db   = 20 log (V1/V2)
                         = 20 log (1.25)
                         = 1.94 db.
                     
                     
                    Calculating Sine Values to Avoid Overflow
                     
                    The  values in the  sine wave table  must calculated to
          avoid  overflow errors when the two samples are summed and output
          to  the DAC.  In this example, an 8 bit D/A converter is used, so
          our  maximum data values  are +127 to  -128.  If  two samples are
          retrieved  from  the table,  added, and  output  to the  DAC, the
          values  in  the  table  must  be between  +63  and  -64  to avoid
          overflow.   In practice, they will  be somewhat smaller since the
          column tones are pre emphasized.
                     
                    The DAC output value is calculated by
                     
                    MaxOutput = MaxSineValue * (1 + PreEmphasis)
                     
                    To solve for the MaxSineValue, rearrange the equation:
                     
                    MaxSineValue   = MaxOutput / (1 + PreEmphasis)
                                   = 127 / (1 + 1.25)
                                   = 56.4
                     
                    So  the sine values in the  table must vary between +/-
          56.
                     
                    A  C program called MAKESINE.C  is available which will
          output  a sine table based on user-defined table size and maximum
          output  value.  The  output format is  compatible with most cross
          assemblers for Motorola microcontrollers.












                     
                    Benchmarking the Assembly Language Code
                     
                    Two  programs are included,  DTMF05.ASM and DTMF11.ASM,
          which  implement the algorithm for  68HC05 and 68HC11 processors.
          Both  programs use the  timer to generate an  interrupt at 128 us
          intervals;   at each  interrupt, the program  calculates the next
          value  to be output, and then updates the row and column pointers
          based on pre-calculated pointer intervals.
                     
                    Looking  at the code, we see  that the 68HC05 takes 116
          clocks  and 464 bytes of code to generate DTMF;  the 68HC11 takes
          119  clocks and 457  bytes of code.   The additional clock cycles
          for  the HC11 is  caused by the  requirement to always manipulate
          16-bit  addresses, whereas the  HC05 can get  away with byte-size
          address  calculations  applied  to  16-bit  offsets.    The HC05,
          operating  at 2 MHz bus speed, uses 116/256 clock cycles (45%) to
          service the DTMF interrupt.  The HC11 is slightly higher at 46%.
                     
                    THD Performance
                     
                    Harmonic  Distortion performance has  not been measured
          at  this time.   I  feel that  a simple  two-pole filter  will be
          sufficient  to reduce  harmonic content to  the point  that it is
          below the 10% limit for network operation.



































