Notifications
Clear all

Power Off Sleep Circuit based on Real Time Clock (DS3231)

51 Posts
4 Users
17 Likes
4,377 Views
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6895
 

@davee I finally got a nice view of the INT pin. I have a 5 sec delay between the pin firing and the reset command. The scope scale is 1 sec per large division. Tomorrow I will use the logic analyzer for the same task. If I get the INT pin to show up on the logic analyzer, I will then try the I2C pins.

70199269480  1478EB45 BB11 48A1 B710 5B3FC588D35A

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1659
Topic starter  

Hi Ron @zander,

   Looks like your making some good progress ... and have been able to see for yourself the difference  using 'proper' I2C pullup resistors makes to the waveforms, compared to relying on the microcontroller's internal pullups.

Personally, I would recommend continue (software and hardware) prototyping your application as far as you can with the RTC board commercial board so you get more familiar and begin to realise all the little niggly things, before you start aiming towards wiring your own, though you can be drawing up a schematic etc., and possibly any 3D printing bits as you go.

------

You mention doing a chip level build ... and that is certainly possible, but the days components with long wire legs and tagstrips are long gone. Of course, a few components are still available in this form, but not enough to make an interesting circuit.

For prototyping, you can get small PCBs that have a single component footprint, and 0.1" spaced pins, which help to put a prototype board together, though you will need to fix your hot air 'wand', etc. if you don't want to do an 'impossible' hand soldering job.

Otherwise, maybe it is time to get into the PCB design world .. Not my expertise really either, though I have done a small number many years ago when the company was paying for both the software and the board fabrication. Now the software is free and there are companies chasing your business for just a few dollars.

-------

You ask about decoupling capacitors ... these aim to provide a small power 'reservoir' to the chip, which will tend to take 'slurps' of current when digital circuits change state. They need to be mounted as close as possible across the power input pins (Vcc and ground). The wires or tracks need to be kept as short as possible, as even a few millmetres of copper has an appreciable inductance, which will oppose the capacitor's attempts to supply the transient current.

The values to pick are a bit of a mixture of art and science ... often chips will give some clues in their data sheets, but the DS3231 data sheet is unhelpful. The tricky bit is you could build 100 identical PCB units with a decoupler missing, and 99 of them could be fine, so it is always difficult to know whether your provision is enough.

The DS3231 board you have has two capacitors in parallel .. look for the snip below on the circuit diagram I (and others) published before.

 

image

 They are 0.1uF and 1uF in parallel, and are surface mount ceramics .. small white bricks with metal coating on two facing sides.

That seems a reasonable start to me.

I would also recommend a similar 0.1 uF from VBAT to GND, to provide some decoupling on that supply. I guess they thought having the coin cell so close to the chip, they could save a few cents.

I would say the copper tracking on the board to the decouplers is much longer than would normally be recommended .. I think this chip is aimed at low power, not speed, so it is probably more forgiving than most contemporary digital chips.

I think I have addressed your main questions, but feel free to bring any I missed to my attention.

Hope that helps -- enjoy yourself!

Dave


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1659
Topic starter  

Hi @byron,

  Good to hear that you have got some success. If you are going to do a PCB, I guess this might be a good time to start doing it on a 'slow part-time' basis, as you won't mind waiting 2-4 weeks for delivery, etc.

As for

For a test I left out the switches, so be careful not to power the pico via its usb and the battery pack at the same time if going the same route. (I realise I don't actually know what would result, but I don't imaging it would be good 😎)

My observation is that getting it wrong 'encouraged' the board to get in a knot about not wanting to download a new code build. I am not sure of the exact details of the knot, but it was frustrating! There may be other downsides as well, I haven't looked into it.

Take care and best wishes, Dave


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6895
 

@davee I am not using the ZS-04 board, I am using the Chronodot. It is just the DS3231 chip with 1 capacitor, probably where you said it should go. I doubt 3D printing is in my future. I can't handle the software. It's one of the most annoying aspects of my autism. Some software I eat up, while others, like CAD, I am hopeless. I have tried quite a few times, and it's hopeless.

When I started, I got a combo soldering and air guns. After a while, the air gun stopped working. I need to get one of those smoke-sucking outfits since I will be in an apartment in a few months, and making solder smoke is a bad idea. I will spend much more money and get a good quality soldering iron and hot air wand.

I have a collection of boards to build on, and the PCB layout is basically CAD, so I won't be doing that, either.

Ok, I get the idea behind the capacitors. Not something we had to worry about in the tube days, at least not that I remember.

The Chronodot V2 board I am using now has the capacitor from VCC to G and open holes for inserting pull-ups from SCL and SDA. I will either scrap the old ZS-04 boards or use them for less critical things or, better still, donate them to whatever electronics club I find when I move.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1659
Topic starter  

