Tiva Lab 13: DTMF Tones Generator / MIDI Player
- Produce simply tones by square wave signal
- Using PWM to generate different frequencies of square wave
Required Reading Material
- Lesson 14: Pulse-Width Modulation (PWM)
- EE3450-Tiva Lab 05: Scan a Key from a Matrix Keypad
- Lesson 09: Add ezTiva Library into Your Project
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.
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
|220-ohm Resistor||× 2|
|4x4 Matrix Keypad||× 1|
|Passive Buzzer||× 1|
|S8050 NPN Transistor||× 1|
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.
- 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.
- Launch the Keil μVisio and create a new project, save the project as Lab13_DTMF_MIDI.
- Add MyDefines.h to the Source Group, and then add the Common folder to the under the "Options for Target" setting.
- 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 under the "Options for Target" setting. (Lesson 09: Add ezTiva Library into Your Project)
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:
- Configure the system clock frequency to 40 MHz by using ezTiva LIB API (check here).
- Configure two PWMs by calling Setup_PWM() function.
- Configure GPIOs by calling Setup_GPIO() function.
- Create a function: char ReadKeypad() to read the keypad and then return the ASCII code for the key pressed by the user.
- 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.
- 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.
- What is the difference between active and passive buzzer?
- 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?