Switching 12V power from DS3231 open-drain INT/SQW pin - Page 1
Forum section: electronics / beginners

author: Peabody
author_rank: Super Contributor
timestamp: December 08, 2020, 03:38:28 pm
content: The DS3231 is an RTC chip with an alarm function. When the alarm time matches the current time, it brings it's INT/SQW pin low. That pin is an open drain output, and the datasheet is pretty clear in saying the maximum voltage allowed on that pin is 5.5V, regardless of what the chip's Vcc is.The attached picture shows the use of the DS3231 to control the power supply of a microcontroller and related sensors, etc. In this case the power is a single 18650 cell at 4.2V maximum. But what if you wanted to switch a higher voltage, such as 12V?The DS3231 Vcc pin is unpowered in this setup, so it's operating on the coin cell on the back of the module.I assume a Zener diode could be used to drop the 12V to 5.5V, provided you've picked a mosfet that's fully turned on at Vgs = -5.5V. But I wonder if there's a more general solution that wouldn't require an oddball Zener value, something involving a transistor stage or two. Does anything come to mind?

author: Ian.M
author_rank: Super Contributor
timestamp: December 08, 2020, 04:01:23 pm
content: Add a NPN transistor, emitter to /INT/SQW, base to the 100K resistor to Vbatt and collector to the 12V switch P-MOSFET gate. Add a 100K pullup from the P-MOSFET gate to unswitched 12V.When /INT/SQW goes low the gate gets pulled down close to ground. When /INT/SQW shuts off, the NPN stops getting any base current when its emitter reaches Vbatt, so it cant go significantly higher. Its leakage current may cause it to go slightly past the rail, but not enough to forward bias any internal protection or parasitic diode on the /INT/SQW pin.

author: Peabody
author_rank: Super Contributor
timestamp: December 08, 2020, 04:59:18 pm
content: Thanks very much. So the only downside would be the current flowing out of the coin cell when the power is on. That would be a function of how much higher value resistor that 100K to Vbat could be and still work, and of course a function of how long the power needs to stay on.What I had in mind in the drawing is that when the processor is ready to shut down, it would bring up the Vcc on the module, set the new alarm time, and then, as it's last act, clear the alarm flag, which would shut down the power. So the traditional NPN driven by a processor GPIO wouldn't be needed. I think that should work as long as the rail is 5.5V or less, but at higher voltages, something more will be needed.How about a diode coming out of Vbat, and another diode coming out of a processor GPIO pin, both cathodes meeting at that 100K resistor to the base. Then if the power needed to stay on a while, the processor could provide the base current. But you know, if that resistor could be 1M, that would only be 3uA coming out of the coin cell, which isn't very much more than it normally draws (I think about 1.5uA if Vcc is turned off).

author: Ian.M
author_rank: Super Contributor
timestamp: December 08, 2020, 05:26:07 pm
content: Alternatively delete the 100K base resistor and use a low Vgs threshold N-MOSFET, gate direct to Vbatt. If you need to hold it on, use another discrete N-MOSFET to pull the P-MOSFET gate low. You cant just use a GPIO configured as open drain in parallel with /INT/SQW as when the MCU looses power its internal protection diode to Vcc would conduct, turning the power back on!

author: Peabody
author_rank: Super Contributor
timestamp: December 08, 2020, 06:38:13 pm
content: Quote from: Ian.M on December 08, 2020, 05:26:07 pmBut wouldn't you still need a GS resistor to keep the source from floating? Seems like you'd need a resistor, and some current flow, even using a mosfet.QuoteYes, I understand. Attached is what I was thinking of, which should work so long as the GPIO high voltage is greater than the coin cell voltage. But I understand you could just use another NPN or N-channel transistor instead of the diodes.

author: Peabody
author_rank: Super Contributor
timestamp: December 12, 2020, 06:39:02 pm
content: Here's what I've settled on at this point. Thanks for the help, Ian.The DS3231 alarm would remain in effect, and the power would stay on, until the processor sets up a new alarm time, and then clears the alarm flag when it's ready to power down. Both of these solutions result in a little current flow out of the coin cell to keep the power on, but it's not much - a few microamps.