Hi Ron @zander,

  Sounds like you have a plan and a way forward.

  But 'tubes' ('valves' in my part of the World) certainly did need decoupling capacitors, albeit you might have called some of them bypass capacitors.

  • in parallel with the cathode bias resistor
  • from the screen grid down to 'chassis'
  • the main 'smoothing' capacitors also provided a decoupling function
  • in a radio or amplifier, the input stages might have had resistor fed anode supply, with decoupling capacitor to 'chassis'

Best wishes, Dave


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6895
 

@davee That was over 60 years ago, so my memory is highly suspect. After graduating in electronics, I never worked in that field. I did a couple of years as an industrial electrician, followed by a lifetime of computers, first in hardware, then software of all kinds. The IBM hardware was transistor-based, but I dealt with them at a card level not the discrete component level so I didn't learn much if anything about solid state. I did get to use a scope a bit but again working with boards or cards a bit bigger than a playing card called SMS logic.

That reminds me of the most diabolical bug I ever worked. I had worked a full 24 hrs with no progress, basically, the computer an IBM 1401 would not start, like a boot today. They sent a guy from the factory which was only an hour away to assist me and about 8 hrs later he said 'I saw something like this once before' whereupon he connected a wire from the ground pin to under the head of a screw on the frame. Problem solved!

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
DaveE reacted
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1659
Topic starter  

Hi Ron @zander,

   Good to hear from you ... perhaps this will bring back some happy memories:

https://www.ebay.com/itm/285024504240

Best wishes and take care my friend, Dave


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6895
 

@davee Yes, very familiar. Strange though, they got overlooked as after the cards were no longer needed, they should have removed the contact tab as it contained gold. Somebody messed up.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6895
 

@davee Dave, here is a photo of one of my Chronodot V2.0 boards with 2 4k7 resistors soldered into the provided placeholders on the board. 

Now, I have to show my ignorance.

I think you said a similar pullup is needed for 'normal' usage where the INT pin is attached to an MPU/MCU pin. My question is about the meaning of the CONTROL Register Battery mode bit. I am unfamiliar with the term 'high impedance' My HS education didn't talk much about impedance, and IIRC impedance was to do with coils/chokes, but I can sense it means more than that today. Here is the datasheet info. My question is, do I still need a resistor (of what value) or is High Impedance the same concept functionally? Since the ISR only fires if the INT pin is low does it matter if it is held HI if it is 'high impedance'. 

This is the infamous Battery Mode setting that caused many programers to fail to get the DS3231 to work on battery. Your solution cleverly eliminates the problem.

Screenshot 2023 04 02 at 10.12.51
Screenshot 2023 04 02 at 10.14.51 1

 

When BBSQW is logic 0, the INT/SQW pin goes high impedance when VCC < VPF. This bit is disabled (logic 0) when power is first applied.

 

IMG 7443

 

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1659
Topic starter  

Hi Ron @zander,

From a dictionary viewpoint:

  Saying a component has a "resistance" suggests it is a resistor or a component that is acting like a resistor, with no consideration of the effects of inductance and capacitance.

  "impedance" broadens this description to take into account not only the resistance, but also the inductance and the capacitance of the component(s).

When a circuit only experiences a constant DC voltage, the capacitance and inductance have no effect, so "impedance" and "resistance" are synonymous.

It is not unusual, and still correct, for a circuit part to be described as exhibiting a particular impedance (high, low, 1 MOhm or whatever), when that value is principally also the resistance value.

-------

Below, I'll discuss the effect of the alarm function on the INT/SQW output in simple terms of tripped/not tripped/reset etc. Of course, much of this activity only applies when the DS3231 has been appropriately configured.

-----------

The "Table 1" you show only really states which power source is powering the 'brains' of the DS3231, saying that the 'brains' will use power on the chip's Vcc pin if it is available, otherwise it will resort to Vbat, usually a coin cell.

Hence, when the DS3231 is communicating via the I2C, which makes the 'brains' work much harder and consume much more power, it is important to provide power to the chip's Vcc pin.

However, the 'brains' have no way of directly powering any output pins, regardless of the voltage on the chip's Vcc pin. This requires external pull up resistors, connected to a supply. The supply for the I2C pins must be 3.3V for the Pico, whilst the INT/SQW pin is the alkaline batteries, to control he external MOSFET Q1.

---------

For the specific case, of the INT/SQW output. The chip can effectively 'connect' the pin to the ground pin of the chip, which it does when the alarm trips. However, it cannot put a voltage on the output pin.

