UberNewbie can't set his clock...


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sinoteq View Post
    When does the shift command actually change the data in BCDByte?
    It is my understanding that the shift command in a case like this will not change the data.
    It only tells what part of the value to use in the calculation.
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    OK, lets break this down...

    DecimalByte=(BCDByte>>4)*10+(BCDByte & $0F)

    The calculations in the brackets will be perfomed first, and the results stored in a PICBasic variable behind the scenes. BCDByte is unchanged - just as well because we refer to it twice, once to access the top four bits, and once to access the bottom four bits.

    Thereafter, PBP follows mathematical rules of priority... ie Multiplication and Division are performed before addition ans subtraction. Because items in brackets are always calculated from the centre out, and each set of brackets is it's own self-contained world, the result of the formula below, will be the same as that above.

    DecimalByte=(BCDByte & $0F)+((BCDByte>>4)*10)

    However, you do have an extra set of brackets there... but PBP actually resolved the formula without any additional penalty. Might not be so lucky on another occasion.

  3. #3
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    Thanks again Melanie,
    Hmmm, I think I almost understand what's going on with that code. I must actually be learning something.

    I ended up with this, from the code you supplied and it works excellent.

    Code:
    increminute: 
    
            rtcmathtemp =(rtcmin>>4)*10+(rtcmin & $0F)  'convert BCD minutes into Decimal minutes
            
            rtcmathtemp=rtcmathtemp+1   'increment by 1
            If rtcmathtemp>59 then      'If minutes exceeds 59
            rtcmathtemp=0               'reset to 0
            endif
      
            rtcmin=((rtcmathtemp DIG 1)<<4)+rtcmathtemp DIG 0 'convert Decimal back to BCD
    
            gosub settime
           
            return

  4. #4
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default Sure would like to turn the trickle charger on...

    Sigh, well I seem to have a new problem. Although I'm obviously able to read/write to the DS1302 in "burst" mode, I seem to be having a problem addressing individual registers.

    For instance, I need to turn the trickle charger on...
    I *thought* it was as simple this:
    Code:
            rst = 1
    
            'Set Battery charger on and set to "1 diode, 2Kohm"
            Shiftout IO, SCLK, LSBFIRST, [$90, $A5]  ' Set charger   [$90, $A5] 
     
            RST = 0
    But that doesn't seem to do it for me.

    Anyone got the patience to help me along a little further....

    p-p-p-please?

    Thanks!

    Steve

  5. #5
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hi Steve, check uot pages5/ 6 of this data sheet, it says: DS 1302 powers up with trickle charger disabled and only a pattern of 1010 will enable charger. http://forums.parallax.com/forums/attach.aspx?a=26594 HTH
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  6. #6
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    Thanks Joe,
    You can't imagine how many times I've read the data sheet.... (it's been open on my desktop for days now)
    I'm clearly not quite understanding yet.

    Yes, a pattern of 1010 turns on the charger, and the other 4 bits of the byte set the charge rate.

    So what ( I think) I want to send is 10100101 which should tun on the charger and set it to "1 diode, 2Kohm" operation. In HEX, that's $A5, right?

    So I've sent $90, which should be the register address for the charger, and $A5, which should be the code to turn it on and set it to my chosen charge mode. I even tried sending the data in binary, like so:
    Code:
            rst = 1
    
            'Set Battery charger on and set to "1 diode, 2Kohm"
            Shiftout IO, SCLK, LSBFIRST, [$90, %10100101]  ' Set charger   [$90, $A5] 
     
            RST = 0
    but with the same (no) result.

    What am I doing wrong? (please!)

    Thanks,
    Steve

  7. #7
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    Ahh, never mind, I figured it out...

    Setting up the trickle charger is the first task task I ask of the DS1302, and I just needed to pull the reset line LOW first, before I yank it high and move the data.
    All I was missing was "rst = 0" up front:

    Code:
     
           rst = 0
           rst = 1
    
            'Set Battery charger on and set to "1 diode, 2Kohm"
            Shiftout IO, SCLK, LSBFIRST, [$90, %10100101]  ' Set charger   [$90, $A5] 
     
            RST = 0
    Thanks again to everyone!

    Steve

Similar Threads

  1. Interruptus Frustratus
    By Byte_Butcher in forum General
    Replies: 16
    Last Post: - 17th April 2009, 21:36
  2. 16F628A - Stops if release power switch.
    By dene12 in forum General
    Replies: 16
    Last Post: - 14th February 2009, 08:57
  3. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 21:36
  4. error on compiling
    By parker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th June 2005, 15:31
  5. How to set external clock source in PBP
    By TurboLS in forum mel PIC BASIC Pro
    Replies: 28
    Last Post: - 19th February 2005, 16:56

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts