Shop OBEX P1 Docs P2 Docs Learn Events
Can't Access Pins in Newly Created Cog? — Parallax Forums

Can't Access Pins in Newly Created Cog?

TylerSkylerTylerSkyler Posts: 72
edited 2012-01-20 21:26 in Propeller 1
Hello All! My propeller bless its...diodes(?) has come up with a new trick and i can't seem to figure out why or how to fix it.
CON


_clkmode = xtal1 + pll8x
_xinfreq = 5_000_000




VAR




byte counter
long Pause,stack[2000],Left,Right Pulsout,Back,Forward,Nil, CDur,CDur1


OBJ


pst : "Parallax Serial Terminal"


PUB Main
Back := 300
Forward := 1000
Nil := 735
pst.start(9600)
Pause := clkfreq/1_000
Pulsout := clkfreq/500_000
dira[0..1]~~
outa[0..1]~
Left := 1
Right := 0

'Move Servos one and two in the forward direction
cognew(Move(Left,Right,Forward,Forward),@stack)




PUB Move(Pin,Pin1,Dur,Dur1)
' All of the "CDur" stuff is for ramping servos
if Dur == Forward
CDur := Dur - 350
if Dur == Back
CDur := Dur + 350
if Dur1 == Forward
CDur1 := Dur1 - 350
if Dur1 == Back
CDur1 := Dur1 + 350
repeat
ifNot CDur == Dur


if Dur == Forward
CDur += 1
if Dur == Back
CDur -= 1
if Dur1 == Forward
CDur1 += 1
if Dur1 == Back
CDur1 -= 1
pst.clear
pst.str(string(" ", 13))
pst.dec(CDur)
outa[Pin]~~
waitcnt(Pulsout * (CDur) + cnt)
outa[Pin]~
outa[Pin1]~~
waitcnt(Pulsout * (CDur1) + cnt)
outa[Pin1]~

Now on to the problem. When I launch the Move function into a new cog nothing happens, but when i simple call it within the main cog it runs fine. Why would this be? How can i call these servos within a new cog correctly? All Help is appreciated!

Thanks,
Tyler

Comments

  • eagletalontimeagletalontim Posts: 1,399
    edited 2012-01-20 19:38
    I just had this problem in my project as well. It appears as though you need to set the pins to what you want in the cog itself.

    Basically, move the code that activates the pins to the cog code.

    [PHP]
    ' Move this to the beginning of the Move function
    dira[0..1]~~
    outa[0..1]~
    Left := 1
    Right := 0
    [/PHP]

    Also, when posting code, use the [.PHP.] and [./PHP] tags (without the periods) to keep it easier to read.


    EDIT : I also noticed you are starting the display in the main code, but not in the Cog. You will also need to move that into the cog as well.
  • pedwardpedward Posts: 1,642
    edited 2012-01-20 19:39
    Tyler, you have used cognew incorrectly. You cannot pass variables to the COG in that manner. cognew is passed the function, a parameter value (which is in the PAR register of the new COG), and a stack pointer.

    What you have to do is establish a protocol to talk between the master COG and "do it" COG. The second argument should be a pointer to a variable that you use to send data back and forth, or a range of variables. There are many examples in the OBEX and included with the PDT. I would recommend looking at the ADC.spin object, since it is fairly short and simple.

    EDIT: Tim beat me to the punch. He's right, the pin direction register is set on a per-COG basis, that is each COG has it's own view of what an input and output is. Each of the COG's DIRA and OUTA registers are logically ORed together. Even though they are ORed, you still need to setup each COG separately.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-01-20 19:58
    pedward wrote:
    Tyler, you have used cognew incorrectly. You cannot pass variables to the COG in that manner. cognew is passed the function, a parameter value (which is in the PAR register of the new COG), and a stack pointer.
    Not so. You can start a Spin cog by using a normal method call with parameters, plus the stack address. Please read the manual before proffering advice.

    -Phil
  • TylerSkylerTylerSkyler Posts: 72
    edited 2012-01-20 20:01
    Thanks, eagle I tried your idea first over pedward's because it seemed like less work and i am lazy :lol: and it worked perfectly. Next time i will configure the code correctly(my first time posting code and i couldn't figure it out). Thanks for the quick responses!

    Cheers,
    Tyler
  • pedwardpedward Posts: 1,642
    edited 2012-01-20 21:22
    Not so. You can start a Spin cog by using a normal method call with parameters, plus the stack address. Please read the manual before proffering advice.

    -Phil

    Well Smile, foot n mouth.
  • kuronekokuroneko Posts: 3,623
    edited 2012-01-20 21:26
    Also, when posting code, use the [.PHP.] and [./PHP] tags (without the periods) to keep it easier to read.
    Using [noparse]
    
    [/noparse] looks even better :)                        
Sign In or Register to comment.