Go Down

Topic: Enhanced mode Mosfet to connect Reset to button when in Deep Sleep (Read 446 times) previous topic - next topic

mightymouse123

I have an ESP8266 Wemos D1 board  with Pin D2 in a Pullup mode connected to a button that is connected to grd when it is pressed. The button is normally used while the ESP8266 board is active. But after the ESP8266 is inactive for a while I want to put the board into deepsleep with no timeout. Right before it is put it into deepsleep it should connect the RST pin to the button circuit so that the next time the button is pressed it will wake up the board. The first command of setup would then be to disconnect the button from the RST pin. 

I have some Enhancement Mode MOSFETs(IRFZ44NPBF). It is normally open but I need more of a normally closed switch. But depletion mode MOSFETs need negative voltage. Is there a way to design a circuit with a few more resistors or other components to make the Enhancement mode MOSFET work as I need it to.  Or is there a better component to be able to make the connection when the board is off but disconnect it when the board turns on.  As I am just controlling gnd I don't need something that is rated for high voltage obviously. Also, the board is running on battery so it would be best if it does not consume a lot of power especially during deepsleep mode.  

Thanks for any input. 

wvmarle

Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

mightymouse123

Here is my attempt at a schematic. I don't do much hardware stuff so this is a bit of a stretch for me. But hopefully this helps convey what I am trying to do. 


wvmarle

The MOSFET is between GND and reset, the switch won't do anything useful to send a reset signal. It may work if you connect it between D2 and RST.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

mightymouse123

Yep. I think that was a flawed schematic. Here is one that I think makes more sense. 

However, I still have the problem of how to have the MOSFET be closed(connecting rst to the button) when I don't have power and disconnecting when D5 is high.


wvmarle

This should work (pull-up resistor R1 should be present on the WeMOS board already):



Just about any small signal n-MOSFET or NPN transistor will do here. In case of using an NPN transistor increase the value of R2 to 10k and R3 to 100k.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

MarkT

I have some Enhancement Mode MOSFETs(IRFZ44NPBF).
Those are not logic level.  They are power MOSFETs.
Quote
It is normally open but I need more of a normally closed switch. But depletion mode MOSFETs need negative voltage.
enhancement mode turn on when there's a voltage, off when there isn't.  Depletion are the opposite.
The actually polarity of the voltage depends on whether p-channel or n-channel, as well as whether
enhancement/depletion.

Depletion mode is rare these days.  Some sort of logic using CMOS logic chips might be the way to
go as these take only nanoamps when static - they can be permanently powered up.  A single signal-level
NPN transistor or n-channel FET can be the switching device for the reset pin to ground - no need to
disconnect it as its high impedance till active.  All you need to do is control whether the button drives
it or not using some combinatorial logic I think.
[ I DO NOT respond to personal messages, I WILL delete them unread, use the forum please ]

ShermanP

I don't think you need a transistor at all.  Unlike Arduino board processors, the ESP8266 automatically does a reset when it wakes up from sleep.  So I think if you can enable a wakeup interrupt on D2 just before going to sleep, that should do the reset when you push the button.  Take a look at Ralph Bacon's video on this subject:

https://www.youtube.com/watch?v=NgPwPKXCLFY

Edit:  Ok, my memory failed me on this one.  It appears you do indeed have to connect something to the reset pin to make it work.

ShermanP

I think this would work.

R1 is probably on the board already, or internal.

D5 would be brought high when you want the button to be connected to the Reset pin.  If it's low, there would be no connection because there would be no base current.  Actually, you could eliminate R2, and make D5 Input-Pullup to turn on the connection, or Input or Output-Low to turn it off.  You just wouldn't want it to ever be Output-High because that would be a dead short when the button is pushed.

D2 is the input pin for normal use of the button in active mode.  And R3 could just be the internal pullup resistor.

So I think it would work with just the transistor, and no added resistors.  And it would draw no current except while the button is pressed, so from that point of view would be as good as a mosfet.

A potential problem is that when the reset takes effect, D5 will immediately go tri-state, which means reset will go back high.  I don't know if there's any requirement to hold reset low for a time after the reset process begins.  I don't think there should be, but the 8266 is a bit strange, so you would have to test it.




mightymouse123

@wvmarle - Thanks for that diagram. I will try that this afternoon and see how it goes. 

@ShermanP - I like the idea of a transistor. I will have to try it. Do you think the input pullup state will remain connected when the ESP8266 is in deepsleep mode? I will give it a try with a PN2222.



ShermanP

I would be surprised if going to sleep changed anything on the GPIO ports.  But when the reset button is pressed I suspect all  the port pins will go into input mode, with no pullup resistors.

mightymouse123

@wvmarle

 - I tried your schematic but for some reason I could not get it to work. But I could not really get the mosfet to respond at all so I was probably doing something wrong. The transistor method is almost working so I am going to pursue that for now but I may come back to the mosfet if needed. 

@ShermanP - This method almost works. It works great if the board is on. I can change D5 from input to input_pullup and it switches the button from normal mode to board reset. However, as soon as the board goes to sleep the button does nothing. I tried installing a manual Pullup resistor from D5 to 3v3 but then as expected no matter what the board just resets when the button is pressed but it does reset the board after deep sleep.  I have included my current schematic which is just using the internal resistors and no extra resistors. Any idea what I should try next. I like using just a little transistor and it is close as it works when the board is on. But maybe when the power is cut the board is losing the input_pullup value. I am really not sure. Is there a way to have the transistor need power to connect the button but then when power is cut revert to connecting to reset. Any ideas are appreciated.



wvmarle

Maybe your MOSFET is not logic level, or if it is maybe it is still almost fully closed at -3.3V VGS. A regular NPN transistor should work as well indeed.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

ShermanP

It appears the state of the GPIO pins isn't maintained during deep sleep.  So you would need an external pullup resistor on D5.  To enable the button to reset the processor, you would set D5 to Input.  To disable reset from the button, you would set D5 to Output, Low.

I found some vague references to GPIO registers that could be set to make GPIOs retain their state during sleep, but found nothing specific on where the registers are or how they work.


mightymouse123

@ShermanP - You are correct. I used an external pullup resistor on D5 and it works with the Output Low. So I think I am all set. 

I did some research on the GPIO registers and I found an example for GPIO14 which happens to be D5. So I am going to try and see if I can get that to work as it would be a very elegant solution to not have to add any external resistors. I will report back if I can get it to work.

Thanks for all of your help everyone.

Go Up