With 2MHz XTAL your internal Tcyc time (the input to TMR2) is 2uS. (Fosc/4)
Consulting the 'Lil Professor:
1 Sec / 2uSec per Tcyc = 500,000 Tcyc per second i.e. you have to count 500K Tcyc then interrupt. This requires 19 bits of counting. You don't have 19 bits worth of timer, prescaler and postscaler so you cannot directly get 1sec from TMR2. You are one bit short. Consider:
19bits needed - 6bit prescaler(/64) - 4bit postscaler (/16) -8bits(PR2) leaves one bit. That is consistent with my calculations that if you max out everything (pre=64,post=16,PR2=255) you get a period of .52224sec. If you had that last bit, you could exceed 1 sec.
To get one second, you'll have set TMR2 up to interrupt on some integer factor of 1 sec (500ms, 100ms etc) then count those interrupts to accumulate one second. Keep in mind that using the /64 prescaler will make it difficult to get an exact multiple of one second (factor 500,000 and group terms into what you can achieve with the pre/post/PR2 settings and you'll see). Alternately, run the PIC at a slower speed.
All of this assumes your oscillator is working as it should.
FWIW:
At 2MHz Fosc, Pre=16, Post=10, PR2=125 gives interrupts at .04sec intervals. Count 25 of these and you get 1 sec.
Good luck.
Consulting the 'Lil Professor:
1 Sec / 2uSec per Tcyc = 500,000 Tcyc per second i.e. you have to count 500K Tcyc then interrupt. This requires 19 bits of counting. You don't have 19 bits worth of timer, prescaler and postscaler so you cannot directly get 1sec from TMR2. You are one bit short. Consider:
19bits needed - 6bit prescaler(/64) - 4bit postscaler (/16) -8bits(PR2) leaves one bit. That is consistent with my calculations that if you max out everything (pre=64,post=16,PR2=255) you get a period of .52224sec. If you had that last bit, you could exceed 1 sec.
To get one second, you'll have set TMR2 up to interrupt on some integer factor of 1 sec (500ms, 100ms etc) then count those interrupts to accumulate one second. Keep in mind that using the /64 prescaler will make it difficult to get an exact multiple of one second (factor 500,000 and group terms into what you can achieve with the pre/post/PR2 settings and you'll see). Alternately, run the PIC at a slower speed.
All of this assumes your oscillator is working as it should.
FWIW:
At 2MHz Fosc, Pre=16, Post=10, PR2=125 gives interrupts at .04sec intervals. Count 25 of these and you get 1 sec.
Good luck.
Last edited: