SOLVED - Can't get IOC on pin change working


+ Reply to Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154

    Question SOLVED - Can't get IOC on pin change working

    16F18877:

    Code:
    #CONFIG
        __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_OFF & _FCMEN_ON
        __config _CONFIG2, _MCLRE_ON & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_ON & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_ON & _DEBUG_OFF
        __config _CONFIG3, _WDTCPS_WDTCPS_11 & _WDTE_ON & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
        __config _CONFIG4, _WRT_OFF & _SCANE_available & _LVP_OFF
        __config _CONFIG5, _CP_OFF & _CPD_OFF
    #ENDCONFIG
    
    DEFINE OSC 32
    
    include     "DT_INTS-14.bas"
    include     "ReEnterPBP.bas"
    
    ASM
    INT_LIST  macro      ;IntSource,  Label,     Type, ResetFlag? 
            INT_Handler   IOC_INT,    _IOCinterrupts,    PBP,  yes
        endm
        INT_CREATE                      ;Creates the interrupt processor
    ENDASM
    
    INTCON = %10000000
    '           bit 7   GIE         Global Interrupt Enable bit
    '                                   1 = Enables all active interrupts
    '           bit 6   PEIE        Peripheral Interrupt Enable bit
    '           bit 5-1     Unimplemented: Read as ‘0’
    '           bit 0   INTEDG      Interrupt Edge Select bit
    
    PIE0 = %00010000    ' PERIPHERAL INTERRUPT ENABLE REGISTER 0
    '           bit 7-6 Unimplemented: Read as ‘0’
    '           bit 5 TMR0IE: TMR0 Overflow Interrupt Enable bit
    '           bit 4 IOCIE: Interrupt-on-Change Interrupt Enable bit
    '                                   1 = Enables the IOC change interrupt
    '           bit 3-1 Unimplemented: Read as ‘0’
    '           bit 0 INTE: INT External Interrupt Flag bit
    
    IOCCP = %00010000   ' INTERRUPT-ON-CHANGE PORTC POSITIVE EDGE REGISTER
    '           bit 7-0 IOCCP<7:0>  Interrupt-on-Change PORTC Positive Edge Enable bits
    '                                   1 = Interrupt-on-Change enabled on the pin
    '                                       for a positive-going edge. IOCCFx bit
    '                                       and IOCIF flag will be set upon detecting an edge.
    
    IOCCN = %00000000   ' INTERRUPT-ON-CHANGE PORTC NEGATIVE EDGE REGISTER
    '           bit 7-0 IOCCP<7:0>  Interrupt-on-Change PORTC Negative Edge Enable bits
    '                                   1 = Interrupt-on-Change enabled on the pin
    '                                       for a Negative-going edge. IOCCFx bit
    '                                       and IOCIF flag will be set upon detecting an edge.
    
    ANSELA = %00000000
    ANSELB = %00000000
    ANSELC = %00000000
    ANSELD = %00000000
    ANSELE = %00000000
    
    TRISA = %00000000
    TRISB = %00000000
    TRISC = %00010000
    TRISD = %00000000
    TRISE = %00000000
    
    PushSwitch      VAR PortC.4
    InterruptLED    VAR LatC.2
    HeartbeatLED    VAR LatC.3
    
    ButtonWasPressed VAR byte
    
        Pause 500                                       ' Let PIC and LCD stabilize
        InterruptLED = 0
        ButtonWasPressed = 0
    
        IOCCF.4 = 0
        
    @ INT_ENABLE IOC_INT
            
        goto Mainloop
    
    IOCinterrupts:
        if IOCCF.4 = 1 then
            ButtonWasPressed = 1                        ' set a flag
            IOCCF.4 = 0
        endif
    @ INT_RETURN
    
    Mainloop:
        if ButtonWasPressed = 1 then                    ' Check flag
            InterruptLED = 1
        endif
    
        HeartbeatLED = 1
        pause 500
        HeartbeatLED = 0    
        pause 500
        
        goto mainloop
    end
    InterruptLED never lights up when I press PushSwitch, and the HeartbeatLED seems to hang for 2-3 seconds when I press.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Can't get IOC on pin change working

    Salaea Logic probe data:

    Name:  IOC pulses.png
