Shop OBEX P1 Docs P2 Docs Learn Events
I'm sure I'm making a silly mistake...... — Parallax Forums

I'm sure I'm making a silly mistake......

cthomascthomas Posts: 17
edited 2013-02-11 18:49 in Propeller 1
This is driving me crazy. My thanks in advance for holding my hand here.
Read_pushbuttons runs in it's own cog and is supposed to monitor the state of four different buttons.
Two work and two don't. Edit: The nested repeats don't post correctly. Dang.

Everything else besides this little area works as planned but see my comments....

Here it is; pushing any of the buttons applies 3.3v to it's respective input pin. All pins have 10k pulldowns.

Pub Read_pushbuttons

Repeat
Repeat while (Stop_state == 1)
If ina[Edge_button] == 1
Edge_targets 'Never happens, even when button is pushed

If ina[Face_button] == 1
Face_targets 'Never happens, even when button is pushed

If ina[start_button] == 1
Stop_state :=0 'Works perfectly when the start button is pushed


Repeat while (stop_state == 0)
If ina[Stop_button] == 1
Stop_state :=1
Reboot Works perfectly when the Stop button is pushed



Pub Edge_targets 'Called by other parts of the program and works fine
OutA[Relay_targets] :=0



Pub Face_targets
OutA[Relay_targets] :=1 'The same, called by other parts of the program and works fine


Thanks,

Craig

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2013-02-10 19:00
    The two non-working cases involve function calls and the function itself runs in a separate cog which suggests a stack size issue (assuming that the buttons work). What is the stack size for this cog?

    Please use [noparse]
    
    [/noparse] tags for any code posting.                        
  • cthomascthomas Posts: 17
    edited 2013-02-10 19:47
    The stack size is 50 longs. I'm new to propeller and gave it 50 without much thought. I just tried 100 and it makes no difference.
    I'm not familiar with the
    
    tags?  If it's easy to explain how to use them, I will.

    Thanks for looking.
  • kuronekokuroneko Posts: 3,623
    edited 2013-02-10 19:57
    cthomas wrote: »
    The stack size is 50 longs. I'm new to propeller and gave it 50 without much thought. I just tried 100 and it makes no difference.
    Well, would have been too easy I guess. Can you verify that your edge/face buttons work by using them instead of the start button? E.g. change the code to
    If ina[edge_button] == 1
      Stop_state :=0 'Works perfectly when the edge button is pushed
    
    Also, could you post the complete code (as attachment), at least the bit which starts the Read_pushbuttons method?
  • MagIO2MagIO2 Posts: 2,243
    edited 2013-02-10 21:22
    In face/edge_targets you write that these work because they are called elsewhere, but in the code you gave us there is no elsewhere. Could it be that these are called in another COG and dira is only set correct in that COG?
  • LeonLeon Posts: 7,620
    edited 2013-02-11 05:15
    cthomas wrote: »
    The stack size is 50 longs. I'm new to propeller and gave it 50 without much thought. I just tried 100 and it makes no difference.
    I'm not familiar with the
    
    tags?  If it's easy to explain how to use them, I will.

    Thanks for looking.

    Just put the [ code] [ /code] tags at the beginning and end of the code (remove the spaces).
  • cthomascthomas Posts: 17
    edited 2013-02-11 16:54
    Well, the commands I am trying to execute from another cog DO run just fine if re-organized and placed into cog 0.

    This:
    Pub Read_pushbuttons
    
    Repeat
      Repeat while (Stop_state == 1)
        'If ina[Edge_button] == 1
          'OutA[Relay_targets] :=0   'I did have this as a method call to Edge_targets where it was the only line and it didn't work that way either but both cases work fine in my cog 0.
    
        'If ina[Face_button] == 1
          'OutA[Relay_targets] :=1  'Same here.  Doesn't work like this, or as a method call but works fine placed in cog 0
    
        If ina[start_button] == 1   ' Works as expected, no problems.
          Stop_state :=0
    
    
      Repeat while (stop_state == 0)  ' Works as expected.
        If ina[Stop_button] == 1
          Stop_state :=1
          Reboot
    

    is the pub I wanted to run in it's own separate cog 1. I have commented out the commands that won't run here but do run perfectly when placed where they run in the cog 0 running most of the program.

    Any thoughts? Thanks everybody.
  • kuronekokuroneko Posts: 3,623
    edited 2013-02-11 17:15
    That's a strong indication for a dira/outa issue as pointed out already by MagIO2. Try adding a dira[Relay_targets] := 1 as the first instruction in your method (before the loop).
  • cthomascthomas Posts: 17
    edited 2013-02-11 18:49
    kuroneko wrote: »
    That's a strong indication for a dira/outa issue as pointed out already by MagIO2. Try adding a dira[Relay_targets] := 1 as the first instruction in your method (before the loop).

    I can see the point, and somehow I missed altogether that spin running in different cogs needs it's own local declarations on the pins it's using? That would explain my difficulty.
    Drat.. I was thinking the one set of declarations in cog 0 took care of it.

    I have the Propeller Education Kit Labs book and I see that the example on page 71 works as you are suggesting but does the book ever spell this out?

    Thanks for helping.
Sign In or Register to comment.