Author Topic: DS3231 is not accurate as it should be  (Read 3704 times)

0 Members and 1 Guest are viewing this topic.

Offline Alptkn

  • Contributor
  • Posts: 6
  • Country: tr
DS3231 is not accurate as it should be
« on: April 18, 2019, 06:41:16 pm »
I have made a nixie clock with 4 digits (shows only hour & and minute) but is seems like it doesnt keep the time accurate as it should. Clock diviated +2 minutes after 3 days. In the datasheet it is stated:
Accuracy ±2ppm from 0°C to +40°C
Accuracy ±3.5ppm from -40°C to +85°C

Which to my calculation was about 1-2 min diviation in a year. (0°C to +40°C)

I have few things on my mind that might cause this problem:

1)I had two ds3231 chip and I desolder one from "DS3231 for pi" module, another I did bought from local electronics shop however I am not certain which one I did solder to the board. Maybe I did some damage when I desolder/solder (I dont exceed 320-330 oC unless it isn't an IC ) and use that one in the board.

2) In the code I read the time every time SQW pin changes the state (I set SQW pin to 1hz output) maybe reading time that often might cause same problem. However in this case I would except a decrease in time not increase in time. I considered this because these modules usualy have an eeprom on them. I did looked in web but I didnt see anything that mentions this kind of situation so I dont think reading time this often from ds3231 might cause problem...

3) I have knock-off or a faulty ds3231 chip (which I am not even sure if it's possible or there is such thing) and it is simply way out of accuracy as it should be.

4) I am using 5V adapter (wall plug adapter) to power the circuit it outputs 5.10V (acording to my Multimeter) but I am not sure about any ripple or noise, but I have a input cap (470uF) which should be getting rid of some noise from the adapter which I am sure it has some but not much (I hope  ::) )

Other than these I dont have any idea what might cause a problem fell free to point them...

First and third one can be solved by switching the ds3231 with the other one but I might need to wait couple of weeks to be sure so this one I dont want to try if there is another problem

For the 2. possible cause I will write another code that will read time from ds3231 every min, so that might solve my issue but as I said I am not hopefull about that one  :-//

Last one can be solved by 7805 regulator but I have to manually solder it some where in board and make changes and again confirm the accuracy by waiting few days or few weeks... (before sending to a pcb warehouse for some sample boards)

Part of the schematic is in the attachments...

Thanks in advance  :-+
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 6898
  • Country: us
Re: DS3231 is not accurate as it should be
« Reply #1 on: April 18, 2019, 07:48:05 pm »
Have you read up on the 'aging' register?  You can change the internal crystal frequency.  If you look at the graph on page 7.  The chip is only accurate over a very narrow temperature band and even then the error can be quite sizable depending on the crystal accuracy.  It's a real shame that the crystal is internal.

BTW, the internal crystal can be damaged by physical shock - like dropping the chip on a workbench.

https://datasheets.maximintegrated.com/en/ds/DS3231.pdf

You could do a decent job of calibrating the crystal if you had an accurate frequency counter.  They do provide the 32 kHz output.  You might also be able to do this by using an oscilloscope to watch the phase change between the internal oscillator and some external source that is known to be accurate.
 

Offline floobydust

  • Super Contributor
  • ***
  • Posts: 3248
  • Country: ca
Re: DS3231 is not accurate as it should be
« Reply #2 on: April 18, 2019, 08:27:34 pm »
A common mistake with the DS3231 is to run PCB traces under it.  DS3231 datasheet:
"Avoid running signal traces under the package, unless a ground plane is placed between the  package and the signal line. All N.C. (no connect) pins must be connected to ground."

High frequency noise from I2C (for example) couple to the internal crystal oscillator and the RTC ends up running fast. Or nearby nixie boost converter EMI can also affect the part, depending on your circuit layout.

edit: I see your boost converter is running off the +5V rail, so it sure to be very noisy.
I would add an RC or LC filter for the 5V supply to the DS3231 to ensure it has clean power.
« Last Edit: April 19, 2019, 02:47:36 am by floobydust »
 

Online NivagSwerdna

  • Super Contributor
  • ***
  • Posts: 1867
  • Country: gb
Re: DS3231 is not accurate as it should be
« Reply #3 on: April 18, 2019, 08:59:24 pm »
I have a nixie clock with a very similar design and use components removed from cheapo DS3231 modules and have never had any issues.  My design is almost identical in that I use SQW (although mine has a 10k pull-up on that line) in the same way... interrupt every second and then read the time from the module.  I get accurate time, a few seconds over many months.

Perhaps test your DS3231 with just an UNO as a sanity check.

 

Offline Alptkn

  • Contributor
  • Posts: 6
  • Country: tr
