Tuesday, June 12, 2012

Overriding PSU Safety Features


So I have one of those computer PSUs that I converted into a "bench power supply;" not really that elegant, but it does the job. However, when I pull too much amps from it, it shuts off. This is a good thing, but one annoying part of it is that I have to disconnect the green wire from ground to reset the safety feature. Especially annoying when both my hands are occupied, holding wires to a capacitor.

I did the only sensible thing and overrode that safety feature, with the help of a certain programmable chip.


(Courtesy of ~underitall from DeviantArt. http://fav.me/d4hkxml)


My very professional-looking schematic of the circuit.




Pin 1 - D/C
Pin 2 - Input - Button with pull-down resistor (1KΩ Brown Black Red)
Pin 3 - Input - Red Wire (+5 VDC from PSU)
Pin 4 - Ground
Pin 5 - D/C
Pin 6 - Output - Status LED
Pin 7 - Output - Green Wire (PSU Power control)
Pin 8 - Vcc - Purple Wire (It provides +5 VDC even if the PSU is "off")


Prototype stage




Perfboard stage







  • When I just press the button, the PSU turns on, no safety features overridden. (State 1)
  • When I press and hold the button while the unit is on, the safety features are overridden. In this stage, the LED continually fades in and out, notifying the user of the possible danger that could occur. (State 2)
  • When the button is pressed again, the unit reverts back to ON. (State 1)
  • When the button is pressed once again, the unit turns off. (State 0)
When the green wire is provided +5 VDC (current sourcing), the PSU views it as disconnected, as when it isn't connected to anything, the voltage on the green wire is +5 VDC.
When it is pulled down to ground (current sinking), the PSU turns on.


And finally, here is the code:
(Get the Bounce Library here: http://www.arduino.cc/playground/Code/Bounce)

#include <Bounce.h>

#define pinLED 1
#define pinCtrl 2
#define pinButton 3
#define pinPower 4
int brightness = 0;
int state = 0; //0 is off, 1 is on, 2 is power


long timecurr = 0;
long timelater = 0;
#define period 500
#define holddown 1000


Bounce button = Bounce(pinButton,5);

void setup(){
  pinMode(pinLED, OUTPUT);
  pinMode(pinCtrl, OUTPUT);
  pinMode(pinButton, INPUT);
  pinMode(pinPower, INPUT);
}

void loop(){

  timecurr = millis();
 

  if(state == 0){
    digitalWrite(pinCtrl, HIGH);
    digitalWrite(pinLED, LOW);
   
    button.update();
    while(button.read() == HIGH){
      button.update();
      if(button.read() == LOW){
        state = 1;
      }
    }
  }
 
  else if(state == 1){
   
    digitalWrite(pinCtrl, LOW);
    digitalWrite(pinLED, HIGH);
   
    button.update();
    timelater = timecurr;
    while(button.read() == HIGH){
     
      timecurr = millis();
     
      if(timecurr - timelater > holddown){
        brightness = 128+127*cos((2*PI*millis())/period);
        analogWrite(pinLED, brightness);
        state = 2;
      }
     
      button.update();
      if(button.read() == LOW && state == 1){
          state = 0;
      }
    }
  }
 
  else{
   
    brightness = 128+127*cos((2*PI*timecurr)/period);
    analogWrite(pinLED, brightness);
   
    digitalWrite(pinCtrl, LOW);
    timelater = timecurr;
    while(digitalRead(pinPower) == LOW){
      digitalWrite(pinCtrl, HIGH);
     
      timecurr = millis();
      do{
        timelater = millis();
        brightness = 128+127*cos((2*PI*millis())/period);
        analogWrite(pinLED, brightness);
      }
      while(timelater - timecurr < 500);
     
      digitalWrite(pinCtrl, LOW);
     
      timecurr = millis();
      do{
        timelater = millis();
        brightness = 128+127*cos((2*PI*millis())/period);
        analogWrite(pinLED, brightness);
      }
      while(timelater - timecurr < 500);
       
    }
   
    button.update();
    while(button.read() == HIGH){
      button.update();
      if(button.read() == LOW){
        state = 1;
      }
    }
   
  }

}

Special Thanks to:

My computer science major friend for helping me debug the code

MIT's High Low Tech for their tutorial on putting Arduino on the Attiny.
My brother for buying me an Arduino for Christmas!
Hack-a-Day for featuring me! Click here.