PDA

View Full Version : Cog not starting



SolderHead
10-16-2011, 10: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.

MagIO2
10-16-2011, 11: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.

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

SolderHead
10-16-2011, 11: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
repeat
framets := cnt+(clkfreq / _1uS * 20000)
repeat pin from 0 to 7
ts := cnt
outa[OutputPins[pin]] := 1
waitcnt(ts+ServoData[pin])
outa[OutputPins[pin]] := 0
waitcnt(framets)

Start is as such...

PUB Start | pin

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

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

'mainloop

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

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

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

4x5n
10-17-2011, 02: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.