Is there a limit to local longs? Strange behavior when I initialize some local longs.
turbosupra
Posts: 1,088
I have code with a bunch of local longs and I was testing to see if there was a limit to that.
When I do not comment out some of the initializations of the local longs, it appears that it hoses the repeat loop or maybe its timing.
When I comment out lines 189-197, the loop then works. Can anyone please explain why this is occurring for my own learning? I have pin 4 feeding pin 5 through a 100ohm resistor.
I can't attach the code to the forum because of the work firewall, but I can place it here. As a warning, the code is not cleaned up, things are commented out everywhere and normally I would try and clean it up a bit, but since this is such an oddball issue, I wanted to present it as is.
http://turbosupra.herobo.com/hosting/seq.zip
Thanks for reading.
When I do not comment out some of the initializations of the local longs, it appears that it hoses the repeat loop or maybe its timing.
When I comment out lines 189-197, the loop then works. Can anyone please explain why this is occurring for my own learning? I have pin 4 feeding pin 5 through a 100ohm resistor.
I can't attach the code to the forum because of the work firewall, but I can place it here. As a warning, the code is not cleaned up, things are commented out everywhere and normally I would try and clean it up a bit, but since this is such an oddball issue, I wanted to present it as is.
http://turbosupra.herobo.com/hosting/seq.zip
Thanks for reading.
Comments
Potentially there might also be a limit, as SPIN might use a byte offset for referencing local variables?! Not sure if I remember having heared something like that ;o)
But in general it's a bad idea to code the propeller in the same way that you'd code a PC. Using to many local variables should simply be avoided.
Can't access your ZIP file because of firewall settings here. Your hoster seems to be on our "NoNo"-list ;o)
@Duane:
Why do they have to be initialized to zero? What if zero does not make sense? Hopefully it can be reassigned to other values after initialization! ;oP
I agree. They also don't show up as using the correct amount of memory when you press "F8".
I did not know that. Now I will have to recheck all my source for errors. What a bummer.
I think that's common to most kind of stacks. It's only that other compilers will give you at least a warning that your variable has not been initialized. But I think this is a kind of a problem you would not be aware of even if it's describes somewhere in the manual. Some things you have to find out the hard way ;o)
;oP ;oP ;oP
As you know, when the "not initilized" thing is a problem it's because the programmer is expecting the values to equal zero as global variables do.
And yes, they can be initialized to anything you want (as long as it fits in a long). Germans!!
I think I should be the only one allowed to purposefully misinterpret a post.
Before making my post, I checked the Propeller Manual for PUB, and sure enough it stated that local variables had a random value.
I normally initialize locals with values, but I may have taken it for granted in a few instances.
Bruce
I am not sure whether to thank you or curse you for that info.
I think I will thank you.
Bruce
Can I email it to you instead?
You can and then I'll post it for you.
My email is my first initial followed by my last name (five letters total so far) at abreviation for Micro Soft Network dot com.
I have increased the stack size of the other cog calls and because they weren't related to the main cog that didn't make a difference I guess, could it be local cog ram related?
Also, this is in the main cog, so is there a way to hard code the amount of stack size for that?
The cog ram only has the Spin interpreter in it (unless you're running PASM code). The interpreter runs the code from hub and sets aside "stack" space for that cog in the hub (how could that be confusing?).
I was initializing all local variables originally. When I started to comment out some of those initializations in "main" before entering the repeat loop in "main", the code started working??? (backwards I know) I spent 6 hours messing around with it yesterday before I even got to that point of figuring that out. Since this is so bassackwards, I had to post about it and find out for my own sanity why this was happening and to avoid it.
It may be because I have so many local variables and if there is a ceiling on that, I would just like to know?
Did you receive my email? I guessed at the abbreviation as msn.com ?
Sorry, day job got in the way.
It will be a while before I can look at it.
Thanks for attaching.
You might want to break them into several lines like this.
The problem still exists after doing that, but that makes readability much much easier.
So although there may be a local variable limit based on the main cogs stack, I don't believe that was my issue after this testing procedures results
The mystery continues ...
Program - 1023 longs
Variable - 437 longs
Stack/Free - 6728 longs
I am not using graphics.spin
I am using
Unless... Are you calling that routine with a lot of local vars recursively?
If these things happen when commenting code you maybe have a problem with race conditions. For example several code-pieces running in different COGs use the same variable one has to write the other reads and does calculations with the read value. In these circumstances such problems might occur if the writer code did not run in time.
It could also be related to the cognew which needs some time to start up the code.
Cog sends frequency out pin 4, jm_freqin reads frequency on pin 5, main cog polls jm_freqin.period method every so often for value and calculates data
This could be the race condition you describe, but would it continually loop over and over, or would it only 0 out in some cases?
Do I need to copy the value before performing calculations on it? How do you eliminate the possibility of a race condition?
1. You seem to work with timings in several areas of your program. But on the other hand you are very generous with usage of PST. But PST has a buffer of 64 bytes. So, when you extend the number of characters send this will slow down your whole program and the conversions will be done in the COG calling the PST functions anyway. So, I'd suggest to think about a debugger/logger COG which runs independently.
2. Chances are high, that these kind of if-statements don't do what you expect
if(cnt > (timeStamp + (clkfreq/l_updateRateDenominator)))
The problem is that the > operation is working with signed numbers. So, from $0000_0000 - $7fff_ffff it will see a positive number and from $ffff_ffff-$8000_0000 it will see negative numbers. In other words for the > operator $0000_0000 will be bigger than $8000_0000.
If you work with a difference you don't have this problem:
if((cnt-timeStamp) > (clkfreq/l_updateRateDenominator))