0
\$\begingroup\$

I am using MikroC for dspic30f4011. I am using a Timer3 interrupt for ADC reading. In this Interrupt services routine, I am reading ADC values. In Void main, where I need some delay in the instruction . will timer3 Interrupt will read the value of ADC and will update the ADC variable? how will it work?

My question is that, if I am using an interrupt, will the delay in the Void main effects the interrupt. Will delay remaining while interrupting occurs?

one more, If use for loop for the delay as given below. If during for loop, interrupt occurs, interrupt will do its task and then start again from where it is interrupted

                               for(long q = 0; q<1000000; q++){
                                //  
                                  }

if an interrupt occurs at q=100, after interrupt service, will the for loop start again from q=101?

\$\endgroup\$
2
  • \$\begingroup\$ I don't know about this specific arch, but conventionally interrupt is interrupting the "normal flow" of the program. And the for loop in main is pretty much a "normal flow". \$\endgroup\$
    – Eugene Sh.
    Feb 21 '18 at 18:48
  • \$\begingroup\$ Just compile with optimizations and that for loop will be gone... \$\endgroup\$
    – Arsenal
    Feb 21 '18 at 19:02
0
\$\begingroup\$

if an interrupt occurs at q=100, after interrupt service, will the for loop start again from q=101?

Yes. The microcontroller suspends its current execution, and saves current state to the stack. Then it executes the interrupt service routine (ISR). Then it restores the state from the stack and continues with what it was doing. That's the nature of interrupt. Normal execution doesn't know that the interrupt have even occurred (unless you create a variable which you set in the ISR).

Just to be clear about the loop. There is no guarantee that the interrupt will occur exactly at the time when the loop starts. The interruption will occur immediately, it will not wait for the end of the loop. The loop counter itself might take several instructions to increment and compare (even if the loop has no instructions inside, and it didn't get optimized away).

\$\endgroup\$
0
\$\begingroup\$

So long as interrupts are enabled, the interrupt should fire just fine during the loop, and execution should continue in the loop where it left off after the interrupt handler finishes. This is basically the whole point of interrupts, to enable time critical processing (e.g. ADC operation) with minimal disruption of a different task (delay loop, in this case).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.