Go Down

Topic: tiny85 self power-off (Read 1 time) previous topic - next topic

JoshNZ

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.

JoshNZ

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

DrAzzy

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....
ATTinyCore and megaTinyCore for all ATtiny, DxCore for DA/DB-series! github.com/SpenceKonde
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

JoshNZ

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.

JoshNZ

#4
Aug 14, 2020, 12:42 am Last Edit: Aug 14, 2020, 03:33 am by JoshNZ
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


JoshNZ

#5
Aug 14, 2020, 12:56 am Last Edit: Aug 14, 2020, 12:56 am by JoshNZ
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  :smiley-lol:

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.


pmagowan

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.

JoshNZ

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 =/.

Paul__B

OK, that circuit never works, by definition.  :smiley-roll:

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!  :smiley-eek:

Or are you going to power a servo motor with 8.4 V?  :smiley-eek:  :smiley-eek:

Bjerknez

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

Bjerknez


ShermanP

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.
 

ShermanP

#12
Aug 14, 2020, 06:49 pm Last Edit: Aug 14, 2020, 06:53 pm by ShermanP
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.



edmcguirk

#13
Aug 14, 2020, 07:53 pm Last Edit: Aug 14, 2020, 08:00 pm by edmcguirk
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.

ShermanP

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.

Go Up