Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

Could not recognize DTMF code using 8870 and AtTiny2313

Status
Not open for further replies.

djc

Full Member level 6
Joined
Jan 27, 2013
Messages
399
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
India
Activity points
4,507
Hi,
I have written a C code using CodeVision AVR and Tiny2313 to detect dtmf tones using 8870 and turn on the relay if any of the valid code is found. Code is as followsm,

Code:
#include <tiny2313.h>
#include <delay.h>

#define EST     PIND.1
#define STD     PINA.1
#define Q4      PINA.0
#define Q3      PIND.2
#define Q2      PIND.3
#define Q1      PIND.4
#define TOE     PORTD.5
#define RELAY   PORTD.6
#define Phn_In  PINB.0


int i=0,j=0,d1=0,d2=0,d3=0,d4=0;
char k =0;
int code[13] = {1780,1781,1782,1783,1784,1785,1786,1787,1788,1789,1790,1791,1799};

// Declare your global variables here

void main(void)
{
// Declare your local variables here

// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=0x80;
CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif

// Input/Output Ports initialization
// Port A initialization
// Func2=In Func1=In Func0=In
// State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;

// Port B initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=In
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=T
PORTB=0x00;
DDRB=0x00;

// Port D initialization
// Func6=Out Func5=Out Func4=In Func3=In Func2=In Func1=In Func0=In
// State6=0 State5=0 State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x60;


while (1)
    {
      // Place your code here

      if(Phn_In==1){

        if(EST==1){
        delay_ms(50);
                 //PORTB.6 = 1;
                 //delay_ms(500);
                 TOE = 1;
                        delay_ms(50);
                        if((Q4==1) && (Q3==0) && (Q2==1) && (Q1==0)){
                        j=0;
                        i++;
                        }

                        if((Q4==0) && (Q3==0) && (Q2==0) && (Q1==1)){
                        j=1;
                        i++;
                        }

                        if((Q4==0) && (Q3==0) && (Q2==1) && (Q1==0)){
                        j=2;
                        i++;
                        }

                        if((Q4==0) && (Q3==0) && (Q2==1) && (Q1==1)){
                        j=3;
                        i++;
                        }

                        if((Q4==0) && (Q3==1) && (Q2==0) && (Q1==0)){
                        j=4;
                        i++;
                        }

                        if((Q4==0) && (Q3==1) && (Q2==0) && (Q1==1)){
                        j=5;
                        i++;
                        }

                        if((Q4==0) && (Q3==1) && (Q2==1) && (Q1==0)){
                        j=6;
                        i++;
                        }

                        if((Q4==0) && (Q3==1) && (Q2==1) && (Q1==1)){
                        j=7;
                        i++;
                        }

                        if((Q4==1) && (Q3==0) && (Q2==0) && (Q1==0)){
                        j=8;
                        i++;
                        }

                        if((Q4==1) && (Q3==0) && (Q2==0) && (Q1==1)){
                        j=9;
                        i++;
                        }

                        if((Q4==1) && (Q3==0) && (Q2==1) && (Q1==1)){        //for *
                        j=1;
                        i++;
                        PORTB.1=1;
                        delay_ms(500);
                        }
                  PORTB.1=0;
                  TOE = 0;
                  //PORTB.6 = 0;

        }

        if(i==1){
        d1=j;
        d1=d1*1000;
        PORTB.2 = 1;
        delay_ms(500);
        PORTB.2 = 0;
        }
        if(i==2){
        d2=j;
        d1=d1+(100*d2);
        PORTB.3 = 1;
        delay_ms(500);
        PORTB.3 = 0;
        }
        if(i==3){
        d3=j;
        d1=d1+(10*d3);
        PORTB.4 = 1;
        delay_ms(500);
        PORTB.4 = 0;
        }
        if(i==4){
        d4=j;
        d1=d1+d4;
        PORTB.5 = 1;
        delay_ms(500);
        PORTB.5 = 0;
                for(k=0;k<13;k++){
                    if(d1==code[k]){
                    RELAY = 1;
                    i=0;
                    break;
                    }

                }
                  

        }

      }

         if(Phn_In ==0){
            i = 0;
            RELAY = 0;
            d1=0;
            d2=0;
            d3=0;
            d4=0;
         }

    };
}
Logic is, when phone is off hook, i have to detect valid dtmf tone, so i checked Est pin,then made TOE pin high and read the OUTPUT and stored the digit accordingly. Used one counter 'i' to know how many times dtmf tone has been appeared, as code is 4 digit. So when i==4 means i have got all four digits then i formed complete number and checked it with numbers stored in an array. I Dont know where i am going wrong. Plz help
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,354
Helped
4,724
Reputation
9,463
Reaction score
4,492
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
122,499
... yes, start again! That code is overcomplicated and I think you are mis-using the 8870 as well.

Forget 'Est', that is used internally for setting the 'discovery time' of the valid tone pair. The signal you should use is 'Std' which gives you a guarantee that a valid digit has been received. Also remove any delays associated with 'Std' as the tones may have finished before the delay and hence be missed altogether.

There are only 16 possible combinations of data from the 8870 so read the data in through a port and use a look-up table to translate it to a 'real' number if necessary. If you use 'Std' you know it is safe to read the digit without adding any delays and you can also use it to count the digits so you know when they have all been received.

Brian.
 

djc

Full Member level 6
Joined
Jan 27, 2013
Messages
399
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
India
Activity points
4,507
Thank you betwixt,
I have used variable 'i' for that purpose only. Whenever EST or Std signal appears, i will increment until it's equal to 4, a complete digit will form and will be compared with numbers stored in an array.
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top