Shop OBEX P1 Docs P2 Docs Learn Events
This Project is almost Done (Resloved Save Data to DS1302 Time Chip)Thank You f — Parallax Forums

This Project is almost Done (Resloved Save Data to DS1302 Time Chip)Thank You f

sam_sam_samsam_sam_sam Posts: 2,286
edited 2009-07-04 19:59 in General Discussion
Hi EveryOne

This is a project that I have been ·ask to do·by employer

As of right now I can not give all of the details.......................
................·but when the Project is done I will share with all of you on the Forum


I know that I have·Tis a another Post but this is a different question
http://forums.parallax.com/showthread.php?p=804156

What I want to do is each time the user stop using the Product it saves it to the DS1302 Chip until the user
Start again·to keep track of how much product is left in the SILO in case the power gose OFF

I try to a few time to get this to work but no luck so far

Dose any one have a routine that they can share with me·· smile.gif
·



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

·
·
·
·
Sam

Post Edited (sam_sam_sam) : 7/4/2009 8:13:42 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-02 14:50
    Have you looked at Nuts and Volts Column #33. There are subroutines shown there that write data to and read data from a DS1302 location. The same routines can be used for the DS1302 RAM, just use the appropriate address. Look at the datasheet for the DS1302 for details.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-05-02 20:07
    Mike

    Thank You for your reply

    I want to save the Data from this routine to the DS1302· Time Chip

    do it the same way that you put data to a serial LCD display in the[noparse][[/noparse] bracket ]

    ·

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

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 5/3/2009 10:34:32 PM GMT
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-05-03 22:31
    I been working on this all afternoon and getting no where

    Can someone help me with this

    I must be having brain failure or something

    I just can not·see·what wrong·with what·I am trying to do



    Metered:

    DEBUG CR,CR, DEC5 ? Silo
    DEBUG CR, CR, DEC5 ? product , DEC5 ?· minutes


    'Silo = Product (- 1)

    product = minutes */435

    ·IF oldmins <> mins THEN
    ·oldmins = mins
    minutes = minutes + 1
    silo = silo + 1
    ENDIF


    WriteRam:······································································· ·'Write to DS1302 Ram
    · reg = WrRam | (Reg << 1)················································ ' RAM Write Mode + Address
    · HIGH CS1302Pin····························································· ·' Select DS1302
    · SHIFTOUT Dta1302Pin, Clk1302Pin, LSBFIRST, [noparse][[/noparse]reg, ioByte]
    LOW CS1302Pin······························································· ·' Deselect DS1302




    ReadRam:···································································· ·'Read From DS1302 Ram
    · reg = RdRam | (Reg << 1)············································ ·' RAM Read Mode + Address
    · HIGH CS1302Pin························································· ·' Select DS1302
    · SHIFTOUT Dta1302Pin, Clk1302Pin, LSBFIRST, [noparse][[/noparse]reg]
    · SHIFTIN Dta1302Pin, Clk1302Pin, LSBPRE, [noparse][[/noparse]ioByte]
    LOW CS1302Pin··························································· ·' Deselect DS1302

    ·WriteRam:········································································ ·'Write to DS1302 Ram
    · reg = WrRam | (Reg << 1)················································ ' RAM Write Mode + Address
    · HIGH CS1302···································································· ·' Select DS1302
    · SHIFTOUT DataIO, Clock,LSBFIRST, [noparse][[/noparse]reg, ioByte]
    · SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]WrBurst]
    · SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]Product,Silo,temp,temp,temp,temp,temp, 0]
    LOW CS1302········································································ ' Deselect DS1302
    RETURN


    ReadRam:······································································· ·'Read From DS1302 Ram
    · reg = RdRam | (Reg << 1)············································· ' RAM Read Mode + Address
    · HIGH CS1302································································ ·' Select DS1302
    · SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]reg]
    · SHIFTIN· DataIO, Clock, LSBPRE, [noparse][[/noparse]ioByte]
    · SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]RdBurst]
    · SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]Product,Silo,temp,temp,temp,temp,temp]
    LOW CS1302


    · RETURN


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

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 5/3/2009 10:44:59 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-03 22:58
    How about explaining what works and what doesn't work. You might also add more DEBUG statements to show what the program is doing.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-05-03 23:33
    Mike Green

    How about explaining what works and what doesn't work

    I am not able to save the Product·or Silo data to the DS1302

    The other Routines·works just the way I want them to work


    You might also add more DEBUG statements to show what the program is doing.

    How do I only read the Ram Data that is saved in the DS1302 Chip




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

    ·
    ·
    ·
    ·
    Sam
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-05-04 00:47
    Hi Sam, the constants RdBurst and WrBurst have the wrong values in your code , they should be $FF and $FE respectively.

    Jeff T.
  • vaclav_salvaclav_sal Posts: 451
    edited 2009-05-04 01:16
    Hint
    Insert DEBUG after reg , you are missing bit 0 = 1 for read



    ·WriteRam:········································································ ·'Write to DS1302 Ram
    · reg = WrRam | (Reg << 1)················································ ' RAM Write Mode + Address

    · DEBUG HEX ? reg

    · HIGH CS1302···································································· ·' Select DS1302
    · SHIFTOUT DataIO, Clock,LSBFIRST, [noparse][[/noparse]reg, ioByte]
    · SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]WrBurst]
    · SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]Product,Silo,temp,temp,temp,temp,temp, 0]
    LOW CS1302········································································ ' Deselect DS1302
    RETURN


    ReadRam:······································································· ·'Read From DS1302 Ram
    · reg = RdRam | (Reg << 1)············································· ' RAM Read Mode + Address

    · DEBUG HEX ? reg

    · HIGH CS1302································································ ·' Select DS1302
    · SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]reg]
    · SHIFTIN· DataIO, Clock, LSBPRE, [noparse][[/noparse]ioByte]
    · SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]RdBurst]
    · SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]Product,Silo,temp,temp,temp,temp,temp]
    LOW CS1302


    · RETURN
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-05-04 02:05
    Hi , perhaps I am misunderstanding the read /write burst method but I didn't think you could specify an address for burst mode.
    I was under the impression it always read and wrote from address zero upward to 30. If my thoughts are right then it also means that burst mode might not be the best method to record production records as each record would overwrite the previous.
    So taking out the address specifier I would write the code as follows for burst.
    WriteRam:
      reg = WrBurst   '$FE
      HIGH CS1302
      SHIFTOUT DataIO, Clock,LSBFIRST, [noparse][[/noparse]reg]
      SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]Product,Silo]
      LOW CS1302
    RETURN
     
    ReadRam:
      reg = RdBurst    '$FF
      HIGH CS1302
      SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]reg]
      SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]Product,Silo]
      LOW CS1302
    RETURN
    

    ·If the objective is to maintain several records in the DS1302 RAM then I would not use burst mode in this program.

    Jeff T.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-05-04 04:02
    Jeff T. and Mike Green

    Thank You For reply s

    But I can not get this to work

    All·I get when power is removed is····· ·128

    Then starts at 00000·· for all Data results

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

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 5/4/2009 4:10:06 AM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-05-04 15:32
    WriteRam:                                                                         'Write to DS1302 Ram
      reg = WrRam | (Reg << 1)                                                 ' RAM Write Mode + Address
      HIGH CS1302Pin                                                               ' Select DS1302
      SHIFTOUT Dta1302Pin, Clk1302Pin, LSBFIRST, [noparse][[/noparse]reg, ioByte]
    LOW CS1302Pin                                                                 ' Deselect DS1302
     
    ReadRam:                                                                      'Read From DS1302 Ram
      reg = RdRam | (Reg << 1)                                              ' RAM Read Mode + Address
      HIGH CS1302Pin                                                           ' Select DS1302
      SHIFTOUT Dta1302Pin, Clk1302Pin, LSBFIRST, [noparse][[/noparse]reg]
      SHIFTIN Dta1302Pin, Clk1302Pin, LSBPRE, [noparse][[/noparse]ioByte]
    LOW CS1302Pin  
    
    

    These look like routines from some sample code I wrote.· Perhaps to make things simpler you could try something like:

    reg = 0
    ioByte = Product
    GOSUB WriteRAM

    reg = 1
    ioByte = Silo
    GOSUB WriteRAM

    etc.· There are simpler ways to write this, but this might be easier to understand.· When you call WriteRAM reg needs to contain the target address and ioByte needs to contain the data to be written.· I hope this helps.· take care.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-05-04 15:36
    Hi Sam, after taking another look at your Silo code I'm thinking you are keeping track of the usage of one silo only . So burst mode is feasible for this project.

    Not completely sure how your doing all this but I did notice that "Product" and "Silo"·are word values , so you need to be writing Product.HighByte and Product.LowByte to RAM and the same with Silo

    SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]Product.HighByte,Product.LowByte,Silo.HighByte,Silo.LowByte]

    Jeff T
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-05-04 17:56
    Jeff, thanks for mentioning that...I did not look at the full code so I did not see the Word declarations.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-05-04 18:13
    @Chris , I believe the code is based on a combination of codes from yourself and Beau , Sam gives credit to this in his comments. The code works fine and Sam just needs to clean up the finer points for his own application.

    @Sam , just keep trying the suggested modifications Sam and post back with your observations .

    Jeff T.

    EDIT: Sam I am adding a small piece of code that writes two word values to RTC Ram and then reads them back , just make sure I have the pin assignment correct for your setup.


    Post Edited (Unsoundcode) : 5/4/2009 6:47:52 PM GMT
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-05-04 21:39
    Unsoundcode

    Thank You for your help with this Project
    I start to think that I was losing it last night trying to get this to work

    I have try ed before to get this to work with no luck but it was·not importance enough to get it to work until now

    Thanks again for your help

    ··Chris Savage

    Thank You for your help as well

    I will use this when I do not need to save it as a WORD






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

    ·
    ·
    ·
    ·
    Sam
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-05-05 01:04
    Unsoundcode or Chris or anyone else

    This routine work as you see it

    But when I add Get_Time Routine It is wiped out
    How do I fix this problem

    ·DS1302_Ram_Save_Demo .BS2

    DataIO······ ··· PIN··· 4·············· ' DS1302.6
    Clock·········· · PIN··· 3············· ' DS1302.7
    CS1302········· PIN··· 5·············· ' DS1302.5


    Product········ VAR·· ·Word
    Silo·············· VAR··· Word
    reg·············· VAR··· Byte


    DO

    GOSUB RdRam
    product = product + 1
    silo = silo + 1·······
    GOSUB WrRam
    PAUSE 200


    LOOP
    WrRam:
    · reg = $FE
    · HIGH CS1302
    · SHIFTOUT DataIO, Clock,LSBFIRST, [noparse][[/noparse]reg]
    · SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]Product.HIGHBYTE,Product.LOWBYTE,Silo.HIGHBYTE,Silo.LOWBYTE]
    · LOW CS1302
    RETURN


    RdRam :
    · reg = $FF
    · HIGH CS1302
    · SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]reg]
    · SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]Product.HIGHBYTE,Product.LOWBYTE,Silo.HIGHBYTE,Silo.LOWBYTE]
    · LOW CS1302
    · DEBUG HOME, "Product = ",DEC Product,"· Silo = ",DEC Silo, CR
    RETURN


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

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 5/5/2009 2:21:49 AM GMT
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-05-05 13:40
    Hi Sam , if adding the RAM routine has upset your Get_Time routine the only thing I can think of is the constants you are using for burst mode.

    There are two values for reading in burst mode and two values for writing in burst mode. Two of these apply to the clock and two to the RAM.

    CLOCK:

    Clk_Wr_Burst CON $BE

    Clk_Rd_Burst CON $BF

    RAM:

    Ram_Wr_Burst CON $FE

    Ram_Rd_Burst CON $FF

    Jeff T.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-05-05 21:01
    Dave

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

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 5/5/2009 9:10:25 PM GMT
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-05-07 14:22
    ·Unsoundcode
    Thank You for your routine of how to save to a DS1302 Time Chip

    The problem·I was having·not being able to··save data was I was trying to save the wrong data

    P = seconds */102········ I was trying to save "P"
    ································· What I need to save was seconds instead


    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    DataIO········· PIN··· 4·············· ' DS1302.6
    Clock·········· ·PIN··· 3············ · ' DS1302.7
    CS1302·········PIN··· 5·············· ' DS1302.5

    Product VAR Word
    Silo VAR Word
    reg VAR Byte

    Silo=3456
    Product=256

    GOSUB WrRam
    GOSUB RdRam

    END

    WrRam:
    · reg = $FE
    · HIGH CS1302
    · SHIFTOUT DataIO, Clock,LSBFIRST, [noparse][[/noparse]reg]
    · SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]Product.HIGHBYTE,Product.LOWBYTE,Silo.HIGHBYTE,Silo.LOWBYTE]
    · LOW CS1302
    RETURN

    RdRam :
    · reg = $FF
    · HIGH CS1302
    · SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]reg]
    · SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]Product.HIGHBYTE,Product.LOWBYTE,Silo.HIGHBYTE,Silo.LOWBYTE]
    · LOW CS1302
    · DEBUG "Product = ",DEC Product,"· Silo = ",DEC Silo
    RETURN

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

    ·
    ·
    ·
    ·
    Sam
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-05-07 14:27
    Here is the Routine Also most Done

    When I·done with this project I will Post it

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

    ·
    ·
    ·
    ·
    Sam
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-07-04 19:59
    This Project is all most done still doing some testing and have found a little bug that I fix to day

    Maybe some time this week if some people at work have time to mount the back plate so I can put up the controller

    And I see that it alright it will take some photo of the controller and post them

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

    ·
    ·
    ·
    ·
    Sam
Sign In or Register to comment.