Shop OBEX P1 Docs P2 Docs Learn Events
Saving variable space while using the Pocket Watch B — Parallax Forums

Saving variable space while using the Pocket Watch B

bytor95bytor95 Posts: 53
edited 2006-10-13 22:35 in BASIC Stamp
Hi,

I've spent about a year on a tide prediction program using the Pocket Watch B. It wants a byte for mm/dd/yr and hr[noparse]:mn:[/noparse]ss for a total of 6 bytes! I was looking for a way around this using scratchpad ram but realized that as you pass or read a date to the pocket watch, it expects 6 variables so you can't store and retrieve it from ram as it expects separate variables to exist.

I will be shocked if anyone figures out how to save variable space using the pocket watch but if you can point me in the right direction, I'd really appreciate it.

Thanks in advance,

Engin

Comments

  • metron9metron9 Posts: 1,100
    edited 2006-10-13 14:15
    I would like to try but I need more information.


    I read the datasheet on the pocket watch B. It uses 7 bytes as the year is high and low bytes

    How much space do you have and how much space do you need to save?

    The scratchpad ram, is that in the stamp of the device, I don't see any reference to ram or memory in the datasheet on the device.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think outside the BOX!
  • bytor95bytor95 Posts: 53
    edited 2006-10-13 18:25
    metron9

    Thanks for the reply. I need to save about 4 bytes or 2 words so I was looking for a trick to interfacing with the pocket watch. The scratchpad ram is in the basic stamp SX itself. I've used that in order to save on variable space on other projects but it does no good here since the pocket watch is waiting for 6 seperate variables for reading and storing time. I'm hoping that someone can prove me wrong.


    Engin
  • metron9metron9 Posts: 1,100
    edited 2006-10-13 19:30
    I guess I am still a bit perplexed.

    You mean you want to read 6 bytes from the device store it in 4 bytes in basic stamp II ram and convert it on the fly for ss[noparse]:mm:[/noparse]hh DD:MM:YYY format?

    or you want to just be able to send and receive 4 bytes to the device because you don't have 6 bytes of free variable space to work with?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think outside the BOX!
  • bytor95bytor95 Posts: 53
    edited 2006-10-13 20:00
    metron9,

    I don't blame you for being perplexed.

    This is the way I receive (and send) time info to and from the pwb.


    SERIN 9,1021,[noparse][[/noparse]ss,mm,hh,dd,mo,yl,yh] 'READ time from pwb


    Notice that there are 6 variables. I'm just complaining that my program has to have a whopping 6 variables


    ss VAR Byte
    mm VAR Byte
    hh VAR Byte
    dd VAR Byte
    mo VAR byte
    yl VAR Byte
    yh VAR Byte


    in order to read and write to the pocket watch. I was wondering if I could use scratchpad ram to my advantage and only have one variable within the running program so I could save on variable space.

    Engin
  • Larry~Larry~ Posts: 242
    edited 2006-10-13 20:32
    so how many bytes do you need of the six. or do you want all six bytes of info and you want to use less than six bytes of variables. On tracy allen's site there is a julian calender which all varables will fit into a word value and with some work can be extracted back out into your format I think.??

    There is nothing stopping you from using the same varable in another section of program for something different
  • Larry~Larry~ Posts: 242
    edited 2006-10-13 20:39
    this is really confusing me why would you read the time and store it and read it back later as the time would have changed if your making a logging device then a Eprom would store months of data with little or no effort, even xtra program space can be used to store data use the varables as much as you need they don't need to be saved as varables reuse the varables for other data.
  • bytor95bytor95 Posts: 53
    edited 2006-10-13 20:56
    The program is set up to read the time and calculate based on harmonic data of the sun/earth/moon relationship, the tide height.

    So once the user keys in the time, the program loops through like this:

    1) read time from pocket watch
    2) calculate number of hours since January of the year. This is floating point and I'm using the um-fpu coproccesor to handle a number like 8543.2354.
    3) based on the time, calculate height using a sine wave formula.
    4) show height and time on lcd
    5) loop back to 1


    So each time I read from the pocket watch, I have to ask for all 6 variables from the pocket watch (I think). This is my question, how can I get around that without using up 6 variables? It seems to me that it wants to read all 6 values at once. Therein lies my problema.

    Thanks,

    Engin


    smilewinkgrin.gifsmilewinkgrin.gif
  • Vern GranerVern Graner Posts: 337
    edited 2006-10-13 22:15
    bytor95 said...
    Hi,

    I've spent about a year on a tide prediction program using the Pocket Watch B. It wants a byte for mm/dd/yr and hr[noparse]:mn:[/noparse]ss for a total of 6 bytes! I was looking for a way around this using scratchpad ram but realized that as you pass or read a date to the pocket watch, it expects 6 variables so you can't store and retrieve it from ram as it expects separate variables to exist.

    I will be shocked if anyone figures out how to save variable space using the pocket watch but if you can point me in the right direction, I'd really appreciate it.

    Thanks in advance,

    Engin

    If you're hurting for Variable space, you might want to reduce some of the byte variables to nibbles, i.e.

    ss VAR Byte
    mm VAR Byte
    hh VAR Byte
    dd VAR Byte
    mo VAR Nib ' max value for mo would be 12
    yl VAR Nib ' this will work till 2015, then you have to use a byte again :)
    yh VAR Byte
    
    



    this saves 1 byte of space...? Of course, with the yl value maxing out at 15, you would have to update the firmware for all your customers by 2015.. of course, by then you would have the entire project ported to Spin, right? wink.gif

    Vern

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Vern Graner CNE/CNA/SSE    | "If the network is down, then you're
    Senior Systems Engineer    | obviously incompetent so why are we
    Texas Information Services | paying you? Of course,if the network
    http://www.txis.com        | is up, then we obviously don't need
    Austin Office 512 328-8947 | you, so why are we paying you?" ©VLG
    
    
  • Vern GranerVern Graner Posts: 337
    edited 2006-10-13 22:35
    bytor95 said...
    The program is set up to read the time and calculate based on harmonic data of the sun/earth/moon relationship, the tide height.

    So once the user keys in the time, the program loops through like this:

    1) read time from pocket watch
    2) calculate number of hours since January of the year. This is floating point and I'm using the um-fpu coproccesor to handle a number like 8543.2354.
    3) based on the time, calculate height using a sine wave formula.
    4) show height and time on lcd
    5) loop back to 1

    So each time I read from the pocket watch, I have to ask for all 6 variables from the pocket watch (I think). This is my question, how can I get around that without using up 6 variables? It seems to me that it wants to read all 6 values at once. Therein lies my problema.

    Ok, based on this description, it appears you are not using the year in your calculations, or the year is assumed to be the year in which the person is entering data? If this is the case, you could use a "disposable" variable to "catch" the data you dont need. i.e. :

      SS  VAR  Byte  'Seconds
      MM  VAR  Byte  'Minutes
      HH  VAR  Byte  'Hours
      DD  VAR  Byte  'Days
      MO  VAR  Nib   'Months
      YL  CON  06    'Year Low (i.e. "05" in 2005)
      YH  CON  20    'Year High (i.e. "20" in 2005)
      temp VAR Byte 'use any variable that is disposable in your program like a counter or somesuch
    
    'Get time from PWB:
      SEROUT ToPWB, PWBBaud, [noparse][[/noparse]$55,$12]  'send request for time
      SERIN FromPWB, PWBBaud, 100, nodat, [noparse][[/noparse]ss,mm,hh,dd,mo,temp,temp] 
      nodat:
    
    



    So this saves what 2.5 bytes or so? If you can make assumptions about other unneeded data, for example, the # of seconds you can save a bit more like this :

      SS  CON  00  'Seconds
      MM  VAR  Byte  'Minutes
      HH  VAR  Byte  'Hours
      DD  VAR  Byte  'Days
      MO  VAR  Nib   'Months
      YL  CON  06    'Year Low (i.e. "05" in 2005)
      YH  CON  20    'Year High (i.e. "20" in 2005)
      temp VAR Byte 'use any variable that is disposable in your program like a counter or somesuch
    
    'Get time from PWB:
      SEROUT ToPWB, PWBBaud, [noparse][[/noparse]$55,$12]  'send request for time
      SERIN FromPWB, PWBBaud, 100, nodat, [noparse][[/noparse]temp,mm,hh,dd,mo,temp,temp] 
      nodat:
    
    



    So now we've saved 3.5 bytes? smile.gif hope this helps...

    Vern

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Vern Graner CNE/CNA/SSE    | "If the network is down, then you're
    Senior Systems Engineer    | obviously incompetent so why are we
    Texas Information Services | paying you? Of course,if the network
    http://www.txis.com        | is up, then we obviously don't need
    Austin Office 512 328-8947 | you, so why are we paying you?" ©VLG
    
    

    Post Edited (Vern) : 10/15/2006 5:13:48 PM GMT
Sign In or Register to comment.