Continue to Site

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.

measuring time difference

Status
Not open for further replies.

lats

Full Member level 4
Joined
Oct 27, 2005
Messages
216
Helped
13
Reputation
26
Reaction score
6
Trophy points
1,298
Activity points
2,945
Hello friends,
i'm trying to make a very simple program in which i'm feeding two signals (basically frequency,square waves) to at89c51 uC to measure time difference between them(one on INT0 and other on INT1 ), but i'm unable to get correct value. I've tried everything, can't understand what mistake i'm making. I'm sending my program (done in Keil c51) along with. someone please help me to find out my mistake.

Thank you friends.

Code:
int timer;

void Int0 (void) interrupt 0
{ 
	TH0=0x00;		
	TL0=0x00;
	TR0=1;
	EX0=0;
	EX1=1;
	
}

void Int1(void) interrupt 2
{

	TR0=0;
	EX1=0;
	
	timer = TH0*256 + TL0;
		
	TH0=0x00;
	TL0=0x00;
	
}





void main(){
	
	
	P3=0x0C;
	
	lcd_init();
	
	
	EA = 1;
	TMOD = (TMOD & 0xF0) | 0x01;  /* Set T/C0 Mode */
		ET0 = 1;                      /* Enable Timer 0 Interrupts */
		TR0 = 0;                      
		
		IT0 = 1;   
		EX0 = 1;   
		IT1 = 1;   
		EX1 = 0;   

	                       
		TH0=0x00;		
		TL0=0x00;
		
while(1)
{

			
	//timer value on lcd
		
	
}
 

lats,
Maybe the time different of the 2 signals is to long, you have to use long int for timer and count the timer 0 overflow rate manually, like this:

Code:
long int timer;

void Int0 (void) interrupt 0
{
   TH0=0x00;      
   TL0=0x00;
   TR0=1;
   EX0=0;
   EX1=1;  
}

void timert0 (void) interrupt 1
{
   timer+=65536;
}

void Int1(void) interrupt 2
{
   TR0=0;
   EX1=0;
   
   timer = (TH0*256 + TL0);
      
   TH0=0x00;
   TL0=0x00;
}

void main(){
   P3=0x0C;
   lcd_init();
   
      TMOD = (TMOD & 0xF0) | 0x01;  /* Set T/C0 Mode */
      TH0=0x00;      
      TL0=0x00;
      TR0 = 0;                     
      
      IT0 = 1;   
      IT1 = 1;   
      EX0 = 1;   
      EX1 = 0;   
      ET0 = 1;                      /* Enable Timer 0 Interrupts *
      EA = 1;                         
      
      timer = 0;
while(1)
{         
   //timer value on lcd    
}
 

my signal length is short .it varies from 0-25 msec only, & i'm using 24Mhz xtal
 

you can not measure difrence between square signals using external interrupt.
As I undersatand you conect the waves on 2 pins generating 2 interrupts, but an exernal interrupt is generated when meets an edge. So you need to find another method to do this.
 

Please note above program is for Configuration (A) below, if you use that program to measure a square waves than you have to use configuration (B)



84_1161793051.gif
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top