Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

DTMF generation using C language.

Status
Not open for further replies.

djc

Advanced Member level 1
Joined
Jan 27, 2013
Messages
402
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
India
Activity points
4,543
Hi,
I have been asked to generate DTMF signals. I am using Atmega 16 and code vision AVR. Language is C. Can anybody guide. Please its urgent. DTMF decoding is not necessary.
 

doraemon

Super Moderator
Staff member
Joined
Jun 21, 2009
Messages
1,068
Helped
273
Reputation
554
Reaction score
248
Trophy points
1,343
Location
Japan
Activity points
10,597
Hello!

You have to give it back tomorrow at the university?
Never say it's urgent when you're asking for something for free.
Basically you make a circular buffer and you read it at various
speeds by incrementing your pointers differently for each of the
frequencies. And you add them 2 by 2 depending on the combination.
Nothing hard in this.

Dora.
 

djc

Advanced Member level 1
Joined
Jan 27, 2013
Messages
402
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
India
Activity points
4,543
Hi,

Thank you ud23 and doraemon. I apologize for word urgent. However i have to give it as soon as possible. I am not getting the point frequency addition. Do i have to add two frequencies and generate third one or generate interrupt with two back to back different frquencies.
 

ud23

Advanced Member level 3
Joined
Apr 20, 2011
Messages
926
Helped
184
Reputation
368
Reaction score
180
Trophy points
1,323
Activity points
6,138
DTMF means dual tone multiple frequencies. So you can do it with the single timer refer the second link it has sample C code.
 

djc

Advanced Member level 1
Joined
Jan 27, 2013
Messages
402
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
India
Activity points
4,543
Thanx ud23. However it's difficult for me to understand somebody Else's logic. What i did is i loaded OCR1AH and OCR1AL with 4 hex values, first two for lower frequencies and another two for higher frequencies and expecting interrupt to occur at specified values in OCR1A and expecting phone with caller id to detect these frequencies. Here is my program. I think i am going terribly wrong.
Code:
#asm("sei")
while (1)
      {
      // Place your code here
            while(phn_10==0){
                i=1;
                //
                OCR1AH=0x2c;
                OCR1AL=0xd4;
                OCR1AH=0x19;
                OCR1AL=0xd8;
//                while(phn_11==1){

//                      master=1;
//                      delay_ms(1000);
//                      master=0;
//            }
          }
         i=0;
         #asm("cli  ")
      };
 

ud23

Advanced Member level 3
Joined
Apr 20, 2011
Messages
926
Helped
184
Reputation
368
Reaction score
180
Trophy points
1,323
Activity points
6,138
i don't get what are you trying to do with the code. You need to make a look up table for different key tones.
 

djc

Advanced Member level 1
Joined
Jan 27, 2013
Messages
402
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
India
Activity points
4,543
yes that logic is totally wrong. can you tell me what is he value of Aa and Bb in equation 1 in PDF in second link to generate DTMF frequency.

- - - Updated - - -

yes that logic is totally wrong. can you tell me what is he value of Aa and Bb in equation 1 in PDF in second link to generate DTMF frequency. How to use 'k' factor in this equation...
f(t) = (Aa sin (2pi fat) + Bb sin (2pi fb t))

(Aa/Bb) = k 0.7<k<.9
 

ud23

Advanced Member level 3
Joined
Apr 20, 2011
Messages
926
Helped
184
Reputation
368
Reaction score
180
Trophy points
1,323
Activity points
6,138
Code:
[syntax=c]
char hexaKeys[ROWS][COLS] = {
  {'D','#','0','*'},
  {'C','9','8','7'},
  {'B','6','5','4'},
  {'A','3','2','1'}
};

//Order of dtmf are : 0123456789 * #
const int DTMF_freq1[] = { 1336, 1209, 1336, 1477, 1209, 1336, 1477, 1209, 1336, 1477,1209 ,1477  }; 
const int DTMF_freq2[] = {  941,  697,  697,  697,  770,  770,  770,  852,  852,  852, 941 ,941   };

// here you need to put the frequency generation values for your controller in above array definition for example  OCR1AH=0x2c; OCR1AL=0xd4;

void playDTMF(uint8_t number, long duration)
{
  freq1.play(DTMF_freq1[number], duration);
  freq2.play(DTMF_freq2[number], duration);
}

 char customKey = customKeypad.getKey();
  
  if (customKey){
     
    switch (customKey) {
      case '0':    
       playDTMF(0, 2ms);
      break;
      case '1':    
       playDTMF(1, 2ms);
      break;
     case '2':    
       playDTMF(2, 2ms);
      break;
      case '3':    
       playDTMF(3, 2ms);
      break;
      case '4':    
       playDTMF(4, 2ms);
      break;
      case '5':    
       playDTMF(5, 2ms);
      break;
      case '6':    
       playDTMF(6, 2ms);
      break;
      case '7':    
       playDTMF(7, 2ms);
      break;
      case '8':    
       playDTMF(8, 2ms);
      break;
      case '9':    
       playDTMF(9, 2ms);
      break;
      case '*':    
       playDTMF(10, 2ms);
      break;
      case '#':    
       playDTMF(11,2ms);
      break;
     
     default:   //just in case the character read has no value at all
    delay(1);
    }
[/syntax]
 
Last edited:

djc

Advanced Member level 1
Joined
Jan 27, 2013
Messages
402
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
India
Activity points
4,543
there are 15 phone lines. there is no keypad on phones. so dtmf detection is not an issue. only DTMF generation. How does 'freq.play' function working in above program. I pardon if i bother you too much.
 

ud23

Advanced Member level 3
Joined
Apr 20, 2011
Messages
926
Helped
184
Reputation
368
Reaction score
180
Trophy points
1,323
Activity points
6,138
actually it is API of arduino to generate the square pulse for tone generation.Sorry i forget to mention you can replace it with the your PWM generation code,But don't use the function in the ISR.

Code:
freq1_play(int16 freq,int long duration)
{
    
  //here your timer register allocation, and delay routine for ms

}
 

djc

Advanced Member level 1
Joined
Jan 27, 2013
Messages
402
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
India
Activity points
4,543
Sorry to bother you again. However i am not getting how to generate look up table. I don't have any function in code vision AVR. for dtmf generation.
 

djc

Advanced Member level 1
Joined
Jan 27, 2013
Messages
402
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
India
Activity points
4,543
Thanx UD3,

It's been so many days. But i am not succeeded yet. So i switched to Fast AVR. It has inbuilt DTMF generation function. But i will keep trying using C.
 

andre_teprom

Super Moderator
Staff member
Joined
Nov 7, 2006
Messages
9,252
Helped
1,151
Reputation
2,321
Reaction score
1,133
Trophy points
1,403
Location
Brazil
Activity points
53,865
I did not take a look on the code above, however I can´t see much issues in generating DTMF tones, if there is available 2 timers to store the fundamental frequency of each tone. Just reload the timer register accordingly.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top