Shop OBEX P1 Docs P2 Docs Learn Events
DS1302 Is there a way to keep track of the timer if it is running — Parallax Forums

DS1302 Is there a way to keep track of the timer if it is running

sam_sam_samsam_sam_sam Posts: 2,286
edited 2006-07-07 03:36 in BASIC Stamp
Hi, Everyone

I am still working on this DS1302 project
I need some help with this problem that i have

When i was taking the project board and putting it in the case one of the wires
on DS1302 chip broke loose and i did not see that it had broken loose

So the power relay came ON like it was supost to but the clock was not running

So the way i had code writen in CARD_READER_TIMER.bs2 it would turn ON the Relay
if the clock was NOT RUNNING

'So i add this line so that if the DS1302 is not running it will not turn ON the Relay At START UP
IF mins = $00 AND secs =$05 THEN
HIGH Relay

What i want to know is there a way to keep track of the timer and if it STOPS RUNNING that
it turns OFF the RELAY

Can this be done and if it can be done how would you write the the code routine
Thanks to anyone that can help with this


Routine1:
mins=$00
secs=$00
GOSUB Set_Time

IF mins = $00 AND secs =$05 THEN 'So add this line
HIGH Relay

DO
GOSUB Get_Time
IF mins=$15 AND secs=$00 THEN EXIT
LOOP
LOW Relay
GOTO Start

