Understanding working of 2 interrupt routine

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a question here please help me understand, lets say i am running 2 timer interrupts both are called after 2ms  and also i am running a  third timer to measure delay so will this simultaneous execution of interrupts with such small time will effect the accuracy of the reading in my Timer? 

I just want to clear my concepts regarding this 

 

Timer1_intialization();

timer2_initialization();

timer3_initialization();

ISR(timer1)

ISR(timer2)

main()

{

I read the 3rd timer value here... WILL this value be 100 percent correct or there will be some error because of the 2 other timers running. 
}

 

 

This topic has a solution.
Last Edited: Fri. May 3, 2019 - 06:42 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you can use the input-capture feature, then it

will be accurate even if you are delayed reading

the value.  What are you measuring the delay of?

 

The answer to your question though is that the

controller can only do one thing at a time, so if

it has two interrupts pending, it will service the

highest priority one first by running its ISR routine.

When it's done, one instruction from your main

loop will execute and then the other ISR will get

to run.

 

--Mike

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

SufyanRaza26 wrote:
a  third timer to measure delay

Depends!

 

Not enough info to answer your question, i.e how are you measuring the delay (what delay), or are you talking about measuring an external pulse width?

The general rule of thumb is to keep your ISR()'s short to minimize the time that main has been interrupted, and non-time critical operations are in main().

 

If you need help with the design of your project, just ask.

 

Jim

 

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There'e only one CPU core and it can only execute one opcode at a time - so even things that look like they are "doing several things at once" are not exactly.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You fail to say how accurate you need timing measurement to be ....1ms? 10us, 100ns?  Please provide

 

Also, just because you are measuring several things does not mean you need a bunch of hardware timers.  Perhaps one can do the work of several.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My project was actually a digital clock interfaced with IR reciever it works fine on atmega8 .... its just that I was reading the Phillips RC5 library written in C .... it uses a biphase encoding so the smallest delay to be measured was less than .8ms and I had a considerably LARGE ISR routine so I was wondering why it is not effecting the calculation of pulse width and it should be making errors in communication.. but then i found out that there is a range in RC5 protocol for measuring width ... I was curious still so i had all the delays printed out serially on my monitor and there was considerable deviation in the value. That's why i asked..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why on earth would you have designed an ISR that takes 800 cycles at 1MHz or even more at faster speeds.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

no my function that reads the key was being called in main() so that's why all the program and a large ISR will surely take this much time... Although i know I should have used a smaller ISR somehow just to abide by the thumb rule as mentioned above..but it works fine so no worries i guess.