Instant Interrupts - Revisited


Closed Thread
Results 1 to 40 of 773

Hybrid View

  1. #1
    Join Date
    Nov 2008
    Posts
    96


    Did you find this post helpful? Yes | No

    Default 12F683 code to 12F629

    Quote Originally Posted by Darrel Taylor View Post
    I like the 683 too. If for nothing more than the CCP module. Of course the extra RAM and program space is also handy.

    With the 629 only having 64 bytes of RAM,
    PBP uses 24-26 bytes
    and DT_INTS-14 and ReEnterPBP want 31 bytes of it (without T? vars)

    Which only leaves about 6-7 bytes for the program. Not much you can do with that.

    But, when using ASM interrupt handlers, DT_INTS-14 only needs 7 bytes of RAM, leaving around 38 bytes for the users program. Now that, is workable. It also uses less program space that way.

    You mentioned earlier that you only needed to toggle a pin in the interrupt, so you might take a look at this page...

    DT_INTS-14 (Assembly Language Interrupts)
    http://www.darreltaylor.com/DT_INTS-14/asm_ints.html

    The ToggleLED1: handler does just that. And if the other handlers aren't too tuff, you might still fit it in a 629.

    HTH,
      DT
    Hi Darrel,
    I tried this above tip to get back some RAM space to try put my old 12F683 code into a 12F629, but I get a persistent PBP error when I try to compile it.

    error[101] d:temp\8chppm~3.asm 450: Error: (ReEnterPBP must be INCLUDEd to use PBP type interrupts)

    I also fiddled the wsave value to get past other errors, but this one escapes me, due to not being very familiar with assembly I'd expect.

    Heres my ASM code at the start of the program, what did I mess up ?
    Thanks Martin
    'Interrupt driven 20mS timer for PPM frame timing. See also "my_handler". Uses Timer 1 interrupts.
    INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
    'INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts

    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler TMR1_INT, _my_handler, PBP, yes
    endm
    INT_CREATE ; Creates the interrupt processor
    INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts

    ENDASM

    T1CON = $1 ; TMR1ON
    '@ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default The Error says it all

    error[101] d:temp\8chppm~3.asm 450: Error: (ReEnterPBP must be INCLUDEd to use PBP type interrupts)

    'INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
    \<-- commented

    INT_Handler TMR1_INT, _my_handler, PBP, yes

    Ahhh chuew ...
    DT

  3. #3
    Join Date
    Nov 2008
    Posts
    96


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    error[101] d:temp\8chppm~3.asm 450: Error: (ReEnterPBP must be INCLUDEd to use PBP type interrupts)

    'INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
    \<-- commented

    INT_Handler TMR1_INT, _my_handler, PBP, yes

    Ahhh chuew ...
    Hi,
    Sorry Darrel I'm even more confused from the reply. I interpreted your old post and the website info to mean that if I wasn't using PBP interrupts e.g. 'On Interrupt' that I could rem out the ReEnterPBP.bas include. I see I'm interpreting that post wrong.
    Can I take that reply to mean that in this case I can't do that, or does this mean I need to write the handler in ASM ?

    That's MR Ahhh Cheuw :-)

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,622


    Did you find this post helpful? Yes | No

    Default

    Hi,
    You can use Darrels routines with interrupt service routines written in assembly and/or BASIC. If the interrupt service routines you write are written in BASIC (PBP) you should declare them as type PBP in the INT_LIST AND you must INCLUDE ReEnterPBP.bas. If you write your interrupt service routines in assembly you declare them as Type ASM in in the INT_LIST and then ReEnterPBP file is NOT needed because you're not using ISR's written in BASIC. Anytime one or more of you ISR's are written in BASIC the ReEnterPBP file must be included, only when all handlers are in ASM can it be left out.

    ON INTERRUPT is the compilers own way of handling interrupts and has nothing to do with DT_Ints. You use either ON INTERRUPT or Darrels routines.

    /Henrik.

  5. #5
    Join Date
    Nov 2008
    Posts
    96


    Did you find this post helpful? Yes | No

    Default

    Thanks Henrik, that explanation is clear, concise, and fully understood now.

    cheers,
    Martin

  6. #6
    Join Date
    Jan 2010
    Location
    PHILADELPHIA, PA - USA
    Posts
    34


    Did you find this post helpful? Yes | No

    Default Understanding RBC_INT

    Well I think I've finally figured out some of the nuances of RBC_INT.
    I think the last example I tried to use was not a very good way to test it out.

    I tried to document this working code example in a way that's understandable and can be used as a template to build on.

    This is setup with PBP type interrupts using ReEnterPBP-18.bas, since I'm using PBP in the Interrupt handler, but ... it seems to work just fine when run as ASM type, and not including ReEnterPBP-18.bas. You can just uncomment out the appropriate lines to suit your needs.

    The thing that was giving me so much of a headache before was the need to read one of the Port B <4-7> registers prior to exiting the Interrupt handler. This ends the mismatch condition and allows the RB Port Change Interrupt Flag Bit to be cleared. Even though I was reading the Port B <4-7> registers frequently, it seems that using GOTO to enter the Interrupt handler exit subroutine, caused the Interrupt Flag Bit to reset.

    Program operation:
    This Program uses DEBUG to send status comments to a 9600 Buad Serial ASCII Terminal on PORTC.6
    On first press of any of the PORTB<4-7> buttons, the program enters the interrupt handler.
    The Interrupt Handler, continuously reads the buttons.
    Buttons 1,2 & 3 just display a status message. You could put any subroutine in place of the DEBUG Statement.
    Button 4 gracefully exits the interrupt handler.
    At this point, RBC_INT is reset and awaiting any PORTB<4-7> button press again to reenter the Interrupt handler.


    Anyway here's the Code and a schematic of the setup... I hope this helps someone who's struggling with RBC_INT like I was.
    The ZIP file attachment has the code, and copies of the version of DT_INTS-18.bas and ReEnterPBP-18.bas that are included.

    Bob W.

    Code:
    ' RBC TEST.BAS
    ' Bob Wozniak
    ' PIC 18F6480 @ 20 MHZ
    ' MPLAB IDE V8.40  /  PBP V2.60  /  Build Options: [-ampasmwin]
    ' RB4  Momentary Contact Button Goes High on Press,  10K Resistor to Ground
    ' RB5  Momentary Contact Button Goes High on Press,  10K Resistor to Ground
    ' RB6  Momentary Contact Button Goes High on Press,  10K Resistor to Ground
    ' RB7  Momentary Contact Button Goes High on Press,  10K Resistor to Ground
    ' RC6  22K ohm to RX on 57600-N-8-1 Serial Terminal
    ' This program created to check Port-B Change Interrupts
    
    INCLUDE "DT_INTS-18.bas"		  ; Include Darrel Taylor's Base Interrupt System for PIC18F [Version:3.4 (NOV 04, 2009)]
    INCLUDE "ReEnterPBP-18.bas"      ; Need to include if using PBP type interrupts
    
    DEFINE OSC 20
    
    DEFINE DEBUG_REG PORTC	' SETUP DEBUG to view output on 9600 BAUD ASCII Terminal on PORTC.6
    DEFINE DEBUG_BIT 6 			
    DEFINE DEBUG_BAUD 9600
    DEFINE DEBUG_MODE 1 
    
    I VAR WORD
    X VAR BYTE
    
    ASM
    INT_LIST  macro ; IntSource,  Label,             Type, ResetFlag?
    ;       INT_Handler RBC_INT, _RBC_INT_HANDLER,   ASM,  no             ; use for ASM type interrupts
            INT_Handler RBC_INT, _RBC_INT_HANDLER,   PBP,  no             ; use for PBP type interrupts
        endm
        INT_CREATE
    ENDASM
    @ INT_ENABLE   RBC_INT
    
    
    
    HOLD_HERE:          ' **** This subrouting loops continuously and waits for button press to activate RBC interrupt handler
    IF I = 0 THEN DEBUG 10,13,10,13,"HOLDING FOR PORTB <4-7> BUTTON PRESS to ACTIVATE INTERRUPT",10,13 : I = 1
    PAUSE 10
    GOTO HOLD_HERE
    
    
    
    RBC_INT_HANDLER:     ' **** Program jumps here when ANY PORTB.4 thru PORTB.7 are changed ****
    DEBUG "############### RBC INTERRUPT ACTIVATED #################",10,13
    PAUSE 250    ' This pause allows time for button debounce - needs to be here unless immediate read of interrupt button req'd
    
    
    READ_BUTTONS:        ' **** Program cycles reading buttons, until button 4 is pressed ****
    If PORTB.4 = 1 Then DEBUG "BUTTON 1 PRESSED",10,13
    If PORTB.5 = 1 Then DEBUG "BUTTON 2 PRESSED",10,13
    If PORTB.6 = 1 Then DEBUG "BUTTON 3 PRESSED",10,13
    If PORTB.7 = 1 Then DEBUG "BUTTON 4 PRESSED - EXITING",10,13 : I = 0 : GOTO END_RBC_INT
    PAUSE 5  
    GOTO READ_BUTTONS
    
    
    END_RBC_INT:        ' **** this subroutine gracefully exits the interrupt handler and resets for next RBC event ****
    PAUSE 250              ; This pause allows time for button debounce - needs to be here or interrupt will immediatly reactivate
    DEBUG "################ EXITING RBC INTERRUPT HANDLER ############",10,13
    
    X = PORTB.7            ; NOTE: Prior to returning from RBC Interrupt, you MUST read at least 1 PORTB <4-7> to end
                           ; the mismatch condition and allow the RB Port Change Interrupt Flag Bit to be cleared.
                           ; If not here, the interrupt will immediatly reactivate if using the GOTO END_RBC_INT statement.
    @ INT_CLEAR RBC_INT
    @ INT_ENABLE RBC_INT
    @ INT_RETURN
    END

    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by WOZZY-2010; - 20th February 2010 at 06:54. Reason: clarify
    Wozzy-2010

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default

    Hi Bob.

    I think you must be very quick on the 4th button to exit (less that 250ms plus the debug delay). If you hold the button longer the ISR will activate again,won't it?

    Also the:

    @ INT_CLEAR RBC_INT
    @ INT_ENABLE RBC_INT

    at the end of the ISR are not necessary as they are handled by the DT_Ints, right?

    Ioannis

  8. #8
    Join Date
    Jan 2010
    Location
    PHILADELPHIA, PA - USA
    Posts
    34


    Did you find this post helpful? Yes | No

    Default Understanding RBC_INT... or not

    Hi,

    I've been trying vary to fully understand the RBC_INT interrupt handler in DT_INTS-18.pbp.

    So I wrote this little program, Created a simulator circuit model and also a similar hardware circuit.

    Here is the Code:
    Code:
    ' RBC TEST.BAS
    ' PIC 18F6480
    ' MPLAB IDE V8.40
    ' PBP V2.60
    ' Build Options: [-ampasmwin]
    ' RB4  Momentary Contact Button Goes High on Press,  10K Resistor to Ground
    ' RB5  Momentary Contact Button Goes High on Press,  10K Resistor to Ground
    ' RB6  Momentary Contact Button Goes High on Press,  10K Resistor to Ground
    ' RB7  Momentary Contact Button Goes High on Press,  10K Resistor to Ground
    ' RC6  22K ohm to RX on 57600-N-8-1 Serial Terminal
    
    INCLUDE "DT_INTS-18.bas"		; Include Darrel Taylor's Base Interrupt System for PIC18F [Version:3.4 (NOV 04, 2009)]
    
    DEFINE OSC 20
    DEFINE DEBUG_REG PORTC	
    DEFINE DEBUG_BIT 6 			
    DEFINE DEBUG_BAUD 57600
    DEFINE DEBUG_MODE 1 
    DEFINE  SHOWDIGITAL 1
    
    TRISB=%11111111
    ADCON0=%00000000
    ADCON1=%00001111
    
    BTN	  VAR	BYTE
    
    ASM
    INT_LIST  macro ; IntSource,  Label,      Type,  ResetFlag?
            INT_Handler RBC_INT, _DO_RBC_INT,   ASM,  yes	
        endm
        INT_CREATE
    ENDASM
    
    @  INT_ENABLE   RBC_INT
    
    DEBUG "INTERRUPT CREATED",10,13
    DEBUG "INTERRUPT ENABLED",10,13
    
    HOLD_HERE:
    DEBUG "WAITING FOR INTERRUPT",10,13
    PAUSE 2500
    GOTO HOLD_HERE
    
    DO_RBC_INT
    DEBUG "############### RBC INTERRUPT ACTIVATED #################",10,13
    
    MENU:
    PAUSE 200
    DEBUG "MENU - READ BUTTONS",10,13
    If PORTB.4 = 1 Then PAUSE 250: Goto DO_ENABLE
    If PORTB.5 = 1 Then PAUSE 250: Goto DO_DISABLE
    If PORTB.6 = 1 Then PAUSE 250: Goto DO_RETURN
    If PORTB.7 = 1 Then PAUSE 250: Goto DO_CLEAR
    GOTO MENU
    
    DO_ENABLE:
    DEBUG "RUNNING DO_ENABLE",10,13
    @ INT_ENABLE RBC_INT
    Pause 250
    GOTO HOLD_HERE
    
    DO_DISABLE:
    DEBUG "RUNNING DO_DISABLE",10,13
    @ INT_DISABLE RBC_INT
    PAUSE 250
    GOTO HOLD_HERE
    
    DO_RETURN:
    DEBUG "RUNNING DO_RETURN",10,13
    @ INT_RETURN
    PAUSE 250
    GOTO HOLD_HERE
    
    DO_CLEAR:
    DEBUG "RUNNING DO_CLEAR",10,13
    @ INT_CLEAR RBC_INT
    PAUSE 250
    GOTO HOLD_HERE
    
    END
    Here is the Circuit:


    There are 4 buttons connected to PORT B <4.7>
    Here are my observations:

    The first press of any button activates the RBC Interrupt and sends program to DO_RBC_INT subroutine, then on to MENU where it checks for button presses. This behaves exactly as I would expect it to.

    Now...After that....

    Pressing Button RB.4 [ENABLE] Runs the DO_ENABLE subroutine then the HOLD_HERE subroutine. At this point, the Interrupt handler seems to shut down as no Port B inputs activate the interrupt handler. I would expect the Interrupt to remain active.

    Pressing Button RB.5 [DISABLE] Runs the DO_DISABLE subroutine then the HOLD_HERE subroutine. The Interrupt handler is now disabled as expected.

    Pressing Button RB.6 [RETURN] Runs the DO_RETURN subroutine then the HOLD_HERE subroutine. It then sends program to DO_RBC_INT subroutine, then on to MENU. I would expect it to return to HOLD_HERE which is wherr the interrupt was originally activated

    Pressing Button RB.7 [CLEAR] Runs the DO_CLEAR subroutine. At this point, the Interrupt handler seems to shut down as no Port B inputs activate the interrupt handler. I would expect this to just clear the interrupt then await another RBC trigger.

    So it seems I can only activate the interrupt one time.

    It doesn't seem to matter whether I use ASM or PBP types or set Resetflag to yes, or no

    Can anyone shed light on what I'm doing wrong, or am I simply misinterpreting the function of the INT_* utilities.

    I'm just not sure if I've got a mistake, am staying up too late working on this stuff, or just really don't get it.

    Thanks,
    Bob
    Attached Images Attached Images  
    Attached Files Attached Files
    Wozzy-2010

  9. #9
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    The idea of an Interrupt, is that it Stops the normal flow of the program ... executes an Interrupt Service Routine (ISR) ... then RETURNs back to the same point it was at when it was Interrupted.

    You can't go back to the Main Loop without INT_RETURN'ing.
    In other words ... no GOTO HOLD_HERE.
    <br>
    DT

  10. #10
    Join Date
    Jan 2010
    Location
    PHILADELPHIA, PA - USA
    Posts
    34


    Did you find this post helpful? Yes | No

    Default Not understanding RBC_INT

    Darrel,

    Thanks for the quick reply.

    I made a cut & paste error in my last post.

    It should have stated:
    Pressing Button RB.6 [RETURN] Runs the DO_RETURN subroutine. It then sends program to DO_RBC_INT subroutine, then on to MENU. I would expect it to return to HOLD_HERE which is where the interrupt was originally activated.

    Pressing Button RB.7 [CLEAR] Runs the DO_CLEAR subroutine Then the HOLD_HERE. At this point, the Interrupt handler seems to shut down as no Port B inputs activate the interrupt handler. I would expect this to just clear the interrupt then await another RBC trigger.

    I agree that it should never get to the GOTO HOLD_HERE statement, at the end of DO_RETURN:, but should still end up in HOLD_HERE since that is where the program was was when the RBC_INT interrupt was initially activated.
    Wozzy-2010

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, 07:32
  5. Replies: 1
    Last Post: - 1st November 2006, 04:11

Members who have read this thread : 4

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