cognew not working...new to prop
**problem solved (I forgot each cog has its own dira, outa registers, so I had to reset my dira[noparse][[/noparse]pins]**
I have in my main method:
where stack is stack[noparse][[/noparse]60]
Here is the startMotors method:
I have an LED light up for 1 second if the startMotors method runs, but I never see the LED light. However, the loop after the "cognew" line executes fine (as indicated by LEDs). What am I doing wrong? Here is the entire code:
Post Edited (bulkhead) : 7/28/2007 3:25:01 AM GMT
I have in my main method:
cognew(startMotors(10), @stack[noparse][[/noparse]0])
where stack is stack[noparse][[/noparse]60]
Here is the startMotors method:
PUB startMotors(startPin) | T,dt,motorLeftSpeed,motorRightSpeed
I have an LED light up for 1 second if the startMotors method runs, but I never see the LED light. However, the loop after the "cognew" line executes fine (as indicated by LEDs). What am I doing wrong? Here is the entire code:
'' File: SumoBot.spin
'' controls sumobot!
VAR
byte motorLeft 'duty cycle, -100 to 100 %
byte motorRight
long stack[noparse][[/noparse]60]
CON
_xinfreq = 5_000_000 ' 5 MHz external crystal
_clkmode = xtal1 + pll16x ' 5 MHz crystal multiplied → 80 MHz
PUB mainMethod
motorLeft :=0
motorRight :=0
dira[noparse][[/noparse]21..23]~ 'switches
dira[noparse][[/noparse]4..9]~~ 'LED's
outa[noparse][[/noparse]4..9]~ 'LED's off
cognew(startMotors(10), @stack[noparse][[/noparse]0])
repeat '**THIS LOOP WORKS**
{{loop stuff}}
' 6 pins....en1, en2, c1,c2,d1,d2
PUB startMotors(startPin) | T,dt,motorLeftSpeed,motorRightSpeed
dira[noparse][[/noparse]startPin..startPin+5]~~ 'change to output
outa[noparse][[/noparse]startPin..startPin+5]~ 'motors off
dT := clkfreq / 80 ' 1kHz refresh rate
outa[noparse][[/noparse]7]:=1 '**NEVER GOES ON**
waitcnt(cnt+80_000_000)
repeat
{{lots of stuff here}}
Post Edited (bulkhead) : 7/28/2007 3:25:01 AM GMT

Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Parallax Forums - If you're ready to learn, we're ready to help.
CJ, I just tried that, and now that part works. Thanks! However, now I have another problem; the indicator LED lights when the cog first starts the method and when it enters the loop, but it never keeps repeating the loop infinitely (the indicator LED lights up once in the loop and shuts off). Here is that method:
' 6 pins....en1, en2, c1,c2,d1,d2 PUB startMotors(startPin) | T,dt,motorLeftSpeed,motorRightSpeed dira[noparse][[/noparse]startPin..startPin+5]~~ 'change to output outa[noparse][[/noparse]startPin..startPin+5]~ 'motors off dT := clkfreq / 80 ' 1kHz refresh rate dira[noparse][[/noparse]4..9]~~ outa[noparse][[/noparse]6]:=1 'pin4 = indicator LED waitcnt(cnt+80_000_000) '**INDICATOR ON 1 SEC** outa[noparse][[/noparse]6]:=0 repeat outa[noparse][[/noparse]6]:=1 '**FLASH INDICATOR-HAPPENS ONCE** waitcnt(clkfreq/5+cnt) outa[noparse][[/noparse]6]:=0 waitcnt(clkfreq+cnt) motorLeftSpeed:=motorLeft motorRightSpeed:=motorRight motorLeftSpeed<#=100 'limit input from -100% to 100% motorLeftSpeed#>=-100 motorRightSpeed<#=100 motorRightSpeed#>=-100 if motorLeftSpeed < 0 'set motor directions outa[noparse][[/noparse]startPin+2..startPin+3]:=%10 elseif motorLeftSpeed>0 outa[noparse][[/noparse]startPin+2..startPin+3]:=%01 if motorRightSpeed < 0 outa[noparse][[/noparse]startPin+4..startPin+5]:=%10 elseif motorRightSpeed>0 outa[noparse][[/noparse]startPin+4..startPin+5]:=%01 outa[noparse][[/noparse]startPin..startPin+1]:=%11 'high duration outa[noparse][[/noparse]7]:=1 outa[noparse][[/noparse]9]:=1 if||motorLeftSpeed < ||motorRightSpeed waitcnt(cnt+dT*(||motorLeftSpeed) ) outa[noparse][[/noparse]startPin]:=0 outa[noparse][[/noparse]7]:=0 waitcnt(cnt+dT*(||motorLeftSpeed-||motorRightSpeed) ) 'low duration outa[noparse][[/noparse]startPin+1]:=0 outa[noparse][[/noparse]9]:=0 waitcnt(cnt+dT*(100-||motorRightSpeed) ) else waitcnt(cnt+dT*(||motorRightSpeed) ) outa[noparse][[/noparse]startPin+1]:=0 outa[noparse][[/noparse]9]:=0 waitcnt(cnt+dT*(||motorRightSpeed-||motorLeftSpeed) ) 'low duration outa[noparse][[/noparse]startPin]:=0 outa[noparse][[/noparse]7]:=0 waitcnt(cnt+dT*(100-||motorLeftSpeed) )Post Edited (bulkhead) : 7/28/2007 2:51:36 AM GMT
I suspect that one of your waitcnt calculations results in a value of cnt+0 which gives a very long pause (about a minute).