Can't Access Pins in Newly Created Cog?
TylerSkyler
Posts: 72
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
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
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.
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
Cheers,
Tyler
Well Smile, foot n mouth.