How Would you count a greater value than 65535 Please give a very simple examp
sam_sam_sam
Posts: 2,286
·I know that this question is very simple for most of you but..........
I·know that with P Basic you would
do this to count
count = count + 1
and you only count 65535 and then it would roll over
and have· another counter start when the first one got to 65534 then start your next counter
The only thing that I have done with the Propeller is the few being example when this chip first came out I would like to learn more about programing this chip as well
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
I·know that with P Basic you would
do this to count
count = count + 1
and you only count 65535 and then it would roll over
and have· another counter start when the first one got to 65534 then start your next counter
The only thing that I have done with the Propeller is the few being example when this chip first came out I would like to learn more about programing this chip as well
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Comments
The propeller won't roll over until you get to 4294967295 as it counts in 32 bits natively rather than 16. Just declare your counter variables as LONG rather than WORD or BYTE.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lt's not particularly silly, is it?
or this:
or this:
or this:
All this variations increment the variable count by 1. If count is a long-variable (=32 Bit) , then you can count up to 2_147_483_647, then the value rolls over to -2_147_483_648 (That is because SPIN handles longs as signed variables).
If you need to count higher then use more than 1 variable and count the roll-overs in a second count variable:
this can also be written like this:
Andy
if not (++count)
counthiword ++
This works for both signed and unsigned numbers, as long as you treat counthiword as the 2's complement extension of count. This works by (1) incrementing count, (2) logical NOT converts any nonzero value to zero and only zero to -1, and if it's -1 (3) carries to the hiword.
Saves you a not operation.
Arida
Can·you help little more with this in explain what is the different between each one that you have here in the way that it would count
or this:
or this:
or this:
or this
·localroger and mpark
··············· if not (++count)
··············· counthiword ++
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 8/31/2009 11:54:10 PM GMT
What the ifnot thingie does is it checks to see if the result of the ++count is zero, which means it has rolled over; just as if you are adding in a one-digit decimal register and you get 7, 8, 9, 0 ... that 0 means there should be a 1 added to the tens. So by checking ++count for zero we are asking, did we just roll over? And if the answer is yes, we add 1 to the next higher "digit." That gives you 64 bit counts (and more if you extend the idea). And that can be a useful thing when the CNT register overflows after 2 minutes or so at 80 MHz.
Thank you for exlplaine this to me that helps a Lot·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam