Shop OBEX P1 Docs P2 Docs Learn Events
count greater than 65535 — Parallax Forums

count greater than 65535

deszdesz Posts: 2
edited 2009-08-28 23:05 in BASIC Stamp
Is it possible to count above 65535?

Comments

  • jknightandkarrjknightandkarr Posts: 234
    edited 2009-08-17 12:14
    I don't think so, not normally, I'm working on a odometer project & for me I had to use an XXX,YYY.Z Format, Z being 1/10th mile, YYY being 0-999 miles & XXX being 1k to 999K Miles, all saved as separate data locations. This is how I had to do it. However you could use an XXXX,YYYY,ZZZZ format giving you up to 9999 in each data location.

    Joe

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'm going insaine. It's SOOOOOO much fun. lol

    Post Edited (jknightandkarr) : 8/17/2009 12:19:26 PM GMT
  • dev/nulldev/null Posts: 381
    edited 2009-08-17 12:18
    Not without using more variable space. You can have say 10 counters in an array, but you can't do any automatic calculation with them.

    Counter VAR Word(10)
    idx VAR nib
    DO
      Counter(idx) = Counter(idx) + 1
      IF Counter(idx) = 65535 THEN idx = idx + 1
      IF idx = 10 THEN EXIT
    LOOP
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • jknightandkarrjknightandkarr Posts: 234
    edited 2009-08-17 12:32
    Out of curiocity I've been sitting here trying to figure out what that program does, but can't come to what I think is an answer. What does that do?

    Joe

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'm going insaine. It's SOOOOOO much fun. lol
  • Mike GreenMike Green Posts: 23,101
    edited 2009-08-17 16:28
    The best way to figure out something like dev/null's program is to work it out on lined paper or even use a spreadsheet. Each column becomes a variable (or element of an array) so you'd have column 1 for idx and columns 2 through 11 for Counter. The first line is the initial condition which is zero for each. Just do what each statement says in order to make line 2 from line 1. Then start over again with the values in line 2. Once you've got the pattern in mind, you can skip ahead to a boundary condition (where the pattern changes), then continue for a while to see the new pattern.
  • dev/nulldev/null Posts: 381
    edited 2009-08-17 18:48
    That's good advice Mike. The code counts to 65535 10 times. The variable idx tells you how many 65535's you've counted. If you exit the loop at any point, you will know the total count by multiplying idx by 65535 and adding the last counter:
    Total count = Counter(idx-1) + 65535 * (idx -2).

    This might be hard to understand, but it's fairly straight forward.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • dev/nulldev/null Posts: 381
    edited 2009-08-17 18:52
    Just for your information, the Total count procedure can't be done in Stamp Basic. If you want to calculate and use a number larger than 65536 you have to use another computer, like your PC. The reason for this is that the Stamp can only hold 16 bit variable. 65535 is what you get with 2^16.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-08-17 19:36
    Here is an alternative that keeps the counters in a neat easy to read decimal format for DEBUG display. The low counter rolls over at 10000 and the high counter can go up to 65535 for a total count of 655,350,000. At 10 milliseconds per DO:LOOP, it would take about 75 days to count that up.

    counter0 VAR Word
    counter1 VAR Word
    DO
      counter0 = counter0 + 1 // 10000  ' low count rolls over at 10000
      IF counter0 =0 THEN counter1 = counter1 + 1  ' increment high count at rollover
      DEBUG DEC5 counter1,DEC4 counter0,CR   ' display 9 digit result
    LOOP
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • dev/nulldev/null Posts: 381
    edited 2009-08-17 22:40
    As a side-note, if you really need 32-bit variables, you could go for this:
    micromegacorp.com/downloads/documentation/uMFPU-V3%20Basic%20Stamp.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • jknightandkarrjknightandkarr Posts: 234
    edited 2009-08-18 02:42
    This may or may not be on topic, but since the BS2 has 16 pins, 16 bit. Would the BS2P40 be 32 bit? Since it has 32 I/O pins & there for be capable of doing math more then 65535? Up to around 4,294,967,296 which is 2^32. Like I said may or maynot be off topic.

    Joe

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'm going insaine. It's SOOOOOO much fun. lol

    Post Edited (jknightandkarr) : 8/18/2009 2:48:35 AM GMT
  • dev/nulldev/null Posts: 381
    edited 2009-08-18 09:41
    No, the BS2p40 is a 16 bit processor. How many pins you have does not relate to the size of the variables in it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • velociostrichvelociostrich Posts: 40
    edited 2009-08-19 03:44
    dev/null said...
    65535 is what you get with 2^16.

    Correction: 2^16 gets you 65536; there are, however, 65536 numbers that can be stored with a 16-bit variable, if zero is included.
  • dev/nulldev/null Posts: 381
    edited 2009-08-19 06:24
    Thank you for pointing that out.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • vaclav_salvaclav_sal Posts: 451
    edited 2009-08-22 02:56
    It is posible to count up to 655250000.

    http://emesystems.com/BS2math6.htm#counter
  • mechanomechano Posts: 8
    edited 2009-08-23 13:22
    vaclav_sal thanks for your note , this website is wonderful

    i was working on project with BS2 & parallax GPS , the main problem were the values witch are bigger than 65536

    i fininshed the project already with some tricks , but the website is really unbelievable

    i like Parallax forum because of these new notes every day

    thanks to you and to all above how share them knowledge

    regards

    MECHANO
  • hinvhinv Posts: 1,255
    edited 2009-08-28 23:05
    Have you thought about switching to the Propeller? It can handle 32 bits natively (+/- 2 billion roughly).
    It is also incredibly easy to learn and FAST!

    Doug
Sign In or Register to comment.