Code:
pausetime var word
ppm var word[16]
ppm_n var byte
n var byte
ppmwrite var bit
T3CON = %10110000 'ppm timer: Prescaler = 8:1, Timer off; bit 5-4 is prescaler (00=1:1, 01=2:1 ... 11=8:1)
INCLUDE "DT_INTS-18.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP interrupts
'----[High Priority PPM Interrupt]----------------------------------------------
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT0_INT, _PULSE_WIDTH, ASM, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
'clear ppm array
for n=0 to 15
ppm[n]=0
next n
ppm_n=0
@ bsf T3CON, TMR3ON ; Start timer
@ INT_ENABLE INT0_INT ; enable external (INT) interrupts
ppmloop:
pause 100
@ INT_DISABLE INT0_INT ; disble external (INT) interrupts
serout2 PIN_OUT,6,[dec ppm[0]," ",dec ppm[1]," ",dec ppm[2]," ",dec ppm[3]," ",dec ppm[4]," ",dec ppm[5]," ",dec ppm[6]," ",dec ppm[7]," ",dec ppm[8]," ",dec ppm[9]," ",dec ppm[10]," ",dec ppm[11]," ",dec ppm[12]," ",dec ppm[13]," ",dec ppm[14]," ",dec ppm[15]," ",dec ppm_n," ",dec ppmwrite,13,10]
@ INT_ENABLE INT0_INT ; enable external (INT) interrupts
goto ppmloop
PULSE_WIDTH:
ASM
movff TMR3L, _pausetime ; Read LB and store in variable 'pausetime' - also loads TMR3H into buffer
movff TMR3H, _pausetime + 1 ; Read HB from buffer
movf _ppm_n, W ; Get index value from variable 'ppm_n' for array address, store in WREG
rlncf WREG, W ; Multiply by 2 since ppm array is words (16bit)
addlw _ppm ; add base address of ppm array to offset in W
movwf FSR0 ; store the calculated address in FSR0
movf _pausetime, W ; load pausetime LB into WREG
movwf INDF0 ; move LB into ppm[ppm_n]
incf FSR0 ; move to next pointer loation for HB
movf _pausetime + 1, W ; load pausetime HB into WREG
movwf INDF0 ; move HB into ppm[ppm_n]
incf _ppm_n, f ; increment array index variable ppm_n
bcf _ppm_n, 4 ; clear bit 4 so array starts over after index 15 (b1111)
btg _ppmwrite ; toggle ppmwrite to check if interrupt occured in main program
INT_RETURN
ENDASM
Bookmarks