DS1302 Is there a way to keep track of the timer if it is running
sam_sam_sam
Posts: 2,286
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
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
· 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 ?
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···· ·····
Post Edited (PJ Allen) : 7/2/2006 12:56:09 AM GMT
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
·· 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...
What you would have to do is add something like this...
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...
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
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
· <> means "does not equal" / "is not equal to"
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 -->
Thank You for explaining this to me
Chris Savage
Thank You For Your POST that help alot
Sam
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
·
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····
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
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
Yes it dose Thanks
Sam