How does the output jump up to 7.5 volts when the switch is closed and opened again?

Sorry if the question might sound dumb. In this circuit, when the switch is closed the output voltage drops to zero and then rapidly charges back up to 5 volts. My question being, when the switch is opened up back again, the voltage spikes up to 7.5 bolts as shown in the oscilloscope figure attached. I am confused as the direction of the current would be the opposite of what it used to be when the switch is closed. Can anyone help me with understanding the behavior of this circuit? thanks!

• When the switch is closed, $C_1$'s left side is tied to $0\:\text{V}$ while the right side is pulled upward, over time, such that it eventually rises to $5\:\text{V}$. So, after some time, there is $5\:\text{V}$ across $C_1$ with the right side more positive than the left. When the switch opens, $C_1$ discharges via both resistors developing $2.5\:\text{V}$ across each. But the mid-point of those resistors is tied to $5\:\text{V}$ so $V_\text{OUT}$ must be $2.5\:\text{V}$ above the $5\:\text{V}$ rail and the left side of $C_1$ then $2.5\:\text{V}$ below it. – jonk Apr 13 '19 at 6:02
• Thank you so much for your great help! – Mohammed Osama Apr 13 '19 at 8:59

1. Here, capacitor $$\C_1\$$ has long been discharged so the voltage difference across its leads is $$\0\:\text{V}\$$. So there is no current in $$\R_1\$$ or $$\R_2\$$ and therefore no voltage drop across either resistor. The output voltage will be $$\5\:\text{V}\$$.
2. Now the switch is closed. $$\R_2\$$ has its own current but doesn't participate in charging $$\C_1\$$ so I removed it as "distracting" so that you can focus on the capacitor charging activity. $$\V_\text{OUT}\$$ will rise, exponentially, until it reaches $$\V_\text{OUT}=+5\:\text{V}\$$ and then the charging process stops.
3. The switch is re-opened and the circuit returns to the configuration shown in step 1 above. However, there is a difference. Now, node $$\N_2\$$ is $$\+5\:\text{V}\$$ relative to node $$\N_1\$$. Because of this, current immediately starts flowing through $$\R_1\$$ and then through $$\R_2\$$ in order to start discharging $$\C_1\$$ via this path. The two resistors have the same value, so their mid-point (which is attached to a $$\+5\:\text{V}\$$ voltage source) will be half-way between or $$\2.5\:\text{V}\$$ lower than node $$\N_2\$$ and $$\2.5\:\text{V}\$$ higher than node $$\N_1\$$. So it must be the case, right after opening the switch, that $$\V_{\text{N}_1}=+2.5\:\text{V}\$$ and $$\V_{\text{N}_2}=+7.5\:\text{V}\$$. Note that there is still just the original $$\5\:\text{V}\$$ voltage difference across $$\C_1\$$. That didn't change (yet.) But now $$\V_\text{OUT}\$$ must initially start higher than $$\+5\:\text{V}\$$ (by the voltage drop across $$\R_1\$$.) Now, $$\C_1\$$ discharges via the two resistors and eventually returns to its discharged state. In the meantime, the current through the two resistors declines and therefore also the voltage at $$\V_\text{OUT}\$$ gradually returns to $$\+5\:\text{V}\$$.
You can adjust the ratio of $$\R_1\$$ and $$\R_2\$$ to get different peak voltages. For example, if you change $$\R_1\$$ to $$\2\:\text{k}\Omega\$$ then $$\V_\text{OUT}\$$ will rise above $$\8.3\:\text{V}\$$ for a short time -- more than the $$\7.5\:\text{V}\$$ you see in your trace.