author: Ian.M
author_rank: Super Contributor
timestamp: December 13, 2020, 05:29:19 am
content: For the MOSFET version, I don't think you need R2. If you re concerned about leakage in the N-MOSFET raisng /INT/SQW's voltage excessively, fit a diode in place of R2, cathode to Vbat.

author: Peabody
author_rank: Super Contributor
timestamp: December 13, 2020, 05:56:44 am
content: I wasn't concerned about leakage. I was concerned about having a floating source. I understand that the gate is solid, but if the source is floating, and subject to picking up stray EMF stuff, then Vgs is also floating, which might result in the mosfet turning on spontaneously, with unpredictable results. But I guess a predictable result would be that if the mosfet turned on even a little bit, the source would immediately rise and the mosfet would turn off because Vgs would approach 0V. So then the question is whether R2 is needed to keep it from fluttering or oscillating. Well, you appear to understand this better than I do. I guess I should just set up a test circuit and see what happens.

author: Ian.M
author_rank: Super Contributor
timestamp: December 13, 2020, 08:39:05 am
content: Certainly its a high impedance node when the /INT/SQW output driver is off, so you'd be well advised to minimize trace length and make sure its run over a ground plane, but as you have realized, if the source picks up EMI, the MOSFET will leak a little on negative peaks, driving the mean source voltage positive until the MOSFET stays cut off. If you've got enough EMI to put peak to peak noise on the source of greater than the MOSFET threshold voltage + one diode drop, you've got bigger problems as the rest of the system will almost certainly be unstable.Due to the cascode circuit, there is no current gain for noise injected at the N-MOSFET source, so you can handle it by decreasing the P-MOSFET gate pullup R1, or adding a RC low pass filter between R1 and the P-MOSFET gate.

author: Peabody
author_rank: Super Contributor
timestamp: December 13, 2020, 03:42:44 pm
content: I will try to breadboard it and see if there's any difference detectable on my scope with and without R2. But I think having it there eliminates any possibility of a problem, although 1Meg might work well enough.I searched on "mosfet floating gate" on Google, but didn't really find anything useful. Now there's at least this thread on it. :-)

author: Peabody
author_rank: Super Contributor
timestamp: December 13, 2020, 10:00:44 pm
content: I did the breadboard test, and couldn't detect that R2 made any difference. I put the scope lead on the drain of the N-channel, and then on the output of the P-channel, which was driving an LED when on. There was noise, but the noise was the same whether R2 was present or not.

author: Peabody
author_rank: Super Contributor
timestamp: December 19, 2020, 03:13:34 pm
content: Here is what I hope is the final version of the mosfet/mosfet circuit without R2.What's still unclear to me is whether the various leakage currents involved could cause a problem without R2 when power is off. It seems the N-channel source could be kept high through gate or drain leakage, but that might be offset by leakage to ground, if any, through the open-drain INT/SQW pin. I've never had to deal with nanoamps before, and I don't think I have any way to measure the actual voltage on the N-channel source. Anyway, the circuit does seem to be stable, even when off for an extended period. That's using a BS170 for the N-channel, which has a higher Vgs threshold voltage than I would like, but works anyway.

author: Ian.M
author_rank: Super Contributor
timestamp: December 19, 2020, 03:20:16 pm
content: If you've got a very high Z input voltmeter (i.e. a valve or FET input one) or a regular DMM with an ultra-low bias current unit gain OPAMP buffer in front of it, see how high the BS170 source voltage gets if you heat up just the BS170. If you aren't happy with the result, and believe my diode clamp suggestion (#6 above) will dump more current into the battery than the quiescent consumption of the RTC chip, we can discuss your options.

author: Peabody
author_rank: Super Contributor
timestamp: December 19, 2020, 06:41:40 pm
content: No, I don't have any of that fancy gear. I understand the logic of putting the diode in place of the resistor. The RTC running on the coin cell draws at least 1.25uA. I haven't studied the leakage currents of various mosfets, but I hope it wouldn't be anywhere near that.Of course the other thing I don't know is in what way the voltage on the pin is limited to 5.5V, "regardless of Vcc voltage". If they've got a 5.6V zener to ground in there, then any low current spillover wouldn't do any harm. But if there's actual damage at higher voltages, that's a different matter. But I could test for the zener, couldn't I? Bring up the voltage on the pin and see if it starts to conduct at some point. Maybe not go beyond 7V or so.

author: Ian.M
author_rank: Super Contributor
timestamp: December 19, 2020, 07:10:47 pm
content: Another way of making a very high impedance DC voltage measurement is by nulling. Put a 50K or 100K multiturn pot across a fresh 9V battery, with its negative side grounded. Connect a 10Meg input impedance DMM between the point you want to measure and the pot wiper and adjust so the DMM reads as close as you can get it to 0V on a range with 1mV or better resolution. Use another DMM to measure the pot wiper voltage with respect to ground, or disconnect the test lead and use the first DMM.Assuming typical accuracy of +/-5 counts for a budget DMM, when it reads zero there cant be more than 5mV across its 10Meg internal resistance so that gets you down into nA territory. To avoid stray leakage currents influencing the result, use a short custom test lead from the DMM clipped onto the circuit, don't hold the lead or let it touch anything. The potentiometer side of the meter is relatively low impedance, so as long as you don't touch any bare terminals you don't have to worry about stray currents. If you aren't 100% confident of the quality, integrity and cleanliness of your DMM's rear case insulation, put the nulling DMM on a sheet of PTFE or clear polystyrene or perspex (not antistactic coated), preferably supported by its corners.

author: Peabody
author_rank: Super Contributor
timestamp: December 20, 2020, 09:37:34 pm
content: I've done more testing, with results I don't understand.First I slowly ramped up the voltage on INT/SQW to see if I could detect the presence of a zener diode to ground. I didn't detect any current flow, and stopped at 7V. So the 5.5V limit in the datasheet appears to result from some other limitation.Then I used the nulling technique to test the basic circuit without R2, using an NDP6020P for the P-channel, a BS170 for the N-channel, and an LED for the load. I only had a 200K multiturn pot, and my meter is an ancient Radio Shack autoranging job. Specs say the input impedance is 10M, but over 100M when it shifts into the 4mV scale. I got 5.13V on INT/SQW, which is also the mosfet source. And I guess that would explain why the power stays off since the source is actually higher than the 3V gate.Then I installed a 1N4148 diode from INT/SQW to Vbat, and I got 2.425V on INT/SQW. That's the first thing that makes no sense. I would have understood 3.6V, but I don't see how installing the diode would bring the voltage *below* Vbat. And yes I'm sure the diode was oriented correctly, with the cathode on Vbat.My R/S meter is hopeless for measuring current because it only goes down to .01mA. But I have an old analog meter with a 50uA scale, which works well for current. So I used it to detect any current flowing though the diode, and there was none - not the slightest movement of the needle.So then I installed a 5.1V zener from INT/SQW to ground and removed the 1N4148, and found that the analog ammeter did produce a very small but noticeable needle movement between connecting the zener and not. The same test with a 5.6V zener produced no such movement. The same test with the 5.1V zener and the 1N4148 produced the same movement as without the 1N4148. So it seems pretty clear that no current is flowing through the 1N4148, and the 2.425V is simply wrong in some way that I can't explain.Based on this, it doesn't seem that either R2 or a 1N4148 diode accomplish anything. A 5.6V zener to ground would appear to clamp the voltage at the right level, but if the 5.13V is as high as it gets, there's really no need for a zener or any other added components.Not sure where to go from here, but my suspicion is that the plain basic circuit will work fine.

author: Ian.M
author_rank: Super Contributor
timestamp: December 20, 2020, 09:50:15 pm
content: Yes, it looks like the simple circuit will do as the leakage isn't enough to raise the source/INT/SQW voltage excessively. The 2.4525V with a 1N4148 diode connected to +3V from the battery will be due to photocurrent as its a glass bodied diode. Use one in an opaque package or work in the dark and you should get very close to 3V.

author: Peabody
author_rank: Super Contributor
timestamp: December 20, 2020, 11:26:55 pm
content: I wrapped the 1N4148 in black electrical tape. No change at all in the voltage. Still 2.425V. Well, it's a mystery.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: December 21, 2020, 12:10:36 am
content: Ambient noise? Try putting a capacitor in parallel with it.Tim