Hi is there anyway of knowing if the LPC is receiving pulses on its INT0 pin. I have it already set up like this: IT0 = 1; //Pulses are edge detected EX0 = 1; //interrupt enable bit EA =1; It works fine, but is there anyway to find out if the pulses have stopped coming into this pin? The time the pulses will be present at this pin is unknown. This message is also posted at http://www.8052.com/forum/post.phtml
Presumably you stop getting an interrupt when the pin stops seeing edges? How long it has to be after the last edge before you decide that they have "stopped" is up to you. Hopefully you have a known input frequency and can just use a fixed timeout. If you've got a timer to spare, you could even start it on each incoming pulse, and have it generate an interrupt some time after the last edge. Otherwise, you might just timestamp the last edge in your interrupt handler, and your main loop can check the last timestamp.
Drew Davis, I think you have a good idea about what I want to do, but I do not have a fixed frequency. Can you tell me a litle bit more about this: "If you've got a timer to spare, you could even start it on each incoming pulse, and have it generate an interrupt some time after the last edge. Otherwise, you might just timestamp the last edge in your interrupt handler, and your main loop can check the last timestamp." can you explain this timestamp in more detail please? how to timestamp exactly? Thank you very much
My thought was that if you have a complicated system, including this pulse detector, you might have a free-running timer. The timestamp would just be an integer containing the time the interrupt occurred. That might be simply the value in your timer register. If the possible time you want to measure is longer than the range available with your timer, then you would have a counter for the higher-order bits that is incremented by a timer interrupt routine, with the low-order bits supplied by the timer countdown register. When an edge occurs, and you get an interrupt from that source, the edge interrupt handler copies the current time into some other variable (or data structure). This is the timestamp for the edge. You might have just one other copy, to remember the last time the most recent edge occurred. Or you might want a circular buffer to store the times for the last N edges, if you want to perform some filtering operation on that information. Once you have this timestamp, some other procedure has to check it. Probably, this is your main loop. Every so often (periodically, every time around the loop, scheduled by whatever means you use to schedule tasks in your system), you would check the timestamp, subtract it from the current time to get the time elapsed since the last edge occurred, and decide whether that elapsed time was long enough that the pulses had "stopped". The only way to be sure that the pulses have stopped is to wait an infinite amount of time. In practice, there has to be some rate so low that you're willing to say that the pulses have stopped after a certain amount of time has elapsed since you've seen an edge. Perhaps this time is a fixed amount of time (say, 1 second). Or perhaps it's a function of the pulse rate you've seen -- say, five times the longest gap between pulses, or five times the average of the most recent N pulses. There are any number of ways to decide the pulses have stopped. (Sorry to be so vague, but I can't really offer more specific suggestions as I don't know the details of your application.) Once you've answered the question "how long means stopped", then you have to figure out how to measure that amount of time. You can measure the time since the timestamp, as described above, or you could program a timer to expire when the right amount of time has elapsed, and just keep resetting that timer on every edge.
Drew Davis Thank you very much for you help. I will go over your posted message.
View all questions in Keil forum