Shop OBEX P1 Docs P2 Docs Learn Events
DS1302 Timekeeper-Using Modulus Operator With BCD — Parallax Forums

DS1302 Timekeeper-Using Modulus Operator With BCD

MikerocontrollerMikerocontroller Posts: 310
edited 2010-01-02 03:37 in BASIC Stamp
· I'm using the DS1302 timekeeper chip and would like to detect when the minutes = 15, 30, and 45.
I tried:

·IF minutes//15=0 THEN Do_Something

· This doesen't work with binary coded decimal.· What formula can I use?

Comments

  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2010-01-01 05:19
    I send you a PM

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

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 1/1/2010 5:34:13 AM GMT
  • MoskogMoskog Posts: 554
    edited 2010-01-01 10:57
    Hey, Sam, please post your solution here too, in case others do have the same sort of problems!

    By the way, Happy new year!
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2010-01-01 18:52
    The most general solution is,

    IF minutes.nib1*10+minutes.nib0//15=0 THEN Do_Something

    That is true also when minutes=0, which was not in your list. Another conditional needed?

    On the subject of BCD and the modulus // operation. Here is a little mathematical quirk. If minutes is in BCD form, it is obvious that
    IF minutes//2=0 THEN Do_Something
    will work, because an even number is even no matter how you convert it. It is also true
    IF minutes//3=0 THEN Do_Something
    and
    IF minutes//6=0 THEN Do_Something
    will work with minutes left in BCD form. It so happens that BCD and Decimal are congruent both mod 2 and mod 3.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • MikerocontrollerMikerocontroller Posts: 310
    edited 2010-01-01 19:10
    The idea is to declare minutes as a byte variable. Multiply the highest 4 bits by 10. Add that to the lowest 4 bits of the minute byte. The result can be divided by your interval value and if the remainder=0 AND seconds =0 THEN perform an action. I used 15 as my interval value. The Action is performed at 0, 15, 30, and 45 minutes.

    minutes VAR Byte
    seconds VAR Byte

    IF (minutes.HIGHNIB*10+minutes.LOWNIB//15=0) AND (seconds=0) THEN GOSUB Perform_An_Action

    Of course whatever action is taken should take at least a second or the action will be performed multiple times as long as (seconds=0)

    ··· Sorry Tracy I did'nt know you posted........................................blush.gif
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2010-01-02 03:37
    That's a good point about the action being performed multiple times while the condition is met. The condition with seconds=0 is good, or a toggle so that the condition has to go back to being not true before it can be triggered again.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.