Shop OBEX P1 Docs P2 Docs Learn Events
1 minute timer clock — Parallax Forums

1 minute timer clock

stampguystampguy Posts: 3
edited 2008-04-01 15:59 in BASIC Stamp
I am trying to use an IC, perhaps the DS1302 or DS1307 to create a simple 1 minute clock; basically every 60 seconds the circuit will give a brief
pulse. Any ideas or Basic Stamp code examples to do this would be much appreciated. I am new to the Stamp. Thanks.

Comments

  • FranklinFranklin Posts: 4,747
    edited 2008-03-22 01:29
    Depending on the accuracy you need a 555 or decade counter would probably do what you need.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-22 01:30
    There are plenty of examples of the use of the DS1307 (and the DS1302). Go through the Nuts and Volts columns to find those on real time clocks (here: www.parallax.com/Resources/NutsVoltsColumns/tabid/272/Default.aspx).
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-03-23 04:05
    stampguy

    This is if you are going to use a DS1302 Time Chip

    Take a look at this post three ed one down from the top

    Please Take a look at the Counter Demo in that post

    ·http://forums.parallax.com/showthread.php?p=568430

    To create a simple 1 minute clock; basically every 60 seconds the circuit will give a brief pulse.

    All you have to do is change the······ IF mins = $03······ ·to this··· ·IF mins = $01· or· secs = $59

    Where it has EXIT just after that·put what you want next thing to do and·go back to this routine and so on

    I put an example ·here for you I have not tested it to see if it works or not but it should your just· have to play with it until you get it working

    ·

    ·

    ·


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 3/27/2008 6:45:47 PM GMT
  • tpw_mantpw_man Posts: 276
    edited 2008-03-23 14:28
    sam_sam_sam, stampguy

    That code looks right, but it would be 59 instead of $59. That is hexadecimal 59, which is 89 in decimal.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I am 1010, so be surprised!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-03-26 21:00
    Actually it would be $59 for the RTC. The values stored there are BCD. Now if you just want to decrement a decimal value for a counter all you need to do is check for the seconds to be changed. I have done this method as well and could post some example code for a time using this method if you like.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-03-26 21:03
    Chris Savage

    I have done this method as well and could post some example code for a time using this method if you like.


    Would you post this so I could see how this is done

    Thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-03-27 18:00
    Okay, so not everyone likes dealing with BCD numbers and I totally understand that. So, if you’re in need of a minute and/or second timer and you have a DS1302 or DS1307 installed you can count seconds/minutes without affecting the time on the module at all. Here’s how…

    First let’s deal with just a seconds timer for simplicity. If you want to see one that handles minutes and seconds I will post that from home since I have a copy there. For seconds you would simply set the number of seconds into a variable. A byte variable can hold a value up to 255, so let’s say we want to pause for 75 seconds…

    timer = 75
    GOSUB Get_Time
    oldSecs = secs
    DO
    GOSUB Get_Time
    IF oldSecs <> secs THEN
    timer = timer – 1
    oldSecs = secs
    ENDIF
    IF timer = 0 THEN EXIT
    LOOP
    ‘ end of time routine

    This routine will count down from 75 seconds down to 0 without affecting the normal real time on the module. It assumes you have declared all variables and are using subroutines from my own DS1302 Demo Code. The code will remain inside the DO…LOOP section until the count reaches zero (75 seconds) at which point it will execute whatever is after the LOOP command. If you want to display the counter during the count on the DEBUG screen you could add the following line just after the ENDIF statement…

    DEBUG HOME, DEC timer, “ REMAINING… “

    I hope this helps. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • stampguystampguy Posts: 3
    edited 2008-03-27 18:29
    Chris:

    I am new to stamps...could you please provide the full code including variable declarations etc, so that I can cut and paste it into my code using a 1307 (I have the PDB).

    So would your code integrate into my code, i.e. does your subroutine need to be constantly called from my main program?

    Basically, I need a circuit outside of the BS2 that is constantly running (or perhaps I may need to enable/disbable it), but for now, let's assume that it runs all the time. Every 1 minute the circuit outputs a short pulse - somewhere in the 1 to 100 ms area...not sure yet. 1 minute later it does the same thing ad infinitum. This 1307 circuit then connects to the BS2.

    Within the BS2 and my program code, I run a subroutine that constantly checks the input pin for the existance of that 1 minute pulse. When I see the pulse then I increment a counter.

    A circuit showing how to configure the 1307 (external parts, crystal, caps, output to stamp etc) would be much appreciated. Thanks Chris.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-03-27 18:40
    Chris

    Thank you for posting this code

    ·If you want to see one that handles minutes and seconds I will post that from home since I have a copy there.

    Would you post this code as well

    ·Thanks for all of your help

    ·

    ·stampguy

    Basically, I need a circuit outside of the BS2 that is constantly running (or perhaps I may need to enable/disbable it), but for now, let's assume that it runs all the time. Every 1 minute the circuit outputs a short pulse - somewhere in the 1 to 100 ms area...not sure yet. 1 minute later it does the same thing ad infinitum.



    First of all you can ONLY do one thing at TIME with a Basic Stamp

    Now if you want to have a timer COUNT for a minutes then do something else then go back to Counting agian· then yes you can do this

    ·But NOT both at the SAME TIME

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 3/27/2008 6:57:01 PM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-03-27 18:46
    I can post the countdown timer code which handles minutes and seconds as decimal values and is non-destructive to the RTC values, however I cannot provide pre-written application code specific to your setup. If you’re using the DS1307 the Stamp Work Manual provides excellent example code for reading the time from the chip. The Get_Time routine will be something similar in that code. You can use that code as a template with what I have provided to accomplish the same thing. You should really look at what is happening in the code and understand it before trying to merge the two concepts. This will help when you actually do. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-03-28 12:25
    Chris

    I can post the countdown timer code which handles minutes and seconds as decimal values and is non-destructive to the RTC values

    Would You please post countdown timer code

    Thank You for your Help

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • John KauffmanJohn Kauffman Posts: 653
    edited 2008-03-28 18:34
    Another approach is to get a timekeeper chip with an alarm function.
    Instead of the STAMP counting up for 60 seconds or checkin gfrequently to see if the real time is sec=00, you can just tell the stamp to sleep until the timeleeper chip changes its alarm pin to high. I forget the numbers of chips that hold hte time, but you can find on maxim / Dallas site.

    This approach is useful when you need the real time anyhow (like to put a time stamp on data) which will require you to buy one of the timepkeeping chips - might as well get one with the alarm feature.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-03-28 20:23
    John Kauffman

    Have you used the DS1306 before and do you have a working Demo Code that

    you can share



    I look at it a little and it seem to have the same type of format

    I am right about this here is the link to it

    http://datasheets.maxim-ic.com/en/ds/DS1306.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-03-28 21:29
    John,

    The second idea (which I more frequently use) is not to check for a 0 value from the RTC, but to use your own counter, using the RTC only as a reference for seconds. The RTC time/date remain intact.

    Sam_sam_sam,

    I will post the code tonight or tomorrow…It is at my home office. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-03-31 16:36
    Chris·


    Sam_sam_sam,

    .....>>>>> I will post the code tonight or tomorrow…It is at my home office.


    Take care...........>>>>>>>>>>>>>>>

    ....>>>> I can post the countdown timer code which handles minutes and seconds as decimal values and is non-destructive to the RTC values,

    Did you for get about me·I would still like to see this code

    Thanks for all of your time and help

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-03-31 20:53
    Sam_sam_sam,

    I would not and could not forget about you! =) I simply forgot to get the code off my home PC. It’s good I have you to keep my on my toes and so I will get it tonight. I am even sending myself an e-mail right now to remind me. Should be here about 3 hours from now. Thanks again for keeping me on my toes!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-04-01 00:19
    Okay, found the code and realized this project was done for a client so I cannot post the code in its entirety...What I can do is provide the timer relevant data...

    In this case the time was set by pressing buttons for the minutes and seconds.· There was also a clear button.· When the start button was pressed the time was saved into the DS1302 RAM so basically the following subroutines were executed...
            GOSUB Set_RAM                   ' Update RTC RAM
            GOSUB Timer_Run                 ' Start Timer Count Down
            GOSUB Times_Up                  ' Time Complete
    
    

    Set RAM stored relevant data for the timing cycle...(maybe it was hours and minutes...fuzzy, I think the comments are wrong· =)· anyway...)

    Set_RAM:
      index = CWPr                          ' Write Protect Register
      ioByte = WPr0                         ' Clear Write Protect
      GOSUB RTC_Out                         ' Send Command
      ioByte = 0                            ' Address Of Alarm 1 Minutes
      index = WrRam | (ioByte << 1)         ' Write RAM Mode + Address
      ioByte = setSecs                      ' Set Alarm 1 Minutes
      GOSUB RTC_Out                         ' Write Value
      ioByte = 1                            ' Address Of Alarm 1 Hours
      index = WrRam | (ioByte << 1)         ' Write RAM Mode + Address
      ioByte = setMins                      ' Set Alarm 1 Hours
      GOSUB RTC_Out                         ' Write Value
      index = CWPr                          ' Write Protect Register
      ioByte = WPr1                         ' Set Write Protect
      GOSUB RTC_Out                         ' Send Command
      RETURN
    
    

    The next routine starts the timing cycle...Even though it is resetting the clock, in most cases you will not need to do that since this routine simply checks for a change in seconds.· Show_Run_Time is simply the subroutine that updates this particular display.· This way if the display changes, only that subroutine is affected.

    Timer_Run:
      runSecs = setSecs                     ' Copy Run Seconds
      runMins = setMins                     ' Copy Run Minutes
      GOSUB Reset_Clock                     ' Reset Clock
      oldSecs = secs                        ' Update Delta
      DO                                    ' Place your main routines here
        GOSUB Get_Time                      ' Get The Current Date/Time
          IF secs <> oldSecs THEN           ' Next Second?
            oldSecs = secs                  ' Update Old Seconds
            GOSUB Ticking                   ' Count Down
            'FREQOUT Buzzer, 300, 1500      ' Disabled Beep
          ENDIF
        GOSUB Show_Run_Time                 ' Display It
        IF runSecs = 0 AND runMins = 0 THEN EXIT
      LOOP
      RETURN
     
    Ticking:
      IF runSecs = 0 THEN                   ' Are Seconds Up?
        runSecs = 59                        ' If So Reset To 59
        runMins = runMins - 1               ' Subtract Minute
      ELSE
        runSecs = runSecs - 1               ' Subtract Second
      ENDIF
      RETURN
    
    

    Finally, when time is up...Flash display and beep...

    Times_Up:
      runSecs = setSecs                     ' Copy Run Seconds
      runMins = setMins                     ' Copy Run Minutes
      GOSUB Show_Run_Time                   ' Display Run Time
      FOR index = 0 TO 2                    ' 3 Flashes/Beeps
        SEROUT SLEDC4, Baud, [noparse][[/noparse]"B", 0, "~"]  ' Display Off
        HIGH Buzzer                         ' Buzzer On
        PAUSE 950                           ' Almost 1 Second
        SEROUT SLEDC4, Baud, [noparse][[/noparse]"B", 30, "~"] ' Display On
        LOW Buzzer                          ' Buzzer Off
        PAUSE 950                           ' Almost 1 Second
      NEXT
      RETURN
    
    

    I hope this provides some useful information...I would be happy to answer specific questions on the code if need be.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-04-01 03:35
    Chris

    Okay, found the code and realized this project was done for a client so I cannot post the code in its entirety...What I can do is provide the timer relevant data...

    Thank You for posting this code this will help ALOT···· smile.gif
    ·I need a mins and secs count down timer for something I am working on

    I have it woking good

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-04-01 14:34
    Bear in mind that this code is different from the original timer code I sent you in that it is designed to use a decimal value in a standard variable as a counter. In this case both minutes and seconds, but as opposed to the BCD format the clock uses. Also, it does not interfere with the clock time, so you can have an application where the real time/date information is used, but at the same time you can have a seconds counter as well, which in this case, also takes care of minutes.

    I was thinking about why I reset the clock in this code during the Timer_Run section and I remembered…If you arbitrarily use the RTC seconds for timing your accuracy could be off by up to one second because the seconds may be changing at any point upon entry into the routine…In most cases this won’t be a problem, but in all fairness I thought I would mention it. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-04-01 15:59
    ·Chris

    I··was thinking about why I reset the clock in this code during the Timer_Run section and I remembered…If you arbitrarily use the RTC seconds for timing your accuracy could be off by up to one second because the seconds may be changing at any point upon entry into the routine…In most cases this won’t be a problem, but in all fairness I thought I would mention it. Take care.


    I was trying to understand why the reset the clock in Timer_Run section my
    self but thought it had to with some part of another routine and that you could
    not share because you........>>>>>>·realized this project was done for a client so I cannot post the code in its entirety...What I can do is provide the timer relevant data...

    Which I comptlely understand that I am glad that you shared this part of the code

    Thanks for sharing it

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
Sign In or Register to comment.