Catalina Cog function Help
AndreP
Posts: 5
Hello all,
Im new here and I am also semi-new to the Propeller. So nice to meet you all! Anyways, I have run into a major issue concerning programs compiled from the Catalina C Compiler:
For some reason, my _cogin_C() function appears to run as a regular function (that is, the function runs in line with the rest of the program as any another function would), and whenever that function reaches the end of its execution, the Propeller reboots. The same issue persists even when I attempt to run the demo multiple_cogs.c provided with Catalina.
And its nice to meet you all, again
AndreP
Im new here and I am also semi-new to the Propeller. So nice to meet you all! Anyways, I have run into a major issue concerning programs compiled from the Catalina C Compiler:
For some reason, my _cogin_C() function appears to run as a regular function (that is, the function runs in line with the rest of the program as any another function would), and whenever that function reaches the end of its execution, the Propeller reboots. The same issue persists even when I attempt to run the demo multiple_cogs.c provided with Catalina.
// start instances of ping_function until there are no cogs left do { // added (delay the program enough so that I have enough time to enable the serial monitor) WAIT(20000000*3); cog = _coginit_C(&ping_function, &stacks[STACK_SIZE*(++i)]); // does it get this far? cogsafe_print(cog, "Did the program get this far?\n"); } while (cog >= 0);When I run the program on my Propeller with the above modifications, the only message that appears in the Serial Terminal window is Cog 4 started! If I comment out the while loop in the definition of ping_function(), the Propeller chip reboots. Seeing as the message "Did the program get this far" never appears on the Serial Terminal, I have concluded the _coginit_C() function is not working as it should. Also, it might be worth noting my _clkfreq() always returns 0, but Ive been circumventing the problem by defining the frequency myself. Im using a custom configuration setup which is the configuration given on page 17 of the Web-PropellerManual-v1.2 manual and I have the CUSTOM_DEF.INC file configured to match my clock of 20 MHz. Im at loss as to what my problem might be, so any kind of advice or possible answer to my issue would greatly by appreciated!!
And its nice to meet you all, again
AndreP
Comments
I did this when I started with the propeller as it was a crystal I had around from my Atmel ATTiny experiments. I didnt read the Prop data sheet carefully: A 20MHz crystal is out of spec! My propeller started up but ran unstable, frequency generation with the cog PLLs was 25% off and I couldn't get the serial terminal running. After much head scratching I found the entry in the data sheet, ordered 5.12MHz crystals and all is fine now.
Again, probably not related to your issue but maybe worth a check.
Cheers, ul5255.
Remove the loop and write the equivalent coginit statments in sequence. Add one at a time until it fails.
@Heater.: It always failed after the first one, but I managed to figure out my own issue (and by figure out, I mean I got seriously lucky)...
I wrote a separate program because I didn't want to mess with the multiple_cogs example any more. But basically, the fact that the _clockfreq() wasn't returning the frequency was actually a big issue. After manually checking the clock frequency using a pointer that pointed to the clock's location in the main memory, I learned the clock's frequency wasn't being saved for reasons I still don't know. In the beginning of the this program, I manually changed the clock frequency in memory with a pointer. Not only does the _clockfreq() function works now, but the _coginit_C() works as well. I managed to fix the rebooting issue by simply telling the cog to stop itself with the _cogstop() function. I'm guessing the Propeller chip is supposed to reboot if a cog finishes the execution of its code, but I couldn't find anywhere in the Catalina reference or the Web-PropellerManual-v1.2 manuals that say that.
Problem solved for now, I guess. Thanks everyone (Heater and ut5255, mainly) for the assistance!
No. If a cog is running PASM it has no way to know that it has finished your code. If you do not have a loop it will run off the end of the instructions you have written, continue to execute whatever random junk is in the COG memory and when it gets to the end of memory wrap around and start executing fron zero again.
If you started a COG running Spin code that does not have an endless loop then the interpreter will execute you spin codes until the end of the function and then stop the COG. The rest of the machine continues as normal.
@Heater: Do you have any idea why my Propeller decides to reboot, then? My original problem was fixed after manually inserting the frequency where it needs to be in main memory (though, the fact that I have to do so is another issue in itself). Might my rebooting issue have something to do with my frequency issue?
Sorry not to notice this thread before. Have you sorted out your problem? If not, please post the entire program and I will have a look. The "muliple_cogs.c" program works ok for me on all my platforms (Hydra, C3, Hybrid, TriBladeProp, RamBlade etc).
Possibly you have a problem with your platform configuration. What propeller board are you using, and what version of Catalina are you using? By the way, I have just posted version 3.8 - if you are using the 3.7 beta you may want to upgrade - the beta version had a few issues.
Ross.