Thanks Darrel for your reply,
1. I'm only showing part of the code, not all of it.
2. I'm not concerned about obtaining a frequency lower than it should be, I'm rather concerned about the gaps in frequency when changing by 1 the value I load into TMR1...
3. While the program is waiting for the interrupt it is only executing a while ...wend loop checking for two digital inputs, that's all. I presume the interrupt doesn't take that much in this case (no PAUSE instructions nor LCDOUT...)
4. When I add the ticks until interrupt routine executes the output frequency seems to be more unstable!!!!

suggestions are welcome, thanks a lot.

Quote Originally Posted by Darrel Taylor
First off, You can't expect ON INTERRUPT to perform accurately in the range of 20khz. It's more of a, "Whenever I get around to it" interrupt system. If you want an accurate frequency in this range, you need to use ASM.

Second, you need to ADD the constant to the existing timer value, instead of just loading the number on each interrupt. Otherwise you lose however many "Ticks" the ON INTERRUPT waited before finally servicing it.

Third, you have to account for the time it takes to ADD the constant to the timer value. And for that, you need to know how long that takes. Hard to know with Basic Interrupts.

Forth, when everything is working correctly, a Const of 65430 will give an interrupt frequency of 22.8 khz instead of 19.8.

and Fifth, You're loading a value into the TIMER registers, not the prescaler.

Ok, let's go for sixth. Setting the T1SYNC (T1CON.2) bit has no effect when using the system clock (FOSC/4) for the timer input. Doesn't hurt, but doesn't do anything constructive either.

And, yes I've been having a bad day. Sorry!
<br>