Maker Pro
Maker Pro

simple function question about interupts, newbie

R

Ryan Kremser

Jan 1, 1970
0
Hello, simple question about interupts. I'm using the hc08qt4 from motorola
but if i'm not mistaken this question will apply to any microcontrollers.
With interupts when they are triggered (a pin going high/low, timer runs
out) its my undertanding that they run a specific block of code, then return
to they location where the interupt was triggered. Is this correct and if
so can one interupt interupt another? or what happens when two occur in the
same time frame. Thanks in advance
 
J

James Beck

Jan 1, 1970
0
Hello, simple question about interupts.
Is there such a thing
I'm using the hc08qt4 from motorola
but if i'm not mistaken this question will apply to any microcontrollers.
With interupts when they are triggered (a pin going high/low, timer runs
out) its my undertanding that they run a specific block of code, then return
to they location where the interupt was triggered.
That is the idea, BUT you have to code the interrupt service routine,
ISR, to handle that correctly. That might be as simple as using the
opcode that does the return (IRET, RETI, what ever the mnemonic is
applicable to your assembler) and the CPU handles the stack, or you
pushing and popping some of the registers yourself. It depends on the
CPU. Best to check the programming reference for your flavor. If you
are using a higher level language, the compiler usually has extensions
to handle interrupts.
Is this correct and if so can one interupt interupt another?
Once again depends on the CPU/MCU. Most small CPU's have a fixed
interrupt priority level, usually they are all treated the same, and
even if you re-enable the ints in your ISR there isn't a way for another
one to trigger until the current one is cleared. In some systems there
is a priority system that only allows a higher priority interrupt to
interrupt an interrupt in progress (say that three times fast). Some
systems even allow you to arrange the priority levels to suit the
application at hand. So, like I said, it depends.
or what happens when two occur in the same time frame.
See the above. If 2 ints are latched during the same cycle the
interrupt priority logic triggers which ever one is coded to be the
higher priority. The other one, or ones, wait their turn. That's just
one of the many reasons not to do too much processing in the ISR. Just
handle the INT and let the main loop do any further processing, when
possible. I have a habit of doing too much in my timer ISR at times.
On smaller systems it is easy to use the interrupt system as a psuedo-
task scheduler, but don't overload your ISRs with a lot of processing
code. You might find your main loop code is getting less clock cycles
than your interrupts.

Jim
 
Top