Shop OBEX P1 Docs P2 Docs Learn Events
Disabling ISR during Serout — Parallax Forums

Disabling ISR during Serout

ackericackeric Posts: 7
edited 2008-08-27 06:30 in General Discussion
I may be trying to do something not possible or inadvisable. Simply I need to send out two byte of serial data , almost any speed will be fine , the faster the better. I need this to be done while watching a dozen IR transistors. The transistor pins or monitored In the ISR. That part works fine. As predicted the ISR screws up my serout Command, sometimes it work some times it does not. Can I simply disable the ISR during serout subroutine? Timing should not be a problem As the pulses on from the transistors last at least 200 ms, plenty of time to send out a few bytes. I have tried screwing around with the option reg. With No luck. Here Is my test code It just motors one transistor.
' =========================================================================
'
'   File...... SingleFlakeTest.SXB
'   Purpose... SX/B Programming Template
'   Author....  
'   E-mail....  
'   Started...
'   Updated...
'
' =========================================================================


' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------


' -------------------------------------------------------------------------
' Device Settings
' -------------------------------------------------------------------------

DEVICE          SX48, OSCXT2
FREQ            50_000_000


' -------------------------------------------------------------------------
' IO Pins
' -------------------------------------------------------------------------
SOutA         PIN    RB.0  OUTPUT   PULLUP
Mt1Front         PIN    RD.0   INPUT    cmos
Mt1Back          PIN    RD.1   INPUT    cmos

' -------------------------------------------------------------------------
' Constants
' -------------------------------------------------------------------------
AllFWD           CON      %11111111
AllRVS           CON      %00000000
BUAD             CON      "T19200"
FwdMt1           CON      $C6
MaxSpd           CON      $7F
ZeroSpd          CON      $0
Front            CON      1
Back             CON      0
ACT              CON      0
notact           CON      1
LmRs             CON      1800
WaitTime         CON      3000
' -------------------------------------------------------------------------
' Variables
' -------------------------------------------------------------------------
i                VAR      Byte
TempA            VAR      Byte
TempB            VAR      Byte 
PosFlagFT        VAR      BIT
PosFlagBK        VAR      BIT
NextPos          VAR      BIT
MtNum            Var     BYTE
SPED             VAr     BYTE
' -------------------------------------------------------------------------
  INTERRUPT  1000000
' -------------------------------------------------------------------------

ISR_Start:
        Serout  SoutA,buad, MtNum
        Serout  SoutA,buad, SPED


    IF Mt1Front = ACT THEN
        PosFlagFT  = ACT
      Else
                posFlagFT =NotAct
    ENDIF

  
Watch PosFlagFT
ISR_Exit:
  RETURNINT 
                                


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


Pgm_ID:
  DATA  "SX/B Template", 0


' -------------------------------------------------------------------------
' Subroutines / Jump Table
' -------------------------------------------------------------------------
GoFront           SUB  0
GOBack            SUB  0
Wait            SUB  0
MotCom          SUB  2

' -------------------------------------------------------------------------
' Program Code
' -------------------------------------------------------------------------

Start:
 OPTION = $88

Serout  SoutA,Buad, FwdMt1
Serout  souta,buad, zeroSpd
PAUSE  2000
Main:
'
DO

GoFront 
Wait 
'GoBack
'Wait 
LOOP
GOTO Main


' -------------------------------------------------------------------------
' Subroutine Code
' -------------------------------------------------------------------------

SUB GoFront
     
    MotCom  FwdMt1, MaxSpd
    PAUSE LmRs
     
    DO While PosFlagFt = NotAct
       IF  PosFlagFt = ACT THEN
     MotCom  FwdMt1, ZeroSpd


         ENDIF
    LOOP

ENDSUB



SUB GoBack 
      
    MotCom  FwdMt1, MaxSpd
    PAUSE LmRS
    DO While PosFlagbk = 0
If posFlagBK = act THEN
MotCom  FwdMt1, ZeroSpd
ENDIF
    LOOP
ENDSUB



SUB   Wait

        PAUSE  WaitTime
ENDSUB

SUB MotCom
'Code  to diable  ISR 
TempA = __PARAM1
TempB = __PARAM2


    SEROUT  SOutA,Buad, TempA
    SEROUT  SOutA,Buad, TempB
'Code to enable ISR 

ENDSUB




Comments

  • JonnyMacJonnyMac Posts: 9,215
    edited 2008-08-25 22:34
    You can easily do 19.2k baud in the ISR -- have your cake and eat it, too. You can't use the SEROUT command, but there's lots of code (posted by me and others) that shows you how to replace SEROUT with ISR code.
  • BeanBean Posts: 8,129
    edited 2008-08-25 23:06
    If the pulses last 200mSec, why are you using the interrupt at all ?
    Just read the pins inside the main loop.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    "A government big enough to give you everything you want, is big enough to take away everything you·have."·· Thomas Jefferson

    "It is our choices, Harry, that show what we truly are, far more than our abilities."·Dumbledore from Harry Potter

    www.iElectronicDesigns.com

    ·
  • ackericackeric Posts: 7
    edited 2008-08-27 03:09
    Thanks, I used the code from N&V 143. I went though the forum before posting some how my mind just filtered out anything with the word Assembly in it . My boss is terrified of it, I am just mildly apprehensive about it. I using the ISR because there will be much more going on then what is in the test code I posted. There will be six large panels rotating to produce patterns while syncing with several lights and other bits and pieces. It just seems easier to do it this way not That somebody else wrote the scary Assembly code. Also I have wanted to learn about interrupts and if some one wants to pay to do it all the better.
  • JonnyMacJonnyMac Posts: 9,215
    edited 2008-08-27 06:30
    Have a look at the program I've attached. It takes care of the ugly Assembly for you and provides a routine called TX_BYTE that you can use in place of SEROUT. The difference is that TX_BYTE uses a buffered UART so you can stuff the byte to send into the UART's buffer and get back to what you're doing.

    To be honest, I really couldn't figure out what your code wants to do as it's all over the place and seems to be bashed together from parts you've found elsewhere (that's okay, we all have differnent learning styles). In the program that I've supplied all 12 sensors (I'm assuming they're active-low) are scanned and with a bit of bit-mashing you end up with a couple of bytes that will have 1 in a bit position of a sensor that went from off-to-on. There front and back sensor elements for a given channel are put together and a stacked IF-THEN structure lets you decide what to do with the new inputs.

    Hopefully, at least some of it will be useful
Sign In or Register to comment.