DS3231 time varies through on/off situation

Go To Last Post
23 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi everyone, I faced a strange situation. I've connected an ATmega32 to a DS3231 and the circuit works properly. The timekeeping system works well and even after a week of operation, no time change happens.

But if I switch it's power on and off frequently, it's time value increases occasionally. In my last test, I switched the power as 5 seconds on and 5 seconds off; after an hour, the seconds of device increased about 40 seconds. Let me mention that if I connect a constant supply, no problem happens even after a week! 

The device has a normal supply with a 3v3 regulator connected to it's VCC pin and a backup battery is connected to its batt pin as well.

 

The tests are reported below but the problem has not solved yet:

1- I've added a 100nf capacitor to it's supply pins (near the chip)

2- I've changed the supply and connected a precise 5V supply before the 3v3 regulator, but nothing has changed in supply switch mode (5 secs on 5 secs off).

3- I tried to supply the ds3231 chip by the microcontroller and used a pulldown resistor on its VCC pin. So I could've manually turn the DS3231 chip on or off. After applying the input voltage, the microcontroller waits for 1 second and then connects the ds3231 supply voltage and starts to communicate. It definitely removes the "unstable supply voltage" after switch on/off. 

4- we also used an original DS3231SN for our work.

This topic has a solution.
Last Edited: Wed. Feb 6, 2019 - 09:32 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Post your code e.g. ZIP up your AS7 project.

Post a schematic or photo of your wiring.

 

The DS3231 should be quite happy alternating between 3.3V VCC and 3.0V VBAT

The mega32 should be quite happy powering on and off if you have enabled Brown Out Detection and have sensible layout with capacitors.

 

Yes,   it seems like a good test i.e. accelerated power-cycling

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you, 

I send you the schematic and PCB as photoes.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Nothing to do with your problem but is C14 really 10uF? (usually 100nF)

 

I remember having a similar problem the first time I used the DS3231, the time would speed up for some reason. After much hair pulling over a couple of days I found a small RF ripple on the 5V supply and this was upsetting the clock. It turned out I had left out a capacitor on the LDO regulator I was using, so used to just use a couple of 100nF with other regulators but this one needed a larger cap on the output side as well as the 100nF.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

The datasheet says not to run signal tracks under the device. The vcc could probably use a bypass cap close to the device.
The bypass caps on the regulator are too far away from it.

Last Edited: Sat. Feb 2, 2019 - 11:09 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for your reply. 

C14 is 10uf but C7 is 100nf which is placed on the supply of DS3231 and close to it. Does it really required to replace C7 to a 100nf cap?

I also have other capacitors (C2, C3, C4) on the supply of microcontroller.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Do you have the brownout detector on in the MCU?

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

'close' is about an inch of track. Probably not close enough. Remember, tracks have inductance - you want to minimise this inductance for the bypass cap to be effective.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I have also vague memories of reading that this thing slows down when the time is read very often.

It might be a good idea to test this by reading it continuously for 24 hours.

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've placed C7 close to the device. you can see it in the pcb design (under R15, top right of DS3231). is it far orf close?

Last Edited: Sun. Feb 3, 2019 - 04:17 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

well, I don't think so... 
does it really affects the design?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

take a look at C7 (under R15, top right of DS3231). is it far or close?

Last Edited: Sun. Feb 3, 2019 - 04:17 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sorry, I didn't get it completely. you mean that if I read the time of RTC very often, it affects the timing of it?

and I have to read the time constantly? Did I understand you?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

makhorsandi wrote:
if I switch it's power on and off frequently, it's time value increases occasionally. In my last test, I switched the power as 5 seconds on and 5 seconds off; after an hour, the seconds of device increased about 40 seconds.

Repeat your experiment by only resetting the MCU
I mean keep power ON for DS3231 only reset the MCU (short circuit C5 for a few seconds and release again)
After this experiment you will know if the problem is from MCU side or it is from DS32321 side
.
Kartman wrote:
'close' is about an inch of track. Probably not close enough.

