Shop OBEX P1 Docs P2 Docs Learn Events
output state not changing — Parallax Forums

output state not changing

TumblerTumbler Posts: 323
edited 2012-08-14 22:22 in Propeller 1
Hello,

I'm having troubles with my code:
PUB Main | i
  'start cogs
  cognew(BtnAllOff, @stack[0])




  dira[0..15] := %0000_0000_0000_0000   ' P0 -P15 → input (this command is redundant)
  dira[16..27]:= %1111_1111_1111        ' P16-P27 → output                


  Pause(100)
  vid.Start(115_200)                                    'start debug screen




  'set first relais on
  set(16)
  pause (100)
  repeat
    'check buttons 1..11
    repeat i from 1 to 11
      if button.ChkBtnPulse(i, 0, 60)
        toggle(16+i)


   
          
PUB BtnAllOff | time


  repeat
      time := button.ChkBtnHoldTime(0, 0, 60, 500)
      if time
         if time==500
           AllOff
    
PUB Set(output)
  outa[output]:=1
  vid.str(string("Set Output "))
  vid.dec(output)
  vid.str(string(" ",cr))
  
PUB Reset(output)
  outa[output]:=0
  vid.str(string("Reset Output "))
  vid.dec(output)
  vid.str(string(" ",cr))


PUB AllOn
  'set = ~~
  'reset= ~
  outa[16..27]~~
  vid.str(string("All On",cr))
 
PUB AllOff
  outa[16..27]~
  vid.str(string("All Off",cr))
  
PUB Toggle(output)
  vid.str(string("Toggle output "))
  vid.dec(output)
  vid.str(string(" ",cr))
  !outa[output]
  


PUB pause(ms) | t
  t := cnt
  repeat ms
    waitcnt(t += MS_001)

When i press buttons 1 to 11, an output will be toggled: ok
When i press the 0 button an half a second, i see the message 'All Off' in the terminal. so the second cog is running, however, the ouputs are not changing.
What i'm doing wrong here?

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-08-14 21:40
    Each cog has its own dira and outa. Because the outputs of all the cogs are ORed, one cog cannot turn off outputs that are set high by another cog.

    -Phil
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-08-14 21:41
    Only set "dira" and "outa" states from one cog.

    If one cog sets a pin as high another cog can't change to low.

    Edit: Phil bet me to it (again).
  • TumblerTumbler Posts: 323
    edited 2012-08-14 22:22
    Ok thx

    Solved with some global vars
Sign In or Register to comment.