Best way to control an ATX PSU with an MCU? - Page 1
Forum section: electronics / beginners

author: sparkydog
author_rank: Regular Contributor
timestamp: June 28, 2023, 09:26:09 pm
content: I have a project for which I want to control a bunch of 12V stuff with an MCU (probably an Arduino Nano, but the following likely applies to any Arduino and possibly other MCUs).This articlediscusses how to do so, including the suggestion to use +5VSB to power the MCU and to use the PSUs own switching for "other stuff". This would save me needing to implement a separate mechanism to turn the 12V on and off. However, the article also suggests controlling the PSU by driving a GPIO HIGH to turn it off, and LOW to turn it on.IIUC, the MCU will start up with its GPIOs in input / high impedance mode, which is fine (equivalent to telling the PSU to stay off). However, switching the GPIO to output will ever-so-briefly switch its output to low, will it not?Is that brief blip going to be "bad" for the PSU? How else could I control the PSU? ("Overkill" would be to connect PS_ON to ground via an SSR that is controlled by the MCU; both input and output-before-write should keep that off. Options in between include using some flavor of transistor, or maybe just adding a capacitor so the voltage the PSU sees can't change enough in between changing the GPIO mode and setting it high?)Bonus question 1: How reliable is this method for turning off the 12V rails? If I'm looking to ensure that the 12V stuff turns off when the MCU signals it to do so, is it worth adding a secondary switching system?Bonus question 2: I saw an ATX-to-MCU board somewhere that featured a whole mess of fuses. Given a PSU is likely to have all sorts of internal protection anyway, and MCUs are frequently powered directly off of "wall warts", do I reallyneeda (separate) fuse?

author: ledtester
author_rank: Super Contributor
timestamp: June 28, 2023, 10:38:12 pm
content: Quote from: sparkydog on June 28, 2023, 09:26:09 pmThis all depends on how your MCU works.On the AVR 8-bit cpus if you set the PORTx bit to a 1 before changing the DDRx bit the pin will go from HI-Z to outputting a HIGH value when you change it from an input to an output.This is a pretty good explanation of how the PORT, DDR and PIN registers work on the AVR 8-bit CPUs:https://exploreembedded.com/wiki/AVR_I/O_Register_ConfigurationKnowing how to use these registers give you more control over the GPIO pins than, for instance, what the Arduino libraries give you.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: June 29, 2023, 05:11:54 am
content: Having the GPIO that is connected to PS_ON temporarily be floating should be fine, because the ATX standard dictates that the PSU have an internal pull-up resistor to keep the signal high when disconnected. As ledtester says, the key to ensuring that the proper logic state is immediately presented when switching the GPIO between input and output is to change the output statebeforechanging the pin direction. However, in reality, I suspect that most PSUs wouldn't mis-behave if you didn't, as the ATX standard specifies that PSUs should have de-bouncing on PS_ON, in order to facilitate use of mechanical switches.Quote from: sparkydog on June 28, 2023, 09:26:09 pmI would not recommend using just the PS_ON signal to be the only method of switching 12V power to your load. The reason for this is because most (all?) ATX PSUs have considerable amounts of capacitance on their outputs (typically several 1000 uF), meaning that when you de-assert PS_ON the power shut-off will probably not actually be instant. If you have a fairly light load, voltage may stay up for a significant amount of time. I would recommend using a secondary switching method, like a P-channel MOSFET, controlled by the MCU.This way you can also utilise the PWR_OK signal (grey wire) to determine that the PSU is actually ready, and only then switch power to the load. The PWR_OK signal is set high by the PSU when all its voltage rails (12V, 5V, 3.3V, etc.) are in regulation - i.e. proper voltage levels have been reached. Conversely, it also goes low when the PSU detects any voltage rail has gone out of regulation, so you should also monitor its state with the MCU and switch off power to the load immediately if this happens, otherwise you might risk damage to the load by improper voltages.Quote from: sparkydog on June 28, 2023, 09:26:09 pmWhile ATX PSUs do typically feature over-current, over-voltage (and sometimes over-power) protection, if your load's current draw is far lower than the capabilities of the PSU, it would be wise to use some secondary current-limiting, like a fuse. Modern ATX PSUs are rated to deliver huge amounts of current on the 12V rail - e.g. 20, 30, 40 amps - and could easily destroy the load, burn wiring, etc. if there is a short-circuit, without ever triggering the PSU's protection. Putting an appropriately-rated fuse for your load between it and the PSU is a wise precaution.

author: sparkydog
author_rank: Regular Contributor
timestamp: June 30, 2023, 09:01:54 pm
content: Quote from: HwAoRrDk on June 29, 2023, 05:11:54 amMy understanding is that a pin in INPUT mode is "high impedance", i.e. should present similarly to an open circuit, which is similar to how the PSU would normally see that line when connected to an ATX motherboard.The more important question is, what happens when I set the pin temporarily to INPUT_PULLUP? (There doesn't seem to be any way to not do this. Note that this is the effect of ledtester's suggestion.) Iwantto say that's fine, as both the PSU and MCU will be trying to pull the line up to 5V?Quote from: HwAoRrDk on June 29, 2023, 05:11:54 amHmm, that's a good point I hadn't considered; thanks! Although, the expected loads are just inductors thatmostlywon't actually care about this, but for those inductors which are also relay coils, faster interruption is better.I was leaning, however, toward using SSRs. How safe is it to drive a MOSFET off of 5V when it's switching 12V? Is that "okay" because it's the same PSU ultimately providing both voltages?(Not quoting it, but that's an ACK on the fuses, also.)

author: magic
author_rank: Super Contributor
timestamp: June 30, 2023, 09:10:56 pm
content: Quote from: sparkydog on June 30, 2023, 09:01:54 pmIIRC the PSU pulls up to 5Vsb, so if the MCU is also powered from there, nothing interesting happens - the pullup resistors are paralleled.But why go through pull-up? Just set PORT to zero and with DDR=0 (power-on default) the pin will be open circuit (PSU off) and with DDR=1 it will be driving low (PSU on). Done.

author: sparkydog
author_rank: Regular Contributor
timestamp: July 03, 2023, 05:55:36 pm
content: Quote from: magic on June 30, 2023, 09:10:56 pm...because that's weird and non-intuitive? One normally expects to signal by switching a GPIO between LOW and HIGH, not between INPUT and OUTPUT.

author: Terry Bites
author_rank: Super Contributor
timestamp: July 06, 2023, 01:54:14 pm
content: An external mosfet switch will be far simpler and safer to implement, make for the shore.

author: sparkydog
author_rank: Regular Contributor
timestamp: July 26, 2023, 10:10:59 pm
content: Okay, I think the answer here is that it's probably sanest to use a simple MOSFET....which Terry said, but failed to explain.This is effectivelythis circuit(also see picture; the simple switch is standing in for the MCU). That is, PS_ON is normally pulled up to 5V and should, in fact, be the same voltage as VSB. Thus, I can see no reason why the device that switches PS_ON to ground would need to be isolated from the MCU's output, so a simple MOSFET should be fine.From a MOSFET's perspective, an MCU pin set to INPUT should be the same as a pin set to OUTPUT LOW, so there is no problem when the PSU is first switched on, nor is there a problem switching the pin from INPUT to OUTPUT. Plus, the MCU logic is more intuitive; LOW is PSU off, HIGH is PSU on.