Shop OBEX P1 Docs P2 Docs Learn Events
Troubles Keeping Time — Parallax Forums

Troubles Keeping Time

francojafrancoja Posts: 10
edited 2007-04-03 19:01 in BASIC Stamp
Hey everyone,

I'm working on building a time sensitive switch; a switch that would turn on and off at specific times specified by user inputs. I'm using the DS1302 timekeeping chip and I ran into a couple problems. I used the first program listed in the AppKit.pdf that was on the online catalog. Using this program I don't have much variable space left for the rest of the program that I have to write.

After I setup the time and date using one program, can I reprogram the Stamp without erasing the DS1302 or is the DS1302 dependent on the Stamp? Can I run the program to initially set the time and date and then run another program that will just take time readings from the DS1302? If so, how?

I'm relatively new to Basic Stamps and the programming language so any help would be appreciated.

Thanks

Comments

  • metron9metron9 Posts: 1,100
    edited 2007-04-02 22:23
    From the pdf file link below

    "A temporary connection to a controller establishes the DS1302’s time. Thereafter, the chip can operate as a stand-alone "



    http://www.google.com/url?sa=t&ct=res&cd=7&url=http://www.parallax.com/dl/docs/prod/appkit/ds1302Rtc.pdf&ei=y4ERRuDuHIz-gwPX6-mAAg&usg=__j3w8kdXdpwFoYbWaPR0_hBkojpc=&sig2=42rVjdVDy9-EfVIyKyxdig

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • francojafrancoja Posts: 10
    edited 2007-04-03 01:16
    Is there a way to setup temporary variables so I can read the time and then over-write the variables for the rest of my program?
  • metron9metron9 Posts: 1,100
    edited 2007-04-03 13:21
    Not sure wat you mean. The stamp has a fixed amount of variable space.
    When you define a variable it simply gives the variable name an address to one of the locations.

    Of course you can overwrite variables.

    Better have a look at the basic stamp help file. Look for "Memory and Variables" in the index. The variable space exists whether you define variables or not.

    You can use the extra space on the time chip for storage

    You can use the program space in the stamp (eeprom) to store variables, see READ, and WRITE commands.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • francojafrancoja Posts: 10
    edited 2007-04-03 16:36
    Reading over my last reply it did dumb. What I want to do is take time readings from the DS1302 in the most efficient manner. I want to take hour, minute, second, etc. readings and then store them as a single variable without having to store each one as a separate variable temporarily and take up much needed space. Can I do that?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-04-03 16:38
    There is no way I know of fitting all the data into a single byte. Even if you were dealing with only minutes it would take two bytes as there are 1440 minutes in a day.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • francojafrancoja Posts: 10
    edited 2007-04-03 16:53
    How do I use the RAM on the DS1302? I read the data sheet and understand how the RAM is used, I just don't know the commands and the language used to do it. Again, I'm new to programming.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-04-03 17:16
    There are application notes (www.parallax.com/dl/docs/books/sw/exp/sw30.pdf and www.parallax.com/dl/docs/prod/appkit/ds1302Rtc.pdf) on the use of the DS1302. All of them talk about mostly access to the time registers. If you look at page 9 (table 2) of the datasheet, you'll see a table showing the layout of the timekeeping registers and the addresses of the registers. If you look at the bottom of the table, you'll see the same kind of layout for the RAM. The timekeeping registers have addresses from $80 to $90 while the RAM is in addresses $C0 to $FD with a read/write bit in the least significant bit of the address. You can use the same routines that you use for reading and writing the timekeeping registers, just with a different address/command byte (see page 6 - figure 4)
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-04-03 17:41
    In the Completed Projects Forum there is a DS1302 Demo Code thread which provides the most details into using the registers on the DS1302. The RAM is explained in detail. Please see the link below. Take care.

    http://forums.parallax.com/showthread.php?p=531080

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • metron9metron9 Posts: 1,100
    edited 2007-04-03 17:43
    You have the cart before the horse so to speak.
    You are looking for the most efficient method to store data but you have not told us how much data you intend to store and what time frame you want to store it.

    How much resolution do you need, to the second, will take 17 bits to store , if you log data for more then 24 hours you need more bits to specify the DAY as well.

    If you were to use a resolution of 2 seconds instead of one you could store 24 hours of data in 2 bytes.
    Taking a fixed amount of readings per day you could store them in an array in eeprom. Each block of x bytes would be a days worth of data so you dont have to store the day.

    If you have variable data you could store one word say $FFFF as a marker between days of data

    So really, one needs to define the data one wants to store before looking for the "best" solution.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-04-03 17:50
    The variables you’re using to store time/date information should give you a clue to how you will need to store this information elsewhere based on how much of it you need.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • francojafrancoja Posts: 10
    edited 2007-04-03 18:01
    Another question, If I'm just interested in reading the day, hours and minutes instead of everything, how do I do that? Below is what I'm using to take time readings now. Any suggestions?

    ReadRTCBurst:
    'Read all time-keeping registers in one burst
    HIGH RTCCS
    SHIFTOUT DTA, Clk, LSBFIRST, [noparse][[/noparse]%1\1,BrstReg\5,%10\2]
    SHIFTIN DTA, Clk, LSBPRE, [noparse][[/noparse]Seconds,Minutes,Hours,Date,Month,Day,Year]
    LOW RTCCS
    RETURN
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-04-03 18:06
    Are those the variables you want to store?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • francojafrancoja Posts: 10
    edited 2007-04-03 18:15
    To answer metron9's question, the resolution in need is 1 minute but i do need to log time longer than 24 hours(actually for a week). I need to keep a log of a week long schedule of on/off times. Since theres 1440 minutes in a day don't i need two bytes for minutes and then one for the day?
  • metron9metron9 Posts: 1,100
    edited 2007-04-03 18:18
    OYou forgot to mention how many data points during the week do you need to store.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • francojafrancoja Posts: 10
    edited 2007-04-03 18:23
    I only need to store the day of the week, the hour and the minute but i only know how to load everything and that is why I'm running out of RAM space. I'm loading all this info that I don't need. Basically, I have hour and minute on/off times for each day off the week. I need to check the current time to see if they match and then when they do I have to switch power to a separate outside system.
  • francojafrancoja Posts: 10
    edited 2007-04-03 18:25
    metron9

    I have a start time and a stop time for each day of the week. So I have 14 hours and minutes I have to store.
  • metron9metron9 Posts: 1,100
    edited 2007-04-03 18:39
    You are not going to store a list of minutes from 0 to 840 per day because that would just be a string of sequential numbers.

    I will try again. How many data points do you need to store during the 840 minutes each day.

    What is it you are storing the time stamp for and how many times does that event happen during the 14 hours each day.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • francojafrancoja Posts: 10
    edited 2007-04-03 18:47
    Oh, I'm sorry I don't I was clear. I have 14 times (7 start and 7 stop times) to store over one week. At the end of the week, it starts over. Is that what you meant by data points?
  • metron9metron9 Posts: 1,100
    edited 2007-04-03 18:48
    I went back up to see your original post. I guess you are not logging events you are just going to have the user input on off times, a simple timer to turn lights on and off?

    How many on / off times do you want the user to be able to inout then?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-04-03 18:53
    If you need on/off times for events based on time from the DS1302 perhaps the following thread will help you out. I posted code I wrote years ago in NY to control my furnace. Essentially a Digital Thermostat it may help you out. Take care.

    http://forums.parallax.com/showthread.php?p=601101

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • metron9metron9 Posts: 1,100
    edited 2007-04-03 18:56
    Yes, so what is the problem then, just store the user data on/off times in eeprom. Poll the time chip and compare it with the list.

    Since the on off times are in the eeprom they will not disapear when power goes off to stamp.

    14 on off times times 7 days is only 98 times 3 bytes is under 300. You have 2047 bytes of eeprom to work with so you can store year,month,day,minute,seconds for that many datapoints.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • francojafrancoja Posts: 10
    edited 2007-04-03 19:01
    Alright, thanks for the help and thanks for putting up with my ignorance.

    I think I'm all set.
Sign In or Register to comment.