Customizing the DT_INTS-XX.bas Instant Interrupt


+ Reply to Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    328

    Default Customizing the DT_INTS-XX.bas Instant Interrupt

    Since Daryl Taylor created his Instant Interrupt Routine, Microchip has added many new features and changed PIR locations for their new MCUs. We recently visited the K40 application on the Forum, and I just revamped a special copy of the DT_INTS-18 for the 18F24_7K42 processors. I wanted to share the process so others could customize a version for whatever processor needed for their next project.

    On page 167 of the 18F27K42 Data Sheet is a Registery Summary for the Interrupt Registers (Table 9-3). Every Data Sheet has such a list. It lists INTCON as well as all of the PIR/PIE Registers. For the K42, there are 10 PIE/PIR Registers (PIR0, PIR1...PIR10). After each register is the Flag name for each Bit. For example, for PIR0 you have IOCIF, CRCIF, SCANIF, NVMIF, CSWIF, OSFIF, HLVDIF, SWIF. Some of these names are familiar, like IOCIF for the Interrupt on Port Change. CRCIF is a relatively new Function called Cyclic Redundancy Check. NVMIF is a new name for an old Interrupt. Old = EEIF for the EEPROM Write Complete Function. Now it's called Non-Volatile Memory Write Complete, or NVMIF. You don't need to know what each of the xxIF's do to create a custom DT_INTS, you just need the Interrupt Registery Summary. For the more familiar PIC18F2x_4xK22, the Interrupt Registery Summary is Table 9-1 on Page 133.

    Next, open a copy of the applicable DT_INTS-18.bas in your Microcode Studio (PBP). Assuming you have opened the last original Daryl Taylor version (not one that has already been customized by one of us Forum members), starting on Line 59 the Interrupts are Defined. On Line 59 we see:

    #define INT_INT INTCON, INTIF ;-- INT External, 16F compatible

    Every Line of the Defines begin with #define. Next is the Interrupt, INT_INT in the above example. This denotes Hardware Interrupt on PORTB.0 INT pin. For the older processors, the INTIF is in the INTCON Register. It is called INTIF in the Interrupt Registery Summary. After that are comments suggesting what that Interrupt does.

    If we leave Line 59 alone and erase from Line 60 to Line 183, we've cleared out all of the #defines for stuff we don't need, and could create conflicts. We'll leave one lone example, which we can copy/paste and modify. Taking the PIR0 listed above, we would make our own #defines like this:

    #define IOC_INT PIR0, IOCIF ;-- Interrupt on Change
    #define CRC_INT PIR0, CRCIF ;-- Cyclic Redundancy Check
    #define SCAN_INT PIR0, SCANIF ;-- For the Scan Function
    #define NMV_INT PIR0, NMVIF ;-- Non-Volatile Memory (EEPROM Write)
    #define CSW_INT PIR0, CSWIF ;-- Clock Switch
    #define OSF_INT PIR0, OSFIF ;-- Oscillator Fail
    #define HVLD_INT PIR0, HVLDIF ;-- High/Low Voltage Detect
    #define SW_INT PIR0, SWIF ;-- ?

    Now we can continue with PIR1:

    #define SMT1PWA_INT PIR1, SMT1PWAIF ;-- .....

    And so forth. Save as something unique (like DT_INTS-18_K42.bas) and you're done. The 'Save As' will prevent this custom version from accidentally getting used for the wrong processor.
    Last edited by mpgmike; - 24th November 2017 at 08:58.

  2. #2
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    328

    Default Re: Customizing the DT_INTS-XX.bas Instant Interrupt

    Part 2

    Next, Starting on Line 218 (of the original) are the same familiar Flags. *The same process is used here, where the appropriate name & Registers*are used for the MCU you are using. *For example, Lines 218 - 220 reads:

    ifdef INT0IF *;----{ INT0 External Interrupt }----------[INTCON, INT0IF]---
    * * * INT_Source *INTCON,INT0IF, INTCON,INT0IE, -1, -1
    * endif

    We would modify it to read:

    ifdef INT0IF *;----{ INT0 External Interrupt }----------[PIR1, INT0IF]---
    * * * INT_Source *PIR1,INT0IF, PIE1,INT0IE, IPR1,INT0IP
    * endif

    Another quick example, original:

    * ifdef TMR1IF *;----{ TMR1 Overflow Interrupt }------------[PIR1, TMR1IF]---
    * * * INT_Source *PIR1,TMR1IF, PIE1,TMR1IE, IPR1,TMR1IP
    * endif

    Modified for the K42:

    * ifdef TMR1IF *;----{ TMR1 Overflow Interrupt }------------[PIR4, TMR1IF]---
    * * * INT_Source *PIR4,TMR1IF, PIE4,TMR1IE, IPR4,TMR1IP
    * endif

    Hope this helps.

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default Re: Customizing the DT_INTS-XX.bas Instant Interrupt

    Thanks for the contribution !!
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231

    Default Re: Customizing the DT_INTS-XX.bas Instant Interrupt

    mpgmike,
    Thank you for explaining this. I just spent too many days trying to figure out why I wasn't getting an upgraded circuit to work. 16F18326 from 12F683. Was driving me nuts.
    Now let's see if I can do this without messing it up.

    bo

  5. #5
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,162

    Default Re: Customizing the DT_INTS-XX.bas Instant Interrupt

    Here is a modified version of DT_INTS_16 I changed to work with 16F18326 processors.
    Attached Files Attached Files
    Dave Purola,
    N8NTA
    EN82fn

  6. #6
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231

    Default Re: Customizing the DT_INTS-XX.bas Instant Interrupt

    Dave,
    Thanks for sharing that. It behaves differently than the one i did, so I'll have to compare and learn what I missed. Still hasn't corrected my INT on Change (IOC_INT) issue, so I still have something wrong. It's always something....

    bo

  7. #7
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,162

    Default Re: Customizing the DT_INTS-XX.bas Instant Interrupt

    Bo, I have NO issue using it with IOC or INT. I would make sure ALL registers are set for using IOC. I have attached the page that tells of all the resisters affected.
    Attached Images Attached Images
    Dave Purola,
    N8NTA
    EN82fn

  8. #8
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231

    Default Re: Customizing the DT_INTS-XX.bas Instant Interrupt

    Dave,
    Thank you for the help. I have been trying to look through the registers, but obviously missing something.

    Here is the stripped down core of the program. I was under the impression that DT_INTS took care of some of these registers, but manually included them in case I'm missing something.

    The TMR code is working fine, I just can't the IOC to work.


    Code:
    '****************************************************************
    '                       16F18624,25,26
    '                ---------------u-----------------
    '      5v pwr  -1|VDD++                    -- VSS |14-    Gnd     
    '              -2|RA5                 RA0/ICSPDAT |13-        
    '  Gge/Tac Drv -3|RA4                         RA1 |12-        
    '              -4|RA3/MCLR/vpp                RA2 |11-    Neutral > ECM          
    '    Tach IN   -5|RC5                         RC0 |10-    Neut LED        
    '              -6|RC4                         RC1 |9-     VSS Led     
    '        VSS   -7|RC3                         RC2 |8-              
    '                ----------------------------------    
    
    '******************************************************************
    #CONFIG
       __config _CONFIG2, _MCLRE_OFF & _CP_OFF
    #ENDCONFIG
    INCLUDE "DT_INTS-16.bas"  ; v1.10 Modified for 16F18326 IOC_INT
    INCLUDE "ReEnterPBP.pbp"    ; Include for DT_INTS.  ver 3.4
    
    ' alias pins:
    Nout        var PORTA.2  ' Neutral switch output signal  
    TachDrv     var PORTA.4  ' Tach Drive 
    N_LED       VAR PORTC.0  ' LED for Neutral
    VSS_LED     VAR PORTC.1  ' LED for VSS
    VSS         var PORTC.3  ' Vehicle Speed Sensor output signal ON 
    TachIN      var PORTC.5  ' Monitor ECM tachometer signal 
    
    PIE0 =  %00010000        ' Enable interrupts (maybe not needed)
    INTCON = %1100001        ' Global and peripheral INTS enabled, Rising edge
    IOCCP = %00100000        ' Interrupt on change on RC5, tach input
    T0CON0 = %10010000       ' TMR0 Postscale=0, 16 bit
    T0CON1 = %01000000       ' Fosc/4, No Prescale
    T1CON = %00000001        ' TMR1 prescale=2, clock=Fosc/4, TMR1=on 
    T1GCON = 0
    PORTA = %00001000        ' Outputs except 3 for SpeedAdj 
    PORTC = %00100000        ' Outputs except 5 for Tach In input 
    TRISA = %00001000        ' Pins output(except 3 for Speed adj)
    TRISC = %00100000        ' Outputs except 5 for Tach In input
    ANSELA = 0
    ANSELC = 0
    ;----[High Priority Interrupts]----------------------------------------
    ASM
    INT_LIST  macro    ; IntSource,   Label,   Type, ResetFlag?
            INT_Handler   IOC_INT,   _Capture,  PBP,  yes
            INT_Handler   TMR0_INT,  _Timer0,   PBP,  yes
            INT_Handler   TMR1_INT,  _Timer1,   PBP, yes
        endm
        INT_CREATE               ; Creates the High Priority interrupt processor
    ENDASM
    @    INT_ENABLE  IOC_INT     ; enable Capture interrupts
    @    INT_ENABLE  TMR0_INT    ; enable Timer 0 interrupts
    @    INT_ENABLE  TMR1_INT    ; enable Timer 1 interrupts
    ;-----------------------------------------------------------------------
    Main: 
    GOTO Main
    '---[IOC - interrupt handler]------------------------------------------
    Capture:  ' Enter here with Tach Pulse from ECM (IOC)
        toggle VSS_led 
        toggle N_LED
        pulsout tachdrv, 50         ' normal 4 cy tach, 500uS  
    @ INT_RETURN 
    '---[TMR0 - interrupt handler]--  --------------------------------------
    Timer0:                         ' Set Idle flag if timer expires,
       toggle Nout
    @ INT_RETURN
    '---[TMR1 - interrupt handler]----------------------------------------
    Timer1:
        toggle VSS
    @ INT_RETURN
    
    END

  9. #9
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    328

    Default Re: Customizing the DT_INTS-XX.bas Instant Interrupt

    Are you resetting the PIR0.IOCIF or IOCCF.5? This would be in the DT_INTs. It's possible you're trying to clear the wrong flag. PIR0.IOCIF is read only and is Hardware cleared when IOCCF.5 = 0.

  10. #10
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,162

    Default Re: Customizing the DT_INTS-XX.bas Instant Interrupt

    I din't see where you are clearing the individual IOCCF flag bits before or after the interrupt?
    Dave Purola,
    N8NTA
    EN82fn

  11. #11
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231

    Default Re: Customizing the DT_INTS-XX.bas Instant Interrupt

    Dave,
    It was my belief that the "yes" in
    Code:
    INT_Handler   IOC_INT,   _Capture,  PBP,  yes
    did that.
    I haven't dissected DT_INTS enough to verify that, and it may be an artifact of not originally being part of Darrel's program.
    I can look at that. Seems reasonable with the results I'm seeing.

    bo

  12. #12
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231

    Default Re: Customizing the DT_INTS-XX.bas Instant Interrupt

    Well, looking at the DT_INTS-16 that Dave was so nice to share, I couldn't see the issue, so I just added a line to clear the flag and it seems to be reacting much better. If I get the time, I may look deeper into DT_INTS and see if I can understand how it works better than the 20% I can make sense of. Until then, this seems to solve my problem.
    Code:
    '---[IOC - interrupt handler]------------------------------------------
    Capture:  ' Enter here with Tach Pulse from ECM (IOC)
        toggle VSS_led 
        toggle N_LED
        pulsout tachdrv, 50         ' normal 4 cy tach, 500uS 
        IOCCF = 0 
    @ INT_RETURN
    Now to incorporate it back into the real program and see if I have the issue solved...

    Thank you guys for all the help. Would not likely have seen that with out it.

    bo
    Last edited by boroko; - 5th May 2020 at 20:43.

  13. #13
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,162

    Default Re: Customizing the DT_INTS-XX.bas Instant Interrupt

    Glad to see you got it working Bo.
    Dave Purola,
    N8NTA
    EN82fn

  14. #14
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231

    Default Re: Customizing the DT_INTS-XX.bas Instant Interrupt

    Yeah, me too.
    Made the jump to the different processor and ordered boards for an ongoing project thinking it would be no problem. They were already a bit late, and I didn't have boards left for the older version, and they needed to go out.
    Thank you guys for the help.

    bo

Similar Threads

  1. RTCC Interrupt for DT_INTS-18.bas
    By readitaloud in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 29th November 2013, 23:33
  2. Can I use DT_INTS-18.bas and MIBAM.pbp together?
    By tacbanon in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th August 2013, 22:20
  3. DT_INTS-14.bas Reset Flag
    By Larryd in forum Serial
    Replies: 2
    Last Post: - 8th April 2013, 22:44
  4. Serial Interrupt with DT_Ints - Error
    By gadelhas in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 11th August 2010, 13:26
  5. Problem with DT_INTS-14.bas and PIC16F628A
    By CesarP in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 9th August 2010, 05:31

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts