Notifications
Clear all

External Power on/off control circuit.

126 Posts
5 Users
9 Reactions
5,788 Views
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1123
Topic starter  

Posted by: @zander

This device is just supposed to turn on the power to the PICO, the PICO will take as long as it needs to do whatever and then send a signal to a device like this turning it off.

Thanks Ron, thats exactly what I have in mind.  For now I'm going to get stuck in with digesting all the info.  


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1123
Topic starter  

@davee 

further to my previous post I now realist the input voltage of the pico can be between 1.8–5.5V DC, so it does a bit of voltage regulating on its own its seems. 


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1123
Topic starter  

@will @davee @zander @papajoe0418

Now I know the pico is tolerant of a range of voltage inputs (between 1.8 and 5.5 volts), and assuming that the components in the circuit @will gave a link to will all be ok with 3 volts (2 AA batteries), then looking in my parts bin I have all the components required except for the RTC and the mosfet.  I will order those tomorrow so I may be ready for the first experiment sometime quite soon.

I'm not completely clear yet on how the DS3231 will work in that circuit. 

I give the circuit below for handy ref.

sch 1

As you can see the DS3231 will have to briefly close the circuit in place of the switch.   An adafruit DS3231 board I looked at seems it can be powered by the same circuit, its voltage range is 2.3V to 5.5V.   It can also be powered with a coin battery presumably to keep the setting once the VIN volts to the DS3231 falls below 2.3V.  (at below the 2.3 volt level I assume the DS3231 will no longer work with this circuit).

Looking at the diagram it seems to me its vin pin will be connected to the IN in the diagram, and ground to a ground connection.  I've not worked out what pin to connect to the switch 2 connection to get it to switch the power to the pico on.  The RST pin seems the likely candidate from the adafruit docs.   What do you think?  

A link to the adafruit board is:

https://learn.adafruit.com/adafruit-ds3231-precision-rtc-breakout/pinouts

Any more thoughts on this or alternative circuits will be gratefully received.

Well thats enough for today, Zeberdee has spung out his box, so its goodnight from me.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2538
 

@byron 

Originally I thought the same thing. But I've come around to believe that the voltage has to be maintained between IN and OUT so that S2 has to be replaced by the source and drain of the MOSFET and the gate of the MOSFET is controlled by the RTC. 

Anything seems possible when you don't know what you're talking about.


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

@byron That is the circuit @will found. The missing piece is the use of the DS3231 in place of S2. Use a MOSFET and let the DS3231 alarm pin control the Gate. IIRC, the DS3231 alarm pin is logic HIGH so any Enhancement mode N channel low power MOSFET should work. I hope to get a PCB made for this as I will use it in a few places, but I probably won't get around to it for quite a while due to health and personal tasks taking most of my time for at least the next 6 months.

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.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1721
 

Hi @byron,

It is much too late now for me to look through all discussion that has followed my last sermon. However, as I think you have discovered, the pico has its own switch mode supply, which has been optimised for efficiency, but is still too thirsty for 24x7 connection to a small battery. Beware the maximum voltage it will accept is much lower than most of the common cheap modules and voltage regulators used in Arduinos, etc. Any readily available external SMTP is likely to be far less efficient, and will probably reduce battery life!

------

I deliberately didn't get into the depths of connecting a particular RTC as I just wanted to introduce the minimum circuit in that sermon, bearing in mind you might not have seen a PMOS fet used in that way before.

As for LTSpice, I use it with Windows, and I think there is a Linux variant, but I have a feeling Apple is not supported.

Best wishes, Dave


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

@davee SMTP? I didn't know we were building a mail server.

Without the RTC, the circuit is useless. The objective is to wake up at certain times of the day and sleep most of the time. Not to worry Dave, @will did it the old-fashioned way (google) and then we adjusted it to work with the RTC. I think for the owl project it's probably overkill, but I will make good use of it for my game cameras. If things go well, I should get a start on building that late fall or maybe next winter, too much uncertainty in my life right now to be more specific.

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.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1123
Topic starter  

@will @davee @zander @papajoe0418

