timer doubts

.

Prove it out for yourself.
Do some serial prints to check if things are indeed doing what you think they are.
Try these additions and open up your serial monitor.

// avr-libc library includes
#include <avr/io.h>
#include <avr/interrupt.h>

volatile int cntr = 0; 
void setup()
{
  pinMode(13, OUTPUT);
  Serial.begin(9600);
  // initialize Timer1
  cli();             // disable global interrupts
  TCCR1A = 0;        // set entire TCCR1A register to 0
  TCCR1B = 0;

  // enable Timer1 overflow interrupt:
  TIMSK1 = (1 << TOIE1);
  // Set CS10 bit so timer runs at clock speed:
  TCCR1B |= (1 << CS10);
  // enable global interrupts:
  sei();
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println(cntr);
  delay(100);
}

ISR(TIMER1_OVF_vect)
{
  digitalWrite(13, !digitalRead(13));
  cntr++;
}

heixin: i'm trying out the timer overflow function is this what i am doing is correct ?

Depends on how you define "correct".

Predict what you expect to see on pin 13, and I'll tell you if you are right.

.,m

mn

Wow, a lot of register and stuff. Have you tried to print the wattage value to the serial monitor to check if it is correct?

the problem i face is not displaying the correct value

Is it displaying anything ?

Why have you not used the loop() function as intended and instead call it repeatedly from setup() in that way ?

Is display some random number up and down

You need to explain what your code is supposed to be doing, there are no comments in the code explaining its purpose and intended function.

Report what signals are coming in on the various pins, what should be happening and also what erroneous behaviour you are observing.

Could it be related to your other thread about overflow interrupts not working ? http://forum.arduino.cc/index.php?topic=206686.0

Calling loop() from an infinite loop in setup() looks pretty stupid. Why are you doing that?

None of the variables that the ISR and loop() access are declared volatile. Why not?