Shop OBEX P1 Docs P2 Docs Learn Events
Aborting a PAUSE — Parallax Forums

Aborting a PAUSE

LightfootLightfoot Posts: 228
edited 2007-07-29 04:27 in General Discussion
I have a very simple program that turns an LED on and off. I want the program to immediately stop if a switch on RA.2 is pushed. If I do it this way (see below) it may take one second to exit the loop. I want the RA.2 input to even override a pause command.

plp_a = 0

DO WHILE RA.2 = 1

RA.0 = ~RA.0
pause 1000

LOOP

rb = %00111100

Thanks

Post Edited By Moderator (Bean (Hitt Consulting)) : 7/29/2007 10:03:59 PM GMT

Comments

  • JonnyMacJonnyMac Posts: 8,940
    edited 2007-07-25 22:55
    You could use an edge-triggered interrupt on one of the RB pins, but this might be a little easier:

    DO WHILE AbortBtn = No
      PAUSE 50
      INC ledTmr
      IF ledTmr = 20 THEN
        Led = ~Led
        ledTmr = 0
      ENDIF
    LOOP
    



    This checks the abort button 20 times per second, instead of once per second as with your code.
  • LightfootLightfoot Posts: 228
    edited 2007-07-26 02:06
    Here is the main program I wish to perform abortions in (see attached). Each DO..LOOP performs a unique function. Pushing the RA.1 button does not break you out of the loops. The LED flasher portion Johnny posted does work. The RA.1 button is supposed to toggle between each of the three functions. Are interrupts the best way in this situation?

    DEVICE          SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
    FREQ            4_000_000
    PROGRAM Start
    
    Start:
    
    plp_a = 0
    tris_b = 0
    tris_c = 0
    ctr var byte
    rnd var byte
    
    DO
        RC = %00000001 'Light Normal Mode LED indicator.
        RB = 255 'Turn lights on.
        
        DO WHILE RA.1 = 1 'Normal Mode (Activates dimmer switch.)
            IF RB < 255 THEN
                RB = RB + ~RA.2
            ENDIF
            IF rb > 0 THEN
                RB = RB - ~RA.3
            ENDIF
            PAUSE 2
        LOOP
    
        RC = %00000010 'Light Fade Mode LED indicator.
    
        DO WHILE RA.1 = 1 'Fade Mode (Lights adjust to a random brightness.)
            RANDOM rnd 'Generate random number.
            IF rnd <= RB THEN
                FOR ctr = RB TO rnd STEP -1
                    DEC RB
                    PAUSE 2
                NEXT
            ELSE
                FOR ctr = RB TO rnd
                    INC RB
                    PAUSE 2
                NEXT
            ENDIF                
        LOOP
    
        RB = 0
        RC = %00000100 'Light Blink Mode LED indicator. 
    
        DO WHILE RA.1 = 1 'Blink Mode (Lights turn on and off.)
            rb = ~rb
            pause 1000            
        LOOP 
    
    LOOP
    
    



    Connected to the RB port is another SX that dies the PWM command.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • CapdiamontCapdiamont Posts: 218
    edited 2007-07-29 03:51
    maybe another way to do it, is to have the main loop check the buttons, then gosub to your loops?

    NOTE this isn't actual code

    main:
    if btn_a = 1 then mode = mode+1
    if btn_b = 1 then goto THEEND
    if mode => maxmode then mode=0

    if mode = 0 gosub loopa
    if mode = 1 gosub loopb
    if mode = 2 gosub loopc
    goto main

    loopa:
    turn output on
    return

    loopb:
    if delaytemp = maxdelay then toggle output
    if delaytemp = maxdelay then delaytemp = 0
    delaytemp = delaytemp + 1
    return

    etc
  • OzStampOzStamp Posts: 377
    edited 2007-07-29 04:27
    Hi

    If your just flashing a led why not
    a pushbutton· +· resistor + flashing led all in series

    ············································ led that flashes by itself..
    ··············································|\
    ·+
    ·PushB·
    [noparse][[/noparse]·resistor]
    | ||----· -
    ············································· |/

    Or a 555 timer astable with a reset button wired to pin 4

    Ronald Nollet
Sign In or Register to comment.