Tiva Lab 13: DTMF Tones Generator / MIDI Player

 

Objective

  • Produce simply tones by square wave signal
  • Using PWM to generate different frequencies of square wave

Required Reading Material

Background Information 

DTMF (Dual-Tone Multi-Frequency)

The short term of the Dual-Tone Multi-Frequency is DTMF. DTMF Technology is used in push-button telephones, where when a key or button is pressed on the phone, a corresponding and unique tone will be generated. This tone is a combination of two different frequencies.

The DTMF system uses a set of eight audio frequencies transmitted in pairs to represent 16 signals, represented by the ten digits (0 ~ 9), the letters A to D, and the symbols # and *. The DTMF telephone keypad is laid out in a 4x4 matrix of push buttons and each button is associated with two frequencies as shown as belows. Each row represents the low frequency tones (697, 770, 852 and 941 Hz) and each column represents the high frequency tones (1209, 1335, 1477 and 1633 Hz) of the DTMF signal. Pressing a key sends a combination of the row and column frequencies. For example, the key 0 produces a superimposition of tones of 941 and 1336 Hz.

 TelephoneKeypadTones
Figure 1: DTMF Keypad Layout and The Corresponding Tone Frequencies

The frequencies and the keypad layout of DTMF tone dialing has been internationally standardized, but the tolerances on individual frequencies may vary in different countries. The North American standard is 1.5% for the generator and 2% for the receiver. Moreover, the tone has to be held for a specific minimum time before it is accepted as a valid dialing digit. In North America, the minimum time for a digit is about 50 ms and the inter-digit interval is also about 50 ms.

The *, #, A, B, C and D keys are widely used worldwide by amateur radio operators and commercial two-way radio systems for equipment control, repeater control, remote-base operations and some telephone communications systems.


In this lab, the system will generate DTMF tones to dial the numbers, which are pressed on the keypad. The DTMF tone is driven by a square wave that is generated by the Pulse Width Modulation (PWM) module of the Tiva TM4C microcontroller instead of Digital-to-Analog Converters (DACs). Since each PWM generator can only produce one square signal, in order to generate dual tones, the system needs two PWM generators to produce two tones at different frequencies.

 

Required Components List

Resistor 64 220-ohm Resistor × 2
MatrixKeypad 4x4 64 4x4 Matrix Keypad × 1
PassiveBuzzer 64 Passive Buzzer × 1
Trnasistor 64 S8050 NPN Transistor × 1

 

Circuit Diagram

You have to decide which two PWM signals will be used to generate the DTMF tone and then connect both PWM signals to an NPN S8050 transistor with two 220 ohm resistors to drive the passive buzzer as shown as above figure. A matrix keypad is also connected to the Tiva LaunchPad board.

dtmf circuit
NPN S8050 Pinout 2

Pin configurations:

DevicePort.Pin Signal TypePCTLDirection:Drive Mode

 

Procedures

  1. Create a new folder under the EE3450 folder and name it Lab13_DTMF_MIDI. Then double-click the folder you just created to jump into it.
  2. Launch the Keil μVisio and create a new project, save the project as Lab13_DTMF_MIDI.
  3. Add MyDefines.h to the Source Group, and then add the Common folder to the include paths under the "Options for Target" setting.
  4. Add ezTiva LIB into your project, increase the stack and heap size under the "startup_TM4cXXX.s (Startup)" setting, and then add the ezTivaLIB folder to the include paths under the "Options for Target" setting. (Lesson 09: Add ezTiva Library into Your Project)

Configurations

Write down the following configuration information on your report.

The PWM generator can produce a square wave signal. The frequency of the signal is controlled by the PWM LOAD register. Change the value in the LOAD register will change the frequency of PWM signal (square wave). The formula for the LOAD value in different PWM frequencies is shown as below:

LOAD = \frac{{{f_{PWMTimer}}}}{{{f_{PWM}}}} = \frac{{({f_{SysClk}}/PWMDIV)}}{{{f_{PWM}}}}

  1. Configure the system clock frequency to 40 MHz by using ezTiva LIB API (check here). 
  2. Configure two PWMs by calling Setup_PWM() function.
  3. Configure GPIOs by calling Setup_GPIO() function.
  4. Create a function: char ReadKeypad() to read the keypad and then return the ASCII code for the key pressed by the user.
  5. Create a function: PlayDTMF(digit, duration) to generate dial tones.
    • The digit is a character to represent the dial ton key for '0' ~ '9', 'A' ~ 'D' and '*', '#'.
    • Calculate the LOAD value for each ton frequency.
    • The duration is the period of the tone in ms.
  6. In the infinite for-loop:
    • Call ReadKeypad() to detect the key pressed by the user. (Use the code you implemented in Lab 5, Exp #2.)
    • If any key is pressed, the call PlayDTMF() function to generate a dial tone.

 

Example Source Code

Copy the following example code to your main.c file.

Note: The example code is not yet complete, you must implement all functions following the lab instructions.

 

Lab Experiments

 

Questions

  1. What is the difference between active and passive buzzer?
  2. Can we use two PWMs that use the same PWM generator to generate the dial tone (for example, uses M0PWM2 and M0PWM3)? Explain why, or why not?