Rich D.
Active Member
Once again I am working on a project that could really use an interrupt timer function. I haven't been able to get the MEGA 2560 to do that - the library which worked for the Uno R3 for some reason didn't apply to the 2560. And yet I need the '2560 for it's 4 UART channels. I really don't understand why the Arduino software doesn't provide a timer interrupt function when it does pin interrupts. I know there are timers in there! I almost want to resort to creating a pulse output and running it straight back into an interrupt input! (I'd rather not.) So my official question is:
Does anybody know how to program an interrupt function on the MEGA2560 that can act as a timer? My application needs to create fairly accurate timer ticks - but not incredibly fast - from a range of 105,411 uSec to 375,000 uSec. I would really like to avoid writing assembly code direct to the AVR if possible. This routine could just perform the micros(); function every so often and report when the time has elapsed. I know the micros(); function only has a resolution of 4uSec, and errors of almost 100uSec are tolerable for my application.
At the fastest speeds of around 105.411 milliseconds, I don't want to truncate the timing to 105 mSec because accumulated errors will add up to poor timing accuracy. So basically I would like to pass to this interrupt function a long int value in the range of [105411 to 375000] and have the interrupt count the microseconds and flag whenever it reaches the count.
Any Arduino masters out there who want to tackle this problem?
Does anybody know how to program an interrupt function on the MEGA2560 that can act as a timer? My application needs to create fairly accurate timer ticks - but not incredibly fast - from a range of 105,411 uSec to 375,000 uSec. I would really like to avoid writing assembly code direct to the AVR if possible. This routine could just perform the micros(); function every so often and report when the time has elapsed. I know the micros(); function only has a resolution of 4uSec, and errors of almost 100uSec are tolerable for my application.
At the fastest speeds of around 105.411 milliseconds, I don't want to truncate the timing to 105 mSec because accumulated errors will add up to poor timing accuracy. So basically I would like to pass to this interrupt function a long int value in the range of [105411 to 375000] and have the interrupt count the microseconds and flag whenever it reaches the count.
Any Arduino masters out there who want to tackle this problem?