Shop OBEX P1 Docs P2 Docs Learn Events
Interrupt with Basic — Parallax Forums

Interrupt with Basic

RemziRemzi Posts: 4
edited 2004-12-16 20:17 in General Discussion
Hello,

I recently purchased the SX Tech board. I am trying to figure out the Interrupt rutine. My task is to use as a emergency stop and reset or go back to beginning of my program.

Please help me out with the pbasic software,·what·I need to do?

Thanks

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-07 07:15
    Give the Help file a glance before you panic -- it has examples for using INTERRUPTs in BASIC (SX/B).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • BeanBean Posts: 8,129
    edited 2004-12-07 12:03
    If you just want to restart the program, you can use the /MCLR pin to do that.

    You'll have to give more details if you want some detailed advise.

    Bean.
  • allanlane5allanlane5 Posts: 3,815
    edited 2004-12-07 15:15
    There is an SX/B 'Template' file, which has defaults for most things. Start with that, and add code in the 'Interrupt' section.
  • RemziRemzi Posts: 4
    edited 2004-12-09 03:49
    I have a switch connected to RB.0 as Active-high
    I have 2 leds, RC.0 and RC.1
    I'd like to Blink the RC.0 as a main program
    when itterrupt happens RC.1 blinks 1 sec. end goes
    back to where ever it's left
    Here my code to be!!! What do I do wrong?

    Thanks,

    DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
    FREQ··········· 4_000_000
    Led1·············VAR···· RC.0
    Led2·············VAR···· RC.1
    '
    INTERRUPT
    '
    ISR_start:
    ·· HIGH LED2
    ·· PAUSE 1000
    ·· LOW LED2
    ISR_Exit:
    ·· WKPND_B = %00000000····· ' Clear pending, enable interrupt
    ·· RETURNINT
    '
    PROGRAM Start··················· ' I dont know why I need this???
    '
    Start:
    ··· TRIS_C = %00000000······· ' port c output
    ··· WKED_B = %11111110······ ' rb.0 falling edge
    ··· WKEN_B = %11111110······ ' rb.0 is input
    ·· ·WKPND_B = %00000000···· ' Clear pending, enable interrupt
    ····HIGH Led1
    ····PAUSE 500
    ·· ·LOW Led1
    ··· PAUSE 500
    ·GOTO Start
    END
    ·····
  • allanlane5allanlane5 Posts: 3,815
    edited 2004-12-09 15:02
    1. NEVER NEVER NEVER do a 'pause' in an ISR (Interrupt Service Routine).
    An ISR is supposed to be QUICK. Get in, set a flag, get out.
    Check the flag in your upper level routine, and do something with it.

    The problem you run into is that an ISR 'interrupts' your main routine. Thus it distorts the timing of your main routine. You want that distortion to be as small as possible.

    The other problem you get is multiple triggers. With a slow ISR, additional triggers are either ignored, or cause re-entrancy into your ISR -- not a good thing.
  • RemziRemzi Posts: 4
    edited 2004-12-13 15:38
    Thanks to all·for the replies, however,·I changed the code·as following,·pause is out inthe interrupt,· and trying to·wait until reset is pressed, I am not sure if·changing wken_b to all 1's does the·job. But this prgram still doesnt·work that·I wantted to.
    simple what I'd like is to when iterrupt happens, stop the blinking led1, turn the led2 until reset.
    Thanks,



    DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
    FREQ··········· 4_000_000
    Led1·············VAR···· RC.0
    Led2·············VAR···· RC.1
    '
    INTERRUPT
    '
    ISR_start:
    ···LOW LED1
    ···HIGH·LED2
    ISR_Exit:
    ·· WKEN_B = %11111111····· '·NO interrupt until reset
    ·· RETURNINT
    '
    PROGRAM Start··················· ' I dont know why I need this???
    '
    Start:
    ··· TRIS_C = %00000000······· ' port c output
    ··· WKED_B = %11111110······ ' rb.0 falling edge
    ··· WKEN_B = %11111110······ ' rb.0 is input
    ·· ·WKPND_B = %00000000···· ' Clear pending, enable interrupt
    ····HIGH Led1
    ····PAUSE 500
    ·· ·LOW Led1
    ··· PAUSE 500
    ·GOTO Start
    END
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-13 16:13
    I've attached a program that does what you want.· Give it a look.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • RemziRemzi Posts: 4
    edited 2004-12-16 19:40
    Thank you all for the support and especially Jon, It works the way I wantted. But I didnt understand this part,

    Pgm_ID:
    DATA "SX/B Template", 0

    Why do you have this? I think I doesnt do anything with ISR...

    Thanks,
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-16 20:17
    Sorry, that was just left over from my default template -- delete it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
Sign In or Register to comment.