Shop OBEX P1 Docs P2 Docs Learn Events
DS1302 Trickle Charge — Parallax Forums

DS1302 Trickle Charge

hmlittle59hmlittle59 Posts: 404
edited 2009-09-06 07:23 in General Discussion
Hello All,
What is missing from this code to turn on the DS1302 Trickle charge? The Super Cap.(+) is connected to pin8. The battery version of this board works. My DS1302 time setting routines work, but this one has me stumped. Thanks for any help

  TChgReg            CON     %01000        ' Trickle Charge time rate(D2R3)
'
'Next three(3) lines is at the beginning of my code
 temp3 =  TChgReg                     ' TURN ON Trickle Charge Command
 value =  01011                          ' Value for Max Charge D2R3
GOSUB WriteRTC                        ' Write Command to DS1302
'
OTHER CODE............
'
WriteRTC:                        ' Write to DS1302
  HIGH RTCCS
  SHIFTOUT Dta, Clk, LSBFIRST, [noparse][[/noparse]%0\1,temp3\5,%10\2,Value]
  LOW RTCCS
RETURN


'


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I'M STILL LEARNING SO MUCH...BUT STILL KNOW SO LITTLE!!!

hmlittle59

Comments

  • mctriviamctrivia Posts: 3,772
    edited 2009-09-02 17:53
    just so you know super caps discharge very rapidly. only hold a usable charge for about a day.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    propmod_us and propmod_1x1 are in stock. Only $30. PCB available for $5

    Want to make projects and have Gadget Gangster sell them for you? propmod-us_ps_sd and propmod-1x1 are now available for use in your Gadget Gangster Projects.

    Need to upload large images or movies for use in the forum. you can do so at uploader.propmodule.com for free.
  • hmlittle59hmlittle59 Posts: 404
    edited 2009-09-02 22:27
    Thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'M STILL LEARNING SO MUCH...BUT STILL KNOW SO LITTLE!!!

    hmlittle59
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-09-02 22:49
    mctrivia
    ·
    just so you know super caps discharge very rapidly. only hold a usable charge for about a day.

    Are you using a· 1 fard Super Cap if so YOU MUST Charge the cap with a 5 volt power supply FIRST so you get the most running time out of this cap

    with a current meter to know when your current is less than 10 milliamp then it ready to be used this need to be done before the DS1302 is installed

    I can run a week with data in the memory in the DS1302 on just the supper cap back up no power to the DS1302

    The DS1302 can not form the cap from the very low current that will allow it to use also use· about 3 volt @ 10 milliamp ·you need 5 volt @ 400 milliamp

    I hope this helps

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

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 9/2/2009 11:00:08 PM GMT
  • hmlittle59hmlittle59 Posts: 404
    edited 2009-09-03 00:52
    Thanks sam,

    Don't understand your last line, but I have my own board that has three(3) volts from a battery and that works. The way I laid out the board I can replace the Battery with the Super Cap. 5.5 v 1.0 F. This is the first time I've tested it mounted into the board and turning on the Trickle charge from software to the DS1302. My understanding when I started this design it would charge over a day or 2 it would power it for a week or so. Was my thinking/understanding wrong about this part? Have you used it this way before?

    hope this is clear, I've got to run out for now, be back in 2 hrs. thanks

    thanks for any help

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'M STILL LEARNING SO MUCH...BUT STILL KNOW SO LITTLE!!!

    hmlittle59
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-09-03 22:56
    I use the supper cap in a few Project where I used a DS1302

    When I first start using the supper cap with out charge it first

    ·I could not get it to keep· time for more·than a few minutes with out charging it·first

    Because when you hook up the supper cap to a power supply·set to 5 volts ·it show about 1 amp a drops very slowly to 500 milliamp and drop to about 100 milliamp in about a minute and down to 10 milliamp in about a minute and a half then it fully charge

    even if you drain the cap all the way down it charge very well with the DS1302 after that

    I hope that help

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

    ·
    ·
    ·
    ·
    Sam
  • Carl HayesCarl Hayes Posts: 841
    edited 2009-09-04 20:18
    sam_sam_sam said...


    I can run a week with data in the memory in the DS1302 on just the supper cap
    Wow, that's impressive.· Me, I'd need at least a lunch cap or two, and probably a breakfast cap and another couple of supper caps to run a whole week.

    But then, I'm old --

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i@arrl.net
  • hmlittle59hmlittle59 Posts: 404
    edited 2009-09-04 21:54
    Thanks Sam,

    That's not good. I've made a Custom component area that can hold either the Cap. or Battery. I'm mad at myself for never testing this before. I'm just going to design it out and save space(board and Software). The (BS2) version needs the extra Bytes/space.

    thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'M STILL LEARNING SO MUCH...BUT STILL KNOW SO LITTLE!!!

    hmlittle59
  • Carl HayesCarl Hayes Posts: 841
    edited 2009-09-04 22:20
    Really all you need is a small lithium coin cell, which will run a DS1302 for about ten years.

    Coin-cell holders occasionally lose contact very briefly under vibration, so I always put a .1 μF capacitor across the coin-cell holder.· That value of capacitance will run the DS1302 for about 100 milliseconds minimum, which is a longer time than the coin-cell holder will ever lose contact.

    That's cheap, doesn't take much space on the board, and is utterly dependable.

    If you use coin cells with solder pigtails, and solder them in, you don't need the capacitor.· Me, I hate having to unsolder something every ten years.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i@arrl.net
  • hmlittle59hmlittle59 Posts: 404
    edited 2009-09-05 01:10
    Thanks again,

    I'm using the 3vdc Coin-cell and I'll look to adding the cap. as you suggested also. I was just making the SCAP. a option on my design. Didn't like the pigtail when I looked at it.


    thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'M STILL LEARNING SO MUCH...BUT STILL KNOW SO LITTLE!!!

    hmlittle59
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-09-05 14:45
    I have to tell you something about using coin cells

    I have a data logger that has for the DS1302 Time chip

    I do not use this Data Logger but maybe 2 or 3 time a year and every time I go to use it the coin cell is DEAD so unless you have power to the DS1302 most of the time this may not work for you



    Just a Heads on this· idea.gif

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

    ·
    ·
    ·
    ·
    Sam
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-09-05 14:49
    hmlittle59
    It is very easy to save the data that you want to save on the DS1302

    Here is an example

    ' {$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 smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 9/5/2009 2:55:15 PM GMT
  • hmlittle59hmlittle59 Posts: 404
    edited 2009-09-05 17:00
    Thanks Sam,

    My board is constantly plugged in from the wall. I wrote my own Auto-boot if power is lost by checking to see if the DS1302 is running...If Running then Check Auto-Boot Flag and if on then Get Defaults/modified values from DS1302 Ram...Else load default values and go to MainMenu. I'm out of Variables and have to work a Variable from RAM some how...I'm still thinking it through. Some Variables once set I can not change...others I can use Local over and over in different parts of my code, so I'm using the RAM already.

    I'll study your code and compare to my code. thanks

    thanks again

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'M STILL LEARNING SO MUCH...BUT STILL KNOW SO LITTLE!!!

    hmlittle59
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-09-05 19:09
    Re use the var that are not need in your code If you post we come up with some thing

    I just had to the same thing in this project

    In these two routine PD VAR·is used in both places for two different thing altogether the one thing is that you can run these to routine together
    at the same time

    If you need to name it two different names
    then here is how you do that

    PD·· VAR· ·WORD
    RC·· VAR· ·PD

    X was the value that I need to save in the RC_Re_Set Routine and in the Metered Routine I need to save The PD Value

    ·x.BIT0(J)=PD/RC_diff

    In my case at lease so far I do not need to save The RC value so just used the PD VAR
    ·
    And if you need to save· the RC Value in The DS1302 Now you can

    RC_Re_Set:············································ · ' This Routine Sets Flow Rate
    ·· DO· WHILE Chg_P = 1 AND Chg_S = 1······ · ' Range is 1.000 to 1.999
    ·· HIGH LED_1
    ·· SEROUT LCD, Baud, [noparse][[/noparse]DispLightOn]
    ·· SEROUT LCD, Baud, [noparse][[/noparse]Clearscreen]
    ·· GOSUB ReadRam
    ··· HIGH RC_Set···································· ·· ' charge the cap
    ··· PAUSE 1············································ ·' for 1 ms
    ··· RCTIME RC_set, 1, PD························· · ' measure RC discharge time
    ··· HIGH RC_Set
    ···· PD = PD - RC_min MAX RC_diff············ · ' Make sure PD falls within range of the CONstants
    ··············································· ' ---- binary division loop ----
    ··· FOR J=15 TO 0·································· ·' 16 bits·· NOTE:· J only needs to be a NIB
    ····· PD=PD//RC_diff<<1························· · ' remainder*2 <--- note the divisor is constant, PD dividend is reduced directly
    ····· x.BIT0(J)=PD/RC_diff························ ·' next bit·· <- using x for the quotient
    ···· NEXT
    · LOW LED_1
    · SEROUT LCD, Baud, [noparse][[/noparse]LineOne0,·····" YOU ARE IN "]
    · SEROUT LCD, Baud, [noparse][[/noparse]LineTwo0,··· " FLOW RATE SET UP"]
    · SEROUT LCD, Baud, [noparse][[/noparse]LineThree0,· "······ 1.", DEC3 x** 1000]
    · SEROUT LCD, Baud, [noparse][[/noparse]LineFour0,·· " ADJ POT CONTROL "]
    ···· PAUSE 1000
    ···· GOSUB WriteRam
    · LOOP
    ·· LOW LED_1
    ·· SEROUT LCD, Baud, [noparse][[/noparse]DispLightOff]
    ·· SEROUT LCD, Baud, [noparse][[/noparse]Clearscreen]
    · RETURN

    Metered:
    · GOSUB ReadRam
    PD = PDsecs + (PDsecs ** x)··········· ' Caculate Sand used from Sand Silo
    SL = SLsecs + (SLsecs ** x)

    T = (SL/500) * 1·························· ·' T = Caculate percentage of product used

    'S = seconds······························· ·' Timer Counter Names are one letter because there is not enough-
    'M = Minutes······························· ·' -space to show all Data on LCD Display
    'H = Hours

    IF s = 60 THEN
    ·S = 00
    ·M = M + 1
    ·IF M = 60 THEN
    ·M = 00
    ·H = H + 1
    ·ENDIF
    ·ENDIF

    IF oldsecs <> secs THEN··········· ·' This Routine Compars the oldsecs to secs
    ·· oldsecs = secs····················· ·' This Routine is so that Counter Update once a Seconds
    ·· S = S + 1···························· ·' This for the Timer Counter for the amount of time·that has·been used by the Sand Silo
    ·· PDSecs = PDSecs + 1
    ·· SLSecs = SLSecs + 1
    ENDIF
    GOSUB WriteRam
    RETURN

    WriteRam:······································· ' Routine to Save Data to a DS1302 Time Chip
    ··················································· ' Send Command
    · reg = $FE
    · HIGH Timer
    · SHIFTOUT DataIO, Clock,LSBFIRST, [noparse][[/noparse]reg]
    · SHIFTOUT DataIO, Clock, LSBFIRST, [noparse]/noparse][color=red]PDSecs.HIGHBYTE,PDSecs.LOWBYTE,[color=black]SLSecs.HIGHBYTE,SLSecs.LOWBYTE,[/color][color=blue]X.HIGHBYTE,X.LOWBYTE[/color][/color][color=black],S,M,H,T[/color
    · LOW Timer
    · RETURN

    · ReadRam :·························· 'Routine to Read Data from DS1302 Time Chip
    · reg = $FF
    · HIGH Timer
    · SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]reg]
    · SHIFTIN DataIO, Clock, LSBPRE, [noparse]/noparse][color=red]PDSecs.HIGHBYTE,PDSecs.LOWBYTE,[color=black]SLSecs.HIGHBYTE,SLSecs.LOWBYTE[/color],[color=blue]X.HIGHBYTE,X.LOWBYTE[/color],[/color][color=black]S,M,H,T[/color
    · LOW Timer
    ·· RETURN

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

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 9/5/2009 8:18:08 PM GMT
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-09-05 19:54
    ·hmlittle59
    I wrote my own Auto-boot if power is lost by checking to see if the DS1302 is running...If Running then Check Auto-Boot Flag

    Could you share this routine with me in how you did this

    Thanks

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

    ·
    ·
    ·
    ·
    Sam
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2009-09-05 23:18
    Just my 2cents worth but I have been using DS1302's with tiny 0.1F supercaps for many years in commercial equipment without problems. The supercap takes several minutes to get enough charge initially but really requires probably a few hours to accumulate a full charge which typically runs the chip for up to a week (tested tested tested). If the equipment is ever ever turned off main power for a few days continually then it probably has been taken off-line for a reason and nobody minds reseting the clock after then anyway.

    Normally my pcb allows either a small 10mm lithium cell or the supercap but I have never had need for supercaps. Clean up the pcb from any solder flux to minimise leakage.

    BTW, all standby circuits require a current limit resistor for compliance with safety standards, even if it seems that it can't cause a problem if it's short-circuited. I use a value of 1K.

    *Peter*

    P.S. Just for the record I will take some more measurements and update this thread soon

    Post Edited (Peter Jakacki) : 9/5/2009 11:39:33 PM GMT
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-09-05 23:58
    I just use the 1 Fards because I got a good deal on the a while back

    Where I work I made them a Sand Blast Controller which out side in weather·and when ever it rain the GFI outlet trips and if it happen on the week-en it will be OFF line for two·Days·that was another reason I used that size supper cap the total amount of sand that was used from the time the vendor came last is important information to keep as well as the flow rate

    I am glad that you share that INFO with us thought

    Peter
    BTW, all standby circuits require a current limit resistor for compliance with safety standards, even if it seems that it can't cause a problem if it's short-circuited. I use a value of 1K.


    This I did not know

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

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 9/6/2009 12:05:23 AM GMT
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2009-09-06 00:27
    Sam, so I see the connection with using the "sand" box forum smile.gif

    Have you done your maths on using the eeprom to store the data? The typical *minimum* endurance is at least 1,000,000 cycles. Now remember that's per cell so you could easily implement a simple routine that says once a "16-bit counter" is full that you proceed to the next location and so on to find a counter that's not full. It's not important that you worry about how many of these used 16-bit counters there are while you are counting, it's only important when you need to report the totals.

    A further optimization would be to use a 24-bit counter but consider it full when you read the million mark. So 300 bytes of EEPROM would hold 100 counters of 1 million each which means you could count to 100 million (is that enough!) without concern.

    More on optimizations is simply updating the counter based upon a time interval so that say every second or so you write the updated count to the eeprom if there has been a change. Of course you could lose up to a second's worth of data but does it really matter in your application? What's a puff of sand anyway?

    *Peter*
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-09-06 00:48
    Ok that sound good BUT there are

    Two thing that I need to ask

    One what is the part #

    Two do you have a Demo for this that you can share

    Peter

    Have you done your maths on using the eeprom to store the data? The typical *minimum* endurance is at least 1,000,000 cycles. Now remember that's per cell so you could easily implement a simple routine that says once a "16-bit counter" is full that you proceed to the next location and so on to find a counter that's not full. It's not important that you worry about how many of these used 16-bit counters there are while you are counting,

    it's only important when you need to report the totals.

    The problem here is that each time they are not using the sand I need to have an update total

    A further optimization would be to use a 24-bit counter but consider it full when you read the million mark. So 300 bytes of EEPROM would hold 100 counters of 1 million each which means you could count to 100 million


    ·(is that enough!) It could be enough maybe

    ·without concern.

    More on optimizations is simply updating the counter based upon a time interval so that say every second or so you write the updated count to the eeprom if there has been a change.


    The only time it need to update is while it is being used most of the time it just waiting·

    Of course you could lose up to a second's worth of data but does it really matter in your application?·

    ·That depend on how many seconds we are talking about


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

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 9/6/2009 1:01:10 AM GMT
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2009-09-06 01:19
    Ok, you can use any eeprom device you like although the 24LC256 devices we commonly use on the Propeller.

    As I mentioned you need not worry about the number of counters or total value WHILE counting because it is not necessary and might slow things down. Of course there is nothing to stop you from reading the counters at any time.

    For the sake of code clarity I won't go into an example of having overlow counters but surely the method of incrementing your counter in RAM and simply writing it every second or so would be easy for you to implement. To keep it simple just set a flag whenever you change your counter and the system polls this flag every second and if it's set it will clear the flag and do a simple write to eeprom. The number of seconds or even milliseconds is totally up to you as you know the situation and a quick number crunch will tell you if this update rate will not exceed the minimum write endurance of the eeprom.

    Gee, you could even make the eeprom replacable every year or two just like if you were replacing a battery if you wanted but that's a lazy approach as software can look after that easier.

    The direct overlow counter method could use a simple location pointer to the current counter so updating is fast. When the counter overflows the location pointer (in ram) is updated. The pointer is also updated at startup by reading through the counters from the first until you find one that isn't the magic 1,000,000.

    *Peter*
  • hinvhinv Posts: 1,255
    edited 2009-09-06 06:20
    Back in the day when I used parallel eproms, I used to time how long it would take to write the byte by writing, reading, comparing if not written write it again.. As the eproms got older and older, it took longer to write. When they took a real long time, I would presume the byte dead and write it somewhere else.
    Is the time to write still a factor?

    Doug
  • hmlittle59hmlittle59 Posts: 404
    edited 2009-09-06 07:23
    Hello Sam,

    Sorry for the delay. The Logic behind the way I executed this routine is to check and see if the DS1302 is running or not with the routine below, a few lines into the program. First I ClearDisplay/Beep/Print start up screen, then I do this routine below.

    
    '***********************************************************************************
    '   =============  Is DS1302 clock running...If yes bypass defaults  ============
    '***********************************************************************************
    '
      GOSUB ReadRTCBurst                   ' Read Clock Values  <<<<<<<<<<<<
      IF (Seconds.BIT7 = $00) THEN AutoCk  ' Clock is Running...SKIP Defaults below
    '
    
    



    Theory:
    1) If the DS1302 is -- NOT -- running then this is the first time running the program...
    2) Load..Default DS1302 time HH/MM/SS...etc set Clock/DS1302 as usual to running(I just GOSUB to the same DEMO code set clock routine)
    3) Write Zero(0) to DS1302 RAM location Zero(0) for AUTOCONFIG. OFF(default)
    4) Go to MainMenu because this is the first time threw and set/change any values you want(Clock to YOUR local time)....AUTO-CONFIG. ON -- or --OFF...these are different MainMenu selections...(I'm up to 8 selections and counting). I also wrote my own clock setting routine within my program...from the MainMenu
    5) Save any important values into DS1302 RAM...ON = 01 .... OFF = 00... or whatever variable(s) you choose to save...REMEMBER the order/location you save them.
    6) Now start the Main Body of your Program
    :
    If power fails the DS1302 should still be running from the 3vdc/10mm Battery(that's what I use)
    :
    1) On power up when the above routine is checked and sees that the DS1302 is running.
    2) This is not the first time threw so now check/GOTO AUTOCONFIG. Routine
    3) KNOW THE LOCATION IN THE DS1302 RAM FOR THE AUTOCONFIG. VALUE....ON/OFF...BYTE(1,2,3...9,10..30,31...ETC.)....I use ZERO(0)
    4) Read that value from RAM and compare.
    5) If... ON/01... then go and reload any important values that you have been saving to the DS1302 RAM on the FLY(I save certain values as the program is running or during MainMenu change.)

    6) Match those Variables with the CORRESPONDING values.
    7) GOTO Main Body of program...BYPASSING any kind of menu(s)...MainMenu.
    8) .......Your program will be back up and running.....I've test and retest this routine and it works
    END.

    AGAIN:
    1) check to see if the DS1302 is running or not...That is my main FLAG.....Because if it's not then the AUTOCONFIG. has to be OFF(Default)...we set it during default load
    2) Because the DS1302 is not running then goto the MainMenu.
    3) At the MainMenu set the AUTOCONFIG. to ON/OFF
    4) If "OFF" then MainMenu every time.
    :
    5) If at line 2 above the DS1302 is running then goto AUTOCONFIG. check
    6) At AUTOCONFIG. check READ the KNOWN location for the AUTOCONFIG. Value....I use Zero(0)
    7) If that value is ON then do the next step...(RE-Load important data that has been saved to the DS1302 RAM...or just restart the Main Body of the program)

    Hope this helps
    I can add more code if some one else needs it, but SAM you already know how to Write to DS1302 RAM...YA'll let me know

    PS: It's 2:00am I hope I didn't miss any steps...just let me know if something is not clear...PM me if you want

    Also...once I thought of the Auto-Reboot routine it took up to much room in the BS2 so I added it to my BS2e code

    I went back to my code and copied it over to the form here...let me know

     Month             = $01              ' Jan..to..Dec
      Date              = $21              ' 01st....31st
      Year              = $09              ' 01...99
      Day               = $04              ' Sun...Sat
      Hours             = $23              ' 09:xx:xx (in 24-hour mode ONLY)
      Minutes           = $00              ' xx:59:xx
      Seconds           = $01              ' xx:xx:01
    
     GOSUB SetTimeAndDate                  ' Set DS1302 with Default Values
    '
    ' ================================================================================
    '     -------   [noparse][[/noparse] Put a Zero(0) in the First DS1302 RAM location  ]  ---------
    '     -------  [noparse][[/noparse] Because the DS1302 was just Started or Restarted  ] ---------
    ' ================================================================================
    '
      temp1 = CWPr                         ' Initialize DS1302
      value = WPr0                         ' Clear Write Protect
    GOSUB RTC_Out                          ' Send Command
    
        idx = 0                            ' RAM Address to Write to ZERO(0)
      value = 0                            ' DATA To Write "00"
      temp1 = WrRam | (idx << 1)           ' Calculated Address (OR) it
    GOSUB RTC_Out                          ' Send Command
    
      temp1 = CWPr                         ' Initialize DS1302
      value = WPr1                         ' Set Write Protect
    GOSUB RTC_Out                          ' Send Command
    
    GOTO  init                             ' First time DS1302 run go around AutoCongig
    '
    '***********************************************************************************
    '                  CK DS1302 for AUTO-CONFIG. ON --  or   -- OFF
    '************************************************************************************
    '
    AutoCk:                                 '
    '
        GOSUB RTC_In0                       ' Get First Byte from DS1302 RAM Location 0/1
    '
    '************************************************************************************
    '
        IF (value = $00) THEN init          ' Auto-Config. is "OFF" if Value = 00
    '
        GOSUB RTC_In
        SAVED_VALUE1    =  value
    
        GOSUB RTC_In
        SAVED_VALUE2    =  value
    
        GOSUB RTC_In
         SAVED_VALUE3  =  value
    
        GOSUB RTC_In
         SAVED_VALUE4    =  value
    
        GOSUB RTC_In
         SAVED_VALUE5 =  value
    
     work = 1:GOTO skip_clear               ' Work = 1 the MainMenu to start your Main Body of your program
    
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''
    RTC_In0:
        idx = -1                           ' RAM Local -1 so it equal 0 after addition
    '
    RTC_In:
        idx =  idx + 1
        value = 0
        work = rdram | (idx << 1)
    RTC_In1:
     HIGH RTCCS                            ' Select DS1302
      SHIFTOUT DTA, Clk, LSBFIRST, [noparse][[/noparse]work]
      SHIFTIN  DTA, Clk, LSBPRE,   [noparse][[/noparse]value] ' Data From Ram location
     LOW  RTCCS                            ' Deselect DS1302
    RETURN
    '
    '***********************************************************************************
    '                 LOAD Default  VARIABLES 
    '***********************************************************************************
    '
    init:                                                 ' First time DS1302 run LOAD DEFAULTS
    
    
    
    
    
    



    Bed time for me...Good Night

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'M STILL LEARNING SO MUCH...BUT STILL KNOW SO LITTLE!!!

    hmlittle59
Sign In or Register to comment.