Shop OBEX P1 Docs P2 Docs Learn Events
Subroutine call inside an ISR — Parallax Forums

Subroutine call inside an ISR

SelfPropelledSelfPropelled Posts: 6
edited 2010-06-29 22:47 in General Discussion
It appears that calling a Subroutine from an Interrupt causes problems.
The SUB directive occurs after the ISR routine, so the Sub call generates
an 'unkown command' error.

Moving the SUB directive above the ISR routine causes other problems.

Am I missing something?

[noparse][[/noparse]code]
'==========================================================================
' INTERRUPT
'

ISR_Start:

PULSOUT RA.0, 1000 'FLASH TEST LED
PULSOUT RA.1, 1000
PULSOUT RA.2, 1000

READKEY ' <<< THIS GENERATES COMPILER ERROR 'UNKNOWN COMMAND'
ISR_Exit:

Keys = %0000_0000 'Set Key Row Drive low for WKED
WakePend = %0000_0000 'CLEAR INTERRUPT PENDING FLAG.
RETURNINT

'=========================================================================

PROGRAM Start
'=========================================================================

'
' Program Code
'

READKEY SUB 0 ' <<< Is this in the right place?

Start:
TRIS_Keys = %1111_0000 ' refresh IO state
Keys = %0000_0000 ' Set Key Row Drive low for WKED
WKED_B = %1111_1111 ' Falling edge detect
WKEN_B = %0000_1111 ' Use bits 4-7 for inputs
ST_B = %0000_1111 ' Bits 4-7 are Schmitt Trigger Inputs

'...

'

SUB READKEY
.
.
.
ENDSUB


'=============================================================

Comments

  • BeanBean Posts: 8,129
    edited 2010-06-29 21:01
    You need to use GOTO

    '==========================================================================
    ' INTERRUPT
    ' -------------------------------------------------------------------------
    
    
    ISR_Start:
      GOTO ISR_Code
      
    '=========================================================================
    
    PROGRAM Start
    '=========================================================================
    
    ' -------------------------------------------------------------------------
    ' Program Code
    ' -------------------------------------------------------------------------
    
    READKEY SUB 0 ' <<< Is this in the right place?
    
    Start:
    TRIS_Keys = %1111_0000 ' refresh IO state
    Keys = %0000_0000 ' Set Key Row Drive low for WKED
    WKED_B = %1111_1111 ' Falling edge detect
    WKEN_B = %0000_1111 ' Use bits 4-7 for inputs
    ST_B = %0000_1111 ' Bits 4-7 are Schmitt Trigger Inputs
    
    '...
    
    '-------------------------------------------------------------------------
    
     
    ISR_Code:
     
    PULSOUT RA.0, 1000 'FLASH TEST LED
    PULSOUT RA.1, 1000 
    PULSOUT RA.2, 1000 
    
    READKEY ' <<< THIS GENERATES COMPILER ERROR 'UNKNOWN COMMAND'
    ISR_Exit:
    
    Keys = %0000_0000 'Set Key Row Drive low for WKED
    WakePend = %0000_0000 'CLEAR INTERRUPT PENDING FLAG.
    RETURNINT
    
    SUB READKEY
    .
    . 
    .
    ENDSUB
    
    
    '=============================================================
    

    Bean


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.
    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There are two rules in life:
    · 1) Never divulge all information
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]
  • JonnyMacJonnyMac Posts: 8,912
    edited 2010-06-29 21:04
    To do this you have to move the ISR code below the SUB/FUNC definitions. The easiest way to do this is to add:

    GOTO ISR_Handler
    



    In the interrupt section -- this is the only thing there. Somewhere in your listing (usually after the main body of the program) you'll have this:

    ISR_Handler:
      ' your code here
      RETURNINT
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
  • SelfPropelledSelfPropelled Posts: 6
    edited 2010-06-29 21:08
    TY Bean.
    Much appreciated.
    Mike
  • SelfPropelledSelfPropelled Posts: 6
    edited 2010-06-29 22:47
    JonnyMac,
    I missed your reply earlier.
    Nice approach.
    Thanks very much.
Sign In or Register to comment.