+ Reply to Thread
Results 1 to 23 of 23
-
- 14th November 2018, 02:36 #1
Question regarding Interrupt handler - No DT_Ints used.
Hello everyone.
I'm just wondering if I should be concerned when using an inline assembly interrupt handler to save w, status and pclath, then using pbp code to something, then reverting back to using inline assembly to exit the interrupt handler?
Any takers are appreciated. Thanks
-
- 14th November 2018, 03:13 #2
Re: Question regarding Interrupt handler - No DT_Ints used.
I'm just wondering if I should be concerned when using an inline assembly interrupt handler to save w, status and pclath, then using pbp code to something, then reverting back to using inline assembly to exit the interrupt handler?
if you mean can I call segments of pbp code called from an inline asm routine that saves and restores context {Wreg,Status,Pclat} then
the answer is no . you need to emulate the functionality of dt's reenter.bas to preserve pbp internal regs and flags.
if you mean does the context need to be preserved in isr routines then
the answer is yes always. some chips have auto context save which means the isr need not bother with that task unless it a low priority interruptThis is more entertaining than Free to Air TV
-
- 14th November 2018, 03:27 #3
Re: Question regarding Interrupt handler - No DT_Ints used.
Thanks for your reply Richard.
So basically what you are saying is that the example below is incorrect?
Code:Define INTHAND OutputControl ... ... ... ;******************************************************************************* ASM OutputControl ; Save the state of critical registers movwf wsave ; Save W swapf STATUS,W ; Swap STATUS to W (swap avoids changing STATUS) clrf STATUS ; Clear STATUS movwf ssave ; Save swapped STATUS movf PCLATH,W ; Move PCLATH to W movwf psave ; Save PCLATH ENDASM TempIOCFlgs = IOCAF for GPCounter = 0 to 3 if TempIOCFlgs.0[GPCounter] = 1 then TimerEnable.0[GPCounter] = 1 endif next GPCounter TempIOCAF = IOCAF ^ $FF ; Clear the individual interrupt flags. IOCAF = TempIOCAF & IOCAF if Mode = 1 then LED3 = 1 else LED3 = 0 endif ASM ; Restore the state of critical registers (PIC12/PIC16) movf psave,W ; restore PCLATH movwf PCLATH swapf ssave,W ; restore STATUS movwf STATUS swapf wsave,F ; restore W (swap avoids changing STATUS) swapf wsave,W retfie ENDASM ;*******************************************************************************
-
- 14th November 2018, 05:00 #4
Re: Question regarding Interrupt handler - No DT_Ints used.
sorry for the delay [customers who needs them]
So basically what you are saying is that the example below is incorrect?This is more entertaining than Free to Air TV
-
- 14th November 2018, 05:03 #5
Re: Question regarding Interrupt handler - No DT_Ints used.
Ok thanks!
-
- 15th November 2018, 00:17 #6
Re: Question regarding Interrupt handler - No DT_Ints used.
Richard,
So doing it this way as well " is a recipe for failure"? Please see example below.
Code:'******************************************************************************* '* Name : TestCode '* Author : csantex '* Notice : Copyright (c) 2018 '* : All Rights Reserved '* Date : 11/8/2018 '* Version : 1.0 '* Notes : '* : '******************************************************************************* ;******************************************************************************* ; Files that are included, ;******************************************************************************* ' @ ERRORLEVEL -306 ; Suppress messages related to Page Boundries. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;MPASM __CONFIG Directive Options. The PBP default configuration for the PIC10F322 is: #CONFIG __config _FOSC_INTOSC & _BOREN_ON & _WDTE_OFF & _MCLRE_OFF & _CP_OFF & _LVP_OFF & _PWRTE_ON & _LPBOR_OFF & _BORV_HI #ENDCONFIG ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DEFINE OSC 4 ; Oscillator set to 4Mhz set by Config1 above. DEFINE INTHAND OutputControl ; Define interrupt handler. ;******************************************************************************* ; Interrupt control registers. ;******************************************************************************* INTCON = %11001000 ; Global/Peripheral Interrups and IOC enabled. PIE1 = %00000010 ; TMR2IE: TMR2 to PR2 Match Interrupt Enable bit. PIR1 = %00000000 CLKRCON = %00000000 ; Bit 6 = 0. Reference Clock output disabled. OSCCON = %01010000 ; Bit 6-4 IRCF<2:0>: INTOSC (FOSC) Frequency Select bits @ 4Mhz. PR2 = 255 ; Decimal 255 = 240 mS timer. T2CON = %01111111 ; 1:16 Postscale, Timer2 is off, Prescaler is 64. ANSELA = %00000000 ; Set all analog pins to digital. TRISA = %00001100 ; Port A set to inputs. WPUA = %00000000 ; Weak pull-ups disabled. PORTA = %00000000 ; Clear register. LATA = %00000000 ; Clear register, set bit 0 high. ;******************************************************************************* ; Interrupt On Change for ports with IOC. Ports A only applies. ; 1 = enabled, 0 = diabled. ;******************************************************************************* IOCAF = %00000000 ; Interrupt-on-Change PORTA flags. IOCAP = %00000100 ; Interrupt-on-Change PORTA Positive Edge Enable bits. IOCAN = %00000100 ; Interrupt-on-Change PORTA Negative Edge Enable bits. ;******************************************************************************* ; Constants. ;******************************************************************************* ;******************************************************************************* ; Variables listing. ;******************************************************************************* wsave var byte BANK0 SYSTEM ; wsave in access RAM ssave var byte BANK0 SYSTEM ; wsave in access RAM psave var byte BANK0 SYSTEM ; wsave in access RAM TMR2ON var T2CON.2 TMR2IF var PIR1.1 PulseCount var byte ; General Puspose Counter to count how many pulses received. NIOCCounter var byte ; General Puspose Counter to count how many edges detected. PIOCCounter var byte ; General Puspose Counter to count how many edges detected. TimerCounts var byte ; General Puspose Counter to count how many times the timers has overflowed. States var byte ; Flag variable. OutputTmrFlg var States.0 FunctModeFlg var States.1 ;******************************************************************************* ; Port Pin names. ;******************************************************************************* Output2 var PORTA.0 ; Active high output. Output1 var PORTA.1 ; Active high output. Control var PORTA.2 ; Active low input. Mode var PORTA.3 ; Logic state input, high or low. goto Start ;******************************************************************************* ; INTERRUPT SERVICE ROUTINES START HERE. ;******************************************************************************* ; IOC interrupt handler checks which interrupt flag has been set for PORTA. ; Each flag bit corresponds to an intput. ;******************************************************************************* ASM OutputControl ; Save the state of critical registers movwf wsave ; Save W swapf STATUS,W ; Swap STATUS to W (swap avoids changing STATUS) movwf ssave ; Save swapped STATUS clrf STATUS ; Clear STATUS ENDASM ; IOC interrupt section. if IOCAF.2 = 1 then TMR2ON = 0 ; 0 = Timer2 is off. if Control = 0 then if NIOCCounter = 1 then if PIOCCounter = 1 then NIOCCounter = 2 endif if NIOCCounter = 0 then NIOCCounter = 1 endif if Control = 1 then if NIOCCounter = 2 then if PIOCCounter = 1 then PIOCCounter = 2 endif if NIOCCounter = 1 then PIOCCounter = 1 endif PR2 = 255 ; Decimal 255 = 240 mS timer. T2CON = %01111111 ; Timer2 is on. ASM MOVLW 0xff XORWF IOCAF, W ANDWF IOCAF, F ENDASM endif ; Timer 2 interrupt section. if TMR2IF = 1 then TMR2IF = 0 ; TMR2ON = 0 ; 1 = Timer2 is off. if NIOCCounter = 2 then if PIOCCounter = 2 then PulseCount = 2 endif if NIOCCounter = 1 then if PIOCCounter = 1 then PulseCount = 1 endif if TimerCounts = 0 then if OutputTmrFlg = 1 then OutputTmrFlg = 0 Output1 = 0 Output2 = 0 NIOCCounter = 0 PIOCCounter = 0 endif endif if TimerCounts = 1 then PR2 = 255 ; Decimal 255 = 240 mS timer. T2CON = %01111111 ; Timer2 is on. TimerCounts = 0 NIOCCounter = 0 PIOCCounter = 0 endif endif ASM ; Restore the state of critical registers swapf ssave,W ; restore STATUS movwf STATUS swapf wsave,F ; restore W (swap avoids changing STATUS) swapf wsave,W retfie ENDASM ;******************************************************************************* ; CODE STARTS HERE. ;******************************************************************************* ; Start of program. ;******************************************************************************* Start: PulseCount = 0 States = 0 NIOCCounter = 0 PIOCCounter = 0 TimerCounts = 0 ;******************************************************************************* Main: if Mode = 0 then ; If the jumper is in place, then we are in legacy mode. if FunctModeFlg = 1 then FunctModeFlg = 0 PulseCount = 0 OutputTmrFlg = 0 endif if PulseCount = 1 then Output2 = 1 TimerCounts = 1 gosub StartTimers endif if PulseCount = 2 then Output1 = 1 TimerCounts = 1 gosub StartTimers endif endif Mode1: if Mode = 1 then ; If the jumper is not in place, then we are in pulse mode. if FunctModeFlg = 0 then FunctModeFlg = 1 PulseCount = 0 OutputTmrFlg = 0 endif if PulseCount = 1 then Output2 = 1 TimerCounts = 0 gosub StartTimers endif if PulseCount = 2 then Output1 = 1 TimerCounts = 0 gosub StartTimers endif endif goto Main StartTimers: PulseCount = 0 PR2 = 255 ; Decimal 255 = 240 mS timer. T2CON = %01111111 ; Timer2 is on. OutputTmrFlg = 1 NIOCCounter = 0 PIOCCounter = 0 return ;******************************************************************************* End ;*******************************************************************************
Thanks again Richard for your input.
I welcome other eyes on the subject or perhaps someone might have a different approach besides converting the whole ISR into assembly.
Thanks to all who can help.
-
- 15th November 2018, 01:26 #7
Re: Question regarding Interrupt handler - No DT_Ints used.
you may get away with this flawed approach in very limited circumstances . rest assured that if you
use code that has conflicting use of pbp internal regs/flags or fsr/tblptr regs it will fail .
a careful examination of the lst file can reveal conflicts
caveat emptorThis is more entertaining than Free to Air TV
-
- 15th November 2018, 03:36 #8
Re: Question regarding Interrupt handler - No DT_Ints used.
Thanks for the pointer Richard.
I have looked through the entire LIST file not sure what I was looking for.
I looked at the following variable/ram locations and there were no inconsistencies between the LIST file and the ASM file that is generated, as one would expect.
R0 = R0_Save
R1 = R1_Save
R2 = R2_Save
R3 = R3_Save
R4 = R4_Save
R5 = R5_Save
R6 = R6_Save
R7 = R7_Save
R8 = R8_Save
FLAGS = Flags_Save
GOP = GOP_Save
RM1 = RM1_Save
RM2 = RM2_Save
RR1 = RR1_Save
RR2 = RR2_Save
The example above was taken from the Renter PBP Include. I did not see any RX_Save variables in the LIST file but I did see the Rx,RRx in there, if this makes any sense. The only reason I mention these is because as you mention before about emulating DT's Reenter PBP Include, I noticed that they were at the top of the include file so I figured that they must take priority and should be saved somewhere. Towards the end of the LIST file, I saw the example below:
Code:MEMORY USAGE MAP ('X' = Used, '-' = Unused) 0000 : X---XXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0040 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX MPASM 5.77 BRC CODE V1.ASM 11-14-2018 18:55:36 PAGE 49 MEMORY USAGE MAP ('X' = Used, '-' = Unused) 0080 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 00C0 : XXXXXXXXXXXXXXXX XXXXXXXX-------- ---------------- ---------------- 2000 : -------X-------- ---------------- ---------------- ---------------- All other memory blocks unused. Program Memory Words Used: 213 Program Memory Words Free: 299 Errors : 0 Warnings : 0 reported, 0 suppressed Messages : 0 reported, 0 suppressed
I also looked at the ERR file generated but it was blank. So I would guess it's a good thing. I understand the consequences of doing this and I do appreciate your feedback so if you have any other "pointers" to look at, again, I would greatly appreciate it.
Thanks again Richard.
-
- 15th November 2018, 03:56 #9
Re: Question regarding Interrupt handler - No DT_Ints used.
no , you must examine the code produced for the isr
expand out any calls it makes and then see what resources it uses .
once you know that you can examine the remainder of your code to see if it uses any of those same resources
if there is any conflict then the isr must preserve the conflicted resources.
there is a good reason why dt-ints exists and why its so popularThis is more entertaining than Free to Air TV
-
- 15th November 2018, 04:24 #10
-
- 15th November 2018, 04:30 #11
Re: Question regarding Interrupt handler - No DT_Ints used.
I can't compile for that chip . so I can't really speculate the list file contents
I would assume that it would not be overly complex
post it if you likeThis is more entertaining than Free to Air TV
-
- 15th November 2018, 04:52 #12
Re: Question regarding Interrupt handler - No DT_Ints used.
I tried to show it in code quotes but it was too long. Please look at the attached file.
-
- 15th November 2018, 05:28 #13
Re: Question regarding Interrupt handler - No DT_Ints used.
the revelent piece of list is below
if you search it for internal regs R0 to R8 there are no hits
if you search it for FSR USE there are no hits
the isr block makes no calls so that's clear too
{the internal regs used can be found in the symbol table at the end of the listing and in the form Rx}
there may be other bits and pieces involved re-enter.bas will give you some clues if anything else is required
Code:00177 ASM? 00178 001D 00179 OutputControl 00180 ; Save the state of critical registers 001D 00DA 00181 movwf wsave ; Save W MPASM 5.77 TEST CODE V1 - COPY.ASM 11-14-2018 21:42:28 PAGE 7 LOC OBJECT CODE LINE SOURCE TEXT VALUE 001E 0E03 00182 swapf STATUS,W ; Swap STATUS to W (swap avoids changing STATUS) 001F 00D9 00183 movwf ssave ; Save swapped STATUS 0020 0183 00184 clrf STATUS ; Clear STATUS 00185 00186 00187 ENDASM? 00188 00189 00190 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00112 PortAIOC: 00191 00192 LABEL?L _PortAIOC M ifdef PM_USED M LALL M _PortAIOC M XALL M else 0021 M _PortAIOC M endif 00193 00194 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00114 if IOCAF.2 = 1 then 00195 CMPNE?TCL _IOCAF??2, 001h, L00001 M if ((001h) == 0) M CLRWDT? M BIT?GOTO 1, IOCAF, 002h, L00001 M else M if ((001h) == 1) M CLRWDT? M ifndef NO_CLRWDT 0021 0064 M clrwdt M endif M BIT?GOTO 0, IOCAF, 002h, L00001 M ifdef USE_LINKER M CLRWDT? M else M if ($ == (L00001)) M CLRWDT? M endif M endif M M if ((0) == 0) 0022 1D1C M btfss IOCAF, 002h M else M btfsc IOCAF, 002h M endif M 0023 2858 M goto L00001 M else M L?GOTO L00001 M endif M endif 00196 00197 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00115 TMR2ON = 0 ; 0 = Timer2 is off. 00198 MOVE?CT 000h, _TMR2ON MPASM 5.77 TEST CODE V1 - COPY.ASM 11-14-2018 21:42:28 PAGE 8 LOC OBJECT CODE LINE SOURCE TEXT VALUE M if (((000h) & 1) == 1) M bsf T2CON, 002h M else 0024 1113 M bcf T2CON, 002h M endif 00199 00200 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00116 if Control = 0 then 00201 CMPNE?TCL _Control, 000h, L00003 M if ((000h) == 0) M CLRWDT? M ifndef NO_CLRWDT 0025 0064 M clrwdt M endif M BIT?GOTO 1, PORTA, 002h, L00003 M ifdef USE_LINKER M CLRWDT? M else M if ($ == (L00003)) M CLRWDT? M endif M endif M M if ((1) == 0) M btfss PORTA, 002h M else 0026 1905 M btfsc PORTA, 002h M endif M 0027 283B M goto L00003 M else M if ((000h) == 1) M CLRWDT? M BIT?GOTO 0, PORTA, 002h, L00003 M else M L?GOTO L00003 M endif M endif 00202 00203 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00117 if NIOCCounter = 1 then 00204 CMPNE?BCL _NIOCCounter, 001h, L00005 M if (((001h) > -100h) & ((001h) < 100h)) M CLRWDT? M ifndef NO_CLRWDT 0028 0064 M clrwdt M endif M MOVE?BA _NIOCCounter 0029 085B M movf _NIOCCounter, W 002A 3C01 M sublw 001h M BIT?GOTO 0, STATUS, Z, L00005 M ifdef USE_LINKER M CLRWDT? M else M if ($ == (L00005)) MPASM 5.77 TEST CODE V1 - COPY.ASM 11-14-2018 21:42:28 PAGE 9 LOC OBJECT CODE LINE SOURCE TEXT VALUE M CLRWDT? M endif M endif M M if ((0) == 0) 002B 1D03 M btfss STATUS, Z M else M btfsc STATUS, Z M endif M 002C 2834 M goto L00005 M else M L?GOTO L00005 M endif 00205 00206 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00118 if PIOCCounter = 1 then NIOCCounter = 2 00207 CMPNE?BCL _PIOCCounter, 001h, L00007 M if (((001h) > -100h) & ((001h) < 100h)) M CLRWDT? M ifndef NO_CLRWDT 002D 0064 M clrwdt M endif M MOVE?BA _PIOCCounter 002E 085C M movf _PIOCCounter, W 002F 3C01 M sublw 001h M BIT?GOTO 0, STATUS, Z, L00007 M ifdef USE_LINKER M CLRWDT? M else M if ($ == (L00007)) M CLRWDT? M endif M endif M M if ((0) == 0) 0030 1D03 M btfss STATUS, Z M else M btfsc STATUS, Z M endif M 0031 2834 M goto L00007 M else M L?GOTO L00007 M endif 00208 MOVE?CB 002h, _NIOCCounter M if (low (002h) == 0) M clrf _NIOCCounter M else 0032 3002 M movlw low (002h) 0033 00DB M movwf _NIOCCounter M endif 00209 LABEL?L L00007 M ifdef PM_USED MPASM 5.77 TEST CODE V1 - COPY.ASM 11-14-2018 21:42:28 PAGE 10 LOC OBJECT CODE LINE SOURCE TEXT VALUE M LALL M L00007 M XALL M else 0034 M L00007 M endif 00210 00211 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00119 endif 00212 LABEL?L L00005 M ifdef PM_USED M LALL M L00005 M XALL M else 0034 M L00005 M endif 00213 00214 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00120 if NIOCCounter = 0 then NIOCCounter = 1 00215 CMPNE?BCL _NIOCCounter, 000h, L00009 M if (((000h) > -100h) & ((000h) < 100h)) M CLRWDT? M ifndef NO_CLRWDT 0034 0064 M clrwdt M endif M MOVE?BA _NIOCCounter 0035 085B M movf _NIOCCounter, W 0036 3C00 M sublw 000h M BIT?GOTO 0, STATUS, Z, L00009 M ifdef USE_LINKER M CLRWDT? M else M if ($ == (L00009)) M CLRWDT? M endif M endif M M if ((0) == 0) 0037 1D03 M btfss STATUS, Z M else M btfsc STATUS, Z M endif M 0038 283B M goto L00009 M else M L?GOTO L00009 M endif 00216 MOVE?CB 001h, _NIOCCounter M if (low (001h) == 0) M clrf _NIOCCounter M else 0039 3001 M movlw low (001h) 003A 00DB M movwf _NIOCCounter M endif MPASM 5.77 TEST CODE V1 - COPY.ASM 11-14-2018 21:42:28 PAGE 11 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00217 LABEL?L L00009 M ifdef PM_USED M LALL M L00009 M XALL M else 003B M L00009 M endif 00218 00219 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00121 endif 00220 LABEL?L L00003 M ifdef PM_USED M LALL M L00003 M XALL M else 003B M L00003 M endif 00221 00222 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00122 if Control = 1 then 00223 CMPNE?TCL _Control, 001h, L00011 M if ((001h) == 0) M CLRWDT? M BIT?GOTO 1, PORTA, 002h, L00011 M else M if ((001h) == 1) M CLRWDT? M ifndef NO_CLRWDT 003B 0064 M clrwdt M endif M BIT?GOTO 0, PORTA, 002h, L00011 M ifdef USE_LINKER M CLRWDT? M else M if ($ == (L00011)) M CLRWDT? M endif M endif M M if ((0) == 0) 003C 1D05 M btfss PORTA, 002h M else M btfsc PORTA, 002h M endif M 003D 2851 M goto L00011 M else M L?GOTO L00011 M endif M endif 00224 00225 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00123 if NIOCCounter = 2 then 00226 CMPNE?BCL _NIOCCounter, 002h, L00013 MPASM 5.77 TEST CODE V1 - COPY.ASM 11-14-2018 21:42:28 PAGE 12 LOC OBJECT CODE LINE SOURCE TEXT VALUE M if (((002h) > -100h) & ((002h) < 100h)) M CLRWDT? M ifndef NO_CLRWDT 003E 0064 M clrwdt M endif M MOVE?BA _NIOCCounter 003F 085B M movf _NIOCCounter, W 0040 3C02 M sublw 002h M BIT?GOTO 0, STATUS, Z, L00013 M ifdef USE_LINKER M CLRWDT? M else M if ($ == (L00013)) M CLRWDT? M endif M endif M M if ((0) == 0) 0041 1D03 M btfss STATUS, Z M else M btfsc STATUS, Z M endif M 0042 284A M goto L00013 M else M L?GOTO L00013 M endif 00227 00228 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00124 if PIOCCounter = 1 then PIOCCounter = 2 00229 CMPNE?BCL _PIOCCounter, 001h, L00015 M if (((001h) > -100h) & ((001h) < 100h)) M CLRWDT? M ifndef NO_CLRWDT 0043 0064 M clrwdt M endif M MOVE?BA _PIOCCounter 0044 085C M movf _PIOCCounter, W 0045 3C01 M sublw 001h M BIT?GOTO 0, STATUS, Z, L00015 M ifdef USE_LINKER M CLRWDT? M else M if ($ == (L00015)) M CLRWDT? M endif M endif M M if ((0) == 0) 0046 1D03 M btfss STATUS, Z M else M btfsc STATUS, Z M endif M MPASM 5.77 TEST CODE V1 - COPY.ASM 11-14-2018 21:42:28 PAGE 13 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0047 284A M goto L00015 M else M L?GOTO L00015 M endif 00230 MOVE?CB 002h, _PIOCCounter M if (low (002h) == 0) M clrf _PIOCCounter M else 0048 3002 M movlw low (002h) 0049 00DC M movwf _PIOCCounter M endif 00231 LABEL?L L00015 M ifdef PM_USED M LALL M L00015 M XALL M else 004A M L00015 M endif 00232 00233 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00125 endif 00234 LABEL?L L00013 M ifdef PM_USED M LALL M L00013 M XALL M else 004A M L00013 M endif 00235 00236 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00126 if NIOCCounter = 1 then PIOCCounter = 1 00237 CMPNE?BCL _NIOCCounter, 001h, L00017 M if (((001h) > -100h) & ((001h) < 100h)) M CLRWDT? M ifndef NO_CLRWDT 004A 0064 M clrwdt M endif M MOVE?BA _NIOCCounter 004B 085B M movf _NIOCCounter, W 004C 3C01 M sublw 001h M BIT?GOTO 0, STATUS, Z, L00017 M ifdef USE_LINKER M CLRWDT? M else M if ($ == (L00017)) M CLRWDT? M endif M endif M M if ((0) == 0) 004D 1D03 M btfss STATUS, Z M else M btfsc STATUS, Z MPASM 5.77 TEST CODE V1 - COPY.ASM 11-14-2018 21:42:28 PAGE 14 LOC OBJECT CODE LINE SOURCE TEXT VALUE M endif M 004E 2851 M goto L00017 M else M L?GOTO L00017 M endif 00238 MOVE?CB 001h, _PIOCCounter M if (low (001h) == 0) M clrf _PIOCCounter M else 004F 3001 M movlw low (001h) 0050 00DC M movwf _PIOCCounter M endif 00239 LABEL?L L00017 M ifdef PM_USED M LALL M L00017 M XALL M else 0051 M L00017 M endif 00240 00241 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00127 endif 00242 LABEL?L L00011 M ifdef PM_USED M LALL M L00011 M XALL M else 0051 M L00011 M endif 00243 00244 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00128 PR2 = 255 ; Decimal 255 = 240 mS timer. 00245 MOVE?CB 0FFh, PR2 M if (low (0FFh) == 0) M clrf PR2 M else 0051 30FF M movlw low (0FFh) 0052 0092 M movwf PR2 M endif 00246 00247 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00129 T2CON = %01111111 ; Timer2 is on. 00248 MOVE?CB 07Fh, T2CON M if (low (07Fh) == 0) M clrf T2CON M else 0053 307F M movlw low (07Fh) 0054 0093 M movwf T2CON M endif 00249 00250 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00130 ASM 00251 00252 ASM? MPASM 5.77 TEST CODE V1 - COPY.ASM 11-14-2018 21:42:28 PAGE 15 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00253 0055 30FF 00254 MOVLW 0xff 0056 061C 00255 XORWF IOCAF, W 0057 059C 00256 ANDWF IOCAF, F 00257 00258 00259 ENDASM? 00260 00261 00262 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00135 endif 00263 LABEL?L L00001 M ifdef PM_USED M LALL M L00001 M XALL M else 0058 M L00001 M endif 00264 00265 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00139 if TMR2IF = 1 then 00266 CMPNE?TCL _TMR2IF, 001h, L00019 M if ((001h) == 0) M CLRWDT? M BIT?GOTO 1, PIR1, 001h, L00019 M else M if ((001h) == 1) M CLRWDT? M ifndef NO_CLRWDT 0058 0064 M clrwdt M endif M BIT?GOTO 0, PIR1, 001h, L00019 M ifdef USE_LINKER M CLRWDT? M else M if ($ == (L00019)) M CLRWDT? M endif M endif M M if ((0) == 0) 0059 1C8C M btfss PIR1, 001h M else M btfsc PIR1, 001h M endif M 005A 288E M goto L00019 M else M L?GOTO L00019 M endif M endif 00267 00268 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00140 TMR2IF = 0 ; 00269 MOVE?CT 000h, _TMR2IF MPASM 5.77 TEST CODE V1 - COPY.ASM 11-14-2018 21:42:28 PAGE 16 LOC OBJECT CODE LINE SOURCE TEXT VALUE M if (((000h) & 1) == 1) M bsf PIR1, 001h M else 005B 108C M bcf PIR1, 001h M endif 00270 00271 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00141 TMR2ON = 0 ; 1 = Timer2 is off. 00272 MOVE?CT 000h, _TMR2ON M if (((000h) & 1) == 1) M bsf T2CON, 002h M else 005C 1113 M bcf T2CON, 002h M endif 00273 00274 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00142 if NIOCCounter = 2 then 00275 CMPNE?BCL _NIOCCounter, 002h, L00021 M if (((002h) > -100h) & ((002h) < 100h)) M CLRWDT? M ifndef NO_CLRWDT 005D 0064 M clrwdt M endif M MOVE?BA _NIOCCounter 005E 085B M movf _NIOCCounter, W 005F 3C02 M sublw 002h M BIT?GOTO 0, STATUS, Z, L00021 M ifdef USE_LINKER M CLRWDT? M else M if ($ == (L00021)) M CLRWDT? M endif M endif M M if ((0) == 0) 0060 1D03 M btfss STATUS, Z M else M btfsc STATUS, Z M endif M 0061 2869 M goto L00021 M else M L?GOTO L00021 M endif 00276 00277 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00143 if PIOCCounter = 2 then PulseCount = 2 00278 CMPNE?BCL _PIOCCounter, 002h, L00023 M if (((002h) > -100h) & ((002h) < 100h)) M CLRWDT? M ifndef NO_CLRWDT 0062 0064 M clrwdt M endif M MOVE?BA _PIOCCounter 0063 085C M movf _PIOCCounter, W MPASM 5.77 TEST CODE V1 - COPY.ASM 11-14-2018 21:42:28 PAGE 17 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0064 3C02 M sublw 002h M BIT?GOTO 0, STATUS, Z, L00023 M ifdef USE_LINKER M CLRWDT? M else M if ($ == (L00023)) M CLRWDT? M endif M endif M M if ((0) == 0) 0065 1D03 M btfss STATUS, Z M else M btfsc STATUS, Z M endif M 0066 2869 M goto L00023 M else M L?GOTO L00023 M endif 00279 MOVE?CB 002h, _PulseCount M if (low (002h) == 0) M clrf _PulseCount M else 0067 3002 M movlw low (002h) 0068 00DD M movwf _PulseCount M endif 00280 LABEL?L L00023 M ifdef PM_USED M LALL M L00023 M XALL M else 0069 M L00023 M endif 00281 00282 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00144 endif 00283 LABEL?L L00021 M ifdef PM_USED M LALL M L00021 M XALL M else 0069 M L00021 M endif 00284 00285 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00145 if NIOCCounter = 1 then 00286 CMPNE?BCL _NIOCCounter, 001h, L00025 M if (((001h) > -100h) & ((001h) < 100h)) M CLRWDT? M ifndef NO_CLRWDT 0069 0064 M clrwdt M endif MPASM 5.77 TEST CODE V1 - COPY.ASM 11-14-2018 21:42:28 PAGE 18 LOC OBJECT CODE LINE SOURCE TEXT VALUE M MOVE?BA _NIOCCounter 006A 085B M movf _NIOCCounter, W 006B 3C01 M sublw 001h M BIT?GOTO 0, STATUS, Z, L00025 M ifdef USE_LINKER M CLRWDT? M else M if ($ == (L00025)) M CLRWDT? M endif M endif M M if ((0) == 0) 006C 1D03 M btfss STATUS, Z M else M btfsc STATUS, Z M endif M 006D 2875 M goto L00025 M else M L?GOTO L00025 M endif 00287 00288 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00146 if PIOCCounter = 1 then PulseCount = 1 00289 CMPNE?BCL _PIOCCounter, 001h, L00027 M if (((001h) > -100h) & ((001h) < 100h)) M CLRWDT? M ifndef NO_CLRWDT 006E 0064 M clrwdt M endif M MOVE?BA _PIOCCounter 006F 085C M movf _PIOCCounter, W 0070 3C01 M sublw 001h M BIT?GOTO 0, STATUS, Z, L00027 M ifdef USE_LINKER M CLRWDT? M else M if ($ == (L00027)) M CLRWDT? M endif M endif M M if ((0) == 0) 0071 1D03 M btfss STATUS, Z M else M btfsc STATUS, Z M endif M 0072 2875 M goto L00027 M else M L?GOTO L00027 M endif 00290 MOVE?CB 001h, _PulseCount MPASM 5.77 TEST CODE V1 - COPY.ASM 11-14-2018 21:42:28 PAGE 19 LOC OBJECT CODE LINE SOURCE TEXT VALUE M if (low (001h) == 0) M clrf _PulseCount M else 0073 3001 M movlw low (001h) 0074 00DD M movwf _PulseCount M endif 00291 LABEL?L L00027 M ifdef PM_USED M LALL M L00027 M XALL M else 0075 M L00027 M endif 00292 00293 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00147 endif 00294 LABEL?L L00025 M ifdef PM_USED M LALL M L00025 M XALL M else 0075 M L00025 M endif 00295 00296 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00148 if TimerCounts = 0 then 00297 CMPNE?BCL _TimerCounts, 000h, L00029 M if (((000h) > -100h) & ((000h) < 100h)) M CLRWDT? M ifndef NO_CLRWDT 0075 0064 M clrwdt M endif M MOVE?BA _TimerCounts 0076 085F M movf _TimerCounts, W 0077 3C00 M sublw 000h M BIT?GOTO 0, STATUS, Z, L00029 M ifdef USE_LINKER M CLRWDT? M else M if ($ == (L00029)) M CLRWDT? M endif M endif M M if ((0) == 0) 0078 1D03 M btfss STATUS, Z M else M btfsc STATUS, Z M endif M 0079 2882 M goto L00029 M else M L?GOTO L00029 MPASM 5.77 TEST CODE V1 - COPY.ASM 11-14-2018 21:42:28 PAGE 20 LOC OBJECT CODE LINE SOURCE TEXT VALUE M endif 00298 00299 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00149 if OutputTmrFlg = 1 then 00300 CMPNE?TCL _OutputTmrFlg, 001h, L00031 M if ((001h) == 0) M CLRWDT? M BIT?GOTO 1, _States, 000h, L00031 M else M if ((001h) == 1) M CLRWDT? M ifndef NO_CLRWDT 007A 0064 M clrwdt M endif M BIT?GOTO 0, _States, 000h, L00031 M ifdef USE_LINKER M CLRWDT? M else M if ($ == (L00031)) M CLRWDT? M endif M endif M M if ((0) == 0) 007B 1C5E M btfss _States, 000h M else M btfsc _States, 000h M endif M 007C 2882 M goto L00031 M else M L?GOTO L00031 M endif M endif 00301 00302 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00150 OutputTmrFlg = 0 00303 MOVE?CT 000h, _OutputTmrFlg M if (((000h) & 1) == 1) M bsf _States, 000h M else 007D 105E M bcf _States, 000h M endif 00304 00305 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00151 Output1 = 0 00306 MOVE?CT 000h, _Output1 M if (((000h) & 1) == 1) M bsf PORTA, 001h M else 007E 1085 M bcf PORTA, 001h M endif 00307 00308 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00152 Output2 = 0 00309 MOVE?CT 000h, _Output2 M if (((000h) & 1) == 1) MPASM 5.77 TEST CODE V1 - COPY.ASM 11-14-2018 21:42:28 PAGE 21 LOC OBJECT CODE LINE SOURCE TEXT VALUE M bsf PORTA, 000h M else 007F 1005 M bcf PORTA, 000h M endif 00310 00311 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00153 NIOCCounter = 0 00312 MOVE?CB 000h, _NIOCCounter M if (low (000h) == 0) 0080 01DB M clrf _NIOCCounter M else M movlw low (000h) M movwf _NIOCCounter M endif 00313 00314 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00154 PIOCCounter = 0 00315 MOVE?CB 000h, _PIOCCounter M if (low (000h) == 0) 0081 01DC M clrf _PIOCCounter M else M movlw low (000h) M movwf _PIOCCounter M endif 00316 00317 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00155 endif 00318 LABEL?L L00031 M ifdef PM_USED M LALL M L00031 M XALL M else 0082 M L00031 M endif 00319 00320 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00156 endif 00321 LABEL?L L00029 M ifdef PM_USED M LALL M L00029 M XALL M else 0082 M L00029 M endif 00322 00323 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00157 if TimerCounts = 1 then 00324 CMPNE?BCL _TimerCounts, 001h, L00033 M if (((001h) > -100h) & ((001h) < 100h)) M CLRWDT? M ifndef NO_CLRWDT 0082 0064 M clrwdt M endif M MOVE?BA _TimerCounts 0083 085F M movf _TimerCounts, W 0084 3C01 M sublw 001h MPASM 5.77 TEST CODE V1 - COPY.ASM 11-14-2018 21:42:28 PAGE 22 LOC OBJECT CODE LINE SOURCE TEXT VALUE M BIT?GOTO 0, STATUS, Z, L00033 M ifdef USE_LINKER M CLRWDT? M else M if ($ == (L00033)) M CLRWDT? M endif M endif M M if ((0) == 0) 0085 1D03 M btfss STATUS, Z M else M btfsc STATUS, Z M endif M 0086 288E M goto L00033 M else M L?GOTO L00033 M endif 00325 00326 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00158 PR2 = 255 ; Decimal 255 = 240 mS timer. 00327 MOVE?CB 0FFh, PR2 M if (low (0FFh) == 0) M clrf PR2 M else 0087 30FF M movlw low (0FFh) 0088 0092 M movwf PR2 M endif 00328 00329 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00159 T2CON = %01111111 ; Timer2 is on. 00330 MOVE?CB 07Fh, T2CON M if (low (07Fh) == 0) M clrf T2CON M else 0089 307F M movlw low (07Fh) 008A 0093 M movwf T2CON M endif 00331 00332 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00160 TimerCounts = 0 00333 MOVE?CB 000h, _TimerCounts M if (low (000h) == 0) 008B 01DF M clrf _TimerCounts M else M movlw low (000h) M movwf _TimerCounts M endif 00334 00335 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00161 NIOCCounter = 0 00336 MOVE?CB 000h, _NIOCCounter M if (low (000h) == 0) 008C 01DB M clrf _NIOCCounter M else M movlw low (000h) MPASM 5.77 TEST CODE V1 - COPY.ASM 11-14-2018 21:42:28 PAGE 23 LOC OBJECT CODE LINE SOURCE TEXT VALUE M movwf _NIOCCounter M endif 00337 00338 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00162 PIOCCounter = 0 00339 MOVE?CB 000h, _PIOCCounter M if (low (000h) == 0) 008D 01DC M clrf _PIOCCounter M else M movlw low (000h) M movwf _PIOCCounter M endif 00340 00341 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00163 endif 00342 LABEL?L L00033 M ifdef PM_USED M LALL M L00033 M XALL M else 008E M L00033 M endif 00343 00344 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00165 endif 00345 LABEL?L L00019 M ifdef PM_USED M LALL M L00019 M XALL M else 008E M L00019 M endif 00346 00347 ; C:\TEST CODE\TEST CODE V1 - COPY.PBP 00167 ASM 00348 00349 ASM? 00350 00351 ; Restore the state of critical registers 008E 0E59 00352 swapf ssave,W ; restore STATUS 008F 0083 00353 movwf STATUS 0090 0EDA 00354 swapf wsave,F ; restore W (swap avoids changing STATUS) 0091 0E5A 00355 swapf wsave,W 0092 0009 00356 retfie 00357 00358 00359 ENDASM? 00360
This is more entertaining than Free to Air TV
-
- 15th November 2018, 05:32 #14
Re: Question regarding Interrupt handler - No DT_Ints used.
ps on those limited resource use
DEFINE NO_CLRWDT 1 'Don’t insert CLRWDTs
and make sure wdt is off in config
can save some spaceThis is more entertaining than Free to Air TV
-
- 15th November 2018, 05:43 #15
Re: Question regarding Interrupt handler - No DT_Ints used.
Thanks for all your help Richard.
-
- 15th November 2018, 10:02 #16
Re: Question regarding Interrupt handler - No DT_Ints used.
Hi,
You could try to use only ReEnterPBP.bas to take care about saving and restoring variables.
So just call
SavePBP_H:
After saving status wreg etc,
And before you exit interrupt call
RestorePBP_H:
Than restore Status etc
-
- 15th November 2018, 20:01 #17
Re: Question regarding Interrupt handler - No DT_Ints used.
Thanks for the advice pedja089. I couldn't make it work as you suggested but I did manage to get it to work this way:
Code:;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DEFINE OSC 4 ; Oscillator set to 4Mhz set by Config1 above. DEFINE INTHAND OutputControl ; Define interrupt handler. DEFINE NO_CLRWDT 1 ; Don’t insert CLRWDTs. ;******************************************************************************* ; Interrupt control registers. Not used. ;******************************************************************************* INTCON = %11001000 ; Global/Peripheral Interrups and IOC enabled. PIE1 = %00000010 ; TMR2IE: TMR2 to PR2 Match Interrupt Enable bit. PIR1 = %00000000 CLKRCON = %00000000 ; Bit 6 = 0. Reference Clock output disabled. OSCCON = %01010000 ; Bit 6-4 IRCF<2:0>: INTOSC (FOSC) Frequency Select bits @ 4Mhz. PR2 = 255 ; Decimal 255 = 240 mS timer. T2CON = %01111111 ; 1:16 Postscale, Timer2 is off, Prescaler is 64. ANSELA = %00000000 ; Set all analog pins to digital. TRISA = %00001100 ; Port A set to inputs. WPUA = %00000000 ; Weak pull-ups disabled. PORTA = %00000000 ; Clear register. LATA = %00000000 ; Clear register, set bit 0 high. ;******************************************************************************* ; Interrupt On Change for ports with IOC. Ports A,B and C only apply. ; 1 = enabled, 0 = diabled. ;******************************************************************************* IOCAF = %00000000 ; Interrupt-on-Change PORTA flags. IOCAP = %00000100 ; Interrupt-on-Change PORTA Positive Edge Enable bits. IOCAN = %00000100 ; Interrupt-on-Change PORTA Negative Edge Enable bits. ;******************************************************************************* ; Constants. ;******************************************************************************* ;******************************************************************************* ; Variables listing. ;******************************************************************************* wsave var byte BANK0 SYSTEM ; wsave in access RAM ssave var byte BANK0 SYSTEM ; wsave in access RAM psave var byte BANK0 SYSTEM ; wsave in access RAM ' Save locations for PBP system Vars R0_Save VAR WORD ;BANK0 SYSTEM R1_Save VAR WORD ;BANK0 SYSTEM R2_Save VAR WORD ;BANK0 SYSTEM R3_Save VAR WORD ;BANK0 SYSTEM R4_Save VAR WORD ;BANK0 SYSTEM R5_Save VAR WORD ;BANK0 SYSTEM R6_Save VAR WORD ;BANK0 SYSTEM R7_Save VAR WORD ;BANK0 SYSTEM R8_Save VAR WORD ;BANK0 SYSTEM Flags_Save VAR BYTE ;BANK0 SYSTEM GOP_Save VAR BYTE ;BANK0 SYSTEM RM1_Save VAR BYTE ;BANK0 SYSTEM RM2_Save VAR BYTE ;BANK0 SYSTEM RR1_Save VAR BYTE ;BANK0 SYSTEM RR2_Save VAR BYTE ;BANK0 SYSTEM TMR2ON var T2CON.2 TMR2IF var PIR1.1 PulseCount var byte ; General Puspose Counter to count how many pulses received. NIOCCounter var byte ; General Puspose Counter to count how many edges detected. PIOCCounter var byte ; General Puspose Counter to count how many edges detected. TimerCounts var byte ; General Puspose Counter to count how many times the timers has overflowed. States var byte ; Flag variable. OutputTmrFlg var States.0 FunctModeFlg var States.1 ControlFlg var States.2 ;******************************************************************************* ; Port Pin names. ;******************************************************************************* Output2 var PORTA.0 ; Active high output. Output1 var PORTA.1 ; Active high output. Control var PORTA.2 ; Active low input. Mode var PORTA.3 ; Logic state input, high or low. goto Start ;******************************************************************************* ; INTERRUPT SERVICE ROUTINES START HERE. ;******************************************************************************* ;ASM INTERRUPTS COURTESY OF DARREL TAYLOR. ;******************************************************************************* ' ASM 'INT_LIST macro ; IntSource, Label, Type, ResetFlag? ' INT_Handler IOC_INT, _OutputControl , PBP, yes ' INT_Handler TMR2_INT, _TimerControl , PBP, yes ' endm ' INT_CREATE ; Creates the interrupt processor ' ENDASM '@ INT_ENABLE IOC_INT ; Enable Interrupts On Change interrupts '@ INT_ENABLE TMR2_INT ; Enable Timer 1 interrupts ; IOC interrupt handler checks which interrupt flag has been set for PORTA. ; Each flag bit corresponds to an intput. ;******************************************************************************* ASM OutputControl ; Save the state of critical registers movwf wsave ; Save W swapf STATUS,W ; Swap STATUS to W (swap avoids changing STATUS) clrf STATUS ; Clear STATUS movwf ssave ; Save swapped STATUS movf PCLATH,W ; Move PCLATH to W movwf psave ; Save PCLATH ; call _SavePBP_H ENDASM SavePBP: ' Save all PBP system Vars R0_Save = R0 ' 4/ 4 R1_Save = R1 ' 4/ 8 R2_Save = R2 ' 4/12 R3_Save = R3 ' 4/16 R4_Save = R4 ' 4/20 R5_Save = R5 ' 4/24 R6_Save = R6 ' 4/28 R7_Save = R7 ' 4/32 R8_Save = R8 ' 4/36 Flags_Save = FLAGS ' 2/38 GOP_Save = GOP ' 2/40 RM1_Save = RM1 ' 2/42 RM2_Save = RM2 ' 2/44 RR1_Save = RR1 ' 2/46 RR2_Save = RR2 ' 2/48 'OutputControl: ; IOC interrupt section. if IOCAF.2 = 1 then TMR2ON = 0 ; 0 = Timer2 is off. if Control = 0 then if NIOCCounter = 1 then if PIOCCounter = 1 then NIOCCounter = 2 endif if NIOCCounter = 0 then NIOCCounter = 1 endif if Control = 1 then if NIOCCounter = 2 then if PIOCCounter = 1 then PIOCCounter = 2 endif if NIOCCounter = 1 then PIOCCounter = 1 endif PR2 = 255 ; Decimal 255 = 240 mS timer. T2CON = %01111111 ; Timer2 is on. ASM MOVLW 0xff XORWF IOCAF, W ANDWF IOCAF, F ENDASM endif '@ INT_RETURN ;******************************************************************************* 'TimerControl: ; Timer 2 interrupt section. if TMR2IF = 1 then TMR2IF = 0 ; TMR2ON = 0 ; 1 = Timer2 is off. if NIOCCounter = 2 then if PIOCCounter = 2 then PulseCount = 2 endif if NIOCCounter = 1 then if PIOCCounter = 1 then PulseCount = 1 endif if TimerCounts = 0 then if OutputTmrFlg = 1 then OutputTmrFlg = 0 Output1 = 0 Output2 = 0 NIOCCounter = 0 PIOCCounter = 0 endif endif if TimerCounts = 1 then PR2 = 255 ; Decimal 255 = 240 mS timer. T2CON = %01111111 ; Timer2 is on. TimerCounts = 0 NIOCCounter = 0 PIOCCounter = 0 endif endif '@ INT_RETURN RestorePBP: R0 = R0_Save R1 = R1_Save R2 = R2_Save R3 = R3_Save R4 = R4_Save R5 = R5_Save R6 = R6_Save R7 = R7_Save R8 = R8_Save FLAGS = Flags_Save GOP = GOP_Save RM1 = RM1_Save RM2 = RM2_Save RR1 = RR1_Save RR2 = RR2_Save ASM ; Restore the state of critical registers ; call _RestorePBP_H movf psave,W ; restore PCLATH movwf PCLATH swapf ssave,W ; restore STATUS movwf STATUS swapf wsave,F ; restore W (swap avoids changing STATUS) swapf wsave,W retfie ENDASM ;******************************************************************************* ; CODE STARTS HERE. ;*******************************************************************************
The test that I've been running has not failed as of yet. I have another test running with this new ISR version. I'll wait and see who will fail first, if anyone is interested.
Thank you both (Richard and pedja089) for your help.
-
- 15th November 2018, 21:38 #18
Re: Question regarding Interrupt handler - No DT_Ints used.
There's nothing wrong with saving all that stuff, but that's a lot of bother for what you've got going on.
If all you do is simple sets and tests with port bits and bytes like you have then you don't really need any of it
except for what you had originally. You're code isn't using any of the PBP system variables.
-
- 15th November 2018, 23:40 #19
Re: Question regarding Interrupt handler - No DT_Ints used.
Thanks for your input tumbleweed. What you said coincides with what I have been able to gather by looking at the LST file. As Richard pointed out, I may have been stepping on system variables but couldn't find anywhere in the file where I was doing it. Thanks to Richard, I now have a greater understanding of the inner workings of PBP.
So far, my testing has not yielded any errors or failures which would add to the belief that the code was fine from the beginning as you stated. Thanks goes to all who put in their two cents. It was money well spent on my education.
If anything changes in my testing, I'll post about it for those who are interested.
Thanks for all the help everyone, Cheers.
-
- 16th November 2018, 04:42 #20
Re: Question regarding Interrupt handler - No DT_Ints used.
Section 6.5 (page 39) of the PIC10F322 Data Sheet declares the only context saving it does is saves the PC. Example 6-1 spells out the minimal Assembly code required to accomplish that feat (note, you must declare the variables wsave and ssave). You can eliminate the psave variable and related code. I'm not sure how time sensitive your Interrupt results are, but here's a thought:
I like to create Bits that I use as flags ("flag1 VAR BIT" works). In the Main routine, I poll these flags. The flags are set by the ISR. Setting them may be time sensitive, but initiating ALL of the code related may not be. If you can "get around to" dealing with at least some of the duties with a couple instruction cycles of delay, just set a flag in the ISR then poll that flag in Main. Create subroutines that deal with the actual duties. It keeps the ISR short, it "corrupts" very few registers, and keeps you in familiar PBP territory.
As a side note, you are attempting to return from your ISR with the "@ INT_RETURN " command. That ONLY works with DT_INTS. Returning from a PBP interrupt, use RESUME; returning from an ASM interrupt, use RETFIE. Hope this helps.
-
- 16th November 2018, 08:11 #21
Re: Question regarding Interrupt handler - No DT_Ints used.
I would be pretty cautious about that. pbp code is full of goto's
actual note from data sheet
Note: These devices do not require saving the
PCLATH. However, if computed GOTOs
are used in both the ISR and the main
code, the PCLATH must be saved and
restored in the ISR.
GOTO Unconditional BranchSyntax: [label ] GOTO k
Operands: 0
k 2047
Operation: k
PC<10:0>
PCLATH<4:3>
PC<12:11>
Status Affected: None
Description:
GOTO is an unconditional branch.
The 11-bit immediate value is
loaded into PC bits <10:0>. The
upper bits of PC are loaded from
PCLATH<4:3>.
GOTO is a
2-cycle instruction
This is more entertaining than Free to Air TV
-
- 16th November 2018, 11:50 #22
Re: Question regarding Interrupt handler - No DT_Ints used.
It's probably good to be aware of the minimal context saving done automatically, but for the code in question it's not using any computed GOTO's so I think you should be safe with the code pretty much as originally posted in #6.
In the Main routine, I poll these flags. The flags are set by the ISR. Setting them may be time sensitive, but initiating ALL of the code related may not be
Depending on what's going on inside the main loop, many times this approach ends up being faster (and a lot more reliable) than using interrupts.
PS a lot of Richard's comments are spot on, esp. the one about adding 'DEFINE NO_CLRWDT 1'. PBP can add a lot of things "behind the scene", so you do have to careful about what features you use when doing the minimal approach.Last edited by tumbleweed; - 16th November 2018 at 12:02.
-
- 16th November 2018, 20:18 #23
Re: Question regarding Interrupt handler - No DT_Ints used.
UART Receive specifically came to mind with the "flags" comment. Unload the RCREG, set a flag, then figure out what it means later. This still requires an Interrupt to clear out the RCREG so the next byte can be received, but it can be loaded into a buffer through the ISR and deciphered later from the Main loop (or subroutine).
Similar Threads
-
Counting Timer0 and Timer1 overflows without any interrupt handler
By dw_picbasic in forum mel PIC BASIC ProReplies: 32Last Post: - 16th March 2015, 22:33 -
PIC18 timer0 interrupt handler, still not getting it
By ImAnEE in forum mel PIC BASIC ProReplies: 4Last Post: - 30th April 2011, 00:25 -
Interrupt Handler issue with PBPro
By DonD in forum mel PIC BASIC ProReplies: 1Last Post: - 18th February 2011, 21:04 -
PIC18 interrupt handler, where to save W etc?
By ImAnEE in forum mel PIC BASIC ProReplies: 16Last Post: - 13th June 2010, 08:18 -
DT-INTs Interrupt handler question
By circuitpro in forum mel PIC BASIC ProReplies: 1Last Post: - 8th January 2010, 01:06
Bookmarks