Sam

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-07-01 18:22
    · I guess, sam_sam_sam, that you know how to get the time from the DS1302 (I don't.)· My assumption is that it provides Seconds.· So, if you get the time for it and the Seconds is X, then·1 Second later, if the clock is running, then Seconds should be X + 1, and another Second later it ought to be X + 2 (or X + 1 + 1).

    · So, you need to read the Seconds and store that in a variable (sec_1) and then get the seconds, again,·a second or two later and store that in another variable (sec_2).·

    · At this point, if sec_1 = sec_2 then the clock must not be running.

    · Y / N ?
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2006-07-02 00:02
    PJ Allen

    I understand what you are saying but how do you store the secs and then used them to
    check to see·if clock is running
    I·have tried alot of thing but i can not get this to work

    Can any one help understand how to do this

    Thanks For any help that you can give me on this
    Or any one else that can help

    San···· idea.gif····· smile.gif
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-07-02 00:47
    OK, well I read over the DS1302 AppMod docs somewhat, and if you are using the program in that as a template (VARs, etc.), then here is one way to go:
    Clk_OK:                             'readRTCburst
      HIGH RTCReset
      SHIFTOUT DTA,Clk,LSBPRE,[noparse][[/noparse]sec_1]   'get seconds
      LOW RTCReset
      PAUSE 1200                        'pause for 1.2 seconds
      HIGH RTCReset                     
      SHIFTOUT DTA,Clk,LSBPRE,[noparse][[/noparse]sec_2]   'get seconds again
      LOW RTCReset
      
    IF sec_1 = sec_2 THEN Clk_kaput
    GOTO Clk_OK                         'go elsewhere or GOSUB
    
    Clk_kaput:
     'turn off relay or whatever
    

    Post Edited (PJ Allen) : 7/2/2006 12:56:09 AM GMT
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2006-07-02 04:08
    PJ Allen

    Thanks PJ Allen you help ME lot by what you put in your POST

    It was not completly right but i could work with it and get it to work

    Thank You So much for helping understand how to get this to work

    Start:

    mins = $00

    secs = $00

    laps = 00

    GOSUB Set_Time

    DO

    GOSUB Get_Time

    DEBUG HOME, HEX2 mins, ":", HEX2 secs, CR

    DEBUG HEX2 mins_1, ":", HEX2 sec_1, CR, CR

    IF mins = $00 AND secs = $05 THEN ' Time Delayed Start

    HIGH relay

    ENDIF

    Laps = Laps + 1 ' This Counter is for the Clock Stops Runing Line

    IF secs = $10 THEN

    GOSUB Get_Time_1

    ENDIF

    PAUSE 30 ' This pause was add so the Clock can run more than 10 secounds with out Stopping

    IF secs = $50 THEN 'This rest both counters

    sec_1 = $00

    Laps = 000

    ENDIF

    ·'This line is for code counter if it get to a 550 count or the clock dose not count up then will turn off

    IF secs < sec_1 OR Laps > 550 THEN·

    LOW relay

    STOP

    ENDIF

    IF mins = $03 AND secs = $15 THEN EXIT

    DEBUG DEC5 Laps

    LOOP

    DEBUG CR, CR, "3:15 Elapsed"

    LOW relay

    STOP

    This was add so i would have a Set Point = ( Get_Time_1 is sec_1[noparse]:)[/noparse] Clock Runing = (Get_Time is secs )

    Get_Time_1: ' DS1302 Burst Read

    HIGH CS1302 ' Select DS1302

    SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]RdBurst]

    SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]sec_1, mins_1, hrs_1, date_1, month_1, day_1, year_1]

    LOW CS1302 ' Deselect DS1302

    RETURN



    Get_Time: ' DS1302 Burst Read

    HIGH CS1302 ' Select DS1302

    SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]RdBurst]

    SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]secs, mins, hrs, date, month, day, year]

    LOW CS1302 ' Deselect DS1302

    RETURN

    Sam

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-07-02 18:21
    sam_sam_sam said... Thanks PJ Allen you·help ME lot by what you put in your POST.· It was not completly right but i could work with it and get it to work
    Well, I'm glad I could help, I guess; sorry about it not being completely right.· Figured the GetRTCBurst subroutine was the way to do it (to retrieve the 1302's time), but...
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-07-03 06:13
    sam_sam_sam,
    ·· In the Binary Digital Clock posted in the Completed Projects Forum the main loop is only updating the time every second.· It basically waits for the seconds to change and then does an update.· You could run a counter in the loop and put a check to see if it passes a certain point and if so then the seconds are not updating as they should.· This is the original code...
    DO
      GOSUB Get_Time                        ' Get Current Time/Date Data
      IF mins = $00 AND secs = $00 THEN
        GOSUB Hourly_Chime                  ' Hourly Chime
      ELSEIF secs <> oldsecs THEN           ' Have Seconds Changed?
        GOSUB Show_Date                     ' Update LCD Display
        GOSUB Show_Time                     ' Update 7-Seg Displays
        oldsecs = secs                      ' Remember Update
        GOSUB Get_Temp                      ' Get Current Temperature
        GOSUB Show_Temp                     ' Display Temperature
        chimed = 0                          ' Reset Chime Flag
      ENDIF
    LOOP
    

    What you would have to do is add something like this...

    DO
      GOSUB Get_Time                        ' Get Current Time/Date Data
      counter = counter + 1                 ' update Counter
      IF counter > 10000 THEN Clock_Fail    ' If Counter Reaches This Point Clock Stopped
      IF mins = $00 AND secs = $00 THEN
        GOSUB Hourly_Chime                  ' Hourly Chime
      ELSEIF secs <> oldsecs THEN           ' Have Seconds Changed?
        GOSUB Show_Date                     ' Update LCD Display
        GOSUB Show_Time                     ' Update 7-Seg Displays
        counter = 0                         ' Reset Counter
        oldsecs = secs                      ' Remember Update
        GOSUB Get_Temp                      ' Get Current Temperature
        GOSUB Show_Temp                     ' Display Temperature
        chimed = 0                          ' Reset Chime Flag
      ENDIF
    LOOP
    

    10000 is just an arbitrary number...You would need to determine the number of times the loop executes every second.· This could easily be done using the DEBUG window to print the value of counter every second during the update using the following code...

    DO
      GOSUB Get_Time                        ' Get Current Time/Date Data
      counter = counter + 1                 ' Update Timeout Counter
      IF mins = $00 AND secs = $00 THEN
        GOSUB Hourly_Chime                  ' Hourly Chime
      ELSEIF secs <> oldsecs THEN           ' Have Seconds Changed?
        GOSUB Show_Date                     ' Update LCD Display
        GOSUB Show_Time                     ' Update 7-Seg Displays
        DEBUG DEC counter, CR               ' Display Value To DEBUG Window
        counter = 0                         ' Reset Counter
        oldsecs = secs                      ' Remember Update
        GOSUB Get_Temp                      ' Get Current Temperature
        GOSUB Show_Temp                     ' Display Temperature
        chimed = 0                          ' Reset Chime Flag
      ENDIF
    LOOP
    

    Remember, in both cases it's important to reset the counter during the update or it will cause a false failure.· the Clock_Fail routine is where you would handle that problem, including turning off your Relay.· I hope this helps.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2006-07-04 13:28
    ·Hi, EveryOne·and·Chris

    How is your 4 of July going i hope OK

    Is every one being SAFE

    Chris or any one

    Can you exaplane was this means in this line of code

    ·IF· secs <> oldsecs THEN

    What dose this do ·( <> )

    I have tried to find this in the help files but i can not find it

    I know that this (>) is Less Than

    I know this (<)·is Greater Than

    But what is this (<>)

    I want to Thank AnyOne that can explane what this dose

    Chris

    This is what i came up with

    From What you had POSTED
    ·
    THANK YOU FOR YOUR HELP

    Start:
    mins = $00
    secs = $00
    GOSUB Set_Time
    ·DO
    · GOSUB Get_Time······························· ' Get Current Time/Date Data
    · DEBUG HOME, HEX2 mins, ":", HEX2 secs, CR
    · DEBUG· HEX2 oldsecs, CR
    · counter = counter + 1························ ' Update Timeout Counter
    · IF mins = $00 AND secs = $05 THEN
    ··· GOSUB relay_ON····························· ' Turn relay ON
    · ELSEIF secs <> oldsecs THEN·················· ' Have Seconds Changed?
    · DEBUG DEC counter, CR························ ' Display Value To DEBUG Window
    ··· counter = 0································ ' Reset Counter
    ··· oldsecs = secs····························· ' Remember Update
    · ENDIF
    ·IF counter· > 100 THEN························ ' Stop if counter get to 100 if clock is not running
    · GOSUB relay_OFF
    · STOP
    · ENDIF

    · IF mins = $03 AND secs = $15 THEN EXIT·········
    LOOP
    DEBUG CR, CR, "3:15 Elapsed", CR
    GOSUB relay_OFF············································· ' Turn relay OFF
    STOP

    Sam
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-07-04 13:51
    sam_sam_sam,

    · <> means "does not equal" / "is not equal to"
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-07-04 14:22
    sam_sam_sam -

    Just to add something to PJ's reply that's also syntactically and logically correct, it's also the same as saying:

    IF secs NOT = oldsecs THEN

    if that makes any more sense.

    Regard,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2006-07-05 21:17
    Bruce Bates and PJ Allen

    Thank You for explaining this to me

    Chris Savage

    Thank You For Your POST that help alot


    Sam
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2006-07-07 03:25
    Hi,Chirs
    and EveryOne

    ·This is what i came up with as a routine for if the clock is NOT running

    Start:
    mins = $00
    secs = $00
    GOSUB Set_Time
    DO
    · GOSUB Get_Time································· ' Get Current Time/Date Data
    · DEBUG HOME,"Time = ", HEX2 mins, ":", HEX2 secs, CR
    · DEBUG "OldSecs = ", HEX2 oldsecs, CR


    · IF secs <> oldsecs THEN························ ' Have Seconds Changed?
    ·Laps = Laps + 1································· ' Update Timeout Counter
    ·DEBUG DEC ? Laps, CR
    ·ELSE
    · Laps = 00····································· ' Display Value TO DEBUG Window
    · ENDIF

    ·IF Laps < 100 THEN
    · oldsecs = secs·······' Remember Update..... IF I ('oldsecs = secs) Then Laps COUNTER runs and
    · ELSE········································' Turns OFF Relay
    ·GOSUB relay_off
    ·GOSUB led_on_off
    · EXIT
    · ENDIF

    · IF mins = $00 AND secs = $05 THEN
    ··· GOSUB· relay_ON······························ ' Turn Relay ON
    · ENDIF

    ·· IF mins = $03 AND secs = $15 THEN EXIT
    LOOP
    GOSUB relay_OFF
    DEBUG CR, CR, "3:15 Elapsed", CR
    STOP

    · idea.gif

    Can·anyone see·any thing wrong with the code routine that i have here

    THANKS To Any One That Can Help With This
    Now i have test this Routine And seem to work ok
    It is doing what i want it to do

    Sam···· smile.gif
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-07-07 03:25
    Does it work?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2006-07-07 03:35
    Hi EveryOne

    The reason that i rewrote this code was that when i would ' comment Out the line (secs <> oldsecs)
    it did not work the way i want it work this is what i had frist

    Start:
    mins = $00
    secs = $00
    GOSUB Set_Time
    ·DO
    · GOSUB Get_Time······························· ' Get Current Time/Date Data
    · DEBUG HOME, HEX2 mins, ":", HEX2 secs, CR
    · DEBUG· HEX2 oldsecs, CR
    · counter = counter + 1························ ' Update Timeout Counter
    · IF mins = $00 AND secs = $05 THEN
    ··· GOSUB relay_ON····························· ' Turn relay ON
    · ELSEIF secs <> oldsecs THEN·················· ' Have Seconds Changed?
    · DEBUG DEC counter, CR························ ' Display Value To DEBUG Window
    ··· counter = 0································ ' Reset Counter
    ··· oldsecs = secs····························· ' Remember Update
    · ENDIF
    ·IF counter· > 100 THEN························ ' Stop if counter get to 100 if clock is not running
    · GOSUB relay_OFF
    · STOP
    · ENDIF

    · IF mins = $03 AND secs = $15 THEN EXIT·········
    LOOP
    DEBUG CR, CR, "3:15 Elapsed", CR
    GOSUB relay_OFF············································· ' Turn relay OFF

    Sam
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2006-07-07 03:36
    Chris

    Yes it dose Thanks

    Sam
Sign In or Register to comment.