Jesus,
This code seems to work for me. What problem are you seeing? g[t] and q[t] are set separately. Since you never hit the case when q[t]==0 and i[t]==0, g[t] is never reset to 0. If you try this code, you will see that the concept works I set g[t] ->0 when q[t] is 0 and i[t] <5 (but clearly it is meaningless for your application).
tf = 0.03;
system = {vo'[t] == -vo[t]/(r c) + i[t] (1 - q[t])/c,
i'[t] == (-(1 - q[t]) vo[t]/l + vi/l) g[t], vo[0] == 0,
i[0] == 0};
control = {q[0] == 0,
WhenEvent[Mod[t, \[Tau]] == 0.695 \[Tau], q[t] -> 0],
WhenEvent[Mod[t, \[Tau]] == 0, q[t] -> 1]};
control1 = {g[0] == 0, WhenEvent[q[t] == 1, g[t] -> 1],
WhenEvent[(q[t] == 0) && (i[t] != 0), g[t] -> 1],
WhenEvent[(q[t] == 0) && (i[t] < 5), g[t] -> 0]};
pars = {vi -> 5, vd -> 16, r -> 15, l -> 50*^-6,
c -> 100*^-6, \[Tau] -> 1/50000};
sol = NDSolve[{system, control, control1} /. pars, {vo, i, q, g}, {t,
0, tf}, DiscreteVariables -> {q, g}, MaxSteps -> Infinity];
GraphicsColumn[{Plot[{vo[t] /. sol, vd /. pars}, {t, 0, tf},
PlotRange -> All, PlotPoints -> 100],
Plot[{i[t] /. sol}, {t, 0, tf}, PlotRange -> All],
Plot[q[t] /. sol, {t, 0, .0004}],
Plot[{g[t] /. sol}, {t, 0, tf}, PlotRange -> All]}]
One other note:
Mathematica notation for scientific notation is 50*^-6
to mean 50E-6 or 50 x 10^-6
Regards,
Neil