View Full Version : Cog not starting

10-16-2011, 09:53 AM
I'm trying to generate PWM output for a project, the cognew command I use is not returning -1, but the code in the function is not running. If I run the function inline it works 100%, but I need it running on a seperate cog. Any Ideas? It's just a standard SPIN function, I'm using this to start the cog

Cog := cognew(mainloop, @Stack)

Maybe the Stack is not big enough? long Stack[120] ...I'm relatively new to this, help would be great. Thanks.

10-16-2011, 10:04 AM
It's possible to attach code to a post. If you want to know what your problem is, you should use this feature, so we can have a look at your actual code.

Yes, any kind of problems can occur if your stack is smaller than the needed stack. So it's possible that this is the cause of your problem, but without code nobody can tell you for sure.

10-16-2011, 10:10 AM
Sounds more like every-cog-has-its-own-dira/outa-register-set.

10-16-2011, 10:12 AM
My entire project code is massive, and to be honest it's not the greatest code. But the part I'm struggling with is the servo code. I'm trying to just generate pwm for servos, this is not rocket science, it should be easy, the main loop should not need much stack, it's real simple, here is a snippet

pub mainloop(dummy) | framets, pin, ts
framets := cnt+(clkfreq / _1uS * 20000)
repeat pin from 0 to 7
ts := cnt
outa[OutputPins[pin]] := 1
outa[OutputPins[pin]] := 0

Start is as such...

PUB Start | pin

repeat pin from 0 to 7
Set(pin, 1000)

Cog := cognew(mainloop(0), @Stack)


if I un-comment mainloop it functions 100% correctly. But not when starting a new cog up.

10-16-2011, 10:26 AM
Sounds more like every-cog-has-its-own-dira/outa-register-set.

Brilliant, Thanks so much. That helped. Happy days...

10-17-2011, 01:16 PM
I think we've all been bit on each cog having it's own dira/outa/ina register set! You don't notice the ina issue so much because the default is input.