Shop OBEX P1 Docs P2 Docs Learn Events
Switching on a cog - once! — Parallax Forums

Switching on a cog - once!

John A. ZoidbergJohn A. Zoidberg Posts: 514
edited 2010-10-26 06:33 in Propeller 1
Hello there,

I've a bit of problem with enabling a cog, which is shown in the code space below:
some program loop here:

repeat
|-- ...
|-- ...
|-- IF (alarm)
     |-- coginit(3, anotherCog, @stack3)
|-- ...


However, the program works, but it didn't initialize the cog once, but a lot of times according to the loop, causing the system to stutter.

How can I turn the cog on once, and latch it? I know it could be a basic programming question, but I couldn't figure this one out. :lol:

Comments

  • blittledblittled Posts: 681
    edited 2010-10-26 05:11
    There isn't much detail to go by here. Did you set alarm to false after the coginit line? If you don't the coginit will launch keep launching cogs while alarm = true which may be causing the stutter.
  • Heater.Heater. Posts: 21,230
    edited 2010-10-26 05:37
    How about something like:
    VAR
      byte alarm
      byte alarmCog
      long stack3[20]
    
    PUB start
    
    repeat
    '...
    '...
        if alarm
            if alarmCog == 0
                alarmCog := cognew(anotherCog, @stack3) + 1
    '...
    '...
    
    
    
    Generally using coginit is frowned upon.
  • John A. ZoidbergJohn A. Zoidberg Posts: 514
    edited 2010-10-26 06:33
    Danke! Thanks for the help. Now I can hook it up to the relay or something for my application. :)
Sign In or Register to comment.