Views: 406
Size:  28.7 KB
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Can't get IOC on pin change working

    Tried it with PEIE enabled as per 7.1 of datasheet (p. 129):

    Code:
    INTCON = %11000000
    '           bit 7   GIE         Global Interrupt Enable bit
    '                                   1 = Enables all active interrupts
    '           bit 6   PEIE        Peripheral Interrupt Enable bit
    '           bit 5-1     Unimplemented: Read as ‘0’
    '           bit 0   INTEDG      Interrupt Edge Select bit
    Did the same thing.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Can't get IOC on pin change working

    I disabled PIE0 and can confirm that the switch signal does reach the PIC (I can manually turn the LED).

    Code:
        if PushSwitch = 1 then
            Toggle InterruptLED
        endif
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Can't get IOC on pin change working

    I removed INTCON and PIE0 as per:
    https://www.picbasic.co.uk/forum/sho...517#post154517

    The HeartbeatLED doesn't hang any more, but the ISR doesn't seem to get triggered.

    Richard gives me hope; the 16F18875 is part of the same family as the 16F18877:
    https://www.picbasic.co.uk/forum/sho...529#post154529

    You need to redo the section that #defines the interrupt bit locations.
    It's in the section that looks like this...
    Code:
      #define INT_INT      	PIR0,INTF,  PIE0,INTE       ;-- External INT
      #define IOC_INT      	PIR0,IOCIF, PIE0,IOCIE     ;-- Int On Change       *
    You need to get the datasheet for the part and change the 'PIR0,INTF, PIE0,INTE' statements to match.
    I have no idea what section of the datasheet I'm supposed to be looking at.
    https://www.picbasic.co.uk/forum/sho...497#post154497

    EDIT: Found this from MpgMike (got some reading to do):
    https://support.melabs.com/forum/pic...tant-interrupt
    Last edited by Demon; - 29th August 2024 at 06:35.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Can't get IOC on pin change working

    IOC on pin C4 now works after using custom INCLUDE DT_INTS-14_16F1885x-7x.bas:

    Code:
    ;---[16F1885x7x]------------------------------------------------------------
    ; #define IOC_INT      INTCON,IOCIF, INTCON,IOCIE  ;-- Int On Change
      #define IOC_INT      PIR0,IOCIF, PIE0,IOCIE      ;-- Int On Change       *
    I need to do more testing to confirm this was all I needed, but at least it picks up the positive edge change on the pin and lights InterruptLED.


    EDIT: Complete code:

    Code:
    #CONFIG
        __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_OFF & _FCMEN_ON
        __config _CONFIG2, _MCLRE_ON & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_ON & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_ON & _DEBUG_OFF
        __config _CONFIG3, _WDTCPS_WDTCPS_11 & _WDTE_ON & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
        __config _CONFIG4, _WRT_OFF & _SCANE_available & _LVP_OFF
        __config _CONFIG5, _CP_OFF & _CPD_OFF
    #ENDCONFIG
    
    DEFINE OSC 32
    
    include     "C:\PBP Includes\DT_INTS-14_16F1885x-7x.bas"
    include     "C:\PBP Includes\ReEnterPBP.bas"
    
    ASM
    INT_LIST  macro      ;IntSource,  Label,     Type, ResetFlag? 
            INT_Handler   IOC_INT,    _MyIOCinterrupts,    PBP,  yes
        endm
        INT_CREATE                      ;Creates the interrupt processor
    ENDASM
    
    '--------------------------------------------------------------------------
    '                           Controlled by DT-INTS
    'INTCON = %10000000
    '           bit 7   GIE         Global Interrupt Enable bit
    '                                   1 = Enables all active interrupts
    '           bit 6   PEIE        Peripheral Interrupt Enable bit
    '           bit 5-1     Unimplemented: Read as ‘0’
    '           bit 0   INTEDG      Interrupt Edge Select bit
    'PIE0 = %00010000    ' PERIPHERAL INTERRUPT ENABLE REGISTER 0
    '           bit 7-6 Unimplemented: Read as ‘0’
    '           bit 5 TMR0IE: TMR0 Overflow Interrupt Enable bit
    '           bit 4 IOCIE: Interrupt-on-Change Interrupt Enable bit
    '                                   1 = Enables the IOC change interrupt
    '           bit 3-1 Unimplemented: Read as ‘0’
    '           bit 0 INTE: INT External Interrupt Flag bit
    '--------------------------------------------------------------------------
    
    IOCCP = %00010000   ' INTERRUPT-ON-CHANGE PORTC POSITIVE EDGE REGISTER
    '           bit 7-0 IOCCP<7:0>  Interrupt-on-Change PORTC Positive Edge Enable bits
    '                                   1 = Interrupt-on-Change enabled on the pin
    '                                       for a positive-going edge. IOCCFx bit
    '                                       and IOCIF flag will be set upon detecting an edge.
    
    IOCCN = %00000000   ' INTERRUPT-ON-CHANGE PORTC NEGATIVE EDGE REGISTER
    '           bit 7-0 IOCCP<7:0>  Interrupt-on-Change PORTC Negative Edge Enable bits
    '                                   1 = Interrupt-on-Change enabled on the pin
    '                                       for a Negative-going edge. IOCCFx bit
    '                                       and IOCIF flag will be set upon detecting an edge.
    
    ANSELA = %00000000
    ANSELB = %00000000
    ANSELC = %00000000
    ANSELD = %00000000
    ANSELE = %00000000
    
    TRISA = %00000000
    TRISB = %00000000
    TRISC = %00010000
    TRISD = %00000000
    TRISE = %00000000
    
    PushSwitch      VAR PortC.4
    InterruptLED    VAR LatC.2
    
    ButtonWasPressed VAR byte
    
        Pause 500                                       ' Let PIC stabilize
        InterruptLED = 0
        ButtonWasPressed = 0
        
    @ INT_ENABLE IOC_INT
    
        IOCCF.4 = 0
    
    Mainloop:
    
        if ButtonWasPressed = 1 then                    ' Check flag
            InterruptLED = 1
        endif
        
        goto mainloop
    
    MyIOCinterrupts:
    
        if IOCCF.4 = 1 then
            ButtonWasPressed = 1                        ' set a flag
            IOCCF.4 = 0
    '        INTCON.7 = 1        ' 7.1 Operation p. 129
                            ' The following events happen when an interrupt event
                            ' occurs while the GIE bit is set:
                            '   ...
                            '   • GIE bit is cleared
                            '   ...
        endif
    @ INT_RETURN
    end
    Last edited by Demon; - 29th August 2024 at 21:41.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

Similar Threads

  1. IOC on a ACD pin ?
    By longpole001 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th August 2013, 01:11
  2. Replies: 1
    Last Post: - 12th May 2012, 12:37
  3. A Simple IOC Routine (Interrupt On Change)
    By lugo.p in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th March 2010, 19:53
  4. Interrupt-on-Change-pin!
    By PICante in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 11th February 2009, 20:22
  5. HELP !!! How change the voltage of a pin ????
    By stormdacta in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 21st August 2007, 20:55

Members who have read this thread : 8

You do not have permission to view the list of names.

Posting Permissions

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