Menu

the external interrupt port

Help
JANIS
2022-11-13
2022-11-14
  • JANIS

    JANIS - 2022-11-13

    Hello!
    I want to use one port as an external interrupt. Attached is a simplified part of the code. in this case I want to use porta.2 as interrupt source. I used the PPS tool, but I probably did not enter the correct syntax.
    The compiler scolds: Error: Invalid interrupt event: EXTINT2
    Please explain where is the my mistake?

     
    • Anobium

      Anobium - 2022-11-13

      Check in PICINFO for the name of the external interrupt name. This will be your issue.

      but, why did you think it was called EXTINT2? :-)

      and, surely as RA2 is the default for that chip? and, therefore PPS remapping is not needed.

       
      • Chris Roper

        Chris Roper - 2022-11-13

        RA2 is the default for that chip? and, therefore PPS remapping is not needed.

        That was my first thought when I looked at the Datasheet but as I am a tad rusty I chose not to comment. I really do need to clean my work bench and get my dev tools out again.
        I have no excuses left and lots of new code to try out.

         
        • Chris Roper

          Chris Roper - 2022-11-13

          I would also be inclined to include a main loop in the code even if it is empty, just good parctice and it seperates the Initialisaton code from the Subroutines.

           
  • mmotte

    mmotte - 2022-11-13

    By looking in the chipfile , that the name should be "ExtInt0" . That is the default interupt pin so you would not need pps.

     
    • Anobium

      Anobium - 2022-11-13

      PICInfo is the right place to look.

      I am trying to get folks to use the tools rather than the raw files. :-)

       
  • JANIS

    JANIS - 2022-11-13

    Thanks!
    I am very sorry for the unnecessary alarm. :)
    My mistake was to write EXTINT0, not EXTINT2.
    That's all right. The problem was with my test board. Now all works super.
    Yes RA.2 is already supposed to be enabled as INT for this chip. then the code is:

    #chip 16f15325,8
    #config osc=int
    
    #define LED PORTa.1
    dir PORTa.1 out
    
    dir porta.2 in
    
      INTF=1 '' bit 1 INTF: INT External Interrupt Flag bit
    '1 = The INT external interrupt occurred
    '0 = The INT external interrupt did not occur
    INTE=1 '' bit 4 INTE: INT External Interrupt Enable bit
    '1 = Enables the INT external interrupt
    '0 = Disables the INT external interrupt
    GIE=1 ''bit 7 GIE: Global Interrupt Enable bit
    ''1 = Enables all active interrupts
    ''0 = Disables all interrupts
    INTEDG=1 ' INTEDG: Interrupt Edge Select bit ;; OPTION_REG: OPTION REGISTER
    ''1 = Interrupt on rising edge of INT pin
    ''0 = Interrupt on falling edge of INT pin
    
    On interrupt ExtInt0  call BLINK
    
    main:
    wait 10 ms
    goto main
    
    sub BLINK
    if INTF then '' External Interrupt Flag bit
    set LED on
    wait 500 ms
    set LED off
    
    INTF=0
    end if
    
    
    end sub
    

    But for another PIN, PPS tool is used, which works great.

    #chip 16f15325,8
    #config osc=int
    #define LED PORTa.1
    dir PORTa.1 out
    dir porta.4 in
        'Generated by PIC PPS Tool for Great Cow Basic
        'PPS Tool version: 0.0.6.2
        'PinManager data: v1.65.2
        'Generated for 16lf15325
        '
        'Template comment at the start of the config file
        '
        #startup InitPPS, 85
        #define PPSToolPart 16lf15325
    
        Sub InitPPS
    
                'Module: EXT_INT
                INTPPS = 0x0004    'RA4 > INT
    
        End Sub
        'Template comment at the end of the config file
    
    
    On interrupt ExtInt0  call BLINK
    
    main:
    wait 100 ms
    goto main
    
    sub BLINK
    set LED on
    wait 3 s
    set LED off
    
    end sub
    

    But the question is, when do need to write extint1, extint2...etc?

     
  • Anobium

    Anobium - 2022-11-13

    No alarm. Just want your program to work.

    INTE , INTF and GIE are all managed for you. Test without these bits to see what happens.

    Well done.

     
  • JANIS

    JANIS - 2022-11-13

    Thanks Anobium.
    Next time I will try INTE, INTF and GIE, everything is already mounted from the test board to the textolite board.
    Please explain when extint1, extint2...3 is used? This means that the PIC controller can use max up to 4 external interrupts?

     
  • Anobium

    Anobium - 2022-11-14

    I may be incorrect. But, there is one external interrupt and this (for this CHIP) it is called ExtInt0 . For other external interrupts use IOC.

    Is this correct? Why? If I misunderstand this then the DAT files are incorrect.

     

Log in to post a comment.