Hence, to be able to observe whether the pin is or is not 'connected' to ground, an external voltage source, via a resistor, must be added ... often called a pull up resistor.

If you look at the circuit I published, you will see that I have 1 MOhm resistor, connected to this output pin, the other end of which connects to the +4.5V battery terminal.

https://forum.dronebotworkshop.com/wp-content/uploads/wpforo/attachments/3899/6553-battery.pdf

After the alarm has been reset, the chip will have an extremely high resistance/impedance from the INT/SQW pin to ground (probably over 1 GigaOhm), so that there is no significant current flow through the 1MOhm resistor, and the voltage at the chip pin will also be +4.5V.

When the alarm trips, the chip will change the resistance between the INT/SQW pin and ground to a low resistance (say less than 1kOhm), effectively connecting the 1MOhm pullup resistor to (very near) ground, and reducing the voltage to almost zero.

However, the same resistor is also connected to the source and gate pins of the external MOSFET Q1.

Before the alarm tripped, both ends of the resistor were at the battery voltage of +4.5V, so voltage difference between the gate and the source was zero. Under these conditions, this MOSFET was non conducting .. that is no significant current could flow between the drain and source pins.

When the alarm tripped, the 1MOHm resistor voltage (with respect to ground) was +4.5V at the end connected to the external MOSFET's source pin, and 0V at the other end. Hence, the gate of the MOSFET was now -4.5V with respect to its source pin, causing the effective resistance between the drain and source to fall to a low value (around 0.2 Ohm), and hence supply 4.5V to the Pico.

Hence the 1 MOhm resistor is acting as both a pull up resistor for the INT/SQW pin, and providing the voltage input drive to the gate of the external MOSFET Q1.

In fact, the value of this resistor could be made even higher, but was chosen as a 'guaranteed to work' starting value. Hopefully, you will agree 1 MOhm is "high resistance", and hence "high impedance". Its battery drain is 4.5 microAmps from the external 3 x AA alkaline batteries, whilst the alarm is in the' tripped' state and the Pico is powered. Whilst the alarm is "not tripped", the current flow from the external batteries was too small for the 0.1 microAmp resolution of my meter to show.

--------

Hope that clarifies a couple of points.

Best wishes, Dave


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6895
 

@davee Did you not notice I said 'normal' usage, NOT the Dave solution? Both my Chronodot and modified RTC board work fine with NO resistors added, but I did see the difference that they made on the SDA/SCL pins, but the INT pin signal is pretty much a square wave. I was hoping you looked at it and saw that and were going to tell me it's not needed. I am sure there is nothing wrong with adding it, but I take my queue from Chronodot, They provided space for the SCL/SDA pullups but did not think it was needed for INT, I wonder why? Don't bother responding Dave, we have beat this to death. If I build with a PICO, I will probably use the PICO board as it is designed for the PICO. Here is a link to it as FYI LINK

No disrespect intended Dave, it's just that I am not learning anything new at this point and I probably will never even build anything using it, it's just wishful thinking. One of the hazards of autism.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1659
Topic starter  

Hi Ron @zander,

   re: I said 'normal' usage,

The only way the 'brains' of the DS3231 can communicate to the outside world .. e.g. a Pico, is by the outside world providing an external power source, via a "pull up resistor", so that the external world has a voltage that changes, and can be interpreted.

This applies to the two I2C pins and the INT/SQW pin.

From the DS3231's health viewpoint, the external power source voltage should not exceed 5.5V  (or go below 0V) and the resistor current shouldn't go too much over 1 milliAmp. Providing this proviso is always met, the DS3231 isn't directly affected by resistor values or voltages on the INT/SQW pin.

The two I2C pins are both inputs on the DS3231, so the voltage waveforms must conform to be correctly interpreted for communications.

So if you want to 'see' when the INT/SQW pin is triggered by an alarm, you need to provide a suitable external voltage and resistor. However, the exact physical form of that resistor, is irrelevant. If you have microcontroller input which is held high by a resistor, that can interpret when it is pulled low by the INT/SQW, and this input meets the DS3231's health voltage and current limits, you have a potential solution. 

Remember, that as you have already seen with the I2C pins with your scope, if the pullup resistor has high value, it will take a considerable time to rise from 0V to the 3.3V high voltage logic level. For an I2C pin, this could cause data corruption. It also makes the input more sensitive to pickup of local electrical and magnetic noise.

Similar considerations apply to the INT/SQW line, but only the microcontroller can see the 'confusing' signals. Nevertheless, having a high impedance circuit attached to the interrupt input of a microcontroller is inviting problems, as even a brief noise pulse could interrupt the processor, and clearly the interrupt input must be negated before the processor is ready to accept the next interrupt. Using microcontroller "input pullups", whose values are high and poorly controlled to pull the pin high is very poor design, even though it may well work in tests.

