Is there a way to fix elapsed time with hold Seconds after stopping the clock.
Here is what i want to it in this post
here is the link
·http://forums.parallax.com/showthread.php?p=736562
·I can see what my current HVAC usage is on a daily basis and see where potential "opportunities" are
* inside temp/humidity
* outside temp/humidity
* system status (on/off)
* heat/cool mode
I am thinking doing something like this
One way to this is to have a Time Counter that runs when you are calling for cooling how get this
·You have optic sensor tie to the contactor this where you get your·signal from
What i have not·figure out is how to stop and start a DS1302 chip to keep track of the time in this way or is there another chip that·I could use to do this with
I have try this couple of time but have not got any where yet
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·
·that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 7/18/2008 1:26:13 AM GMT
here is the link
·http://forums.parallax.com/showthread.php?p=736562
·I can see what my current HVAC usage is on a daily basis and see where potential "opportunities" are
* inside temp/humidity
* outside temp/humidity
* system status (on/off)
* heat/cool mode
I am thinking doing something like this
One way to this is to have a Time Counter that runs when you are calling for cooling how get this
·You have optic sensor tie to the contactor this where you get your·signal from
What i have not·figure out is how to stop and start a DS1302 chip to keep track of the time in this way or is there another chip that·I could use to do this with
I have try this couple of time but have not got any where yet
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·
![idea.gif](http://forums.parallax.com/images/smilies/idea.gif)
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 7/18/2008 1:26:13 AM GMT
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
Thank You for your reply
I though about doing it that way also
But what I·want to is to have running total time where
·I dd not have to· subtract the times it done for me
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·
·
·
·
·
Sam
·
How about an external oscillator to the DS1302 that you can "gate".
·
Last I checked, you can still communicate to the DS1302 without the crystal... the crystal is strictly for timekeeping.
·
You will still need to set some sort of initial reference time, because by default·if·some of the mode registers are not set
correctly, the clock is·disabled.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
How about an external oscillator to the DS1302 that you can "gate".
This sounds just like·what·I looking for do you any info that you can share on how to do this
·
You will still need to set some sort of initial reference time, because by default·if·some of the mode registers are not set
correctly, the clock is·disabled.
This··would a great help and thank you for any help that you can give me on this
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·
·
·
·
·
Sam
·
Forget my previous post, I took a closer look at the datasheet under the "CLOCK HALT" or CH flag. This is Bit 7 of the second register. If it is set to "1" the clock oscillator is stopped and the DS1302 enters a low power mode <100nA. When the bit is set to "0" the clock will start again.
·
This way you could use any of the Stamps, SX, or Propeller ... The other method that I had mentioned would only have been easier with the Propeller.
·
Starting the Clock and resetting values (first time run):
Write %10000000 to address 80h·· ... This·stops the clock
Write %00000000 to address 84h·· ... This initializes the clock in 24 hour mode and clears the hours to "00"
Write %00000000 to address 82h·· ... This clears the·minutes to "00"
Write %00000000 to address 80h·· ... This starts the clock and clears the·minutes to "00"
·
Stop the Clock and read elapsed time:
Read from address 81h and store in 'seconds'
subtract 128 from 'seconds' and Write the new value of 'seconds'·to address 80h· ... This·stops the clock and preserves the seconds value
Read from address 82h and store in 'minutes'
Read from address 84h and store in 'hours'
·
Restart·the Clock resume counting elapsed time:
add 128 to·'seconds' and Write new 'seconds' value to address 80h· ... This·starts the clock and preserves the seconds value
If you need to go further, you can access the registers as you normally would out to Days, Months, and Years.
·
Reference:
http://pdfserv.maxim-ic.com/en/ds/DS1302.pdf
Page 7 and Page 9
.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 7/13/2008 5:47:27 AM GMT
Thank You for your reply
Could you give an example of how·I would do this the part
Starting the Clock and resetting values (first time run):
Write %10000000 to address 80h·· ... This·stops the clock
Write %00000000 to address 84h·· ... This initializes the clock in 24 hour mode and clears the hours to "00"
Write %00000000 to address 82h·· ... This clears the·minutes to "00"
Write %00000000 to address 80h·· ... This starts the clock and clears the·minutes to "00"
Stop the Clock and read elapsed time:
Read from address 81h and store in 'seconds'
subtract 127 from 'seconds' and Write the new value of 'seconds'·to address 80h· ... This·stops the clock and preserves the seconds value
Read from address 82h and store in 'minutes'
Read from address 84h and store in 'hours'
·
Restart·the Clock resume counting elapsed time:
add 127 to·'seconds' and Write new 'seconds' value to address 80h· ... This·starts the clock and preserves the seconds value
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 7/13/2008 4:49:13 AM GMT
Nuts and Volts Column #33 goes into detail on the use of the DS1302 and includes downloadable sample code.
You will also need the datasheet for the DS1302 from Dallas's website.
Rather than saying "i do not fully understand how to do", how about describing what you do understand and what you don't understand. Also indicate what references and examples you have looked at.
Nuts and Volts Column #33 goes into detail on the use of the DS1302 and includes down loadable sample code.
In the Nut and volt #33 and #34 Dose Not talk about how to do what Beau Schwabe·(Parallax) is saying in his post and ALL of the demo·I have seen do not show how to do this and if it dose than·I must be missing something
I understand that you have to access bit 7 in order to halt the clock but how do you write it
All i was asking for was an example of how to do it
You will also need the data sheet for the DS1302 from Dallas's website.
I read it four time and also read the In the Nut and volt #33
If this sound rough·I am truly sorry about that
I had first look at all of the demos on the DS1302
I do enjoy reading your post and have learn a LOT from reading them and·I thank you for them
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·
·
·
·
·
Sam
To write the value %10000000 to the register $80, you do
Note that RTCout in the sample code is incorrect. This has been corrected.
You'll have to define CS_1302, Dio, Clk appropriately and declare addr and ioByte as byte variables.
·
What I gave you is just a basic programming flow.· There are several examples on how to read and write to the DS1302 registers.
·
In the attachment that you provided, the two read and write routines are as follows:
·
Read:
Write:
·
Prior to calling the Read or Write subroutine, you need to set the 'reg' (register)·variable , and for a Write, you need to set the 'ioByte' (Data) variable.
·
So for...
Starting the Clock and resetting values (first time run):
Write %10000000 to address 80h·· ... This·stops the clock
Write %00000000 to address 84h·· ... This initializes the clock in 24 hour mode and clears the hours to "00"
Write %00000000 to address 82h·· ... This clears the·minutes to "00"
Write %00000000 to address 80h·· ... This starts the clock and clears the·minutes to "00"
·
·it might look something like this...
·
·
The general idea, is that you initially set the clock to 00:00:00 (<- This format is valid only in 24 hour mode).· This would be a timer reset or a first time run.· All subsequent runs would just stop and start the clock.· Since the Clock Halt bit is embedded within the seconds register, you need to preserve the seconds if the seconds are of interest to you... you may just want minute accuracy ... depends on what you want.· By adding or subtracting 128 from the seconds value, you effectively set or clear the Clock Halt Bit and preserve the elapsed seconds value.
·
So for...
Stop the Clock and read elapsed time:
Read from address 81h and store in 'seconds'
subtract 128 from 'seconds' and Write the new value of 'seconds'·to address 80h· ... This·stops the clock and preserves the seconds value
Read from address 82h and store in 'minutes'
Read from address 84h and store in 'hours'
·
It might look something like this...
·
And for...
Restart·the Clock resume counting elapsed time:
add 128 to·'seconds' and Write new 'seconds' value to address 80h· ... This·starts the clock and preserves the seconds value
·
It might look something like this...
·
·
Note: I hade erroneously used the number 127, when I should have used 128 instead.
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 7/13/2008 5:54:28 AM GMT
"...In the Nut and volt #33 and #34 Dose Not talk about how to do what Beau Schwabe (Parallax) is saying in his post and ALL of the demo I have seen do not show how to do this and if it dose than I must be missing something..."
No, your probably not missing anything, the DEMO's are usually a general design angled in a way that will help get you started. Something in the order of stopping or starting the clock is a more specific, specialized application.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Thank You for your reply
Thank You for the example that you gave to me·that help alot i did get it to work the way·I want it to work
clockstop:
··· addr = $80········· ' Point to register 80h
ioByte = %10000000 ' Set Clock Halt Bit
GOSUB RTCOut····· ' Send Command
addr = $84········· ' Point to register 84h
ioByte = %00000000 ' initializes the clock in 24 hour mode and clear the hours to "00"
GOSUB RTCOut····· ' Send Command
DEBUG CLS ,CLS, CR
DO
laps = laps + 1
DEBUG HOME, DEC4 ? laps
LOOP UNTIL laps = 1000
addr = $80
ioByte = %00000000 ' starts the clock by clearing the Clock Halt bit and clears the seconds to "00"
GOSUB RTCOut····· ' Send Command
GOSUB start
Mike Green Thank you as well
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 7/13/2008 10:30:36 AM GMT
What am i doing wrong i also try the button command and that did not do ether
' {$STAMP BS2}
' {$PBASIC 2.5}
' Program Listing 33.1
' Stamp Applications: Nuts & Volts, November 1997
' ----[noparse][[/noparse] Title ]
'
' File...... BS2CLOCK.BS2
' Purpose... Stamp II-based Alarm Clock
' Author.... Jon Williams
' E-mail.... jonwms@aol.com
' WWW....... http://members.aol.com/jonwms
' Started... 20 SEP 97
' Updated... 27 SEP 97
'
' ----[noparse][[/noparse] Main Code ]
'
Start:
DEBUG CLS
· DO
· GOSUB GetTm
GOSUB ShowTm
· INPUT 2······························ ' Make P2 an input
· DEBUG· CR, CR, "State of P2: ",
······· BIN1 IN2, CR
LOOP UNTIL IN2 = 1
·· GOSUB clockstop
' ----[noparse][[/noparse] Subroutines ]
' showtm:
· DEBUG HOME,HEX2 hrs, ":", HEX2 mins, ":",HEX2 secs
· oldSc = secs····· ' reset check value
· RETURN
·clockstop:
DO
· INPUT 2
· PAUSE 1····························· ' Make P2 an input
LOOP UNTIL IN2 = 0
··· addr = $80········· ' Point to register 80h
ioByte = %10000000 ' Set Clock Halt Bit
GOSUB RTCOut····· ' Send Command
addr = $84········· ' Point to register 84h
ioByte = %00000000 ' initializes the clock in 24 hour mode and clear the hours to "00"
GOSUB RTCOut····· ' Send Command
addr = $80
ioByte = %00000000 ' starts the clock by clearing the Clock Halt bit and clears the seconds to "00"
GOSUB RTCOut····· ' Send Command
·addr = $80·········· ' Point to register 80h
ioByte = secs + 128 ' Set Clock Halt Bit
GOSUB RTCOut······ ' Send Command
GOSUB start
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 7/15/2008 12:25:59 PM GMT
But the clock dose not alway restart·when you remove··power·from pin # 2 if you power pin agian and remove· then it will restart
The second stay where they left off but when it dose not restart you will see 89 , 99 or something like that
I have a 10k ohm rest from pin 2 to vss and from pin 2 a 220· ohm rest to vdd when powering pin 2
What do I need to add to·fix this problem
main:
DO· WHILE· IN2 = 0
· GOSUB Get_Time
· DEBUG HOME, HEX2 mins, ":", HEX2 secs
· LOOP
· DO WHILE IN2 = 1
· reg = $81·········································· ·' Point to register 81h
GOSUB RTC_In····································· ·' Receive Command
ioByte = ioByte - 128····························· ' Clear Clock Halt Bit
secs = ioByte········································' Store elapsed Seconds value
reg = $80··········································· ·' Point to register 80h
GOSUB RTC_Out·································· ·' Send Command
reg = $82··········································· ·' Point to register 82h
GOSUB RTC_In···································· ·' Receive Command
mins = ioByte······································ ' Store elapsed Minutes value
reg = $84········································· ·' Point to register 84h
GOSUB RTC_In·································· ·' Receive Command
hrs = ioByte·······································' Store elapsed Hours value
LOOP
·reg = $80······································· ' Point to register 80h
ioByte = secs + 128·························· ' Set Clock Halt Bit
GOSUB RTC_Out······························· ' Send Command
GOSUB· main
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 7/15/2008 12:30:30 PM GMT
End $.02
kenjj
Thank You for your reply
I understand what you are talking about
Could you give an example of how you would write the routine to·this
I am open to any··
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·
·
·
·
·
Sam
You seem to have code to initialize the 1302. I take it for granted you have a grasp of the registers and how they are used. I also suppose that the processor is doing mostly nothing else other than read a temp sensor and/or wait for something like the furnace to turn on. You basically run in a tight loop:
1. waiting for some input from the user
2. read a temp sensor
and/or
3. monitor an event like the power up of a heating or cooling device
So, at initialization you create five byte variables: new_sec, old_sec, seconds, mins, and hours (and days, if you want). When an event you want to time happens, you jump into a subroutine where you
1. read the seconds register in the 1302 and store the value in new_sec.
2. compare that reading to the previous reading in old_sec. If it's different, take an action. The first time here you're almost guaranteed to have a mismatch, since it may be anywhere from several seconds to several hours since the last measurable event occurred. OK, you're going to be adding a second to all these measurements. I can't see that as a real problem. After this any difference in the value is a real second passing in time.
3. IF the values differ THEN save new_sec to old_sec and increment the seconds count. If not, return to loop.
4. IF seconds equals 60 THEN set seconds to zero and increment minutes. If not, return to loop.
5. IF you incremented minutes, check to see if minutes equals 60. IF yes THEN zero out minutes and increment hours. If not, return to loop.
And you keep carrying on like this until the event you're timing stops. You now have a running elapsed time counter going. The beauty is, you don't have to stop and convert a bunch of BCD readings from the 1302 into integer numbers and subtract to get this count. If you want you can still read all the 1302 registers at the start and end of each event. Later, when the user asks for a readout, you convert them to time strings, i.e., HH:MM:SS. As for the elapsed time counter here, no conversion is necessary, just print them out after converting from hex to decimal, which is probably just a modifier in PBasic.
Later!
kenjj
Thank You for your reply
When i have some time and when·I finish the project that i am working on right
now and can find the how to convert ·BCD format then i will work on this some more
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 7/19/2008 1:09:56 AM GMT
For some reason·I have not able to get this part of the routine to work the way·I would like it to work
reg = $81············ ' Point to register 81h
GOSUB RTC_In········· ' Receive Command
ioByte = ioByte - 128 ' Clear Clock Halt Bit
secs = ioByte······· ·' Store elapsed Seconds value
reg = $80··········· ·' Point to register 80h
GOSUB RTC_Out······· ·' Send Command
reg = $80· ········ '·Point to register 80h
ioByte = secs + 128 ' Set Clock Halt Bit
GOSUB RTC_Out······ ' Send Command
I also try this and this did not help ether
Likewise for similar reasons, where you have this...
...use this instead...
The problem that·I am having with this routine is that seconds do not restart or you have like 80 seconds ond nothing happens or if you can get
the seconds to restart you have power the input on the Basic Stamp one that i am using to restart the clock with code that you gave to try
is there a away to fix the or do need to just except that this realy can not be done this way with a Basic Stamp
Now this routine work great and Thank You for helping with this routine
reg = $80········· ' Point to register 80h
ioByte = %10000000 ' Set Clock Halt Bit
GOSUB RTC_Out······' Send Command
reg = $84········· ' Point to register 84h
ioByte = %00000000 ' initializes the clock in 24 hour mode and clear the hours to "00"
GOSUB RTC_Out····· ' Send Command
reg = $82········ ·' Point to register 82h
ioByte = %00000000 ' clear the minutes to "00"
GOSUB RTC_Out···· ·' Send Command
reg = $80········· ' Point to register 80h
ioByte = %00000000 ' starts the clock by clearing the Clock Halt bit and clears the minutes to "00"
GOSUB RTC_Out····· ' Send Command
Like i said in other post about this that if i change this part to this··%0110000· .......instead of %00000000· this
I change the clock seconds to 30 and count from
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 7/18/2008 1:39:00 AM GMT