Discussion in "8051 Discussion Forum" started by    pdi33    Apr 14, 2008.
Mon Apr 14 2008, 08:30 am
well, this is a tricky problem i am facing in the external interrupt routine.
i am using the external interrupt to create a counter which accepts a limit switch input. works fine. but there is one practical problem. the limit switch sometimes generates a train of pulses(1~5 pulses) . the inetrrupt being very fast increments the counter five counts instead of one. so i had a solution, to disable the interrupt for say around 0.5 seconds as soon as the first pulse is sensed. it too works fine. but there is an inherent property of the 8051 (AT89C51), that it stores the second pulse (from the train) as a pending interrupt. so when the interupt is again enabled,the 89c51 incrementes the counter with an extra one count even if i don't give an external interrupt. how do i remove the pending interrupt?

Note: I cannot poll the input pin in main loop as i am using a multiplexed LED display which will be affected.
Even if i put the display in timer interrupt, there is a chance of missing a pulse when the display routine is executing. very confused. :mad .
help me out please.

[ Edited Mon Apr 14 2008, 09:13 am ]
Tags external interrupt 8051 (AT89C51)
Mon Apr 14 2008, 03:57 pm
simple answer :-) use edge triggered interrupt. Only when edge is sensed interrupt will be activated :-)
Mon Apr 14 2008, 04:37 pm

simple answer :-) use edge triggered interrupt. Only when edge is sensed interrupt will be activated :-)


a train of pulses can contain lot of edges
Mon Apr 14 2008, 05:48 pm
well, i was using a edge triggered interrupt . actually, i tweaked the interrupt a little.the problem is supposedly solved i think !dance .
What i did previously was
1. to clear the ie0+3 bit (disablee the interrupt in the service routine).
2. set the bit in the timer interrrupt service routine after the 1 sec. flag i needed.

the only thing i did was to clear the hardware interrupt flag (tcon+3) just before enablig the interrupt to clear any pending interrupts after it was disabled. that did the trick.

thanks guys anyway for trying to help me out.
Tue Apr 15 2008, 03:04 pm
well if you are counting edges of a i/p wave whos frequency is more than that of operating frequency of controller then surely you'll face a problem. also you will be missing pulses..

@abbas, using edge triggered interrupt you can easily count number of pulses.
Tue Apr 15 2008, 03:13 pm
I agree with u ajay that it will miss pulses if the next valid pulse is occuring within 1 second of the previous pulse. But in my case, the event occurs once in a few seconds, so missing the pulse is not ann issue. Still i can control the delay (in this case it is 1 sec.) and reduce it if required.
Tue Apr 15 2008, 04:22 pm
hmm.. you were doing something specific according to your requirement.. thats why was hard for me to understand.. good u over come ur problem
Tue Nov 24 2009, 06:17 pm

I also have problem using external Interrupt. At pin 3.2(AT89C51) I'm feeding INT0 with a pulse as follow.
Low level duration: 301 us

As Mentioned in Mazidi that the duration of low level pulse must be 4 MC unless the Interrupt again get interrupted in ISR itself.
But here it is 301 us/(4*1.085 us)= 69 (approx). It means it get interrupted 69 times or what ?

As reading the interrupt I have to generate certain time pulse.

what to do ?

[ Edited Tue Nov 24 2009, 06:19 pm ]
Wed Nov 25 2009, 04:03 pm
well if you are returning from ISR before the low level is gone from interrupt pin then processor will consider it as another interrupt.

there are two ways.. first is using edge interrupts, second delay in you ISR so that low level goes before you come out of ISR. you can also monitor state of Int pin and wait till the INT pin becomes high and then leave ISR.
Wed Nov 25 2009, 05:43 pm
I have solved it before your reply

But Anyways..Thanks

Get Social


Powered by e107 Forum System



Mon Jun 05 2023, 12:09 am
Sun Jun 04 2023, 09:34 pm
Sun Jun 04 2023, 05:31 pm
Fri Jun 02 2023, 03:12 pm
Thu Jun 01 2023, 07:33 am
Wed May 31 2023, 01:12 am
Tue May 30 2023, 12:50 pm
Tue May 30 2023, 01:06 am