Page 1 of 1

counting with uLong numbers

Posted: Tue May 22, 2012 4:17 am
by brandonb
i have a project that i want to count higher numbers than 65535, the next level is ulong which counts over 4 billion numbers, if i count at a 1khz frequency will there be any issues? it seems a bit insane, how many registers does it take to be able to count to 4.2 billion anyway, 4 registers isnt it (256x256x256x256)? .....question two, in program i have a commanded count in a 16 bit uint variable that goes to 65535, i have the screen to show "error" with numbers above 32767, can i command a number with a 16 bit integer using numbers below 65535 but compare the accumulated count using a 32 bit number in the 16 bit range? reason why i need a 32 bit number is because in another menu option i free count numbers, then save the number and data into memory to later recall the data to recreate that menu options tests, this number can go into the 100,000 ranges.... i hope you guys can make sense out of the way its written since the flowchart is too big to post

Re: counting with uLong numbers

Posted: Tue May 22, 2012 10:07 am
by Benj
Hello,
if i count at a 1khz frequency will there be any issues?
No I don't see why there would be any as long as your micro is running fast enough to keep up.
4 registers isnt it (256x256x256x256)?
Yep the long variable type consumes 4 bytes in memory.
can i command a number with a 16 bit integer using numbers below 65535 but compare the accumulated count using a 32 bit number in the 16 bit range?
Yes you should be able to shift the long variable so that it falls back within the 16-bit range.

checkvar = longvar >> 16

Re: counting with uLong numbers

Posted: Thu May 24, 2012 12:32 am
by brandonb
thanks ben overlooked a detail, had to use 32 bit for all counting pids, works great at 150k counts with 484hz the freq is uneffected