Menu

interrupt on change not calling the interrupt sub

2019-02-09
2019-02-09
  • Giuseppe D'Elia

    Giuseppe D'Elia - 2019-02-09

    Hi all,
    I'm using interrupts on change on rising edge of one of four selected pins.
    The code is sensing the rising edge. In fact the code execution stops when the rising edge is encountered.
    However, the interrupt sub is not called and the code is freezed.
    Here the relevant parts of the code:

    #chip 18F45k42, 64
    #option explicit
    #config MCLRE = ON
    #startup InitPPS, 85
    
    '______________
    '   USART
    #define USART_BAUD_RATE 9600
    #define USART_DELAY     5 ms
    #define USART_BLOCKING
    'Set pin USART directions
    Dir portC.7 IN
    Dir portC.6 OUT
    #define x_lim              PortC.1
    #define y_lim              PortC.2
    #define z_lim              PortA.6
    #define Stop               PortC.0
    
    Dir PortC.1 IN
    Dir PortC.2 IN
    Dir PortA.6 IN
    Dir PortC.0 IN
    
    Dim ind               as Byte
    Dim intpt0          As Byte
    Dim intpt1          As Byte
    
    '============= Code ======================
    ind=0
    intpt0=0
    intpt1=0
    
    'Interrupt settings
    SET INTCON0.GIE   ON  'enabling global interrupt
    SET PIE0.IOCIE    ON  'enabling interrupt on Change
    SET IPR0.IOCIP    ON  'set high priority
    'SET IOCxP.IOCxPy  ON;  interrupts su A6, C0, C1, C2 on rising edge
    SET IOCAP.IOCAP6  ON
    SET IOCCP.IOCCP0  ON
    SET IOCCP.IOCCP1  ON
    SET IOCCP.IOCCP2  ON
    SET IOCAF6  OFF
    SET IOCCF0  OFF
    SET IOCCF1  OFF
    SET IOCCF2  OFF
    'INTON
    
    main:
       ind=ind+1
       if ind>100 then
          HSerPrint " ind= "
          HSerPrint ind
          HSerPrintCRLF 1
         ind=0
       end if
      goto main
    
    end
    '____________________________
    
    sub Interrupt:
    
      SET PIE0.IOCIE    OFF
      if IOCAF.IOCAF6=1 or IOCCF.IOCCF1=1 or IOCCF.IOCCF2=1 then
        intpt0=1
      end if
      if IOCCF.IOCCF0=1 then
        intpt1=1
      end if
    
      HSerPrint " intpt0= "
      HSerPrint intpt0
      HSerPrint " intpt1= "
      HSerPrint intpt1
    
      SET PIE0.IOCIE    OFF
      SET IOCAF6  OFF
      SET IOCCF0  OFF
      SET IOCCF1  OFF
      SET IOCCF2  OFF
    End Sub
    
    Sub InitPPS
        '//sets up pins for USART
    
        UNLOCKPPS
            'Module: UART1
            U1RXPPS = 0x0017    'RC7 > RX1
            RC6PPS  = 0x0013     'TX1 > RC6
        LOCKPPS
     End Sub
    

    I do not understand why the interrupt sub it is not called (as I believe, because intp0 and intp1 are never written and the code freezes).
    I also used INTON command without success.
    Thank you for any help.

     

    Last edit: Anobium 2019-02-09
  • Anobium

    Anobium - 2019-02-09

    Try removing the colon from the following line

    sub Interrupt:

     
  • Giuseppe D'Elia

    Giuseppe D'Elia - 2019-02-09

    Hi Anobium,
    thank you for your answer.
    I apologize for my question.
    In fact, at the beginning of the interrupt routine it was a "wait 40 s" instruction.
    During my tests, I forgot that and I never waited 40 s to see if the code was fine. Accordingly, it seemed to me that the code never got the interrupt routine.
    following your suggestion, I wached the first rows of the routine and I understood the mistake.
    Finally, I cannot say why the "wait 40 s" instruction was not included in the code I submitted to the Forum.!!
    I sincerely apologize for that.

     

Log in to post a comment.