Attiny based N-Channel Mosfet switch does not turn off fully. - Page 1
Forum section: electronics / beginners

author: rohanwoods
author_rank: Newbie
timestamp: May 24, 2021, 10:31:58 am
content: I have designed a circuit using an N-Channel mosfet as a low side switch controlled by an Attiny13a, but it goes into a half on state when it starts up or I try to turn it off by resetting the MC. I have done a similar thing in the past with a P-Channel, but it is cheaper and easier to get made with the AO3400A mosfet.Datasheethttps://media.digikey.com/pdf/Data%20Sheets/Alpha%20&%20Omega/AO3400A_ds.pdfAny ideas what I am doing wrong/how to fix it?Voltage measurements on the mosfet with reference to battery ground:With enable track to MC cut - G 0v S 0V D 4V - Everything off, works as intendedOn - G 4v S 0V D 0V Everything on, works as intended.Switch "off" - G 1.15v S 0V D 1.63VRelevant Arduino code which should keep the circuit off on startup until and on button is held for 1s// set PB0 to be outputDDRB |= (1 << PB0); //replaces pinMode(PB0, OUTPUT);PORTB |= (1 << PB0); //replaces digitalWrite(PB0, LOW);_delay_ms(1000);PORTB |= (1 << PB0); //replaces digitalWrite(PB0, HIGH);It's hard to get my head around low side switching as everything is backwards.Circuit below:

author: Moriambar
author_rank: Unknown
timestamp: May 24, 2021, 11:14:44 am
content: If you're talking about Q1, in the schematic it's upside-down, meaning that gnd now is connected to drain while it should be connected to the source, and your load should have its return to ground on the drain of the tranny and not on the source

author: jpanhalt
author_rank: Super Contributor
timestamp: May 24, 2021, 11:19:05 am
content: You seem to have the mosfet installed backwards. The source needs to be connected to ground. Clue: Look at the orientation of the diode.

author: Peabody
author_rank: Super Contributor
timestamp: May 24, 2021, 03:02:52 pm
content: I'm not sure the mosfet is backwards, depending on what you're trying to do. Do you want the ATtiny to stay powered while you turn all the other stuff off? If so, there have to be separate ground lines - one for the ATTiny, which is probably the same as battery ground, and the other line that goes through the mosfet to battery ground. In your circuit, it looks like the ATtiny is trying to switch off its own ground. Well, maybe I'm not reading it right, but it looks strange to me.

author: madires
author_rank: Super Contributor
timestamp: May 24, 2021, 04:16:40 pm
content: The circuit's ground is BAT- but the ATtiny's GND pin isn't connected to BAT-. Therefore the ATtiny can't pull down the gate to ground.

author: Peabody
author_rank: Super Contributor
timestamp: May 24, 2021, 04:34:26 pm
content: Also, I don't understand SW1. When that switch is closed, you have a direct short from Vcc to PB0, which is not a good thing if you try to take PB0 low.

author: madires
author_rank: Super Contributor
timestamp: May 24, 2021, 04:54:48 pm
content: Yep! If SW1 is meant as a manual overwrite then there should be a resistor in series.

author: rohanwoods
author_rank: Newbie
timestamp: May 24, 2021, 10:08:27 pm
content: I have tried swapping the mosfet around so Source is GND(Load) and Drain is Bat-(Ground) and the mosfet just stays on, even if I completely disconnect the Gate.This is supposed to be a self latching circuit. Everything should be off at the start, until SW1 is pressed. When SW1 is pressed the mosfet should turn on, enabling the microcontroller and the rest of the circuit. When the MC starts up it waits for 1 second(so SW1 has to be held for 1 second) then latches PB0 high to keep the mosfet on.When SW2 is pressed the MC resets. The mosfet should then be turned off by the R2 pull down resistor, turning everything off.Thanks for all the help so far everyone.

author: ledtester
author_rank: Super Contributor
timestamp: May 24, 2021, 11:31:36 pm
content: QuoteThere are a lot of posts on the forum about soft power latching switches. For instance:https://www.eevblog.com/forum/projects/attiny13a-power-button/msg3356266/#msg3356266