The plan is to add in an auxiliary circuit(in red) for the capacitor to charge and discharge when power imbalance occur between the AC and DC side. I could not figure out a way to control the newly added circuit in order to achieve the function above. Can anyone give some advice? Thank you.