This missive is concentrating on the DS3231 and my understanding thus far (which may well be flawed).   I've not yet had time to look at the spice diagram provided by @davee that appears to be on a different and possible interest tack that does not use the DS3231.  (I've just downloaded a spice  for the mac, so I may be in business with spice later on)

Following on from all your various comments and some googling on the DS3231 this is what I think is the situation:

The DS3231

1. The DS3231 is usually connected to a microcontoller via an i2c interface to set / read the time on the RTC. It has a pinout called SQW that is an optional square waver or interrupt output. It is this SQW pin, which is normally pulled high, that can be driven low on an alarm condition (an interupt signal) that can be programmed into the DS3231 (an interupt signal)

2. I assume that once an alarm setting is programmed in to the DS3231 its battery backup (a coin cell battery) will keep these settings when its disconnected from a microcontroller and power.

3. I hope that when power is again applied to the DS3231 by means of an external circuit that can supply a voltage of between 2.3v and 5.5v (that volt range is for the adafruit breakout board - I will have to check other breakout boards) then it will function as normal and will continue to send an alarm/interupt signal on its SQW pin.

The Latching Circuit:

The latching circuit found by @will and created by Electonoobs needs to momentarily close a push button switch to create a latching circuit that could power a microcontroller. This push button switch can be replaced by anything (such as a vibration switch etc) that will close the switch.  (just a momentary switch close is all that is required)

The latching circuit connects to a pin on the microcontroller to wait for this pin to be set HIGH to remove the power latch to remove all power from the microcontroller.  (the microcontroller and the latching circuit must share a common ground)

Both @will and @zander mentioned linking a mosfet to the DS3231 alarm pin (the SQW pin) to achieve this momentary switch close.  Its not clear to me how a SQW pin being driven low can be used in conjunction with a mosfet to achieve this.  Any clarification on the exact circuit for this would be most useful.

Info / Links:
Other links / copied items garnered from googling on the topic of the DS3231 are given below for referece.

The SQW pin:

Active-Low Interrupt or Square-Wave Output. This open-drain pin requires an external pullup resistor connected to a supply at 5.5V or less. This multifunction pin is determined by the state of the INTCN bit in the Control Register (0Eh). When INTCN is set to logic 0, this pin outputs a square wave and its frequency is determined by RS2 and RS1 bits. When INTCN is set to logic 1, then a match between the timekeeping registers and either of the alarm registers activates the INT/SQW pin (if the alarm is enabled). Because the INTCN bit is set to logic 1 when power is first applied, the pin defaults to an interrupt output with alarms disabled. The pullup voltage can be up to 5.5V, regardless of the voltage on VCC. If not used, this pin can be left unconnected.

SQW - optional square wave or interrupt output. Open drain, you need to attach a pullup to read this signal from a microcontroller pin

Setting the Alarm with Arduino

https://github.com/JChristensen/DS3232RTC/issues/5

Setting the Alarm with micropython

https://github.com/pangopi/micropython-DS3231-AT24C32

Ok, so now on the spice download 😀 


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1721
 

Hi Ron @zander,

  Sorry my mistake ... I picked the wrong one from the acronym soup ... instead of SMTP I meant SMPS - Switch Mode Power Supply .. I should have listened to Zebedee when he said 'Time for bed'!

NB my 'concept circuit' was just that ... I have a couple of thoughts about how to connect the DS3231, but I was aiming to demonstrate the basis for any wake up source, without getting into the details for any particular one.

Best wishes, Dave


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

@byron I am attaching the author's explainer. I think everything you said was accurate other than not knowing how to use the SQW/Interrupt pin. I am also attaching the comparison sheet from the mfg for all the DS323X devices. HERE  The 3232 is newer but the only significant difference is the addition of some SRAM that we do not need and some tweaking that you can read about in the link. The 3232 library has the best examples and the 3231 library has the best alarm details however it is bit level, I recommend the high level library calls. I attached the comment block for the alarm details.

I leave it as an exercise for the reader to choose and manipulate some other examples to achieve the desired results.

