Go Down

Topic: timer interrupt (Read 564 times) previous topic - next topic

lesto

hi,
i have some code that communicate over i2c with a sensor.
Sometimes the sensor stop working and the code stay locked in the i2c function.
Now i want use an interrupt timer, it has to be launched at least every seconds, and don't modify any prescaler etc.. because i need the timers for external library.
it will look at a variable that is incremented every loop(), and if the variable is >0 all is fine, otherwise it will reset the sensor (turn it off and restart communications?)
i've tried:

Code: [Select]

void setup(){
  Serial.begin(19200);
  TIMSK2 |= B00000100;
}
unsigned long time = micros();
void loop(){
}

ISR(TIMER2_OVF_vect) {
  Serial.println(micros()-time);
  time=micros();
};


but nothing happen... help please?
sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Graynomad

#1
Feb 03, 2011, 02:00 am Last Edit: Feb 03, 2011, 02:02 am by Graynomad Reason: 1
It looks like you're setting the OCIE2B bit (output compare), try setting TOIE2 (overflow, 0000001).

Also try using nmemonics

TIMSK2 |= (1<<TOIE2);

And "time" should be volatile if you ever start using it outside the ISR.
______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy