# Timer1 interrupt exactly one second on 16 Mhz

**URL:** <https://forum.arduino.cc/t/timer1-interrupt-exactly-one-second-on-16-mhz/434491>\
**Category:** Programming\
**Created:** [January 30, 2017, 5:53pm UTC](https://forum.arduino.cc/t/timer1-interrupt-exactly-one-second-on-16-mhz/434491 "2017-01-30T17:53:37Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![cattledog](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cattledog/32/217816_2.png) [@cattledog](https://forum.arduino.cc/u/cattledog)\
**Post date:** [January 30, 2017, 10:18pm UTC](https://forum.arduino.cc/t/timer1-interrupt-exactly-one-second-on-16-mhz/434491/7 "2017-01-30T22:18:01Z")

</div>

> each second I would like to read a counter value which is incremented when a signal is present on pin 2

What is providing the signal to pin 2 which is supposed to be 1000 counts/second?

```arduino
  TCCR1A = 0;
  TCCR1B = 0;
  timer1_counter = 34286;   // preload timer 65536-16MHz/256/2Hz

  TCNT1 = timer1_counter;   // preload timer
  TCCR1B |= (1 << CS12);    // 256 prescaler
  TIMSK1 |= (1 << TOIE1);   // enable timer overflow interrupt

```

I think you have set up the overflow for .5 second not 1 second.  
By your calulation 65536 - 34286 = 31250 _.0625_256 = .5

The factor of 2 is only relevant when you are using the timer in a mode where it counts up and down.  
When you initialize the registers you have Normal Mode (WGM13:WGM10 =0) which only counts up to OxFFFF and resets.

---

_[View the full topic](https://forum.arduino.cc/t/timer1-interrupt-exactly-one-second-on-16-mhz/434491)._
