Tuesday, February 27, 2018

Toggle Switch to Pulse Conversion Circuit

For my next computer build - my filevault and media server - I wanted to take a less microcontrollery way to turn the computer on and off. My parents' build required a microcontroller because I didn't have the parts for this when I built it, so I had to make do. But, as I said before, I don't like cutting sandwiches with chainsaws. It seems wasteful to me to use a whole microcontroller to do one simple task and sleep the rest of the time. So I designed a specialized circuit to do it. I'm by no means a electrical engineer, so this may be a poor design. But stay with me to the end, because this simple thing works (and it's a very short post because it's so simple).

There were several ideas around how I should change a non-momentary toggle switch into a pulse like a momentary button. The simplest of answers I found on the internet was to use a small capacitor to make the motherboard sense the power switch pin being pulled to ground. But I didn't like that because it seemed sketchy. There were some other solutions I came across but I think my roommate pushed me in the right direction when he gave a suggestion about a capacitor and a XOR gate.

I looked this design up and I couldn't find it anywhere. I was surprised that this hadn't been done before, so I decided to try it and document it here.

Here's a picture of the circuit on a perfboard hooked up to the filevault (next post)


But you'd probably get more information from the circuit diagram. Here it is using an online circuit simulator. I'll describe what it's doing very briefly if it isn't immediately clear.

The switch in the diagram acts as the power button on my case. When that's closed, the XOR gate will receive a high signal on one of its pins. At that same point, that same signal is being delayed on the other line because of the capacitor (the time it takes to charge and thus the length of the impulse is dependent on the RC pair and I'm not good enough at the calculations to figure out an equation for that). While the capacitor is charging, it will go 'logically high' on the other XOR gate input shortly after. During this time, the XOR will output a high value. When the capacitor is charged, it'll output a low value. This causes the XOR output to pulse.

In the case of turning a computer on, I decided to use a transistor as a gate. When the input of the base is high, the power button header on the motherboard will be closed. With that pulse, it's like pressing the power button. This strategy works incredibly well and it's fairly foolproof. Sometimes I fear the capacitor isn't discharging completely, but I have yet to damage the motherboard after many power cycles so I guess everything is fine so far.

I'm using a 2N2222 transistor and a SN74AHC86 Quad-channel XOR gate (because I couldn't find a single channel XOR gate). I connected VCC and Ground on the USB header on the motherboard. It runs on 5V.

That's really all there is to it. I just wanted to make a dedicated post about this because I didn't see a non-clocked edge detection circuit like this. Hope it's interesting if not helpful to someone out there.

No comments:

Post a Comment