tiny85 self power-off

Hello all,

I'm working on a useless box project here, it is powered by 2xlipos and a 5v LDO, and an attiny85 MC.

The switch i'm using is a double pole so i had this idea that, in resting state everything would be powered off. When throwing the switch one of the poles would connect the lipo to a mosfets gate (IRL540N) which would then switch on the LDOreg, and everything would fire up, which works good.
Obviously the box then switches the switch off, and in the mean time I have had the MC take over driving the mosfet gate via an output pin and 220ohm resistor (i figured this can be high ohms, because it's not driving the gate open, just taking over holding it open).

My idea was then to timeout the program after the switch being off for x time and write the mosfet gate pin low, which has a pull-down resistor on it. Then it would all power off until the next time the switch was thrown.

The last bit is where I'm having a problem. I've written the pin low but I can still hear the servos humming and holding their position so they obviously have power. If I pluck the wire off the mosfet control pin, then all goes silent and the servos relax.

I fear I am probably embarrassing myself by asking but, what am i missing hah...

Thanks in advance of course.

I think i've found my answer which has been answered before, sorry about that.

Just so it's not a wasted post, my understanding is enough current is leaking from the control pin to keep the mosfet energized?

I'll have a go at adding in a second P-mosfet

Please draw a schematic (hand drawn and photographed with your phone is fine, and better than fritzing and that kind of crap)....

But first thought is, if you're using an LDO and running something on batteries, you've already lost the war.

My thought is - keep the uC powered full time by the batteries, but in power-down sleep mode until it receives user interaction. then it turns on the fet to do it's thing with the motors, cloe box, and go back to sleep....

I had thought of that but something made me stray away from it. I think that would mean powering the servos by regulated 5v but the pwm signal would be as much as 8.4v. it's outside their parameters anyway.

The LDO is below the fet like you say, the 10ma quiescent wasn't going to work, shame it's not 10ua. I'll draw a circuit later today.

Here's the circuit I don't know that it was going to be any clearer with a scribble on paper sorry!

If the battery were connected to that circuit it should remain powered off as the FETs gate is held low by the 10k pull-down resistor. But it doesn't. Regardless of what I set PB0 to, output/input and written HIGH or LOW, it drives the gate as soon as the lipo pack is live.

If I disconnect PB0, then the circuit operates as it should, the upper pole of the switch drives the gate and as the arm opens the switch, it all powers down.

PB0 being written LOW, is still leaking enough current that the gate remains driven...? Which doesn't make a whole lot of sense to me on second thought actually, why can you ever drive a gate with a uC in that case.

Anyway, I've read about switching the power supply with a P-channel FET instead, and driving its gate with the N-channel FET. i.e. hold the P-channel gate low while operating, then let the P-channel go high with a pullup when powering off.

Edit: I drew MOSFET on high side accidentally, it is on low side as reflected in updated circuit below

It is a gift for my 10 month old niece who is coming out of surgery today, my brother says she likes switches. But yes, still, I wish I never started it :grinning:

It is surprisingly difficult to tune the timing of its responses right, to give it 'personality' rather than look like a weird automated machine.

In any case, it'd be great to just have 1 switch and leave it on the shelf indefinitely without a current drain.

You could use a small relay. It would use more current while it was on but could switch completely off without the sensitivities of the transistor.

I've considered that too and I've got one in the box but I'm not quite there yet. Even if I did it'd bug me not knowing why this doesn't work =/.

OK, that circuit never works, by definition. :roll_eyes:

So, what is wrong with the sleep mode of the ATtiny85, and why are you using two LiPos? I see 18650 rechargeables.

I hope you do not propose to use the regulator to drive the servo motor! :astonished:

Or are you going to power a servo motor with 8.4 V? :astonished: :astonished:

Is it just me, or is the ground wired wrong in the schematic?

Ahh… forget it. Sorry :slight_smile:

I think what may be happening is that when you turn off the switch, then bring PB0 low, you are disconnecting the circuit ground from the battery ground, and the entire circuit potential then rises to the potential of the battery positive, which IS connected - about 8V. No current flows, but if you measure the voltage at the regulator's OUT pin, and at PB0, and even the processor's ground pin, all with respect to battery ground, I think you will find a positive voltage. But this may not be correct because it would power up automatically when you first connect the battery, even with the switch off. So I don't know.

I'm so used to seeing high side switching that I'm having trouble figuring out how to make this work. But I strongly supect you're going to need a transistor in the PB0 line. I think perhaps a PNP, with the emitter connected to PB1 and the base connected to PB0 through a resistor, then the collector connected to the 220R resistor to the mosfet gate. To maintain power, you would bring PB1 high, and PB0 low. That turns on the transistor, which brings the gate high.

But when you make PB0 and PB1 high impedance (inputs), there's no voltage differential between the emitter and the base, and no current flow, so the PNP transistor turns off.

I don't know if that's clear. If I get some time later today I'll draw it up.

Here's a drawing of what I tried to suggest above. But on reflection, I think the emitter can just be tied to the 5V supply instead of PB1. Also, I've replaced the 220R resistor with a diode. You don't really need the resistor, but when the switch is closed, you have 8V coming back into the PNP, and I frankly don't remember what happens when the collector is at a higher voltage than the emitter. It's possible no current would flow anyway at these voltages, and you won't need the diode.

So the PNP conducts only when the EB voltage exceeds 0.6V and current flows through that junction. If the processor brings PB0 low, that condition is satisfied, and 5V will flow to the mosfet and maintain power when the switch is off. But when PB0 goes back high, or becomes high impedance, no current will flow through the base, the PNP turns off, and the pulldown resistor on the gate turns the mosfet off. The voltages at the processor may rise towards the 8V battery voltage, but there still will be no differential between the 5V pin and PB0 that would lead to turning on the PNP.

Maybe I'm just confused but I think the MC is connected to mosfet switched power and toggle switched ground. When the toggle switch opens, the MC floats to battery and the mosfet gate floats to battery.

If the MC ground is removed from the mosfet switched ground and connected directly to the battery ground, I think it should work as expected. Right?

edit - yes I am confused. The both the MC power and MC ground are switched by the mosfet. However the results and the fix should still be the same.

edit - yes I am confused. The both the MC power and MC ground are switched by the mosfet. However the results and the fix should still be the same.

I'm not sure I understand what you're suggesting. Perhaps you could post a schematic showing your fix.

Some ideas, FYI




Aww jeez I just lost my entire reply :cry: :cry: Hopefully i don't miss anything, thanks for replies let me go through them.

Paul if you can see that working then there's nothing wrong with it but I couldn't get my head around it. The LDO has to be powered off as its quiescent current is high, so the uC has to be powered directly from the battery. This means the PWM signal going to the servos has to be 8.4V (at full charge) which is outside their parameters. Even if they are powered from the reg. I could switch them through the 5V rail but that is two more transistors anyway.
Yeah Li-ions sorry, force of habit from other hobbies. I'm powering the servos from the 5V reg, how else would I do it? The stall currents combined are within parameters.

Sherman I think you are right, and it does power up when connecting PB0 as you say, I'm not sure what I was observing the first time maybe I didn't have that wire in yet. I will give your circuit a try.

Ed i had a friend here who suggested the same thing and i tried it, the circuit still powered up upon connecting PB0 to the gate.

Larry I'll come back to that diagram I hope i can get away with something involving less components than that. CB will be starting to get packed!

Happy to update that the circuit is working now, using an N-channel fet in the uC circuit which switches a P-channel fet in the circuit above the regulator.

I have a delay at the beginning of my setup function as functions below it seemed to be skipped entirely, or behaved irregularly, I assumed while the voltage supply was settling down and becoming stable. Is it common practice to do this? Even so, I am noticing a significantly longer delay when switching on with the switch now. I wouldn't have thought the time for the FETs to respond would be observable by me. But I will play with that delay at the beginning anyway.



What MOSFETs are you using?
Do they have Drain-Source diodes fitted?
Are they logic level MOSFETS?
What LDO are you using and have you checked its datatsheet to see if it needs bypass caps?

Tom.. :slight_smile:

Sorry but I had to redraw that diagram.

Tom... :slight_smile: