Shop OBEX P1 Docs P2 Docs Learn Events
DS1302 Object Output — Parallax Forums

DS1302 Object Output

GCXGCX Posts: 3
edited 2008-07-05 16:40 in Propeller 1
Hello guys, I'm totally newbie with the spin programming and so the question might be really dumb but anyways...
For the newest project I need to compare the current time (hour particularly) with certain decimal values like "if hour > 12" but, as I understand, the "readTime" method in the DS1302 object from OBEX returns binary values. So, how should I convert them to decimal? The second question is: I've compared the "config" method settings with the ds1302 datasheet and seems that it's set to 24-hour scheme (which I actually need), is that correct?
Thanks very much.

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-07-03 14:32
    GCX,

    A value stored in a memory location is not inherently stored as Decimal or Hex, it is always stored as a binary number. When we display it in decimal we are choosing to format the output to view the value in that manner, same as Hex. So if the hour is 12 it won’t matter whether it is in Binary or Decimal format…the variable will contain the value 12. Now if it was a formatted value then the format would make a difference, but this would only be possible if the value was BCD or string. I would try displaying the returned value as if it were decimal.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Forest GodfreyForest Godfrey Posts: 38
    edited 2008-07-03 20:27
    In this case, GCX actually meant Binary Coded Decimal (BCD), not binary. The DS1302 internally does BCD representation, which is great until you want to actually do comparisons.... When I originally downloaded the 1302 driver object, it was returning BCD values. It appears, however, that the newer object now does the BCD conversion for you so you don't have to deal with it.
  • GCXGCX Posts: 3
    edited 2008-07-03 20:34
    Thanks for replies. Well, it doesn't seem to return decimal values and it still uses private method 1302_to_bin for returning of the current time. At least, simple statement like

    if heure > 10
    outa[noparse][[/noparse]0]~~

    wouldn't work. So is there a way to bring those values to decimal format?
    Forest, did you also had to evaluate the current time in decimal presentation?
  • Forest GodfreyForest Godfrey Posts: 38
    edited 2008-07-04 02:56
    I had to convert from BCD to Decimal, which is what the 1302_to_bin() routine does. The "if hour >10" should certainly work, even if it were still in BCD.

    Do you have any way to hook up an output device (a VGA, TV, or serial LCD)? If so, hook it up and print the values in hexadecimal. If they look like this: $0, $1, $2, ...$9, $a, $b, $c then the output is unformated, normal, numbers. If they are $0, $1, ... $9, $10, $11, $12 then you are in binary-coded-decimal.

    One other thing to check for - the 1302 can run in either 12 or 24 hour mode. Make sure that you are running the chip in the mode you thought you were....
  • hippyhippy Posts: 1,981
    edited 2008-07-05 03:16
    Forest's "1302_to_bin()" is probably what you need and for a two digit BCD to decimal conversion that code will be something like ...

    decimalVal := ( bcdVal / 16 * 10 ) + ( bcdVal & $F )
  • GCXGCX Posts: 3
    edited 2008-07-05 08:03
    First of all, 12 or 24 hour mode is not the issue - it doesn't work with minutes either, and the hour register shouldn't affect the minutes one. I'll hook up the serial LCD on monday so I could monitor the operation. So, I guess, the problem is with the presentation of values.

    Hippy, I've already tried that one and it didn't work, which is really strange.
  • hippyhippy Posts: 1,981
    edited 2008-07-05 16:40
    Very odd. Are there other bits being set in the BCD byte which comes back from the 1302 ? I don't have any experience of it. You could try ...

    decimalVal := ( ( bcdVal & $7 ) / 16 * 10 ) + ( bcdVal & $F ) ' For 0..59 BCD
    decimalVal := ( ( bcdVal & $3 ) / 16 * 10 ) + ( bcdVal & $F ) ' For 0..23 BCD
    decimalVal := ( ( bcdVal & $1 ) / 16 * 10 ) + ( bcdVal & $F ) ' For 0..12 BCD

    Have you checked what the raw binary data values are which come back ? If it's I2C but not being correctly addressed all data can end up as $FF.
Sign In or Register to comment.