Hi Guys,
i am working into a small project (library) that will configure the interrupt to call a function at every X millisecond that you want.
i got the librarie working, the class, the include part all going well.
BUT...
i got jam in the part that i need to send the function name to the interrupt routine.
right now the call is TimeCall.go(millisecond); and i would like it to be TimeCall.go(function, millisecond) and to get the ISR to call that function.
Right now i do a digital write (toggle) as a proof of concept but this is where i would like to insert the function call that TimeCall.go would have send.
Does anyone could pin point how to do that?
Thanks in advance.
Here is all my working code
#include <TimeCall.h>
// #include <avr/interrupt.h>
#include <avr/io.h>
TimeCall montime;
void setup() {
montime.go(100); // This will make a interrupt a every 100ms
}
void loop() {
}
/*
TimeCall.h - Library for calling a function at an interval time interrupt
Created by Patgadget, October 2, 2010
Released into the public domain
*/
#ifndef TimeCall_h
#define TimeCall_h
#include "WProgram.h"
class TimeCall
{
public:
void go(uint16_t millisecond );
private:
int _variable;
};
#endif
/*
TimeCall.cpp - Library for calling a function at an interval time interrupt
Created by Patgadget, October 2, 2010
Released into the public domain
*/
#include "WProgram.h"
#include <TimeCall.h>
volatile int32_t int_counter;
volatile uint16_t internal_millisecond;
void TimeCall::go(uint16_t millisecond)
{
internal_millisecond = millisecond;
//Timer2 Settings: Timer Prescaler /64,
TCCR2B = 0;
TCCR2A = 0;
TCCR2B |= (1<<CS22);
TCCR2B &= ~(1<<CS21);
TCCR2B &= ~(1<<CS20);
// Use normal mode
TCCR2A &= ~((1<<WGM21) | (1<<WGM20));
TCCR2B &= ~(1<<WGM22);
// Use internal clock - external clock not used in Arduino
ASSR |= (0<<AS2);
//Timer2 Overflow Interrupt Enable
TIMSK2 |= (1<<TOIE2);
TIMSK2 &= ~((1<<OCIE2B) | (1<<OCIE2B));
TCNT2 = 6;
}
ISR(TIMER2_OVF_vect) {
TCNT2 = 6;
int_counter += 1;
if (int_counter == internal_millisecond) {
int_counter = 0;
digitalWrite(13,1-digitalRead(13)); // THIS IS WHAT i want to replace with a function call
}
}