crystal driven interrupt calculations

Thread Starter

darrough

Joined Jan 18, 2015
86
I have miscalculated speed that an interrupt should be occurring.

Hardware is a PIC16F690. Using internal oscillator but I also have a 32.768 khz crystal for the interrupt. Timer1 has a 16 bit register. When the register overflows there is an interrupt. I preload the register with 0xFC00 = 1111 1100 0000 0000. Therefore there should be an overflow (and interrupt) after 0100 0000 0000 = 2^10 = 1024 ticks from the crystal. Right? It seems like there should be 32768 / 1024 = 32 overflows (interrupts) per second, but in fact there are around 320 per second. Where is my miscalculation? I have been over and over the math, but I cannot find the error.
 

JohnInTX

Joined Jun 26, 2012
4,787
Your basic tik counting is OK. I would suspect something in your setup or how you are reloading the timer after overflow. Writing twice to a running timer can be problematic - although in this case just writing FFh to TMR1H may be sufficient. Consider using the CCP module in mode CCP1M=1011 (count up to the compare register, reset the timer automatically).
Be sure you are running TMR1 with the ext. XTAL oscillator (TMR1CS=1) and that its oscillating at the right freq. (scope OSC2).

If you can post your code, we can take a look at it.
Have fun.
 
Last edited:
Top