PDA

View Full Version : Cog shutdown?



mosquito56
01-23-2008, 01:37 PM
If I load a module in a cog that is only a called·subroutine, does the cog continue to count phsa,b etc or does the cog shut down somehow?

·When I put:
·repeat
·· call subroutine· ' the counter works
··························'take the repeat out and only use the main to call the subroutine it doesn't work.



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
······· "What do you mean, it doesn't have any tubes?"

······· "No such thing as a dumb question" unless it's on the internet

Technologically challenged individual, Please have pity.

Beau Schwabe
01-23-2008, 01:48 PM
Can you post more of your code?

When you 'call subroutine' is this a new cog?
What if you place a delay before calling your subroutine?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

Mike Green
01-23-2008, 02:35 PM
mosquito56,
The only way to start up a new cog is to use COGNEW or COGINIT, either directly or indirectly (by calling a subroutine that uses one of those statements). Not all objects start new cogs. Some of them are just objects (collections of subroutines and data).

When you start up a new cog, that cog has its own special registers including the counters. The original cog continues to run and its counters continue to do whatever they're set up to do. In multiprocessing parlance, the COGNEW or COGINIT acts as a fork operation.

mosquito56
01-23-2008, 10:58 PM
O.K. here is the code....
It uses phsa and phsb to send count every second depending on freqa setting. When phsa rolls over phsb counts up one. The idea is to have a timer that keeps track of how long the chip is on without tieing up a cog.

·1. start timerb in cog 2
·2. Main program just prints value of phsb

Problem. If you remove the "repeat" in timerb it won't work but it should· if the counters in cog 2 are running.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
······· "What do you mean, it doesn't have any tubes?"

······· "No such thing as a dumb question" unless it's on the internet

Technologically challenged individual, Please have pity.

Mike Green
01-24-2008, 03:16 AM
When a cog is started with a Spin method call, a dummy return address gets pushed on to the new stack. If the Spin method ever returns, it's to a COGSTOP for that cog. If your main method "falls through" to its end, it returns, causing the cog to stop itself which disables the cog's counters. You need a REPEAT at the end of that main method to prevent the cog from stopping itself. If you want to save power, you could put a WAITCNT in the REPEAT loop, but the method can't be allowed to exit until you no longer need the cog counters.

mosquito56
01-24-2008, 03:40 AM
·Thanx, I suspected that the cog was stopping for some reason. I put the "repeat" at the end of the timerb and it does nothing. I have never·used it at the end before··but it's a moot point as I will be putting more code in the upper loop eventually anyway. It does what I wanted so I can live with it as is.

· Since the manual gives the impression that all cogs get there own ticks, then does this mean that a program with only 2 cogs running goes faster than one with 8 cogs running all else being equal?



Appreciate the help. Thanx

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
······· "What do you mean, it doesn't have any tubes?"

······· "No such thing as a dumb question" unless it's on the internet

Technologically challenged individual, Please have pity.

Mike Green
01-24-2008, 03:50 AM
The cogs all run at full speed, every clock tick unless they're stopped or waiting for something like an I/O pin or a specific time to occur or they're waiting for their turn at access to hub memory. It doesn't matter how many are running. That only affects the power requirement of the chip.

mosquito56
01-24-2008, 04:29 AM
O.K. seems like a contradiction. If no code in cog to run, cog shuts down, counters stop but still uses a tick anyway? Seems a little strange. Also, If counters are running in cog, wouldn't it be better for them to continue running?

·Just a note for the next prop? Hmm. Thanx for the help, I think you've more than answered my questions.

Have a propping Day

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
······· "What do you mean, it doesn't have any tubes?"

······· "No such thing as a dumb question" unless it's on the internet

Technologically challenged individual, Please have pity.

Mike Green
01-24-2008, 05:31 AM
Actually, you want it to work this way. There isn't the notion of "using a tick". There's nothing to "use". The cogs just run full speed unless they're stopped or a program is waiting for something to occur. The counters are stopped because a reset is defined as a low power state where nothing unnecessary is running. The counters can be the fastest circuitry on the chip running at up to 160MHz. Their power consumption goes up roughly as the square of their switching speed. You really want them off unless you're using them for something.

mosquito56
01-24-2008, 07:00 AM
·I guess I just don't get how the chip works. I was under the impression that each cog got a "tick" and can run 2 or 4 instructions.· Assuming all 8 cogs are doing the same thing, then only running 4 cogs would be twice as fast or the same speed? If the same speed then the cogs are getting their "ticks".

Not really sure I need this much input or really want to get this deep. I spent 4 days trying to get the code to work.

I tried the idea of seting pin 18 hi when ctra rolled over and checking in main module if pin is hi. If hi add to time and turn off pin. Never got it to work. Problably something to do with switching dira's .

Here the idea: I guess this is what you had in mind.

Cog 0 runs

·cog 1 turn on light every second

cog 0 sees light and adds to timer and turns light off.

· I could get the light on, but never off.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
······· "What do you mean, it doesn't have any tubes?"

······· "No such thing as a dumb question" unless it's on the internet

Technologically challenged individual, Please have pity.

Mike Green
01-24-2008, 07:25 AM
Ah! When you're referring to "ticks", you're really talking about hub memory access. As I mentioned, all of the cogs that are running do a cycle every system clock and it usually takes 4 system clocks to do an instruction. When a cog attempts to access the shared "hub" memory, it only gets one access per 16 system clocks and it's forced to wait until its "slot" comes up. There's time in this 16 system clock cycle for the hub access plus two instructions (8 system clocks) plus a little left over. If the cog misses its slot, it has to wait until its next one comes up.

mosquito56
01-24-2008, 10:51 PM
Ok. Getting a little clearer. Can different cogs be setup to run at different speed by changing· the pll timer? Everytime I d/l a module it has the clock freq setup. It seems a waste of memory albiet a small bit of memory but can I remove all of these statements from sub modules or can each cog run at a different speed?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
······· "What do you mean, it doesn't have any tubes?"

······· "No such thing as a dumb question" unless it's on the internet

Technologically challenged individual, Please have pity.

Mike Green
01-25-2008, 12:51 AM
The system clock is global. It applies to all cogs. The _CLKFREQ / _CLKMODE / _XINFREQ values in the "main" object are the ones that stored in the RAM / EEPROM image. If they're in a sub-object, they're ignored and don't take up any memory. _CLKFREQ is stored as a long in location 0-3 and _CLKMODE is used to construct a CLKMODE value which is stored as a byte in location 4. If you specify _XINFREQ instead of _CLKFREQ, the compiler computes the CLKFREQ value from that and _CLKMODE.

If you don't supply these values, the compiler uses RCFAST as the default with CLKFREQ as 12MHz (which is approximate for this internal clock).

mosquito56
01-25-2008, 07:17 AM
O.K. thanx again for the clearup. Nice to know I don't have to comment those lines out and can just leave the clkfreq alone.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
······· "What do you mean, it doesn't have any tubes?"

······· "No such thing as a dumb question" unless it's on the internet

Technologically challenged individual, Please have pity.