Menu English Ukrainian russian Home

Free technical library for hobbyists and professionals Free technical library


ENCYCLOPEDIA OF RADIO ELECTRONICS AND ELECTRICAL ENGINEERING
Free library / Schemes of radio-electronic and electrical devices

Dual tone multi-frequency (DTMF) generator on the AVR. Encyclopedia of radio electronics and electrical engineering

Free technical library

Encyclopedia of radio electronics and electrical engineering / Telephony

Comments on the article Comments on the article

Otherness

  • Generation of sinusoidal signals using pulse-width modulation (PWM)
  • Combining various sinusoidal signals into one DTMF signal
  • Assembly and C source codes
  • Designed to work with STK500
  • Program code size 260 bytes / Constant table size 128 bytes
  • Using the table conversion method

Introduction

This document describes how to generate DTMF (Dual Tone Multi-Frequency) signals using any AVR microcontroller containing a Pulse Width Modulation (PWM) block and SRAM. These signals are widely used in telephony, where they are played when you press the dialing buttons of the telephone set. To correctly generate a DTMF signal, two frequencies must be superimposed together: a low frequency (fb) and a high frequency (fa). Table 1 shows how different frequencies are mixed to produce DTMF tones when different keys are pressed.

Dual tone multi-frequency (DTMF) generator on the AVR. Schematic of the DTMF signal generator
Figure 1. Diagram of the DTMF signal generator

Table 1. Tone Shaping Matrix

fb/fa 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

The rows of Table 1 represent low frequency values, and the columns show high frequency values. For example, the matrix shows that pressing the button "5" should mix the frequencies fb = 770 Hz and fa = 1336 Hz. As a result of the addition of two sinusoidal signals of different frequencies, a DTMF signal is formed

(1)

where the ratio of amplitudes K=Ab/Aa source signals must meet the condition

(2)

Operating principle

In addition to general information about the use of pulse-width modulation, the following will show how pulse-width modulation allows you to generate sinusoidal signals. The following paragraph describes how to obtain different frequencies using the base PWM frequency. After considering the theoretical foundations, a description of the DTMF signal generator itself will be given. Generation of sinusoidal signals

Depending on the ratio of the duration of the high VH and low VL voltage levels, the average value at the PWM output changes. If the ratio between the durations of both levels is kept constant, then a constant voltage level VAV will be generated as a result. Figure 2 shows a pulse width modulated signal.

Dual tone multi-frequency (DTMF) generator on the AVR. DC voltage level generation
Figure 2. DC voltage level generation

The voltage level is determined by the expression:

(3)

A sinusoidal signal can be generated provided that the average value of the voltage generated by the pulse width modulation will change every PWM cycle. The ratio between high and low levels must be set according to the voltage level of the sinusoidal signal at the corresponding time. Figure 3 illustrates this process. The initial data for PWM are calculated for each of its periods and recorded in the conversion table (TP).

Figure 3 also illustrates the relationship between the frequency of the fundamental sine wave and the number of samples. The higher the number of samples (Nc) - the higher the modeling accuracy of the resulting signal:

(4)

where f is the frequency of the sinusoidal signal (1/T)
f1 - PWM frequency (fCK/ 510)
T is the period of the main sinusoidal signal;
fCK - clock frequency of the timer;
NC - number of samples (=12 in Fig. 3)

The PWM frequency depends on the PWM resolution. With 8-bit resolution, the end value (top of count) of the timer is 0xFF (255). Because timer counts up and down, this value must be doubled. Therefore, the PWM frequency can be calculated by dividing the timer clock fCK by 510. Thus, with a timer clock frequency of 8 MHz, the resulting PWM frequency will be 15.6 kHz.

Dual Tone Multi-Frequency (DTMF) Generator on AVR
Figure 3. Generation of a sinusoidal signal using PWM

Changing the frequency of a sinusoidal signal

Assume that the sinusoidal samples are read from the lookup table not sequentially, but one at a time. In this case, at the same sample rate, a signal with a double frequency will be generated (see Figure 4).

Dual Tone Multi-Frequency (DTMF) Generator on AVR
Figure 4. Doubling the resulting frequency (XSW = 2)

