Shop OBEX P1 Docs P2 Docs Learn Events
Making a BS2 Controlled Alarm Clock? Or even Clock? — Parallax Forums

Making a BS2 Controlled Alarm Clock? Or even Clock?

EmissionEmission Posts: 15
edited 2006-07-28 14:12 in BASIC Stamp
I thought this would be an intresting experiment, so im curious to know just what I might need to emulate a real clock. I could probably be able to code for half of it but im totally stumped on part of the circutry. Any ideas?

Comments

  • HarborHarbor Posts: 73
    edited 2006-06-30 02:55
    DS1302. Using one myself this very evening.
    http://www.parallax.com/detail.asp?product_id=604-00005
  • EmissionEmission Posts: 15
    edited 2006-06-30 03:02
    I have this 60-Second timer code that I have to start with. Its connected to a 10-LED ..thingy? (I forgot what they're called), 3 of the leds cycle back and forth to show that its counting, 6 of the leds are used to keep track of how many 10-second sequences have passed, and 1 un-used led is in between both sections (to make it more organized). 1 blue led apart from the 10 leds shows that the sequence is finished, and a handy debug message is in there to verify that it works %100. All I need to make this useful are 16 leds, and a bunch of wire cool.gif . From there on, I can connect each led to an I/O pin, and recode the program to count in a binary fashion. Example Scenario:

    8 - * * * *
    4 - * * . * *
    2 - * * . * *
    1 - * * * *

    Each * is a led, and they are lit up in order to show the time in 00:00 format (after binary conversion, as show by the numbers).

    Heres the 60-Second portion of code I worked on:

    ' {$STAMP BS2}
    'Terminally Controlled Clock
    '-60 Second Scrolling Sequence
    
    countseq:
      GOSUB seq1
      HIGH 8
      GOSUB seq1
      HIGH 9
      GOSUB seq1
      HIGH 10
      GOSUB seq1
      HIGH 11
      GOSUB seq1
      HIGH 12
      GOSUB seq1
      HIGH 13
    GOTO finished
    
    finished:
      DEBUG "Finished!"
      HIGH 14
    END
    
    seq1:
      HIGH 4
      PAUSE 1000
      LOW 4
      HIGH 5
      PAUSE 1000
      LOW 5
      HIGH 6
      PAUSE 1000
      LOW 6
      HIGH 5
      PAUSE 1000
      LOW 5
      HIGH 4
      PAUSE 1000
      LOW 4
      HIGH 5
      PAUSE 1000
      LOW 5
      HIGH 6
      PAUSE 1000
      LOW 6
      HIGH 5
      PAUSE 1000
      LOW 5
      HIGH 4
      PAUSE 1000
      LOW 4
      HIGH 5
      PAUSE 1000
      LOW 5
    RETURN
    
    



    What im intrested in knowing, is if theres a way to use some kind of For..Next coding to replace the bulky gosub's and high sequences. I'll probably check the Nuts and Volts pages, but if anyone knows a specific page on that, do tell lol.gif .

    yeah.gif

    Post Edited (Emission) : 6/30/2006 3:07:29 AM GMT
  • EmissionEmission Posts: 15
    edited 2006-06-30 03:03
    Harbor said...
    DS1302. Using one myself this very evening.
    http://www.parallax.com/detail.asp?product_id=604-00005

    Thats intresting, im gonna look into that. Thanks.
  • Matt WhiteMatt White Posts: 60
    edited 2006-06-30 04:50
    DS1307 also works well for me. I've used the RTC on the Professional Development Board from Parallax as well as this one:

    http://www.mindsensors.com/index.php?module=pagemaster&PAGE_user_op=view_page&PAGE_id=53

    I like Nitin's RTC because of its small size and it has mounting holes I can easily mount it to my BOE bot. It also doesn't take up any breadboard space (except the 4.7k pullup resistors for the I2C communication).

    Matt
  • FranklinFranklin Posts: 4,747
    edited 2006-06-30 19:30
    for i = 5 to 6
    high i
    pause 1000
    low i
    next
    for i = 5 to 4
    high i
    pause 1000
    low i
    next

    Off the top of my head (warning, the top of my head is bald)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • SSteveSSteve Posts: 808
    edited 2006-06-30 21:04
    That code won't do the same thing. That will just do this:
    HIGH 5
      PAUSE 1000
      LOW 5
      HIGH 6
      PAUSE 1000
      LOW 6
      HIGH 5
      PAUSE 1000
      LOW 5
      HIGH 4
      PAUSE 1000
      LOW 4
    
    


    I'll post something in a few minutes that should work.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows

    links:
    My band's website
    Our album on the iTunes Music Store
  • SSteveSSteve Posts: 808
    edited 2006-06-30 21:12
    This should work:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    CountPin    VAR        NIB
    seqPin    VAR        NIB
    idx        VAR        NIB
    
    countseq:
        FOR CountPin = 8 TO 14
            IF CountPin < 14 THEN
                GOSUB seq1
            ELSE
                DEBUG "Finished!"
            ENDIF
            HIGH CountPin
        NEXT
    END
    
    seq1:
        FOR idx = 0 TO 9
            LOOKUP idx, [noparse][[/noparse]4, 5, 6, 5, 4, 5, 6, 5, 4, 5], seqPin
            HIGH seqPin
            PAUSE 1000
            LOW seqPin
        NEXT
    RETURN
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows

    links:
    My band's website
    Our album on the iTunes Music Store
  • EmissionEmission Posts: 15
    edited 2006-06-30 22:07
    OMG! Thank you! I can build off this code, thank you very much!
  • EmissionEmission Posts: 15
    edited 2006-06-30 22:55
    Now im stumped on the binary part. If I want to display time in a 1 2 4 8 binary format (where its read by reading the sum of the digits, as binary is read), I need to store the necessary pin combinations for each number, but I dont know how to do that without manually entering the high and low sequences required for every 10 second/10 minute phase. Is there a way to store the data somehow for each pin combo in some kind of table or something? I'll get back to you guys with what code I can come up with for the time being.
  • EmissionEmission Posts: 15
    edited 2006-07-01 00:28
    Here's my prototype control code. Pins 4 thru 7 are the 4 LED's that represent each 4-bit sequence, 1 2 4 8 (Signifying xxxx of the binary code).

    This code itself only takes up 7% of the EEPROM so theres plenty of room for the rest of the sequences, and the actual clock coding.

    ' {$STAMP BS2}
    ' Variable Test Environment
    
    clockseq:
      HIGH 4
      PAUSE 995
      GOSUB clrnums
      HIGH 5
      PAUSE 995
      GOSUB clrnums
      GOSUB numseq3
      PAUSE 994
      GOSUB clrnums
      HIGH 6
      PAUSE 995
      GOSUB clrnums
      GOSUB numseq5
      PAUSE 994
      GOSUB clrnums
      GOSUB numseq6
      PAUSE 994
      GOSUB clrnums
      GOSUB numseq7
      PAUSE 994
      GOSUB clrnums
      HIGH 7
      PAUSE 995
      GOSUB clrnums
      GOSUB numseq9
      PAUSE 994
      GOSUB clrnums
      PAUSE 995
    GOTO clockseq
    
    clrnums:
      LOW 4
      LOW 5
      LOW 6
      LOW 7
    RETURN
    
    numseq3:
      HIGH 4
      HIGH 5
    RETURN
    
    numseq5:
      HIGH 4
      HIGH 6
    RETURN
    
    numseq6:
      HIGH 5
      HIGH 6
    RETURN
    
    numseq7:
      HIGH 4
      HIGH 5
      HIGH 6
    RETURN
    
    numseq9:
      HIGH 4
      HIGH 7
    RETURN
    
  • SSteveSSteve Posts: 808
    edited 2006-07-01 00:35
    Pins 4-7 are addressed with outb, so you can just write
    outb = whateverValue
    

    No need to go through all the gymnastics you're performing.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows

    links:
    My band's website
    Our album on the iTunes Music Store
  • EmissionEmission Posts: 15
    edited 2006-07-01 00:59
    Can you give me an example of how I would use outb? And, is outb applicable for all pins 0 - 15? If not, just throw that info in there if you can, Since i'm not really sure how to use outb to turn on the pins I need. Thanks.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2006-07-01 02:03
    Emission
    ·······················································································
    I am with you on this one
    I·would like to know this my self·· idea.gif

    Can you give me an example of how I would use outb?

    And, is outb applicable for all pins 0 - 15?

    I reading this POST·to see what comes out of this

    This might be a cool project


    SSteve·said this

    outb·=·whateverValue

    Please explane whateverValue are you meaning binary #

    If I want to display time in a 1 2 4 8 binary format (where its read by reading the sum of the digits, as binary is read is this what you are taking about whateverValue

    Thanks to anyone that can help me understand how to do this and Thank You for your Time

    Sam··· smile.gif
  • FlyingFishFingerFlyingFishFinger Posts: 461
    edited 2006-07-01 02:06
    OUTB specifies pins 4,5,6 and 7. It's a nibble (4 bits), where each bit corresponds to a pin. Saying OUTB=16 (binary %1111) will set all four pins high. You can address the individual pins like this: OUTB=%1101 or whatever value you want. (% specifies binary, you can also use decimal, then your pins will have the states that correspond to the binary value of the decimal number). For all 16 pins, there are 4 such variables: OUTA (pins 0,1,2,3), OUTB (pins4,5,6,7) OUTC (8,9,10,11) and OUTD (12,13,14,15). There are also other such variables, see the Stamp Manual (http://www.parallax.com/dl/docs/prod/stamps/web-BSM-v2.2.pdf ; Pages 81-84)

    Rafael

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You've got to play the game.
    You can't win.
    You can't break even, except on a very cold day.
    It doesn't get that cold.
    ~Laws of Thermodynamics~
  • SSteveSSteve Posts: 808
    edited 2006-07-01 02:06
    ina/outa = pins 0-3
    inb/outb = pins 4-7
    inc/outc = pins 8-11
    ind/outd = pins 12-15

    inl/outl = pins 0-7
    inh/ouh = pins 8-15

    ins/outs = pins 0-15

    outb = 7
    

    will set pins 4, 5, & 6 to high and pin 7 to low.

    This is described in the BASIC Stamp reference manual under "Memory Organization"

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows

    links:
    My band's website
    Our album on the iTunes Music Store
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-07-01 02:14
    Emission said...
    I thought this would be an intresting experiment, so im curious to know just what I might need to emulate a real clock. I could probably be able to code for half of it but im totally stumped on part of the circutry. Any ideas?
    Have you seen this project?· A complete Binary Digital Clock with Day/Date/Temperature Display...

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


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • EmissionEmission Posts: 15
    edited 2006-07-01 02:46
    AHHH!! For some reason, I can't get the OUT command to work right. I even used this code to test output but it DOSNT WORK!:

    ' Test
    
    OUTB = %1111
    END
    



    The LED's just wont light up, I don't understand. Am I doing something wrong?

    And no, I haven't seen that project, but it looks cool. Think I can reduce the size of that whole setup to the size of a watch? devil.gif
  • SSteveSSteve Posts: 808
    edited 2006-07-01 04:45
    I think the END statement shuts the Stamp down and doesn't keep the outputs driven. Try this:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    DIRB = %1111
    
    here:
    OUTB = %1111
    PAUSE 1000
    GOTO here
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows

    links:
    My band's website
    Our album on the iTunes Music Store
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2006-07-01 04:47
    ' Test
    DIRB = %1111   '<---- first turn direction of pins to output
    OUTB = %1111
    STOP   '<---- STOP keeps Stamp awake; END puts it to sleep.
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • EmissionEmission Posts: 15
    edited 2006-07-01 08:03
    The DIRB directive was all I needed, I even used END and the LED's stayed lit. Found the problem smile.gif , thanks guys. Here's the prototype coding for a single digit:

    ' {$STAMP BS2}
    ' Single Digit Binary Clock
    
    idx     VAR     Nib
    binval  VAR     Nib
    
    DIRB = %1111
    
    CLK_SEQ
      FOR idx = 0 TO 9
        LOOKUP idx, [noparse][[/noparse]%0000, %0001, %0010, %0011, %0100, %0101, %0110, %0111, %1000, %1001], binval
          OUTB = binval
          PAUSE 998
      NEXT
    GOTO CLK_SEQ
    



    Man, without your help id be so lost, but look, I reduced those gymnastics to 8 lines of efficient code. The Pause phase will be replaced by a counter that keeps track of the time and convert the decimal values to binary coding for the display. Its looking a lot easier now that I have this down-pat. I'll get back to you guys when I have the final coding written out.
  • SSteveSSteve Posts: 808
    edited 2006-07-02 01:47
    This line:
    LOOKUP idx, [noparse][[/noparse]%0000, %0001, %0010, %0011, %0100, %0101, %0110, %0111, %1000, %1001], binval
    

    has exactly the same effect as
    binval = idx
    

    so your code can be reduced to this:
    ' {$STAMP BS2}
    ' Single Digit Binary Clock
    
    idx     VAR     Nib
    binval  VAR     Nib
    
    DIRB = %1111
    
    CLK_SEQ
      FOR idx = 0 TO 9
          OUTB = idx
          PAUSE 998
      NEXT
    GOTO CLK_SEQ
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows

    links:
    My band's website
    Our album on the iTunes Music Store
  • EmissionEmission Posts: 15
    edited 2006-07-02 03:26
    Heres my revised program code for the entire clock:

    ' {$STAMP BS2}
    ' HH:MM Binary Format LED Clock
    
    mincyc0        VAR    Byte
    mincyc1        VAR    Byte
    hrcyc0         VAR    Byte
    hrcyc1         VAR    Byte
    hrcyccheck     VAR    Byte
    
    DIRS = %1111111111111111
    
    INIT_VAL
      hrcyc1 = 1
      hrcyc0 = 2
      OUTH = %00010010
      hrcyccheck = 12
    
    START
    PAUSE 59984
    
    MIN_CYC0
      mincyc0 = mincyc0 + 1
      OUTA = mincyc0
      IF mincyc0 = 10 THEN MIN_CYC1
    GOTO START
    
    MIN_CYC1
      mincyc0 = 0
      mincyc1 = mincyc1 + 1
      OUTB = mincyc1
      IF mincyc1 = 6 THEN MIN_CLR
    GOTO START
    
    MIN_CLR
      mincyc1 = 0
      GOTO HR_CYC0
    RETURN
    
    HR_CYC0
      hrcyc0 = hrcyc0 + 1
      hrcyccheck = hrcyccheck + 1
      OUTC = hrcyc0
      IF hrcyc0 = 10 THEN HR_CYC1
      IF hrcyccheck = 13 THEN HR_CLR
    GOTO START
    
    HR_CYC1
      hrcyc0 = 0
      hrcyc1 = hrcyc1 + 1
      OUTD = hrcyc1
    GOTO START
    
    HR_CLR
      hrcyccheck = 1
      hrcyc0 = 1
      hrcyc1 = 0
    GOTO START
    
    



    The INIT_VAL line tells the clock to start at 12:00 (hrcyc1 = 1 & hrcyc0 = 2, hrcyccheck is the checking system). The hrcyccheck variable is used to check to make sure the clock rolls over to 01:00 when the clock reaches 12:59:59. This code takes up a mere 6% of EEPROM but if you can shorten this code, feel free. The clock works %100 to my knowledge (the right LED's light up at the right time), but there might be one or two bugs that I haven't noticed. I went through and wrote the program fairly quickly so im not %100 sure. I'll get back to you guys with the final pictures of the working clock yeah.gif .

    By the way, that project that chris is doing, he's cheating a little by using a time keeper IC and other IC's. I did the entire functions of my clock within the BS2, the only external circutry consists of the LED's.

    Now that this project is consdered DONE, I'm gonna go revise Chris's project a little devil.gif . You can see that i'm getting better at this programming stuff yeah.gif .

    Post Edited (Emission) : 7/2/2006 5:48:07 AM GMT
  • SSteveSSteve Posts: 808
    edited 2006-07-02 05:35
    Emission said...
    This code takes up a mere 6% of EEPROM but if you can shorten this code, feel free.

    MIN_CLR
    mincyc1 = 0
    GOTO HR_CYC0
    RETURN


    HR_CYC0
    hrcyc0 = hrcyc0 + 1

    You can leave out the lines in red.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows

    links:
    My band's website
    Our album on the iTunes Music Store
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-07-02 06:02
    Emission -

    Please don't be to quick to judge one persons project over another. Let me assure you, Chris isn't cheating by using an external IC for his clock. Since none of the PBASIC Stamps have an accurate timebase built-in, the only proper way to keep time, and have alarms is with an external IC.

    You will find that the longer your program operates the more INACCURATE it will become. Additionally, the solution Chris has chosen will be much more accurate over varied temperatures, as well as over longer periods of time.

    Add to that the ability to set and reset the exact time which Chris has, and you do not. Moreover, Chris has the date handy as well, and you do not. Last is the issue of daylight savings time (if that is applicable to you) and year 2000 compatibility (Y2K).

    If you were to change the resonator on the Stamp to a crystal, you might end up with a more accurate timebase, but you'd still have the other "features" to contend with.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->

    Post Edited (Bruce Bates) : 7/2/2006 6:29:15 AM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-07-03 05:58
    And to add to what Bruce said (Thanks) if the power goes out, the time keeps on ticking, thanks to that battery backup...· =)


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • EmissionEmission Posts: 15
    edited 2006-07-28 14:12
    I understand that doing timekeeping through the stamp itself leaves a lot of room for inaccuracy, and it was a bit of a selfish comment, but I just wanted to present the idea of having a single chip manage many features without the use of external hardware (and thus saving money, even though, probably not a LOT). I do like the project though, and im gonna look into ways that it can be improved smile.gifturn.gif .
Sign In or Register to comment.