Ok, just to show you what is involved in ASM interrupts, this is an example for your particular case. This is the first time I am trying something like this using DT_ints, so, I may be off the mark. Most times I do it the hard way - pure asm code. Someone please correct me if I am wrong here. You should be able to realize significant improvement in the values you see. Darrell's wrapper code is cool and if you still need to save some more, look at the generated LST file and you should be able to sneak a trick or two from there. The ISR vector is at location 0004 in the PIC. So, you will find a goto INTHAND at that address.
In your case since you are not doing any math functions or gosubs in the INTs, you could keep the PBP code as-is and do away with the ASM. Can save you some agony
Code:@ __CONFIG _FCMEN_OFF & _HS_OSC & _WDT_OFF & _MCLRE_OFF & _CP_OFF & _IESO_OFF & _BOR_OFF & _PWRTE_OFF DEFINE OSC 20 ' set Oscillator at 20Mhz. DEFINE NO_CLRWDT 1 ' PBP doesn't clear WDT automatically DEFINE HSER_TXSTA 24h ' Enable transmit DEFINE HSER_SPBRG 129 ' set USART to 9600 baud @20Mhz '********************************************************************************* '16F690 Pin Connections.... ' PIN# NAME USE & CONNECTION ' 1 Vdd +5VDC power supply TRISC.4 = 0 ' 6 RC4 C2OUT TRISC.3 = 1 ' 7 RC3 C12IN3- (comparator1 input) TRISC.2 = 1 ' 14 RC2 C12IN2- (comparator2 input) TRISA.2 = 0 ' 17 RA2 C1OUT ' 20 Vss Ground '********************************************************************************* OSCCON.0 = %0001000 txsta = %10100100 'setup the tx register RCSTA.7 = 1 ' Enable RB7 for TX USART INTCON.0 = 0 ' clears the RABIF Flag (to 0), COULD be 1 on reset (unique to F690) ANSEL = 0 'disable AtoD. ANSELH = 0 'disable AtoD. 'Turn on & Set up Comparator 1 CM1CON0.7 = 1 'Comparator 1 on. CM1CON0.6 = 0 'C1OUT POLARITY BIT CM1CON0.5 = 1 '1 = C1OUT is present on the C1OUT pin (pin 17) CM1CON0.4 = 1 'C1OUT logic - 0 is not inverted (1 for inverted) CM1CON0.3 = 0 'unimplemented CM1CON0.2 = 1 'Connect internally to the output of C1VREF (or 0 for the the associated comp 'in' ext pin) CM1CON0.1 = 1 'this bit with bit 1 set the external incoming pin - in this case c12in3- (pin 7) CM1CON0.0 = 1 'this bit with bit 1 set the external incoming pin - in this case c12in3- (pin 7) 'Turn on & Set up Comparator 2 CM2CON0.7 = 1 'Comparator 2 on. CM2CON0.6 = 0 'C1OUT POLARITY BIT CM2CON0.5 = 1 '1 = C2OUT is present on the C2OUT pin (pin 6) CM2CON0.4 = 1 'C1OUT logic is not inverted (1 for inverted) CM2CON0.3 = 0 'unimplemented CM2CON0.2 = 1 'Connect internally to the output of C1VREF (or 0 for the the associated comp 'in' ext pin) CM2CON0.1 = 1 'this bit with bit 1 set the external incoming pin - in this case c12in2- (pin 14) CM2CON0.0 = 0 'this bit with bit 1 set the external incoming pin - in this case c12in2- (pin 14) ' Setup the internal VREF VRCON.7 = 1 'Comparator1 CV Ref enable bit VRCON.6 = 1 'Comparator2 CV Ref enable bit VRCON.5 = 0 'high or low range 0 = High Range, 1 = low range VRCON.4 = 0 '0.6V Reference Enable bit ....0 is disabled VRCON.3 = 0 'these 4 bits set the divider of the VREF ladder 16 values - 7 should yield 1/2 VCC VRCON.2 = 1 'these 4 bits set the divider of the VREF ladder 16 values - 7 should yield 1/2 VCC VRCON.1 = 1 'these 4 bits set the divider of the VREF ladder 16 values - 7 should yield 1/2 VCC VRCON.0 = 1 'these 4 bits set the divider of the VREF ladder 16 values - 7 should yield 1/2 VCC Comp1Time var word ' used to amalgamate TMR1 High & Low Bytes. Comp2Time var word ;-- Place a copy of these variables in your Main program ------------------- ;-- The compiler will tell you which lines to un-comment -- ;-- Do Not un-comment these lines -- ;--------------------------------------------------------------------------- wsave VAR BYTE $20 SYSTEM ' location for W if in bank0 ;wsave VAR BYTE $70 SYSTEM ' alternate save location for W ' if using $70, comment wsave1-3 ' --- IF any of these three lines cause an error ?? ------------------------ ' Comment them out to fix the problem ---- ' -- Which variables are needed, depends on the Chip you are using -- wsave1 VAR BYTE $A0 SYSTEM ' location for W if in bank1 wsave2 VAR BYTE $120 SYSTEM ' location for W if in bank2 ;wsave3 VAR BYTE $1A0 SYSTEM ' location for W if in bank3 ' -------------------------------------------------------------------------- INCLUDE "DT_INTS-14.bas" ' Base Interrupt System PO90OOO9 'INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler CMP_INT, _Comp1_Int, ASM, yes INT_Handler CMP2_INT, _Comp2_Int, ASM, yes endm INT_CREATE ; Creates the interrupt processor ENDASM T1CON.0= 1 'start timer Comp1Time = 0 'clear down Comp1Time, prior to starting. comp2Time = 0 'clear down Comp2Time, prior to starting @ INT_ENABLE CMP1_INT ; enable Comparator 1 interrupts @ INT_ENABLE CMP2_INT ; enable Comparator 2 interrupts 'Main body of Code**************************************************************** Main: HSEROUT ["comp1=",dec Comp1Time,9,"comp2Time=", dec comp2time, 13, 10] PAUSE 80 goto Main end 'Comparator1 Interrupt Handler++++++++++++++++++++++++++++++++++++++++++++++++++++ Comp1_Int: ' Comp1Time.Lowbyte = TMR1L 'Store timer1 Low into a variable ' Comp1Time.Highbyte = TMR1H 'Store timer1 high into a variable. ' TMR1H = 0 'Set the high part of the timer value to 0 ' TMR1L = 0 'Set the low part of the timer value to 0 asm movf TMR1L,w movwf _Comp1Time+0 ; the lsb movf TMR1H,w movwf _Comp1Time+1 ; the msb clrw movwf TMR1L movwf TMR1H endasm @ INT_RETURN 'Comparator2 Interrupt Handler++++++++++++++++++++++++++++++++++++++++++++++++++++ Comp2_Int: ' Comp2Time.Lowbyte = TMR1L 'Store timer1 Low into a variable ' Comp2Time.Highbyte = TMR1H 'Store timer1 high into a variable. asm movf TMR1L,w movwf _Comp2Time+0 ; the lsb movf TMR1H,w movwf _Comp2Time+1 ; the msb endasm @ INT_RETURN


, so, I may be off the mark. Most times I do it the hard way - pure asm code. Someone please correct me if I am wrong here. You should be able to realize significant improvement in the values you see. Darrell's wrapper code is cool and if you still need to save some more, look at the generated LST file and you should be able to sneak a trick or two from there. The ISR vector is at location 0004 in the PIC. So, you will find a goto INTHAND at that address.


Bookmarks