Using a PBP interrupt eats hundreds of instruction cycles just saving & restoring PBP system
variables.
You can get much more accurate timing, and save hundreds of instruction cycles with a
CCP Compare interrupt & .asm interrupt handler.
Try something like this;
Code:
INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
LED VAR PORTB.7
OUTPUT LED
LED = 1
ADCON1 = 7
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler CCP1_INT, CCP_INT, ASM, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
@ INT_ENABLE CCP1_INT ; enable Compare interrupt
T1CON = %00000001 ; Prescaler = 1, TMR1ON
CCP1CON = %00001011 ; compare mode, int when TMR1 = CCPR1
CCPR1L = 100 ; interrupt every 100 instruction cycles
CCPR1H = 0
MAIN:
PAUSE 50
GOTO MAIN
ASM
CCP_INT
MOVLW 0x80 ; W = %10000000
XORWF PORTB,F ; toggle RB7 on each interrupt
INT_RETURN
ENDASM
This should give you a 5kHz signal on RB7, with Timer1 reset by hardware. To change the
frequency, just change the value in CCPR1 high & low registers.
See analyzer screen capture attached.
Bookmarks