Code:
#CONFIG
CONFIG FOSC=INTIO67, FCMEN=OFF, IESO=OFF, PWRT=OFF, BOREN=SBORDIS, BORV=18
CONFIG WDTEN=ON, WDTPS=512, CCP2MX=PORTC, PBADEN=OFF, LPT1OSC=OFF, HFOFST=ON
CONFIG MCLRE=ON, STVREN=ON, LVP=OFF, XINST=OFF, DEBUG=OFF, CP0=OFF, CP1=OFF
CONFIG CP2=OFF, CP3=OFF, CPB=OFF, CPD=OFF, WRT0=OFF, WRT1=OFF, WRT2=OFF
CONFIG WRT3=OFF, WRTC=OFF, WRTB=OFF, WRTD=OFF, EBTR0=OFF, EBTR1=OFF
CONFIG EBTR2=OFF, EBTR3=OFF, EBTRB=OFF
#ENDCONFIG
DEFINE OSC 16
pausetime var word bank0
ppm var word[16]
ppm_n var byte bank0
aflags var byte bank0
ppmwrite var aflags.0
LED VAR LATA.0
T3CON = % 10110000 'ppm timer: Prescaler = 8:1, Timer off; bit 5-4 is prescaler (00=1:1, 01=2:1 ... 11=8:1)
TRISA = % 11111110
ANSEL = $CF
OSCCON = $70
RCSTA = $90 ' Enable serial port & continuous receive
TXSTA = $20 ' Enable transmit, BRGH = 0
SPBRG = 25 ' 38400 Baud @ 16MHz, 0.16%
SPBRGH = 0
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
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
PAUSE 1000
HSErout [ "READY",13,10]
ppm_n=0
@ bsf T3CON, TMR3ON ; Start timer
@ INT_ENABLE INT0_INT ; enable external (INT) interrupts
ppmloop:
if ppmwrite then
@ INT_DISABLE INT0_INT ; disble external (INT) interrupts
;HSErout [dec ppm_N,13,10]
HSErout [13,10,13,10]
; print timer value at capture
HSErout [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],13,10]
; print interval between interrupts
HSErout [dec ppm[1]- ppm[0] ," "]
HSErout [dec ppm[3]- ppm[2] ," "]
HSErout [dec ppm[5]- ppm[4] ," "]
HSErout [dec ppm[7]- ppm[6] ," "]
HSErout [dec ppm[9]- ppm[8] ," "]
HSErout [dec ppm[11]- ppm[10] ," "]
HSErout [dec ppm[13]- ppm[12] ," "]
HSErout [dec ppm[15]- ppm[14] ,13,10]
intcon.1=0 ;clr int0 flag
ppmwrite = 0
@ INT_ENABLE INT0_INT ; enable external (INT) interrupts
endif
goto ppmloop
PULSE_WIDTH:
ASM
BTG LATA,0,A
movff TMR3L, _pausetime ; Read LB and store in variable 'pausetime' - also loads TMR3H into buffer
movff TMR3H, _pausetime + 1 ; Read HB from buffer
banksel 0
lfsr FSR0, _ppm ; set fsr0
rlncf _ppm_n, W ; Multiply index by 2 since ppm array is words (16bit)
addwf FSR0L, F ; Add offset to low byte of pointer
movlw 0 ; clear WREG although carry flag is still active in STATUS REGISTER bit 0 (pretty sure that's how it works?)
addwfc FSR0H, F ; Add carry to high byte of pointer
movf _pausetime, W ; Load pausetime LB into WREG
movwf POSTINC0 ; Store pausetime LB in ppm location and automatically increment FSR0
movf _pausetime + 1, W ; Load pausetime HB into WREG
movwf INDF0 ; Store pausetime HB in ppm location
incf _ppm_n,F ; increment index ppm_n
BTFSS _ppm_n, 4
GOTO WWW
clrf _ppm_n ; clear index after index == 16
bsf _aflags,0 ; set ppmwrite to signal main program data captured
WWW
INT_RETURN
ENDASM
Bookmarks