Quote Originally Posted by skimask View Post
8Mhz / 4 = 2Mhz...
Clocking a 16 bit timer off the instruction clock @ 2Mhz = 2Mhz / 65536 = 30.517578125 interrupts per second (have to take the 1/x of the result, that's the part you forgot).
Set up the interrupt routine to count to 30, then take a sample. Yes, you'll be 16.69ms off for each second, unless you reload that particular timer at each interrupt with a correction factor to make it exactly one second. Look up the phrase PIC Multi-Calc.
If you clock an 8 bit timer off the instruction clock @ 2Mhz, 2Mhz / 256 = 7812.5 interrupts per second. Set up that interrupt routine to count to 7812, then take a sample. With the 8 bit timer, you'll only be 65us off in each second.
Oh my god, it looks so much simpler after you explained it to me. I've been reading about the timer and I still was wrong but after your explanation it is so clear to me now. Thank you!!!!!!! Just to make sure about prescaler. For example using 16bit timer with a prescaler 1:1 it would interrupt approximately 30 times per second and using prescaler 1:2 it should interrupt approximately 60 times. Is it correct?

I was just reading thread about instruction execution time by Darrel Taylor and after testing I can easily calculate what it takes to do ADC, CCP, etc. Probably I can even make a simple software clock and add to the clock execution time to compensate missing nanoseconds/milliseconds. I think interrupt clock is much easier and faster to write but what would you recommend interrupt or software clock?