Shop OBEX P1 Docs P2 Docs Learn Events
Interupts in BASIC? — Parallax Forums

Interupts in BASIC?

Armored CarsArmored Cars Posts: 172
edited 2004-08-20 02:19 in BASIC Stamp
Can interupts be programmed in BASIC?· If so how or where can I·find out·how, I havnt seen it anywhere.
Aaron

Comments

  • GadgetmanGadgetman Posts: 2,436
    edited 2004-08-19 12:12
    The short and sweet of it is 'no'...

    On the BS2p and BS2pe you have the POLL instructions, though, but no real interrupts.
  • BeanBean Posts: 8,129
    edited 2004-08-19 12:18
    Is there something in particular that you are trying to do ?
    Maybe there is a way around it.

    Terry
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-08-19 13:05
    No, you cannot do interrupts in BASIC -- not with Parallax product, not with anybody's product. BASIC is not reentrant. As indicated above, the BS2p and BS2pe allow polling between instructions, and other vendors use this technique to a lesser or greater degree as well.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • Armored CarsArmored Cars Posts: 172
    edited 2004-08-19 17:55
    What is polling?
    What I am doing is controlling a standard RC car, I have so many IFs and Subroutines Im afraid of running out of memory or sensors lagging since it check only one at a time.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-08-19 18:07
    On the BS2p and BS2pe, polling allows the BASIC Stamp to check the status of designated IO pins an take an action (within limits).· Have a look at the various POLL commands in the manual or help file (note: polling is a bit advanced).
    Regarding your program, there is a strategy that many use that is the high-level equivalen of the way a lot of assembly programs are designed.· The idea is to create a task switcher such that important code runs every time through the main control loop.· After the important code, then next task is run.· Under normal operation each task simply points to the next, but it has the ability to redirect to a new task if conditions warrant.· Here's a bit of pseudo-code to give you an idea:

    Main: 
      GOSUB Very_Important_Stuff                ' -- like background code   
      ON task GOSUB Task0, Task1, Task2, ... 
      GOTO Main 
    
    Task0: 
      ' do task code first 
      IF (conditions are okay) THEN 
        task = task + 1 // NumTasks             ' point to "normal" next task 
      ELSE 
        IF (condtion is really bad) 
          GOSUB Emergency_Handler 
        ELSE 
          task = xx                             ' point to next task that should run 
        ENDIF 
      ENDIF 
      RETURN
    


    By placing your task code in subroutines, the code can be called from anywhere within your program -- including other tasks.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2004-08-19 19:49
    I have a little tutorial on "advanced" usage of polling at this URL:
    www.emesystems.com/BS2pe.htm#spram_specials

    The examples in the manual barely scratch the surface, and the tutorial does not get very deep into it either. You have to understand the role of the extra read-only locations in the scratchpad ram, how they can latch the occurance of events that occur on input pins while the program is off doing other things. I have made use of the pollwait command in the context of having the Stamp sleep until any of several different triggering events occur.

    If your program is getting too many IFs and branches, it will really be a good idea and follow Jon's advice about program organization.

    -- Tracy

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • DonDon Posts: 34
    edited 2004-08-20 02:19
    Actually, on NetMedia's BX-24 you can set up a task and then tell it to wait for an external interrupt. That task stays blocked until the interrupt occurs. When it does, the waiting task is run on the next instruction cycle.

    It's true that this is nowhere near what the interrupt response that you'd get by programming a microcontroller in assembly language or a compiled language but it does give you a reasonable ability to respond to an asynchronous event.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don Kinzer

    ·
Sign In or Register to comment.