Newbie COG question
Shane M
Posts: 58
Hi. This PUB function works perfectly.·
I only want to start this in it's own COG.· Nothing I try works.· I followed the examples.
When I put it in it's own cog, it acts completely different.· I'm guessing I'm missing something key.
How would you start this in it's own COG?
PUB PollSerial
··· serial.RxStr(@strin)··
··· if (not strcomp(@strin,@strlast))
····· emic.say(@strin, true)· 'have emic say text
····· serial.str(@strin)·· ' debug
····· emic.WaitNotBusy···· ' wait for emic
····· CopyString(@strlast,@strin) ' copy current string
··· emic.WaitNotBusy
Here is what I did.
Original Main Loop:
·
Original PUB:
Works fine!· THEN I TRIED THIS:
New Main:
New PollSerial:
The biggest thing I see is that the serial.RxStr command waits for me to send ONE byte and then loops and loops.· Never again waiting for data.· The Serial object is a spin object I downloaded.· But again, I don't see how this should be so vastly different just because I ran it in a cog.
Any ideas?
Shane Merem
www.websiteforge.com
www.magnusoft.com
I only want to start this in it's own COG.· Nothing I try works.· I followed the examples.
When I put it in it's own cog, it acts completely different.· I'm guessing I'm missing something key.
How would you start this in it's own COG?
PUB PollSerial
··· serial.RxStr(@strin)··
··· if (not strcomp(@strin,@strlast))
····· emic.say(@strin, true)· 'have emic say text
····· serial.str(@strin)·· ' debug
····· emic.WaitNotBusy···· ' wait for emic
····· CopyString(@strlast,@strin) ' copy current string
··· emic.WaitNotBusy
Here is what I did.
Original Main Loop:
PUB Run 'Main Loop - watch serial/watch pink/watch button 'initialze Emic,Serial and Network Initialize repeat PollSerial ' the function I'll show you next PollButton
·
Original PUB:
PUB PollSerial serial.RxStr(@strin) if (not strcomp(@strin,@strlast)) emic.say(@strin, true) 'have emic say text serial.str(@strin) ' debug emic.WaitNotBusy ' wait for emic CopyString(@strlast,@strin) ' copy current string emic.WaitNotBusy
Works fine!· THEN I TRIED THIS:
New Main:
PUB Run 'Main Loop - watch serial/watch pink/watch button 'initialze Emic,Serial and Network Initialize if (not (cognew(PollSerial, @SqStack) ) repeat PollButton
New PollSerial:
PUB PollSerial repeat ' ONLY LINE I ADDED** serial.RxStr(@strin) ' get serial data if (not strcomp(@strin,@strlast)) emic.say(@strin, true) 'have emic say text serial.str(@strin) ' debug emic.WaitNotBusy ' wait for emic CopyString(@strlast,@strin) ' copy current string emic.WaitNotBusy
The biggest thing I see is that the serial.RxStr command waits for me to send ONE byte and then loops and loops.· Never again waiting for data.· The Serial object is a spin object I downloaded.· But again, I don't see how this should be so vastly different just because I ran it in a cog.
Any ideas?
Shane Merem
www.websiteforge.com
www.magnusoft.com
Comments
I don't have a link to the EMic driver. I suspect the problem is that you're calling the EMic from a cog different from the one it was initialized in. Each cog has a separate set of I/O registers (INA / OUTA / DIRA). Usually the initialization routine sets up the DIRA register and the initial OUTA register. If you try to access those I/O pins from a 2nd cog, they're all set up as inputs and, if you try to set up two cogs so they both try to output to the same I/O pin, one of them will override the other. Any cog that tries to set output mode will override all other cogs that want input mode and any cog that tries to take an output pin high will override all other cogs that try to take the output pin low. In other words, all the DIRA registers are logically or'd together and all the OUTA registers are logically or'd together.
Short version... Writing a program from scratch, I just start with:
long stack1[noparse][[/noparse]200]
If the program fails to run for no obvious reason, I increase the stack space until it works. Not very sophisticated, but it works for me, and does not involve any sort of animal sacrifice as other methods do.
Conversely, if my program works, but it may be included as an object elsewhere, I decrease the stack until the program fails (then increase it just above the threshold) in order to keep the overall project lean.
And Don't Forget F8. Hitting F8 will show you how your memory usage stacks up...
(Also available from the Menu under Run/Compile Current/View Info)
Ned
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"They may have computers, and other weapons of mass destruction." - Janet Reno
NOW -- I can hardly remember a line of Assembly Language. So I am impatiently crashing through everything trying to come up to speed. The spin language definitely helps.
On the stack. I basically did what you said. It was at 9. Bumped it to 30. After adding a constant it crashed again. So bumped it to 40. Works great. I'll probably make it a bit bigger later.
Thanks again.
Shane Merem
www.websiteforge.com
www.magnusoft.com
It was kind of bizarre reading your last post... you are me, except I never did the alarm thing. Fifteen years ago I was working on flight simulators, and now I'm having to re-learn C and learn Spin and Propeller Assembler. Microcontrollers are *so* much more fun and interesting than database work. Basically what I really got into electronics and computers for in the first place!
The important thing to remember about Spin as one of your available tools is that it may run much slower than PASM, but it generates much more compact code, so never discount it as being a crutch to avoid PASM, it has its place. PASM code can run 10 times faster than Spin, but but takes up roughly 8 times the space of the equivalent code in Spin. The reason is that Spin gets compiled down into 8 bit tokens that are run by the Spin interpreter (small code with delay), while PASM compiles down to 32 bit machine code directly (hefty code size, but fast). Fortunately, you can use spin for most of your code, and create PASM code "modules" for parts that really need to be fast.
As for your current project, if you've found a stack size that works, there's no need to make it larger later. There's no dynamic allocation of space, so if it works, it works... don't go back and "fix it".
Ned
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"They may have computers, and other weapons of mass destruction." - Janet Reno
Post Edited (WNed) : 6/29/2009 4:36:59 PM GMT
Like you mentioned. This suff is WAY funner. I went to school for my EE. I'm in Michigan so I found out it's hard to be your own boss in that field (automotive industry was going downhill even 15 years ago -- just nobody noticed).... So I ended up in the computer field to "make a living". I have done well -- but my true love is digital electronics.
From designing and etching my own circuit boards to the programming! It's great!
Thanks again
Shane Merem
www.websiteforge.com
www.magnusoft.com