Shop OBEX P1 Docs P2 Docs Learn Events
How to use a ping sensor and a DS1302 chip — Parallax Forums

How to use a ping sensor and a DS1302 chip

sam_sam_samsam_sam_sam Posts: 2,286
edited 2006-02-25 02:09 in BASIC Stamp
HI every one

I·am at·it agian whith another project hop.gif


I want to use a ping sensor and a DS1302
What i have learned with the·DEBUG DEC
command is that·the line in the code·that
says

DEBUG DEC seconds.HIGHNIB,·second.LOWNIB

·How i use this as a time base to have a outputs turn
ON & OFF at diffrent times

·Would i use these (seconds.HIGHNIB,·second.LOWNIB)
as my time base or someting else

Can any one help with this
THANKS TO ANYONE THAT CAN HELP

The code that i am using is in the ATTACHMENT

SAM

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-18 00:03
    Sam,

    ·· Why couldn't you just use seconds?· What exactly are you trying to do?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2005-09-18 00:23
    CHRIS

    Could you show me how to that

    That was why i post it i do not how to write the code for it

    ·Iwas tring to earlyer and was not getting any where

    THANKS FOR ANY HELP·YOU CAN GIVE ME IN THIS MATTER

    SAM
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-18 00:31
    Sam,

    ·· What I was saying is that you're trying to break the variable seconds up into LOWNIB and HIGHNIB, but you should just use the whole variable, seconds.

    DEBUG DEC seconds

    You still haven't stated what you're trying to do exactly.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2005-09-18 01:51
    HI CHRIS

    I tried the DEBUG DEC seconds and it dose not counts right
    IT counts like this
    0 to 50 ok then 51,52,53,54,55,58,60,61,62,63,64,65,68,71,72,73,74,75,76,77,78,79,80,
    81,82,83,84,85,86,87,88,89,09,19,29,39,40,41,42,43,44,45,46,47,48,49,50,
    51,52,53,54,55,58,60,61,62,63,64,65,68,71,72,73,74,75,76,77,78,79,80,
    81,82,83,84,85,86,87,88,89,09,19,29,39,40,41,42,43,>>>>>>> and so on

    Now when i use the DEBUG DEC second.HIGHNIB, DEC second.LOWNIB, CR

    This works ok

    In another post i ask about turning
    THREE OUTPUTS ON and OFF for different amounts of time (1) for 30 seconds
    (2) for 2 seconds (3) for 300 seconds OR MORE seconds than that

    I would like to it in seconds if i could

    THANKS FOR YOU FOR YOUR HELP IN THIS MATTER

    SAM
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-18 05:23
    Sam,

    ·· Whoops!· THat's because in trying to figure out what exactly you were trying to do, I didn't stop to think about the DS1302...Which stores it's values in BCD...Try this...

    DEBUG HEX seconds

    As for the other post I must have missed it...That's why it's important to keep everything related to a thread in the same thread so one can look back and see what it's about.· There is example code which I posted for the DS1302 already on the forums at the following thread.· That code explains how to read and display the time from the DS1302 as well as set it.

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


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com


    Post Edited (Chris Savage (Parallax)) : 9/19/2005 2:17:33 PM GMT
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2005-09-18 06:11
    ·HI CHRIS

    THANKS for the repley
    How do i write the·command code to do what i want to from the DS1302 code
    i know that the command CODE for ping is the INCHES and use·with the·
    · IF and THEN·I do not know what to use on the· DS1302 what
    is the command for this and how to put it together i··have tried to it but i· can get it to work
    I have down load the code that you are taking about but i do not understand
    how to DEBUG code as well as i do this one at lest i·some what understand the one i am using now if you where to help me understand this i would use if it will
    work better
    AND LIKE ALL WAYS SAY THANK YOU FOR HELPING IN THIS MATTER
    I have been·getting some of it·little bit here and there it·takes some time·for me to get it

    THREE OUTPUTS ON and OFF for different amounts of time (1) for 30 seconds
    (2) for 2 seconds (3) for 300 seconds OR MORE seconds than that

    I would like to it in seconds if i could

    THANKS FOR YOU FOR YOUR HELP IN THIS MATTER

    SAM·· cool.gif
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-18 18:26
    Sam,

    ·· If you're going to need counts of 300 seconds, then I will suggest you try different code for the DS1302.· Please see the StampWorks manual at the link below.· It contains code for dealing with the time in all seconds.·

    ·· My code won't work in your application because you won't be able to just use the seconds register easily for counting that high.· I could adapt it, but if you're not fluent in PBASIC programming it would easier to use the exiting code from the StampWorks guide to figure out how to do this.

    http://www.parallax.com/detail.asp?product_id=27220

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-09-19 13:27
    Actually, the 1302 stores its values in Binary Coded Decimal (BCD). This is a funny way to use Hex.
    And, that's why you have to use "HighNib" and "LowNib" to get the values -- each Nib counts 0..9.

    So, (in hex) it counts like:
    0x0,0x01,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20

    If you convert that directly to decimal, you get
    0,1,2,3,4,5,6,7,8,9,16,17,18,19,20, etc.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-19 14:27
    Allan,
    ·· Deja Vu...I found myself once saying the same thing to the last person who was posting DS1302 code..Anyway, I corrected my one typo, but what I meant to·convey was that you do not need to display them or deal with them using HIGHNIB and LOWNIB.· You can display the seconds register directly using the HEX modifier.·

    The following clip demonstrates this:
      IF (modeFlag = Hr24) THEN             ' Check For 24 Hour Display mode
        DEBUG HEX2 hrs, ":", HEX2 mins, ":", HEX2 secs
      ELSE
        DEBUG HEX2 hrs, ":", HEX2 mins      ' Print Hours/Minutes
        IF ampmFlag = 0 THEN
          DEBUG "AM"
        ELSE
          DEBUG "PM"
        ENDIF
        DEBUG " [noparse][[/noparse]", HEX2 secs, "]"
      ENDIF
    
    

    You can adjust and calculate by doing a quick conversion to decimal, which can be done quite easily.

    Now, as for StampWorks...Jon's code in that includes a function to convert the time into all seconds (1440 in a day) so you could easily do timing of events.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-09-19 14:33
    True, you can DISPLAY them using the HEX2 modifier -- Hour 12 will "look like" 12 when printed using HEX2.
    However, it is NOT a 'value' 12 -- If I use it as a 'value', 12 hex is actually 18.

    So there may need to be some BCD to binary conversion there, typically using HIGHBYTE and LOWBYTE.

    And while you SAY there's a "quick conversion" to Decimal, you don't say what it IS. That might be nice, especially if it's short.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-19 14:37
    These are subroutines from one of my own clock projects...Routines are here for converting both ways...
    BCD_Decimal:
      counter = (counter.NIB1 * 10) + counter.NIB0
      RETURN
                                    ' Convert BCD To Decimal
    Decimal_BCD:
      counter = (counter / 10 << 4) + (counter // 10)
      RETURN 
    

    And the need for the seconds in a readable value is why I suggested the code in StampWorks, which would allow you a resolution of 1440 seconds/day you could read as a useable value.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2005-09-21 04:26
    Hi CHRIS
    THANKS FOR THE POST
    I will try this over the weaken

    SAM
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-21 14:24
    Just for clarification, you would replace the variable counter with the name of the variable you're trying to convert.·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2005-09-24 07:44
    HI CHRIS
    Or any one else
    I have some code that i am using to turn and ON &OFF at diffrent times
    i have firgut out this much out so far
    ·IF INCHES > 70 then HIGH 2
    IF SECONDS.HIGHNIB = $30 AND SECONDS.NIB = $00 THEN LOW 2
    I can·turn the output#2 on & off at time i want and that work fine
    What i what to ask is that·do i·have to turn the·power off on·the DS1302
    chip·to restart the timer or how would you start timer·at 00:00
    ·with code can it be done this way

    (1)·IF INCHES > 70 then HIGH 2

    (2)·IF INCHES > 70 then HIGH 3

    (3)·IF SECONDS.HIGHNIB = $30 AND SECONDS.NIB = $00 THEN LOW 2
    Stays on for 30 seconds··

    (4)·IF MINUTES.HIGHNIB = $30·AND MINUTES.LOWNIB = $00·AND SECONDS.HIGHNIB = $00 AND SECONDS.LOWNIB = $00 THEN LOW 3
    Stays on for 3 minutes
    ...................................................................................................
    ·(5) timer returns to 00:00
    THEN starts over to line one and waits
    This part i do not know where to start now i could have a relay turn off the
    power to the chip for one second and that would restart it to 00:00
    I·did not want to do it that way if i do not have to
    ...................................................................................................
    Also is there a better way to do this
    This is what have come up with so far is there anyone that can help
    samburger.gif

    I CHRIS

    Post Edited (sam_sam_sam) : 9/24/2005 8:32:58 AM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-24 22:06
    Sam,

    ·· You're still trying to use HIGHNIB and LOWNIB.· And you're testing for values in them like $30.· A nibble can not be $30.· A nibble can only hold a value between 0 and 15 ($00 to $0F in Hex).· In BCD the highest value will be 9 ($09).· If you're testing for a specific number of seconds, I don't understand why you're not just reading the entire variable "seconds"?·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2005-09-29 02:28
    HI Chris
    HI everone
    This was in one of your post( inpart)
    Just for clarification, you would replace the variable counter with the name of the variable you're trying to convert.
    These are subroutines from one of my own clock projects...Routines are here for converting both ways...
    ...............................................................................................................
    BCD_Decimal:
    ·' counter = (counter.NIB1 * 10) + counter.NIB0
    ' This is what i used and it only counts to 60 then return's to 00
    Am i missing something
    ·· counter = (secs.NIB1 * 10) + secs.NIB0
    · RETURN
    ······························· ' Convert BCD To Decimal
    .....................................................................................................................
    ' How do i convert the time into all seconds (1440 in a day) so you could easily do timing of events.
    (Also inpart)·············
    And the need for the seconds in a readable value is why I suggested the code in StampWorks, which would allow you a resolution of 1440 seconds/day you could read as a useable value.
    I did read this and how to i do not understand all of it
    Where is this at i was looking for· and could not find it
    Please show me what part· converts the time into all seconds (1440 in a day) and displays " (1440 in a day) " in code please
    ·So i can understand this i want to learn this
    ·I am lost
    Now, as for StampWorks...Jon's code in that includes a function to convert the time into all seconds (1440 in a day) so you could easily do timing of events.
    Also could you show·me in code· and·explain·how this works
    ·I know how A OUTPUT works
    I mean the part of the code that i would use to control the output based on seconds
    This part would really help me to understand this more with a sample code and explain how it works
    THANK YOU FOR ANY HELP· THAT YOU CAN GIVE· ME IN THIS MATTER

    THANKS

    Sam

    Post Edited (sam_sam_sam) : 9/29/2005 12:22:58 PM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-29 14:12
    Okay,

    ·· First of all, I mis-quoted the number of seconds in a day.· There are 86,400 seconds in a day, which is too many for a word variable.· 1440 is the number of minutes in a day.· As for the reason I am using the NIB function in the conversion routines is that it's needed there.· But you are using HIGHNIB and LOWNIB to refer to values higher than can be in a NIB.· On top of that you don't need to deal with these values in this way when checking for elapsed time.· You just check seconds.

    IF seconds = $30 THEN
       ...your code
    ENDIF
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2005-10-01 17:26
    HI Chris
    HI EVERY ONE

    If this can be done

    Can you show me in code how to do this

    Use a resolution of 3600 seconds for an hour that you could read as a useable value.

    What do i need to change to be able to do this

    IF seconds = $30 THEN
    ...your code
    ENDIF

    I understand this and got this to work but now i need more than 60 seconds
    And how do i get a resolution 3600 instead of 60 seconds
    Code wise


    I am not useing this to keep time i just need to count the seconds for a hour and
    Once i learn how to do this i may want to do the same with minutes but one thing at a time

    Can you help me learn this

    THANKS FOR ANY HELP YOU GIVE WIH THIS MATTER


    SAM
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-10-01 18:09
    After you read the DS1302, you will have BCD values in the following variables:
    second
    minute
    hour

    Here is the number of seconds you are into the current hour, a value from 0 to 3259:
    sechour = minute.nib1 * 10 + minute.nib0 * 6 + second.nib1 * 10 + second.nib0
    Don't use parenthese. It computes strictly left to right.

    Here is the number of the minute you are into the current day, from 0 to 1439:
    minday = hour.nib1 * 10 + hour.nib0 * 6 + minute.nib0 * 10 + minute.nib0

    The number of seconds in a day is 86400, but if you can be satisfied with 2 second resolution, the number of two second intervals in a day is 43200.
    sec2day = hour.nib1*10 + hour.nib0*6 + minute.nib0*10 + minute.nib0 *6 + second.nib1*5 + (second.nib0/2)
    evenoddsec = second//1 ' even or odd second.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2005-10-01 23:44
    HI·Tracy

    THANK YOU·for your·reply in this matter
    I will try this very soon
    I·have to hook up the DS 1302 agian to test this

    THANK·YOU FOR HELP AGIAN YOU also reply to another·POST i had today


    SAM·
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2006-02-19 09:12
    HI EveryOne

    attachment.php?attachmentid=73924

    Post Edited (sam_sam_sam) : 2/19/2006 9:22:13 AM GMT
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2006-02-24 22:46
    HI every one

    I am still with this same project but now i want understand
    How to use the RAM on the DS1302
    What can you put in the RAM
    Is there a POST that has a Demo code that shows what can be done
    And how to Do it and explains it in more detail

    I post the part of the code that i do not completly understand

    What address would you use and what would you put in them

    Now this maybe asking something stupid and if that is the case
    Please for give me but i would like to learn this if i can


    ' Write RAM command = 11xxxxx0 (Uses 3 bits)
    ' Read RAM command = 11xxxxx1 (Uses 3 bits)
    ' xxxxx address (Uses 5 bits)

    I want to thank anyone that can help with this
    Sam
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-02-25 02:09
    sam,

    ·· The original DS1302 Demo Code that I pointed you to in the beginning covers using the RAM.· I have used it to store settings that I want to keep battery backed up where using the EEPROM isn't a good idea due to updating frequency.· As a side note, the reason the other codes you mentioned above didn't work was that you were comparing to Decimal values, and BCD is not a decimal value.· It is two numbers packed into a single byte, so you can't do a compare with say 12, it has to be $12.

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

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
Sign In or Register to comment.