By analogy, if you read not every second value, but every third, fourth, fifth (respectively, the step width is 3, 4, 5 ...), etc. it is possible to generate Nc-frequencies in the range [1/T Hz .. 0 Hz]. Note that for high frequencies the resulting waveform will not be sinusoidal. The step width according to the conversion table is denoted as XSWWhere

(5)

Calculation of the current position in the TP for the next PWM period (when the timer overflows) is performed using expression (6). New value at X positionLUT depends on its previous state at position X'LUT with the addition of step width XSW

(6)

where XLUT - previous position in the conversion table;
X'LUT - current position in the lookup table.

Adding different frequencies to get a DTMF signal

The DTMF signal can be generated using expressions (1) and (2). For simplicity of arithmetic operations, the value of the coefficient K is taken equal to 0.75 in order to replace the arithmetic operation with logical shifts. Taking into account expression (6), the current value for PWM control can be calculated by the expression:

(7)

and taking into account that XLUTa=X'LUTa + XSWa,XLUTb=X'LUTb + XSWb, we finally write

(8)

Implementing a DTMF Generator

This appendix discusses building a DTMF tone generator using an 8-bit PWM output (OC1A) and a table of 128 sine function samples (Nc), each specified by 7 bits (n). The following expressions show this dependency and also show how to calculate the elements of the lookup table:

(9)

The advantage of using 7 bits is that the sum of the high and low frequency signal values ​​is one byte in size. To support the full set of DTMF tones, 8 values ​​for each DTMF frequency from Table 1 must be calculated and entered into a conversion table.

To achieve higher precision, the following solution was made: the values ​​​​calculated by expression 5 require only 5 bytes. To use all 8 bytes, which will reduce the rounding error, this value is multiplied by 8. A pointer to the conversion table is written in the same way. But in this case, it takes two bytes to store 8 times the value. This means that 3 right shifts and an Nc base modulo operation (logical multiplication by Nc-1) must be performed before using these bytes as a pointer to sinusoid values ​​in

(10)

where XLUTa,b - current position of the element in the conversion table (actual format);
XLUTa,bExt - the previous position of the element in the conversion table (extended format);
ROUND - rounding function.

Dual tone multi-frequency (DTMF) generator on the AVR. Module diagram for connection to STK500
Figure 5. Scheme of the module for connecting to STK500

The PWM signal is generated at the OC1A (PD5) pin. An additional output filter will help to better match the sinusoidal waveform. As the PWM frequency decreases, it may be necessary to use a filter with a steeper frequency response to obtain a good result.

The connection of the keyboard is shown in Figure 1. The operation of the keyboard must be organized in such a way that it is possible to determine the pressed key. This can be done using the following algorithm:

  1. Determining the string of the pressed key
    • set the lower tetrad of port B to the output and set the log. "0"
    • configure the high tetrad of port B to the input with the connection of pull-up resistors
    • the line with the pressed button is defined as the digit of the highest tetrad with a log. "0"
  2. Determining the Key Pressed Column
    • configure the senior tetrad of port B to the output and set the log. "0"
    • set the lower tetrad of port B to the input with the connection of pull-up resistors
    • the column with the pressed button is defined as the digit of the lowest tetrad with a log. "0"

Note: The STK200 has resistors in series between the PORTB connector pins and the microcontroller pins BP5, PB6, and PB7 (see the STK200 schematic). This will cause problems if a keyboard is connected to the PORTB connector.

Figure 6 illustrates the operation of the subroutine for determining the pressed key. Depending on the key pressed, the duration of the interval is determined. The interrupt routine uses this value to calculate the PWM settings for the two DTM tone sine waves. The interrupt handling procedure is shown in Figures 7 and 8.

This routine calculates a value to compare with the timer output for the next PWM period. The interrupt routine first calculates the position of the next sample value in the lookup table and reads the value stored there.

The position of the sample in the lookup table is determined by the pulse duration, and the actual pulse duration is determined by the generated frequency.

The final value, which is written to the timer comparison register, is determined using formula (7), which takes into account the sample values ​​of both DTMF frequencies.

Dual tone multi-frequency (DTMF) generator on the AVR. Flowchart of the main program
Figure 6. Block diagram of the main program

