How to check if interrupt is working

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

Hello,

To start interrupt I use tc_start(). To stop it I use tc_stop().
I need to check if interrupt is working or not. How to do that? What register (and its field) to check?

Regards

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

Try a breakpoint in the interrupt handler?

-sma

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

There is timer interrupt handler which I start from main program. Then interrupts works for a while and in some case stops itself. I need some "while" loop in main program, which would be checking if interrupt is running or stoped.

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

// it is automatically called by timer a few times a second
interrupt handler {
if something happened, then stop_interrupt
}

main{
start_interrupt();

while(is_interrupt_working())
;

// we are here, because interrupt stopped
}

How to construct is_interrupt_working() ?

I did it with use of variable, but how to do this with use of tc's registers?

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

Use a global variable. Increment it in the interrupt routine. Create a loop in main that does the following:
-Wait some second(s)
-Print counter value
-Clear the counter

You then have a frequency counter in main that shows the frequency of the interrupt.

Another approach is to print and clear the counter variable each time it reaches a specific value, then blink a LED to watch the pace. Actually a frequency divider.

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

Heihopp wrote:
Use a global variable. Increment it in the interrupt routine. Create a loop in main that does the following:

I have already done it with global variable. It is not a problem.
But my real question is: is there any field of any tc register which I could read to determine if interrupt handler is running or not?
Probably tc_start() sets some field of some register and tc_stop() clears such field of such register. I need to know this register and field.

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

Quote:
is there any field of any tc register which I could read to determine if interrupt handler is running or not?

This does not mean anything. You will see in the TC registers that interrupts are enabled. Then you can check the SR register (M bits) in the interrupt handler to make sure you're running in the right mode.
Or you can increment a (volatile) variable in the handler.

-sma