Strange Behavior with Soft Latching Power Circuit: LED Inconsistently Staying On

I'm here because I'm experiencing a very strange behavior with a Soft Latching power circuit found on YouTube.

Yesterday, after finishing my circuit and code, it was working weirdly: the LED would light up, then turn off, and then light up again instantly for 6 seconds. A few dozen minutes later, it was impossible to keep the LED on.

I decided to take my circuit to a friend's place. We started by testing a few terminals with a multimeter and, voila, it worked perfectly—the LED stayed on for 6 seconds. I went back home, set up in my living room, reconnected the battery, and everything was fine. I disconnected the battery and, 3-4 hours later, went back to my office, connected the battery, and it didn't work anymore.

Could it be interference from my big PC? I don't understand...

I added a led to OUTPUT 1 to simulate a process with my ATTiny85.
I removed the C1 because the internal capacitor of my mosfets is enought. (And because it worked good depending where i am...) And I changed the resistors with the exact value i need (calculated with CISS)

Here is an image of the circuit i found.
here

Here is my setup (sorry, I did my best):
here

And a video (with my old version (long câbles)):

My code:

int stay = 2;
int led = 1;

void setup() {
  // Serial.begin(9600);
  pinMode(stay, OUTPUT);
  pinMode(led, OUTPUT); 
  digitalWrite(stay, 1);
  digitalWrite(led, 1); 
}

void loop() {
    delay(6000);
    digitalWrite(stay, 0); 
}

My specifications:

  • Lipo 3.7v
  • ATTiny85
  • P-channel MOSFET TO-2305:
    • Condition: VDS=VGS, ID=-250uA
    • Min: -0.45V
    • Max: -1.5V
    • Ciss: 1200
  • N-channel MOSFET TO-2302:
    • Condition: VDS=VGS, ID=-250uA
    • Min: 0.4V
    • Max: 1V
    • Ciss: 300
  • R1: 820 ohms
  • R2: 3.3k ohms

Thanks for your help.

If the uC is output only, how does the uC know to light the LED?
[edit]Your code sets both pins HIGH, waits six seconds and sets PB2 LOW. No input.

Sounds like intermittent or poor connections. Breadboards are not reliable.

Neither are pushbuttons and their breadboard contacts (make SURE you have wired the pushbutton correctly, as they can be mounted in two different ways).

It doesn't. The operator is supposed to push the switch to power and restart the Arduino, which lights the LED, then turns off the power after six seconds.

Skinny 1/4W resistor leads in cheap, sloppy, loose breadboard holes = ARGGG! :grimacing: :angry: :rage:

In post #1

  • Your LED looks like it is connected to pin 6, not pin 1. :thinking:

  • The N channel gate is connected to pin 7, not pin 2. :roll_eyes:


Okay, You are using the I/O names not the pin numbers.
You should get into the habit of using the pin numbers in wiring diagrams and add the signal name to the connection.

What C1? And by 'internal capacitor of your mosfets', what part of the parastic capacitance do you mean? For what purpose is it enough?

I do notice that you're running that ATtiny without any decoupling or buffer capacitor, which is inviting problems. At least add 100nF to its Vcc. You may also want to connect e.g. 10k between its Reset pin and Vcc, and 10nF between Reset and GND. This will reduce the possibility of a wake-up process in which a very temporary brownout condition occurs (e.g. due to button bounce), locking up the controller in the process.

They're totally non-critical, but in all honesty I would have just taken something like 100k for both R1 and R2. Why make R1 less than 1k? It'll just burn power unnecessarily as the circuit is on. The same for R2, but 16 times less...
So what exactly did you calculate and on what basis?

There's in fact a possible problem with your small value for R1 and the "internal capacitor" of your P-channel mosfet in the sense that the low impedance of R1 will allow the gate of Q1 to charge very rapidly. This means that any bounce in your push button will result in temporary erratic switching of the Vcc to the controller. If you pick R1 to be much larger (100k or bigger), this behavior will be much reduced. The circuit will be less responsive, but this will not be noticeable at a human timescale.

Hey, thanks for that. Look my new circuit and tell me what do you think !
For now it works perfectly, but happy to improve it.
(C1 is ceramic)

Untitled

A current limiting resistor is required between the Q2 gate and the I/O pin.

Is it mandatory? Why do i need a limiting resistor?

The gate capacitance of the MOSFET acts as a dead short circuit to ground, the instant that the port pin drives it. That briefly exceeds the manufacturer's absolute maximum current draw from the port pin.

EE professionals who understand circuit theory and are trained to design circuits to operate reliably, for years, do not make the elementary mistake of leaving out the series resistor.

150 Ohms is high enough for a 5V ATmega MCU, but should be significantly higher for more modern MCUs with lower allowed port pin current draw.

lol[quote="xfpd, post:2, topic:1283056, full:true"]
If the uC is output only, how does the uC know to light the LED?
[edit]Your code sets both pins HIGH, waits six seconds and sets PB2 LOW. No input.
[/quote]

lol :grin: :laughing: :rofl:

That's what counts!
Neither C1 nor R3 are needed. They don't hurt (much) either. I doubt R2 does anything here either, but this 'hurts' even less.

No. It'll work fine without. If you want to insure against the risk @jremington mentions, feel free to add 1k or so. However, I personally have yet to come across the first microcontroller that malfunctioned because of this 'omission', even after years of service.

So for you I can remove R3, C1 and R2?
I will try tonight if I can :slight_smile:

Thanks

@nanoss
R2 is necessary, otherwise the gate Q2 is just floating and you may seem some bizzare turn on/off effects