If the charge and discharge rates must be identical, then you are going to need to switch both the charge and discharge sides as shown by @Hearth. If they do not need to be identical, then there are a few alternate approaches.
The following is an example of using all N-channel devices to charge and discharge capacitor C1. C1 is charged through R2 when M1 is turned on, and discharged through R1 + R2 when M1 is turned off.
M2, C2, R3, and R4 are used to 'charge-pump' the gate of M1, so that it can turn on even though there is no higher-voltage supply for switching M1.
How It Works:
Control is a 0V/5V signal. Low turns off M2. High turns on M2.
- Start with Control LOW and M1 OFF.
- C1 discharges to 0V through R1 + R2.
- C2 'discharges' to 5V on both sides through R3 and R4.
- Set Control HIGH
- M2 is turned on
- C2 is pulled to approximately ground (source-drain voltage of M2) on one side, and the other side charges to approx. 5V through R4.
- When C2 is charged, it contains a stored charge of C x V == 0.1uF x 5V.
- M1 remains off
- Set Control LOW
- C2 still has the stored charge 0.1uF x 5V.
- C2 right-side charges towards 5V through R3.
- At same time C2 left-side is 'pushed' to over 5V due to stored charge.
- C2 left-side starts to discharge towards 5V through R4.
- Discharge of left-side is slower than charge-up of right-side.
- Current difference is 100k / 100.
- Left-side of C2 discharges 1e3 times slower than right-side charges.
- The stored charge is slowly drained off until both sides C2 are about 5V.
- MEANWHILE...
- M1 gate goes to about 10V and discharges towards 5V as left-side C2 discharges.
- M1 turns ON.
- C1 charges towards 5V through R2.
- If you leave Control LOW long enough, eventually M1 gate discharges to cutoff and M1 shuts off.
- Set Control HIGH
- M2 turns ON.
- C2 right-side gets pulled to ground(ish).
- C2 has about zero stored charge.
- C2 left-side gets pulled to about ground
- M1 turns OFF if it is not already off due to leaving Control LOW too long.
- C2 left-side begins to charge towards 5V through R4.
Lather, rinse, repeat. :)
Notes:
- You must switch Control HI/LOW fast enough to keep M1 from turning off when the C2 'pump' voltage drops below M1's gate-source turn-on voltage.
- You can play with R3/R4 to control the 'pump' time constant which impacts the required period for Control.
If you want C2 to recharge fast, you can add D1 in parallel with R4 as shown below. With this change, when control goes HIGH, C2 right-side is 'grounded' and C2 left-side charges "really fast" through D1 to 5V - 0.6V(ish, the forward-biased diode voltage). When Control goes LOW, D1 reverse-biases and C2 left-side discharges through R3 as in the first circuit.