Shop OBEX P1 Docs P2 Docs Learn Events
Can you use two DS1302 with a Basic Stamp ----->>>> Solved — Parallax Forums

Can you use two DS1302 with a Basic Stamp ----->>>> Solved

sam_sam_samsam_sam_sam Posts: 2,286
edited 2008-12-03 02:19 in General Discussion
Hi Every One

If this can be done how would you

I would like to use Elapsed Timer on one DS1302

I would·like to use DS1302_Counter timer on·other ·

Can any pins be shared

(one)·· How would you·hook up the two DS1302

(two)·· How would set up the time keeping part of the routine too switch from elapsed timer to regular timer

The regular (counter timer)·timer would be the one in the back ground this would keep track of the total amount of elapsed
··

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·idea.gif·that you may have and all of your time finding them

·
·
·
·
Sam

Post Edited (sam_sam_sam) : 12/6/2008 2:16:47 PM GMT

Comments

  • CapdiamontCapdiamont Posts: 218
    edited 2008-10-19 06:20
    I'm unclear why you want to use two ds1302 chips. DS1302 is a time keeping chip. What I would do is use the extra 7 bytes in the chip to store the start time, then calculate the difference between the stored time and the current time read from the chip.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-10-19 11:51
    I'm unclear why you want to use two ds1302 chips. DS1302 is a time keeping chip

    Thank You for your reply

    I need to run one time chip all the time and stop and start the other time chip

    For something·I working on the·Elapsed Timer routine that·I wrote a few month ago·now·I want to·also have a running timer that keep track of total Elapsed Time

    Here is the link to this Project

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

    What I would do is use the extra 7 bytes in the chip to store the start time, then calculate the difference between the stored time and the current time read from the chip

    Could you give an example of how to do this

    __________________________________________________________________________________________________

    ·Thanks for any·idea.gif·that you may have and all of your time finding them

    Sam

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 10/19/2008 12:10:21 PM GMT
  • CapdiamontCapdiamont Posts: 218
    edited 2008-10-19 15:32
    How long of time are you measuring?

    Looks like your application is to measure your on time for your HVAC unit over X amount of time. Also looks like your using a BS2.

    Maybe we are thinking too complicated. Do you really need the DS1302? Do you have power outages? If not power outages and not needing a highly accurate time base, you can do everything in the stamps RAM. Just remember one thing, there is tons of ways to do things.

    the following is not code that will work, just a thought process.
    Startup:
    Make all ram values = 0, also all bytes, gives you up to 255 on each
    I figure only 8 bytes are being used, and can add another 4 bytes for when your water sprayer is on. +-)



    Main: 'for when not on, only update total elapsed time
    If Pump is On gosub onmode 'start measuring on time
    PAUSE 1000 ' wait 1 second
    gosub AddTotal 'add to total time
    gosub UpdateDisplay 'refresh display
    Goto Main

    AddTotal: '
    TSec=TSec + 1 'add one to total on seconds
    IF TSec>=60 Then 'if seconds is equal to or over 60 add one to minute, and reset seconds
    TMin=TMin+1
    TSec=0
    ENDIF
    IF Tmin>=60 Then
    THour=THour+1
    Tmin=0
    ENDIF
    IF THour>=24 Then
    TDay=TDay+1 'note if allowed to run over 255 days it will get reset to 0, or error out. Can make this a word type variable for over 60k days.
    THour=0
    ENDIF
    RETURN

    OnMode:
    Do until Pump = 0 'keep looping until pump is turned off
    Pause 1000 'wait one second
    OSec=OSec + 1 'add one to "on" seconds
    IF OSec>=60 Then 'if seconds is equal to or over 60 add one to minute, and reset seconds
    OMin=OMin+1
    OSec=0
    ENDIF
    IF OMin>=60 Then
    OHour=OHour+1
    OMin=0
    ENDIF
    IF THour>=24 Then
    ODay=ODay+1 'note if allowed to run over 255 days it will get reset to 0, or error out. Can make this a word type variable for over 60k days.
    OHour=0
    ENDIF
    gosub AddTotal 'add to total time
    gosub UpdateDisplay 'refresh display
    Loop
    Return

    UpdateDisplay:
    Add code here to scroll through info needed.
    Return
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-10-20 00:33
    Capdiamont

    Thank You for your reply

    A few thing

    (One)·I will not be controling any thing except for·the DS1302 with the Basic Stamp
    (Two) I am needing· a highly accurate Time Base

    With the elapsed timer routine that·I wrote it work very well

    What the problem is that I need to keep track of how long the timer has been running·from the last time it was start to next time i want to reset the timer


    Here is what I want to

    ONE
    ·Keep track of running time of AC unit when compresor is running
    Two
    ·How many restarts there are

    These two I have already done· I need to do the last one and get it to work if there is a way to to do this

    Three
    How many Months, Day, Hours and Minutes have Elapsed Time has gone by when the timer was start

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-10-21 22:12
    I have only had one project that used two DS1302 chips. I don’t have it together right now because it was a concept (built on the PDB). However the basic idea is that you could have 10 of these if you wanted. As I covered in my Binary Digital Clock project, I demonstrated that you can connect multiple SPI devices using the same clock and data pins and simply adding one chip select pin per package. The DS1302 was used in that project with a DS1620, three 74HC595 and a MAX7219. All of these chips use an SPI interface and all had common clock and data lines. I would check it out. It is posted in the sticky thread in the Completed Projects Forum.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-11-28 14:14
    Do you have to use a different routine for each DS1302 Chip
    The reason I am asking is I want to display both DS1302 Chips Time on an LCD Display

    Also do you have to use different "VAR" "CON" and also SUB Rountine for each DS1302 Chip


    RTC_Out:
    · HIGH CS1302··························
    · SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]reg, ioByte]
    · LOW CS1302···························
    · RETURN

    RTC_In:
    · HIGH CS1302··························
    · SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]reg]
    · SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]ioByte]
    · LOW CS1302···························
    · RETURN

    Set_Time:······························
    · HIGH CS1302··························
    · SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]WrBurst]
    · SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]secs, mins, hrs,
    date, month, day, year, 0]
    · LOW CS1302···························
    · RETURN

    Get_Time:······························
    · HIGH CS1302···························
    · SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]RdBurst]
    · SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]secs, mins, hrs, date, month, day, year]
    · LOW CS1302····························
    · RETURN



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 11/28/2008 2:23:43 PM GMT
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-11-28 14:30
    Sam -

    I'm not all that familiar with the DS1302, but you would need to have a SELECT or ENABLE line in order to address each chip separately. Otherwise you will have contention on the DATA and CLOCK lines.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When all else fails, try inserting a new battery.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-11-29 03:38
    Chris

    Thank You for your reply but

    The reason I am asking is I want to display both DS1302 Chips Times on an LCD Display at the same
    I know that the stamp can only one thing at a time

    I have to ask a·question·and it this

    As I have below in a post where I ask about·do you have to have different·VAR and CON and SUB Routine for each DS1302 Chip

    RTC_Out:
    RTC_Out1:·········· and so on for each routine

    All of these chips use an SPI interface and all had common clock and data lines.

    I understand the part about·sharing the Clock and Data Line


    Bruce Bates

    Thank You for your reply

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 11/29/2008 2:20:45 PM GMT
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-11-29 14:58
    Look at the Attachment below this what i have so far

    Can one tell me if I am on the right track or not

    I am working on a dual DS1302 Chip board today so i can not try it now to see if it will work

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-11-29 16:51
    sam -

    Unless I've overlooked something, you need a second set of variables for the elapsed time timer. Take a look:

    Get_Time: ' DS1302 Burst Read
    HIGH Timer ' Select DS1302
    SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]RdBurst]
    SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]secs, mins, hrs, date, month, day, year] <==
    LOW Timer ' Deselect DS1302
    PAUSE 100
    HIGH ElapsTimer ' Select DS1302
    SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]RdBurst]
    SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]secs, mins, hrs, date, month, day, year] <==
    LOW ElapsTimer
    RETURN

    The second fetch of information will clobber the first, presuming you wanted to keep the elapsed time data separate from the regular timer data.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When all else fails, try inserting a new battery.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-11-29 17:32
    Bruce Bates

    Thank You for point this out to me

    The second fetch of information will clobber the first, presuming you wanted to keep the elapsed time data separate from the regular timer data.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • kelvin jameskelvin james Posts: 531
    edited 2008-11-29 20:18
    You could use the same variables, but they would have to be zeroed after each read / lcd display of the selected timer. Not fully understanding the concept of the total operation, if there is time data you need to keep for reference, you could just write the data to eeprom, and go back and check it when needed, it will always be there.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-11-30 17:04
    If you're doing nothing but displayed the values to an LCD you can use the same variables. You fetch and display then fetch and display again, rinse and repeat. Now, if you actually need to compare any of the information then you will need a whole new set of variable to handle this. Take care.

    P.S. - As a note...the project I mentioned that had two DS1302 chips was because I wanted one to have the time, and use the other as a counter. Later I consolidated the project by simply incrementing or decrementing a counter variable whenever the seconds changed. It only required two variables and got rid of the second DS1302.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-11-30 20:26
    Chris

    Thank You for your reply

    This is just what·I want to do·what you have here

    ·Now, if you actually need to compare any of the information then you will need a whole new set of variable to handle this. Take care.

    Can you share the code for this

    I wanted one to have the time, and use the other as a counter. Later I consolidated the project by simply incrementing or decrementing a counter variable whenever the seconds changed. It only required two variables and got rid of the second DS1302.





    I want one timer to run all the time and the other timer to run when the equipment is running

    Here is· what·I came up with in the Attachement below

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-12-01 22:59
    Sam,

    When I needed a separate counter from the time I just used the program loop to increment (or decrement) the counter variable each time the seconds changed. For example, say you have the DS1302 set and running with the current time. Whatever it is doing its seconds are always updating. So now you need to run a timer…maybe it needs to count up until an event happens. So here’s some pseudo-code…

    [color=#000000]Count_Loop:[/color]
    [color=#000000]   GOSUB Check_Event   &#8216;Here&#8217;s where you&#8217;d look for whatever stops the counting.[/color]
    [color=#000000]   IF event THEN GOTO Target_Label &#8216;your event happened, so stop counting[/color]
    [color=#000000]   GOSUB Get_Time[/color]
    [color=#000000]   IF seconds = oldSeconds THEN Count_Loop[/color]
    [color=#000000]   oldSeconds = seconds   &#8216;reset compare[/color]
    [color=#000000]   counter = counter + 1    &#8216;This might be a word variable holding the count.[/color]
    [color=#000000]   GOSUB Display_Count &#8216; Maybe you&#8217;re displaying the counter on an LCD?[/color]
    [color=#000000]   GOTO Count_Loop[/color]
    
    

    Of course, you will want to reset the counter on entry and there are several other little details missing, such as the specifics of each subroutine.· But this all depends on the application.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-12-03 02:19
    Chris

    Thanks for the··pseudo-code…· very help full

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
Sign In or Register to comment.