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


In this lab, the system will generate DTMF tones to dial the numbers 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, to generate dual tones, the system needs two PWM generators to produce two tones at different frequencies.

Calculation

The PWM generator can produce a square wave signal. The PWM LOAD register controls the frequency of the signal. Changing the value in the LOAD register will change the frequency of the PWM signal (square wave). The formula for the LOAD value in different PWM frequencies is shown 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.)
    • The call PlayDTMF() function generates a dial tone if any key is pressed.

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 TypePCTLDirectionDrive 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 the Common and ezTivaLIB folders to the include paths under the "Options for Target" setting.
  4. Add ezTiva LIB into your project, and increase the stack and heap size under the "startup_TM4cXXX.s (Startup)" setting.

Configurations

Example Source Code

Lab Experiments

Questions

  1. What is the difference between active and passive buzzers?
  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?

© 2024 Air Supply Information Center (Air Supply BBS)