Dear Neil,
Based on you observation I have changed my code to be
tf = 0.003;
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] <= 0), 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];
{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]}
The response
is closer to what is should be. See what happens in SystemModeler
It seems that some additional tuning is required but WhenEvent[] does a good job.
Any ideas to improve the response to equate the WSM solution?
Regards,
Jesus