Instant Interrupts - Revisited - Page 20


+ Reply to Thread
Page 20 of 20 FirstFirst ... 101617181920
Results 761 to 791 of 791
  1. #761
    Join Date
    Jul 2008
    Location
    TURKIYE-KONYA
    Posts
    51

    Default Re: Instant Interrupts - Revisited

    I'm working on a project using 18LF13K22. I need to use RAB Change Interrupt with DT Ints18. I made changes on DT_INTS-18.bas below but i couldn't succeed. Any suggestion?

    Code:
    #define RABC_INT  INTCON, RABIF   ;-- RAB Port Change
    .........

    Code:
    ifdef RABIF
          INT_Source  INTCON,RABIF, INTCON, RABIE,INTCON2,RABIP
      endif
    Thanks..

  2. #762
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219

    Default Re: Instant Interrupts - Revisited

    I had to do the same thing with the PIC18F14K50.
    Our entries look similar except your label is RABC_INT.

    Code:
    #define RAB_INT   INTCON, RABIF   ;-- RAB Port Change, Added 3/15/14 for PIC18F14K50
    and

    Code:
      ifdef RABIF    ;----{ RAB Port Change Interrupt }-----------[INTCON, RABIF]--- (Added 3/15/14 for PIC18F14K50
          INT_Source  INTCON,RABIF, INTCON,RABIE, INTCON2,RABIP 
      endif
    Could it be you're not enabling it with:
    Code:
    INT_ENABLE  RABC_INT   ; Enable IOC
    Louie

  3. #763
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219

    Default Re: Instant Interrupts - Revisited

    Edit: ooops, forgot the "@".

    Code:
    @ INT_ENABLE  RABC_INT   ; Enable IOC
    Louie

  4. #764
    Join Date
    Jul 2008
    Location
    TURKIYE-KONYA
    Posts
    51

    Default Re: Instant Interrupts - Revisited

    Quote Originally Posted by LinkMTech View Post
    I had to do the same thing with the PIC18F14K50.
    Our entries look similar except your label is RABC_INT.

    Code:
    #define RAB_INT   INTCON, RABIF   ;-- RAB Port Change, Added 3/15/14 for PIC18F14K50
    and

    Code:
      ifdef RABIF    ;----{ RAB Port Change Interrupt }-----------[INTCON, RABIF]--- (Added 3/15/14 for PIC18F14K50
          INT_Source  INTCON,RABIF, INTCON,RABIE, INTCON2,RABIP 
      endif
    Could it be you're not enabling it with:
    Code:
    INT_ENABLE  RABC_INT   ; Enable IOC
    Thanks for your reply. I tried to work it with ISIS. It may cause for it. I'm waiting for chips. I will try it again.

  5. #765
    Join Date
    Jul 2008
    Location
    TURKIYE-KONYA
    Posts
    51

    Default Re: Instant Interrupts - Revisited

    The chips have arrived. I tried RAB change interrupt on a demo board. The situation is the same with isis. This is my test code below.

    Code:
        INCLUDE "DT_INTS-18.bas"     ' Base Interrupt System
        INCLUDE "ReEnterPBP-18.bas"     ' Include if using PBP interrupts
        
        ........
    
        OSCCON  = %00110100
        OSCCON2 = 0
        OSCTUNE = %10000000
        
        TRISA   = %11101111
        TRISB   = %11111111
        TRISC   = %00000000
    
        ANSEL   = 0
        ANSELH  = 0
        
        INTCON2.7   = 0
        WPUA        = %00101111
        WPUB        = %11110000
        IOCA        = %00000111
        IOCB        = %01010000
    
        ASM
    INT_LIST  macro    ; IntSource,      Label,  Type, ResetFlag?
                        INT_Handler   RABC_INT,  _RABC,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
        INT_ENABLE  RABC_INT
        ENDASM
    
        MAIN:
    
       
        ......
    GOTO MAIN
    
    
         RABC : 
        
        COUNTER = COUNTER + 1
        
        
    @ INT_RETURN

  6. #766
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219

    Default Re: Instant Interrupts - Revisited

    I tried your INT code mod and sample code here (added Counter VAR Word) and it compiled okay.
    A couple questions:
    What are you try to do that is not happening?
    And excuse my ignorance, but what is ISIS?
    Louie

  7. #767
    Join Date
    May 2013
    Location
    australia
    Posts
    1,558

    Default Re: Instant Interrupts - Revisited

    but what is ISIS?
    looks like an Egyptian goddess

    https://en.wikipedia.org/wiki/Isis

    but it probably this
    http:/'s/www.picmicros.org.uk/Interfacing/TUTORIAL.htm

  8. #768
    Join Date
    Jul 2008
    Location
    TURKIYE-KONYA
    Posts
    51

    Default Re: Instant Interrupts - Revisited

    Quote Originally Posted by LinkMTech View Post
    I tried your INT code mod and sample code here (added Counter VAR Word) and it compiled okay.
    A couple questions:
    What are you try to do that is not happening?
    And excuse my ignorance, but what is ISIS?
    * There is no problem with compiling. It's okay.

    * There are buttons tied PORTA.0, PORTA.1, PORTA.2 - PORTB.4 and PORTB.6. I want to get interrupt every logic change on this ports. If you look at IOCA and IOCB registers, these ports are enabled for interrupt.

    * ISIS is a simulation program.

  9. #769
    Join Date
    May 2013
    Location
    australia
    Posts
    1,558

    Default Re: Instant Interrupts - Revisited

    DT_INTS does not clear the ioc int flag you need to do that yourself either in your isr or when you ready to rearm the interrupt

  10. #770
    Join Date
    May 2013
    Location
    australia
    Posts
    1,558

    Default Re: Instant Interrupts - Revisited

    I'm wrong there, I was thinking of ioca/b int issues I had some years back . but after having another look it was with a 16f1825 which has an individual ioc flag for every ioc pin , but it won't hurt to rule that out anyway

  11. #771
    Join Date
    Jul 2008
    Location
    TURKIYE-KONYA
    Posts
    51

    Default Re: Instant Interrupts - Revisited

    Hello everyone..

    I read this post today. And added MOVF PORTA, W - MOVF PORTB, W. Now it's working as it should be.

    Code:
    RABC : 
    
    @ MOVF PORTA, W
    @ MOVF PORTB, W
    
        COUNTER = COUNTER + 1   
        
    @ INT_RETURN

  12. #772
    Join Date
    Feb 2010
    Posts
    30

    Default Re: Instant Interrupts - Revisited

    Hello,
    i have a working code which uses
    CMP_INT and TMR1_INT.

    I want when TMR1_INT event triggered ,
    to change the period (or Frequency as entered) and reload the TMR1 with a new value.

    Is this possible to put mutiple instances of e.g.

    @Freq = 416 ; Frequency of Interrupts in Hz 416Hz

    ??

    Thank you.

  13. #773
    Join Date
    May 2013
    Location
    australia
    Posts
    1,558

    Default Re: Instant Interrupts - Revisited

    Is this possible to put mutiple instances of e.g. @Freq = 416
    "Freq " would be a label and cannot be redefined
    you can however
    @Freq1 = 416
    @Freq2 = 410
    @Freq3 = 466

    if you need to change the tmr1 interrupt rate the tmr1 reload value needs to be a var

  14. #774

    Default Re: Instant Interrupts - Revisited

    Dear all,

    apologize for my absent, i had to focus on my PhD based on bioprinting and really didnt have enough time to be here.

    I know that i have left my big project with LORA modules apart, because really i cannot have enough knowledge to make it work. But i will try my best to find time for that project and improve my knowledge to make small steps until to understand how i can make a simple LED to light from one end to the other.

    Apart from that i have tried to play with DT's interrupts. It is the first time i tried the interrupts and it is the first time i try to understand how they work.

    On the following code, which PIC18F46K22 is used, i have tried to light few leds by using external interrupts on RB0 - RB1 - RB2 ( INT0 - INT1 - INT2).

    The program works fine when only INT0 and TMR0 is used. The time i add a second INT1 then the 'main' program doesn't work the TMR0 as well.

    What is the mistake i have done?

    Could you please advise?

    Code:
                     '*****************************************
                     '*  Name    : PIC18F46K22v3.BAS          *
                     '*  Author  : Leonardo Bilalis           *
                     '*  Notice  : Copyright (c) 2018 by L.B. *
                     '*          : All Rights Reserved        *
                     '*  Date    : 31/DEC/2018                *
                     '*  Version : 1.0                        *
                     '*  Notes   : Development Board          *
                     '*****************************************
    
    #IF __PROCESSOR__ = "18F46k22"
    
     #CONFIG   ;  The PBP configuration for the PIC18F46K22 is:
     ;   CONFIG FOSC     = RCIO6	    ; External RC oscillator
         CONFIG FOSC    = HSHP	        ; HS oscillator (high power > 16 MHz)
     ;    CONFIG FOSC = XT	    ;XT oscillator
     ;    CONFIG FOSC = LP	    ;LP oscillator
    
    ;*---------------------------------4x PLL ENABLE--------------------------------------*|
    ;*  4X PLL Enable                                                                     *|
    ;    CONFIG PLLCFG  = OFF	        ;Oscillator used directly                         *|
         CONFIG PLLCFG    = ON	        ;Oscillator multiplied by 4                       *|
    ;*------------------------------------------------------------------------------------*|
    ;
    ;  Primary clock enable bit
    ;    CONFIG PRICLKEN = OFF	        ;Primary clock can be disabled by software
        CONFIG PRICLKEN  = ON	        ;Primary clock enabled
    ;
    ;  Fail-Safe Clock Monitor Enable bit
         CONFIG FCMEN    = OFF	        ;Fail-Safe Clock Monitor disabled
    ;    CONFIG FCMEN    = ON	        ;Fail-Safe Clock Monitor enabled
    ;
    ;  Internal/External Oscillator Switchover bit
        CONFIG IESO      = OFF	        ;Oscillator Switchover mode disabled
    ;    CONFIG IESO     = ON	        ;Oscillator Switchover mode enabled
        
        CONFIG  BOREN    = SBORDIS      ; Brown-out Reset enabled in hardware only (SBOREN is disabled)
        
    ;*---------------------------------------------------------------------------------------------------------;|
        CONFIG  WDTEN    = ON           ; WDT is always enabled. SWDTEN bit has no effect                      ;|
        CONFIG  WDTPS    = 32768        ; 1:32768 ---> HERE enable the watchdog timer with a 1:32768 postscale ;|
    ;*---------------------------------------------------------------------------------------------------------;|
        
        CONFIG  PWRTEN   = ON
        CONFIG  HFOFST   = ON           ; HFINTOSC output and ready status are not delayed by the oscillator stable status
        CONFIG  MCLRE    = EXTMCLR      ; MCLR pin enabled, RE3 input pin disabled
        ;CONFIG MCLRE    = INTMCLR	    ; RE3 input pin enabled; MCLR disabled
    
        CONFIG  LVP      = OFF          ; Single-Supply ICSP disabled
        CONFIG  XINST    = OFF          ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
        CONFIG  DEBUG    = OFF          ; Disabled
    
    ;*----------------------------------------------------------------------------------|
    ;*---------------Available configuration settings for PIC18F46K22-------------------|
    ;*----------------------------------------------------------------------------------|
    ;
    ;  Oscillator Selection bits
    ;    CONFIG FOSC = RC	    ;111X External RC oscillator, CLKOUT function on RA6
    ;    CONFIG FOSC = ECLPIO6  ;EC oscillator (low power, <500 kHz)
    ;    CONFIG FOSC = ECLP	    ;EC oscillator, CLKOUT function on OSC2 (low power, <500 kHz)
    ;    CONFIG FOSC = ECMPIO6  ;EC oscillator (medium power, 500 kHz-16 MHz)
    ;    CONFIG FOSC = ECMP	    ;EC oscillator, CLKOUT function on OSC2 (medium power, 500 kHz-16 MHz)
    ;    CONFIG FOSC = INTIO7   ;Internal oscillator block, CLKOUT function on OSC2
    ;    CONFIG FOSC = INTIO67  ;Internal oscillator block
    ;    CONFIG FOSC = RCIO6    ;External RC oscillator
    ;    CONFIG FOSC = RC	    ;External RC oscillator, CLKOUT function on OSC2
    ;    CONFIG FOSC = ECHPIO6  ;EC oscillator (high power, >16 MHz)
    ;    CONFIG FOSC = ECHP	    ;EC oscillator, CLKOUT function on OSC2 (high power, >16 MHz)
    ;    CONFIG FOSC = HSMP	    ;HS oscillator (medium power 4-16 MHz)
    ;    CONFIG FOSC = HSHP	    ;HS oscillator (high power > 16 MHz)
    ;    CONFIG FOSC = XT	    ;XT oscillator
    ;    CONFIG FOSC = LP	    ;LP oscillator
        
    ;*--------------------------------------------------------------------------------------------------------|
    ;*                                  | -------------------------- |                                        |
    ;*  -----------------------------   |  [PROTECTED OPTION FUSES]  |  ------------------------------------  |
    ;*                                  | -------------------------- |                                        |
    ;*--------------------------------------------------------------------------------------------------------|
    
        CONFIG  CP0 = OFF             ; Block 0 (000800-003FFFh) not code-protected
        CONFIG  CP1 = OFF             ; Block 1 (004000-007FFFh) not code-protected
        CONFIG  CP2 = OFF             ; Block 2 (008000-00BFFFh) not code-protected
        CONFIG  CP3 = OFF             ; Block 3 (00C000-00FFFFh) not code-protected
        CONFIG  CPB = OFF             ; Boot block (000000-0007FFh) not code-protected
        CONFIG  CPD = OFF             ; Data EEPROM not code-protected
        CONFIG  WRT0 = OFF            ; Block 0 (000800-003FFFh) not write-protected
        CONFIG  WRT1 = OFF            ; Block 1 (004000-007FFFh) not write-protected
        CONFIG  WRT2 = OFF            ; Block 2 (008000-00BFFFh) not write-protected
        CONFIG  WRT3 = OFF            ; Block 3 (00C000-00FFFFh) not write-protected
        CONFIG  WRTC = OFF            ; Configuration registers (300000-3000FFh) not write-protected
        CONFIG  WRTB = OFF            ; Boot Block (000000-0007FFh) not write-protected
        CONFIG  WRTD = OFF            ; Data EEPROM not write-protected
        CONFIG  EBTR0 = OFF           ; Block 0 (000800-003FFFh) not protected from table reads executed in other blocks
        CONFIG  EBTR1 = OFF           ; Block 1 (004000-007FFFh) not protected from table reads executed in other blocks
        CONFIG  EBTR2 = OFF           ; Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks
        CONFIG  EBTR3 = OFF           ; Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks
        CONFIG  EBTRB = OFF           ; Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
    
      #ENDCONFIG
    
    #ELSE
        #MSG "Wrong Processor selected!"
    #ENDIF
      
    ;*-----------------------------------------------------------------------------|
    ;*-----------------------------------------------------------------------------|
    
    define  OSC 64
    
            DEFINE USE_LOWPRIORITY 1
            INCLUDE "modedefs.bas"
            INCLUDE "ALLDIGITAL.pbp"
            INCLUDE "DT_INTS-18.bas"        ; Base Interrupt System
            INCLUDE "ReEnterPBP-18LP.bas" ; Include if using Low Pr. PBP INTS
            INCLUDE "ReEnterPBP-18.bas"     ; Include if using PBP interrupts
            
    OSCCON    = %01110000   ; 64Mhz
    OSCTUNE.6 = 1           ; Enable 4x PLL
    
    while ! osccon2.7 = 1 :WEND ; to make sure the pll has stabilised before you run any other code
    
    '------------------------------------------------------------------------------|
    '                           Enable Interrupts                                  |
    '------------------------------------------------------------------------------|
    
    'INTCON.4 = 1    ' Enable interrupt INT0
    'INTCON.5 = 1    ' Enable interrupt INT1
    'INTCON.6 = 1    ' Enable interrupt INT2
    
    INTCON2.6 = 0   ' INTEDG0 = 0  for the INT0 
                    ' External Interrupt 0 Edge Select bit
                    ' 1 = Interrupt on rising edge
                    ' 0 = Interrupt on falling edge
    '------------------------------------------------------------------------------|
    '                            INITIALIZE RAM                                    |
    '------------------------------------------------------------------------------|
    initialize:
    	CLEAR                   
    	
    '-------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    TRISA = %00000000   'use TRISA to specify which pin is (1 = input) and which (0 = output)  (ALL pins are output)
    TRISB = %00000111   'use TRISB to specify which pin is (1 = input) and which (0 = output)  (ALL pins are output)
    TRISC = %00000000   'use TRISC to specify which pin is (1 = input) and which (0 = output)  (ALL pins are output)
    TRISD = %00000000   'use TRISC to specify which pin is (1 = input) and which (0 = output)  (ALL pins are output)
    TRISE = %00000000   'use TRISC to specify which pin is (1 = input) and which (0 = output)  (ALL pins are output)
    '------------------------------------------------------------------------|
    '--------------------------- TRIS A B C D E -----------------------------|
    '------------------------------------------------------------------------|
    ' PORTA.7  PORTA.6  PORTA.5  PORTA.4  PORTA.3  PORTA.2  PORTA.1  PORTA.0 |
    '  bit7     bit6     bit5     bit4     bit3     bit2     bit1     bit0   |
    '   0        0        0        0        0        0        0        0     |
    '------------------------------------------------------------------------|
    '------------------------------------------------------------------------|
    ' PORTB.7  PORTB.6  PORTB.5  PORTB.4  PORTB.3  PORTB.2  PORTB.1  PORTB.0 |
    '  bit7     bit6     bit5     bit4     bit3     bit2     bit1     bit0   |
    '   0        0        0        0        0        1        1        1     |
    '------------------------------------------------------------------------|
    '------------------------------------------------------------------------|
    ' PORTC.7  PORTC.6  PORTC.5  PORTC.4  PORTC.3  PORTC.2  PORTC.1  PORTC.0 |
    '  bit7     bit6     bit5     bit4     bit3     bit2     bit1     bit0   |
    '   0        0        0        0        0        0        0        0     |
    '------------------------------------------------------------------------|
    '------------------------------------------------------------------------|
    ' PORTD.7  PORTD.6  PORTD.5  PORTD.4  PORTD.3  PORTD.2  PORTD.1  PORTD.0 |
    '  bit7     bit6     bit5     bit4     bit3     bit2     bit1     bit0   |
    '   0        0        0        0        0        0        0        0     |
    '------------------------------------------------------------------------|
    '------------------------------------------------------------------------|
    ' PORTE.-  PORTE.-  PORTE.-  PORTE.-  PORTE.3  PORTE.2  PORTE.1  PORTE.0 |
    '  bit7     bit6     bit5     bit4     bit3     bit2     bit1     bit0   |
    '   -        -        -        -        0        0        0        0     |
    '------------------------------------------------------------------------|
    
    '------------------------------------------------------------------------|
    '----------------------- At start all PORTS LOW -------------------------|
    '------------------------------------------------------------------------|
    PORTA = 0            'make low all ports at A range                      |
    PORTB = 0            'make low all ports at B range                      |
    PORTC = 0            'make low all ports at C range                      |
    PORTD = 0            'make low all ports at D range                      |
    PORTE = 0            'make low all ports at E range                      |
    '------------------------------------------------------------------------|
    
    '------------------------------------------------------------------------|
    '-------------------------- COMPARATORS OFF -----------------------------|
    '------------------------------------------------------------------------|
    CM1CON0.7 = 0 'Disable comparator1                                       |
    CM2CON0.7 = 0 'Disable comparator2                                       |
    '------------------------------------------------------------------------|
    
    
    ' -----------------------------------------------------------------------------|  
    '                        [ CPU SPEED TEST with LEDs ]                          |
    '------------------------------------------------------------------------------|
                                 ' FIRST TIME BOOTUP '
    goSUB PWRUP
    '------------------------------------------------------------------------------|
    '*-----------------------------------------------------------------------------|
    '*                                BOOTUP LEDs                                  |
    '*-----------------------------------------------------------------------------|
    
    PWRLED  var PORTB.4 ' power led RED lights up when everything is ok
    REDLED  Var PORTA.1 ' together with Power Green Led. Normally used for failure notifcation
    
    UVLED1  var PORTB.5
    UVLED2  Var PORTA.0
    
    '------------------------------------------------------------------------------|
    '                              //  RGB LED  //                                 |
    '------------------------------------------------------------------------------|
    
    BLUE    var PORTE.0 ' indicates that PIC is working on port C.4
    RED     var PORTE.1
    GREEN   VAR PORTE.2
    
    UVRight var PORTC.2
    BUZZLED var PORTC.0
    
    '------------------------------------------------------------------------------|
    '                           //INTERRUPT BUTTONS //                             |
    '------------------------------------------------------------------------------|
    
    BUTT1   var PORTB.0
    BUTT2   VAR PORTB.1
    BUTT3   var PORTB.2
    
    '------------------------------------------------------------------------------|
    '                           Setting the Power Led                              |
    '------------------------------------------------------------------------------|
    
    high pwrled
    high redled ' this is an option here just to tes the code
    
    '------------------------------------------------------------------------------|
    '                            //  INTERRUPT  ///                                |
    '------------------------------------------------------------------------------|
    ;------------------------[High Priority Interrupts]----------------------------|
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    INT0_INT,  _ToggleLED1,  PBP,  yes
            INT_Handler   TMR0_INT,  _ToggleLED,   PBP,  yes
        endm
        INT_CREATE             ; Creates the interrupt processor
    
    ;------------------------------------------------------------------------------|
    ;------------------------[Low Priority Interrupts]-----------------------------|
    ;------------------------------------------------------------------------------|
    
    INT_LIST_L macro ; IntSource, Label, Type, ResetFlag?
            INT_Handler INT2_INT, _ToggleLED2, PBP, no
        endm
        INT_CREATE_L ; Creates the Low Priority interrupt processor 
    
    ENDASM
    T0CON = %10010110            ; T0 = 16-bit, Prescaler 8
    @   INT_ENABLE   INT0_INT     ; enable external (INT) interrupts
    @   INT_ENABLE  INT2_INT     ; enable external (INT) interrupts
    @   INT_ENABLE  TMR0_INT     ; enable Timer 0 interrupts 
    
    '*-----------------------------------------------------------------------------|
    '*                           //    MAIN    \\                                  |
    '*-----------------------------------------------------------------------------|
    
    Main:
        
        if butt2 = 0 then
         high red
         pause 500
         low red
         high green
         pause 500
         low green
         high blue
         pause 500
         low blue
        else 
         low REd : low Green : low Blue
        endif
        
    goto main
    
    end
    
    
    
    '-------------------------------------------------------------------------------|
    '                                POWER UP LEDs                                  |
    '-------------------------------------------------------------------------------|
    
    PWRUP:
    high RED
    high BLUE
    high GREEN
    pause 1000
    low RED
    LOW BLUE
    LOW GREEN
    Pause 100
    
    high blue
    Pause 10
    low blue 
    pause 100 
    high blue
    Pause 10
    low blue 
    pause 100
    high blue
    Pause 10
    low blue 
    pause 100
    
    high red
    Pause 10
    low red 
    pause 100
    high red
    Pause 10
    low red 
    pause 100
    high red
    Pause 10
    low red 
    pause 100
    
    high green
    Pause 10
    low green 
    pause 100
    high green
    Pause 10
    low green 
    pause 100
    high green
    Pause 10
    low green 
    pause 100
    
    return
    
    '---[INT - interrupt handler]---------------------------------------------------
    
    ToggleLED:
         TOGGLE uVLed1 : toggle uvled2
    @ INT_RETURN
    
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
         if butt1 = 0 then
         toggle uvright
         else 
         low uvright 
         endif
         while portb.0=0:pause 10:wend
    @ INT_RETURN
    
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED2:
         if butt3 = 0 then
         sound buzzled,[100,10,50,10]
         else 
         low buzzled
         endif
         while portb.2=0:pause 10:wend
    @ INT_RETURN
    Last edited by astanapane; - 8th January 2019 at 21:55.

  15. #775
    Join Date
    May 2013
    Location
    australia
    Posts
    1,558

    Default Re: Instant Interrupts - Revisited

    have a look at this for a realistic way to read some switches while blinking some leds

    http://dt.picbasic.co.uk/INT14/BruceExample


    how do you allow for button bounce ?
    ---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
    if butt1 = 0 then
    toggle uvright
    else
    low uvright
    endif
    while portb.0=0ause 10:wend /// never a good look in an isr
    @ INT_RETURN
    This is more entertaining than Free to Air TV

  16. #776
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,786

    Default Re: Instant Interrupts - Revisited

    My problem always was how to handle debounce in relation to interrupts. Sure Pause is not a good idea for an ISR.

    This needs maybe an RTOS or, at least, a framework to base all operations once and for all.

    Ioannis

  17. #777
    Join Date
    May 2013
    Location
    australia
    Posts
    1,558

    Default Re: Instant Interrupts - Revisited

    My problem always was how to handle debounce in relation to interrupts. Sure Pause is not a good idea for an ISR.


    This needs maybe an RTOS or, at least, a framework to base all operations once and for all.
    i agree

    in most of my "real" projects i run a timer to give 4mS timer ticks to a word sized counter in mS
    by using unsigned subtractions its dead simple to measure any interval between 4mS and 65 seconds
    very useful for debounce\ long press\ valid press detetion for keys , flashing leds , long short buzzer sounds
    not to mention scheduling timed polling or other processes.
    i try to show these ideas in my postings but the concept always falls on deaf ears. the spaghetti coders are fixed in their ways
    i don't think they even want to learn . i can't even get the concept of lat regs across the barrier
    This is more entertaining than Free to Air TV

  18. #778
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,786

    Default Re: Instant Interrupts - Revisited

    I think is the Basic syndrome to create spaghetti programs mixed with a series of goto everywhere!

    Even text books do not promote the Subroutines in basic language teaching. Maybe if variables could be passed to the sub, things would be more convenient.

    I am curious, why you select 4ms and not 5 or 1 that makes counting seconds more easy?

    A long time now I wanted to propose the creation of a general purpose framework as teamwork, to house such processes, like key read and debounce, lcd messages, serial coms, etc.

    Ioannis
    Last edited by Ioannis; - 9th January 2019 at 09:21.

  19. #779
    Join Date
    May 2013
    Location
    australia
    Posts
    1,558

    Default Re: Instant Interrupts - Revisited

    I am curious, why you select 4ms and not 5 or 1 that makes counting seconds more easy?
    i tend to use 64mhz clocks its not exactly 4mS its 3906uS 4 is close enough its not a chronometer and not too big a burden on the pic chip processing wise and
    powers of 2 are easy to find short cuts for
    This is more entertaining than Free to Air TV

  20. #780

    Default Re: Instant Interrupts - Revisited

    Hi Richard,

    thanks for taking time to answer to my question.

    I have read what you have suggested, as well as the http://dt.picbasic.co.uk/CODEX/IocInterrupts.

    Reading the above i realized that i need to use IOC. Then i had a look at the following as well, in order to understand what the difference is.

    1. https://electronics.stackexchange.co...terrupt-on-pic

    Which explains the "The three biggest differences between interrupt-on change and external interrupt pins"

    "1.The external interrupt pins allow software to specify whether the interrupt should be triggered by a rising edge or by a falling edge; if e.g. a pin is low and one is interested in falling edges only, an interrupt will not be triggered until the pin rises and subsquently falls. Using interrupt-on-change, one would have to wake up on both events.

    2. The external interrupt pins have individual latching status bits. Even if an input pulse comes and goes before software has a chance to respond to it, software can still find out that it happened and react suitably.

    3. Reading an I/O port which has a pin-change interrupt enabled at precisely the time the input changes may result in the pin-change interrupt not triggering. By contrast, reading the I/O port connected an external interrupt pin has no effect on the interrrupt.

    The PIC's external interrupts are more versatile and reliable than the general-purpose pin-change interrupts. I'd suggest using the former when practical."


    i would like to understand if i could stay with external interrupts, or it is a must to use IOC.

    As it is the first time i use any interrupts, i thought that i could use the INT0 - INT1 -INT2, so i already made a simple pcb at home.

    Name:  20190109_091835.jpg
Views: 43
Size:  240.0 KB

    Could you please let me know if i could stay with my current design and use the external interrupt? In case i have to change to IOC then i will also change the PCB....

  21. #781
    Join Date
    May 2013
    Location
    australia
    Posts
    1,558

    Default Re: Instant Interrupts - Revisited

    I think is the Basic syndrome to create spaghetti programs mixed with a series of goto everywhere!
    art is correct in his assertion that pbp and c are syntactically similar . if you divide your tasks up into subs place them all into a polling loop
    its nearly identical functionally and visually .[ passing of vars being the only difference , it just something you need to manage]
    but better still the discipline involved in structuring your code that way always leads to better results ,esp as the complexity increases
    a foray into c can improve your pbp results
    you would be quite suprised how much more efficient pbp can be speed/size wise over c for some tasks its only let dow by poor memory management
    lack of variety of vars and no pointers

    did you see my spi slave/master posts last week , i think i posted the c version too . its almost a line by line copy
    This is more entertaining than Free to Air TV

  22. #782
    Join Date
    May 2013
    Location
    australia
    Posts
    1,558

    Default Re: Instant Interrupts - Revisited

    For that chip ioc only functions on portb4:7 . so ioc can't work for your pcb as it is

    not that interrupts are even necessary or even a good way to read keys . if you structure your pgm properly it possible to poll the keys at regular intervals and
    get a better result with the ability to detect long/short presses it really can be a low as 10 or 20 times a second for excellent result. with a cpu that does 16 million
    instructions per second is not a big ask. if you want the device to be able to "sleep" one of intx interrupts could be employed to wake the device \
    i see no reason to abandon the board at this stage

  23. #783
    Join Date
    May 2013
    Location
    australia
    Posts
    1,558

    Default Re: Instant Interrupts - Revisited

    leo
    check out this thread to get an idea about polling keys , ignore the capsense stuff just look at the polling of the keys and noting how the state and hold time of keys are calculated and used

    http://www.picbasic.co.uk/forum/show...light=capsense

  24. #784

    Default Re: Instant Interrupts - Revisited

    Richard, i do so and have a look at the thread,

    Before that, i can tell that i'm more confused now.

    My goal is to use 3 buttons, as an interrupt, and in my case the INT0 - INT1 - INT2, to light 3 different leds.

    Can i do that with the help of DT's interrupt?

    My question is, can i use more than one external interrupt in the same program in addition to TMR0?

    As you see on the code above, i tried to use the INT0 and INT1 in addition to TMR0.

    When i run the program on the board, the main program doesnt run and the TRM0 doesnt run as well. But the INT0 and INT1 reacts as it should.....

    Now as it is right now, i need first to understand why the main program and the TMR0 doesnt run....

    Think that im not familiar with coding and not professional. So i need to understand step by step why the INT0 works in addition with TMR0 and main program when the INT1 is not included in the program.

    Then i add the INT1 and i have the effect described.

    thanks for helping.

  25. #785
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,786

    Default Re: Instant Interrupts - Revisited

    Richard was clear. IOC are available only for PortB<4:7> for this chip. So you have to connect your buttons on these lines for IOC.

    Look at DS, page 132.

    But on post #783 Richard directed you to the polling technique, also good for your board and with no need to re-wire the buttons.

    Ioannis

  26. #786
    Join Date
    May 2013
    Location
    australia
    Posts
    1,558

    Default Re: Instant Interrupts - Revisited

    My question is, can i use more than one external interrupt in the same program in addition to TMR0?
    you can , my point is that interrupts are not a particularly good method for reading keys . the way you tried does not consider keybounce and cannot
    discriminate between long a press ,a keybounce ,a noise spike ,a fleeting touch or a real press ;
    a key may bounce hundreds of times for 2 or 3 mS when pressed in that time the isr may fire several times at least , a human interface never needs that sort of response time

    When i run the program on the board, the main program doesnt run and the TRM0 doesnt run as well. But the INT0 and INT1 reacts as it should.....

    Now as it is right now, i need first to understand why the main program and the TMR0 doesnt run...
    .

    when an high priority isr is running the chip can do nothing else at all , thats why delays and while loops in isr's are toxic
    when an low priority isr is running the chip can do nothing else but that or service a high priority isr if one occurs.
    the concept is flawed as it is ,a different strategy is necessary
    This is more entertaining than Free to Air TV

  27. #787
    Join Date
    May 2013
    Location
    australia
    Posts
    1,558

    Default Re: Instant Interrupts - Revisited

    INTCON2.6 = 0 ' INTEDG0 = 0 for the INT0
    why is this button different to the other one

    bit hard going through the visual white noise in your code

  28. #788

    Default Re: Instant Interrupts - Revisited

    Quote Originally Posted by richard View Post
    why is this button different to the other one

    bit hard going through the visual white noise in your code
    I just wanted to see the difference on rising edge and falling edge.

    I think i can configure each button the way i want to be functioned.

    Really i made this pcb as it is, in order to simply understand the interrupts.

    I started with only one INT0 by using a button. I understand the situation that the button is not the way i could test this, because of the reasons Richard mentioned.

    Richard also mentioned "when an high priority isr is running the chip can do nothing else at all , thats why delays and while loops in isr's are toxic when an low priority isr is running the chip can do nothing else but that or service a high priority isr if one occurs.the concept is flawed as it is ,a different strategy is necessary"

    So from that statement, when a high priority interrupt is set, or occurs...then the main program doesnt run? If that is what you meant, then what the reason of using interrupt?

  29. #789

    Default Re: Instant Interrupts - Revisited

    with the following configuration i managed to get what i wanted.

    just changed INT 2 with INT1.

    For the main i used the BUTT3 instead of BUTT2.

    Code:
                     '*****************************************
                     '*  Name    : PIC18F46K22v3.BAS          *
                     '*  Author  : Leonardo Bilalis           *
                     '*  Notice  : Copyright (c) 2018 by L.B. *
                     '*          : All Rights Reserved        *
                     '*  Date    : 31/DEC/2018                *
                     '*  Version : 1.0                        *
                     '*  Notes   : Development Board          *
                     '*****************************************
    
    #IF __PROCESSOR__ = "18F46k22"
    
     #CONFIG   ;  The PBP configuration for the PIC18F46K22 is:
     ;   CONFIG FOSC     = RCIO6	    ; External RC oscillator
         CONFIG FOSC    = HSHP	        ; HS oscillator (high power &gt; 16 MHz)
     ;    CONFIG FOSC = XT	    ;XT oscillator
     ;    CONFIG FOSC = LP	    ;LP oscillator
    
    ;*---------------------------------4x PLL ENABLE--------------------------------------*|
    ;*  4X PLL Enable                                                                     *|
    ;    CONFIG PLLCFG  = OFF	        ;Oscillator used directly                         *|
         CONFIG PLLCFG    = ON	        ;Oscillator multiplied by 4                       *|
    ;*------------------------------------------------------------------------------------*|
    ;
    ;  Primary clock enable bit
    ;    CONFIG PRICLKEN = OFF	        ;Primary clock can be disabled by software
        CONFIG PRICLKEN  = ON	        ;Primary clock enabled
    ;
    ;  Fail-Safe Clock Monitor Enable bit
         CONFIG FCMEN    = OFF	        ;Fail-Safe Clock Monitor disabled
    ;    CONFIG FCMEN    = ON	        ;Fail-Safe Clock Monitor enabled
    ;
    ;  Internal/External Oscillator Switchover bit
        CONFIG IESO      = OFF	        ;Oscillator Switchover mode disabled
    ;    CONFIG IESO     = ON	        ;Oscillator Switchover mode enabled
        
        CONFIG  BOREN    = SBORDIS      ; Brown-out Reset enabled in hardware only (SBOREN is disabled)
        
    ;*---------------------------------------------------------------------------------------------------------;|
        CONFIG  WDTEN    = ON           ; WDT is always enabled. SWDTEN bit has no effect                      ;|
        CONFIG  WDTPS    = 32768        ; 1:32768 ---> HERE enable the watchdog timer with a 1:32768 postscale ;|
    ;*---------------------------------------------------------------------------------------------------------;|
        
        CONFIG  PWRTEN   = ON
        CONFIG  HFOFST   = ON           ; HFINTOSC output and ready status are not delayed by the oscillator stable status
        CONFIG  MCLRE    = EXTMCLR      ; MCLR pin enabled, RE3 input pin disabled
        ;CONFIG MCLRE    = INTMCLR	    ; RE3 input pin enabled; MCLR disabled
    
        CONFIG  LVP      = OFF          ; Single-Supply ICSP disabled
        CONFIG  XINST    = OFF          ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
        CONFIG  DEBUG    = OFF          ; Disabled
    
    ;*----------------------------------------------------------------------------------|
    ;*---------------Available configuration settings for PIC18F46K22-------------------|
    ;*----------------------------------------------------------------------------------|
    ;
    ;  Oscillator Selection bits
    ;    CONFIG FOSC = RC	    ;111X External RC oscillator, CLKOUT function on RA6
    ;    CONFIG FOSC = ECLPIO6  ;EC oscillator (low power, &lt;500 kHz)
    ;    CONFIG FOSC = ECLP	    ;EC oscillator, CLKOUT function on OSC2 (low power, &lt;500 kHz)
    ;    CONFIG FOSC = ECMPIO6  ;EC oscillator (medium power, 500 kHz-16 MHz)
    ;    CONFIG FOSC = ECMP	    ;EC oscillator, CLKOUT function on OSC2 (medium power, 500 kHz-16 MHz)
    ;    CONFIG FOSC = INTIO7   ;Internal oscillator block, CLKOUT function on OSC2
    ;    CONFIG FOSC = INTIO67  ;Internal oscillator block
    ;    CONFIG FOSC = RCIO6    ;External RC oscillator
    ;    CONFIG FOSC = RC	    ;External RC oscillator, CLKOUT function on OSC2
    ;    CONFIG FOSC = ECHPIO6  ;EC oscillator (high power, &gt;16 MHz)
    ;    CONFIG FOSC = ECHP	    ;EC oscillator, CLKOUT function on OSC2 (high power, &gt;16 MHz)
    ;    CONFIG FOSC = HSMP	    ;HS oscillator (medium power 4-16 MHz)
    ;    CONFIG FOSC = HSHP	    ;HS oscillator (high power &gt; 16 MHz)
    ;    CONFIG FOSC = XT	    ;XT oscillator
    ;    CONFIG FOSC = LP	    ;LP oscillator
        
    ;*--------------------------------------------------------------------------------------------------------|
    ;*                                  | -------------------------- |                                        |
    ;*  -----------------------------   |  [PROTECTED OPTION FUSES]  |  ------------------------------------  |
    ;*                                  | -------------------------- |                                        |
    ;*--------------------------------------------------------------------------------------------------------|
    
        CONFIG  CP0 = OFF             ; Block 0 (000800-003FFFh) not code-protected
        CONFIG  CP1 = OFF             ; Block 1 (004000-007FFFh) not code-protected
        CONFIG  CP2 = OFF             ; Block 2 (008000-00BFFFh) not code-protected
        CONFIG  CP3 = OFF             ; Block 3 (00C000-00FFFFh) not code-protected
        CONFIG  CPB = OFF             ; Boot block (000000-0007FFh) not code-protected
        CONFIG  CPD = OFF             ; Data EEPROM not code-protected
        CONFIG  WRT0 = OFF            ; Block 0 (000800-003FFFh) not write-protected
        CONFIG  WRT1 = OFF            ; Block 1 (004000-007FFFh) not write-protected
        CONFIG  WRT2 = OFF            ; Block 2 (008000-00BFFFh) not write-protected
        CONFIG  WRT3 = OFF            ; Block 3 (00C000-00FFFFh) not write-protected
        CONFIG  WRTC = OFF            ; Configuration registers (300000-3000FFh) not write-protected
        CONFIG  WRTB = OFF            ; Boot Block (000000-0007FFh) not write-protected
        CONFIG  WRTD = OFF            ; Data EEPROM not write-protected
        CONFIG  EBTR0 = OFF           ; Block 0 (000800-003FFFh) not protected from table reads executed in other blocks
        CONFIG  EBTR1 = OFF           ; Block 1 (004000-007FFFh) not protected from table reads executed in other blocks
        CONFIG  EBTR2 = OFF           ; Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks
        CONFIG  EBTR3 = OFF           ; Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks
        CONFIG  EBTRB = OFF           ; Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
    
      #ENDCONFIG
    
    #ELSE
        #MSG "Wrong Processor selected!"
    #ENDIF
      
    ;*-----------------------------------------------------------------------------|
    ;*-----------------------------------------------------------------------------|
            define  OSC 64
            
            'DEFINE NO_CLRWDT 1   ' PBP doesn't clear WDT automatically
            DEFINE USE_LOWPRIORITY 1
            INCLUDE "modedefs.bas"
            INCLUDE "ALLDIGITAL.pbp"
            INCLUDE "DT_INTS-18.bas"        ; Base Interrupt System
            INCLUDE "ReEnterPBP-18LP.bas" ; Include if using Low Pr. PBP INTS
            INCLUDE "ReEnterPBP-18.bas"     ; Include if using PBP interrupts
            
    OSCCON    = %01110000   ; 64Mhz
    OSCTUNE.6 = 1           ; Enable 4x PLL
    
    while ! osccon2.7 = 1 :WEND ; to make sure the pll has stabilised before you run any other code
    
    '------------------------------------------------------------------------------|
    '                           Enable Interrupts                                  |
    '------------------------------------------------------------------------------|
    
    INTCON.4 = 1    ' Enable interrupt INT0
    INTCON.5 = 1    ' Enable interrupt INT1
    INTCON.6 = 1    ' Enable interrupt INT2
    
    INTCON2.6 = 0   ' INTEDG0 = 0  for the INT0 
                    ' External Interrupt 0 Edge Select bit
                    ' 1 = Interrupt on rising edge
                    ' 0 = Interrupt on falling edge
    
    INTCON2.5 = 0   ' INTEDG1 = 0  for the INT1 
                    ' External Interrupt 0 Edge Select bit
                    ' 1 = Interrupt on rising edge
                    ' 0 = Interrupt on falling edge
    
    INTCON2.4 = 1   ' INTEDG2 = 0  for the INT2 
                    ' External Interrupt 0 Edge Select bit
                    ' 1 = Interrupt on rising edge
                    ' 0 = Interrupt on falling edge
    '------------------------------------------------------------------------------|
    '                            INITIALIZE RAM                                    |
    '------------------------------------------------------------------------------|
    initialize:
    	CLEAR                   
    	
    '-------------------------------------------------------------------------------------------------------------------------------------------------------------
    
    TRISA = %00000000   'use TRISA to specify which pin is (1 = input) and which (0 = output)  (ALL pins are output)
    TRISB = %00000111   'use TRISB to specify which pin is (1 = input) and which (0 = output)  (ALL pins are output)
    TRISC = %00000000   'use TRISC to specify which pin is (1 = input) and which (0 = output)  (ALL pins are output)
    TRISD = %00000000   'use TRISC to specify which pin is (1 = input) and which (0 = output)  (ALL pins are output)
    TRISE = %00000000   'use TRISC to specify which pin is (1 = input) and which (0 = output)  (ALL pins are output)
    '------------------------------------------------------------------------|
    '--------------------------- TRIS A B C D E -----------------------------|
    '------------------------------------------------------------------------|
    ' PORTA.7  PORTA.6  PORTA.5  PORTA.4  PORTA.3  PORTA.2  PORTA.1  PORTA.0 |
    '  bit7     bit6     bit5     bit4     bit3     bit2     bit1     bit0   |
    '   0        0        0        0        0        0        0        0     |
    '------------------------------------------------------------------------|
    '------------------------------------------------------------------------|
    ' PORTB.7  PORTB.6  PORTB.5  PORTB.4  PORTB.3  PORTB.2  PORTB.1  PORTB.0 |
    '  bit7     bit6     bit5     bit4     bit3     bit2     bit1     bit0   |
    '   0        0        0        0        0        1        1        1     |
    '------------------------------------------------------------------------|
    '------------------------------------------------------------------------|
    ' PORTC.7  PORTC.6  PORTC.5  PORTC.4  PORTC.3  PORTC.2  PORTC.1  PORTC.0 |
    '  bit7     bit6     bit5     bit4     bit3     bit2     bit1     bit0   |
    '   0        0        0        0        0        0        0        0     |
    '------------------------------------------------------------------------|
    '------------------------------------------------------------------------|
    ' PORTD.7  PORTD.6  PORTD.5  PORTD.4  PORTD.3  PORTD.2  PORTD.1  PORTD.0 |
    '  bit7     bit6     bit5     bit4     bit3     bit2     bit1     bit0   |
    '   0        0        0        0        0        0        0        0     |
    '------------------------------------------------------------------------|
    '------------------------------------------------------------------------|
    ' PORTE.-  PORTE.-  PORTE.-  PORTE.-  PORTE.3  PORTE.2  PORTE.1  PORTE.0 |
    '  bit7     bit6     bit5     bit4     bit3     bit2     bit1     bit0   |
    '   -        -        -        -        0        0        0        0     |
    '------------------------------------------------------------------------|
    
    '------------------------------------------------------------------------|
    '----------------------- At start all PORTS LOW -------------------------|
    '------------------------------------------------------------------------|
    PORTA = 0            'make low all ports at A range                      |
    PORTB = 0            'make low all ports at B range                      |
    PORTC = 0            'make low all ports at C range                      |
    PORTD = 0            'make low all ports at D range                      |
    PORTE = 0            'make low all ports at E range                      |
    '------------------------------------------------------------------------|
    
    '------------------------------------------------------------------------|
    '-------------------------- COMPARATORS OFF -----------------------------|
    '------------------------------------------------------------------------|
    CM1CON0.7 = 0 'Disable comparator1                                       |
    CM2CON0.7 = 0 'Disable comparator2                                       |
    '------------------------------------------------------------------------|
    
    '------------------------------------------------------------------------------|
    '*-----------------------------------------------------------------------------|
    '*                                BOOTUP LEDs                                  |
    '*-----------------------------------------------------------------------------|
    
    PWRLED  var PORTB.4 ' power led RED lights up when everything is ok
    REDLED  Var PORTA.1 ' together with Power Green Led. Normally used for failure notifcation
    
    UVLED1  var PORTB.5
    UVLED2  Var PORTA.0
    
    '------------------------------------------------------------------------------|
    '                              //  RGB LED  //                                 |
    '------------------------------------------------------------------------------|
    
    BLUE    var PORTE.0 ' indicates that PIC is working on port C.4
    RED     var PORTE.1
    GREEN   VAR PORTE.2
    
    UVRight var PORTC.2
    BUZZLED var PORTC.0
    
    '------------------------------------------------------------------------------|
    '                           //INTERRUPT BUTTONS //                             |
    '------------------------------------------------------------------------------|
    
    BUTT1   var PORTB.0
    BUTT2   VAR PORTB.1
    BUTT3   var PORTB.2
    
    '------------------------------------------------------------------------------|
    '                           Setting the Power Led                              |
    '------------------------------------------------------------------------------|
    
    ' -----------------------------------------------------------------------------|  
    '                        [ CPU SPEED TEST with LEDs ]                          |
    '------------------------------------------------------------------------------|
                                 ' FIRST TIME BOOTUP '
    goSUB PWRUP
    
    
    high pwrled
    high redled ' this is an option here just to tes the code
    
    '------------------------------------------------------------------------------|
    '                            //  INTERRUPT  ///                                |
    '------------------------------------------------------------------------------|
    ;------------------------[High Priority Interrupts]----------------------------|
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    INT0_INT,  _ToggleLED1,  PBP,  yes
            INT_Handler    TMR0_INT,  _ToggleLED,   PBP,  yes
        endm
        INT_CREATE             ; Creates the interrupt processor
    
    ;------------------------------------------------------------------------------|
    ;------------------------[Low Priority Interrupts]-----------------------------|
    ;------------------------------------------------------------------------------|
    
    INT_LIST_L macro ; IntSource, Label, Type, ResetFlag?
            INT_Handler INT1_INT, _ToggleLED2, PBP, yes
        endm
        INT_CREATE_L ; Creates the Low Priority interrupt processor 
    
    ENDASM
    T0CON = %10010110            ; T0 = 16-bit, Prescaler 8
    @   INT_ENABLE  INT0_INT     ; enable external (INT) interrupts
    @   INT_ENABLE  INT1_INT     ; enable external (INT) interrupts
    @   INT_ENABLE  TMR0_INT     ; enable Timer 0 interrupts 
    
    '*-----------------------------------------------------------------------------|
    '*                           //    MAIN    \\                                  |
    '*-----------------------------------------------------------------------------|
    
    Main:
        
        if butt3 = 0 then
         high red
         pause 500
         low red
         high green
         pause 500
         low green
         high blue
         pause 500
         low blue
        else 
         low REd : low Green : low Blue
        endif
        
    goto main
    
    end
    
    
    
    '-------------------------------------------------------------------------------|
    '                                POWER UP LEDs                                  |
    '-------------------------------------------------------------------------------|
    
    PWRUP:
    high RED
    high BLUE
    high GREEN
    pause 1000
    low RED
    LOW BLUE
    LOW GREEN
    Pause 100
    
    high blue
    Pause 10
    low blue 
    pause 100 
    high blue
    Pause 10
    low blue 
    pause 100
    high blue
    Pause 10
    low blue 
    pause 100
    
    high red
    Pause 10
    low red 
    pause 100
    high red
    Pause 10
    low red 
    pause 100
    high red
    Pause 10
    low red 
    pause 100
    
    high green
    Pause 10
    low green 
    pause 100
    high green
    Pause 10
    low green 
    pause 100
    high green
    Pause 10
    low green 
    pause 100
    
    return
    
    '---[INT - interrupt handler]---------------------------------------------------
    
    ToggleLED:
         TOGGLE uVLed1 : toggle uvled2
    @ INT_RETURN
    
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
         if butt1 = 0 then
         toggle uvright
         else 
         low uvright 
         endif
    @ INT_RETURN
    
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED2:
         if butt2 = 0 then
         sound buzzled,[111,20]
         else 
         low buzzled
         endif
    @ INT_RETURN
    Last edited by astanapane; - 9th January 2019 at 14:38.

  30. #790
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,786

    Default Re: Instant Interrupts - Revisited

    Exactly what the name says! To interrupt the main routine for something urgent that needs to be done that instant and then return to the daily routine.

    Say to update the timer counter exactly every tick (whatever that is, seconds, ms or hours).

    Or to serve an incoming character in the USART, put it in a ring array and then return to the main routine. Sometime then you read the array at your convenience.

    That is why an ISR cannot have PAUSE or WHILE-WEND or even FOR-NEXT loops. It has to serve immediately and return control to main routines.

    From the above you understand that your last ISR that has a sound command is not the best practice because while the sound is playing other interrupts are blocked. If the other was a USART or Timer you would have a lost character or lost second etc.

    Ioannis
    Last edited by Ioannis; - 9th January 2019 at 14:50.

  31. #791

    Default Re: Instant Interrupts - Revisited

    comments on the following corrected. I have made a mistake on the comments on the code above.

    Code:
    INTCON.4 = 1    ' Enable interrupt INT0
    INTCON.5 = 1    ' TMR0IE: TMR0 Overflow Interrupt Enable bit
                    ' 1 = Enables the TMR0 overflow interrupt
                    ' 0 = Disables the TMR0 overflow interrupt 
    INTCON.6 = 1    'PEIE/GIEL: Peripheral Interrupt Enable bit
                    'When IPEN = 0:
                    '1 = Enables all unmasked peripheral interrupts
                    '0 = Disables all peripheral interrupts
                    'When IPEN = 1:
                    '1 = Enables all low priority interrupts
                    '0 = Disables all low priority interrupts

Similar Threads

  1. Clock using Instant Interrupts
    By PICpocket in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th February 2009, 22:43
  2. DT instant interrupts with mister_e keypad
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th November 2008, 21:02
  3. DT's Instant Interrupts trouble
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th November 2008, 21:48
  4. Keypad and DT's Instant Interrupts
    By Homerclese in forum General
    Replies: 11
    Last Post: - 27th April 2007, 06:32
  5. Replies: 1
    Last Post: - 1st November 2006, 04:11

Members who have read this thread : 33

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

Tags for this Thread

Posting Permissions

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