Dual tone multi-frequency (DTMF) generator on the AVR. Timer Overflow Interrupt Processing Flowchart
Figure 7. Timer Overflow Interrupt Processing Flowchart

Dual tone multi-frequency (DTMF) generator on the AVR. Flowchart of the "GetSample" sample reading procedure
Figure 8. Flowchart of the "GetSample" sample reading procedure

Publication: cxem.net

See other articles Section Telephony.

Read and write useful comments on this article.

<< Back

Latest news of science and technology, new electronics:

Artificial leather for touch emulation 15.04.2024

In a modern technology world where distance is becoming increasingly commonplace, maintaining connection and a sense of closeness is important. Recent developments in artificial skin by German scientists from Saarland University represent a new era in virtual interactions. German researchers from Saarland University have developed ultra-thin films that can transmit the sensation of touch over a distance. This cutting-edge technology provides new opportunities for virtual communication, especially for those who find themselves far from their loved ones. The ultra-thin films developed by the researchers, just 50 micrometers thick, can be integrated into textiles and worn like a second skin. These films act as sensors that recognize tactile signals from mom or dad, and as actuators that transmit these movements to the baby. Parents' touch to the fabric activates sensors that react to pressure and deform the ultra-thin film. This ... >>

Petgugu Global cat litter 15.04.2024

Taking care of pets can often be a challenge, especially when it comes to keeping your home clean. A new interesting solution from the Petgugu Global startup has been presented, which will make life easier for cat owners and help them keep their home perfectly clean and tidy. Startup Petgugu Global has unveiled a unique cat toilet that can automatically flush feces, keeping your home clean and fresh. This innovative device is equipped with various smart sensors that monitor your pet's toilet activity and activate to automatically clean after use. The device connects to the sewer system and ensures efficient waste removal without the need for intervention from the owner. Additionally, the toilet has a large flushable storage capacity, making it ideal for multi-cat households. The Petgugu cat litter bowl is designed for use with water-soluble litters and offers a range of additional ... >>

The attractiveness of caring men 14.04.2024

The stereotype that women prefer "bad boys" has long been widespread. However, recent research conducted by British scientists from Monash University offers a new perspective on this issue. They looked at how women responded to men's emotional responsibility and willingness to help others. The study's findings could change our understanding of what makes men attractive to women. A study conducted by scientists from Monash University leads to new findings about men's attractiveness to women. In the experiment, women were shown photographs of men with brief stories about their behavior in various situations, including their reaction to an encounter with a homeless person. Some of the men ignored the homeless man, while others helped him, such as buying him food. A study found that men who showed empathy and kindness were more attractive to women compared to men who showed empathy and kindness. ... >>

Random news from the Archive

Magnetic glue 10.03.2007

German chemists have created a glue whose properties are subject to a magnetic field.

In a colloidal solution of silicon dioxide (liquid glass, ordinary office glue), they mixed dusty iron oxide. The parts to be glued are exposed to a high-frequency alternating magnetic field, the iron oxide particles are heated, and the glue immediately sets.

If the connection needs to be glued, it is subjected to the same, but more powerful, alternating magnetic field, the glue is very hot, and the connection breaks up.

The only drawback of the new adhesive is that it is not suitable for electrically conductive materials.

Other interesting news:

▪ Needle found in Greenland

▪ Adjustable adhesive

▪ Jupiter diverts comets and sends asteroids to Earth

▪ Camera Pentax Q

▪ Solar panels for FlixBus

News feed of science and technology, new electronics

 

Interesting materials of the Free Technical Library:

▪ site section Power Amplifiers. Article selection

▪ article Venereal disease. Basics of safe life

▪ article What is in the US area, the area code of which is 321? Detailed answer

▪ article Specialist in foreign economic activity. Job description

▪ article Temperature controller on a thyristor. Encyclopedia of radio electronics and electrical engineering

▪ Article Optocouplers. Part 2. Encyclopedia of radio electronics and electrical engineering

Leave your comment on this article:

Name:


Email (optional):


A comment:





All languages ​​of this page

Home page | Library | Articles | Website map | Site Reviews

www.diagram.com.ua

www.diagram.com.ua
2000-2024