Shop OBEX P1 Docs P2 Docs Learn Events
Prop Basis & Tasks — Parallax Forums

Prop Basis & Tasks

TimHTimH Posts: 48
edited 2011-08-10 10:23 in Propeller 1
I've just started playing with a QuickStart board and PropBasic so I'm at the flashing LED's stage.
I want to start 2 tasks (running in separate cogs) each one flashing a different LED.
Here's my very simple test code:

DEVICE P8X32A, XTAL1, PLL16X
FREQ 80_000_000
'FLASHES LED'S ON THE QUICKSTART BOARD

PROGRAM Start
'Define Tasks
Led_Flash1 TASK
Led_Flash2 TASK


Start:

COGSTART Led_Flash1
COGSTART Led_Flash2

END




TASK Led_Flash1
LED1 PIN 16 OUTPUT
High LED1
PAUSE 500
LOW LED1
ENDTASK

TASK Led_Flash2
LED2 PIN 17 OUTPUT
HIGH LED2
PAUSE 500
LOW LED2
ENDTASK

I get errors when I compile with PropBasic. Anyone have any input - I read all material on this I can find.

Comments

  • StefanL38StefanL38 Posts: 2,292
    edited 2011-08-10 08:38
    How about using SPIN?
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
      LED1 = 16
      LED2 = 17
    
    VAR
     long LedStack1[20]
       
    PUB Main
    
      cognew(Led_Flash1,@LedStack1) 'start new cog (task)
      Led_Flash2                    'use actual cog (task) to run Subroutine in the actual cog
    
    
    PUB Led_Flash1
    
      DIRA[LED1] := 1    'set Propeller-IO-Pin as output
      repeat
        OUTA[LED1] := 1  'set propeller-IO-Pin to High (3.3V)
        Pause(500)
        OUTA[LED1] := 0  'set propeller-IO-Pin to Low (0.0V)
        Pause(500)
    
    
    PUB Led_Flash2
    
      DIRA[LED2] := 1    'set Propeller-IO-Pin as output
      repeat
        OUTA[LED2] := 1  'set propeller-IO-Pin to High (3.3V)
        Pause(250)
        OUTA[LED2] := 0  'set propeller-IO-Pin to Low (0.0V)
        Pause(250)
    
    
    PUB Pause(PauseTime)
      WaitCnt(ClkFreq / 1000 * PauseTime + cnt)
    
    keep the questions coming
    best regards

    Stefan
  • TimHTimH Posts: 48
    edited 2011-08-10 08:44
    Yes - I've used SPIN for other projects but want to try out Prop Basic. It would seem to offer better speed than SPIN with the same ease of use.
  • mindrobotsmindrobots Posts: 6,506
    edited 2011-08-10 10:09
    OK, how about this:
    DEVICE P8X32A, XTAL1, PLL16X
    FREQ 80_000_000
    'FLASHES LED'S ON THE QUICKSTART BOARD
    'Define Tasks
    Led_Flash1 TASK                  ' moved these to outside "Program"
    Led_Flash2 TASK                  ' moved
    PROGRAM Start
    Start:
    COGSTART Led_Flash1
    COGSTART Led_Flash2
    END
     
    TASK Led_Flash1
    LED1 PIN 16 OUTPUT
    Flash1:          ' added this
    High LED1
    PAUSE 500
    LOW LED1
    PAUSE 500  ' added this
    Goto Flash1 ' added this
    ENDTASK
     
    TASK Led_Flash2
    LED2 PIN 17 OUTPUT
    Flash2:                          ' added this
    HIGH LED2
    PAUSE 500
    LOW LED2
    PAUSE 500               ' added this
    Goto Flash2              ' added this
    ENDTASK
    

    I don't do PropBASIC, yet but:

    1) it appears the TASK definitions need to be outside the Program definition. Thsi got rid of the compile error and cause some valid SPIN to be generated.
    2) your Flasher tasks needed to loop, otherwise, they just turned on the LED and left.

    The code above blinks 2 LEDs on my QuickStart board on 1/2 second, off 1/2 second.

    Happy coding!!
  • TimHTimH Posts: 48
    edited 2011-08-10 10:23
    Thanks Mindrobots
    That compiles -- I realized I had missed the loop in the tasts, but thought should still compile. I will try on my QuickStart tonight.
Sign In or Register to comment.