+1
.
makhorsandi wrote:
take a look at C7 (under R15, top right of DS3231). is it far or close?

I read somewhere bypass caps have no effect if placed far than 2cm,
They MUST be as close as possible to Vcc pin.
ka7ehk wrote:
Do you have the brownout detector on in the MCU?

+1

Majid

Last Edited: Sun. Feb 3, 2019 - 06:00 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Your schematic is pretty vague because the resolution is too low.

There are also a lot of pin numbers missing.

 

There is also not much filtering happening.

I see quite a lot of (100nF? decoupling caps (can't read the text properly) but I see no bigger buffer caps.

 

How are you switching your supply voltage? Some Fet / Transistor, or a hard switch / Relay, and where does the power come from?

 

In my experience such simple power designs sorta work on the bench, but for more reliability you need some LC filters.

High frequency stuff (switching events, external noise picked up through cables) passes through almost everything.

High frequency noise goes right from the connector to your AMS1117 without taking a detour through C15 and the voltage regulator itself is also too slow to filter it.

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

well I'll upload a new color shcematic of DS3231 part.
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

well I'll do the test you said about the resetting the MCU.

The 100nf capacitor is physically close to the device but the tracks seems to be far to VCC and GND pins of DS3231.

I'll activate the brown out detection fuse bit of the MCT to see if the problem solved.

yes​​​​​​​

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

well there are several 100nf capacitors in my design. 3 of them close the MCU supply and one close to the DS3231. I also added a 10uf capacitor after the 3V3 regulator. Do you think I have to add a specific LC filter, ferrite bead or other buffer caps?

 

I've connected two types of power supplies before the regulator (a lab power supply and a capacitor-based step down none-isolated supply) and they had no difference. I've switched the supplies by connecting the input 220V of related supply using a relay and a timer.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

makhorsandi wrote:
I'll activate the brown out detection fuse bit of the MCT to see if the problem solved.

You need to select :

1) BODEN

2) BODLEVEL (table 15)

3) SUT1, SUT0 (table 10)

.

.

Majid

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Too far!. And the capacitors for your regulator - too far. The distance of the tracks are probably good for oscillations at 100MHz. C7 should be next to pin 2 of the ds3231 and don't run the power track under the ds3231. What difference does it make? Could be very significant.

Last Edited: Sun. Feb 3, 2019 - 09:16 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Keep in mind that 'close' capacitance on power rails should be considered as a loop.  If your cap is v. close to the chip on the ground, but the power has to ramble all over to get there, it's not going to be a very happy cap.  The corollary is also true - if it's very close to power but a long way from ground (see: politicians cheeky) then it's not going to help much.  S.

 

Edited to add PS:

PS - I really don't like that U3 trace splitting the ground plane.  What made you think THAT was a good idea?  S.

Last Edited: Sun. Feb 3, 2019 - 09:57 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

makhorsandi wrote:
Do you think I have to add a specific LC filter, ferrite bead or other buffer caps?

In my book any inductor or ferrite bead is better than none.

Two are better than one.

 

It is important to  make sure that the inductor or ferrite bead is the only entry to your PCB. For example do not put a GND plane under the track between the power input and your inductor.

But this stuff gets real complicated real fast, which is why most people (including me) sort of roll their eyes and try to follow some simple rules instead of juggling with Maxwell's Equasions (Did he have a silver hammer?) or study very thick and expensive books.

For a first experiment my advise is to add some filter components in the power cord close to the PCB.

If you happen to have an splittable Ferrite core in a plastic housing, then you can also wrap that around your power cord.

I've had significant improvement in reliability by adding such a ferrite core to the end of a long CAT-5 cable in my home network ( 24Vdc power + RS485 data).

After that I started paying more attention to filtering.

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

well....

it seems that the problem solved. I's been 3 days that I've checked the circuit and it has been going crazy, but since yesterday, it had no problem. I made several changes (adding 100nf caps, remocing power line under chip, etc) but after activating brown out detection the problem has not occured yet...

but I still need more time to be sure....