Cog 1 doesn't want to play
evil_aaronm
Posts: 11
Hi there! New to the Propeller - mine's a Rev A QuickStart - but not new to micros or programming in general, C in particular. I have the following program but, for some reason, Cog 1 doesn't want to participate. I'd expect all 8 cogs to run, but here's the output I get, and the LED for Cog 1 stays dark. Otherwise, this has a nice twinkle effect.
Output:
Started on cog 2
Started on cog 3
Started on cog 4
Started on cog 5
Started on cog 6
Started on cog 7
Started on cog -1
Also, in the on-line example code, the demo stack size is "40 + 25" or 65 bytes. Using trial and error, I found that cogstart() failed (returned -1) for any stack size less than 180. Does this comport with others' experience, or am I doing something wrong?
Thanks for any assistance!
Output:
Started on cog 2
Started on cog 3
Started on cog 4
Started on cog 5
Started on cog 6
Started on cog 7
Started on cog -1
Also, in the on-line example code, the demo stack size is "40 + 25" or 65 bytes. Using trial and error, I found that cogstart() failed (returned -1) for any stack size less than 180. Does this comport with others' experience, or am I doing something wrong?
Thanks for any assistance!
/* Blank Simple Project.c http://learn.parallax.com/propeller-c-tutorials */ #include "simpletools.h" // Include simple tools void cogFlashLight( void * ); int randNum( int upperLimit ) { unsigned long long int c; c = CNT; return( c % upperLimit ); } void cogFlashLight( void *par ) { int led = cogid() + 16; // 16 is the base pin int n; //pause( (led - 16) * 100 ); //printf( "In cogid %d\n", led - 16 ); while ( 1 ) { n = randNum( 10 ); high( led ); pause( (n + 1) * 100 ); // tenths of a second n = randNum( 10 ); low( led ); pause( (n + 1) * 100 ); } } //#define STACKSIZE (40 + 25) //#define STACKSIZE 65 #define STACKSIZE 180 #define COGS 7 unsigned int stack[COGS][STACKSIZE]; //unsigned int stack[STACKSIZE]; int main() // Main function { int i; int n; printf( "%c", CLS ); pause( 500 ); for ( i = 0; i < COGS; i++ ) { n = cogstart( &cogFlashLight, NULL, stack[i], STACKSIZE ); printf( "Started on cog %d\n", n ); } cogFlashLight( NULL ); }
Comments
As for not being able to utilise all 8 cogs, the others may simply be busy/in use by the system. One is certainly used to run your program. Not sure what the second one is used for (could be a driver or runtime support).
As for cog 1, the main program falls into the same LED flashing routine as the others, after kicking them off, so they should all be flashing. When I was testing with just one cog, the "printf's" showed that cog 0 was running the main loop. I've no idea what cog 1 could be doing.
Just had to try this myself. And it works. Could it be a side effect of your stack (mis)management? I don't use any console output which seems to give me 7 other cogs plus the primary one. All of them blinking (QS, CMM).
Eric
There are no extra cogs being started in the background for the code. Parallax Education has insisted that anything added would be obvious. For example, a full-duplex serial can be added with #include "fdserial.h" and fdserial_open(...) if necessary.
We have a winner! I commented out the printfs and all 8 leds are flickering. Thanks, Eric.
This doesn't make any sense. The only way that printf should be using another cog is if you explicitly changed stdio to use FullDuplexserial using the _Device array or if you added fpucog.c to your project.
I did neither, so I don't know. The code above is cut-and-paste. Project options uses CMM Main RAM Compact memory model, Size optimization. Compiler uses 32 bit doubles, all warnings, "-std=c99" options. Linker uses Math lib. Otherwise, it's a completely stock SimpleIDE installation.
The simpletools.h library includes fpucog. When you add printf and enable the math library when using simpletools.h, fpucog gets included in the build. This is normally a good thing if you need floating point. In this case, you don't need the math library. Some of the Simple Workspace examples have Math checked by default which is probably a mistake.
How can you find out this stuff? The SimpleIDE project manager has options like "Show Map File" and "Show Assembly". If you right-click on any project file, you can see the popup menu. The resulting "Show Map File" tells you everything about a successfully compiled and linked program.