Shop OBEX P1 Docs P2 Docs Learn Events
DS 1302 - Gaining Time — Parallax Forums

DS 1302 - Gaining Time

SELSEL Posts: 80
edited 2010-07-13 16:01 in Propeller 1
I have bread boarded the DS 1302 chip with the recommended crystal from Parallax.
I am using DS1302_Full Object based on Daniel Robert's DS 1302 Object. The last revision on this object was Mar 28 2010 to fix a bug that caused the seconds to be reset in the config method. I am out putting, to a LCD display, the date and time.

The Problem: The chip is gaining time. ( about 10 seconds in 12 Hrs. )

On the pin layout connection to the Propeller I followed the schematic from DS1302_Full Object.

Does anyone know why the chip is gaining time? I have the crystal standing straight up. Do I need to bend it over away from the Chip? I have the crystal plugged in next to the x1 and x0 connections.

My bread board platform is the Propeller Demo Board.

Any advise would be appreciated!

Comments

  • BRBR Posts: 92
    edited 2010-07-06 23:36
    I happen to have a ds1302 on my prop demo board now (am playing around with the backup power features and working on a few cosmetic updates to the ds1302_full object). I'll leave my setup on overnight to see if I see the same thing.

    Just to ask the question, what are you using for a time reference when you compare? Hopefully something like this:
    http://tycho.usno.navy.mil/simpletime.html
  • SELSEL Posts: 80
    edited 2010-07-07 00:00
    To set the time, for now, I am using the SetDatetime method. I am letting Vcc2 float. Maxim Application Note 82 give this as an option.
    I ordered a 1 farad supercap today. I will connect that to Vcc2 when it arrives

    Since I asked for help I've created a new cog for the ReadTime and readDate methods. I display the date and time using an LCD.

    Thanks for helping. I look forward to your report later.

    The GetDateTime method runs in it's own cod.

    Here is the code:

    PUB GetDateTime

    rtc.readTime( @hour, @minute, @second ) 'read time from DS1302
    rtc.readDate( @day, @month, @year, @dow ) 'read date from DS1302

    Lcd.gotoxy(1,0)
    Lcd.str(tempDOW)
    Lcd.str(string(": "))
    Lcd.decx(month,2)
    Lcd.str(string("-"))
    Lcd.decx(day,2)
    Lcd.str(string("-"))
    Lcd.decx(year,2)
    Lcd.gotoxy(0,1)
    Lcd.str(string("Time: "))
    Lcd.decx(hour,2)
    Lcd.str(string(":"))
    Lcd.decx(minute,2)
    Lcd.str(string(":"))
    Lcd.decx(second,2)

    waitcnt( clkfreq + cnt )
    if (hour == 00 and minute == 0) or tempDow < 1
    tempDOW := GetDow(dow)

    PRI GetDOW(__dow)
    case __dow
    1:
    return @_dow[noparse][[/noparse]0]
    2:
    return @_dow
    3:
    return @_dow[noparse][[/noparse]8]
    4:
    return @_dow[noparse][[/noparse]16]
    5:
    return @_dow[noparse][[/noparse]32]
    6:
    return @_dow[noparse][[/noparse]64]
    7:
    return @_dow[noparse][[/noparse]128]
    other:
    return @NA

    DAT
    _dow byte "Sun",0,"Mon",0,"Tue",0,"Wed",0,"Thu",0,"Fri",0,"Sat",0,"UKN",0
    NA byte "N/A",0

    As you can see I am new to spin. I know there has to be betters ways, but one has to start somewhere.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2010-07-07 19:48
    SEL,

    It sounds like you got a crystal with the wrong load capacitance. Parallax even received some wrong units once and this is in bulk, so even if it came from us it may be the wrong load capacitance. It must be 6pF or you will gain / lose time depending on yours.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    ·
  • SELSEL Posts: 80
    edited 2010-07-07 20:04
    Chris and All,

    I just received the crystal from Parallax, I believe, about a week ago.

    If I can't get the timing to behave like it should I'll call and see if there is something I am doing wrong.

    I have taken the chip (ds1302 ) and mounted it on the Propeller Professional Development Board. I will run it for a while and see if anything changes for the better.
    Maybe we have to replace the crystal?

    Oh, this may be important. I had pin 8 floating before. I have grounded it. I am waiting for a super cap ( 1 Farad ) to arrive in a few days.

    Could Pin 8 floating have caused the crystal time gain?

    Thanks!

    SEL
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2010-07-07 22:01
    SEL,

    Most likely you simply got the wrong crystal. I'm not sure if we purged our stock on these or not to get rid of the mix-up. I think there were like 1500+ crystals last time I checked. The other possibility, although difficult to test is the added capacitance of running this from the bread board. To solve this some people have soldered the crystal directly to the pins on the DS1302. This is not something I recommend if you're not comfortable doing it. A little too much heat and the crystal (and possibly the DS1302) could be damaged. A known good crystal can be gotten from Digi-Key as part number SER3205-ND. If you're still having the same issue after that then it is simply the bread board causing the issue. Dallas/Maxim has a AppNote that defines the proper layout and ground routing to ensure the crystal stays within its specifications. Remember temperature can also cause problems. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    ·
  • BRBR Posts: 92
    edited 2010-07-07 23:11
    Well, the results are in. I estimate that my 1302 on the prop demo board (with 3.3v supply, with 1000uF electrolytic cap on vcc2) gained about 1 sec in ~22 hours.
  • SapiehaSapieha Posts: 2,964
    edited 2010-07-07 23:36
    Hi Chris Savage (Parallax).

    Good practice to use Crystal's on Breadboard are to CUT 2 pins from one Machine-pins IC holder and stuck in breadboard AND XTal in it.
    It not help to have smaller Capacitance BUT give good connection that give reliable working IC's oscillator.
    As many inaccurate frequencies on Breadboard come from BAD connection rather as from little differences in capacitance.


    Regards
    Christoffer J

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nothing is impossible, there are only different degrees of difficulty.
    For every stupid question there is at least one intelligent answer.
    Don't guess - ask instead.
    If you don't ask you won't know.
    If your gonna construct something, make it·as simple as·possible yet as versatile as posible.


    Sapieha
  • SELSEL Posts: 80
    edited 2010-07-08 00:16
    My thanks to all.

    It would seem that BR has been able to use the Prop Demo Board and make the crystal work.

    I will backup and start over. Every failure is a good learning experience.

    My lack of programming experience in this area is the limiting factor, it would seem.

    Thanks again to ALL!

    PS: Special thank you to Chris Savage!
  • hmlittle59hmlittle59 Posts: 404
    edited 2010-07-08 04:12
    Hello Chris,

    Parallax Website and .PDF file for the 32.768 crystal shows a load Cap. of 12.5 cl. I just received 100 from Mouser with these spec., I want to make sure of this before I start setting up my kits. I have not tested any of these parts this time.

    Please let me know.

    Thanks

    Howard

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

    hmlittle59
  • SELSEL Posts: 80
    edited 2010-07-08 14:54
    Well another 14 hours has gone bye and the DS1302 is still gaining time.

    I am trying another object. I was using DS1302_Full. I will now use DS1302.

    If the chip still will not keep proper time I will call Parallax and request they send another crystal.

    As Chris Savage said: I might have gone bad crystal.

    SEL
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2010-07-08 19:09
    hmlittle & SEL...make sure you get a 6pF crystal. It may be that Parallax has the wrong value do to having received the wrong part before. Unfortunately, is receiving gets the wrong part they don't always know, especially if the invoice says it is the right part.

    Sapieha, yes, that is why my focus has been on the crystal. I too have used the breadboard and with solid connections have not experienced issue, however the time I did the crystal turned out to be the wrong spec, and I expect that is what is the case here. But if the Parallax crystal is 12.5pF then it won't work.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    ·
  • SELSEL Posts: 80
    edited 2010-07-08 19:54
    Chris, thank you!

    I will get with Parallax and request a new crystal. I received this crystal from Parallax about a week ago.
    when I ordered the DS1302 there was a link on that page to the crystal. It was supposed be rated at 6pf.

    Of course, I could have just gotten the right crystal that was defective.

    Many thanks to you all.

    Chris, I know we all feel good knowing that you are looking out for we newbees!!

    SEL

    P.S.: Chris, last year ( 2/2009 ) you said on this forum that you were looking at the DS3234. That chip would solve the crystal problem.

    How far did you get with your investigation? I am just in the bread board stage and would change if you had an object for this chip!
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2010-07-08 20:33
    SEL,

    page 5 of the datasheet below under CLOCK ACCURACY ... "External circuit noise coupled into the oscillator circuit may result in the clock running fast." ... do you have a decoupling capacitor across the power supply to the DS1302?


    With the wrong crystal (i.e. more load capacitance) my intuition would lead me to believe that the clock speed would be slower. Because this does not seem to be the case, I would start focusing on potential noise issues in the immediate environment of the DS1302.

    Reference DataSheet:
    pdfserv.maxim-ic.com/en/ds/DS1302.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • SELSEL Posts: 80
    edited 2010-07-08 21:09
    Beau,

    Thanks for the info and advice.

    I have a bread board setup at the moment.

    After your response I took a closer look and found I had a wire looping over the crystal. This might induce some emf that would effect the crystal.

    I do not seem to have any situation that the app note makes reference to, except as stated above.

    BR, was able to use a Propeller Demo Board and has no problem with the crystal! This lead me down the path of maybe, if the over the crystal wire is not the problem, that I may need to replace the crystal.

    But as you say: 'the crystal would be slower'.

    Have you done any coding for the DS3234? Chris S. was going to look into this in Feb of last year.

    Thank you very much.

    SEL
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2010-07-08 21:14
    Actually, it should be as I said earlier...the 12.5pF crystal would cause the clock to run fast. This information is readily available on the Maxim website and anyone having issues should always refer to the datasheet and related AppNotes when trying to diagnose the problem.· This wealth of information can save weeks of headaches.· I usually point out the information in Application Note 58 as that is what I go by regarding the Crystal considerations, nonetheless here is what it states in terms of fast and slow clocks:

    Fast Clocks - The following are the most common scenarios that cause a crystal-based RTC to run fast.
    • Noise coupling into the crystal from adjacent signals. This problem has been extensively covered above. Noise coupling usually causes an RTC to be grossly inaccurate.
    • Wrong crystal. An RTC typically runs fast if a crystal with a specified load capacitance (CL) greater than the RTC-specified load capacitance is used. The severity of the inaccuracy is dependent on the value of the CL. For example, using a crystal with a CL of 12pF on an RTC designed with a 6pF CL causes the RTC to be about 3 to 4 minutes per month fast.


    Slow Clocks - The following are the most common scenarios that cause a crystal-based RTC to run slow.
    • Overshoots on RTC input pins. It is possible to cause a RTC to run slow by periodically stopping the oscillator. This can be inadvertently accomplished by noisy input signals to the RTC. If an input signal rises to a voltage that is greater than a diode drop (~0.3V) above VDD, the ESD protection diode for the input pin will forward bias, allowing the substrate to be flooded with current. This, in turn, stops the oscillator until the input signal voltage decreases to below a diode drop above VDD.· This mechanism can cause the oscillator to stop frequently if input signals are noisy. Therefore, care should be taken to ensure there is no overshoot on input signals.
    • Another situation that is common to overshoot problem is having an input to the RTC at 5V when the RTC is in battery-backup mode. This can be a problem in systems that systematically shut down certain circuits but keep others powered up. It is very important to ensure there are no input signals to the RTC that are greater than the battery voltage (unless stated otherwise in the device data sheet) when the device is in battery-backup mode.
    • Wrong crystal. A RTC typically runs slow if a crystal with a specified CL is less than the CL of the RTC. The severity of the inaccuracy is dependent on the value of the CL.
      Stray capacitance. Stray capacitance between the crystal pins and/or to ground can slow an RTC down. Therefore, care must be taken when designing the PC board layout to ensure the stray capacitance is kept to a minimum.
      Temperature. The further the operating temperature is from the crystal turnover temperature, the slower the crystal oscillates. See Figures 3 and 4.


    Clock Does Not Run - The following are the most common scenarios that cause a RTC to not run.
    • The single most common problem when the clock does not run is that the CH (clock halt) or EOSC (enable oscillator) bit has not been set or cleared, as required. Many Dallas RTCs include a circuit that keeps the oscillator from running when power is first applied. This allows a system to wait for shipment to the customer, without drawing power from the backup battery. When the system is powered for the first time, the software/firmware must enable the oscillator and prompt the user for the correct time and date.
    • Surface mount crystals may have some N.C. (no connect) pins. Make sure that the correct pins from the crystal are connected to the X1 and X2 pins.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering


    Post Edited (Chris Savage (Parallax)) : 7/8/2010 9:21:44 PM GMT
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2010-07-08 21:21
    SEL,

    "But as you say: 'the crystal would be slower'." - I said that intuitively it would make me think that the crystal would run slower.


    let me ask you this, Are you using the solderless bread-board with the crystal (i.e. sharing the same pins with the bread board) ... If so, and if a higher capacitance causes the DS1302 to run faster, then THAT is the culprit. The solderless bread board contributes a considerable amount of parasitic capacitance between pins, this being the case, it would cause your DS1302 to run faster.

    "Have you done any coding for the DS3234?" - I personally have not

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 7/8/2010 9:28:12 PM GMT
  • SELSEL Posts: 80
    edited 2010-07-08 22:33
    Chris S.,

    Thank you so much for taking the time to explain so much to me. I now that this takes a great amount of energy over the course of a day!

    I have looked at the reference material that you stated. Of course, not being an electrical engineer it takes time to adapt to reading data sheets.
    It is easy to miss or dismiss what you do not understand.

    Have you mad progress on the DS3234 chip?

    With respect,
    Stan
  • SELSEL Posts: 80
    edited 2010-07-13 16:01
    This is a little late in the game, but....

    I installed a decoupling cap, 0.1ufd, on the power supply side and now the DS1302 is running slower.

    This supports what Chris S. said below that the wrong crystal would cause the clock to run slower. It has lost 15 seconds in about 24 hrs.
    Before the gain was about 40 seconds in 24 hours.
    Of course, this is just one 24 period, but it has always gained time. The decoupling cap must be the difference.

    The crystal I ordered, about two weeks ago, from Parallax was rated with CL of 6pfs.

    I have been in touch with Tech Support and they have told me that Chris is testing a new batch of crystals and will have the results soon.

    I hope these helps.

    SEL
Sign In or Register to comment.