As to how to use the RTC and a MOSFET to replace the NO switch, it's just a matter of choosing the right MOSFET. I don't know how to figure out the exact number but it will need to be an Enhanced Mode P Channel MOSFET that requires a Gate of logic LOW to cause the 'switch' to close. Please excuse me if I got that wrong, I am just now learning about MOSFETs as my education in electronics was before they were taught in school, but I do know enough to know that some require logic low to trigger and some logic high so the answer is out there.

The last attachment shows 2 things, the first is the number of examples for the DS3232 library, and the 2nd is that I have 3 libraries in my personal library, one for the 3232 and 2 for the 3231. Each has value, but I will probably reduce them to one once I have started using them seriously.

JOB DONE, thanks to @will and his masterful google skills.

Screenshot 2023 02 27 at 05.58.45
Screenshot 2023 02 27 at 05.47.42

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.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1721
 

Hi @byron, Ron @zander, @will@papajoe0418,

  Lots of crosstalk to cope with. Sorry that my main sermon took so long to put together from first principles  ... obviously it uses the same MOSFET trick for supplying power to the Pico, wrapped up in a latching circuit.

For shorthand, I'll assume the processor to be powered up is a Pico, but it could be any of the usual suspects, such as ESP32/8266.

In answer to @papajoe0418 's question, then yes, it is possible for the Pico to cut it's own power and the latching circuit does that. I think there may be other options (unproven of course), discussed below.

I had also thought about adding a latching facility, but decidded to leave it for this sequel sermon.

