DS1302 object : problem with hours?
Paul Rowntree
Posts: 49
Greetings All;
Has anybody had any trouble with the DS1302 object from the exchange? I am developing a control board for a balloon flight, and want the clock to be able to survive a reboot with valid data.
I am using Daniel Robert's DS1302 (Real Time Clock) object on a prop protoboard. I have code in RAM that sets the clock, then reads it every second and output this to the prop plug. In EEPROM I have the same code, but without the setting of the clock. I have a 3.0 V battery backup supply, and the chip is run off the 3.3 V rail. I find that all parameters except the hours are maintained correctly; the EEPROM code starts the hours from 00, indicating that this parameter is not being saved or read correctly.
Replacing the DS1302 has no effect. I have tried removing the trickle charge configuration in the DS1302 Init routine, to no effect. My code is essentially that of the supplied demo, except using the serial routines instead of the TV video.
Thanks for any help that you can provide!
Has anybody had any trouble with the DS1302 object from the exchange? I am developing a control board for a balloon flight, and want the clock to be able to survive a reboot with valid data.
I am using Daniel Robert's DS1302 (Real Time Clock) object on a prop protoboard. I have code in RAM that sets the clock, then reads it every second and output this to the prop plug. In EEPROM I have the same code, but without the setting of the clock. I have a 3.0 V battery backup supply, and the chip is run off the 3.3 V rail. I find that all parameters except the hours are maintained correctly; the EEPROM code starts the hours from 00, indicating that this parameter is not being saved or read correctly.
Replacing the DS1302 has no effect. I have tried removing the trickle charge configuration in the DS1302 Init routine, to no effect. My code is essentially that of the supplied demo, except using the serial routines instead of the TV video.
Thanks for any help that you can provide!
Comments
I tried that. It is a problem with the initializing sequence. I look at this imediately.
dro.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
in medio virtus
Post Edited (inservi) : 5/8/2007 12:16:47 PM GMT
The problem occur because the init() procedure is setting the 12/24 register and replace the hour value in the same register.
I suggest to split the init procedure to two procedure init and config.
As you see, the init procedure set the communication ports and the config set all registers of the DS1302.
So you need to call init, config and setDatetime after the DS1302 power on only.
After a reboot of the propeller, you need to call only the init procedure.
and sometime the setDatetime procedure for adjust the time.
Here are the modified code:
and the modif in the DS1302 driver:
[code]
PUB init( inClk, inIo, inCe )
clkcycles_us := ( clkfreq / _1us ) #> 381 ' will work better with Propeller II
clk := inClk
io := inIo
ce := inCe
dira[noparse][[/noparse]ce]~~ 'set to output
outa[noparse][[/noparse]ce]~
delay_us(2)
dira[noparse][[/noparse]clk]~~
outa[noparse][[/noparse]clk]~
PUB config
write($90,$a6) ' Init chargeing register 1010 0110 charge activ
here are the complete demo corrected.
dro.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
in medio virtus
Ca va bien! merci !
THis is a good solution. BTW : I am using a battery instead of the trickle charger : is commenting out the line in the config routine enough?
How much hold time do you get with a supercap type charger?
Cheers!
Je suis content que vous alliez bien.
With battery, you mean a not rechargeable one ?
In that case, commenting out the line in the config routine is enough ! if you power off - on the DS1302
For more security, change the value with :
write($90,%00000000 ) or any think different than 1010 xxxx
As described in the DS1302 data sheet, the bits 4 to 7 must be initialized with 1010 for activating the trickle charger (for security). At startup, the trickle charger is disabled.
The backup time with a supercap of 0.2F is at at least 100 hours. Personally, i use 1F supercap but I'm not sure that i can multiply the time by 5 because the supercap is auto-discharging because internal leakage.
For more information, read at http://www.maxim-ic.com/appnotes.cfm/appnote_number/3517 At the bottom of this page, you can also find the full data sheet.
Best regards,
dro
thank-you for the title word in French.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
in medio virtus