Re: DS3231 is not accurate as it should be
« Reply #4 on: April 18, 2019, 09:23:41 pm »
Well I didn't read up the ds3231 datasheet comprehensively to be honest because I switched to ds1307 to ds3231 couple of days before sending this board to pcb warehouse and I was thinking like "ow this one has internal calibrated osilator and better ppm accuracy let me slap that in here".

However I will check 32khz output with my oscilloscope and try to correct it with "agging" register if thats the problem.

But before that I should re-route the signals that goes under DS3231...  Not sure if those (SDA and SQW) lines would make a problem but if it does reading time every second can definetly ruin the time accuracy. (Part of the board is in attachment). The boost converter is not really nearby and both (top layer ground doesn't show on attachment) layers are filled with ground plane where no signal traceses present. So I doubt that boost converter can couse that*.

I will also check it with arduino but that might take a bit time since I throw the rest of the module away... |O

I will look in to those details at work and write back thanks :-+ ...


edit: *Boost converter EMI. Noisy 5V rail: Yes might cause a problem.
« Last Edit: April 18, 2019, 09:33:37 pm by Alptkn »
 

Offline rf-loop

  • Super Contributor
  • ***
  • Posts: 3142
  • Country: cn
  • Born with DLL21 in hand
Re: DS3231 is not accurate as it should be
« Reply #5 on: April 18, 2019, 09:43:01 pm »
Is better also to note what version of DS3231 when talk about it. Specially today when peoples buy these modules from eBay (and not only from chinese sellers). Short time ago I have experience that most of modules are made using DS3231M (pin compatible but not fully functionally compatible and less accurate MEMS oscillator)
Many eBay sellers description picture they still show DS3231SN but what you get is mostly DS3231M and same even if buy just these IC's.


https://blog.heypete.com/2017/09/05/major-differences-between-the-ds3231-and-ds3231m-rtc-chips/

Advantage with MEMS oscillator is that its shock resistance is better, so it can use some places where xtal versions may fail. But MEMS is less accurate. 
Then need also keep in mind how DS3231SN/M works and how it internally adjust related to temp. Short time accuracy may be lot of more bad than bit longer.


« Last Edit: April 18, 2019, 09:46:24 pm by rf-loop »
If practice and theory is not equal it tells that used application of theory is wrong or the theory itself is wrong.
-
Harmony OS
 
The following users thanked this post: oPossum, thm_w, edavid, tooki

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 6898
  • Country: us
Re: DS3231 is not accurate as it should be
« Reply #6 on: April 18, 2019, 10:36:06 pm »
It appears that all 3 versions -S, -SN and -M are in stock at DigiKey and cost between $8 and $10 (rounded up).  It is probably worth the time to compare the datasheets between the -S and -M versions.  AFAICT, the -SN is covered by the -S datasheet.

The -S and -SN are more accurate than the -M but the -M may be more rugged.

I don't buy components from eBay or Chinese sources.
« Last Edit: April 18, 2019, 11:53:19 pm by rstofer »
 

Offline floobydust

  • Super Contributor
  • ***
  • Posts: 3248
  • Country: ca
Re: DS3231 is not accurate as it should be
« Reply #7 on: April 18, 2019, 10:45:15 pm »
Noisy 5V rail: Yes might cause a problem.

Where are your decoupling capacitors for the RTC and MCU? I don't see any on 5V.
A look inside the DS3231   I could not see the crystal wiring but that would be susceptible to pulses on SDA or SCL.
 
The following users thanked this post: edavid

Offline wilfred

  • Frequent Contributor
  • **
  • Posts: 885
  • Country: au
Re: DS3231 is not accurate as it should be
« Reply #8 on: April 18, 2019, 11:02:22 pm »
I was reading this yesterday. RTC clock chips are susceptible to noise on PCB's. This App Note is for a different RTC chip but there's probably one for yours specifically too. But I imagine they are more alike than different in this regard.
https://pdfserv.maximintegrated.com/en/an/AN58.pdf


I'd start with disabling the HV powersupply and seeing if that changes anything. Set the time, switch off the HV supply circuit, come back in 24h and check the time. If it is good then you have the source of the problem.
« Last Edit: April 18, 2019, 11:15:53 pm by wilfred »
 

Online NivagSwerdna

  • Super Contributor
  • ***
  • Posts: 1867
  • Country: gb
Re: DS3231 is not accurate as it should be
« Reply #9 on: April 18, 2019, 11:08:41 pm »
I have plenty of traces under mine and no issues.  You should probably look more towards the supply side?
 

Offline schmitt trigger

  • Super Contributor
  • ***
  • Posts: 1498
  • Country: mx
Re: DS3231 is not accurate as it should be
« Reply #10 on: April 18, 2019, 11:47:48 pm »
I bought a DS3231 module from Adafruit, and employed it as a timebase in a binary clock of my own creation.

I only update the module twice a year when the DST kicks in or out, and in the 3 years I've had it, the device has not yet drifted above 1 minute.
I don't use SQW, I actually read the registers via I2C.
 

Online imo

  • Super Contributor
  • ***
  • Posts: 2382
  • Country: 00
Re: DS3231 is not accurate as it should be
« Reply #11 on: April 19, 2019, 05:59:30 am »
The DS3231 is the most precise RTC chip you can get. My 2 cheapo ebay modules (SN chip) did 1-2secs in 6 months.

The reading the chip may introduce an issue when the "I2C reading sequence takes longer than 1sec", afaik. So if it is shorter it cannot cause issues even you read the chip a few times per second.

Wire 100nF ceramics in parallel with 10u ceramics close to your chip's Vcc and GND.

Doublecheck your software as well. Try with different libraries. I bet it is a sw bug.


« Last Edit: April 19, 2019, 06:49:05 am by imo »
 

Offline Alptkn

  • Contributor
  • Posts: 6
  • Country: tr
Re: DS3231 is not accurate as it should be
« Reply #12 on: April 19, 2019, 02:45:28 pm »
So far I found nasty ripple in the +5V rail and fixed it I put 7805 and couple of capasitors at output so +5V rail looks much better than before.

I configured the ds3231 to output 8.192kHz signal at sqw pin and checked it with my osciloscope but, i figure there is no point to see accuracy of the frequency with my osciloscope.

I did update the software now its reading the clock every 60sec and as before only necesary bits needed so this should eliminate unnecesary use of the I2C usage. (Next would be the try other librarys)

Also I checked the markings on the IC as some of you suggested and one I am using is DS3231-SN variant other one is also SN variant.

I am gonna let is sit for a day and see if there is any drift. I also check seconds so I will know if its drifted or not (when my PC second is at 38sec it displays the next min on my clock).

If its drifted like min or so tomorow I will try disable the HV supply circuit and wait another day.

Edit: attachment added.
« Last Edit: April 19, 2019, 02:51:20 pm by Alptkn »
 

Online NivagSwerdna

  • Super Contributor
  • ***
  • Posts: 1867
  • Country: gb
Re: DS3231 is not accurate as it should be
« Reply #13 on: April 19, 2019, 02:49:59 pm »
DS3231-SN
FWIW That's the same as mine.  :-+
 

Online imo

  • Super Contributor
  • ***
  • Posts: 2382
  • Country: 00
Re: DS3231 is not accurate as it should be
« Reply #14 on: April 19, 2019, 02:54:14 pm »
I am gonna let is sit for a day and see if there is any drift. I also check seconds so I will know if its drifted or not (when my PC second is at 38sec it displays the next min on my clock).
Always sync your PC with the "internet time" before the measurements (as the PC clocks are not stable enough).
 

Offline JackJones

  • Regular Contributor
  • *
  • Posts: 178
  • Country: fi
Re: DS3231 is not accurate as it should be
« Reply #15 on: April 19, 2019, 03:38:41 pm »
If you bought them from ali/ebay they are 99% fake. (it's likely that this is the source for your local shop too) I bought a few from different sellers about a year ago and none of them functioned properly. I bought both modules and just the ICs themselves.

Cheapest source I found for them was LCSC, something like 1.5€ a piece in small quantities. So far I've had no issues with them, they seem to be genuine.
« Last Edit: April 19, 2019, 03:42:07 pm by JackJones »
 

Offline Alptkn

  • Contributor
  • Posts: 6
  • Country: tr
Re: DS3231 is not accurate as it should be
« Reply #16 on: April 20, 2019, 06:45:29 am »
Well clock is 4-5 min ahead  |O

At this point I dont thing data line or noisy +5v rail supply is the cause of this, because it is worse than before  :palm: and I think the chip is simply fake or HV supply EMI is effecting the chip.

I am gonna order some ds3231 over lcsc. While they arrive I will isolate the HV supply...




 

Online imo

  • Super Contributor
  • ***
  • Posts: 2382
  • Country: 00
Re: DS3231 is not accurate as it should be
« Reply #17 on: April 21, 2019, 12:41:40 pm »
The SQW is an open-drain output. Try to wire a pullup there, for example 4k7.

PS: when running with arduino libraries - you must do not have to read the external RTC once a second - there is a library (I think "Time") which includes a function for syncing the internal system "Time" with the external RTC "provider" with a sync period you may set as you wish.
See
setSyncProvider()
setSyncInterval(time_t interval)

Set it for 30minutes with a cheapo atmega crystal. It will run the system time for 30minutes based on the atmega's crystal and then it synces the system time with the RTC, and so on, and so on..
« Last Edit: April 23, 2019, 11:15:29 am by imo »
 

Online NivagSwerdna

  • Super Contributor
  • ***
  • Posts: 1867
  • Country: gb
Re: DS3231 is not accurate as it should be
« Reply #18 on: April 23, 2019, 10:27:07 am »
The SQW is an open-drain output. Try to wire a pullup there, for example 4k7.
:-+ As per the datasheet... needs a pull-up but you can potentially use the  INPUT_PULLUP if using a digital pin which you are.


you must not read the external RTC once a second
Why not? That's exactly what I do.


« Last Edit: April 23, 2019, 10:32:41 am by NivagSwerdna »
 
The following users thanked this post: imo

Online Kjelt

  • Super Contributor
  • ***
  • Posts: 5759
  • Country: nl
Re: DS3231 is not accurate as it should be
« Reply #19 on: April 23, 2019, 11:20:49 am »
If you bought them from ali/ebay they are 99% fake.
Really ? And I paid $0,73 for

Arduino DS3231 ZS042 AT24C32 IIC Module Precision RTC Real time Clock Memory

A pcb, DS3231, 4k Flash eprom, and passives, you would think it was legit for that price  :-DD
« Last Edit: April 23, 2019, 11:22:54 am by Kjelt »
 

Online Kjelt

  • Super Contributor
  • ***
  • Posts: 5759
  • Country: nl
Re: DS3231 is not accurate as it should be
« Reply #20 on: April 23, 2019, 11:25:23 am »
Why not? That's exactly what I do. 
Makes no sense to read it every second.
You can only hang your I2C bus, block it for other traffic and cause noise for other components for what ?
Your accuracy will not be higher then if you read it once a minute or so, esp if you calibrate the deviation of the clock of your processor once and correct for it.
 

Online imo

  • Super Contributor
  • ***
  • Posts: 2382
  • Country: 00
Re: DS3231 is not accurate as it should be
« Reply #21 on: April 23, 2019, 11:28:07 am »
If you bought them from ali/ebay they are 99% fake.
I can hardly imagine such an economy able to copy/fake almost all chips ever produced by all known chip manufacturers in last 50years.. :P
« Last Edit: April 23, 2019, 11:31:22 am by imo »
 
The following users thanked this post: tooki, cpt.armadillo

Offline Alptkn

  • Contributor
  • Posts: 6
  • Country: tr
Re: DS3231 is not accurate as it should be
« Reply #22 on: April 23, 2019, 11:41:43 am »
I am using internal pullup for SQW pin. Which should do the trick. I did research in to the other forums related to the this subject (avrfreaks, forum.arduino etc.) and it seems like every one who had similar problem is due to the cheap ds3231 chips. I think they use QC fail IC on these cheap modules.

I also switch the ds3231 with the other one I had in my inventory that one was also cheap, I did test this one about 36 hours and it has similar accuracy (2-3 min ahead as it should be) problems...

To day I will test for the EMI; I will sync the ds3231 and leave the clock unpluged and let it run from the little battery which only powers ds3231. Day or two should reveal the drift.

If I see a drift again I will wait for the chips from lcsc that I ordered maybe I will order couple from digikey mean while just to be sure.
 

Online imo

  • Super Contributor
  • ***
  • Posts: 2382
  • Country: 00
Re: DS3231 is not accurate as it should be
« Reply #23 on: April 23, 2019, 11:52:18 am »
The internal pullup is weak (ie 50k). It could pick up some noise and therefore it runs fast (because of false triggering).

Try with 4k7. You may also wire a small capacitor (ie 1-10nF) from the 4k7 (SQW signal) to GND.

You may also run a statistics - count the interrupts coming from the RTC and compare (or timestamp) it with your atmega's crystal time.
With false SQW triggers you will see an irregular pattern.
With "fast RTC" the pattern will be linear.

PS: and it could help to show us your code. I still bet it is a sw bug..

PPS: do create a simple sketch reading the RTC once a second (or any other period), get rid of all other stuff.
The sketch shall send the RTC time via UART to your PC.
« Last Edit: April 23, 2019, 12:26:08 pm by imo »
 

Online PA0PBZ

  • Super Contributor
  • ***
  • Posts: 4234
  • Country: nl
Re: DS3231 is not accurate as it should be
« Reply #24 on: April 23, 2019, 12:25:41 pm »
4) I am using 5V adapter (wall plug adapter) to power the circuit it outputs 5.10V (acording to my Multimeter) but I am not sure about any ripple or noise, but I have a input cap (470uF) which should be getting rid of some noise from the adapter which I am sure it has some but not much (I hope  ::) )

So far I found nasty ripple in the +5V rail and fixed it I put 7805 and couple of capasitors at output so +5V rail looks much better than before.

So what are you feeding the 7805? Surely the 5.1V from the adaptor is not enough.
Keyboard error: Press F1 to continue.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf