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.

Time Delay between interrupts

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


}
 

Did u enable global interrupts bit?? Also see to that the highest priority interrupt is given to the most appropriate signal of the both.
 

Hi,

I think u did it . But just check it whether you have converted the decimal value to the corresponding hexadecimal value.
 

To measure time delay between EXT interrupts you have to set bits IE1 (TCON.3) and IE0 (TCON.1) ..
These bits select between LEVEL and EDGE detection .. You need EDGE detection, so set them to "1" ..

Regards,
IanP
 

you have to set bits IE1 (TCON.3) and IE0 (TCON.1) ..
These bits select between LEVEL and EDGE detection ..


Sorry IanP, not IE0/IE1 but IT0/IT1, lats already set those bits.
 

Of course, it should be IT0 and IT1 .. They select falling edge / low level ..

Regards,
IanP
 

lats said:
int timer;
bit endtimer;



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;

endtimer := 1; measurement finish

TH0=0x00;
TL0=0x00;

}


void main(){

P3=0x0C;

lcd_init();

EA = 1;
TMOD = (TMOD & 0xF0) | 0x01; /* Set T/C0 Mode */
ET0 = 0; disable timer interrupt

TR0 = 0;

IT0 = 1;
IT1 = 1;
EX1 = 0;

TH0=0x00;
TL0=0x00;
endtimer = 0; flag for measurement is finish

while(1)
{

EX0 = 1; enable external intterupt 0

while (!endtimer) waiting for timer measuerent

//timer value on lcd

end timer = 0; for next measurement


}

Hi I was editing your code. may be can help your problem
Please calculate maximum and minimum your frequency signal and timer of microntroller
I think you must disable timer interupt. Only Run and Stop with TR0.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top