mmm, can you (or someone else) try the following for me? Try both with a 4 MHz and then with a 20MHz crystal. You just need to change the DEFINE OSC and the code will automatically change for you (config fuses, Prescaller and PR2). Sit a scope on PinActivar (PORTB.0) and measure the frequency. It has to be close of 4KHz
Code 1 with ON INTERRUPT
Code:
DEFINE OSC 4 ' select 4 or 20
PinActivar VAR portb.0
LoopCount VAR WORD
TMR2IF VAR PIR1.1
TRISB = 0
portb = 0
INTCON = %11000000
PIE1 = %00000010
PIR1 = %00000000
OPTION_REG = %00000000
PinActivar = 0
@ IF (OSC==20)
@ __config _HS_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
pr2 = 155
T2CON = %00000101 ' TMR2 Prescale 1:4
@ ELSE
@ __config _XT_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
PR2 = 118
T2CON = %00000100 ' TMR2 prescale 1:1
@ ENDIF
ON INTERRUPT GOTO Sample
MAIN:
GOTO MAIN
disable
Sample:
TOGGLE PinActivar
tmr2if=0
resume
enable
Code 2, with DT-INT
Code:
DEFINE OSC 4 ' select 4 or 20
INCLUDE "c:\pbp_prog\Include_routines\DT_INTS-14.bas"
INCLUDE "c:\pbp_prog\Include_routines\ReEnterPBP.bas"
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR2_INT, _Sample, PBP, YES
endm
INT_CREATE
ENDASM
PinActivar VAR portb.0
TRISB = 0
portb = 0
OPTION_REG = %00000000
@ IF (OSC==20)
@ __config _HS_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
pr2 = 155 ' load tmr2 PR2 to reset every 125 uSec
T2CON = %00000101 ' TMR2 Prescale 1:4
@ ELSE
@ __config _XT_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF
PR2 = 118
T2CON = %00000100 ' TMR2 prescale 1:1
@ ENDIF
@ INT_ENABLE TMR2_INT
MAIN:
GOTO MAIN
Sample:
toggle pinactivar
@ INT_RETURN
i'm curious to knwo if there's any significant difference between the above, and how much. I feel them equal @20MHz, but some doubt on 4MHz.
Obviously this code don't do anything interesting... i'm just curious...
As i said, i can't check anything it here.
Bookmarks