Shop OBEX P1 Docs P2 Docs Learn Events
How to stipulate the execute time of the propeller controller ? — Parallax Forums

How to stipulate the execute time of the propeller controller ?

kevinspacekevinspace Posts: 56
edited 2011-06-08 09:43 in Propeller 1
Hello everyone~
How to stipulate the execution time of my propeller controller ?
For example :
CON
    _clkmode = xtal1 + pll16x                           
    _xinfreq = 5_000_000                               
PUB Main
    dira[16] := 1    
repeat    
    outa[16] := 1
Above the code, how to stipulate the bright time of LED?


Thanks a lot ~

Comments

  • Cluso99Cluso99 Posts: 18,069
    edited 2011-06-08 01:54
    In your example you are repeating the loop that outputs a 1 to P16. It will be on permanently. Delays will not help here.

    To toggle the output pin see the "~" command.
    To delay see the "waitcnt" command
    both are in the prop manual pdf that came with the PropTool so access it from the help menu of PropTool.

    This should get you started. There is a prop tutorial (is it in the manual?) that shows how to flash a LED and then goes on to show how to get multiple cogs flashing leds.

    If you still have problems, please ask.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-06-08 08:12
    To toggle the output pin see the "~" command.

    I think you mean !.


    @Kevin: Here's a simple blinker loop:
    dira[ LED ] := 1
    repeat
      !outa[ LED ]
    

    This will blink the LED as fast as spin can, probably too fast to see. Slow it down with a delay:
    dira[ LED ] := 1
    repeat
      !outa[ LED ]
      waitcnt(clkfreq / 10 + cnt)
    
  • kevinspacekevinspace Posts: 56
    edited 2011-06-08 08:50
    Thanks, JonnyMac!
    But I hope that I can designate the working time of the repeat loop.
    In your way, the result will blink the LED always.

    I hope the result that will launch the LED with my designate time, in the other hand,
    I hope that I can set a counter, however, if I set the counter as 10 seconds, the LED will
    launch 10 seconds, and then which will break the infinite loop, and if I set the counter as 20 seconds, the LED will launch 20 seconds and then which will break the infinite loop.

    Therefore, how to edit the code of counter?

    Thanks a lot~
  • Mike GreenMike Green Posts: 23,101
    edited 2011-06-08 09:13
    You need to use two separate cogs. One cog just blinks the LED. The other cog is your main program which decides (from some kind of user or sensor input) how fast the LED is to blink.

    It sounds like you need to learn how to program the Propeller and I suggest going through the Propeller Education Kit (PEK) tutorials. These are available from the downloads section of Parallax's website or via a "sticky" thread at the top of the thread list of this forum. There are examples in the tutorials for using multiple cogs for this sort of thing.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-06-08 09:43
    When you say you want to "launch the LED" with your designated time do you mean that you want to have it run autonomously from the rest of the application? If this is the case, you will create a method that is called with cognew that can blink the LED using a separate cog. When that cog is finished it will unload itself. See the attached example.

    [Edit] Do follow Mike's advice and download the PEK documentation. It's a good place to start.
Sign In or Register to comment.