I'm looking to create a simple circuit to connect/disconnect a power storage capacitor to/from a larger circuit. In the model railroading world, we use capacitors as "keep-alives" to keep the decoder (the larger circuit mentioned above) powered when a train rolls over dirty track or a dead spot. This can create a problem when programming the decoder. The programming process requires removing power from the decoder for periods of time, and if the capacitor is connected during this process, programming can fail.
The decoders I use have a logic level (4.5V) output that is active high when the capacitor (~12V) can be connected to the decoder, low when the capacitor should be disconnected. I've seen others use this signal to control a FET that controls a solid state relay that connects and disconnects the capacitor, but SSRs are (relatively) expensive and this seems like something that should have a single IC solution to me. I was thinking this could probably be done with a power MOSFET, not remembering that MOSFETs are unidirectional devices (since the capacitor is both charged and discharged by this circuit).
I found that two MOSFETs can be used back-to-back to create a bidirectional "switch", so I ordered a few QS5K2TR common source 2 channel N-FETs to play around with. I have gotten this approach to work on my bench by connecting drain 1 to ground and drain 2 to the negative side of the capacitor and controlling the gates by connecting them to +5V or leaving them floating. For this to work, I had to connect the shared Source to the gate through a 10K ohm resistor, similar to what is found here: https://www.homemade-circuits.com/bidirectional-switch. I haven't seemed to need the charge pump mentioned when using back-to-back N-FETs.
Here's the circuit as it stands:
I'm a bit uncomfortable with this solution since I don't really understand why the shared Source needs to be connected to the gate through the resistor. (Well, I understand that N-FETs rely on Vgs to turn on/off, but I would think that connecting the shared Source to Gate through a resistor would prevent this from working correctly, especially since the "high" voltage current of charging or discharging the capacitor flows through this shared Source)
I also haven't been able to find what seems like the usual solution for what I have to imagine is a rather common problem: disconnecting a battery/capacitor that is charged and drained over the same lines. I'm sure this is because I'm not using the right search terms.
Can anybody point me towards the correct approach for this problem? Is there a single IC that could fill the roll of U1 above, replacing the dashed box?
Thanks for your help!