Art,

Wow, that seems complicated, glad it was you figuring it out.

I took what you posted and looked at DT's Elapsed.bas.
I believe the formula that Darrel used to calculate the Timer preload value can be calculated a little easier.

First a couple of statements.
1. One thing to point out first is that if OSC = 40Mhz he sets the Timer Prescale to 2.
Otherwise the Prescale is set to 1.

2. He is indeed allowing for 8 Instruction Cycles to accommodate setting the Timer value.


The formula to set the Timer1 Preload value is the following:
Tpl = ((2^Tb)-1)-(It/(1/(Fosc/4)*Ps)-Tric)

Where:
Tpl = Timer Preload value
Fosc = OSC Frequency
It = Target Interrupt Time
Ps = Prescale value
Tb = Timer Bits (8 or 16)
Tric = Timer Reload Instruction Cycles


Here are the computation for 4,8,10,20 and 40 Mhz

4Mhz:
Tpl = ((2^Tb)-1)-(It/(1/(Fosc/4)*Ps)-Tric)
Tpl = ((2^16)-1)-(.01/(1/(4,000,000/4)*1)-8) = 55,543 (0xd8f)

8Mhz:
Tpl = ((2^Tb)-1)-(It/(1/(Fosc/4)*Ps)-Tric)
Tpl = ((2^16)-1)-(.01/(1/(8,000,000/4)*1)-8) = 45,543 (0xb1e7)

10Mhz:
Tpl = ((2^Tb)-1)-(It/(1/(Fosc/4)*Ps)-Tric)
Tpl = ((2^16)-1)-(.01/(1/(10,000,000/4)*1)-8) = 40,543 (0x9e5f)

20Mhz:
Tpl = ((2^Tb)-1)-(It/(1/(Fosc/4)*Ps)-Tric)
Tpl = ((2^16)-1)-(.01/(1/(20,000,000/4)*1)-8) = 15,543 (0x3cb7)

40Mhz:
Tpl = ((2^Tb)-1)-(It/(1/(Fosc/4)*Ps)-Tric)
Tpl = ((2^16)-1)-(.01/(1/(40,000,000/4)*2)-8) = 15,543 (0x3cb7)

Cheers.