There are also other 'specification' options that might be different, depending on what you want to happen.

  • Is the DS3231 RTC chosen to do the wake up?
    • I'll assume so for now ...
    •  
  • What sort of a wake up schedule is desired ... it can apparently do a repetitive wakes at a FIXED rate, such as once per minute or once per hour (forever), but is that what is required, and does the DS3231 do the required repetition rate? (Sorry, I haven't carefully analysed the precise options it can achieve.)
    • This might be fine for collecting and storing temperature data on a 24 hour basis, not so good for things like hooting that are only wanted during the night, although the processor could find out the actual time and compare to schedule to decide what to do.
    •  
  • Does the processor need to retrieve the actual time from the RTC?
    • e.g. because it is desirable to label any data with time and date, or because the actions may differ depending on some kind of schedule
    •  
  • Does the Pico need to change/set the DS3231 alarm times?
    • e.g to avoid it activating during certain times of day or night, or for a schedule that varies the sleep time
    •  
  • Is minimum component count a high priority?
    • a latching circuit is slightly more complex, but is more flexible about the wake time
    •  
  • Is the total processing time known to be either less than 1 second or less than 1 minute?
    • related to the minimum component count question
  •  

--------

The following section should be treated like Baldrick's cunning plans .. Blackadder has yet to review them ... you have been warned ...

I haven't carefully checked, but I think the alarm output pin can be programmed to be low, when the actual (RTC) time matches either of the preset time in the alarm registers.The following is my initial impression of when the alarm output pin will go active low .. it may have errors, as I haven't got one to check and I only glanced at the data sheet, so please check and let me know what I have misunderstood.

The alarm register fields cover days (1-31) down to seconds (0-59), so if all the alarm register fields of a given register are 'enabled', I presume this means the alarm pin will be 'active' for 1 second per month.

I can't find any mention of how long the alarm output is active, so I can only guess it depends on which fields are being compared. e.g. if the seconds field is compared, then the match will last for 1 second, but if the minutes are compared, but seconds are not, then the match will last for 1 minute. Note this is only a logical guess!!

Since there are two alarm registers, then each register contributes different alarm match options, which makes it a little complex and error prone for me (another warning!).. I discuss a few options that might be of interest

I think it is possible to mask any of these field matches, so to enable repetitive 'active' periods, eg.:

  • mask the day field.. DY/DT= X,  A1M4 =1,  A1M1-3=0
    • .... the alarm will be active for 1 second per day (it doesn't care which day it is)
    •  
  • mask the seconds field  DY/DT= 0,  A2M4 =0,  A2M2-3=0
    • ... the alarm will be active for 1 minute per month (assuming that day exists in that month .. day=30 will not match in February!)(it matches for the whole minute)
    •  
  • mask the date, hour and second fields DY/DT= X,  A2M3-4 =1,  A2M2=0
    • ... the alarm will be active for 1 specified minute in each hour

So that if the processor required about 30 seconds, once per hour, the last of these three options would provide power to processor for 1 minute, allowing it to complete its task with a comfortable margin.

Although the processor would be powered for longer than necessary, it is possible to consider the processor would go into some kind of sleep mode, so the current consumption would be low. When the power is restored at the next active period, the processor would be doing a power up reset, so any doubtful issues regarding sleep mode recovery should be irrelevant. This would remove the need for any external latching action

An alternate approach could be:

  • mask the date and hour fields DY/DT= X,  A1M3-4 =1,  A1M1-2=0
    • ... the alarm will be active for 1 specified second in each hour
    •  

The cunning plan here is to assume that 1 second would be long enough for the Pico to wake up and assert a level (specified as high or low, chosen to be convenient to the external circuit) on one of its GPIO pins. This pin would in turn drive a transistor to hold the power on ... when the processor had finished its task, it would change the level on the pin, thereby cutting the Pico's own power supply.

-----------------

Referring back to my concept circuit:

image

The minimum component connection option, would remove the NMOS FET and connect the DS3231 alarm output directly to the gate input of the PMOS FET, labelled Control_in. Provided the Pico battery voltage does not exceed the 5.5V rating of the DS3231 alarm pin, it should be possiible to program the PICO to be powered for period of 1 second or 1 minute, using the options described in the previous section.

The second option would start with the same circuit, with the addition of keeping the NMOS FET, but obviously not the voltage source V-RTC_output.This would use the last cunning plan in the previous section. In this case the NMOS-FET gate would be driven by the PICO GPIO output pin. The pin would be set high at the beginning of its processing cycle, and then returned to low to cut the power, assuming the DS3231 alarm pin has now become inactive.

-----------

Obviously, it is also possible to build a more complex latch circuit, as the Electronoobs have provided.

-----------

In addition to alarm ouput, you may wish to connect the SCL and SDA pins between the Pico and the DS3231. If so, be careful to ensure they have pull up resistors, connected to the regulated 3.3 V power from the Pico. That is the resistors should only have power when the Pico is powered, and it should not exceed the ratings of the PICO GPIO pins.  This connection means the Pico can set the next alarm times, etc., read the present time, and even reset the RTC time if the Pico has access to a more accurate value, e.g. via NTP.

-----------

I hope some of this is helpful and best wishes, Dave


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

@davee No need to guess anymore, I just posted the explainer and the bit mask thing. This use case is a little different in that for a period of time there will be repeated alarms and then for the bulk of the time (18 hrs), everyone sleeps. 

Yes the PICO or whatever board is picked will need to get the time to determine the next wake time from its hardcoded table.

NO WiFi so no NTP. Not needed in any case, the RTC is plenty accurate for this use case.

I think an alarm interrupt is a typical pulse, not on for the alarm unit as you guessed.

I think the add-on circuit should be dumb in that it turns on the PICO and then the PICO decides when to turn off the add-on circuit. The PICO has the information to decide, but the add-on does not.

Scheduling is probably best done with a hard-coded table indexed on hour. The table entry is either the absolute time of the next hoot, or the wait time used to calculate the next hoot. I am sure there are even more methods to do this but the concept is simple.

I think you are right that the Electronoobs circuit might be able to be simplified now that we are using a MOSFET instead of a sensor or push button. When I have more time I will look into that but of course, the other two requirements must still be met, latching and PICO controlled turn off. Since the transistors used cost less than $0.10 each, I am in no rush to reduce component count and cost though.

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.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1721
 

Hi Ron @zander,

  I have been reluctant to find specific devices, because availability and pricing is location dependent. Hence, I'll try to give a general guide as to what to look for.

RE: P Channel MOSFET that requires a Gate of logic LOW to cause the 'switch' to close. 

That is essentially correct, but you might find it tricky to match to the data sheet of a candidate device.

As you know, MOSFET data sheets run to several pages, so this is very much the bare essentials .. if these don't match the device is a "no-hope", but just matching these is not a guarantee of success.

Lazily, I picked a device from the list that comes with the simulator .. which also has a convenient data sheet.  https://www.vishay.com/docs/69979/si4459ad.pdf

I don't know if you can conveniently buy it, but I'll use it as an example of what I would look for by taking snips from the data sheet ...

I know I want a p-channel MOSFET as the right function, and I might be switching up to 6V ...

Headline says

image

 So it is P-channel and 30 V Drain-source looks promising, as my maximum voltage is 6V.

image

I want the FET to be low resistance (drain to source), when it is switched on, since the Pico requires 100 mA and more, so every 10 milliOhm resistance will drop 1 millivolt at 0.1 A.

This table says Rds 7.75 milliOhm when Vgs = -4.5V,  .. and this applies at an appreciable current (23A).

So this value of Rds (< 10miliOhm) and current rating (>20 A) is fine, but the Vgs value must be checked as well, particularly when a FET is being driven by a low voltage circuit, such as 3.3V logic.

In this case, the Rds is specified at -4.5V.

Looking at the circuit I drew, the applied voltage will be (almost) the Pico battery voltage of 3.7 V, providing the pulldown NMOS transistor (or its equivalent Alarm output pin of the DS3231) exhibits a much lower resistance in the 'active' state' than the 100 k pullup resistor.

Now obviously -3.7V is less than -4.5V, so I would expect the actual Rds to be higher than 7.75 milliOhm, but I thought it was close enough for the concept demonstration.

Had I intended to actually choose the device, I would dig deeper into the data sheet .. e.g.

 

image

This shows that at 3.7V, the device is still managing a low Rds, but that Rds was increasing rapidly if the voltage dropped to 3V and below.

Hence, this device looks OK so far for (say) a 3.7V lithium or 3 x 1.5V = 4.5 alkaline batteries, but it might struggle with only 2 alkaline batteries producing about 3V.

----

In some applications, I might also check power dissipation.

In this case, 0.1 A and 10 milliOhms, suggests 0.1 (A) * 0.1(A) * 0.01(Ohm) = 0.1 mW   .. not a problem!!

------

Please bear in mind individual device characteristics might ary appreciably from the data sheet, and even more so if an 'economical' source has been used, so try to leave wide margins and be ready to try more than 1 device.

Best wishes, Dave


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

@davee I envy your youthful energy, but at almost 81 I have to spend my remaining time carefully, so I will be 'stealing from the best' whenever I can. In this case, since the needed MOSFET is identical to the other one in the circuit, I do not need to go through all those lookups and calculations you did.  I have built a few projects that used MOSFETs and the only specs I checked were turn-on voltage and current capacity. In a couple of them, some people said it wouldn't work due to something I don't remember, maybe gate voltage. Well, it worked, so I guess I am just lucky.

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.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
DaveE reacted
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1123
Topic starter  

@zander @davee,

Thanks for your 2 detailed posts, it will take me some time to absorb. 

But I was doing a bit of thinking about the power required.   The motivation of this idea for a switch on/off circuit was of course the discussion that the rpi pico with its, currently, dubious deep sleep current budget might be better served when on battery power with such a circuit.

The latching circuit of Electonoobs will of course reduce the sleep power to zero, but it turns on via mechanical means.  I will be looking at the latest spice diagram from Dave to see what I can make of an alternative circuit

The proposed way of turning on our circuit thus far is via a DS3231 RTC.  The current draw, when idle, of the DS3231, from another bout of googling, appears to be about 1.5mA. (and more when communicating via i2c with a microcontroller.   Compare this to the current  draw of the UM TinyPico (a ESP32 based board), according to its docs can be as low as 20uA in deep sleep.  I found this video from Ralph Bacon on the DS3231

I hope I have these facts correct, and if so the current draw of the DS3231 RTC seems to mean it wont be suitable for this sort of circuit.   One would be better off using the UM Tiny Pico instead of the DS3231 to wake up the pico which of course would be a bit of a nonsense.

Nevertheless, this delve into electronics has been very fruitful and interesting for me, and I'm now going to read your posts in detail.

Let me know if I've got the wrong end of the stick with the current requirements of the boards and components  as it quite likely I'm spouting out the wrong end. 😀 

This post was modified 1 year ago 2 times by byron

   
ReplyQuote
Page 3 / 9