Go Down

Topic: Add call address to millisecond interrupt (Read 1 time) previous topic - next topic

bolts

May 26, 2016, 12:28 pm Last Edit: May 26, 2016, 12:52 pm by bolts
Many applications need to do something on a regular basis.  Clearly the millisecond interrupt is ideal for implementing this.

This interrupt could be made much more useful by being able to set a call address.

Example:

Code: [Select]

void periodic ()
{
   .
   .
   .
}

millisecond.set (&periodic);


In the above example, the function periodic will be called with every millisecond interrupt.

Yes, I know we are in critical interrupt time and there is a chance that the time spent here could be abused, but "buyer beware".

Currently I have to check if the millisecond count has changed to know if I should execute the code, which is significant overhead.

I have made these changes myself to the ISR and it works well.  But I have to apply the changes with each IDE release

Delta_G

I wouldn't exactly call a call to millis "significant overhead".
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

dmjlambert

I have made these changes myself to the ISR and it works well.  But I have to apply the changes with each IDE release
Can you please describe in detail where you make the change and how you make it, and where do you put your ISR function in the sketch you write to make use of it?

westfw


Code: [Select]
ISR(TIMER0_OVF_vect)
{
    unsigned long m = timer0_millis;
  :
    timer0_millis = m;
    timer0_overflow_count++;
// New code
   TIMER_OVF_Callback();
}


TIMER0_OVF_Callback would be initialized to point to a null function, and would have an API to set it to an arbitrary user function (just like attachInterrupt().)

It's actually a pretty bad idea.  The was ISRs work on AVR, having any function call in your ISR causes a rather large number of additional expensive instructions to be added to save and restore context that is defined by the C ABI as "callee changeable."

Go Up