Pages: [1]   Go Down
Author Topic: How to pass parameters to timer interrupt callback methods  (Read 698 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

When using a library like Timer1 to call a method after a certain amount of time, how do you give that callback method parameters?
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 89
Posts: 3483
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you got an example of what you want to do ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Edison Member
*
Karma: 17
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

When using a library like Timer1 to call a method after a certain amount of time, how do you give that callback method parameters?
You cannot with that library.

However, I think it is possible to figure out what triggered the interrupt with "flag registers," such as TIFR0. Check out the atmega328 datasheet for more information.
Logged

Chicago
Offline Offline
Full Member
***
Karma: 0
Posts: 111
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why not use Timer 1 directly? Set up the registers and add a interrupt handler.
It's pretty easy to do are you looking to use output compare ? what kind of time delay do you need?
Don
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
code]
Timer1.initialize(1500000);
Timer1.attachInterrupt(callBackMethod);

...


void callBackMethod(int someInt, int someOtherInt)
{
  ...
}


I want to do something like this, but I don't know how to pass the arguments to the callback method. The Timer1 will be assigned new interrupts/callback methods/arguments periodically.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 184
Posts: 11173
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think your only option would be to put the parameter values in volatile global variables. You can't pass them in as arguments as you're trying to do, since the interrupt mechanism doesn't support that.

If you wanted to hide the mechanics of that and didn't mind the overhead, you could write an interrupt handler which called some other function with the global variables as arguments.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok thanks. can you been using Timer1 for two interrupts (counts) at the same time? do Timer2 and 3 do the same thing as Timer1?
Logged

Pages: [1]   Go Up
Jump to: