Thanks for the insight! I ended up putting all the variables used in the ISR in bank 3 and starting the interrupt with "banksel _ppm_n" in case I every move them to a different bank. I may not need the subsequent "movlw 0" and "addwfc FSR0H, f" operations since the variables are now in the same bank?
I also consolidated a few operations. The ISR now is able to initiate, run, and return to the main program in ~127 instruction cycles, which is great:
Now I'm working on converting the other ISR to asm, and am having some issues. I suspect it's how I'm trying to update the outputs on PORTC or how I'm trying to preload the highbyte of timer1 (timer1 is configured for two 8-bit R/W operations). I think the issues with the code are in red? PORTC is configured entirely as outputs and is updated with a precalculated byte from motor[mcount] that has zeros for the 4 LSBs (i.e. %XXXX0000). The value in preload[mcount] is also precalculated. Any thoughts or suggestions are much appreciated!Code:PULSE_WIDTH: asm banksel _ppm_n ; Variables used in interrupts are stored one bank via config definition - can change bank # as long as vars are in same bank movf _ppm_n, W ; Get index value from variable 'ppm_n' for array address, store in WREG 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) rlncf WREG, W ; Multiply WREG by 2 since ppm array is words (16bit) lfsr FSR0, _ppm ; Load the full 12-bit address of ppm into FSR0 addwf FSR0L, f ; Add offset from WREG to low byte of pointer movlw 0 ; clear WREG although carry flag is still active in STATUS REGISTER bit 0 addwfc FSR0H, f ; Add carry to high byte of pointer movff TMR3L, POSTINC0 ; Move TMR0L into ppm and automatically increment FSR0 movff TMR3H, INDF0 ; Move TMR0H into ppm clrf TMR3H ; reset TMR0H by loading 0 into TMR3H buffer clrf TMR3L ; reset TMR0 by loading 0 into low byte and pushing in high byte buffer btg _ppmwrite ; toggle ppmwrite to check if interrupt occured in main program INT_RETURN endasm
Code:mcount var byte bank3 motor var BYTE[6] bank3 preload var BYTE[7] bank3 T1CON = %00010000 TRISC = %00000000 '----------[High Priority Motor Interrupt]------------ ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler TMR1_INT, _MOTOR_CONTROL, ASM, yes endm INT_CREATE ENDASM MOTOR_CONTROL: ASM banksel _mcount ; Variables used in interrupts are stored one bank via config definition - can change bank # as long as vars are in same bank movf _mcount, W ; Get index value from variable 'mcount' for array address, store in WREG lfsr FSR0, _motor ; Load the full 12-bit address of motor array into FSR0 addwf FSR0L, f ; Add offset to low byte of pointer movlw 0 ; clear WREG although carry flag is still active in STATUS REGISTER bit0 addwfc FSR0H, f ; Add carry to high byte of pointer MOVFF INDF0, LATC ; Change PORTC output to adjust which motors are powered incf _mcount, f ; Increment mcount movf _mcount, W ; Get index value from variable 'mcount' for array address, store in WREG lfsr FSR0, _preload ; Load the full 12-bit address of preload array into FSR0 addwf FSR0L, f ; Add offset to low byte of pointer movlw 0 ; clear WREG although carry flag is still active in STATUS REGISTER bit0 addwfc FSR0H, f ; Add carry to high byte of pointer MOVFF INDF0, TMR1H ; Load preload byte into TMR1H INT_RETURN endasm


Reply With Quote

Bookmarks