Shop OBEX P1 Docs P2 Docs Learn Events
Time — Parallax Forums

Time

chris joneschris jones Posts: 391
edited 2009-10-20 21:50 in BASIC Stamp
Hello

i need to display running time on my basic stamp exmple if stamp has been running for 2 hours or 2 days

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-19 17:26
    You need to provide more information.

    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.
  • chris joneschris jones Posts: 391
    edited 2009-10-19 17:31
    the main thing i will want the stamp to do is keep elapsed time
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-19 17:57
    We will not do your class project(s) for you. You are going to have to make use of the references available and build your own program. There are plenty of examples available of the pieces you'll need. You could also browse through the Completed Projects forum here and look for other similar projects.

    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.
  • chris joneschris jones Posts: 391
    edited 2009-10-19 19:58
    This is not a class project or homework just someone who needs help
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-19 20:15
    You've been given help all along with references to existing examples and educational material as well as a general framework for accomplishing your goal.

    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.
  • chris joneschris jones Posts: 391
    edited 2009-10-19 20:41
    i am not sure what you are needing i need to display hours min

    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
  • FranklinFranklin Posts: 4,747
    edited 2009-10-19 21:41
    You would be better served if you were to get a 'RTC' (real time clock) Parallax sells them. They come with sample code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-19 22:34
    Since you only need the time to the nearest minute this is relatively easy. You'd have two variables, Minutes, and Hours and they'd both be initialized to zero when the Stamp is powered on. The first thing your program would do is to display the two values. I can't tell you how to do that because you haven't said what kind of display you have. If it were a serial LCD display, part of the process would include something like

    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
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-10-19 23:00
    Here is a Demo that will give you some· idea.gif·s

    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·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam
  • chris joneschris jones Posts: 391
    edited 2009-10-19 23:07
    ok i am trying your exmaple but it displays 1 and will not add to min


    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
  • chris joneschris jones Posts: 391
    edited 2009-10-19 23:21
    ok i made some changes

    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
  • chris joneschris jones Posts: 391
    edited 2009-10-19 23:33
    another exmaple i have tried you told me to post my attempts

    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
  • chris joneschris jones Posts: 391
    edited 2009-10-19 23:39
    another try i have looked for exmaples online and nuts and volts and dont see any exmaples

    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
  • chris joneschris jones Posts: 391
    edited 2009-10-19 23:55
    i have done some comments to prove that i knowe whats going on but not why its not adding 1 to the minutes


    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
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-10-20 00:12
    Try This

    ·' {$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·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 10/20/2009 12:19:15 AM GMT
  • chris joneschris jones Posts: 391
    edited 2009-10-20 00:19
    ok i have added the coede but my display still diaplays 00:00


    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
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-10-20 00:25
    For one thing you can not do it this way

    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·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam
  • chris joneschris jones Posts: 391
    edited 2009-10-20 00:35
    i tried this and it does not work eather

    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
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-10-20 00:37
    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

    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·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 10/20/2009 12:55:14 AM GMT
  • chris joneschris jones Posts: 391
    edited 2009-10-20 00:50
    ok this is all i have and i still get 00:00

    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
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-10-20 00:56
    SEROUT TxPin, Baud19200,[noparse][[/noparse]$86,DEC Hours, ":", DEC2 Minutes] ' display the time ell

    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·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 10/20/2009 1:27:42 AM GMT
  • chris joneschris jones Posts: 391
    edited 2009-10-20 05:59
    Hello to anyone that can help i was told to stop asking questions but my last question on the forum is what type of time chip do i need to keep time?

    sam_sam_sam i think you had one in mind from your earlyer post.

    Thanks everyone for your help with the parallax stuff
  • allanlane5allanlane5 Posts: 3,815
    edited 2009-10-20 14:28
    I don't have a BS2 with me right now, but the following should work:

    ' {$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
  • FranklinFranklin Posts: 4,747
    edited 2009-10-20 21:50
    http://www.parallax.com/StoreSearchResults/tabid/768/txtSearch/time/List/0/SortField/4/ProductID/233/Default.aspx

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
Sign In or Register to comment.