Time
chris jones
Posts: 391
Hello
i need to display running time on my basic stamp exmple if stamp has been running for 2 hours or 2 days
i need to display running time on my basic stamp exmple if stamp has been running for 2 hours or 2 days
Comments
What else is the Stamp doing? Is it only displaying the elapsed time?
The reason I ask this is that the Stamps have no absolute time standard. There's no built-in clock. There is the ability to wait for a specific period of time using the PAUSE statement. Usually clocks are implemented by having the Stamp sit in a loop. First the Stamp updates the display. This takes only a few milliseconds. Then the Stamp waits for some fixed time, often one second or some fraction of a second (like 1/10th), then this whole process repeats. The time needed to update the display is small compared to the PAUSE and this time is close to being the same every time. The PAUSE is done very accurately and you can adjust the PAUSE time downwards slightly to compensate for the time needed to update the display. The result is a fairly accurate display time.
If the Stamp has to do something else while it's keeping time, this scheme probably won't work and you'll need to have an external real time clock chip. There are some Nuts and Volts Columns that discuss this, complete with schematics and sample code. You'll have to browse the index to find the specific Columns. Again, go to the "Resources" tab and you'll see a link to the index.
This forum is not intended to provide people with ready-to-go solutions for problems. Rarely does one person's project exactly fit in with the needs of someone else. You would have to understand what someone else has done and modify it to fit your particular needs. This forum is really much better at answering specific questions from someone with a partial solution that either doesn't work or perhaps they misunderstand how something works.
Take the examples suggested, try them, get them to work as is, and make an initial attempt to combine them. Post the source code as an attachment to a message and describe what it does or doesn't do. We'll make suggestions and try to clarify misunderstandings.
If you don't understand Stamp programming enough to do that much, you'll have to start with some kind of introductory text like the "What's a Microcontroller?" tutorial. Work through the examples. Don't just skim through the tutorial. You won't learn much by just reading.
If you don't know where the tutorials are kept, start with the "Resources" tab on Parallax's website and look at the "Downloads and Press" link (the tutorials are under "Stamps in Class Downloads") and the "Nuts and Volts Columns" link. Explore both to see what's available. There's a lot.
You've given very little information about what you already know, what kind of experience you have. You've given very little detail on your project other than it's supposed to keep elapsed time and display it some of the time. What's the accuracy you need? How often do you want to display the information? It's very important to describe what else the Stamp needs to be doing. If it's only displaying the elapsed time, that's one thing. If it has to do anything else, the whole design may have to be different.
EXMAPLE
49:59
EXMAPLE
02:00
i need this to be displayed the whole time power is connected to the basic stamp board when its disconected i need it to start over, i am still looking in the nuts and volts. but since i have a vision imparement i have my cctv pointed on my stap board to i can see it, and zoom text does not read pdf files so great.But that has nothing to do with the question at hand
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
SEROUT <pin>,<Baudmode>,[noparse][[/noparse]DEC Hours, ":", DEC2 Minutes]
Then you'd wait for a minute by doing
PAUSE 60000
Next you'd have a routine that would increment the Minutes and Hours
Minutes = Minutes + 1
IF Minutes = 60 THEN
Minutes = 0
Hours = Hours + 1
ENDIF
Last you'd have a GOTO that would go back to the beginning of the display routine.
If you need the elapsed time in days as well, you'd have another variable for Days, you'd include it in the SEROUT statement, and you'd need something like this just before the above ENDIF:
IF Hours = 24 THEN
Hours = 0
Days = Days + 1
ENDIF
There is two routines one·STARTS the time chip and other STOP the time chip
One hint is that the STOP routine has to be in a loop the START only has to be used once
I will leave the rest to you
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
CODE
FOR cnt = 1 TO 5000
Minutes = Minutes + 1
IF Minutes = 60 THEN
Minutes = 0
Hours = Hours + 1
ENDIF
SEROUT TxPin, Baud19200,[noparse][[/noparse]$86," T ",DEC Hours, ":", DEC2 Minutes]
PAUSE 60000
cnt = cnt + 1
NEXT
SEROUT TxPin, Baud19200,[noparse][[/noparse]$86,DEC Hours, ":", DEC2 Minutes]
PAUSE 60000
FOR counter = 0 TO 9999 ' Count to 12; increment at 1/2 s
Minutes = Minutes + 1
IF Minutes = 60 THEN
Minutes = 0
Hours = Hours + 1
ENDIF
NEXT
Main:
SEROUT TxPin, Baud19200,[noparse][[/noparse]$86,DEC Hours, ":", DEC2 Minutes]
PAUSE 60000
GOTO clock
clock:
Minutes = Minutes + 1
IF Minutes = 60 THEN
Minutes = 0
Hours = Hours + 1
ENDIF
GOTO main
DO
Minutes = Minutes + 1
IF Minutes = 60 THEN
Minutes = 0
Hours = Hours + 1
ENDIF
GOTO clock
LOOP
clock:
SEROUT TxPin, Baud19200,[noparse][[/noparse]$86,DEC Hours, ":", DEC2 Minutes]
PAUSE 60000
GOTO main
Main:
DO
SEROUT TxPin, Baud19200,[noparse][[/noparse]$86,DEC Hours, ":", DEC2 Minutes] ' display the time ell
PAUSE 60000 ' pause for 1 minute
GOSUB clock ' calls the count function
LOOP
clock:
DO
Minutes = Minutes + 1 ' adds 1 to minutes
IF Minutes = 60 THEN ' add 1 to hourse since 60 minutes have passed
Minutes = 0 ' reset minutes varable
Hours = Hours + 1 ' add 1 to hours
IF Hours = 24 THEN 'check to see if a day has passed
Hours = 0 'set hours back TO 0
Days = Days + 1 'add 1 to days
ENDIF ' end
ENDIF ' end
LOOP ' never stop the loop
·' {$STAMP BS2}
' {$PBASIC 2.5}
seconds·· VAR·· Byte
minutes·· VAR·· Byte
hours···· VAR·· Byte
days····· VAR·· Word
DO
PAUSE 1000·· ' This may need to be adj for how long it take to run this routine 900 to 1000
seconds = seconds + 1
IF seconds = 60 THEN
minutes = minutes + 1
seconds = 0
ENDIF
IF hours = 23 AND minutes = 59 THEN
days = days + 1
ELSE
IF minutes = 60 THEN
hours = hours + 1
minutes = 0
ENDIF
ENDIF
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 10/20/2009 12:19:15 AM GMT
Main:
SEROUT TxPin, Baud19200,[noparse][[/noparse]$86,DEC Hours, ":", DEC2 Minutes] ' display the time ell
PAUSE 60000 ' pause for 1 minute
GOSUB clock ' calls the count function
clock:
DO
PAUSE 1000 ' This may need to be adj for how long it take to run this routine
seconds = seconds + 1
IF seconds = 60 THEN
minutes = minutes + 1
seconds = 0
ENDIF
IF hours = 23 AND minutes = 59 THEN
days = days + 1
ELSE
IF minutes = 60 THEN
hours = hours + 1
minutes = 0
ENDIF
ENDIF
LOOP ' never stop the loop
FOR cnt = 1 TO 5000
Minutes = Minutes + 1
IF Minutes = 60 THEN
Minutes = 0
Hours = Hours + 1
ENDIF
SEROUT TxPin, Baud19200,[noparse][[/noparse]$86," T ",DEC Hours, ":", DEC2 Minutes]
PAUSE 60000
cnt = cnt + 1
NEXT
·I have not try ed this so I do not know if this would work or not
DO
FOR cnt = 1 TO 5000
NEXT
cnt = cnt + 1
PAUSE 60000
Minutes = Minutes + 1
IF Minutes = 60 THEN
Minutes = 0
Hours = Hours + 1
ENDIF
SEROUT TxPin, Baud19200,[noparse][[/noparse]$86," T ",DEC Hours, ":", DEC2 Minutes]
LOOP
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
DO
FOR cnt = 1 TO 5000
NEXT
cnt = cnt + 1
PAUSE 60000
Minutes = Minutes + 1
IF Minutes = 60 THEN
Minutes = 0
Hours = Hours + 1
ENDIF
SEROUT TxPin, Baud19200,[noparse][[/noparse]$86," T ",DEC Hours, ":", DEC2 Minutes]
LOOP
SEROUT TxPin, Baud19200,[noparse][[/noparse]$86,DEC Hours, ":", DEC2 Minutes] ' display the time ell
PAUSE 60000 ' pause for 1 minute
GOSUB clock ' calls the count function
You DO NOT NEED THIS
Do this as a TEST· as I·have it here ·now and it work for me
clock:
DO
PAUSE 10· ' This may need to be adj for how long it take to run this routine
DEBUG HOME,DEC3 days,":", DEC2 hours,":", DEC2 minutes,":", DEC2 seconds
·seconds = seconds + 1
IF seconds = 60 THEN
minutes = minutes + 1
seconds = 0
ENDIF
IF hours = 23 AND minutes = 59 THEN
days = days + 1
ELSE
IF minutes = 60 THEN
hours = hours + 1
minutes = 0
ENDIF
ENDIF
LOOP ' never stop the loop
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 10/20/2009 12:55:14 AM GMT
clock:
DO
SEROUT TxPin, Baud19200,[noparse][[/noparse]$86,DEC Hours, ":", DEC2 Minutes] ' display the time ell
PAUSE 1000 ' This may need to be adj for how long it take to run this routine
seconds = seconds + 1
IF seconds = 60 THEN
minutes = minutes + 1
seconds = 0
ENDIF
IF hours = 23 AND minutes = 59 THEN
days = days + 1
ELSE
IF minutes = 60 THEN
hours = hours + 1
minutes = 0
ENDIF
ENDIF
LOOP ' never stop the loop
Change this line to
SEROUT TxPin, Baud19200,[noparse][[/noparse]$86,DEC Hours, ":", DEC2 Minutes ,":", DEC2 seconds] ' display the time ell
I also try ed this as well and this works also
' {$STAMP BS2}
' {$PBASIC 2.5}
·cnt······ VAR··· Word
·minutes·· VAR··· Byte
·hours···· VAR··· Byte
DO
DEBUG HOME,DEC Hours, ":", DEC2 Minutes
FOR cnt = 1 TO 60000
NEXT
cnt = cnt + 1
Minutes = Minutes + 1
IF Minutes = 60 THEN
Minutes = 0
Hours = Hours + 1
ENDIF
LOOP
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 10/20/2009 1:27:42 AM GMT
sam_sam_sam i think you had one in mind from your earlyer post.
Thanks everyone for your help with the parallax stuff
' {$STAMP BS2}
' {$PBASIC 2.5}
I········ VAR Byte
Seconds·· VAR Byte
Minutes·· VAR Byte
Hours···· VAR Byte
' Initialization Section
Seconds = 0
Minutes = 0
Hours =·0
MAIN:· ' Main loop
· FOR I = 1 TO 60
··· GOSUB WaitSecond
· NEXT
· Minutes = Minutes + 1
· IF (Minutes = 60) THEN
··· Minutes = 0
··· Hours = Hours + 1
· ENDIF
· SEROUT 16, 16864, [noparse][[/noparse]DEC2 Hours, ":", DEC2 Minutes]
· GOTO MAIN
WaitSecond:
· PAUSE 1000
· RETURN
This follows several good rules for programming with micro-processors.
1.· ALWAYS initialize variables.
2.· Have a 'main loop' that runs forever.
3.· Use subroutines to encapsulate functionality.
Post Edited (allanlane5) : 10/20/2009 2:34:06 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen