Shop OBEX P1 Docs P2 Docs Learn Events
How is this done? — Parallax Forums

How is this done?

idbruceidbruce Posts: 6,197
edited 2011-05-05 14:21 in Propeller 1
lllllllllllllllllllllllllll

Comments

  • ElectricAyeElectricAye Posts: 4,561
    edited 2011-01-12 20:35
    What do you mean by "join"? Are you talking about making a string variable out of them?
  • idbruceidbruce Posts: 6,197
    edited 2011-01-12 20:36
    I am saying that DigitsJoined is RETURN'ed with a value of 00(FirstDigitSecondDigit)

    Do I need it to be a string to accomplish this?
  • JonnyMacJonnyMac Posts: 9,233
    edited 2011-01-12 20:46
    Easy peasy
    pub join(tens, ones)
    
      return tens * 10 + ones
    

    You may recall that in one of your other threads I demonstrated how to read a decimal number from the keyboard you're working with.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-01-12 20:46
    Ditto ElectricAye's question ... What do you mean by "join"?

    Do you mean to do something like: FirstDigit * 10 + SecondDigit

    Do you mean to do something like: (SecondDigit + "0") << 8 + (FirstDigit + "0")

    How about the other way around: (FirstDigit + "0") << 8 + (SecondDigit + "0")

    I'm sure I could figure out other equally valid ways. Which do you want?
  • idbruceidbruce Posts: 6,197
    edited 2011-01-12 20:51
    JonnyMac
    return tens * 10 + ones

    Mike Green
    Do you mean to do something like: FirstDigit * 10 + SecondDigit

    That is what I am doing now and it isn't working.

    For instance, if the first digit is 0, 0* 10 = 0, if the second digit is 7, 0 * 10 + 7 = 7 not 07

    This value will be passed to a DS1302 Real Time Clock for years, seconds, minutes, etc... These all have the potential to be 00

    Bruce
  • Mike GreenMike Green Posts: 23,101
    edited 2011-01-12 21:05
    Ah! That's useful information. The DS1302 uses BCD (Binary Coded Decimal) for its numbers with each digit represented in 4 bits, typically 2 digits per byte.

    You'd want: (FirstDigit << 4) + SecondDigit to put the most significant digit in the high order 4 bits of the byte and the least significant digit in the low order 4 bits of the byte.

    Instead of splitting out the digits, then recombining them, you could take a number from 0 to 99 and convert it to BCD like this:

    BCD := (Number / 10) << 4 + (Number // 10)
  • idbruceidbruce Posts: 6,197
    edited 2011-01-12 21:30
    Mike

    Thank you very much for that interesting piece of information. One of those things that you must know.

    Bruce
  • idbruceidbruce Posts: 6,197
    edited 2011-01-12 21:52
    Mike

    Works perfectly now. Thanks again very much.

    Bruce
  • TappermanTapperman Posts: 319
    edited 2011-04-30 13:10
    Mike Green wrote: »
    Ah! That's useful information. The DS1302 uses BCD (Binary Coded Decimal) for its numbers with each digit represented in 4 bits, typically 2 digits per byte.

    On a different note, I'm using this chip and when I use the driver from the OBEX:

    http://obex.parallax.com/objects/519/

    to store info in the chip. It takes everything but the seconds value. It never records the seconds to the chip. Any idea why?

    ... Tim
  • idbruceidbruce Posts: 6,197
    edited 2011-04-30 13:14
    Tapperman

    You will need to post your code that sets the time clock, otherwise it will just be a guess for those trying to help you.

    Bruce
  • TappermanTapperman Posts: 319
    edited 2011-04-30 13:25
    idbruce wrote: »
    Tapperman

    You will need to post your code ...

    Okay here's the snippet that sets the clock:
    PUB SetClock              '' Set clock from PC clock.
        ' important note: real time clock (DS1302) and the thermometer (DS1620) share
        ' the same clock and data lines!
      if (mode & 2) > 0 
        rtc.init( 21, 20, 19 )                          ' ports (Clock, data, chip enable)
        rtc.config                                      ' Set configuration register
        ' --------------- 
        ' when propeller sends a string "NOW" to my Excel macro, it replies with
        ' each parameter on its own line.  Year, Month, Day ... etc.
       ' Control(string) sends a string w/CR and returns a long from the PC.
       '  ----------------------------
        year   := Control(String("NOW")) - 2000         ' ask pc 4 time data
        month  := GetDec
        day    := GetDec
        dow    := GetDec
        hour   := GetDec
        minute := GetDec
        second := GetDec
        rtc.setDatetime(month, day, year, dow, hour, minute, second)    ' set clock
     
    return 
    
  • TappermanTapperman Posts: 319
    edited 2011-04-30 14:07
    idbruce wrote: »
    Tapperman

    You will need to post your code ...

    Followup information:

    Here's the VB code in excell that respons to the propeller request "NOW".
    '*****************************************************
    '*   PLX-DAQ Data Acquisition for Excel              *
    '*   Copyright 2007, Parallax Inc.                   *
    '*   PLX-DAQ is a trademark of Parallax, Inc.        *
    '*   [URL="http://www.parallax.com"]www.parallax.com[/URL]                                *
    '*****************************************************
        Case "NOW"
            Stamp.SendData Year(Now)
            Stamp.SendData Month(Now)
            Stamp.SendData Day(Now)
            Stamp.SendData Weekday(Now)
            Stamp.SendData Hour(Now)
            Stamp.SendData Minute(Now)
            Stamp.SendData Second(Now)
     
    

    I added this snippet of code inside the stamp_DataReady() method.

    ... Tim
  • TappermanTapperman Posts: 319
    edited 2011-05-02 15:34
    idbruce wrote: »
    post your code

    Well ... that being done, I'm still left with the question of why the seconds do not store in the chip? Has anyone else noticed this on the DS1302?
  • RS_JimRS_Jim Posts: 1,773
    edited 2011-05-05 07:09
    Tapperman,
    I don't have the DS1302 to test with, but a thought occurs to me that often timer chips always store 00 to the seconds value and expect a start on the minute mark to be seconds accurate.
    Jim
  • Dave HeinDave Hein Posts: 6,347
    edited 2011-05-05 07:29
    The datasheet for the DS1302 shows that seconds is written just like any other field, so you should be able to set the seconds. I would suggest testing it independent of the VB code. Maybe the VB code isn't sending the seconds correctly.
  • TappermanTapperman Posts: 319
    edited 2011-05-05 14:17
    RS_Jim wrote: »
    Tapperman,
    I don't have the DS1302 to test with, but a thought occurs to me that often timer chips always store 00 to the seconds value and expect a start on the minute mark to be seconds accurate.
    Jim

    http://datasheets.maxim-ic.com/en/ds/DS1302.pdf datasheet for this chip

    Yeah, I found this is the manual on page 6:
    When reading or writing the time and date registers, secondary (user) buffers are used to prevent errors when the internal registers update. When reading the time and date registers, the user buffers are synchronized to the internal registers the rising edge of CE.

    The countdown chain is reset whenever the seconds register is written. Write transfers occur on the falling edge of CE. To avoid rollover issues, once the countdown chain is reset, the remaining time and date registers must be written within 1 second.

    I was just hoping that someone else would tell me thier chip DOES record the seconds value. And I just have a bad chip perhaps?

    ... Tim
  • TappermanTapperman Posts: 319
    edited 2011-05-05 14:21
    Dave Hein wrote: »
    I would suggest testing it independent of the VB code. Maybe the VB code isn't sending the seconds correctly.

    No ... I thought of that ... and the values passed by VB are all there ... and even if I try to set the value hard coded to '30' seconds (lets say) ... the result is the same.

    Im thinking about trying it in 'burst' mode? Perhaps that might do the trick.

    ----[ a little while later]

    nope ... that didn't work either.

    I'm wondering ... is anyone else confused by this paragraph out of the datasheet:
    The countdown chain is reset whenever the seconds register is written. Write transfers occur on the falling edge of CE. To avoid rollover issues, once the countdown chain is reset, the remaining time and date registers must be written within 1 second.

    What do they mean by countdown chain? Could this be an issue?

    ... Tim
Sign In or Register to comment.