(Using a high value resistor to control the power, as in my circuit, is less of a problem because the DS3231 INT/SQW can pull down with a low-ish impedance, so that it robustly switches the Pico power on, whilst the effect of slightly delaying the power removal or by noise unintentionally momentarily powering up the Pico, will not be maintain the power long enough for it to boot and do anything significant. )

Best wishes, Dave


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1121
 

Posted by: @zander

I think you said a similar pullup is needed for 'normal' usage where the INT pin is attached to an MPU/MCU pin.

I know you want to give this all a rest, so ignore this and move on, but I cant help mention for anyone else that could be interested in the RTC board that whereas 'normal' usage may be to attach Int to a MPU/MCU pin, the point of this exercise was to connect the Int to a gate of a mosfet.  A different thing entirely and not normal usage.  When I connect the int pin of an unmodified DS3231 board directly to a pico pin then a pull up resistor as per the  ' Power Off Sleep circuit was not needed ' (but a pull-up is provided on the board along with the i2c pull-ups).  

When you first mentioned the chronodot RTC board I did look up the details and I posted some of the specifications and the following, as per previous post, should be noted.

" The SQW pin can be configured to output a square wave signal at 1.000 Hz, 1024 Hz, 4096 Hz, or 8192 Hz. This is controlled by the RS2 and RS1 bits in the control register (address 0x0E). The pin can also be used as an alarm trigger. If the INTCN bit in the control register is set, then the output will go low when the current time matches the time set in either of the two alarm registers. This pin needs to be pulled up to VCC with a resistor if it is used, 10K would be a good choice." 

As concerns the pico RTC board I think you have, I have looked at it in the passed.  It will connect directly to the pico and can be used as a RTC and give alarms to the pico, but it will not, without surgery, be any good for removing and restoring the power to the pico.  The alarms will normally be read via i2c.  Note in the docs for this board it states  " The INT pin of DS3231 is not used by default. if you need to use it, you can solder the 0R resistor on the R5,R6,R7  positions ".   The real point of this board for the pico is to give a battery backed RTC as the internal RTC on the pico starts from unix 0 time on bootup and the current time has to be set via the internet ntptime  or via an external battery backed RTC. 

Surely over and out from me too, see you on another topic.

 


   
Ron and DaveE reacted
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1659
Topic starter  

Hi Ron @zander,

I am sure there is nothing wrong with adding it, but I take my queue from Chronodot, They provided space for the SCL/SDA pullups but did not think it was needed for INT, I wonder why? Don't bother responding Dave, we have beat this to death.

Different designers have different requirement specifications to meet ... I don't know what Chronodot's or any suppliers requirements were ... presumably not one that used the INT/SQW output pin ... maybe just an RTC to 'consult' to find the time when required.

If I build with a PICO, I will probably use the PICO board as it is designed for the PICO. Here is a link to it as FYI LINK

No disrespect intended Dave, it's just that I am not learning anything new at this point and I probably will never even build anything using it, it's just wishful thinking. One of the hazards of autism.

It's all about learning, discovering and making choices, hopefully based on being as well-informed as reasonably possible. I can quite undestand deciphering my sermons takes some patience!

Take care, maybe a take a break and think about what you want to do next!

Best wishes,

Dave


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6895
 

@davee @byron I just found this video VIDEO  and thought it might add to our collective knowledge. These are the guys who most impressed me with their mastery of low power in the real world. This 'hack' is very different and so much easier with the Chronodot (no hack needed, I think). Couple these discoveries with the knowledge from the DS3231 datasheet that the I2C is powered by VBAT or VCC 

I2C Interface
The I2C interface is accessible whenever either VCC or

VBAT is at a valid level.

and you can see how the ZS-042 can be made into a much better board. Of course, for slightly more money, the Chronodot V2.0 is a better choice, technologically speaking.

The solution that Dave produced is the hands-down lowest power solution but as you are both aware, that solution is only usable with an MPU/MCU that can be turned ON quickly enough. (the bootloader removal on a UNO or NANO per Ralph Bacon VIDEO might be a worthwhile additional technique)

But for those solutions that do not meet the criteria of Dave's solution these new findings are more fuel for the fire.

I have not heard of any updates on the PICO re low power, and do not know if the Dave solution even works on a PICO programmed in C instead of Python. Have you heard anything @byron ?

IF the PICO isn't ready by the time I am ready, I think a bare ATmega328P might be the route to go with a Chronodot v2 or if data logging is needed v3.

EDIT Here is a ton of info re low power, logging, harsh environments. LINK

EDIT2 More info LINK

 

 

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Page 3 / 4