DTMF Generator using IIR Filter with the chipKIT™ Pro MX7 Revision: April 12, 2015 Richard W. Wall 1300 NE Henley Court, Suite 3 Pullman, WA 99163 (509) 334 6306 Voice | (509) 334 6300 Fax Project 14b: IIR DTMF Digital Generators Table of Contents Project 14b: IIR DTMF Digital Generators ......................................................................................... 1 Table of Contents .................................................................................................................................. 1 Purpose ..................................................................................................................................................... 2 Minimum Knowledge and Programming Skills ......................................................................................... 2 Equipment List........................................................................................................................................... 2 Software Resources ................................................................................................................................... 2 References ................................................................................................................................................. 2 DTMF ......................................................................................................................................................... 3 Introduction to Digital Signal Processing .................................................................................................. 5 Digital Filter Fundamentals ................................................................................................................... 5 The Z-Plane Unit Circle .......................................................................................................................... 6 An IIR Digital Oscillator.......................................................................................................................... 7 C Code for Dual Tone to Key conversion: ................................................................................................. 9 16 Button Keypad................................................................................................................................ 10 Digital Oscillator .................................................................................................................................. 11 Analog Output Filtering........................................................................................................................... 14 Code Performance ................................................................................................................................... 16 Final Remarks .......................................................................................................................................... 20 APPRNDIX I - Hardware Configuration ........................................................................................................ 22 page 1 of 22 DTMF Tone Generation TM with the ChipKIT Pro MX7™ Purpose The purpose of this reference design is to present a method for using a PIC32 microcontroller to generate DTMF tones using digital filter technology. The technique that will be demonstrated in this reference design uses the power of digital signal processing that requires only 64 bytes of memory and a minimal amount of processor computation. The performance of this approach clearly demonstrates that generating multiple tone signals requires a minimum of microprocessor resources. Minimum Knowledge and Programming Skills 1. Knowledge of C or C++ programming 2. Working knowledge of MPLAB® X IDE 3. LCD Interface (Optional) 4. Understanding of Finite Impulse Response Filters 5. DTMF tones Equipment List 1. chipKITTM Pro MX7 processor board with USB cable 2. Pmod-DA2 Dual Channel D to A converter 3. PmodKYPD 16 Button Keypad 4. PmodSTEP Stepper Motor Driver module (Used for performance timing) 5. Character LCD (optional) 6. Logic analyzer, or oscilloscope (Suggestion - Digilent Analog Discovery) Software Resources 1. MPLAB® X Integrated Development Environment (IDE)\ 2. MPLAB® XC32 C/C++ Compiler 3. XC32® C/C++ Compiler Users Guide References 1. chipKITTM Pro MX7 Board Reference Manual 2. C Programming Reference page 2 of 22 DTMF Tone Generation TM with the ChipKIT Pro MX7™ 3. PIC32 Family Reference Manual, Timers Section 14: http://ww1.microchip.com/downloads/en/DeviceDoc/61105E.pdf 4. Web Based DTMF Signal Generator 5. “A Discrete Fourier Transform Based Digital DTMF Detection Algorithm”, http://www.rootsecure.net/content/downloads/pdf/paper_dtmf.pdf 6. “Specification of Dual Tone Multi-Frequency (DTMF) Transmitters and Receivers” http://www.etsi.org/deliver/etsi_es/201200_201299/20123502/01.01.01_60/es_20123502v010 101p.pdf 7. Steven W. Smith, The Scientist and Engineer’s Guide to Digital Signal Processing DTMF Touch tone dialing was introduced by AT&T for telephones in 1963 as a replacement for rotary dialsi. The primary advantage of touch tone dialing over rotary dialing is that the dialing information can be carried in the audio band where as the dialing information for rotary dialing is DC. The rotary phones (circa 1891-present day) created pulses in the voltage supplied by the telephone exchange to power the telephone. Rotary dials are mechanical devices that use a cam to actuate a mechanical switch. Over time the mechanics of the rotary dial would break or begin to operate so slowly that the pulses could no longer be accurately decoded. Conventional touch tone operated telephones have 12 keys: 0 through 9 as well as the “*” and “#” keys. The full implementation of the touch tone key pad as shown in Figure 1 contains 16 keys. The additional four keys are designated A through D. Some phone systems use the additional keys for phone system management and control. Figure 1. Key organization for 16 Key touch tone pad ii Touch tone phones generate a multi tone signal containing the combination of two signals at set frequencies hence the designation of DTMF for the dual tones multiple frequencies employed. As illustrated in Table I, there are four row frequencies (697 Hz, 770 Hz, 852 Hz, and 941 Hz) and four column frequencies (1209 Hz, 1336 Hz, 1477 Hz, and 1633 Hz). Whenever a key is pressed, the signal is generated that consists of the two frequencies specified by the key’s row and column. DTMF standards specify that the frequencies of the eight DTMF tones be accurate to within 1.8%. This tolerance results page 3 of 22 DTMF Tone Generation TM with the ChipKIT Pro MX7™ in a tone band width of 25Hz based on the row one frequency to 59 Hz for the column four. This has ramifications when designing a digital filter to identify the tone pairs when a key is pressed. Table I. DTMF keypad frequencies 1209 Hz 1336 Hz 1477 Hz 1633 Hz 697 Hz 1 2 3 A 770 Hz 4 5 6 B 852 Hz 7 8 9 C 941 Hz * 0 # D DTMF signals in the form of wave files can be generated using a web-based audio generator. However, this technique for generating DTMF tones requires 16 memory arrays each containing a minimum of 12 integers or a total of 384 bytes of memory. Figure 2 shows the series of outputs that are required to generate the minimum and maximum frequency DTMF tones as well as the sum that would be needed to generate the tones for the “D” key. The series of 12 outputs needs to be repeated generated at an 8KHz rate. Observe that initial output of each series is zero. This is a result of synthesizing the series using a sine function. When repeating this sequence of output, this initial output may not mathematically follow the last output in the series. This discontinuity both spreads the spectrum of the tone frequencies and well as generating harmonic as illustrated in Figure 3 and Figure 4. Depending on the amount of frequency spreading generated, the resulting signal can exceed the DTMF specification provided above. 8 KHz DTMF Tone Samples Amplitude 2 1 0 1 2 0 5 10 Sample ROW 1 Tone COL 4 Tone Sum of Tones Figure 2. Sample plots for the lowest and highest DTMF tone frequencies page 4 of 22 DTMF Tone Generation TM with the ChipKIT Pro MX7™ Spectrum of Table Driven output ofr ROW 1 Tone Magnitude 0.05 0.04 0.03 0.02 0.01 0 660 680 700 720 740 Frequency - Hz DFT of ROW 1 Figure 3. Frequency spectrum of Row 1 tone generated with a table Spectrum of Table Driven Output for Column 4 Tone Magnitude 0.05 0.04 0.03 0.02 0.01 0 3 1.610 3 1.6510 3 1.710 3 1.7510 3 1.810 Frequency - Hz DFT of COL 4 Figure 4. Frequency spectrum of Column 4 tone generated with a table Introduction to Digital Signal Processing Digital Filter Fundamentals Digital filters are a subset of a technology known as digital signal processing (DSP) that data back to the 1960’s. The digital filter is a computer algorithm that process data sets or discrete time sampled data to isolate information in one frequency range from signals or noise in other frequency ranges. Digital filters function in a similar manner to analog filters that are electronic circuits designed using resistors, capacitors, inductors, and operational amplifiers. Although it is beyond the scope of this tutorial to present a complete treatment of digital filter design, a brief introduction is provided to assist the reader in understanding the concept that is used to generate the digital oscillators. Figure 1 is a block diagram representing the components of a typical DSP application. For the DSP algorithm to function correctly, the frequency range of the input to analog filter must be limited to being no greater than half the rate that the input signal is sampled. This sampling rate is referred to as the Nyquist rate. An analog filter is commonly used to preprocess the input signal so that signal frequencies higher than the Nyquist rate are greatly attenuated. page 5 of 22 DTMF Tone Generation TM with the ChipKIT Pro MX7™ PIC32 Microprocessor Analog Input Analog Antialiasing Filter Sample and Hold Analog to Digital Converter (ADC) DSP Algorithm (Software) Digital to Analog Converter (DAC) Analog Output Filter Analog Output Figure 5. Microprocessor Digital Signal Processing block diagram One mathematical representation of a digital filter algorithm is expressed a ratio of the output to the inputs that are expressed by two polynomials in z inverse as shown in Equations 1. The term z-1 represents a delay of one sample period while the ai and bi coefficients are uniquely determined based on the requirements of the digital filter. Procedures for determining these polynomial coefficients will be addressed below. Equation 1. Equating X(z)*z-i to x(n-i) and Y(z)*z-k to y(n-k), Equation 1 can be rewritten as shown in Equation 2 which is the general form of a recursive difference equation. The expression x(n-i) represents the input sample that occurred “i” samples earlier. Equation 2. Equation 2 is a recursive equation that requires present and past inputs as well as past outputs. Recursive equations are referred to as an infinite impulse response (IIR) filters because the feedback of past outputs gives the filter infinite memory. If a filter is generated that results in all coefficient ak = 0 for k > 0, then the filter has no memory and is referred to as a finite impulse response (FIR) filters. The outputs of FIR filters are a function of the coefficients that multiple present and past inputs. Once an input exceeds the number of delays equal to the order of the numerator polynomial in Equation 2, the input is forgotten hence inputs have finite persistence. The Z-Plane Unit Circle It will become obvious in the reference design to need to understand the z-plane representation of digital filters. Roots of the numeration of the polynomial expressed in Equation 1 are called “zeros”. Roots of the denominator polynomial are referred to as poles. Figure 6 illustrates the poles (denoted as a blue triangle) and zeros (denoted as red dots) for a digital filter plotted on the z-plane. Since the digit filter design process generates a unique polynomial, the placement of the poles and zeros in the z-plane are equally unique. Zeros on the unit circle will cause the filter to output a zero amplitude signal when excited at the frequency corresponding to the angle . Poles on the unit circle cause the polynomial page 6 of 22 DTMF Tone Generation TM with the ChipKIT Pro MX7™ denominator to equal zero hence the output of the filter will be infinite when excited at the frequency corresponding to the angle from the real axis. Poles outside the units circle indicate that the filter is unstable and the amplitude of the oscillations will increase toward infinity. Poles just inside the unit circle will cause the filter to oscillate however the amplitude is bounded (fixed maximum). We will take advantage of this characteristic to make the eight oscillators needed for the DTMF tones. Chebyshevy II Filter Response Z Plane Unit Circle 0 1 ej1 =p, z=1 0 20 =0, z=1 40 60 0.5 1 1 Amplitude Imaginary 0.5 0.5 0 0.5 1 Real Figure 6. Poles and zeros plotted on the z-plane 80 0 1 2 3 Frequency - Hz Figure 7. Digital filter frequency response Note that poles and zeros that do not lie on the real axis exist in complex conjugate pairs. The effect of zeros on the filter response can be clearly noted on Figure 7. The z-plane frequency, , relates to the real-world signal frequency by noting that = p for f = the Nyquist rate which is half of the sampling rate in samples per second. An IIR Digital Oscillator As discussed above, there are eight unique DTMF frequencies: one for each of the button rows and one for each of the button columns. From the previous discussion we can compute the eight complex conjugate pairs associated with the eight DTMF frequencies as i = Fi/Fs for i = 1 through 8 and Fs is the rate that the new outputs are generated. Table I lists the four row and the four column tone frequencies. Table II lists the normalized frequencies in radians for the eight tones that are computed by dividing by the sampling frequency. Digital signal processing theory states that of the denominator polynomial (poles) that lie on the unit circle results in filters that are not, by definition roots, stable. However, if the filter poles are exactly on the unit circle oscillations are sustained but neither grows nor diminishes in amplitude. The filters that we are designing to be used as oscillators make use of this characteristic. The pairs of complex conjugate page 7 of 22 DTMF Tone Generation TM with the ChipKIT Pro MX7™ poles presented in Table III that lie on the unit circle are generated using Equation 3. The filter gain for each oscillator, also listed in Table II, are scale factors needed to make the peak amplitudes equal to ±1. Figure 8 shows the eight pairs of complex conjugate pole pairs are plotted on a z-plane graph. Equation 3 Table II. Normalized oscillator frequencies 2 p Fr1 Fs 2 p Fr2 R2 = Fs 2 p Fr3 R3 = Fs 2 p Fr4 R4 = Fs R1 = = 0.547 = 0.605 = 0.669 = 0.739 2 p Fc1 Fs 2 p Fc2 C2 = Fs 2 p Fc3 C3 = Fs 2 p Fc4 C4 = Fs C1 = = 0.95 = 1.049 = 1.16 = 1.283 Table III. Complex conjugate pole pairs and transfer function gain for the row and column tones Row frequency poles pairs e PR1 = e e PR2 = e e PR3 = e e PR4 = e 0.854 0.52i = 1 R1 0.854 0.52i 1 R2 0.823 0.569i = 1 R2 0.823 0.569i 1 R3 0.784 0.62i = 1 R3 0.784 0.62i 1 R1 0.739 0.674i = 1 R4 0.739 0.674i Column frequency poles pairs GR1=0.520 e PC1 = e GR2=0.569 PC2 = GR3=0.620 1 R4 GR4=0.676 e e e PC3 = e e PC4 = e 0.582 0.813i = 1 C1 0.582 0.813i 1 C1 0.498 0.867i = 1 C2 0.498 0.867i 1 C3 0.399 0.917i = 1 C3 0.399 0.917i 1 C4 0.284 0.959i = 1 C4 0.284 0.959i GC14=0.813 1 C2 GC2=0.871 GC3=0.917 GC4=0.959 page 8 of 22 DTMF Tone Generation TM with the ChipKIT Pro MX7™ Z Plane Unit Circle for the 8 DTMF Oscillators 1.1 =jp 0.733 Imaginary 0.367 =p, 0 z=1 =0, z=1 0.367 0.733 1.1 1.1 =jp 0.733 0.367 0 0.367 0.733 1.1 Real Figure 8. Pole-zero plot for the 8 DTMF oscillators The required eight oscillator transfer functions are computed using Equation 4. Since the input is a unit impulse and only exists for the computation of the y[0] output which is set for as the digital filter initial condition. – Equation 4 Each of the eight digital oscillator filters have unique values for the coefficient a1 and Gi. Equation 5 To generate the two tones associated with a particular key pressed, two oscillating filters are activated and the output added together before being sent to the digital to analog converter. C Code for Dual Tone to Key conversion: Listing 1 shows the code for the function main. After initializing the hardware, the keypad is continuously polled using “read_keypad” to determine is any key is pressed. The function, “start_tones” is called that provides the row and column of the key that is pressed. If “NO_KEY” is detected, row and column zero are sent to “start_tones”. This turns off all oscillators. Since the “start_tones” function initializes the digital filters, this function is only called when a new key is pressed or when a key is let up. Listing 1. int main(void) { int row = 0, col = 0; setup_hardware(); page 9 of 22 DTMF Tone Generation TM with the ChipKIT Pro MX7™ while(1) { key1 = read_keypad(&row, &col); /* poll key pad */ if(key1 != key2) /* Check for change of key state */ { key2 = key1; if(key1 == NO_KEY) start_tones(0, 0); /* Stop oscillations * else start_tones(row, col); /* Start tone generation */ } } return (EXIT_FAILURE); } 16 Button Keypad A Digilent Pmod-KYPD 16-key keypad is used to indicate which of the 16 tone pairs is to be generated. As shown in Figure 9 the ‘#’ and ‘*’ keys are not represented on the keypad. The code for this reference designs associates the conventional ‘*’ with the keypad ‘F’ key and the conventional ‘#’ key with the keypad ‘E’ key. The Pmod-KYPD 16 provides four inputs and four outputs. The keys are scanned using a walking zero pattern for the column outputs and reading the row inputs. Since the Pmod connectors on the chipKIT Pro MX7 are not connected consecutively to the PIC32 IO port pins, individual IO must be managed in a bit-bang fashion. CAUTION: Do not attempt to use the JD connector on the chipKIT Pro MX7 for the keypad interface as two of the pins also connect to the RS232 FTDI IC on the processor board. This reference design uses the chipKIT Pro MX7 JF port. The driver code for the keypad interface is provided in files “keypad.c” and “keypad.h”. The function, “keypad_init”, must be call prior to calling the function “read_keypad” which when called will return values in the row and column variable associated with a pressed key. This function returns a “NO_KEY” or one of the key identifiers. The “read_keypad” function also displays the key that is pressed on the LCD. Figure 9. Digilent Pmod-KYPD 16 button Keypad page 10 of 22 DTMF Tone Generation TM with the ChipKIT Pro MX7™ Digital Oscillator The Table IV lists the functions in the “dtmf_gen.c” file and briefly describes their functionality. Following Table IV, the code for these functions is included to illustrate the simplicity of operation. All functions listed as static are private (exclusive) to outer functions in this file. The Timer 1 ISR is set to generate an interrupt each 0.125ms which generates the 8KHz sample rate. The call to generate a new analog output is disabled only when the filter coefficients change. When there is no button pressed on the 16 button keypad, the row and column tone filter coefficients are set to zero. The analog output is offset to one half of the the maximum output. If the output is to drive a speaker, a DC blocking capacitor must be used. Constant definitions are provided by the support header file ”dtmf_gen.h” Table IV. dtmf_gen.c functions Listing Number 1 2 3 4 5 6 Function name void start_tones(int row, int col); static void select_filters(int row, int col); static void gen_tones(void); static void DA2(WORD CH1, WORD CH2); static void pwm_analog(int ana); void __ISR(_TIMER_1_VECTOR, IPL2SOFT) Timer1Handler(void) Description Selects the filter coefficients and starts oscillation Selects filter coefficients IIR filter that generates the analog outputs Analog output using PmodDA2 Analog output using PWM (Timer 2) Analog output timer (Timer 1) Listing 1 /* Select oscillator constants according to row and column number */ static void select_filter(int row, int col) { switch(row) { case 1: row_filter.a0 = filt_r1[0]; row_filter.a1 = filt_r1[1]; row_filter.a2 = filt_r1[2]; break; case 2: row_filter.a0 = filt_r2[0]; row_filter.a1 = filt_r2[1]; row_filter.a2 = filt_r2[2]; break; case 3: row_filter.a0 = filt_r3[0]; row_filter.a1 = filt_r3[1]; row_filter.a2 = filt_r3[2]; break; case 4: page 11 of 22 DTMF Tone Generation TM with the ChipKIT Pro MX7™ row_filter.a0 row_filter.a1 row_filter.a2 break; default: row_filter.a0 row_filter.a1 row_filter.a2 break; } switch(col) { case 1: col_filter.a0 col_filter.a1 col_filter.a2 break; case 2: col_filter.a0 col_filter.a1 col_filter.a2 break; case 3: col_filter.a0 col_filter.a1 col_filter.a2 break; case 4: col_filter.a0 col_filter.a1 col_filter.a2 break; default: col_filter.a0 col_filter.a1 col_filter.a2 break; } = filt_r4[0]; = filt_r4[1]; = filt_r4[2]; = 0; = 0; = 0; = filt_c1[0]; = filt_c1[1]; = filt_c1[2]; = filt_c2[0]; = filt_c2[1]; = filt_c2[2]; = filt_c3[0]; = filt_c3[1]; = filt_c3[2]; = filt_c4[0]; = filt_c4[1]; = filt_c4[2]; = 0; = 0; = 0; } Listing 2 /* ------------------- Set Oscillator frequency ------------------------ */ void start_tones(int row, int col) { tones_active = FALSE; /* Disable Timer ISR oscillator */ select_filter(row, col); /* Set filter coefficients */ x[0] = row_filter.a1; x[1] = 0; x[2] = 0; /* Initialize Row oscillator filter */ page 12 of 22 DTMF Tone Generation TM with the ChipKIT Pro MX7™ y[0] = col_filter.a1; y[1] = 0; y[2] = 0; /* Initialize Row oscillator filter */ tones_active = TRUE; /* Enable Timer ISR oscillator */ } Listing 3 /* --------------- Tone generator IIR Filter code ------------ */ static void gen_tones(void) { int ch1, ch2 = 2048; /* Set Channel 2 for DC output */ /* Row oscillator IIR filter */ x[2] = x[1]; /* Shift row channel outputs and compute new output */ x[1] = x[0]; x[0] = (row_filter.a1 * x[1] + row_filter.a2 * x[2]) >> 8; /* Column oscillator IIR filter */ y[2] = y[1]; /* Shift column channel outputs and compute new output */ y[1] = y[0]; y[0] = (col_filter.a1 * y[1] + col_filter.a2 * y[2]) >> 8; /* Sum and add offset to signal */ ch1 = (y[0] + x[0]) + 2048; if(ch1 < ch1 if(ch1 > ch1 0) = 0; 4097) = 4097; pwm_analog(ch1 >> 2); DA2(ch1, ch2); /* Send scaled ch1 output to PWM */ /* Send ch1 and ch2 output to DAC */ } Listing 4 /* -------------------------- Output to PmodDA2 ---------------------------- */ /* Bit bang SPI because it outputs to two analog channels simultaneously */ static void DA2(WORD CH1, WORD CH2) { int i; PULSE_SCLK(); /* Reset DAC */ PULSE_SYNC(); for(i = 15; i >= 0; i--) /* Shift out data bits MSB first */ { CHAN_A = (CH1 >> i) & 0x01; CHAN_B = (CH2 >> i) & 0x01; PULSE_SCLK(); page 13 of 22 DTMF Tone Generation TM with the ChipKIT Pro MX7™ } PULSE_SCLK(); /* Finalize SPI transfer */ } Listing 5 /* --------------------------- PWM update ------------------------------ */ static void pwm_analog(int ana) { SetDCOC3PWM(ana); /* Set PWM ratio */ } Listing 6 /* ------------------ Time 1 Interrupt Service Routine ----------------- */ void __ISR(_TIMER_1_VECTOR, IPL2SOFT) Timer1Handler(void) { if(tones_active == TRUE) /* Call IIR filter only if turned on */ gen_tones() INTClearFlag( INT_T1 ); /* Clear the Timer interrupt flag */ } Analog Output Filtering Figure 10 show a captured waveform of the output for the PWM and DAC. The PWM carrier frequency and the DAC update rate are both 8KHz. Figure 11 is a similar waveform capture showing the PWM output after being filtered with a simple RC low-pass filter. Note that the peak to peak filtered PWM output is only 0.2V. In most applications, an analog amplifier would be necessary thus permitting the implementation on a third order filter requiring only three resistors, three capacitors and a dual operations amplifier IC1,2. Figure 13 shows a simulated output when both the DAC and the PWM outputs are filtered with a third order Butterworth low-pass analog filter with a cutoff frequency set for 1700Hz. This filter has a frequency response as shown in Figure 12. 1 http://www.analog.com/library/analogDialogue/archives/43-09/EDCh%208%20filter.pdf 2 http://www.maximintegrated.com/en/app-notes/index.mvp/id/1795 page 14 of 22 DTMF Tone Generation TM with the ChipKIT Pro MX7™ Figure 10. DAC and PWM Output Signal st Figure 11. DAC and RC (100k / 0.33uF) 1 order filtered PWM output page 15 of 22 DTMF Tone Generation TM with the ChipKIT Pro MX7™ 3rd Order Butterw orth Analog Filter Frequency Response Gain - db 0 10 20 0 3 3 110 210 3 310 3 410 Frequency - Hz Figure 12. Output 3rd order filter frequency response Analog Filtered DAC and PWM outputs Amplitude 3 2 1 0 0 2 4 Time - ms Filtered DAC Filtered PWM Figure 13. High order analog filtered DAC and PWM outputs Code Performance The frequency accuracy signals generated by the IIR oscillator algorithm are shown in Table V. The measurements were made using the frequency output of a Fluke 867B Graphical Multimeter. The results show that the worse frequency case is less than 0.18% making the accuracy greater than 99%. The measured error is 10 times less than the DTMF standard requires. Table V. Measured Tone Frequency Errors page 16 of 22 DTMF Tone Generation TM with the ChipKIT Pro MX7™ Row 1 2 3 4 Column 1 2 3 4 Standard 697 770 852 941 IIR Measured 697.48 770.37 853.50 941.78 % Error 0.07% 0.05% 0.18% 0.08% 1209 1336 1477 1633 1208.4 1335.5 1477.5 1630.6 -0.05% -0.03% 0.03% -0.14% Table VI provides a performance measure for this implementation of the DTMF signal. Although the PIC32 processor has software floating point capability, the signal generating IIR filter shown in Listing 3 uses integer mathematics for improved speed performance. All filter constants are scaled by 256. For example, the row 1 filter constants are defined by the declaration: int filt_r1[3] = {K_R1, 437, 256}; /* R1 */ K_R1 is the scale numerator coefficient listed in Table IV as GR1. The second element in the array is the scaled a1 coefficient as described by Equation 5. The last element in the coefficient array is the scaled value of 1 used for the a2 coefficient. The actual IIR filter is implemented with the line of C code shown below. Since the scale factor is a power of 2, the multiplication and division by 256 is implemented with right and left binary shift operations both of which require only 150ns to implement. x[0] = (row_filter.a1 * x[1] - row_filter.a2 * x[2]) >> 8; /* >> 8 = divide by 256 */ The run-time execution performance reported in Table 6 shows that the bit-banged SPI output is by far the slowest executing process. Figure 14 and Figure 15 show the timing waveforms for a DAC update cycle. The trace labeled LEDA is the duration of time needed to execute the program code of Listing 3 for the two IIR filters. Table VI. Task code execution timing Task Sample Rate Interrupt latency IIR Filters SPI Analog Output Execution Time 8KHz 1.03 s 1.03 s 9.94 s page 17 of 22 DTMF Tone Generation TM with the ChipKIT Pro MX7™ Figure 14. Timing of the DTMF decoder program. Figure 15. Expanded view of the time required for decoding and LCD update. page 18 of 22 DTMF Tone Generation TM with the ChipKIT Pro MX7™ Figure 16. DAC output for two-tone generation when sampled at 8KHz page 19 of 22 DTMF Tone Generation TM with the ChipKIT Pro MX7™ Figure 17. Fourier series of a digitally generated two DTMF tones showing the sidebands create by modulation due to sampling when using a DAC. Final Remarks The IIR oscillator provides very accurate frequency signal generation with a minimal amount of computational burden. The time to compute an analog output is a faster than the bit-banged SPI DAC interface by a factor of 10. This can be significantly reduced by using a different DAC device. page 20 of 22 DTMF Tone Generation TM with the ChipKIT Pro MX7™ The tradeoff between using a PWM output and a DAC depends the degree of analog output filtering. The PWM requires significantly more analog electronics to achieve that same degree of digital modulation rejection as a DAC output. The DAC used in this design requires three IO pins whereas the PWM requires only one. A discontinued Digilent PmodAMP1 was used for this project. This module had the advantage of using a DC blocking capacitor to remove the DAC and PWM DC bias. Future designs will consider using the PmodAMP3 which combines a power amplifier with a stereo DAC using an I2S serial interface. page 21 of 22 DTMF Tone Generation TM with the ChipKIT Pro MX7™ APPRNDIX I - Hardware Configuration chipKIT PRO MX7 PC PModCLP PMP Ctrl Bus –JC Pins7 , 8 , and 9 2 X 16 Character LCD DEBUG USB (5 V PWR) PG.12 PG.13 PG.14 PG.15 PModKYPD JF RD9 – JD1 RD0 – JD2 RC4 – JD3 RC10 – JD4 GND – JD5 3.3V – JD6 BTN1 BTN2 BTN3 1 - SYNC 2 -DINA 3 - DINB 4 - SCLK 6 - Gnd 7 - Vcc VOUTA -1 N/C - 3 VOUTA -2 N/C - 4 Gnd - 6 Vcc - 7 1-LEFT 2-N/C 3-RIGHT 4-N/C 5-GND 6-Vcc PmodAMP1 LED1 LED2 LED3 LED4 Pmod-DAC2 MPLAB IDE PMP Data Bus- JB LEFT DAC Audio GND Output RIGHT PG.6 PG.7 PA.0 RD2 – JD8 OC3 100K 33nF PWM Audio Output GND – JD11 i ii http://en.wikipedia.org/wiki/Rotary_dial http://en.wikipedia.org/wiki/Dual-tone_multi-frequency_signaling#.23.2C_.2A.2C_A.2C_B.2C_C.2C_and_D page 22 of 22