Many thanks for those who help me! (:
I got a problem here...
If i were to use 3 types of interrupts(external interrupt0, timer0 and timer1) in one single program, how should i go about writing the codes in the program?
erik, As Per Westermark mentioned in the following post, a level triggered interrupt that remains asserted can cause havoc. That can happen even if a peripheral is shutdown! I still didn't finish reading all posts, but another con I can think of, is that often when using interrupts you are bound to a certain processor pin, making portability a little more difficult.
As Per Westermark mentioned in the following post, a level triggered interrupt that remains asserted can cause havoc. That can happen even if a peripheral is shutdown! It will "cause havoc" even if polled.
Erik
which is, of course, true. but it won't if it is edge triggered :)
It will "cause havoc" even if polled.
No. A polling loop will/may run slower, but will continue to run. It is only the loop time that controls how often the signal gets polled. It is only when/if the program contains something silly like:
while (signal_x_active) process_signal_x();
that it gets into troubles if the signal is stuck.
A constantly generated interrupt will totally kill anything that hasn't higher priority than the interrupt. The main loop may not get enough processor time to be able to notice the stuck interrupt.
Since the majority of applications perform most of their jobs outside of interrupts, they are very sensitive to a interrupt handler constantly being trigged.
Per, You are right, but frankly, most of the embedded code I have seen so far does not take into consideration that a signal might "get stuck". I have to admit - I don't always check that either. I do when there is functional reason to do so - a signal remaining high for too long may indicate that the machine is experiencing some mechanial failure, and then I indicate an error and stop everything to prevent somebody from being squashed...
most level triggered interrupts reset "the level" in the ISR. in such a case it is easy to check if the reset "worked" and take action if not.
The exception to the above is some derivatives requirement for a wake up interrupt, but similar detection can be done there.
THUS, even a level triggered interrupt can be detected stuck and disabled.
Erik,
you wrote
what is a wake interrupt in this context? what do you mean?
read any datasheet for modern derivative that can be woken up from sleep mode by e.g. int0. I recall none that will wake up fron an edge int, all I recall require a level int to wake up.
Ah, I understand what you meant.