Timer 1 settings for use with Uno 16Mhz and Pro Mini 8Mhz

The title tells most of the story. I need to setup Timer 1 for a 1 millisecond interrupt period, and need to use the same code on both the Arduino UNO 5V 16Mhz and the Arduino Pro Mini 3.3V 8Mhz.

I found these settings for Timer 1 running in TIMER1_COMPA_vect mode

  TCCR1A = 0;          // normal operation
  TCCR1B = bit(WGM12) | bit(CS10) | bit (CS11);   // CTC, scale to clock / 1024
  OCR1A =  249;       // compare A register value (1000 * clock speed / 1024)
  TIMSK1 = bit (OCIE1A);             // interrupt on Compare A Match

But I think they only work with the 16Mhz chip, though I can't see where on Nick's website that is stated. I'm not sure which registers need to be changed in order to get the 1 millisecond interrupt on the 8Mhz chip. I think it is OCR1A, but don't see any instructions on how to compute the value.

Any help, answers, or links to definitive answers is appreciated. I need to get this running for work tomorrow. (I actually needed it today, but don't think any one noticed I didn't do it because I noticed the time was wrong)

The formula for the OCR value is in the datasheet. When I'm front of my other computer I will post details. In the meantime download the ATmega328P datasheet and start browsing.

Or, just grab a copy of the Timer1 library and let it do the heavy lifting for 'ya. If you're so inclined, lift the hood on the library and figure out how it handles different time bases and different clock speeds. Nothing like having a working model to examine...

https://playground.arduino.cc/Code/Timer1

avr_fred:
Or, just grab a copy of the Timer1 library and let it do the heavy lifting for 'ya. If you're so inclined, lift the hood on the library and figure out how it handles different time bases and different clock speeds. Nothing like having a working model to examine...

Arduino Playground - HomePage

Thank you for the link, but it is too late. I have the UNO working and found out past the last minute the Pro Mini wasn't timing correctly. I did not know nor did anyone mention the library. I was pointed in a direction and this is where I landed. I don't have time to rewrite the program to use the library.

scale to clock / 1024

This comment is incorrect. The registers you set(CS11,CS10) provide a clock divider of 64.

16Mhz > .0625 us *64 = 4us per tick 250 ticks (OCR1A = 249, zero referenced) = 1milliscond

8MHz > .125 us * 64 = 8us per tick 125 ticks (OCR1A = 124, zero referenced) = 1 millisecond

For the promini you want OCR1A = 124 to provide 125 clock counts * 8us.
For the uno you want OCR1A =249 to provide 250 clock counts * 4us.