Shop OBEX P1 Docs P2 Docs Learn Events
Nested Objects — Parallax Forums

Nested Objects

Chip CoxChip Cox Posts: 73
edited 2009-08-17 23:54 in Propeller 1
I am just starting out with Spin so please forgive me if this is an obvious question or is answered elsewhere.

I am playing with the multiple cog object example from the Prop education kit labs.· I have the setup the basic circuit and duplicated it over 3 switches and leds.· I have an array of button cogobjects setup so that I can press a button and a light comes on and blinks like it should.· Each button object calls a blink object to handle the blinking.· Since each button is a separate instance running in it's own cog ( so it can monitor the buttons separately, I thought that each reference to the blink cog_object would be a separate instance as well since it's beng defined in separate instances of button.· But I seem to be getting some cross talk between the objects and don't understand why.
Thanks

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-08-16 22:11
    Without a listing of your program, it's impossible to tell for sure, but you may need a larger stack area for each cog. Best is to use the Attachment Manager to attach a copy of the program.
  • Chip CoxChip Cox Posts: 73
    edited 2009-08-17 03:46
    I thought I had it, but no.· I've attached all 3 objects.· Ccbuttonblinkercogmain is the top.· Just to help make sense of some of my jibberish around the pins, I am using one of the propeller demo boards which has p0-p7 exposed for jumpers and p16-p23 hardwired to leds on the board.· So I am calculating input and led ports based on an index offset for my button array.· Also, so I can tell which light is blinking, I am using every 3rd light.· In short, the math is strange, but the math works.·
    The problems start when I try pressing two buttons at once.· Sometimes it works sometimes it doesn't.· The stack is huge so I don't think that's the problem.· When I press two buttons lets say buttons 1 and 3.· Lights 1 and 3 start blinking like they should.· But then if I press button 2, light 3 goes out and it's like the button cog for button 3 dies.·
    That's why my original question was around the scope of the objects run by cogs.· I have 3 instances of the button object running in 3 cogs.· So the way I understand it, (put much more simply than it is)·each cog has it's own copy·of the variables to work with.· This keeps any variables in the button cog separate from each other.· If I didn't have separate instances of the objects, the global variables in the object would be common between all three object/cogs.· Thats why I'm wondering about the objects/cogs started from the three instances of button.· Since they seem to have their own address space, do the global variables for the blink objects go into their spaces, or do they all fire against one address space?
    I'm sorry I'm doing such a poor job of describing this.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-08-17 04:17
    Each instance of ccBlinker has its own private copy of ccButton, so there are 3 copies of ccButton, each with its own ccButton (a total of 3 ccButton).

    If there's noise or bounce on the pushbutton inputs, the delta will be too short and Blink won't work as you expect it. Put a "sanity" check in ccButton and don't call Blink if the delay is less than 100ms (CLKFREQ/10).
  • photomankcphotomankc Posts: 943
    edited 2009-08-17 13:34
    To expand a bit on what Mike said I have my own button objects (not cog spawning though) that have a programmable delay requirement. So sor instance when you call IsPressed(PIN, STATE, 80) it looks to see if the pin is in the requested state. It then waits the requested number of milisecs (80 for instance) and looks again to see if it's still in that state. If it is it was a button press and the function returns true, if not it's discarded and the function returns a false. Keeps it from recognizing transients as button presses.
  • Chip CoxChip Cox Posts: 73
    edited 2009-08-17 23:54
    Ok, that makes sense for how it's working. I'm just trying to expand on the samples to learn more. So it's not anything critical. Thanks for yall's help. I hope I can return the favor sometime.
Sign In or Register to comment.